Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-mips.c -- assemble code for a MIPS chip. |
056350c6 | 2 | Copyright (C) 1993, 94, 95, 96, 97, 98, 1999, 2000 Free Software Foundation, Inc. |
252b5132 RH |
3 | Contributed by the OSF and Ralph Campbell. |
4 | Written by Keith Knowles and Ralph Campbell, working independently. | |
5 | Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus | |
6 | Support. | |
7 | ||
8 | This file is part of GAS. | |
9 | ||
10 | GAS is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2, or (at your option) | |
13 | any later version. | |
14 | ||
15 | GAS is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GAS; see the file COPYING. If not, write to the Free | |
22 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
23 | 02111-1307, USA. */ | |
24 | ||
25 | #include "as.h" | |
26 | #include "config.h" | |
27 | #include "subsegs.h" | |
28 | ||
29 | #include <ctype.h> | |
30 | ||
31 | #ifdef USE_STDARG | |
32 | #include <stdarg.h> | |
33 | #endif | |
34 | #ifdef USE_VARARGS | |
35 | #include <varargs.h> | |
36 | #endif | |
37 | ||
38 | #include "opcode/mips.h" | |
39 | #include "itbl-ops.h" | |
40 | ||
41 | #ifdef DEBUG | |
42 | #define DBG(x) printf x | |
43 | #else | |
44 | #define DBG(x) | |
45 | #endif | |
46 | ||
47 | #ifdef OBJ_MAYBE_ELF | |
48 | /* Clean up namespace so we can include obj-elf.h too. */ | |
49 | static int mips_output_flavor PARAMS ((void)); | |
50 | static int mips_output_flavor () { return OUTPUT_FLAVOR; } | |
51 | #undef OBJ_PROCESS_STAB | |
52 | #undef OUTPUT_FLAVOR | |
53 | #undef S_GET_ALIGN | |
54 | #undef S_GET_SIZE | |
55 | #undef S_SET_ALIGN | |
56 | #undef S_SET_SIZE | |
252b5132 RH |
57 | #undef obj_frob_file |
58 | #undef obj_frob_file_after_relocs | |
59 | #undef obj_frob_symbol | |
60 | #undef obj_pop_insert | |
61 | #undef obj_sec_sym_ok_for_reloc | |
62 | #undef OBJ_COPY_SYMBOL_ATTRIBUTES | |
63 | ||
64 | #include "obj-elf.h" | |
65 | /* Fix any of them that we actually care about. */ | |
66 | #undef OUTPUT_FLAVOR | |
67 | #define OUTPUT_FLAVOR mips_output_flavor() | |
68 | #endif | |
69 | ||
70 | #if defined (OBJ_ELF) | |
71 | #include "elf/mips.h" | |
72 | #endif | |
73 | ||
74 | #ifndef ECOFF_DEBUGGING | |
75 | #define NO_ECOFF_DEBUGGING | |
76 | #define ECOFF_DEBUGGING 0 | |
77 | #endif | |
78 | ||
79 | #include "ecoff.h" | |
80 | ||
81 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
82 | static char *mips_regmask_frag; | |
83 | #endif | |
84 | ||
85 | #define AT 1 | |
86 | #define TREG 24 | |
87 | #define PIC_CALL_REG 25 | |
88 | #define KT0 26 | |
89 | #define KT1 27 | |
90 | #define GP 28 | |
91 | #define SP 29 | |
92 | #define FP 30 | |
93 | #define RA 31 | |
94 | ||
95 | #define ILLEGAL_REG (32) | |
96 | ||
97 | /* Allow override of standard little-endian ECOFF format. */ | |
98 | ||
99 | #ifndef ECOFF_LITTLE_FORMAT | |
100 | #define ECOFF_LITTLE_FORMAT "ecoff-littlemips" | |
101 | #endif | |
102 | ||
103 | extern int target_big_endian; | |
104 | ||
105 | /* 1 is we should use the 64 bit MIPS ELF ABI, 0 if we should use the | |
106 | 32 bit ABI. This has no meaning for ECOFF. | |
107 | Note that the default is always 32 bit, even if "configured" for | |
108 | 64 bit [e.g. --target=mips64-elf]. */ | |
109 | static int mips_64; | |
110 | ||
111 | /* The default target format to use. */ | |
112 | const char * | |
113 | mips_target_format () | |
114 | { | |
115 | switch (OUTPUT_FLAVOR) | |
116 | { | |
117 | case bfd_target_aout_flavour: | |
118 | return target_big_endian ? "a.out-mips-big" : "a.out-mips-little"; | |
119 | case bfd_target_ecoff_flavour: | |
120 | return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT; | |
056350c6 NC |
121 | case bfd_target_coff_flavour: |
122 | return "pe-mips"; | |
252b5132 | 123 | case bfd_target_elf_flavour: |
8614eeee UC |
124 | #ifdef TE_TMIPS |
125 | /* This is traditional mips */ | |
126 | return (target_big_endian | |
127 | ? "elf32-tradbigmips" : "elf32-tradlittlemips"); | |
128 | #else | |
252b5132 RH |
129 | return (target_big_endian |
130 | ? (mips_64 ? "elf64-bigmips" : "elf32-bigmips") | |
131 | : (mips_64 ? "elf64-littlemips" : "elf32-littlemips")); | |
8614eeee | 132 | #endif |
252b5132 RH |
133 | default: |
134 | abort (); | |
135 | return NULL; | |
136 | } | |
137 | } | |
138 | ||
139 | /* The name of the readonly data section. */ | |
140 | #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \ | |
141 | ? ".data" \ | |
142 | : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \ | |
143 | ? ".rdata" \ | |
056350c6 NC |
144 | : OUTPUT_FLAVOR == bfd_target_coff_flavour \ |
145 | ? ".rdata" \ | |
252b5132 RH |
146 | : OUTPUT_FLAVOR == bfd_target_elf_flavour \ |
147 | ? ".rodata" \ | |
148 | : (abort (), "")) | |
149 | ||
150 | /* This is the set of options which may be modified by the .set | |
151 | pseudo-op. We use a struct so that .set push and .set pop are more | |
152 | reliable. */ | |
153 | ||
154 | struct mips_set_options | |
155 | { | |
156 | /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 | |
157 | if it has not been initialized. Changed by `.set mipsN', and the | |
158 | -mipsN command line option, and the default CPU. */ | |
159 | int isa; | |
160 | /* Whether we are assembling for the mips16 processor. 0 if we are | |
161 | not, 1 if we are, and -1 if the value has not been initialized. | |
162 | Changed by `.set mips16' and `.set nomips16', and the -mips16 and | |
163 | -nomips16 command line options, and the default CPU. */ | |
164 | int mips16; | |
165 | /* Non-zero if we should not reorder instructions. Changed by `.set | |
166 | reorder' and `.set noreorder'. */ | |
167 | int noreorder; | |
168 | /* Non-zero if we should not permit the $at ($1) register to be used | |
169 | in instructions. Changed by `.set at' and `.set noat'. */ | |
170 | int noat; | |
171 | /* Non-zero if we should warn when a macro instruction expands into | |
172 | more than one machine instruction. Changed by `.set nomacro' and | |
173 | `.set macro'. */ | |
174 | int warn_about_macros; | |
175 | /* Non-zero if we should not move instructions. Changed by `.set | |
176 | move', `.set volatile', `.set nomove', and `.set novolatile'. */ | |
177 | int nomove; | |
178 | /* Non-zero if we should not optimize branches by moving the target | |
179 | of the branch into the delay slot. Actually, we don't perform | |
180 | this optimization anyhow. Changed by `.set bopt' and `.set | |
181 | nobopt'. */ | |
182 | int nobopt; | |
183 | /* Non-zero if we should not autoextend mips16 instructions. | |
184 | Changed by `.set autoextend' and `.set noautoextend'. */ | |
185 | int noautoextend; | |
186 | }; | |
187 | ||
188 | /* This is the struct we use to hold the current set of options. Note | |
189 | that we must set the isa and mips16 fields to -1 to indicate that | |
190 | they have not been initialized. */ | |
191 | ||
43841e91 | 192 | static struct mips_set_options mips_opts = { -1, -1, 0, 0, 0, 0, 0, 0 }; |
252b5132 RH |
193 | |
194 | /* These variables are filled in with the masks of registers used. | |
195 | The object format code reads them and puts them in the appropriate | |
196 | place. */ | |
197 | unsigned long mips_gprmask; | |
198 | unsigned long mips_cprmask[4]; | |
199 | ||
200 | /* MIPS ISA we are using for this output file. */ | |
201 | static int file_mips_isa; | |
202 | ||
203 | /* The CPU type as a number: 2000, 3000, 4000, 4400, etc. */ | |
204 | static int mips_cpu = -1; | |
205 | ||
bdaaa2e1 | 206 | /* The argument of the -mabi= flag. */ |
252b5132 RH |
207 | static char* mips_abi_string = 0; |
208 | ||
bdaaa2e1 | 209 | /* Wether we should mark the file EABI64 or EABI32. */ |
252b5132 RH |
210 | static int mips_eabi64 = 0; |
211 | ||
212 | /* If they asked for mips1 or mips2 and a cpu that is | |
bdaaa2e1 | 213 | mips3 or greater, then mark the object file 32BITMODE. */ |
252b5132 RH |
214 | static int mips_32bitmode = 0; |
215 | ||
bdaaa2e1 | 216 | /* True if -mgp32 was passed. */ |
c97ef257 AH |
217 | static int mips_gp32 = 0; |
218 | ||
9ce8a5dd GRK |
219 | /* Some ISA's have delay slots for instructions which read or write |
220 | from a coprocessor (eg. mips1-mips3); some don't (eg mips4). | |
bdaaa2e1 | 221 | Return true if instructions marked INSN_LOAD_COPROC_DELAY, |
9ce8a5dd GRK |
222 | INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a |
223 | delay slot in this ISA. The uses of this macro assume that any | |
224 | ISA that has delay slots for one of these, has them for all. They | |
225 | also assume that ISAs which don't have delays for these insns, don't | |
bdaaa2e1 | 226 | have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */ |
9ce8a5dd GRK |
227 | #define ISA_HAS_COPROC_DELAYS(ISA) ( \ |
228 | (ISA) == 1 \ | |
229 | || (ISA) == 2 \ | |
230 | || (ISA) == 3 \ | |
231 | ) | |
232 | ||
bdaaa2e1 | 233 | /* Return true if ISA supports 64 bit gp register instructions. */ |
9ce8a5dd GRK |
234 | #define ISA_HAS_64BIT_REGS(ISA) ( \ |
235 | (ISA) == 3 \ | |
236 | || (ISA) == 4 \ | |
237 | ) | |
238 | ||
bdaaa2e1 | 239 | /* Whether the processor uses hardware interlocks to protect |
252b5132 RH |
240 | reads from the HI and LO registers, and thus does not |
241 | require nops to be inserted. | |
242 | ||
243 | FIXME: GCC makes a distinction between -mcpu=FOO and -mFOO: | |
244 | -mcpu=FOO schedules for FOO, but still produces code that meets the | |
245 | requirements of MIPS ISA I. For example, it won't generate any | |
246 | FOO-specific instructions, and it will still assume that any | |
247 | scheduling hazards described in MIPS ISA I are there, even if FOO | |
248 | has interlocks. -mFOO gives GCC permission to generate code that | |
249 | will only run on a FOO; it will generate FOO-specific instructions, | |
250 | and assume interlocks provided by a FOO. | |
251 | ||
252 | However, GAS currently doesn't make this distinction; before Jan 28 | |
253 | 1999, GAS's -mcpu=FOO implied -mFOO, which violates GCC's | |
254 | assumptions. The GCC driver passes these flags through to GAS, so | |
255 | if GAS actually does anything that doesn't meet MIPS ISA I with | |
256 | -mFOO, then GCC's -mcpu=FOO flag isn't going to work. | |
257 | ||
258 | And furthermore, it did not assume that -mFOO implied -mcpu=FOO, | |
259 | which seems senseless --- why generate code which will only run on | |
260 | a FOO, but schedule for something else? | |
261 | ||
262 | So now, at least, -mcpu=FOO and -mFOO are exactly equivalent. | |
263 | ||
264 | -- Jim Blandy <jimb@cygnus.com> */ | |
265 | ||
156c2f8b | 266 | #define hilo_interlocks (mips_cpu == CPU_R4010 \ |
252b5132 RH |
267 | ) |
268 | ||
269 | /* Whether the processor uses hardware interlocks to protect reads | |
270 | from the GPRs, and thus does not require nops to be inserted. */ | |
271 | #define gpr_interlocks \ | |
9ce8a5dd | 272 | (mips_opts.isa != 1 \ |
156c2f8b | 273 | || mips_cpu == CPU_R3900) |
252b5132 RH |
274 | |
275 | /* As with other "interlocks" this is used by hardware that has FP | |
276 | (co-processor) interlocks. */ | |
bdaaa2e1 | 277 | /* Itbl support may require additional care here. */ |
156c2f8b | 278 | #define cop_interlocks (mips_cpu == CPU_R4300 \ |
252b5132 RH |
279 | ) |
280 | ||
6b76fefe CM |
281 | /* Is this a mfhi or mflo instruction? */ |
282 | #define MF_HILO_INSN(PINFO) \ | |
283 | ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO)) | |
284 | ||
252b5132 RH |
285 | /* MIPS PIC level. */ |
286 | ||
287 | enum mips_pic_level | |
288 | { | |
289 | /* Do not generate PIC code. */ | |
290 | NO_PIC, | |
291 | ||
292 | /* Generate PIC code as in Irix 4. This is not implemented, and I'm | |
293 | not sure what it is supposed to do. */ | |
294 | IRIX4_PIC, | |
295 | ||
296 | /* Generate PIC code as in the SVR4 MIPS ABI. */ | |
297 | SVR4_PIC, | |
298 | ||
299 | /* Generate PIC code without using a global offset table: the data | |
300 | segment has a maximum size of 64K, all data references are off | |
301 | the $gp register, and all text references are PC relative. This | |
302 | is used on some embedded systems. */ | |
303 | EMBEDDED_PIC | |
304 | }; | |
305 | ||
306 | static enum mips_pic_level mips_pic; | |
307 | ||
308 | /* 1 if we should generate 32 bit offsets from the GP register in | |
309 | SVR4_PIC mode. Currently has no meaning in other modes. */ | |
310 | static int mips_big_got; | |
311 | ||
312 | /* 1 if trap instructions should used for overflow rather than break | |
313 | instructions. */ | |
314 | static int mips_trap; | |
315 | ||
119d663a NC |
316 | /* 1 if double width floating point constants should not be constructed |
317 | by a assembling two single width halves into two single width floating | |
318 | point registers which just happen to alias the double width destination | |
319 | register. On some architectures this aliasing can be disabled by a bit | |
d547a75e | 320 | in the status register, and the setting of this bit cannot be determined |
119d663a NC |
321 | automatically at assemble time. */ |
322 | static int mips_disable_float_construction; | |
323 | ||
252b5132 RH |
324 | /* Non-zero if any .set noreorder directives were used. */ |
325 | ||
326 | static int mips_any_noreorder; | |
327 | ||
6b76fefe CM |
328 | /* Non-zero if nops should be inserted when the register referenced in |
329 | an mfhi/mflo instruction is read in the next two instructions. */ | |
330 | static int mips_7000_hilo_fix; | |
331 | ||
252b5132 | 332 | /* The size of the small data section. */ |
156c2f8b | 333 | static unsigned int g_switch_value = 8; |
252b5132 RH |
334 | /* Whether the -G option was used. */ |
335 | static int g_switch_seen = 0; | |
336 | ||
337 | #define N_RMASK 0xc4 | |
338 | #define N_VFP 0xd4 | |
339 | ||
340 | /* If we can determine in advance that GP optimization won't be | |
341 | possible, we can skip the relaxation stuff that tries to produce | |
342 | GP-relative references. This makes delay slot optimization work | |
343 | better. | |
344 | ||
345 | This function can only provide a guess, but it seems to work for | |
fba2b7f9 GK |
346 | gcc output. It needs to guess right for gcc, otherwise gcc |
347 | will put what it thinks is a GP-relative instruction in a branch | |
348 | delay slot. | |
252b5132 RH |
349 | |
350 | I don't know if a fix is needed for the SVR4_PIC mode. I've only | |
351 | fixed it for the non-PIC mode. KR 95/04/07 */ | |
352 | static int nopic_need_relax PARAMS ((symbolS *, int)); | |
353 | ||
354 | /* handle of the OPCODE hash table */ | |
355 | static struct hash_control *op_hash = NULL; | |
356 | ||
357 | /* The opcode hash table we use for the mips16. */ | |
358 | static struct hash_control *mips16_op_hash = NULL; | |
359 | ||
360 | /* This array holds the chars that always start a comment. If the | |
361 | pre-processor is disabled, these aren't very useful */ | |
362 | const char comment_chars[] = "#"; | |
363 | ||
364 | /* This array holds the chars that only start a comment at the beginning of | |
365 | a line. If the line seems to have the form '# 123 filename' | |
366 | .line and .file directives will appear in the pre-processed output */ | |
367 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
368 | first line of the input file. This is because the compiler outputs | |
bdaaa2e1 | 369 | #NO_APP at the beginning of its output. */ |
252b5132 RH |
370 | /* Also note that C style comments are always supported. */ |
371 | const char line_comment_chars[] = "#"; | |
372 | ||
bdaaa2e1 | 373 | /* This array holds machine specific line separator characters. */ |
63a0b638 | 374 | const char line_separator_chars[] = ";"; |
252b5132 RH |
375 | |
376 | /* Chars that can be used to separate mant from exp in floating point nums */ | |
377 | const char EXP_CHARS[] = "eE"; | |
378 | ||
379 | /* Chars that mean this number is a floating point constant */ | |
380 | /* As in 0f12.456 */ | |
381 | /* or 0d1.2345e12 */ | |
382 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
383 | ||
384 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
385 | changed in read.c . Ideally it shouldn't have to know about it at all, | |
386 | but nothing is ideal around here. | |
387 | */ | |
388 | ||
389 | static char *insn_error; | |
390 | ||
391 | static int auto_align = 1; | |
392 | ||
393 | /* When outputting SVR4 PIC code, the assembler needs to know the | |
394 | offset in the stack frame from which to restore the $gp register. | |
395 | This is set by the .cprestore pseudo-op, and saved in this | |
396 | variable. */ | |
397 | static offsetT mips_cprestore_offset = -1; | |
398 | ||
399 | /* This is the register which holds the stack frame, as set by the | |
400 | .frame pseudo-op. This is needed to implement .cprestore. */ | |
401 | static int mips_frame_reg = SP; | |
402 | ||
403 | /* To output NOP instructions correctly, we need to keep information | |
404 | about the previous two instructions. */ | |
405 | ||
406 | /* Whether we are optimizing. The default value of 2 means to remove | |
407 | unneeded NOPs and swap branch instructions when possible. A value | |
408 | of 1 means to not swap branches. A value of 0 means to always | |
409 | insert NOPs. */ | |
410 | static int mips_optimize = 2; | |
411 | ||
412 | /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is | |
413 | equivalent to seeing no -g option at all. */ | |
414 | static int mips_debug = 0; | |
415 | ||
416 | /* The previous instruction. */ | |
417 | static struct mips_cl_insn prev_insn; | |
418 | ||
419 | /* The instruction before prev_insn. */ | |
420 | static struct mips_cl_insn prev_prev_insn; | |
421 | ||
422 | /* If we don't want information for prev_insn or prev_prev_insn, we | |
423 | point the insn_mo field at this dummy integer. */ | |
43841e91 | 424 | static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 }; |
252b5132 RH |
425 | |
426 | /* Non-zero if prev_insn is valid. */ | |
427 | static int prev_insn_valid; | |
428 | ||
429 | /* The frag for the previous instruction. */ | |
430 | static struct frag *prev_insn_frag; | |
431 | ||
432 | /* The offset into prev_insn_frag for the previous instruction. */ | |
433 | static long prev_insn_where; | |
434 | ||
435 | /* The reloc type for the previous instruction, if any. */ | |
436 | static bfd_reloc_code_real_type prev_insn_reloc_type; | |
437 | ||
438 | /* The reloc for the previous instruction, if any. */ | |
439 | static fixS *prev_insn_fixp; | |
440 | ||
441 | /* Non-zero if the previous instruction was in a delay slot. */ | |
442 | static int prev_insn_is_delay_slot; | |
443 | ||
444 | /* Non-zero if the previous instruction was in a .set noreorder. */ | |
445 | static int prev_insn_unreordered; | |
446 | ||
447 | /* Non-zero if the previous instruction uses an extend opcode (if | |
448 | mips16). */ | |
449 | static int prev_insn_extended; | |
450 | ||
451 | /* Non-zero if the previous previous instruction was in a .set | |
452 | noreorder. */ | |
453 | static int prev_prev_insn_unreordered; | |
454 | ||
455 | /* If this is set, it points to a frag holding nop instructions which | |
456 | were inserted before the start of a noreorder section. If those | |
457 | nops turn out to be unnecessary, the size of the frag can be | |
458 | decreased. */ | |
459 | static fragS *prev_nop_frag; | |
460 | ||
461 | /* The number of nop instructions we created in prev_nop_frag. */ | |
462 | static int prev_nop_frag_holds; | |
463 | ||
464 | /* The number of nop instructions that we know we need in | |
bdaaa2e1 | 465 | prev_nop_frag. */ |
252b5132 RH |
466 | static int prev_nop_frag_required; |
467 | ||
468 | /* The number of instructions we've seen since prev_nop_frag. */ | |
469 | static int prev_nop_frag_since; | |
470 | ||
471 | /* For ECOFF and ELF, relocations against symbols are done in two | |
472 | parts, with a HI relocation and a LO relocation. Each relocation | |
473 | has only 16 bits of space to store an addend. This means that in | |
474 | order for the linker to handle carries correctly, it must be able | |
475 | to locate both the HI and the LO relocation. This means that the | |
476 | relocations must appear in order in the relocation table. | |
477 | ||
478 | In order to implement this, we keep track of each unmatched HI | |
479 | relocation. We then sort them so that they immediately precede the | |
bdaaa2e1 | 480 | corresponding LO relocation. */ |
252b5132 RH |
481 | |
482 | struct mips_hi_fixup | |
483 | { | |
484 | /* Next HI fixup. */ | |
485 | struct mips_hi_fixup *next; | |
486 | /* This fixup. */ | |
487 | fixS *fixp; | |
488 | /* The section this fixup is in. */ | |
489 | segT seg; | |
490 | }; | |
491 | ||
492 | /* The list of unmatched HI relocs. */ | |
493 | ||
494 | static struct mips_hi_fixup *mips_hi_fixup_list; | |
495 | ||
496 | /* Map normal MIPS register numbers to mips16 register numbers. */ | |
497 | ||
498 | #define X ILLEGAL_REG | |
499 | static const int mips32_to_16_reg_map[] = | |
500 | { | |
501 | X, X, 2, 3, 4, 5, 6, 7, | |
502 | X, X, X, X, X, X, X, X, | |
503 | 0, 1, X, X, X, X, X, X, | |
504 | X, X, X, X, X, X, X, X | |
505 | }; | |
506 | #undef X | |
507 | ||
508 | /* Map mips16 register numbers to normal MIPS register numbers. */ | |
509 | ||
156c2f8b | 510 | static const unsigned int mips16_to_32_reg_map[] = |
252b5132 RH |
511 | { |
512 | 16, 17, 2, 3, 4, 5, 6, 7 | |
513 | }; | |
514 | \f | |
515 | /* Since the MIPS does not have multiple forms of PC relative | |
516 | instructions, we do not have to do relaxing as is done on other | |
517 | platforms. However, we do have to handle GP relative addressing | |
518 | correctly, which turns out to be a similar problem. | |
519 | ||
520 | Every macro that refers to a symbol can occur in (at least) two | |
521 | forms, one with GP relative addressing and one without. For | |
522 | example, loading a global variable into a register generally uses | |
523 | a macro instruction like this: | |
524 | lw $4,i | |
525 | If i can be addressed off the GP register (this is true if it is in | |
526 | the .sbss or .sdata section, or if it is known to be smaller than | |
527 | the -G argument) this will generate the following instruction: | |
528 | lw $4,i($gp) | |
529 | This instruction will use a GPREL reloc. If i can not be addressed | |
530 | off the GP register, the following instruction sequence will be used: | |
531 | lui $at,i | |
532 | lw $4,i($at) | |
533 | In this case the first instruction will have a HI16 reloc, and the | |
534 | second reloc will have a LO16 reloc. Both relocs will be against | |
535 | the symbol i. | |
536 | ||
537 | The issue here is that we may not know whether i is GP addressable | |
538 | until after we see the instruction that uses it. Therefore, we | |
539 | want to be able to choose the final instruction sequence only at | |
540 | the end of the assembly. This is similar to the way other | |
541 | platforms choose the size of a PC relative instruction only at the | |
542 | end of assembly. | |
543 | ||
544 | When generating position independent code we do not use GP | |
545 | addressing in quite the same way, but the issue still arises as | |
546 | external symbols and local symbols must be handled differently. | |
547 | ||
548 | We handle these issues by actually generating both possible | |
549 | instruction sequences. The longer one is put in a frag_var with | |
550 | type rs_machine_dependent. We encode what to do with the frag in | |
551 | the subtype field. We encode (1) the number of existing bytes to | |
552 | replace, (2) the number of new bytes to use, (3) the offset from | |
553 | the start of the existing bytes to the first reloc we must generate | |
554 | (that is, the offset is applied from the start of the existing | |
555 | bytes after they are replaced by the new bytes, if any), (4) the | |
556 | offset from the start of the existing bytes to the second reloc, | |
557 | (5) whether a third reloc is needed (the third reloc is always four | |
558 | bytes after the second reloc), and (6) whether to warn if this | |
559 | variant is used (this is sometimes needed if .set nomacro or .set | |
560 | noat is in effect). All these numbers are reasonably small. | |
561 | ||
562 | Generating two instruction sequences must be handled carefully to | |
563 | ensure that delay slots are handled correctly. Fortunately, there | |
564 | are a limited number of cases. When the second instruction | |
565 | sequence is generated, append_insn is directed to maintain the | |
566 | existing delay slot information, so it continues to apply to any | |
567 | code after the second instruction sequence. This means that the | |
568 | second instruction sequence must not impose any requirements not | |
569 | required by the first instruction sequence. | |
570 | ||
571 | These variant frags are then handled in functions called by the | |
572 | machine independent code. md_estimate_size_before_relax returns | |
573 | the final size of the frag. md_convert_frag sets up the final form | |
574 | of the frag. tc_gen_reloc adjust the first reloc and adds a second | |
575 | one if needed. */ | |
576 | #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \ | |
577 | ((relax_substateT) \ | |
578 | (((old) << 23) \ | |
579 | | ((new) << 16) \ | |
580 | | (((reloc1) + 64) << 9) \ | |
581 | | (((reloc2) + 64) << 2) \ | |
582 | | ((reloc3) ? (1 << 1) : 0) \ | |
583 | | ((warn) ? 1 : 0))) | |
584 | #define RELAX_OLD(i) (((i) >> 23) & 0x7f) | |
585 | #define RELAX_NEW(i) (((i) >> 16) & 0x7f) | |
586 | #define RELAX_RELOC1(i) ((bfd_vma)(((i) >> 9) & 0x7f) - 64) | |
587 | #define RELAX_RELOC2(i) ((bfd_vma)(((i) >> 2) & 0x7f) - 64) | |
588 | #define RELAX_RELOC3(i) (((i) >> 1) & 1) | |
589 | #define RELAX_WARN(i) ((i) & 1) | |
590 | ||
591 | /* For mips16 code, we use an entirely different form of relaxation. | |
592 | mips16 supports two versions of most instructions which take | |
593 | immediate values: a small one which takes some small value, and a | |
594 | larger one which takes a 16 bit value. Since branches also follow | |
595 | this pattern, relaxing these values is required. | |
596 | ||
597 | We can assemble both mips16 and normal MIPS code in a single | |
598 | object. Therefore, we need to support this type of relaxation at | |
599 | the same time that we support the relaxation described above. We | |
600 | use the high bit of the subtype field to distinguish these cases. | |
601 | ||
602 | The information we store for this type of relaxation is the | |
603 | argument code found in the opcode file for this relocation, whether | |
604 | the user explicitly requested a small or extended form, and whether | |
605 | the relocation is in a jump or jal delay slot. That tells us the | |
606 | size of the value, and how it should be stored. We also store | |
607 | whether the fragment is considered to be extended or not. We also | |
608 | store whether this is known to be a branch to a different section, | |
609 | whether we have tried to relax this frag yet, and whether we have | |
610 | ever extended a PC relative fragment because of a shift count. */ | |
611 | #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \ | |
612 | (0x80000000 \ | |
613 | | ((type) & 0xff) \ | |
614 | | ((small) ? 0x100 : 0) \ | |
615 | | ((ext) ? 0x200 : 0) \ | |
616 | | ((dslot) ? 0x400 : 0) \ | |
617 | | ((jal_dslot) ? 0x800 : 0)) | |
618 | #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0) | |
619 | #define RELAX_MIPS16_TYPE(i) ((i) & 0xff) | |
620 | #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0) | |
621 | #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0) | |
622 | #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0) | |
623 | #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0) | |
624 | #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0) | |
625 | #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000) | |
626 | #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000) | |
627 | #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0) | |
628 | #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000) | |
629 | #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000) | |
630 | \f | |
631 | /* Prototypes for static functions. */ | |
632 | ||
633 | #ifdef __STDC__ | |
634 | #define internalError() \ | |
635 | as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__) | |
636 | #else | |
637 | #define internalError() as_fatal (_("MIPS internal Error")); | |
638 | #endif | |
639 | ||
640 | enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG }; | |
641 | ||
642 | static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip, | |
643 | unsigned int reg, enum mips_regclass class)); | |
156c2f8b | 644 | static int reg_needs_delay PARAMS ((unsigned int)); |
252b5132 RH |
645 | static void mips16_mark_labels PARAMS ((void)); |
646 | static void append_insn PARAMS ((char *place, | |
647 | struct mips_cl_insn * ip, | |
648 | expressionS * p, | |
649 | bfd_reloc_code_real_type r, | |
650 | boolean)); | |
651 | static void mips_no_prev_insn PARAMS ((int)); | |
652 | static void mips_emit_delays PARAMS ((boolean)); | |
653 | #ifdef USE_STDARG | |
654 | static void macro_build PARAMS ((char *place, int *counter, expressionS * ep, | |
655 | const char *name, const char *fmt, | |
656 | ...)); | |
657 | #else | |
658 | static void macro_build (); | |
659 | #endif | |
660 | static void mips16_macro_build PARAMS ((char *, int *, expressionS *, | |
661 | const char *, const char *, | |
662 | va_list)); | |
663 | static void macro_build_lui PARAMS ((char *place, int *counter, | |
664 | expressionS * ep, int regnum)); | |
665 | static void set_at PARAMS ((int *counter, int reg, int unsignedp)); | |
666 | static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip, | |
667 | expressionS *)); | |
668 | static void load_register PARAMS ((int *, int, expressionS *, int)); | |
669 | static void load_address PARAMS ((int *counter, int reg, expressionS *ep)); | |
670 | static void macro PARAMS ((struct mips_cl_insn * ip)); | |
671 | static void mips16_macro PARAMS ((struct mips_cl_insn * ip)); | |
672 | #ifdef LOSING_COMPILER | |
673 | static void macro2 PARAMS ((struct mips_cl_insn * ip)); | |
674 | #endif | |
675 | static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
676 | static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip)); | |
677 | static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean, | |
678 | boolean, boolean, unsigned long *, | |
679 | boolean *, unsigned short *)); | |
680 | static int my_getSmallExpression PARAMS ((expressionS * ep, char *str)); | |
681 | static void my_getExpression PARAMS ((expressionS * ep, char *str)); | |
682 | static symbolS *get_symbol PARAMS ((void)); | |
683 | static void mips_align PARAMS ((int to, int fill, symbolS *label)); | |
684 | static void s_align PARAMS ((int)); | |
685 | static void s_change_sec PARAMS ((int)); | |
686 | static void s_cons PARAMS ((int)); | |
687 | static void s_float_cons PARAMS ((int)); | |
688 | static void s_mips_globl PARAMS ((int)); | |
689 | static void s_option PARAMS ((int)); | |
690 | static void s_mipsset PARAMS ((int)); | |
691 | static void s_abicalls PARAMS ((int)); | |
692 | static void s_cpload PARAMS ((int)); | |
693 | static void s_cprestore PARAMS ((int)); | |
694 | static void s_gpword PARAMS ((int)); | |
695 | static void s_cpadd PARAMS ((int)); | |
696 | static void s_insn PARAMS ((int)); | |
697 | static void md_obj_begin PARAMS ((void)); | |
698 | static void md_obj_end PARAMS ((void)); | |
699 | static long get_number PARAMS ((void)); | |
700 | static void s_mips_ent PARAMS ((int)); | |
701 | static void s_mips_end PARAMS ((int)); | |
702 | static void s_mips_frame PARAMS ((int)); | |
703 | static void s_mips_mask PARAMS ((int)); | |
704 | static void s_mips_stab PARAMS ((int)); | |
705 | static void s_mips_weakext PARAMS ((int)); | |
706 | static void s_file PARAMS ((int)); | |
707 | static int mips16_extended_frag PARAMS ((fragS *, asection *, long)); | |
156c2f8b | 708 | static char *mips_cpu_to_str PARAMS ((int)); |
252b5132 | 709 | |
252b5132 RH |
710 | static int validate_mips_insn PARAMS ((const struct mips_opcode *)); |
711 | \f | |
712 | /* Pseudo-op table. | |
713 | ||
714 | The following pseudo-ops from the Kane and Heinrich MIPS book | |
715 | should be defined here, but are currently unsupported: .alias, | |
716 | .galive, .gjaldef, .gjrlive, .livereg, .noalias. | |
717 | ||
718 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
719 | specific to the type of debugging information being generated, and | |
720 | should be defined by the object format: .aent, .begin, .bend, | |
721 | .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp, | |
722 | .vreg. | |
723 | ||
724 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
725 | not MIPS CPU specific, but are also not specific to the object file | |
726 | format. This file is probably the best place to define them, but | |
727 | they are not currently supported: .asm0, .endr, .lab, .repeat, | |
728 | .struct. */ | |
729 | ||
730 | static const pseudo_typeS mips_pseudo_table[] = | |
731 | { | |
732 | /* MIPS specific pseudo-ops. */ | |
733 | {"option", s_option, 0}, | |
734 | {"set", s_mipsset, 0}, | |
735 | {"rdata", s_change_sec, 'r'}, | |
736 | {"sdata", s_change_sec, 's'}, | |
737 | {"livereg", s_ignore, 0}, | |
738 | {"abicalls", s_abicalls, 0}, | |
739 | {"cpload", s_cpload, 0}, | |
740 | {"cprestore", s_cprestore, 0}, | |
741 | {"gpword", s_gpword, 0}, | |
742 | {"cpadd", s_cpadd, 0}, | |
743 | {"insn", s_insn, 0}, | |
744 | ||
745 | /* Relatively generic pseudo-ops that happen to be used on MIPS | |
746 | chips. */ | |
747 | {"asciiz", stringer, 1}, | |
748 | {"bss", s_change_sec, 'b'}, | |
749 | {"err", s_err, 0}, | |
750 | {"half", s_cons, 1}, | |
751 | {"dword", s_cons, 3}, | |
752 | {"weakext", s_mips_weakext, 0}, | |
753 | ||
754 | /* These pseudo-ops are defined in read.c, but must be overridden | |
755 | here for one reason or another. */ | |
756 | {"align", s_align, 0}, | |
757 | {"byte", s_cons, 0}, | |
758 | {"data", s_change_sec, 'd'}, | |
759 | {"double", s_float_cons, 'd'}, | |
760 | {"float", s_float_cons, 'f'}, | |
761 | {"globl", s_mips_globl, 0}, | |
762 | {"global", s_mips_globl, 0}, | |
763 | {"hword", s_cons, 1}, | |
764 | {"int", s_cons, 2}, | |
765 | {"long", s_cons, 2}, | |
766 | {"octa", s_cons, 4}, | |
767 | {"quad", s_cons, 3}, | |
768 | {"short", s_cons, 1}, | |
769 | {"single", s_float_cons, 'f'}, | |
770 | {"stabn", s_mips_stab, 'n'}, | |
771 | {"text", s_change_sec, 't'}, | |
772 | {"word", s_cons, 2}, | |
43841e91 | 773 | { NULL, NULL, 0 }, |
252b5132 RH |
774 | }; |
775 | ||
776 | static const pseudo_typeS mips_nonecoff_pseudo_table[] = { | |
777 | /* These pseudo-ops should be defined by the object file format. | |
778 | However, a.out doesn't support them, so we have versions here. */ | |
779 | {"aent", s_mips_ent, 1}, | |
780 | {"bgnb", s_ignore, 0}, | |
781 | {"end", s_mips_end, 0}, | |
782 | {"endb", s_ignore, 0}, | |
783 | {"ent", s_mips_ent, 0}, | |
784 | {"file", s_file, 0}, | |
785 | {"fmask", s_mips_mask, 'F'}, | |
786 | {"frame", s_mips_frame, 0}, | |
787 | {"loc", s_ignore, 0}, | |
788 | {"mask", s_mips_mask, 'R'}, | |
789 | {"verstamp", s_ignore, 0}, | |
43841e91 | 790 | { NULL, NULL, 0 }, |
252b5132 RH |
791 | }; |
792 | ||
793 | extern void pop_insert PARAMS ((const pseudo_typeS *)); | |
794 | ||
795 | void | |
796 | mips_pop_insert () | |
797 | { | |
798 | pop_insert (mips_pseudo_table); | |
799 | if (! ECOFF_DEBUGGING) | |
800 | pop_insert (mips_nonecoff_pseudo_table); | |
801 | } | |
802 | \f | |
803 | /* Symbols labelling the current insn. */ | |
804 | ||
805 | struct insn_label_list | |
806 | { | |
807 | struct insn_label_list *next; | |
808 | symbolS *label; | |
809 | }; | |
810 | ||
811 | static struct insn_label_list *insn_labels; | |
812 | static struct insn_label_list *free_insn_labels; | |
813 | ||
814 | static void mips_clear_insn_labels PARAMS ((void)); | |
815 | ||
816 | static inline void | |
817 | mips_clear_insn_labels () | |
818 | { | |
819 | register struct insn_label_list **pl; | |
820 | ||
821 | for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next) | |
822 | ; | |
823 | *pl = insn_labels; | |
824 | insn_labels = NULL; | |
825 | } | |
826 | \f | |
827 | static char *expr_end; | |
828 | ||
829 | /* Expressions which appear in instructions. These are set by | |
830 | mips_ip. */ | |
831 | ||
832 | static expressionS imm_expr; | |
833 | static expressionS offset_expr; | |
834 | ||
835 | /* Relocs associated with imm_expr and offset_expr. */ | |
836 | ||
837 | static bfd_reloc_code_real_type imm_reloc; | |
838 | static bfd_reloc_code_real_type offset_reloc; | |
839 | ||
840 | /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */ | |
841 | ||
842 | static boolean imm_unmatched_hi; | |
843 | ||
844 | /* These are set by mips16_ip if an explicit extension is used. */ | |
845 | ||
846 | static boolean mips16_small, mips16_ext; | |
847 | ||
848 | #ifdef MIPS_STABS_ELF | |
849 | /* The pdr segment for per procedure frame/regmask info */ | |
850 | ||
851 | static segT pdr_seg; | |
852 | #endif | |
853 | ||
156c2f8b NC |
854 | static char * |
855 | mips_cpu_to_str (cpu) | |
856 | int cpu; | |
857 | { | |
858 | static char s[16]; | |
859 | switch (cpu) | |
860 | { | |
861 | case CPU_R2000: return "R2000"; | |
862 | case CPU_R3000: return "R3000"; | |
863 | case CPU_R3900: return "R3900"; | |
864 | case CPU_R4000: return "R4000"; | |
865 | case CPU_R4010: return "R4010"; | |
866 | case CPU_VR4100: return "VR4100"; | |
867 | case CPU_R4111: return "R4111"; | |
868 | case CPU_R4300: return "R4300"; | |
869 | case CPU_R4400: return "R4400"; | |
870 | case CPU_R4600: return "R4600"; | |
871 | case CPU_R4650: return "R4650"; | |
872 | case CPU_R5000: return "R5000"; | |
873 | case CPU_R6000: return "R6000"; | |
874 | case CPU_R8000: return "R8000"; | |
875 | case CPU_R10000: return "R10000"; | |
876 | case CPU_4K: return "4K"; | |
877 | default: | |
878 | sprintf (s, "%d", cpu); | |
879 | return s; | |
880 | } | |
881 | } | |
882 | ||
883 | /* This function is called once, at assembler startup time. It should | |
884 | set up all the tables, etc. that the MD part of the assembler will need. */ | |
885 | ||
252b5132 RH |
886 | void |
887 | md_begin () | |
888 | { | |
889 | boolean ok = false; | |
890 | register const char *retval = NULL; | |
156c2f8b | 891 | int i = 0; |
252b5132 RH |
892 | const char *cpu; |
893 | char *a = NULL; | |
894 | int broken = 0; | |
895 | int mips_isa_from_cpu; | |
896 | ||
056350c6 NC |
897 | /* GP relative stuff not working for PE */ |
898 | if (strncmp (TARGET_OS, "pe", 2) == 0 | |
899 | && g_switch_value != 0) | |
900 | { | |
901 | if (g_switch_seen) | |
902 | as_bad (_("-G not supported in this configuration.")); | |
903 | g_switch_value = 0; | |
904 | } | |
905 | ||
252b5132 RH |
906 | cpu = TARGET_CPU; |
907 | if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0) | |
908 | { | |
909 | a = xmalloc (sizeof TARGET_CPU); | |
910 | strcpy (a, TARGET_CPU); | |
911 | a[(sizeof TARGET_CPU) - 3] = '\0'; | |
912 | cpu = a; | |
913 | } | |
914 | ||
915 | if (mips_cpu < 0) | |
916 | { | |
917 | /* Set mips_cpu based on TARGET_CPU, unless TARGET_CPU is | |
918 | just the generic 'mips', in which case set mips_cpu based | |
bdaaa2e1 | 919 | on the given ISA, if any. */ |
252b5132 RH |
920 | |
921 | if (strcmp (cpu, "mips") == 0) | |
922 | { | |
9ce8a5dd | 923 | if (mips_opts.isa < 0) |
156c2f8b | 924 | mips_cpu = CPU_R3000; |
252b5132 | 925 | |
9ce8a5dd | 926 | else if (mips_opts.isa == 2) |
156c2f8b | 927 | mips_cpu = CPU_R6000; |
252b5132 RH |
928 | |
929 | else if (mips_opts.isa == 3) | |
156c2f8b | 930 | mips_cpu = CPU_R4000; |
252b5132 RH |
931 | |
932 | else if (mips_opts.isa == 4) | |
156c2f8b | 933 | mips_cpu = CPU_R8000; |
252b5132 | 934 | |
bdaaa2e1 | 935 | else |
156c2f8b | 936 | mips_cpu = CPU_R3000; |
252b5132 | 937 | } |
bdaaa2e1 | 938 | |
252b5132 RH |
939 | else if (strcmp (cpu, "r3900") == 0 |
940 | || strcmp (cpu, "mipstx39") == 0 | |
941 | ) | |
156c2f8b | 942 | mips_cpu = CPU_R3900; |
252b5132 RH |
943 | |
944 | else if (strcmp (cpu, "r6000") == 0 | |
945 | || strcmp (cpu, "mips2") == 0) | |
156c2f8b | 946 | mips_cpu = CPU_R6000; |
252b5132 RH |
947 | |
948 | else if (strcmp (cpu, "mips64") == 0 | |
949 | || strcmp (cpu, "r4000") == 0 | |
950 | || strcmp (cpu, "mips3") == 0) | |
156c2f8b | 951 | mips_cpu = CPU_R4000; |
252b5132 RH |
952 | |
953 | else if (strcmp (cpu, "r4400") == 0) | |
156c2f8b | 954 | mips_cpu = CPU_R4400; |
252b5132 RH |
955 | |
956 | else if (strcmp (cpu, "mips64orion") == 0 | |
957 | || strcmp (cpu, "r4600") == 0) | |
156c2f8b | 958 | mips_cpu = CPU_R4600; |
252b5132 RH |
959 | |
960 | else if (strcmp (cpu, "r4650") == 0) | |
156c2f8b | 961 | mips_cpu = CPU_R4650; |
252b5132 RH |
962 | |
963 | else if (strcmp (cpu, "mips64vr4300") == 0) | |
156c2f8b | 964 | mips_cpu = CPU_R4300; |
252b5132 RH |
965 | |
966 | else if (strcmp (cpu, "mips64vr4111") == 0) | |
156c2f8b | 967 | mips_cpu = CPU_R4111; |
252b5132 RH |
968 | |
969 | else if (strcmp (cpu, "mips64vr4100") == 0) | |
156c2f8b | 970 | mips_cpu = CPU_VR4100; |
252b5132 RH |
971 | |
972 | else if (strcmp (cpu, "r4010") == 0) | |
156c2f8b NC |
973 | mips_cpu = CPU_R4010; |
974 | ||
975 | else if (strcmp (cpu, "4Kc") == 0 | |
976 | || strcmp (cpu, "4Kp") == 0 | |
977 | || strcmp (cpu, "4Km") == 0) | |
978 | mips_cpu = CPU_4K; | |
252b5132 | 979 | |
252b5132 RH |
980 | else if (strcmp (cpu, "r5000") == 0 |
981 | || strcmp (cpu, "mips64vr5000") == 0) | |
156c2f8b | 982 | mips_cpu = CPU_R5000; |
252b5132 | 983 | |
252b5132 RH |
984 | else if (strcmp (cpu, "r8000") == 0 |
985 | || strcmp (cpu, "mips4") == 0) | |
156c2f8b | 986 | mips_cpu = CPU_R8000; |
bdaaa2e1 | 987 | |
252b5132 | 988 | else if (strcmp (cpu, "r10000") == 0) |
156c2f8b | 989 | mips_cpu = CPU_R10000; |
252b5132 RH |
990 | |
991 | else if (strcmp (cpu, "mips16") == 0) | |
992 | mips_cpu = 0; /* FIXME */ | |
993 | ||
994 | else | |
156c2f8b | 995 | mips_cpu = CPU_R3000; |
252b5132 RH |
996 | } |
997 | ||
156c2f8b NC |
998 | if (mips_cpu == CPU_R3000 |
999 | || mips_cpu == CPU_R3900) | |
252b5132 RH |
1000 | mips_isa_from_cpu = 1; |
1001 | ||
156c2f8b NC |
1002 | else if (mips_cpu == CPU_R6000 |
1003 | || mips_cpu == CPU_R4010) | |
252b5132 RH |
1004 | mips_isa_from_cpu = 2; |
1005 | ||
156c2f8b NC |
1006 | else if (mips_cpu == CPU_R4000 |
1007 | || mips_cpu == CPU_VR4100 | |
1008 | || mips_cpu == CPU_R4111 | |
1009 | || mips_cpu == CPU_R4400 | |
1010 | || mips_cpu == CPU_R4300 | |
1011 | || mips_cpu == CPU_R4600 | |
1012 | || mips_cpu == CPU_R4650) | |
252b5132 RH |
1013 | mips_isa_from_cpu = 3; |
1014 | ||
156c2f8b NC |
1015 | else if (mips_cpu == CPU_R5000 |
1016 | || mips_cpu == CPU_R8000 | |
1017 | || mips_cpu == CPU_R10000) | |
252b5132 RH |
1018 | mips_isa_from_cpu = 4; |
1019 | ||
1020 | else | |
1021 | mips_isa_from_cpu = -1; | |
1022 | ||
1023 | if (mips_opts.isa == -1) | |
1024 | { | |
1025 | if (mips_isa_from_cpu != -1) | |
1026 | mips_opts.isa = mips_isa_from_cpu; | |
1027 | else | |
1028 | mips_opts.isa = 1; | |
1029 | } | |
1030 | ||
1031 | if (mips_opts.mips16 < 0) | |
1032 | { | |
1033 | if (strncmp (TARGET_CPU, "mips16", sizeof "mips16" - 1) == 0) | |
1034 | mips_opts.mips16 = 1; | |
1035 | else | |
1036 | mips_opts.mips16 = 0; | |
1037 | } | |
1038 | ||
1039 | /* End of TARGET_CPU processing, get rid of malloced memory | |
bdaaa2e1 | 1040 | if necessary. */ |
252b5132 RH |
1041 | cpu = NULL; |
1042 | if (a != NULL) | |
1043 | { | |
156c2f8b NC |
1044 | free (a); |
1045 | a = NULL; | |
252b5132 RH |
1046 | } |
1047 | ||
9ce8a5dd | 1048 | if (mips_opts.isa == 1 && mips_trap) |
252b5132 RH |
1049 | as_bad (_("trap exception not supported at ISA 1")); |
1050 | ||
1051 | /* Set the EABI kind based on the ISA before the user gets | |
1052 | to change the ISA with directives. This isn't really | |
bdaaa2e1 | 1053 | the best, but then neither is basing the abi on the isa. */ |
9ce8a5dd | 1054 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) |
252b5132 RH |
1055 | && mips_abi_string |
1056 | && 0 == strcmp (mips_abi_string,"eabi")) | |
1057 | mips_eabi64 = 1; | |
1058 | ||
1059 | if (mips_cpu != 0 && mips_cpu != -1) | |
1060 | { | |
1061 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_cpu); | |
bdaaa2e1 | 1062 | |
252b5132 | 1063 | /* If they asked for mips1 or mips2 and a cpu that is |
bdaaa2e1 | 1064 | mips3 or greater, then mark the object file 32BITMODE. */ |
252b5132 | 1065 | if (mips_isa_from_cpu != -1 |
bdaaa2e1 | 1066 | && ! ISA_HAS_64BIT_REGS (mips_opts.isa) |
9ce8a5dd | 1067 | && ISA_HAS_64BIT_REGS (mips_isa_from_cpu)) |
252b5132 RH |
1068 | mips_32bitmode = 1; |
1069 | } | |
1070 | else | |
1071 | { | |
1072 | switch (mips_opts.isa) | |
1073 | { | |
1074 | case 1: | |
156c2f8b | 1075 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, CPU_R3000); |
252b5132 RH |
1076 | break; |
1077 | case 2: | |
156c2f8b | 1078 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, CPU_R6000); |
252b5132 RH |
1079 | break; |
1080 | case 3: | |
156c2f8b | 1081 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, CPU_R4000); |
252b5132 RH |
1082 | break; |
1083 | case 4: | |
156c2f8b | 1084 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, CPU_R8000); |
252b5132 RH |
1085 | break; |
1086 | } | |
1087 | } | |
1088 | ||
1089 | if (! ok) | |
1090 | as_warn (_("Could not set architecture and machine")); | |
1091 | ||
1092 | file_mips_isa = mips_opts.isa; | |
1093 | ||
1094 | op_hash = hash_new (); | |
1095 | ||
1096 | for (i = 0; i < NUMOPCODES;) | |
1097 | { | |
1098 | const char *name = mips_opcodes[i].name; | |
1099 | ||
1100 | retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]); | |
1101 | if (retval != NULL) | |
1102 | { | |
1103 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), | |
1104 | mips_opcodes[i].name, retval); | |
1105 | /* Probably a memory allocation problem? Give up now. */ | |
1106 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1107 | } | |
1108 | do | |
1109 | { | |
1110 | if (mips_opcodes[i].pinfo != INSN_MACRO) | |
1111 | { | |
1112 | if (!validate_mips_insn (&mips_opcodes[i])) | |
1113 | broken = 1; | |
1114 | } | |
1115 | ++i; | |
1116 | } | |
1117 | while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name)); | |
1118 | } | |
1119 | ||
1120 | mips16_op_hash = hash_new (); | |
1121 | ||
1122 | i = 0; | |
1123 | while (i < bfd_mips16_num_opcodes) | |
1124 | { | |
1125 | const char *name = mips16_opcodes[i].name; | |
1126 | ||
1127 | retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]); | |
1128 | if (retval != NULL) | |
1129 | as_fatal (_("internal: can't hash `%s': %s"), | |
1130 | mips16_opcodes[i].name, retval); | |
1131 | do | |
1132 | { | |
1133 | if (mips16_opcodes[i].pinfo != INSN_MACRO | |
1134 | && ((mips16_opcodes[i].match & mips16_opcodes[i].mask) | |
1135 | != mips16_opcodes[i].match)) | |
1136 | { | |
1137 | fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"), | |
1138 | mips16_opcodes[i].name, mips16_opcodes[i].args); | |
1139 | broken = 1; | |
1140 | } | |
1141 | ++i; | |
1142 | } | |
1143 | while (i < bfd_mips16_num_opcodes | |
1144 | && strcmp (mips16_opcodes[i].name, name) == 0); | |
1145 | } | |
1146 | ||
1147 | if (broken) | |
1148 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1149 | ||
1150 | /* We add all the general register names to the symbol table. This | |
1151 | helps us detect invalid uses of them. */ | |
1152 | for (i = 0; i < 32; i++) | |
1153 | { | |
1154 | char buf[5]; | |
1155 | ||
1156 | sprintf (buf, "$%d", i); | |
1157 | symbol_table_insert (symbol_new (buf, reg_section, i, | |
1158 | &zero_address_frag)); | |
1159 | } | |
1160 | symbol_table_insert (symbol_new ("$fp", reg_section, FP, | |
1161 | &zero_address_frag)); | |
1162 | symbol_table_insert (symbol_new ("$sp", reg_section, SP, | |
1163 | &zero_address_frag)); | |
1164 | symbol_table_insert (symbol_new ("$gp", reg_section, GP, | |
1165 | &zero_address_frag)); | |
1166 | symbol_table_insert (symbol_new ("$at", reg_section, AT, | |
1167 | &zero_address_frag)); | |
1168 | symbol_table_insert (symbol_new ("$kt0", reg_section, KT0, | |
1169 | &zero_address_frag)); | |
1170 | symbol_table_insert (symbol_new ("$kt1", reg_section, KT1, | |
1171 | &zero_address_frag)); | |
1172 | symbol_table_insert (symbol_new ("$pc", reg_section, -1, | |
1173 | &zero_address_frag)); | |
1174 | ||
1175 | mips_no_prev_insn (false); | |
1176 | ||
1177 | mips_gprmask = 0; | |
1178 | mips_cprmask[0] = 0; | |
1179 | mips_cprmask[1] = 0; | |
1180 | mips_cprmask[2] = 0; | |
1181 | mips_cprmask[3] = 0; | |
1182 | ||
1183 | /* set the default alignment for the text section (2**2) */ | |
1184 | record_alignment (text_section, 2); | |
1185 | ||
1186 | if (USE_GLOBAL_POINTER_OPT) | |
1187 | bfd_set_gp_size (stdoutput, g_switch_value); | |
1188 | ||
1189 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1190 | { | |
1191 | /* On a native system, sections must be aligned to 16 byte | |
1192 | boundaries. When configured for an embedded ELF target, we | |
1193 | don't bother. */ | |
1194 | if (strcmp (TARGET_OS, "elf") != 0) | |
1195 | { | |
1196 | (void) bfd_set_section_alignment (stdoutput, text_section, 4); | |
1197 | (void) bfd_set_section_alignment (stdoutput, data_section, 4); | |
1198 | (void) bfd_set_section_alignment (stdoutput, bss_section, 4); | |
1199 | } | |
1200 | ||
1201 | /* Create a .reginfo section for register masks and a .mdebug | |
1202 | section for debugging information. */ | |
1203 | { | |
1204 | segT seg; | |
1205 | subsegT subseg; | |
1206 | flagword flags; | |
1207 | segT sec; | |
1208 | ||
1209 | seg = now_seg; | |
1210 | subseg = now_subseg; | |
1211 | ||
1212 | /* The ABI says this section should be loaded so that the | |
1213 | running program can access it. However, we don't load it | |
1214 | if we are configured for an embedded target */ | |
1215 | flags = SEC_READONLY | SEC_DATA; | |
1216 | if (strcmp (TARGET_OS, "elf") != 0) | |
1217 | flags |= SEC_ALLOC | SEC_LOAD; | |
1218 | ||
1219 | if (! mips_64) | |
1220 | { | |
1221 | sec = subseg_new (".reginfo", (subsegT) 0); | |
1222 | ||
252b5132 RH |
1223 | (void) bfd_set_section_flags (stdoutput, sec, flags); |
1224 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
bdaaa2e1 | 1225 | |
252b5132 RH |
1226 | #ifdef OBJ_ELF |
1227 | mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo)); | |
1228 | #endif | |
1229 | } | |
1230 | else | |
1231 | { | |
1232 | /* The 64-bit ABI uses a .MIPS.options section rather than | |
1233 | .reginfo section. */ | |
1234 | sec = subseg_new (".MIPS.options", (subsegT) 0); | |
1235 | (void) bfd_set_section_flags (stdoutput, sec, flags); | |
1236 | (void) bfd_set_section_alignment (stdoutput, sec, 3); | |
1237 | ||
1238 | #ifdef OBJ_ELF | |
1239 | /* Set up the option header. */ | |
1240 | { | |
1241 | Elf_Internal_Options opthdr; | |
1242 | char *f; | |
1243 | ||
1244 | opthdr.kind = ODK_REGINFO; | |
1245 | opthdr.size = (sizeof (Elf_External_Options) | |
1246 | + sizeof (Elf64_External_RegInfo)); | |
1247 | opthdr.section = 0; | |
1248 | opthdr.info = 0; | |
1249 | f = frag_more (sizeof (Elf_External_Options)); | |
1250 | bfd_mips_elf_swap_options_out (stdoutput, &opthdr, | |
1251 | (Elf_External_Options *) f); | |
1252 | ||
1253 | mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo)); | |
1254 | } | |
1255 | #endif | |
1256 | } | |
1257 | ||
1258 | if (ECOFF_DEBUGGING) | |
1259 | { | |
1260 | sec = subseg_new (".mdebug", (subsegT) 0); | |
1261 | (void) bfd_set_section_flags (stdoutput, sec, | |
1262 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1263 | (void) bfd_set_section_alignment (stdoutput, sec, 2); | |
1264 | } | |
1265 | ||
1266 | #ifdef MIPS_STABS_ELF | |
1267 | pdr_seg = subseg_new (".pdr", (subsegT) 0); | |
1268 | (void) bfd_set_section_flags (stdoutput, pdr_seg, | |
1269 | SEC_READONLY | SEC_RELOC | SEC_DEBUGGING); | |
1270 | (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2); | |
1271 | #endif | |
1272 | ||
1273 | subseg_set (seg, subseg); | |
1274 | } | |
1275 | } | |
1276 | ||
1277 | if (! ECOFF_DEBUGGING) | |
1278 | md_obj_begin (); | |
1279 | } | |
1280 | ||
1281 | void | |
1282 | md_mips_end () | |
1283 | { | |
1284 | if (! ECOFF_DEBUGGING) | |
1285 | md_obj_end (); | |
1286 | } | |
1287 | ||
1288 | void | |
1289 | md_assemble (str) | |
1290 | char *str; | |
1291 | { | |
1292 | struct mips_cl_insn insn; | |
1293 | ||
1294 | imm_expr.X_op = O_absent; | |
1295 | imm_reloc = BFD_RELOC_UNUSED; | |
1296 | imm_unmatched_hi = false; | |
1297 | offset_expr.X_op = O_absent; | |
1298 | offset_reloc = BFD_RELOC_UNUSED; | |
1299 | ||
1300 | if (mips_opts.mips16) | |
1301 | mips16_ip (str, &insn); | |
1302 | else | |
1303 | { | |
1304 | mips_ip (str, &insn); | |
bdaaa2e1 | 1305 | DBG((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), |
252b5132 RH |
1306 | str, insn.insn_opcode)); |
1307 | } | |
1308 | ||
1309 | if (insn_error) | |
1310 | { | |
1311 | as_bad ("%s `%s'", insn_error, str); | |
1312 | return; | |
1313 | } | |
1314 | ||
1315 | if (insn.insn_mo->pinfo == INSN_MACRO) | |
1316 | { | |
1317 | if (mips_opts.mips16) | |
1318 | mips16_macro (&insn); | |
1319 | else | |
1320 | macro (&insn); | |
1321 | } | |
1322 | else | |
1323 | { | |
1324 | if (imm_expr.X_op != O_absent) | |
1325 | append_insn ((char *) NULL, &insn, &imm_expr, imm_reloc, | |
1326 | imm_unmatched_hi); | |
1327 | else if (offset_expr.X_op != O_absent) | |
1328 | append_insn ((char *) NULL, &insn, &offset_expr, offset_reloc, false); | |
1329 | else | |
1330 | append_insn ((char *) NULL, &insn, NULL, BFD_RELOC_UNUSED, false); | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | /* See whether instruction IP reads register REG. CLASS is the type | |
1335 | of register. */ | |
1336 | ||
1337 | static int | |
1338 | insn_uses_reg (ip, reg, class) | |
1339 | struct mips_cl_insn *ip; | |
1340 | unsigned int reg; | |
1341 | enum mips_regclass class; | |
1342 | { | |
1343 | if (class == MIPS16_REG) | |
1344 | { | |
1345 | assert (mips_opts.mips16); | |
1346 | reg = mips16_to_32_reg_map[reg]; | |
1347 | class = MIPS_GR_REG; | |
1348 | } | |
1349 | ||
1350 | /* Don't report on general register 0, since it never changes. */ | |
1351 | if (class == MIPS_GR_REG && reg == 0) | |
1352 | return 0; | |
1353 | ||
1354 | if (class == MIPS_FP_REG) | |
1355 | { | |
1356 | assert (! mips_opts.mips16); | |
1357 | /* If we are called with either $f0 or $f1, we must check $f0. | |
1358 | This is not optimal, because it will introduce an unnecessary | |
1359 | NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would | |
1360 | need to distinguish reading both $f0 and $f1 or just one of | |
1361 | them. Note that we don't have to check the other way, | |
1362 | because there is no instruction that sets both $f0 and $f1 | |
1363 | and requires a delay. */ | |
1364 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_S) | |
1365 | && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1) | |
1366 | == (reg &~ (unsigned) 1))) | |
1367 | return 1; | |
1368 | if ((ip->insn_mo->pinfo & INSN_READ_FPR_T) | |
1369 | && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1) | |
1370 | == (reg &~ (unsigned) 1))) | |
1371 | return 1; | |
1372 | } | |
1373 | else if (! mips_opts.mips16) | |
1374 | { | |
1375 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_S) | |
1376 | && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg) | |
1377 | return 1; | |
1378 | if ((ip->insn_mo->pinfo & INSN_READ_GPR_T) | |
1379 | && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg) | |
1380 | return 1; | |
1381 | } | |
1382 | else | |
1383 | { | |
1384 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X) | |
1385 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX) | |
1386 | & MIPS16OP_MASK_RX)] | |
1387 | == reg)) | |
1388 | return 1; | |
1389 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y) | |
1390 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY) | |
1391 | & MIPS16OP_MASK_RY)] | |
1392 | == reg)) | |
1393 | return 1; | |
1394 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z) | |
1395 | && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
1396 | & MIPS16OP_MASK_MOVE32Z)] | |
1397 | == reg)) | |
1398 | return 1; | |
1399 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG) | |
1400 | return 1; | |
1401 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP) | |
1402 | return 1; | |
1403 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA) | |
1404 | return 1; | |
1405 | if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X) | |
1406 | && ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
1407 | & MIPS16OP_MASK_REGR32) == reg) | |
1408 | return 1; | |
1409 | } | |
1410 | ||
1411 | return 0; | |
1412 | } | |
1413 | ||
1414 | /* This function returns true if modifying a register requires a | |
1415 | delay. */ | |
1416 | ||
1417 | static int | |
1418 | reg_needs_delay (reg) | |
156c2f8b | 1419 | unsigned int reg; |
252b5132 RH |
1420 | { |
1421 | unsigned long prev_pinfo; | |
1422 | ||
1423 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1424 | if (! mips_opts.noreorder | |
9ce8a5dd | 1425 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1426 | && ((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1427 | || (! gpr_interlocks | |
1428 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1429 | { | |
1430 | /* A load from a coprocessor or from memory. All load | |
1431 | delays delay the use of general register rt for one | |
1432 | instruction on the r3000. The r6000 and r4000 use | |
1433 | interlocks. */ | |
bdaaa2e1 | 1434 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1435 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1436 | if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)) | |
1437 | return 1; | |
1438 | } | |
1439 | ||
1440 | return 0; | |
1441 | } | |
1442 | ||
1443 | /* Mark instruction labels in mips16 mode. This permits the linker to | |
1444 | handle them specially, such as generating jalx instructions when | |
1445 | needed. We also make them odd for the duration of the assembly, in | |
1446 | order to generate the right sort of code. We will make them even | |
1447 | in the adjust_symtab routine, while leaving them marked. This is | |
1448 | convenient for the debugger and the disassembler. The linker knows | |
1449 | to make them odd again. */ | |
1450 | ||
1451 | static void | |
1452 | mips16_mark_labels () | |
1453 | { | |
1454 | if (mips_opts.mips16) | |
1455 | { | |
1456 | struct insn_label_list *l; | |
1457 | ||
1458 | for (l = insn_labels; l != NULL; l = l->next) | |
1459 | { | |
1460 | #ifdef OBJ_ELF | |
1461 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1462 | S_SET_OTHER (l->label, STO_MIPS16); | |
1463 | #endif | |
49309057 ILT |
1464 | if ((S_GET_VALUE (l->label) & 1) == 0) |
1465 | S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1); | |
252b5132 RH |
1466 | } |
1467 | } | |
1468 | } | |
1469 | ||
1470 | /* Output an instruction. PLACE is where to put the instruction; if | |
1471 | it is NULL, this uses frag_more to get room. IP is the instruction | |
1472 | information. ADDRESS_EXPR is an operand of the instruction to be | |
1473 | used with RELOC_TYPE. */ | |
1474 | ||
1475 | static void | |
1476 | append_insn (place, ip, address_expr, reloc_type, unmatched_hi) | |
1477 | char *place; | |
1478 | struct mips_cl_insn *ip; | |
1479 | expressionS *address_expr; | |
1480 | bfd_reloc_code_real_type reloc_type; | |
1481 | boolean unmatched_hi; | |
1482 | { | |
1483 | register unsigned long prev_pinfo, pinfo; | |
1484 | char *f; | |
1485 | fixS *fixp; | |
1486 | int nops = 0; | |
1487 | ||
1488 | /* Mark instruction labels in mips16 mode. */ | |
1489 | if (mips_opts.mips16) | |
1490 | mips16_mark_labels (); | |
1491 | ||
1492 | prev_pinfo = prev_insn.insn_mo->pinfo; | |
1493 | pinfo = ip->insn_mo->pinfo; | |
1494 | ||
1495 | if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL)) | |
1496 | { | |
1497 | int prev_prev_nop; | |
1498 | ||
1499 | /* If the previous insn required any delay slots, see if we need | |
1500 | to insert a NOP or two. There are eight kinds of possible | |
1501 | hazards, of which an instruction can have at most one type. | |
1502 | (1) a load from memory delay | |
1503 | (2) a load from a coprocessor delay | |
1504 | (3) an unconditional branch delay | |
1505 | (4) a conditional branch delay | |
1506 | (5) a move to coprocessor register delay | |
1507 | (6) a load coprocessor register from memory delay | |
1508 | (7) a coprocessor condition code delay | |
1509 | (8) a HI/LO special register delay | |
1510 | ||
1511 | There are a lot of optimizations we could do that we don't. | |
1512 | In particular, we do not, in general, reorder instructions. | |
1513 | If you use gcc with optimization, it will reorder | |
1514 | instructions and generally do much more optimization then we | |
1515 | do here; repeating all that work in the assembler would only | |
1516 | benefit hand written assembly code, and does not seem worth | |
1517 | it. */ | |
1518 | ||
1519 | /* This is how a NOP is emitted. */ | |
1520 | #define emit_nop() \ | |
1521 | (mips_opts.mips16 \ | |
1522 | ? md_number_to_chars (frag_more (2), 0x6500, 2) \ | |
1523 | : md_number_to_chars (frag_more (4), 0, 4)) | |
1524 | ||
1525 | /* The previous insn might require a delay slot, depending upon | |
1526 | the contents of the current insn. */ | |
1527 | if (! mips_opts.mips16 | |
9ce8a5dd | 1528 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1529 | && (((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
1530 | && ! cop_interlocks) | |
1531 | || (! gpr_interlocks | |
1532 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)))) | |
1533 | { | |
1534 | /* A load from a coprocessor or from memory. All load | |
1535 | delays delay the use of general register rt for one | |
1536 | instruction on the r3000. The r6000 and r4000 use | |
1537 | interlocks. */ | |
bdaaa2e1 | 1538 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1539 | know (prev_pinfo & INSN_WRITE_GPR_T); |
1540 | if (mips_optimize == 0 | |
1541 | || insn_uses_reg (ip, | |
1542 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
1543 | & OP_MASK_RT), | |
1544 | MIPS_GR_REG)) | |
1545 | ++nops; | |
1546 | } | |
1547 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1548 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1549 | && (((prev_pinfo & INSN_COPROC_MOVE_DELAY) |
1550 | && ! cop_interlocks) | |
9ce8a5dd | 1551 | || (mips_opts.isa == 1 |
252b5132 RH |
1552 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)))) |
1553 | { | |
1554 | /* A generic coprocessor delay. The previous instruction | |
1555 | modified a coprocessor general or control register. If | |
1556 | it modified a control register, we need to avoid any | |
1557 | coprocessor instruction (this is probably not always | |
1558 | required, but it sometimes is). If it modified a general | |
1559 | register, we avoid using that register. | |
1560 | ||
1561 | On the r6000 and r4000 loading a coprocessor register | |
1562 | from memory is interlocked, and does not require a delay. | |
1563 | ||
1564 | This case is not handled very well. There is no special | |
1565 | knowledge of CP0 handling, and the coprocessors other | |
1566 | than the floating point unit are not distinguished at | |
1567 | all. */ | |
1568 | /* Itbl support may require additional care here. FIXME! | |
bdaaa2e1 | 1569 | Need to modify this to include knowledge about |
252b5132 RH |
1570 | user specified delays! */ |
1571 | if (prev_pinfo & INSN_WRITE_FPR_T) | |
1572 | { | |
1573 | if (mips_optimize == 0 | |
1574 | || insn_uses_reg (ip, | |
1575 | ((prev_insn.insn_opcode >> OP_SH_FT) | |
1576 | & OP_MASK_FT), | |
1577 | MIPS_FP_REG)) | |
1578 | ++nops; | |
1579 | } | |
1580 | else if (prev_pinfo & INSN_WRITE_FPR_S) | |
1581 | { | |
1582 | if (mips_optimize == 0 | |
1583 | || insn_uses_reg (ip, | |
1584 | ((prev_insn.insn_opcode >> OP_SH_FS) | |
1585 | & OP_MASK_FS), | |
1586 | MIPS_FP_REG)) | |
1587 | ++nops; | |
1588 | } | |
1589 | else | |
1590 | { | |
1591 | /* We don't know exactly what the previous instruction | |
1592 | does. If the current instruction uses a coprocessor | |
1593 | register, we must insert a NOP. If previous | |
1594 | instruction may set the condition codes, and the | |
1595 | current instruction uses them, we must insert two | |
1596 | NOPS. */ | |
bdaaa2e1 | 1597 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1598 | if (mips_optimize == 0 |
1599 | || ((prev_pinfo & INSN_WRITE_COND_CODE) | |
1600 | && (pinfo & INSN_READ_COND_CODE))) | |
1601 | nops += 2; | |
1602 | else if (pinfo & INSN_COP) | |
1603 | ++nops; | |
1604 | } | |
1605 | } | |
1606 | else if (! mips_opts.mips16 | |
9ce8a5dd | 1607 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1608 | && (prev_pinfo & INSN_WRITE_COND_CODE) |
1609 | && ! cop_interlocks) | |
1610 | { | |
1611 | /* The previous instruction sets the coprocessor condition | |
1612 | codes, but does not require a general coprocessor delay | |
1613 | (this means it is a floating point comparison | |
1614 | instruction). If this instruction uses the condition | |
1615 | codes, we need to insert a single NOP. */ | |
bdaaa2e1 | 1616 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1617 | if (mips_optimize == 0 |
1618 | || (pinfo & INSN_READ_COND_CODE)) | |
1619 | ++nops; | |
1620 | } | |
6b76fefe CM |
1621 | |
1622 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1623 | previous insn was an mfhi/mflo and the current insn | |
1624 | reads the register that the mfhi/mflo wrote to, then | |
1625 | insert two nops. */ | |
1626 | ||
1627 | else if (mips_7000_hilo_fix | |
1628 | && MF_HILO_INSN (prev_pinfo) | |
1629 | && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD) | |
1630 | & OP_MASK_RD), | |
1631 | MIPS_GR_REG)) | |
1632 | ||
1633 | { | |
1634 | nops += 2; | |
1635 | } | |
1636 | ||
1637 | /* If we're fixing up mfhi/mflo for the r7000 and the | |
1638 | 2nd previous insn was an mfhi/mflo and the current insn | |
1639 | reads the register that the mfhi/mflo wrote to, then | |
1640 | insert one nop. */ | |
1641 | ||
1642 | else if (mips_7000_hilo_fix | |
1643 | && MF_HILO_INSN (prev_prev_insn.insn_opcode) | |
1644 | && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD) | |
1645 | & OP_MASK_RD), | |
1646 | MIPS_GR_REG)) | |
bdaaa2e1 | 1647 | |
6b76fefe CM |
1648 | { |
1649 | nops += 1; | |
1650 | } | |
bdaaa2e1 | 1651 | |
252b5132 RH |
1652 | else if (prev_pinfo & INSN_READ_LO) |
1653 | { | |
1654 | /* The previous instruction reads the LO register; if the | |
1655 | current instruction writes to the LO register, we must | |
bdaaa2e1 KH |
1656 | insert two NOPS. Some newer processors have interlocks. |
1657 | Also the tx39's multiply instructions can be exectuted | |
252b5132 | 1658 | immediatly after a read from HI/LO (without the delay), |
bdaaa2e1 KH |
1659 | though the tx39's divide insns still do require the |
1660 | delay. */ | |
252b5132 | 1661 | if (! (hilo_interlocks |
156c2f8b | 1662 | || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1663 | && (mips_optimize == 0 |
1664 | || (pinfo & INSN_WRITE_LO))) | |
1665 | nops += 2; | |
1666 | /* Most mips16 branch insns don't have a delay slot. | |
1667 | If a read from LO is immediately followed by a branch | |
1668 | to a write to LO we have a read followed by a write | |
1669 | less than 2 insns away. We assume the target of | |
1670 | a branch might be a write to LO, and insert a nop | |
bdaaa2e1 | 1671 | between a read and an immediately following branch. */ |
252b5132 RH |
1672 | else if (mips_opts.mips16 |
1673 | && (mips_optimize == 0 | |
1674 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1675 | nops += 1; | |
1676 | } | |
1677 | else if (prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
1678 | { | |
1679 | /* The previous instruction reads the HI register; if the | |
1680 | current instruction writes to the HI register, we must | |
1681 | insert a NOP. Some newer processors have interlocks. | |
bdaaa2e1 | 1682 | Also the note tx39's multiply above. */ |
252b5132 | 1683 | if (! (hilo_interlocks |
156c2f8b | 1684 | || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
1685 | && (mips_optimize == 0 |
1686 | || (pinfo & INSN_WRITE_HI))) | |
1687 | nops += 2; | |
1688 | /* Most mips16 branch insns don't have a delay slot. | |
1689 | If a read from HI is immediately followed by a branch | |
1690 | to a write to HI we have a read followed by a write | |
1691 | less than 2 insns away. We assume the target of | |
1692 | a branch might be a write to HI, and insert a nop | |
bdaaa2e1 | 1693 | between a read and an immediately following branch. */ |
252b5132 RH |
1694 | else if (mips_opts.mips16 |
1695 | && (mips_optimize == 0 | |
1696 | || (pinfo & MIPS16_INSN_BRANCH))) | |
1697 | nops += 1; | |
1698 | } | |
1699 | ||
1700 | /* If the previous instruction was in a noreorder section, then | |
1701 | we don't want to insert the nop after all. */ | |
bdaaa2e1 | 1702 | /* Itbl support may require additional care here. */ |
252b5132 RH |
1703 | if (prev_insn_unreordered) |
1704 | nops = 0; | |
1705 | ||
1706 | /* There are two cases which require two intervening | |
1707 | instructions: 1) setting the condition codes using a move to | |
1708 | coprocessor instruction which requires a general coprocessor | |
1709 | delay and then reading the condition codes 2) reading the HI | |
1710 | or LO register and then writing to it (except on processors | |
1711 | which have interlocks). If we are not already emitting a NOP | |
1712 | instruction, we must check for these cases compared to the | |
1713 | instruction previous to the previous instruction. */ | |
1714 | if ((! mips_opts.mips16 | |
9ce8a5dd | 1715 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
1716 | && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY) |
1717 | && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE) | |
1718 | && (pinfo & INSN_READ_COND_CODE) | |
1719 | && ! cop_interlocks) | |
1720 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO) | |
1721 | && (pinfo & INSN_WRITE_LO) | |
1722 | && ! (hilo_interlocks | |
156c2f8b | 1723 | || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT)))) |
252b5132 RH |
1724 | || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) |
1725 | && (pinfo & INSN_WRITE_HI) | |
1726 | && ! (hilo_interlocks | |
156c2f8b | 1727 | || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT))))) |
252b5132 RH |
1728 | prev_prev_nop = 1; |
1729 | else | |
1730 | prev_prev_nop = 0; | |
1731 | ||
1732 | if (prev_prev_insn_unreordered) | |
1733 | prev_prev_nop = 0; | |
1734 | ||
1735 | if (prev_prev_nop && nops == 0) | |
1736 | ++nops; | |
1737 | ||
1738 | /* If we are being given a nop instruction, don't bother with | |
1739 | one of the nops we would otherwise output. This will only | |
1740 | happen when a nop instruction is used with mips_optimize set | |
1741 | to 0. */ | |
1742 | if (nops > 0 | |
1743 | && ! mips_opts.noreorder | |
156c2f8b | 1744 | && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0)) |
252b5132 RH |
1745 | --nops; |
1746 | ||
1747 | /* Now emit the right number of NOP instructions. */ | |
1748 | if (nops > 0 && ! mips_opts.noreorder) | |
1749 | { | |
1750 | fragS *old_frag; | |
1751 | unsigned long old_frag_offset; | |
1752 | int i; | |
1753 | struct insn_label_list *l; | |
1754 | ||
1755 | old_frag = frag_now; | |
1756 | old_frag_offset = frag_now_fix (); | |
1757 | ||
1758 | for (i = 0; i < nops; i++) | |
1759 | emit_nop (); | |
1760 | ||
1761 | if (listing) | |
1762 | { | |
1763 | listing_prev_line (); | |
1764 | /* We may be at the start of a variant frag. In case we | |
1765 | are, make sure there is enough space for the frag | |
1766 | after the frags created by listing_prev_line. The | |
1767 | argument to frag_grow here must be at least as large | |
1768 | as the argument to all other calls to frag_grow in | |
1769 | this file. We don't have to worry about being in the | |
1770 | middle of a variant frag, because the variants insert | |
1771 | all needed nop instructions themselves. */ | |
1772 | frag_grow (40); | |
1773 | } | |
1774 | ||
1775 | for (l = insn_labels; l != NULL; l = l->next) | |
1776 | { | |
1777 | assert (S_GET_SEGMENT (l->label) == now_seg); | |
49309057 | 1778 | symbol_set_frag (l->label, frag_now); |
252b5132 RH |
1779 | S_SET_VALUE (l->label, (valueT) frag_now_fix ()); |
1780 | /* mips16 text labels are stored as odd. */ | |
1781 | if (mips_opts.mips16) | |
49309057 | 1782 | S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1); |
252b5132 RH |
1783 | } |
1784 | ||
1785 | #ifndef NO_ECOFF_DEBUGGING | |
1786 | if (ECOFF_DEBUGGING) | |
1787 | ecoff_fix_loc (old_frag, old_frag_offset); | |
1788 | #endif | |
1789 | } | |
1790 | else if (prev_nop_frag != NULL) | |
1791 | { | |
1792 | /* We have a frag holding nops we may be able to remove. If | |
1793 | we don't need any nops, we can decrease the size of | |
1794 | prev_nop_frag by the size of one instruction. If we do | |
bdaaa2e1 | 1795 | need some nops, we count them in prev_nops_required. */ |
252b5132 RH |
1796 | if (prev_nop_frag_since == 0) |
1797 | { | |
1798 | if (nops == 0) | |
1799 | { | |
1800 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1801 | --prev_nop_frag_holds; | |
1802 | } | |
1803 | else | |
1804 | prev_nop_frag_required += nops; | |
1805 | } | |
1806 | else | |
1807 | { | |
1808 | if (prev_prev_nop == 0) | |
1809 | { | |
1810 | prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4; | |
1811 | --prev_nop_frag_holds; | |
1812 | } | |
1813 | else | |
1814 | ++prev_nop_frag_required; | |
1815 | } | |
1816 | ||
1817 | if (prev_nop_frag_holds <= prev_nop_frag_required) | |
1818 | prev_nop_frag = NULL; | |
1819 | ||
1820 | ++prev_nop_frag_since; | |
1821 | ||
1822 | /* Sanity check: by the time we reach the second instruction | |
1823 | after prev_nop_frag, we should have used up all the nops | |
1824 | one way or another. */ | |
1825 | assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL); | |
1826 | } | |
1827 | } | |
1828 | ||
1829 | if (reloc_type > BFD_RELOC_UNUSED) | |
1830 | { | |
1831 | /* We need to set up a variant frag. */ | |
1832 | assert (mips_opts.mips16 && address_expr != NULL); | |
1833 | f = frag_var (rs_machine_dependent, 4, 0, | |
1834 | RELAX_MIPS16_ENCODE (reloc_type - BFD_RELOC_UNUSED, | |
1835 | mips16_small, mips16_ext, | |
1836 | (prev_pinfo | |
1837 | & INSN_UNCOND_BRANCH_DELAY), | |
1838 | (prev_insn_reloc_type | |
1839 | == BFD_RELOC_MIPS16_JMP)), | |
1840 | make_expr_symbol (address_expr), (offsetT) 0, | |
1841 | (char *) NULL); | |
1842 | } | |
1843 | else if (place != NULL) | |
1844 | f = place; | |
1845 | else if (mips_opts.mips16 | |
1846 | && ! ip->use_extend | |
1847 | && reloc_type != BFD_RELOC_MIPS16_JMP) | |
1848 | { | |
1849 | /* Make sure there is enough room to swap this instruction with | |
1850 | a following jump instruction. */ | |
1851 | frag_grow (6); | |
1852 | f = frag_more (2); | |
1853 | } | |
1854 | else | |
1855 | { | |
1856 | if (mips_opts.mips16 | |
1857 | && mips_opts.noreorder | |
1858 | && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0) | |
1859 | as_warn (_("extended instruction in delay slot")); | |
1860 | ||
1861 | f = frag_more (4); | |
1862 | } | |
1863 | ||
1864 | fixp = NULL; | |
1865 | if (address_expr != NULL && reloc_type < BFD_RELOC_UNUSED) | |
1866 | { | |
1867 | if (address_expr->X_op == O_constant) | |
1868 | { | |
1869 | switch (reloc_type) | |
1870 | { | |
1871 | case BFD_RELOC_32: | |
1872 | ip->insn_opcode |= address_expr->X_add_number; | |
1873 | break; | |
1874 | ||
1875 | case BFD_RELOC_LO16: | |
1876 | ip->insn_opcode |= address_expr->X_add_number & 0xffff; | |
1877 | break; | |
1878 | ||
1879 | case BFD_RELOC_MIPS_JMP: | |
1880 | if ((address_expr->X_add_number & 3) != 0) | |
1881 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1882 | (unsigned long) address_expr->X_add_number); | |
1883 | ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff; | |
1884 | break; | |
1885 | ||
1886 | case BFD_RELOC_MIPS16_JMP: | |
1887 | if ((address_expr->X_add_number & 3) != 0) | |
1888 | as_bad (_("jump to misaligned address (0x%lx)"), | |
1889 | (unsigned long) address_expr->X_add_number); | |
1890 | ip->insn_opcode |= | |
1891 | (((address_expr->X_add_number & 0x7c0000) << 3) | |
1892 | | ((address_expr->X_add_number & 0xf800000) >> 7) | |
1893 | | ((address_expr->X_add_number & 0x3fffc) >> 2)); | |
1894 | break; | |
1895 | ||
252b5132 RH |
1896 | case BFD_RELOC_16_PCREL_S2: |
1897 | goto need_reloc; | |
1898 | ||
1899 | default: | |
1900 | internalError (); | |
1901 | } | |
1902 | } | |
1903 | else | |
1904 | { | |
1905 | need_reloc: | |
1906 | /* Don't generate a reloc if we are writing into a variant | |
1907 | frag. */ | |
1908 | if (place == NULL) | |
1909 | { | |
1910 | fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4, | |
1911 | address_expr, | |
1912 | reloc_type == BFD_RELOC_16_PCREL_S2, | |
1913 | reloc_type); | |
1914 | if (unmatched_hi) | |
1915 | { | |
1916 | struct mips_hi_fixup *hi_fixup; | |
1917 | ||
1918 | assert (reloc_type == BFD_RELOC_HI16_S); | |
1919 | hi_fixup = ((struct mips_hi_fixup *) | |
1920 | xmalloc (sizeof (struct mips_hi_fixup))); | |
1921 | hi_fixup->fixp = fixp; | |
1922 | hi_fixup->seg = now_seg; | |
1923 | hi_fixup->next = mips_hi_fixup_list; | |
1924 | mips_hi_fixup_list = hi_fixup; | |
1925 | } | |
1926 | } | |
1927 | } | |
1928 | } | |
1929 | ||
1930 | if (! mips_opts.mips16) | |
1931 | md_number_to_chars (f, ip->insn_opcode, 4); | |
1932 | else if (reloc_type == BFD_RELOC_MIPS16_JMP) | |
1933 | { | |
1934 | md_number_to_chars (f, ip->insn_opcode >> 16, 2); | |
1935 | md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2); | |
1936 | } | |
1937 | else | |
1938 | { | |
1939 | if (ip->use_extend) | |
1940 | { | |
1941 | md_number_to_chars (f, 0xf000 | ip->extend, 2); | |
1942 | f += 2; | |
1943 | } | |
1944 | md_number_to_chars (f, ip->insn_opcode, 2); | |
1945 | } | |
1946 | ||
1947 | /* Update the register mask information. */ | |
1948 | if (! mips_opts.mips16) | |
1949 | { | |
1950 | if (pinfo & INSN_WRITE_GPR_D) | |
1951 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD); | |
1952 | if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0) | |
1953 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT); | |
1954 | if (pinfo & INSN_READ_GPR_S) | |
1955 | mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS); | |
1956 | if (pinfo & INSN_WRITE_GPR_31) | |
1957 | mips_gprmask |= 1 << 31; | |
1958 | if (pinfo & INSN_WRITE_FPR_D) | |
1959 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD); | |
1960 | if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0) | |
1961 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS); | |
1962 | if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0) | |
1963 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT); | |
1964 | if ((pinfo & INSN_READ_FPR_R) != 0) | |
1965 | mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR); | |
1966 | if (pinfo & INSN_COP) | |
1967 | { | |
bdaaa2e1 KH |
1968 | /* We don't keep enough information to sort these cases out. |
1969 | The itbl support does keep this information however, although | |
1970 | we currently don't support itbl fprmats as part of the cop | |
1971 | instruction. May want to add this support in the future. */ | |
252b5132 RH |
1972 | } |
1973 | /* Never set the bit for $0, which is always zero. */ | |
1974 | mips_gprmask &=~ 1 << 0; | |
1975 | } | |
1976 | else | |
1977 | { | |
1978 | if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X)) | |
1979 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX) | |
1980 | & MIPS16OP_MASK_RX); | |
1981 | if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y)) | |
1982 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY) | |
1983 | & MIPS16OP_MASK_RY); | |
1984 | if (pinfo & MIPS16_INSN_WRITE_Z) | |
1985 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ) | |
1986 | & MIPS16OP_MASK_RZ); | |
1987 | if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T)) | |
1988 | mips_gprmask |= 1 << TREG; | |
1989 | if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP)) | |
1990 | mips_gprmask |= 1 << SP; | |
1991 | if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31)) | |
1992 | mips_gprmask |= 1 << RA; | |
1993 | if (pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
1994 | mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode); | |
1995 | if (pinfo & MIPS16_INSN_READ_Z) | |
1996 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z) | |
1997 | & MIPS16OP_MASK_MOVE32Z); | |
1998 | if (pinfo & MIPS16_INSN_READ_GPR_X) | |
1999 | mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32) | |
2000 | & MIPS16OP_MASK_REGR32); | |
2001 | } | |
2002 | ||
2003 | if (place == NULL && ! mips_opts.noreorder) | |
2004 | { | |
2005 | /* Filling the branch delay slot is more complex. We try to | |
2006 | switch the branch with the previous instruction, which we can | |
2007 | do if the previous instruction does not set up a condition | |
2008 | that the branch tests and if the branch is not itself the | |
2009 | target of any branch. */ | |
2010 | if ((pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2011 | || (pinfo & INSN_COND_BRANCH_DELAY)) | |
2012 | { | |
2013 | if (mips_optimize < 2 | |
2014 | /* If we have seen .set volatile or .set nomove, don't | |
2015 | optimize. */ | |
2016 | || mips_opts.nomove != 0 | |
2017 | /* If we had to emit any NOP instructions, then we | |
2018 | already know we can not swap. */ | |
2019 | || nops != 0 | |
2020 | /* If we don't even know the previous insn, we can not | |
bdaaa2e1 | 2021 | swap. */ |
252b5132 RH |
2022 | || ! prev_insn_valid |
2023 | /* If the previous insn is already in a branch delay | |
2024 | slot, then we can not swap. */ | |
2025 | || prev_insn_is_delay_slot | |
2026 | /* If the previous previous insn was in a .set | |
2027 | noreorder, we can't swap. Actually, the MIPS | |
2028 | assembler will swap in this situation. However, gcc | |
2029 | configured -with-gnu-as will generate code like | |
2030 | .set noreorder | |
2031 | lw $4,XXX | |
2032 | .set reorder | |
2033 | INSN | |
2034 | bne $4,$0,foo | |
2035 | in which we can not swap the bne and INSN. If gcc is | |
2036 | not configured -with-gnu-as, it does not output the | |
2037 | .set pseudo-ops. We don't have to check | |
2038 | prev_insn_unreordered, because prev_insn_valid will | |
2039 | be 0 in that case. We don't want to use | |
2040 | prev_prev_insn_valid, because we do want to be able | |
2041 | to swap at the start of a function. */ | |
2042 | || prev_prev_insn_unreordered | |
2043 | /* If the branch is itself the target of a branch, we | |
2044 | can not swap. We cheat on this; all we check for is | |
2045 | whether there is a label on this instruction. If | |
2046 | there are any branches to anything other than a | |
2047 | label, users must use .set noreorder. */ | |
2048 | || insn_labels != NULL | |
2049 | /* If the previous instruction is in a variant frag, we | |
2050 | can not do the swap. This does not apply to the | |
2051 | mips16, which uses variant frags for different | |
2052 | purposes. */ | |
2053 | || (! mips_opts.mips16 | |
2054 | && prev_insn_frag->fr_type == rs_machine_dependent) | |
2055 | /* If the branch reads the condition codes, we don't | |
2056 | even try to swap, because in the sequence | |
2057 | ctc1 $X,$31 | |
2058 | INSN | |
2059 | INSN | |
2060 | bc1t LABEL | |
2061 | we can not swap, and I don't feel like handling that | |
2062 | case. */ | |
2063 | || (! mips_opts.mips16 | |
9ce8a5dd | 2064 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2065 | && (pinfo & INSN_READ_COND_CODE)) |
2066 | /* We can not swap with an instruction that requires a | |
2067 | delay slot, becase the target of the branch might | |
2068 | interfere with that instruction. */ | |
2069 | || (! mips_opts.mips16 | |
9ce8a5dd | 2070 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 | 2071 | && (prev_pinfo |
bdaaa2e1 | 2072 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2073 | & (INSN_LOAD_COPROC_DELAY |
2074 | | INSN_COPROC_MOVE_DELAY | |
2075 | | INSN_WRITE_COND_CODE))) | |
2076 | || (! (hilo_interlocks | |
156c2f8b | 2077 | || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT))) |
252b5132 RH |
2078 | && (prev_pinfo |
2079 | & (INSN_READ_LO | |
2080 | | INSN_READ_HI))) | |
2081 | || (! mips_opts.mips16 | |
2082 | && ! gpr_interlocks | |
2083 | && (prev_pinfo & INSN_LOAD_MEMORY_DELAY)) | |
2084 | || (! mips_opts.mips16 | |
9ce8a5dd | 2085 | && mips_opts.isa == 1 |
bdaaa2e1 | 2086 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2087 | && (prev_pinfo & INSN_COPROC_MEMORY_DELAY)) |
2088 | /* We can not swap with a branch instruction. */ | |
2089 | || (prev_pinfo | |
2090 | & (INSN_UNCOND_BRANCH_DELAY | |
2091 | | INSN_COND_BRANCH_DELAY | |
2092 | | INSN_COND_BRANCH_LIKELY)) | |
2093 | /* We do not swap with a trap instruction, since it | |
2094 | complicates trap handlers to have the trap | |
2095 | instruction be in a delay slot. */ | |
2096 | || (prev_pinfo & INSN_TRAP) | |
2097 | /* If the branch reads a register that the previous | |
2098 | instruction sets, we can not swap. */ | |
2099 | || (! mips_opts.mips16 | |
2100 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2101 | && insn_uses_reg (ip, | |
2102 | ((prev_insn.insn_opcode >> OP_SH_RT) | |
2103 | & OP_MASK_RT), | |
2104 | MIPS_GR_REG)) | |
2105 | || (! mips_opts.mips16 | |
2106 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2107 | && insn_uses_reg (ip, | |
2108 | ((prev_insn.insn_opcode >> OP_SH_RD) | |
2109 | & OP_MASK_RD), | |
2110 | MIPS_GR_REG)) | |
2111 | || (mips_opts.mips16 | |
2112 | && (((prev_pinfo & MIPS16_INSN_WRITE_X) | |
2113 | && insn_uses_reg (ip, | |
2114 | ((prev_insn.insn_opcode | |
2115 | >> MIPS16OP_SH_RX) | |
2116 | & MIPS16OP_MASK_RX), | |
2117 | MIPS16_REG)) | |
2118 | || ((prev_pinfo & MIPS16_INSN_WRITE_Y) | |
2119 | && insn_uses_reg (ip, | |
2120 | ((prev_insn.insn_opcode | |
2121 | >> MIPS16OP_SH_RY) | |
2122 | & MIPS16OP_MASK_RY), | |
2123 | MIPS16_REG)) | |
2124 | || ((prev_pinfo & MIPS16_INSN_WRITE_Z) | |
2125 | && insn_uses_reg (ip, | |
2126 | ((prev_insn.insn_opcode | |
2127 | >> MIPS16OP_SH_RZ) | |
2128 | & MIPS16OP_MASK_RZ), | |
2129 | MIPS16_REG)) | |
2130 | || ((prev_pinfo & MIPS16_INSN_WRITE_T) | |
2131 | && insn_uses_reg (ip, TREG, MIPS_GR_REG)) | |
2132 | || ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2133 | && insn_uses_reg (ip, RA, MIPS_GR_REG)) | |
2134 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2135 | && insn_uses_reg (ip, | |
2136 | MIPS16OP_EXTRACT_REG32R (prev_insn. | |
2137 | insn_opcode), | |
2138 | MIPS_GR_REG)))) | |
2139 | /* If the branch writes a register that the previous | |
2140 | instruction sets, we can not swap (we know that | |
2141 | branches write only to RD or to $31). */ | |
2142 | || (! mips_opts.mips16 | |
2143 | && (prev_pinfo & INSN_WRITE_GPR_T) | |
2144 | && (((pinfo & INSN_WRITE_GPR_D) | |
2145 | && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT) | |
2146 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2147 | || ((pinfo & INSN_WRITE_GPR_31) | |
2148 | && (((prev_insn.insn_opcode >> OP_SH_RT) | |
2149 | & OP_MASK_RT) | |
2150 | == 31)))) | |
2151 | || (! mips_opts.mips16 | |
2152 | && (prev_pinfo & INSN_WRITE_GPR_D) | |
2153 | && (((pinfo & INSN_WRITE_GPR_D) | |
2154 | && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD) | |
2155 | == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD))) | |
2156 | || ((pinfo & INSN_WRITE_GPR_31) | |
2157 | && (((prev_insn.insn_opcode >> OP_SH_RD) | |
2158 | & OP_MASK_RD) | |
2159 | == 31)))) | |
2160 | || (mips_opts.mips16 | |
2161 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2162 | && ((prev_pinfo & MIPS16_INSN_WRITE_31) | |
2163 | || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y) | |
2164 | && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode) | |
2165 | == RA)))) | |
2166 | /* If the branch writes a register that the previous | |
2167 | instruction reads, we can not swap (we know that | |
2168 | branches only write to RD or to $31). */ | |
2169 | || (! mips_opts.mips16 | |
2170 | && (pinfo & INSN_WRITE_GPR_D) | |
2171 | && insn_uses_reg (&prev_insn, | |
2172 | ((ip->insn_opcode >> OP_SH_RD) | |
2173 | & OP_MASK_RD), | |
2174 | MIPS_GR_REG)) | |
2175 | || (! mips_opts.mips16 | |
2176 | && (pinfo & INSN_WRITE_GPR_31) | |
2177 | && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG)) | |
2178 | || (mips_opts.mips16 | |
2179 | && (pinfo & MIPS16_INSN_WRITE_31) | |
2180 | && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG)) | |
2181 | /* If we are generating embedded PIC code, the branch | |
2182 | might be expanded into a sequence which uses $at, so | |
2183 | we can't swap with an instruction which reads it. */ | |
2184 | || (mips_pic == EMBEDDED_PIC | |
2185 | && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG)) | |
2186 | /* If the previous previous instruction has a load | |
2187 | delay, and sets a register that the branch reads, we | |
2188 | can not swap. */ | |
2189 | || (! mips_opts.mips16 | |
9ce8a5dd | 2190 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
bdaaa2e1 | 2191 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2192 | && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY) |
2193 | || (! gpr_interlocks | |
2194 | && (prev_prev_insn.insn_mo->pinfo | |
2195 | & INSN_LOAD_MEMORY_DELAY))) | |
2196 | && insn_uses_reg (ip, | |
2197 | ((prev_prev_insn.insn_opcode >> OP_SH_RT) | |
2198 | & OP_MASK_RT), | |
2199 | MIPS_GR_REG)) | |
2200 | /* If one instruction sets a condition code and the | |
2201 | other one uses a condition code, we can not swap. */ | |
2202 | || ((pinfo & INSN_READ_COND_CODE) | |
2203 | && (prev_pinfo & INSN_WRITE_COND_CODE)) | |
2204 | || ((pinfo & INSN_WRITE_COND_CODE) | |
2205 | && (prev_pinfo & INSN_READ_COND_CODE)) | |
2206 | /* If the previous instruction uses the PC, we can not | |
2207 | swap. */ | |
2208 | || (mips_opts.mips16 | |
2209 | && (prev_pinfo & MIPS16_INSN_READ_PC)) | |
2210 | /* If the previous instruction was extended, we can not | |
2211 | swap. */ | |
2212 | || (mips_opts.mips16 && prev_insn_extended) | |
2213 | /* If the previous instruction had a fixup in mips16 | |
2214 | mode, we can not swap. This normally means that the | |
2215 | previous instruction was a 4 byte branch anyhow. */ | |
2216 | || (mips_opts.mips16 && prev_insn_fixp) | |
bdaaa2e1 KH |
2217 | /* If the previous instruction is a sync, sync.l, or |
2218 | sync.p, we can not swap. */ | |
f173e82e | 2219 | || (prev_pinfo & INSN_SYNC)) |
252b5132 RH |
2220 | { |
2221 | /* We could do even better for unconditional branches to | |
2222 | portions of this object file; we could pick up the | |
2223 | instruction at the destination, put it in the delay | |
2224 | slot, and bump the destination address. */ | |
2225 | emit_nop (); | |
2226 | /* Update the previous insn information. */ | |
2227 | prev_prev_insn = *ip; | |
2228 | prev_insn.insn_mo = &dummy_opcode; | |
2229 | } | |
2230 | else | |
2231 | { | |
2232 | /* It looks like we can actually do the swap. */ | |
2233 | if (! mips_opts.mips16) | |
2234 | { | |
2235 | char *prev_f; | |
2236 | char temp[4]; | |
2237 | ||
2238 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2239 | memcpy (temp, prev_f, 4); | |
2240 | memcpy (prev_f, f, 4); | |
2241 | memcpy (f, temp, 4); | |
2242 | if (prev_insn_fixp) | |
2243 | { | |
2244 | prev_insn_fixp->fx_frag = frag_now; | |
2245 | prev_insn_fixp->fx_where = f - frag_now->fr_literal; | |
2246 | } | |
2247 | if (fixp) | |
2248 | { | |
2249 | fixp->fx_frag = prev_insn_frag; | |
2250 | fixp->fx_where = prev_insn_where; | |
2251 | } | |
2252 | } | |
2253 | else | |
2254 | { | |
2255 | char *prev_f; | |
2256 | char temp[2]; | |
2257 | ||
2258 | assert (prev_insn_fixp == NULL); | |
2259 | prev_f = prev_insn_frag->fr_literal + prev_insn_where; | |
2260 | memcpy (temp, prev_f, 2); | |
2261 | memcpy (prev_f, f, 2); | |
2262 | if (reloc_type != BFD_RELOC_MIPS16_JMP) | |
2263 | { | |
2264 | assert (reloc_type == BFD_RELOC_UNUSED); | |
2265 | memcpy (f, temp, 2); | |
2266 | } | |
2267 | else | |
2268 | { | |
2269 | memcpy (f, f + 2, 2); | |
2270 | memcpy (f + 2, temp, 2); | |
2271 | } | |
2272 | if (fixp) | |
2273 | { | |
2274 | fixp->fx_frag = prev_insn_frag; | |
2275 | fixp->fx_where = prev_insn_where; | |
2276 | } | |
2277 | } | |
2278 | ||
2279 | /* Update the previous insn information; leave prev_insn | |
2280 | unchanged. */ | |
2281 | prev_prev_insn = *ip; | |
2282 | } | |
2283 | prev_insn_is_delay_slot = 1; | |
2284 | ||
2285 | /* If that was an unconditional branch, forget the previous | |
2286 | insn information. */ | |
2287 | if (pinfo & INSN_UNCOND_BRANCH_DELAY) | |
2288 | { | |
2289 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2290 | prev_insn.insn_mo = &dummy_opcode; | |
2291 | } | |
2292 | ||
2293 | prev_insn_fixp = NULL; | |
2294 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2295 | prev_insn_extended = 0; | |
2296 | } | |
2297 | else if (pinfo & INSN_COND_BRANCH_LIKELY) | |
2298 | { | |
2299 | /* We don't yet optimize a branch likely. What we should do | |
2300 | is look at the target, copy the instruction found there | |
2301 | into the delay slot, and increment the branch to jump to | |
2302 | the next instruction. */ | |
2303 | emit_nop (); | |
2304 | /* Update the previous insn information. */ | |
2305 | prev_prev_insn = *ip; | |
2306 | prev_insn.insn_mo = &dummy_opcode; | |
2307 | prev_insn_fixp = NULL; | |
2308 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2309 | prev_insn_extended = 0; | |
2310 | } | |
2311 | else | |
2312 | { | |
2313 | /* Update the previous insn information. */ | |
2314 | if (nops > 0) | |
2315 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2316 | else | |
2317 | prev_prev_insn = prev_insn; | |
2318 | prev_insn = *ip; | |
2319 | ||
2320 | /* Any time we see a branch, we always fill the delay slot | |
2321 | immediately; since this insn is not a branch, we know it | |
2322 | is not in a delay slot. */ | |
2323 | prev_insn_is_delay_slot = 0; | |
2324 | ||
2325 | prev_insn_fixp = fixp; | |
2326 | prev_insn_reloc_type = reloc_type; | |
2327 | if (mips_opts.mips16) | |
2328 | prev_insn_extended = (ip->use_extend | |
2329 | || reloc_type > BFD_RELOC_UNUSED); | |
2330 | } | |
2331 | ||
2332 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2333 | prev_insn_unreordered = 0; | |
2334 | prev_insn_frag = frag_now; | |
2335 | prev_insn_where = f - frag_now->fr_literal; | |
2336 | prev_insn_valid = 1; | |
2337 | } | |
2338 | else if (place == NULL) | |
2339 | { | |
2340 | /* We need to record a bit of information even when we are not | |
2341 | reordering, in order to determine the base address for mips16 | |
2342 | PC relative relocs. */ | |
2343 | prev_prev_insn = prev_insn; | |
2344 | prev_insn = *ip; | |
2345 | prev_insn_reloc_type = reloc_type; | |
2346 | prev_prev_insn_unreordered = prev_insn_unreordered; | |
2347 | prev_insn_unreordered = 1; | |
2348 | } | |
2349 | ||
2350 | /* We just output an insn, so the next one doesn't have a label. */ | |
2351 | mips_clear_insn_labels (); | |
2352 | ||
2353 | /* We must ensure that a fixup associated with an unmatched %hi | |
2354 | reloc does not become a variant frag. Otherwise, the | |
2355 | rearrangement of %hi relocs in frob_file may confuse | |
2356 | tc_gen_reloc. */ | |
2357 | if (unmatched_hi) | |
2358 | { | |
2359 | frag_wane (frag_now); | |
2360 | frag_new (0); | |
2361 | } | |
2362 | } | |
2363 | ||
2364 | /* This function forgets that there was any previous instruction or | |
2365 | label. If PRESERVE is non-zero, it remembers enough information to | |
bdaaa2e1 | 2366 | know whether nops are needed before a noreorder section. */ |
252b5132 RH |
2367 | |
2368 | static void | |
2369 | mips_no_prev_insn (preserve) | |
2370 | int preserve; | |
2371 | { | |
2372 | if (! preserve) | |
2373 | { | |
2374 | prev_insn.insn_mo = &dummy_opcode; | |
2375 | prev_prev_insn.insn_mo = &dummy_opcode; | |
2376 | prev_nop_frag = NULL; | |
2377 | prev_nop_frag_holds = 0; | |
2378 | prev_nop_frag_required = 0; | |
2379 | prev_nop_frag_since = 0; | |
2380 | } | |
2381 | prev_insn_valid = 0; | |
2382 | prev_insn_is_delay_slot = 0; | |
2383 | prev_insn_unreordered = 0; | |
2384 | prev_insn_extended = 0; | |
2385 | prev_insn_reloc_type = BFD_RELOC_UNUSED; | |
2386 | prev_prev_insn_unreordered = 0; | |
2387 | mips_clear_insn_labels (); | |
2388 | } | |
2389 | ||
2390 | /* This function must be called whenever we turn on noreorder or emit | |
2391 | something other than instructions. It inserts any NOPS which might | |
2392 | be needed by the previous instruction, and clears the information | |
2393 | kept for the previous instructions. The INSNS parameter is true if | |
bdaaa2e1 | 2394 | instructions are to follow. */ |
252b5132 RH |
2395 | |
2396 | static void | |
2397 | mips_emit_delays (insns) | |
2398 | boolean insns; | |
2399 | { | |
2400 | if (! mips_opts.noreorder) | |
2401 | { | |
2402 | int nops; | |
2403 | ||
2404 | nops = 0; | |
2405 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2406 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2407 | && (! cop_interlocks |
2408 | && (prev_insn.insn_mo->pinfo | |
2409 | & (INSN_LOAD_COPROC_DELAY | |
2410 | | INSN_COPROC_MOVE_DELAY | |
2411 | | INSN_WRITE_COND_CODE)))) | |
2412 | || (! hilo_interlocks | |
2413 | && (prev_insn.insn_mo->pinfo | |
2414 | & (INSN_READ_LO | |
2415 | | INSN_READ_HI))) | |
2416 | || (! mips_opts.mips16 | |
2417 | && ! gpr_interlocks | |
bdaaa2e1 | 2418 | && (prev_insn.insn_mo->pinfo |
252b5132 RH |
2419 | & INSN_LOAD_MEMORY_DELAY)) |
2420 | || (! mips_opts.mips16 | |
9ce8a5dd | 2421 | && mips_opts.isa == 1 |
252b5132 RH |
2422 | && (prev_insn.insn_mo->pinfo |
2423 | & INSN_COPROC_MEMORY_DELAY))) | |
2424 | { | |
bdaaa2e1 | 2425 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2426 | ++nops; |
2427 | if ((! mips_opts.mips16 | |
9ce8a5dd | 2428 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2429 | && (! cop_interlocks |
2430 | && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2431 | || (! hilo_interlocks | |
2432 | && ((prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2433 | || (prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2434 | ++nops; | |
2435 | ||
2436 | if (prev_insn_unreordered) | |
2437 | nops = 0; | |
2438 | } | |
2439 | else if ((! mips_opts.mips16 | |
9ce8a5dd | 2440 | && ISA_HAS_COPROC_DELAYS (mips_opts.isa) |
252b5132 RH |
2441 | && (! cop_interlocks |
2442 | && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)) | |
2443 | || (! hilo_interlocks | |
2444 | && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI) | |
2445 | || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)))) | |
2446 | { | |
bdaaa2e1 | 2447 | /* Itbl support may require additional care here. */ |
252b5132 RH |
2448 | if (! prev_prev_insn_unreordered) |
2449 | ++nops; | |
2450 | } | |
2451 | ||
2452 | if (nops > 0) | |
2453 | { | |
2454 | struct insn_label_list *l; | |
2455 | ||
2456 | if (insns) | |
2457 | { | |
2458 | /* Record the frag which holds the nop instructions, so | |
2459 | that we can remove them if we don't need them. */ | |
2460 | frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4); | |
2461 | prev_nop_frag = frag_now; | |
2462 | prev_nop_frag_holds = nops; | |
2463 | prev_nop_frag_required = 0; | |
2464 | prev_nop_frag_since = 0; | |
2465 | } | |
2466 | ||
2467 | for (; nops > 0; --nops) | |
2468 | emit_nop (); | |
2469 | ||
2470 | if (insns) | |
2471 | { | |
2472 | /* Move on to a new frag, so that it is safe to simply | |
bdaaa2e1 | 2473 | decrease the size of prev_nop_frag. */ |
252b5132 RH |
2474 | frag_wane (frag_now); |
2475 | frag_new (0); | |
2476 | } | |
2477 | ||
2478 | for (l = insn_labels; l != NULL; l = l->next) | |
2479 | { | |
2480 | assert (S_GET_SEGMENT (l->label) == now_seg); | |
49309057 | 2481 | symbol_set_frag (l->label, frag_now); |
252b5132 RH |
2482 | S_SET_VALUE (l->label, (valueT) frag_now_fix ()); |
2483 | /* mips16 text labels are stored as odd. */ | |
2484 | if (mips_opts.mips16) | |
49309057 | 2485 | S_SET_VALUE (l->label, S_GET_VALUE (l->label) + 1); |
252b5132 RH |
2486 | } |
2487 | } | |
2488 | } | |
2489 | ||
2490 | /* Mark instruction labels in mips16 mode. */ | |
2491 | if (mips_opts.mips16 && insns) | |
2492 | mips16_mark_labels (); | |
2493 | ||
2494 | mips_no_prev_insn (insns); | |
2495 | } | |
2496 | ||
2497 | /* Build an instruction created by a macro expansion. This is passed | |
2498 | a pointer to the count of instructions created so far, an | |
2499 | expression, the name of the instruction to build, an operand format | |
2500 | string, and corresponding arguments. */ | |
2501 | ||
2502 | #ifdef USE_STDARG | |
2503 | static void | |
2504 | macro_build (char *place, | |
2505 | int *counter, | |
2506 | expressionS * ep, | |
2507 | const char *name, | |
2508 | const char *fmt, | |
2509 | ...) | |
2510 | #else | |
2511 | static void | |
2512 | macro_build (place, counter, ep, name, fmt, va_alist) | |
2513 | char *place; | |
2514 | int *counter; | |
2515 | expressionS *ep; | |
2516 | const char *name; | |
2517 | const char *fmt; | |
2518 | va_dcl | |
2519 | #endif | |
2520 | { | |
2521 | struct mips_cl_insn insn; | |
2522 | bfd_reloc_code_real_type r; | |
2523 | va_list args; | |
252b5132 RH |
2524 | |
2525 | #ifdef USE_STDARG | |
2526 | va_start (args, fmt); | |
2527 | #else | |
2528 | va_start (args); | |
2529 | #endif | |
2530 | ||
2531 | /* | |
2532 | * If the macro is about to expand into a second instruction, | |
2533 | * print a warning if needed. We need to pass ip as a parameter | |
2534 | * to generate a better warning message here... | |
2535 | */ | |
2536 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2537 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2538 | ||
2539 | if (place == NULL) | |
2540 | *counter += 1; /* bump instruction counter */ | |
2541 | ||
2542 | if (mips_opts.mips16) | |
2543 | { | |
2544 | mips16_macro_build (place, counter, ep, name, fmt, args); | |
2545 | va_end (args); | |
2546 | return; | |
2547 | } | |
2548 | ||
2549 | r = BFD_RELOC_UNUSED; | |
2550 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
2551 | assert (insn.insn_mo); | |
2552 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2553 | ||
2554 | /* Search until we get a match for NAME. */ | |
2555 | while (1) | |
2556 | { | |
252b5132 RH |
2557 | if (strcmp (fmt, insn.insn_mo->args) == 0 |
2558 | && insn.insn_mo->pinfo != INSN_MACRO | |
bdaaa2e1 | 2559 | && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_cpu, |
c97ef257 | 2560 | mips_gp32) |
156c2f8b | 2561 | && (mips_cpu != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0)) |
252b5132 RH |
2562 | break; |
2563 | ||
2564 | ++insn.insn_mo; | |
2565 | assert (insn.insn_mo->name); | |
2566 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2567 | } | |
2568 | ||
2569 | insn.insn_opcode = insn.insn_mo->match; | |
2570 | for (;;) | |
2571 | { | |
2572 | switch (*fmt++) | |
2573 | { | |
2574 | case '\0': | |
2575 | break; | |
2576 | ||
2577 | case ',': | |
2578 | case '(': | |
2579 | case ')': | |
2580 | continue; | |
2581 | ||
2582 | case 't': | |
2583 | case 'w': | |
2584 | case 'E': | |
2585 | insn.insn_opcode |= va_arg (args, int) << 16; | |
2586 | continue; | |
2587 | ||
2588 | case 'c': | |
2589 | case 'T': | |
2590 | case 'W': | |
2591 | insn.insn_opcode |= va_arg (args, int) << 16; | |
2592 | continue; | |
2593 | ||
2594 | case 'd': | |
2595 | case 'G': | |
2596 | insn.insn_opcode |= va_arg (args, int) << 11; | |
2597 | continue; | |
2598 | ||
2599 | case 'V': | |
2600 | case 'S': | |
2601 | insn.insn_opcode |= va_arg (args, int) << 11; | |
2602 | continue; | |
2603 | ||
2604 | case 'z': | |
2605 | continue; | |
2606 | ||
2607 | case '<': | |
2608 | insn.insn_opcode |= va_arg (args, int) << 6; | |
2609 | continue; | |
2610 | ||
2611 | case 'D': | |
2612 | insn.insn_opcode |= va_arg (args, int) << 6; | |
2613 | continue; | |
2614 | ||
2615 | case 'B': | |
2616 | insn.insn_opcode |= va_arg (args, int) << 6; | |
2617 | continue; | |
2618 | ||
2619 | case 'q': | |
2620 | insn.insn_opcode |= va_arg (args, int) << 6; | |
2621 | continue; | |
2622 | ||
2623 | case 'b': | |
2624 | case 's': | |
2625 | case 'r': | |
2626 | case 'v': | |
2627 | insn.insn_opcode |= va_arg (args, int) << 21; | |
2628 | continue; | |
2629 | ||
2630 | case 'i': | |
2631 | case 'j': | |
2632 | case 'o': | |
2633 | r = (bfd_reloc_code_real_type) va_arg (args, int); | |
2634 | assert (r == BFD_RELOC_MIPS_GPREL | |
2635 | || r == BFD_RELOC_MIPS_LITERAL | |
2636 | || r == BFD_RELOC_LO16 | |
2637 | || r == BFD_RELOC_MIPS_GOT16 | |
2638 | || r == BFD_RELOC_MIPS_CALL16 | |
2639 | || r == BFD_RELOC_MIPS_GOT_LO16 | |
2640 | || r == BFD_RELOC_MIPS_CALL_LO16 | |
2641 | || (ep->X_op == O_subtract | |
252b5132 RH |
2642 | && r == BFD_RELOC_PCREL_LO16)); |
2643 | continue; | |
2644 | ||
2645 | case 'u': | |
2646 | r = (bfd_reloc_code_real_type) va_arg (args, int); | |
2647 | assert (ep != NULL | |
2648 | && (ep->X_op == O_constant | |
2649 | || (ep->X_op == O_symbol | |
2650 | && (r == BFD_RELOC_HI16_S | |
2651 | || r == BFD_RELOC_HI16 | |
2652 | || r == BFD_RELOC_MIPS_GOT_HI16 | |
2653 | || r == BFD_RELOC_MIPS_CALL_HI16)) | |
2654 | || (ep->X_op == O_subtract | |
252b5132 RH |
2655 | && r == BFD_RELOC_PCREL_HI16_S))); |
2656 | if (ep->X_op == O_constant) | |
2657 | { | |
2658 | insn.insn_opcode |= (ep->X_add_number >> 16) & 0xffff; | |
2659 | ep = NULL; | |
2660 | r = BFD_RELOC_UNUSED; | |
2661 | } | |
2662 | continue; | |
2663 | ||
2664 | case 'p': | |
2665 | assert (ep != NULL); | |
2666 | /* | |
2667 | * This allows macro() to pass an immediate expression for | |
2668 | * creating short branches without creating a symbol. | |
2669 | * Note that the expression still might come from the assembly | |
2670 | * input, in which case the value is not checked for range nor | |
2671 | * is a relocation entry generated (yuck). | |
2672 | */ | |
2673 | if (ep->X_op == O_constant) | |
2674 | { | |
2675 | insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff; | |
2676 | ep = NULL; | |
2677 | } | |
2678 | else | |
2679 | r = BFD_RELOC_16_PCREL_S2; | |
2680 | continue; | |
2681 | ||
2682 | case 'a': | |
2683 | assert (ep != NULL); | |
2684 | r = BFD_RELOC_MIPS_JMP; | |
2685 | continue; | |
2686 | ||
2687 | case 'C': | |
2688 | insn.insn_opcode |= va_arg (args, unsigned long); | |
2689 | continue; | |
2690 | ||
2691 | default: | |
2692 | internalError (); | |
2693 | } | |
2694 | break; | |
2695 | } | |
2696 | va_end (args); | |
2697 | assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); | |
2698 | ||
2699 | append_insn (place, &insn, ep, r, false); | |
2700 | } | |
2701 | ||
2702 | static void | |
2703 | mips16_macro_build (place, counter, ep, name, fmt, args) | |
2704 | char *place; | |
43841e91 | 2705 | int *counter ATTRIBUTE_UNUSED; |
252b5132 RH |
2706 | expressionS *ep; |
2707 | const char *name; | |
2708 | const char *fmt; | |
2709 | va_list args; | |
2710 | { | |
2711 | struct mips_cl_insn insn; | |
2712 | bfd_reloc_code_real_type r; | |
2713 | ||
2714 | r = BFD_RELOC_UNUSED; | |
2715 | insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name); | |
2716 | assert (insn.insn_mo); | |
2717 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2718 | ||
2719 | while (strcmp (fmt, insn.insn_mo->args) != 0 | |
2720 | || insn.insn_mo->pinfo == INSN_MACRO) | |
2721 | { | |
2722 | ++insn.insn_mo; | |
2723 | assert (insn.insn_mo->name); | |
2724 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2725 | } | |
2726 | ||
2727 | insn.insn_opcode = insn.insn_mo->match; | |
2728 | insn.use_extend = false; | |
2729 | ||
2730 | for (;;) | |
2731 | { | |
2732 | int c; | |
2733 | ||
2734 | c = *fmt++; | |
2735 | switch (c) | |
2736 | { | |
2737 | case '\0': | |
2738 | break; | |
2739 | ||
2740 | case ',': | |
2741 | case '(': | |
2742 | case ')': | |
2743 | continue; | |
2744 | ||
2745 | case 'y': | |
2746 | case 'w': | |
2747 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY; | |
2748 | continue; | |
2749 | ||
2750 | case 'x': | |
2751 | case 'v': | |
2752 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX; | |
2753 | continue; | |
2754 | ||
2755 | case 'z': | |
2756 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ; | |
2757 | continue; | |
2758 | ||
2759 | case 'Z': | |
2760 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z; | |
2761 | continue; | |
2762 | ||
2763 | case '0': | |
2764 | case 'S': | |
2765 | case 'P': | |
2766 | case 'R': | |
2767 | continue; | |
2768 | ||
2769 | case 'X': | |
2770 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32; | |
2771 | continue; | |
2772 | ||
2773 | case 'Y': | |
2774 | { | |
2775 | int regno; | |
2776 | ||
2777 | regno = va_arg (args, int); | |
2778 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
2779 | insn.insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
2780 | } | |
2781 | continue; | |
2782 | ||
2783 | case '<': | |
2784 | case '>': | |
2785 | case '4': | |
2786 | case '5': | |
2787 | case 'H': | |
2788 | case 'W': | |
2789 | case 'D': | |
2790 | case 'j': | |
2791 | case '8': | |
2792 | case 'V': | |
2793 | case 'C': | |
2794 | case 'U': | |
2795 | case 'k': | |
2796 | case 'K': | |
2797 | case 'p': | |
2798 | case 'q': | |
2799 | { | |
2800 | assert (ep != NULL); | |
2801 | ||
2802 | if (ep->X_op != O_constant) | |
2803 | r = BFD_RELOC_UNUSED + c; | |
2804 | else | |
2805 | { | |
2806 | mips16_immed ((char *) NULL, 0, c, ep->X_add_number, false, | |
2807 | false, false, &insn.insn_opcode, | |
2808 | &insn.use_extend, &insn.extend); | |
2809 | ep = NULL; | |
2810 | r = BFD_RELOC_UNUSED; | |
2811 | } | |
2812 | } | |
2813 | continue; | |
2814 | ||
2815 | case '6': | |
2816 | insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6; | |
2817 | continue; | |
2818 | } | |
2819 | ||
2820 | break; | |
2821 | } | |
2822 | ||
2823 | assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); | |
2824 | ||
2825 | append_insn (place, &insn, ep, r, false); | |
2826 | } | |
2827 | ||
2828 | /* | |
2829 | * Generate a "lui" instruction. | |
2830 | */ | |
2831 | static void | |
2832 | macro_build_lui (place, counter, ep, regnum) | |
2833 | char *place; | |
2834 | int *counter; | |
2835 | expressionS *ep; | |
2836 | int regnum; | |
2837 | { | |
2838 | expressionS high_expr; | |
2839 | struct mips_cl_insn insn; | |
2840 | bfd_reloc_code_real_type r; | |
2841 | CONST char *name = "lui"; | |
2842 | CONST char *fmt = "t,u"; | |
2843 | ||
2844 | assert (! mips_opts.mips16); | |
2845 | ||
2846 | if (place == NULL) | |
2847 | high_expr = *ep; | |
2848 | else | |
2849 | { | |
2850 | high_expr.X_op = O_constant; | |
2851 | high_expr.X_add_number = ep->X_add_number; | |
2852 | } | |
2853 | ||
2854 | if (high_expr.X_op == O_constant) | |
2855 | { | |
2856 | /* we can compute the instruction now without a relocation entry */ | |
2857 | if (high_expr.X_add_number & 0x8000) | |
2858 | high_expr.X_add_number += 0x10000; | |
2859 | high_expr.X_add_number = | |
2860 | ((unsigned long) high_expr.X_add_number >> 16) & 0xffff; | |
2861 | r = BFD_RELOC_UNUSED; | |
2862 | } | |
2863 | else | |
2864 | { | |
2865 | assert (ep->X_op == O_symbol); | |
2866 | /* _gp_disp is a special case, used from s_cpload. */ | |
2867 | assert (mips_pic == NO_PIC | |
2868 | || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0); | |
2869 | r = BFD_RELOC_HI16_S; | |
2870 | } | |
2871 | ||
2872 | /* | |
2873 | * If the macro is about to expand into a second instruction, | |
2874 | * print a warning if needed. We need to pass ip as a parameter | |
2875 | * to generate a better warning message here... | |
2876 | */ | |
2877 | if (mips_opts.warn_about_macros && place == NULL && *counter == 1) | |
2878 | as_warn (_("Macro instruction expanded into multiple instructions")); | |
2879 | ||
2880 | if (place == NULL) | |
2881 | *counter += 1; /* bump instruction counter */ | |
2882 | ||
2883 | insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name); | |
2884 | assert (insn.insn_mo); | |
2885 | assert (strcmp (name, insn.insn_mo->name) == 0); | |
2886 | assert (strcmp (fmt, insn.insn_mo->args) == 0); | |
2887 | ||
2888 | insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT); | |
2889 | if (r == BFD_RELOC_UNUSED) | |
2890 | { | |
2891 | insn.insn_opcode |= high_expr.X_add_number; | |
2892 | append_insn (place, &insn, NULL, r, false); | |
2893 | } | |
2894 | else | |
2895 | append_insn (place, &insn, &high_expr, r, false); | |
2896 | } | |
2897 | ||
2898 | /* set_at() | |
2899 | * Generates code to set the $at register to true (one) | |
2900 | * if reg is less than the immediate expression. | |
2901 | */ | |
2902 | static void | |
2903 | set_at (counter, reg, unsignedp) | |
2904 | int *counter; | |
2905 | int reg; | |
2906 | int unsignedp; | |
2907 | { | |
2908 | if (imm_expr.X_op == O_constant | |
2909 | && imm_expr.X_add_number >= -0x8000 | |
2910 | && imm_expr.X_add_number < 0x8000) | |
2911 | macro_build ((char *) NULL, counter, &imm_expr, | |
2912 | unsignedp ? "sltiu" : "slti", | |
2913 | "t,r,j", AT, reg, (int) BFD_RELOC_LO16); | |
2914 | else | |
2915 | { | |
2916 | load_register (counter, AT, &imm_expr, 0); | |
2917 | macro_build ((char *) NULL, counter, NULL, | |
2918 | unsignedp ? "sltu" : "slt", | |
2919 | "d,v,t", AT, reg, AT); | |
2920 | } | |
2921 | } | |
2922 | ||
2923 | /* Warn if an expression is not a constant. */ | |
2924 | ||
2925 | static void | |
2926 | check_absolute_expr (ip, ex) | |
2927 | struct mips_cl_insn *ip; | |
2928 | expressionS *ex; | |
2929 | { | |
2930 | if (ex->X_op == O_big) | |
2931 | as_bad (_("unsupported large constant")); | |
2932 | else if (ex->X_op != O_constant) | |
2933 | as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name); | |
2934 | } | |
2935 | ||
2936 | /* Count the leading zeroes by performing a binary chop. This is a | |
2937 | bulky bit of source, but performance is a LOT better for the | |
2938 | majority of values than a simple loop to count the bits: | |
2939 | for (lcnt = 0; (lcnt < 32); lcnt++) | |
2940 | if ((v) & (1 << (31 - lcnt))) | |
2941 | break; | |
2942 | However it is not code size friendly, and the gain will drop a bit | |
2943 | on certain cached systems. | |
2944 | */ | |
2945 | #define COUNT_TOP_ZEROES(v) \ | |
2946 | (((v) & ~0xffff) == 0 \ | |
2947 | ? ((v) & ~0xff) == 0 \ | |
2948 | ? ((v) & ~0xf) == 0 \ | |
2949 | ? ((v) & ~0x3) == 0 \ | |
2950 | ? ((v) & ~0x1) == 0 \ | |
2951 | ? !(v) \ | |
2952 | ? 32 \ | |
2953 | : 31 \ | |
2954 | : 30 \ | |
2955 | : ((v) & ~0x7) == 0 \ | |
2956 | ? 29 \ | |
2957 | : 28 \ | |
2958 | : ((v) & ~0x3f) == 0 \ | |
2959 | ? ((v) & ~0x1f) == 0 \ | |
2960 | ? 27 \ | |
2961 | : 26 \ | |
2962 | : ((v) & ~0x7f) == 0 \ | |
2963 | ? 25 \ | |
2964 | : 24 \ | |
2965 | : ((v) & ~0xfff) == 0 \ | |
2966 | ? ((v) & ~0x3ff) == 0 \ | |
2967 | ? ((v) & ~0x1ff) == 0 \ | |
2968 | ? 23 \ | |
2969 | : 22 \ | |
2970 | : ((v) & ~0x7ff) == 0 \ | |
2971 | ? 21 \ | |
2972 | : 20 \ | |
2973 | : ((v) & ~0x3fff) == 0 \ | |
2974 | ? ((v) & ~0x1fff) == 0 \ | |
2975 | ? 19 \ | |
2976 | : 18 \ | |
2977 | : ((v) & ~0x7fff) == 0 \ | |
2978 | ? 17 \ | |
2979 | : 16 \ | |
2980 | : ((v) & ~0xffffff) == 0 \ | |
2981 | ? ((v) & ~0xfffff) == 0 \ | |
2982 | ? ((v) & ~0x3ffff) == 0 \ | |
2983 | ? ((v) & ~0x1ffff) == 0 \ | |
2984 | ? 15 \ | |
2985 | : 14 \ | |
2986 | : ((v) & ~0x7ffff) == 0 \ | |
2987 | ? 13 \ | |
2988 | : 12 \ | |
2989 | : ((v) & ~0x3fffff) == 0 \ | |
2990 | ? ((v) & ~0x1fffff) == 0 \ | |
2991 | ? 11 \ | |
2992 | : 10 \ | |
2993 | : ((v) & ~0x7fffff) == 0 \ | |
2994 | ? 9 \ | |
2995 | : 8 \ | |
2996 | : ((v) & ~0xfffffff) == 0 \ | |
2997 | ? ((v) & ~0x3ffffff) == 0 \ | |
2998 | ? ((v) & ~0x1ffffff) == 0 \ | |
2999 | ? 7 \ | |
3000 | : 6 \ | |
3001 | : ((v) & ~0x7ffffff) == 0 \ | |
3002 | ? 5 \ | |
3003 | : 4 \ | |
3004 | : ((v) & ~0x3fffffff) == 0 \ | |
3005 | ? ((v) & ~0x1fffffff) == 0 \ | |
3006 | ? 3 \ | |
3007 | : 2 \ | |
3008 | : ((v) & ~0x7fffffff) == 0 \ | |
3009 | ? 1 \ | |
3010 | : 0) | |
3011 | ||
3012 | /* load_register() | |
3013 | * This routine generates the least number of instructions neccessary to load | |
3014 | * an absolute expression value into a register. | |
3015 | */ | |
3016 | static void | |
3017 | load_register (counter, reg, ep, dbl) | |
3018 | int *counter; | |
3019 | int reg; | |
3020 | expressionS *ep; | |
3021 | int dbl; | |
3022 | { | |
3023 | int freg; | |
3024 | expressionS hi32, lo32; | |
3025 | ||
3026 | if (ep->X_op != O_big) | |
3027 | { | |
3028 | assert (ep->X_op == O_constant); | |
3029 | if (ep->X_add_number < 0x8000 | |
3030 | && (ep->X_add_number >= 0 | |
3031 | || (ep->X_add_number >= -0x8000 | |
3032 | && (! dbl | |
3033 | || ! ep->X_unsigned | |
3034 | || sizeof (ep->X_add_number) > 4)))) | |
3035 | { | |
3036 | /* We can handle 16 bit signed values with an addiu to | |
3037 | $zero. No need to ever use daddiu here, since $zero and | |
3038 | the result are always correct in 32 bit mode. */ | |
3039 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3040 | (int) BFD_RELOC_LO16); | |
3041 | return; | |
3042 | } | |
3043 | else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000) | |
3044 | { | |
3045 | /* We can handle 16 bit unsigned values with an ori to | |
3046 | $zero. */ | |
3047 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0, | |
3048 | (int) BFD_RELOC_LO16); | |
3049 | return; | |
3050 | } | |
3051 | else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0 | |
3052 | || ((ep->X_add_number &~ (offsetT) 0x7fffffff) | |
3053 | == ~ (offsetT) 0x7fffffff)) | |
3054 | && (! dbl | |
3055 | || ! ep->X_unsigned | |
3056 | || sizeof (ep->X_add_number) > 4 | |
3057 | || (ep->X_add_number & 0x80000000) == 0)) | |
9ce8a5dd | 3058 | || ((! ISA_HAS_64BIT_REGS (mips_opts.isa) || ! dbl) |
252b5132 | 3059 | && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0) |
9ce8a5dd | 3060 | || (! ISA_HAS_64BIT_REGS (mips_opts.isa) |
252b5132 RH |
3061 | && ! dbl |
3062 | && ((ep->X_add_number &~ (offsetT) 0xffffffff) | |
3063 | == ~ (offsetT) 0xffffffff))) | |
3064 | { | |
3065 | /* 32 bit values require an lui. */ | |
3066 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3067 | (int) BFD_RELOC_HI16); | |
3068 | if ((ep->X_add_number & 0xffff) != 0) | |
3069 | macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg, | |
3070 | (int) BFD_RELOC_LO16); | |
3071 | return; | |
3072 | } | |
3073 | } | |
3074 | ||
3075 | /* The value is larger than 32 bits. */ | |
3076 | ||
9ce8a5dd | 3077 | if (! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3078 | { |
3079 | as_bad (_("Number larger than 32 bits")); | |
3080 | macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0, | |
3081 | (int) BFD_RELOC_LO16); | |
3082 | return; | |
3083 | } | |
3084 | ||
3085 | if (ep->X_op != O_big) | |
3086 | { | |
3087 | hi32 = *ep; | |
3088 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3089 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; | |
3090 | hi32.X_add_number &= 0xffffffff; | |
3091 | lo32 = *ep; | |
3092 | lo32.X_add_number &= 0xffffffff; | |
3093 | } | |
3094 | else | |
3095 | { | |
3096 | assert (ep->X_add_number > 2); | |
3097 | if (ep->X_add_number == 3) | |
3098 | generic_bignum[3] = 0; | |
3099 | else if (ep->X_add_number > 4) | |
3100 | as_bad (_("Number larger than 64 bits")); | |
3101 | lo32.X_op = O_constant; | |
3102 | lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16); | |
3103 | hi32.X_op = O_constant; | |
3104 | hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16); | |
3105 | } | |
3106 | ||
3107 | if (hi32.X_add_number == 0) | |
3108 | freg = 0; | |
3109 | else | |
3110 | { | |
3111 | int shift, bit; | |
3112 | unsigned long hi, lo; | |
3113 | ||
3114 | if (hi32.X_add_number == 0xffffffff) | |
3115 | { | |
3116 | if ((lo32.X_add_number & 0xffff8000) == 0xffff8000) | |
3117 | { | |
3118 | macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j", | |
3119 | reg, 0, (int) BFD_RELOC_LO16); | |
3120 | return; | |
3121 | } | |
3122 | if (lo32.X_add_number & 0x80000000) | |
3123 | { | |
3124 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, | |
3125 | (int) BFD_RELOC_HI16); | |
3126 | if (lo32.X_add_number & 0xffff) | |
3127 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", | |
3128 | reg, reg, (int) BFD_RELOC_LO16); | |
3129 | return; | |
3130 | } | |
3131 | } | |
3132 | ||
3133 | /* Check for 16bit shifted constant. We know that hi32 is | |
3134 | non-zero, so start the mask on the first bit of the hi32 | |
3135 | value. */ | |
3136 | shift = 17; | |
3137 | do | |
3138 | { | |
3139 | unsigned long himask, lomask; | |
3140 | ||
3141 | if (shift < 32) | |
3142 | { | |
3143 | himask = 0xffff >> (32 - shift); | |
3144 | lomask = (0xffff << shift) & 0xffffffff; | |
3145 | } | |
3146 | else | |
3147 | { | |
3148 | himask = 0xffff << (shift - 32); | |
3149 | lomask = 0; | |
3150 | } | |
3151 | if ((hi32.X_add_number & ~ (offsetT) himask) == 0 | |
3152 | && (lo32.X_add_number & ~ (offsetT) lomask) == 0) | |
3153 | { | |
3154 | expressionS tmp; | |
3155 | ||
3156 | tmp.X_op = O_constant; | |
3157 | if (shift < 32) | |
3158 | tmp.X_add_number = ((hi32.X_add_number << (32 - shift)) | |
3159 | | (lo32.X_add_number >> shift)); | |
3160 | else | |
3161 | tmp.X_add_number = hi32.X_add_number >> (shift - 32); | |
3162 | macro_build ((char *) NULL, counter, &tmp, "ori", "t,r,i", reg, 0, | |
3163 | (int) BFD_RELOC_LO16); | |
3164 | macro_build ((char *) NULL, counter, NULL, | |
3165 | (shift >= 32) ? "dsll32" : "dsll", | |
3166 | "d,w,<", reg, reg, | |
3167 | (shift >= 32) ? shift - 32 : shift); | |
3168 | return; | |
3169 | } | |
3170 | shift++; | |
3171 | } while (shift <= (64 - 16)); | |
3172 | ||
3173 | /* Find the bit number of the lowest one bit, and store the | |
3174 | shifted value in hi/lo. */ | |
3175 | hi = (unsigned long) (hi32.X_add_number & 0xffffffff); | |
3176 | lo = (unsigned long) (lo32.X_add_number & 0xffffffff); | |
3177 | if (lo != 0) | |
3178 | { | |
3179 | bit = 0; | |
3180 | while ((lo & 1) == 0) | |
3181 | { | |
3182 | lo >>= 1; | |
3183 | ++bit; | |
3184 | } | |
3185 | lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit); | |
3186 | hi >>= bit; | |
3187 | } | |
3188 | else | |
3189 | { | |
3190 | bit = 32; | |
3191 | while ((hi & 1) == 0) | |
3192 | { | |
3193 | hi >>= 1; | |
3194 | ++bit; | |
3195 | } | |
3196 | lo = hi; | |
3197 | hi = 0; | |
3198 | } | |
3199 | ||
3200 | /* Optimize if the shifted value is a (power of 2) - 1. */ | |
3201 | if ((hi == 0 && ((lo + 1) & lo) == 0) | |
3202 | || (lo == 0xffffffff && ((hi + 1) & hi) == 0)) | |
3203 | { | |
3204 | shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number); | |
3205 | if (shift != 0) | |
3206 | { | |
3207 | expressionS tmp; | |
3208 | ||
3209 | /* This instruction will set the register to be all | |
3210 | ones. */ | |
3211 | tmp.X_op = O_constant; | |
3212 | tmp.X_add_number = (offsetT) -1; | |
3213 | macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j", | |
3214 | reg, 0, (int) BFD_RELOC_LO16); | |
3215 | if (bit != 0) | |
3216 | { | |
3217 | bit += shift; | |
3218 | macro_build ((char *) NULL, counter, NULL, | |
3219 | (bit >= 32) ? "dsll32" : "dsll", | |
3220 | "d,w,<", reg, reg, | |
3221 | (bit >= 32) ? bit - 32 : bit); | |
3222 | } | |
3223 | macro_build ((char *) NULL, counter, NULL, | |
3224 | (shift >= 32) ? "dsrl32" : "dsrl", | |
3225 | "d,w,<", reg, reg, | |
3226 | (shift >= 32) ? shift - 32 : shift); | |
3227 | return; | |
3228 | } | |
3229 | } | |
3230 | ||
3231 | /* Sign extend hi32 before calling load_register, because we can | |
3232 | generally get better code when we load a sign extended value. */ | |
3233 | if ((hi32.X_add_number & 0x80000000) != 0) | |
3234 | hi32.X_add_number |= ~ (offsetT) 0xffffffff; | |
3235 | load_register (counter, reg, &hi32, 0); | |
3236 | freg = reg; | |
3237 | } | |
3238 | if ((lo32.X_add_number & 0xffff0000) == 0) | |
3239 | { | |
3240 | if (freg != 0) | |
3241 | { | |
3242 | macro_build ((char *) NULL, counter, NULL, "dsll32", "d,w,<", reg, | |
3243 | freg, 0); | |
3244 | freg = reg; | |
3245 | } | |
3246 | } | |
3247 | else | |
3248 | { | |
3249 | expressionS mid16; | |
3250 | ||
3251 | if ((freg == 0) && (lo32.X_add_number == 0xffffffff)) | |
3252 | { | |
3253 | macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg, | |
3254 | (int) BFD_RELOC_HI16); | |
3255 | macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg, | |
3256 | reg, 0); | |
3257 | return; | |
3258 | } | |
3259 | ||
3260 | if (freg != 0) | |
3261 | { | |
3262 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3263 | freg, 16); | |
3264 | freg = reg; | |
3265 | } | |
3266 | mid16 = lo32; | |
3267 | mid16.X_add_number >>= 16; | |
3268 | macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg, | |
3269 | freg, (int) BFD_RELOC_LO16); | |
3270 | macro_build ((char *) NULL, counter, NULL, "dsll", "d,w,<", reg, | |
3271 | reg, 16); | |
3272 | freg = reg; | |
3273 | } | |
3274 | if ((lo32.X_add_number & 0xffff) != 0) | |
3275 | macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg, | |
3276 | (int) BFD_RELOC_LO16); | |
3277 | } | |
3278 | ||
3279 | /* Load an address into a register. */ | |
3280 | ||
3281 | static void | |
3282 | load_address (counter, reg, ep) | |
3283 | int *counter; | |
3284 | int reg; | |
3285 | expressionS *ep; | |
3286 | { | |
3287 | char *p; | |
3288 | ||
3289 | if (ep->X_op != O_constant | |
3290 | && ep->X_op != O_symbol) | |
3291 | { | |
3292 | as_bad (_("expression too complex")); | |
3293 | ep->X_op = O_constant; | |
3294 | } | |
3295 | ||
3296 | if (ep->X_op == O_constant) | |
3297 | { | |
3298 | load_register (counter, reg, ep, 0); | |
3299 | return; | |
3300 | } | |
3301 | ||
3302 | if (mips_pic == NO_PIC) | |
3303 | { | |
3304 | /* If this is a reference to a GP relative symbol, we want | |
3305 | addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
3306 | Otherwise we want | |
3307 | lui $reg,<sym> (BFD_RELOC_HI16_S) | |
3308 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3309 | If we have an addend, we always use the latter form. */ | |
3310 | if ((valueT) ep->X_add_number >= MAX_GPREL_OFFSET | |
3311 | || nopic_need_relax (ep->X_add_symbol, 1)) | |
3312 | p = NULL; | |
3313 | else | |
3314 | { | |
3315 | frag_grow (20); | |
3316 | macro_build ((char *) NULL, counter, ep, | |
3317 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3318 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3319 | ? "addiu" : "daddiu"), |
3320 | "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
3321 | p = frag_var (rs_machine_dependent, 8, 0, | |
3322 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
3323 | mips_opts.warn_about_macros), | |
3324 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3325 | } | |
3326 | macro_build_lui (p, counter, ep, reg); | |
3327 | if (p != NULL) | |
3328 | p += 4; | |
3329 | macro_build (p, counter, ep, | |
3330 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3331 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3332 | ? "addiu" : "daddiu"), |
3333 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3334 | } | |
3335 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
3336 | { | |
3337 | expressionS ex; | |
3338 | ||
3339 | /* If this is a reference to an external symbol, we want | |
3340 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3341 | Otherwise we want | |
3342 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3343 | nop | |
3344 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3345 | If there is a constant, it must be added in after. */ | |
3346 | ex.X_add_number = ep->X_add_number; | |
3347 | ep->X_add_number = 0; | |
3348 | frag_grow (20); | |
3349 | macro_build ((char *) NULL, counter, ep, | |
3350 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3351 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3352 | ? "lw" : "ld"), |
3353 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
3354 | macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", ""); | |
3355 | p = frag_var (rs_machine_dependent, 4, 0, | |
3356 | RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros), | |
3357 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3358 | macro_build (p, counter, ep, | |
3359 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3360 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3361 | ? "addiu" : "daddiu"), |
3362 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3363 | if (ex.X_add_number != 0) | |
3364 | { | |
3365 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3366 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3367 | ex.X_op = O_constant; | |
3368 | macro_build ((char *) NULL, counter, &ex, | |
3369 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3370 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3371 | ? "addiu" : "daddiu"), |
3372 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3373 | } | |
3374 | } | |
3375 | else if (mips_pic == SVR4_PIC) | |
3376 | { | |
3377 | expressionS ex; | |
3378 | int off; | |
3379 | ||
3380 | /* This is the large GOT case. If this is a reference to an | |
3381 | external symbol, we want | |
3382 | lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
3383 | addu $reg,$reg,$gp | |
3384 | lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16) | |
3385 | Otherwise, for a reference to a local symbol, we want | |
3386 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
3387 | nop | |
3388 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) | |
3389 | If there is a constant, it must be added in after. */ | |
3390 | ex.X_add_number = ep->X_add_number; | |
3391 | ep->X_add_number = 0; | |
3392 | if (reg_needs_delay (GP)) | |
3393 | off = 4; | |
3394 | else | |
3395 | off = 0; | |
3396 | frag_grow (32); | |
3397 | macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg, | |
3398 | (int) BFD_RELOC_MIPS_GOT_HI16); | |
3399 | macro_build ((char *) NULL, counter, (expressionS *) NULL, | |
3400 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3401 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3402 | ? "addu" : "daddu"), |
3403 | "d,v,t", reg, reg, GP); | |
3404 | macro_build ((char *) NULL, counter, ep, | |
3405 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3406 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3407 | ? "lw" : "ld"), |
3408 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg); | |
3409 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
3410 | RELAX_ENCODE (12, 12 + off, off, 8 + off, 0, | |
3411 | mips_opts.warn_about_macros), | |
3412 | ep->X_add_symbol, (offsetT) 0, (char *) NULL); | |
3413 | if (off > 0) | |
3414 | { | |
3415 | /* We need a nop before loading from $gp. This special | |
3416 | check is required because the lui which starts the main | |
3417 | instruction stream does not refer to $gp, and so will not | |
3418 | insert the nop which may be required. */ | |
3419 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3420 | p += 4; | |
3421 | } | |
3422 | macro_build (p, counter, ep, | |
3423 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3424 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3425 | ? "lw" : "ld"), |
3426 | "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
3427 | p += 4; | |
3428 | macro_build (p, counter, (expressionS *) NULL, "nop", ""); | |
3429 | p += 4; | |
3430 | macro_build (p, counter, ep, | |
3431 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3432 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3433 | ? "addiu" : "daddiu"), |
3434 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3435 | if (ex.X_add_number != 0) | |
3436 | { | |
3437 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) | |
3438 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
3439 | ex.X_op = O_constant; | |
3440 | macro_build ((char *) NULL, counter, &ex, | |
3441 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3442 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3443 | ? "addiu" : "daddiu"), |
3444 | "t,r,j", reg, reg, (int) BFD_RELOC_LO16); | |
3445 | } | |
3446 | } | |
3447 | else if (mips_pic == EMBEDDED_PIC) | |
3448 | { | |
3449 | /* We always do | |
3450 | addiu $reg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
3451 | */ | |
3452 | macro_build ((char *) NULL, counter, ep, | |
3453 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 3454 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
3455 | ? "addiu" : "daddiu"), |
3456 | "t,r,j", reg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
3457 | } | |
3458 | else | |
3459 | abort (); | |
3460 | } | |
3461 | ||
3462 | /* | |
3463 | * Build macros | |
3464 | * This routine implements the seemingly endless macro or synthesized | |
3465 | * instructions and addressing modes in the mips assembly language. Many | |
3466 | * of these macros are simple and are similar to each other. These could | |
3467 | * probably be handled by some kind of table or grammer aproach instead of | |
3468 | * this verbose method. Others are not simple macros but are more like | |
3469 | * optimizing code generation. | |
3470 | * One interesting optimization is when several store macros appear | |
3471 | * consecutivly that would load AT with the upper half of the same address. | |
3472 | * The ensuing load upper instructions are ommited. This implies some kind | |
3473 | * of global optimization. We currently only optimize within a single macro. | |
3474 | * For many of the load and store macros if the address is specified as a | |
3475 | * constant expression in the first 64k of memory (ie ld $2,0x4000c) we | |
3476 | * first load register 'at' with zero and use it as the base register. The | |
3477 | * mips assembler simply uses register $zero. Just one tiny optimization | |
3478 | * we're missing. | |
3479 | */ | |
3480 | static void | |
3481 | macro (ip) | |
3482 | struct mips_cl_insn *ip; | |
3483 | { | |
3484 | register int treg, sreg, dreg, breg; | |
3485 | int tempreg; | |
3486 | int mask; | |
3487 | int icnt = 0; | |
43841e91 | 3488 | int used_at = 0; |
252b5132 RH |
3489 | expressionS expr1; |
3490 | const char *s; | |
3491 | const char *s2; | |
3492 | const char *fmt; | |
3493 | int likely = 0; | |
3494 | int dbl = 0; | |
3495 | int coproc = 0; | |
3496 | int lr = 0; | |
3497 | int imm = 0; | |
3498 | offsetT maxnum; | |
3499 | int off; | |
3500 | bfd_reloc_code_real_type r; | |
3501 | char *p; | |
3502 | int hold_mips_optimize; | |
3503 | ||
3504 | assert (! mips_opts.mips16); | |
3505 | ||
3506 | treg = (ip->insn_opcode >> 16) & 0x1f; | |
3507 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
3508 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
3509 | mask = ip->insn_mo->mask; | |
3510 | ||
3511 | expr1.X_op = O_constant; | |
3512 | expr1.X_op_symbol = NULL; | |
3513 | expr1.X_add_symbol = NULL; | |
3514 | expr1.X_add_number = 1; | |
3515 | ||
3516 | switch (mask) | |
3517 | { | |
3518 | case M_DABS: | |
3519 | dbl = 1; | |
3520 | case M_ABS: | |
3521 | /* bgez $a0,.+12 | |
3522 | move v0,$a0 | |
3523 | sub v0,$zero,$a0 | |
3524 | */ | |
3525 | ||
3526 | mips_emit_delays (true); | |
3527 | ++mips_opts.noreorder; | |
3528 | mips_any_noreorder = 1; | |
3529 | ||
3530 | expr1.X_add_number = 8; | |
3531 | macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg); | |
3532 | if (dreg == sreg) | |
3533 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
3534 | else | |
3535 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, sreg, 0); | |
3536 | macro_build ((char *) NULL, &icnt, NULL, | |
3537 | dbl ? "dsub" : "sub", | |
3538 | "d,v,t", dreg, 0, sreg); | |
3539 | ||
3540 | --mips_opts.noreorder; | |
3541 | return; | |
3542 | ||
3543 | case M_ADD_I: | |
3544 | s = "addi"; | |
3545 | s2 = "add"; | |
3546 | goto do_addi; | |
3547 | case M_ADDU_I: | |
3548 | s = "addiu"; | |
3549 | s2 = "addu"; | |
3550 | goto do_addi; | |
3551 | case M_DADD_I: | |
3552 | dbl = 1; | |
3553 | s = "daddi"; | |
3554 | s2 = "dadd"; | |
3555 | goto do_addi; | |
3556 | case M_DADDU_I: | |
3557 | dbl = 1; | |
3558 | s = "daddiu"; | |
3559 | s2 = "daddu"; | |
3560 | do_addi: | |
3561 | if (imm_expr.X_op == O_constant | |
3562 | && imm_expr.X_add_number >= -0x8000 | |
3563 | && imm_expr.X_add_number < 0x8000) | |
3564 | { | |
3565 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg, | |
3566 | (int) BFD_RELOC_LO16); | |
3567 | return; | |
3568 | } | |
3569 | load_register (&icnt, AT, &imm_expr, dbl); | |
3570 | macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT); | |
3571 | break; | |
3572 | ||
3573 | case M_AND_I: | |
3574 | s = "andi"; | |
3575 | s2 = "and"; | |
3576 | goto do_bit; | |
3577 | case M_OR_I: | |
3578 | s = "ori"; | |
3579 | s2 = "or"; | |
3580 | goto do_bit; | |
3581 | case M_NOR_I: | |
3582 | s = ""; | |
3583 | s2 = "nor"; | |
3584 | goto do_bit; | |
3585 | case M_XOR_I: | |
3586 | s = "xori"; | |
3587 | s2 = "xor"; | |
3588 | do_bit: | |
3589 | if (imm_expr.X_op == O_constant | |
3590 | && imm_expr.X_add_number >= 0 | |
3591 | && imm_expr.X_add_number < 0x10000) | |
3592 | { | |
3593 | if (mask != M_NOR_I) | |
3594 | macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg, | |
3595 | sreg, (int) BFD_RELOC_LO16); | |
3596 | else | |
3597 | { | |
3598 | macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i", | |
3599 | treg, sreg, (int) BFD_RELOC_LO16); | |
3600 | macro_build ((char *) NULL, &icnt, NULL, "nor", "d,v,t", | |
3601 | treg, treg, 0); | |
3602 | } | |
3603 | return; | |
3604 | } | |
3605 | ||
3606 | load_register (&icnt, AT, &imm_expr, 0); | |
3607 | macro_build ((char *) NULL, &icnt, NULL, s2, "d,v,t", treg, sreg, AT); | |
3608 | break; | |
3609 | ||
3610 | case M_BEQ_I: | |
3611 | s = "beq"; | |
3612 | goto beq_i; | |
3613 | case M_BEQL_I: | |
3614 | s = "beql"; | |
3615 | likely = 1; | |
3616 | goto beq_i; | |
3617 | case M_BNE_I: | |
3618 | s = "bne"; | |
3619 | goto beq_i; | |
3620 | case M_BNEL_I: | |
3621 | s = "bnel"; | |
3622 | likely = 1; | |
3623 | beq_i: | |
3624 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3625 | { | |
3626 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, | |
3627 | 0); | |
3628 | return; | |
3629 | } | |
3630 | load_register (&icnt, AT, &imm_expr, 0); | |
3631 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT); | |
3632 | break; | |
3633 | ||
3634 | case M_BGEL: | |
3635 | likely = 1; | |
3636 | case M_BGE: | |
3637 | if (treg == 0) | |
3638 | { | |
3639 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3640 | likely ? "bgezl" : "bgez", | |
3641 | "s,p", sreg); | |
3642 | return; | |
3643 | } | |
3644 | if (sreg == 0) | |
3645 | { | |
3646 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3647 | likely ? "blezl" : "blez", | |
3648 | "s,p", treg); | |
3649 | return; | |
3650 | } | |
3651 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg); | |
3652 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3653 | likely ? "beql" : "beq", | |
3654 | "s,t,p", AT, 0); | |
3655 | break; | |
3656 | ||
3657 | case M_BGTL_I: | |
3658 | likely = 1; | |
3659 | case M_BGT_I: | |
3660 | /* check for > max integer */ | |
3661 | maxnum = 0x7fffffff; | |
9ce8a5dd | 3662 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4) |
252b5132 RH |
3663 | { |
3664 | maxnum <<= 16; | |
3665 | maxnum |= 0xffff; | |
3666 | maxnum <<= 16; | |
3667 | maxnum |= 0xffff; | |
3668 | } | |
3669 | if (imm_expr.X_op == O_constant | |
3670 | && imm_expr.X_add_number >= maxnum | |
9ce8a5dd | 3671 | && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4)) |
252b5132 RH |
3672 | { |
3673 | do_false: | |
3674 | /* result is always false */ | |
3675 | if (! likely) | |
3676 | { | |
3677 | as_warn (_("Branch %s is always false (nop)"), ip->insn_mo->name); | |
3678 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
3679 | } | |
3680 | else | |
3681 | { | |
3682 | as_warn (_("Branch likely %s is always false"), ip->insn_mo->name); | |
3683 | macro_build ((char *) NULL, &icnt, &offset_expr, "bnel", | |
3684 | "s,t,p", 0, 0); | |
3685 | } | |
3686 | return; | |
3687 | } | |
3688 | if (imm_expr.X_op != O_constant) | |
3689 | as_bad (_("Unsupported large constant")); | |
3690 | imm_expr.X_add_number++; | |
3691 | /* FALLTHROUGH */ | |
3692 | case M_BGE_I: | |
3693 | case M_BGEL_I: | |
3694 | if (mask == M_BGEL_I) | |
3695 | likely = 1; | |
3696 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3697 | { | |
3698 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3699 | likely ? "bgezl" : "bgez", | |
3700 | "s,p", sreg); | |
3701 | return; | |
3702 | } | |
3703 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3704 | { | |
3705 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3706 | likely ? "bgtzl" : "bgtz", | |
3707 | "s,p", sreg); | |
3708 | return; | |
3709 | } | |
3710 | maxnum = 0x7fffffff; | |
9ce8a5dd | 3711 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4) |
252b5132 RH |
3712 | { |
3713 | maxnum <<= 16; | |
3714 | maxnum |= 0xffff; | |
3715 | maxnum <<= 16; | |
3716 | maxnum |= 0xffff; | |
3717 | } | |
3718 | maxnum = - maxnum - 1; | |
3719 | if (imm_expr.X_op == O_constant | |
3720 | && imm_expr.X_add_number <= maxnum | |
9ce8a5dd | 3721 | && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4)) |
252b5132 RH |
3722 | { |
3723 | do_true: | |
3724 | /* result is always true */ | |
3725 | as_warn (_("Branch %s is always true"), ip->insn_mo->name); | |
3726 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
3727 | return; | |
3728 | } | |
3729 | set_at (&icnt, sreg, 0); | |
3730 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3731 | likely ? "beql" : "beq", | |
3732 | "s,t,p", AT, 0); | |
3733 | break; | |
3734 | ||
3735 | case M_BGEUL: | |
3736 | likely = 1; | |
3737 | case M_BGEU: | |
3738 | if (treg == 0) | |
3739 | goto do_true; | |
3740 | if (sreg == 0) | |
3741 | { | |
3742 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3743 | likely ? "beql" : "beq", | |
3744 | "s,t,p", 0, treg); | |
3745 | return; | |
3746 | } | |
3747 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, | |
3748 | treg); | |
3749 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3750 | likely ? "beql" : "beq", | |
3751 | "s,t,p", AT, 0); | |
3752 | break; | |
3753 | ||
3754 | case M_BGTUL_I: | |
3755 | likely = 1; | |
3756 | case M_BGTU_I: | |
3757 | if (sreg == 0 | |
9ce8a5dd | 3758 | || (! ISA_HAS_64BIT_REGS (mips_opts.isa) |
252b5132 RH |
3759 | && imm_expr.X_op == O_constant |
3760 | && imm_expr.X_add_number == 0xffffffff)) | |
3761 | goto do_false; | |
3762 | if (imm_expr.X_op != O_constant) | |
3763 | as_bad (_("Unsupported large constant")); | |
3764 | imm_expr.X_add_number++; | |
3765 | /* FALLTHROUGH */ | |
3766 | case M_BGEU_I: | |
3767 | case M_BGEUL_I: | |
3768 | if (mask == M_BGEUL_I) | |
3769 | likely = 1; | |
3770 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3771 | goto do_true; | |
3772 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3773 | { | |
3774 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3775 | likely ? "bnel" : "bne", | |
3776 | "s,t,p", sreg, 0); | |
3777 | return; | |
3778 | } | |
3779 | set_at (&icnt, sreg, 1); | |
3780 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3781 | likely ? "beql" : "beq", | |
3782 | "s,t,p", AT, 0); | |
3783 | break; | |
3784 | ||
3785 | case M_BGTL: | |
3786 | likely = 1; | |
3787 | case M_BGT: | |
3788 | if (treg == 0) | |
3789 | { | |
3790 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3791 | likely ? "bgtzl" : "bgtz", | |
3792 | "s,p", sreg); | |
3793 | return; | |
3794 | } | |
3795 | if (sreg == 0) | |
3796 | { | |
3797 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3798 | likely ? "bltzl" : "bltz", | |
3799 | "s,p", treg); | |
3800 | return; | |
3801 | } | |
3802 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg); | |
3803 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3804 | likely ? "bnel" : "bne", | |
3805 | "s,t,p", AT, 0); | |
3806 | break; | |
3807 | ||
3808 | case M_BGTUL: | |
3809 | likely = 1; | |
3810 | case M_BGTU: | |
3811 | if (treg == 0) | |
3812 | { | |
3813 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3814 | likely ? "bnel" : "bne", | |
3815 | "s,t,p", sreg, 0); | |
3816 | return; | |
3817 | } | |
3818 | if (sreg == 0) | |
3819 | goto do_false; | |
3820 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, | |
3821 | sreg); | |
3822 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3823 | likely ? "bnel" : "bne", | |
3824 | "s,t,p", AT, 0); | |
3825 | break; | |
3826 | ||
3827 | case M_BLEL: | |
3828 | likely = 1; | |
3829 | case M_BLE: | |
3830 | if (treg == 0) | |
3831 | { | |
3832 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3833 | likely ? "blezl" : "blez", | |
3834 | "s,p", sreg); | |
3835 | return; | |
3836 | } | |
3837 | if (sreg == 0) | |
3838 | { | |
3839 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3840 | likely ? "bgezl" : "bgez", | |
3841 | "s,p", treg); | |
3842 | return; | |
3843 | } | |
3844 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, treg, sreg); | |
3845 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3846 | likely ? "beql" : "beq", | |
3847 | "s,t,p", AT, 0); | |
3848 | break; | |
3849 | ||
3850 | case M_BLEL_I: | |
3851 | likely = 1; | |
3852 | case M_BLE_I: | |
3853 | maxnum = 0x7fffffff; | |
9ce8a5dd | 3854 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) && sizeof (maxnum) > 4) |
252b5132 RH |
3855 | { |
3856 | maxnum <<= 16; | |
3857 | maxnum |= 0xffff; | |
3858 | maxnum <<= 16; | |
3859 | maxnum |= 0xffff; | |
3860 | } | |
3861 | if (imm_expr.X_op == O_constant | |
3862 | && imm_expr.X_add_number >= maxnum | |
9ce8a5dd | 3863 | && (! ISA_HAS_64BIT_REGS (mips_opts.isa) || sizeof (maxnum) > 4)) |
252b5132 RH |
3864 | goto do_true; |
3865 | if (imm_expr.X_op != O_constant) | |
3866 | as_bad (_("Unsupported large constant")); | |
3867 | imm_expr.X_add_number++; | |
3868 | /* FALLTHROUGH */ | |
3869 | case M_BLT_I: | |
3870 | case M_BLTL_I: | |
3871 | if (mask == M_BLTL_I) | |
3872 | likely = 1; | |
3873 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3874 | { | |
3875 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3876 | likely ? "bltzl" : "bltz", | |
3877 | "s,p", sreg); | |
3878 | return; | |
3879 | } | |
3880 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3881 | { | |
3882 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3883 | likely ? "blezl" : "blez", | |
3884 | "s,p", sreg); | |
3885 | return; | |
3886 | } | |
3887 | set_at (&icnt, sreg, 0); | |
3888 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3889 | likely ? "bnel" : "bne", | |
3890 | "s,t,p", AT, 0); | |
3891 | break; | |
3892 | ||
3893 | case M_BLEUL: | |
3894 | likely = 1; | |
3895 | case M_BLEU: | |
3896 | if (treg == 0) | |
3897 | { | |
3898 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3899 | likely ? "beql" : "beq", | |
3900 | "s,t,p", sreg, 0); | |
3901 | return; | |
3902 | } | |
3903 | if (sreg == 0) | |
3904 | goto do_true; | |
3905 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, treg, | |
3906 | sreg); | |
3907 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3908 | likely ? "beql" : "beq", | |
3909 | "s,t,p", AT, 0); | |
3910 | break; | |
3911 | ||
3912 | case M_BLEUL_I: | |
3913 | likely = 1; | |
3914 | case M_BLEU_I: | |
3915 | if (sreg == 0 | |
9ce8a5dd | 3916 | || (! ISA_HAS_64BIT_REGS (mips_opts.isa) |
252b5132 RH |
3917 | && imm_expr.X_op == O_constant |
3918 | && imm_expr.X_add_number == 0xffffffff)) | |
3919 | goto do_true; | |
3920 | if (imm_expr.X_op != O_constant) | |
3921 | as_bad (_("Unsupported large constant")); | |
3922 | imm_expr.X_add_number++; | |
3923 | /* FALLTHROUGH */ | |
3924 | case M_BLTU_I: | |
3925 | case M_BLTUL_I: | |
3926 | if (mask == M_BLTUL_I) | |
3927 | likely = 1; | |
3928 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
3929 | goto do_false; | |
3930 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
3931 | { | |
3932 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3933 | likely ? "beql" : "beq", | |
3934 | "s,t,p", sreg, 0); | |
3935 | return; | |
3936 | } | |
3937 | set_at (&icnt, sreg, 1); | |
3938 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3939 | likely ? "bnel" : "bne", | |
3940 | "s,t,p", AT, 0); | |
3941 | break; | |
3942 | ||
3943 | case M_BLTL: | |
3944 | likely = 1; | |
3945 | case M_BLT: | |
3946 | if (treg == 0) | |
3947 | { | |
3948 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3949 | likely ? "bltzl" : "bltz", | |
3950 | "s,p", sreg); | |
3951 | return; | |
3952 | } | |
3953 | if (sreg == 0) | |
3954 | { | |
3955 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3956 | likely ? "bgtzl" : "bgtz", | |
3957 | "s,p", treg); | |
3958 | return; | |
3959 | } | |
3960 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", AT, sreg, treg); | |
3961 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3962 | likely ? "bnel" : "bne", | |
3963 | "s,t,p", AT, 0); | |
3964 | break; | |
3965 | ||
3966 | case M_BLTUL: | |
3967 | likely = 1; | |
3968 | case M_BLTU: | |
3969 | if (treg == 0) | |
3970 | goto do_false; | |
3971 | if (sreg == 0) | |
3972 | { | |
3973 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3974 | likely ? "bnel" : "bne", | |
3975 | "s,t,p", 0, treg); | |
3976 | return; | |
3977 | } | |
3978 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", AT, sreg, | |
3979 | treg); | |
3980 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
3981 | likely ? "bnel" : "bne", | |
3982 | "s,t,p", AT, 0); | |
3983 | break; | |
3984 | ||
3985 | case M_DDIV_3: | |
3986 | dbl = 1; | |
3987 | case M_DIV_3: | |
3988 | s = "mflo"; | |
3989 | goto do_div3; | |
3990 | case M_DREM_3: | |
3991 | dbl = 1; | |
3992 | case M_REM_3: | |
3993 | s = "mfhi"; | |
3994 | do_div3: | |
3995 | if (treg == 0) | |
3996 | { | |
3997 | as_warn (_("Divide by zero.")); | |
3998 | if (mips_trap) | |
3999 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0); | |
4000 | else | |
4001 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); | |
4002 | return; | |
4003 | } | |
4004 | ||
4005 | mips_emit_delays (true); | |
4006 | ++mips_opts.noreorder; | |
4007 | mips_any_noreorder = 1; | |
4008 | if (mips_trap) | |
4009 | { | |
4010 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0); | |
4011 | macro_build ((char *) NULL, &icnt, NULL, | |
4012 | dbl ? "ddiv" : "div", | |
4013 | "z,s,t", sreg, treg); | |
4014 | } | |
4015 | else | |
4016 | { | |
4017 | expr1.X_add_number = 8; | |
4018 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
4019 | macro_build ((char *) NULL, &icnt, NULL, | |
4020 | dbl ? "ddiv" : "div", | |
4021 | "z,s,t", sreg, treg); | |
4022 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); | |
4023 | } | |
4024 | expr1.X_add_number = -1; | |
4025 | macro_build ((char *) NULL, &icnt, &expr1, | |
4026 | dbl ? "daddiu" : "addiu", | |
4027 | "t,r,j", AT, 0, (int) BFD_RELOC_LO16); | |
4028 | expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16); | |
4029 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT); | |
4030 | if (dbl) | |
4031 | { | |
4032 | expr1.X_add_number = 1; | |
4033 | macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0, | |
4034 | (int) BFD_RELOC_LO16); | |
4035 | macro_build ((char *) NULL, &icnt, NULL, "dsll32", "d,w,<", AT, AT, | |
4036 | 31); | |
4037 | } | |
4038 | else | |
4039 | { | |
4040 | expr1.X_add_number = 0x80000000; | |
4041 | macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT, | |
4042 | (int) BFD_RELOC_HI16); | |
4043 | } | |
4044 | if (mips_trap) | |
4045 | { | |
4046 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", sreg, AT); | |
4047 | /* We want to close the noreorder block as soon as possible, so | |
4048 | that later insns are available for delay slot filling. */ | |
4049 | --mips_opts.noreorder; | |
4050 | } | |
4051 | else | |
4052 | { | |
4053 | expr1.X_add_number = 8; | |
4054 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT); | |
4055 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
4056 | ||
4057 | /* We want to close the noreorder block as soon as possible, so | |
4058 | that later insns are available for delay slot filling. */ | |
4059 | --mips_opts.noreorder; | |
4060 | ||
4061 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); | |
4062 | } | |
4063 | macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg); | |
4064 | break; | |
4065 | ||
4066 | case M_DIV_3I: | |
4067 | s = "div"; | |
4068 | s2 = "mflo"; | |
4069 | goto do_divi; | |
4070 | case M_DIVU_3I: | |
4071 | s = "divu"; | |
4072 | s2 = "mflo"; | |
4073 | goto do_divi; | |
4074 | case M_REM_3I: | |
4075 | s = "div"; | |
4076 | s2 = "mfhi"; | |
4077 | goto do_divi; | |
4078 | case M_REMU_3I: | |
4079 | s = "divu"; | |
4080 | s2 = "mfhi"; | |
4081 | goto do_divi; | |
4082 | case M_DDIV_3I: | |
4083 | dbl = 1; | |
4084 | s = "ddiv"; | |
4085 | s2 = "mflo"; | |
4086 | goto do_divi; | |
4087 | case M_DDIVU_3I: | |
4088 | dbl = 1; | |
4089 | s = "ddivu"; | |
4090 | s2 = "mflo"; | |
4091 | goto do_divi; | |
4092 | case M_DREM_3I: | |
4093 | dbl = 1; | |
4094 | s = "ddiv"; | |
4095 | s2 = "mfhi"; | |
4096 | goto do_divi; | |
4097 | case M_DREMU_3I: | |
4098 | dbl = 1; | |
4099 | s = "ddivu"; | |
4100 | s2 = "mfhi"; | |
4101 | do_divi: | |
4102 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
4103 | { | |
4104 | as_warn (_("Divide by zero.")); | |
4105 | if (mips_trap) | |
4106 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0); | |
4107 | else | |
4108 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); | |
4109 | return; | |
4110 | } | |
4111 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) | |
4112 | { | |
4113 | if (strcmp (s2, "mflo") == 0) | |
4114 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, | |
4115 | sreg); | |
4116 | else | |
4117 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0); | |
4118 | return; | |
4119 | } | |
4120 | if (imm_expr.X_op == O_constant | |
4121 | && imm_expr.X_add_number == -1 | |
4122 | && s[strlen (s) - 1] != 'u') | |
4123 | { | |
4124 | if (strcmp (s2, "mflo") == 0) | |
4125 | { | |
4126 | if (dbl) | |
4127 | macro_build ((char *) NULL, &icnt, NULL, "dneg", "d,w", dreg, | |
4128 | sreg); | |
4129 | else | |
4130 | macro_build ((char *) NULL, &icnt, NULL, "neg", "d,w", dreg, | |
4131 | sreg); | |
4132 | } | |
4133 | else | |
4134 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0); | |
4135 | return; | |
4136 | } | |
4137 | ||
4138 | load_register (&icnt, AT, &imm_expr, dbl); | |
4139 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, AT); | |
4140 | macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg); | |
4141 | break; | |
4142 | ||
4143 | case M_DIVU_3: | |
4144 | s = "divu"; | |
4145 | s2 = "mflo"; | |
4146 | goto do_divu3; | |
4147 | case M_REMU_3: | |
4148 | s = "divu"; | |
4149 | s2 = "mfhi"; | |
4150 | goto do_divu3; | |
4151 | case M_DDIVU_3: | |
4152 | s = "ddivu"; | |
4153 | s2 = "mflo"; | |
4154 | goto do_divu3; | |
4155 | case M_DREMU_3: | |
4156 | s = "ddivu"; | |
4157 | s2 = "mfhi"; | |
4158 | do_divu3: | |
4159 | mips_emit_delays (true); | |
4160 | ++mips_opts.noreorder; | |
4161 | mips_any_noreorder = 1; | |
4162 | if (mips_trap) | |
4163 | { | |
4164 | macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", treg, 0); | |
4165 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg); | |
4166 | /* We want to close the noreorder block as soon as possible, so | |
4167 | that later insns are available for delay slot filling. */ | |
4168 | --mips_opts.noreorder; | |
4169 | } | |
4170 | else | |
4171 | { | |
4172 | expr1.X_add_number = 8; | |
4173 | macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0); | |
4174 | macro_build ((char *) NULL, &icnt, NULL, s, "z,s,t", sreg, treg); | |
4175 | ||
4176 | /* We want to close the noreorder block as soon as possible, so | |
4177 | that later insns are available for delay slot filling. */ | |
4178 | --mips_opts.noreorder; | |
4179 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7); | |
4180 | } | |
4181 | macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg); | |
4182 | return; | |
4183 | ||
4184 | case M_DLA_AB: | |
4185 | dbl = 1; | |
4186 | case M_LA_AB: | |
4187 | /* Load the address of a symbol into a register. If breg is not | |
4188 | zero, we then add a base register to it. */ | |
4189 | ||
4190 | /* When generating embedded PIC code, we permit expressions of | |
4191 | the form | |
4192 | la $4,foo-bar | |
bb2d6cd7 | 4193 | where bar is an address in the current section. These are used |
252b5132 RH |
4194 | when getting the addresses of functions. We don't permit |
4195 | X_add_number to be non-zero, because if the symbol is | |
4196 | external the relaxing code needs to know that any addend is | |
4197 | purely the offset to X_op_symbol. */ | |
4198 | if (mips_pic == EMBEDDED_PIC | |
4199 | && offset_expr.X_op == O_subtract | |
49309057 | 4200 | && (symbol_constant_p (offset_expr.X_op_symbol) |
bb2d6cd7 | 4201 | ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg |
49309057 ILT |
4202 | : (symbol_equated_p (offset_expr.X_op_symbol) |
4203 | && (S_GET_SEGMENT | |
4204 | (symbol_get_value_expression (offset_expr.X_op_symbol) | |
4205 | ->X_add_symbol) | |
bb2d6cd7 | 4206 | == now_seg))) |
252b5132 | 4207 | && breg == 0 |
bb2d6cd7 GK |
4208 | && (offset_expr.X_add_number == 0 |
4209 | || OUTPUT_FLAVOR == bfd_target_elf_flavour)) | |
252b5132 RH |
4210 | { |
4211 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4212 | treg, (int) BFD_RELOC_PCREL_HI16_S); | |
4213 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4214 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4215 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4216 | ? "addiu" : "daddiu"), |
4217 | "t,r,j", treg, treg, (int) BFD_RELOC_PCREL_LO16); | |
4218 | return; | |
4219 | } | |
4220 | ||
4221 | if (offset_expr.X_op != O_symbol | |
4222 | && offset_expr.X_op != O_constant) | |
4223 | { | |
4224 | as_bad (_("expression too complex")); | |
4225 | offset_expr.X_op = O_constant; | |
4226 | } | |
4227 | ||
4228 | if (treg == breg) | |
4229 | { | |
4230 | tempreg = AT; | |
4231 | used_at = 1; | |
4232 | } | |
4233 | else | |
4234 | { | |
4235 | tempreg = treg; | |
4236 | used_at = 0; | |
4237 | } | |
4238 | ||
4239 | if (offset_expr.X_op == O_constant) | |
4240 | load_register (&icnt, tempreg, &offset_expr, dbl); | |
4241 | else if (mips_pic == NO_PIC) | |
4242 | { | |
4243 | /* If this is a reference to an GP relative symbol, we want | |
4244 | addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
4245 | Otherwise we want | |
4246 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
4247 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4248 | If we have a constant, we need two instructions anyhow, | |
4249 | so we may as well always use the latter form. */ | |
4250 | if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET | |
4251 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
4252 | p = NULL; | |
4253 | else | |
4254 | { | |
4255 | frag_grow (20); | |
4256 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4257 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4258 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4259 | ? "addiu" : "daddiu"), |
4260 | "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
4261 | p = frag_var (rs_machine_dependent, 8, 0, | |
4262 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
4263 | mips_opts.warn_about_macros), | |
4264 | offset_expr.X_add_symbol, (offsetT) 0, | |
4265 | (char *) NULL); | |
4266 | } | |
4267 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
4268 | if (p != NULL) | |
4269 | p += 4; | |
4270 | macro_build (p, &icnt, &offset_expr, | |
4271 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4272 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4273 | ? "addiu" : "daddiu"), |
4274 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4275 | } | |
4276 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
4277 | { | |
4278 | /* If this is a reference to an external symbol, and there | |
4279 | is no constant, we want | |
4280 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4281 | For a local symbol, we want | |
4282 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4283 | nop | |
4284 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4285 | ||
4286 | If we have a small constant, and this is a reference to | |
4287 | an external symbol, we want | |
4288 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4289 | nop | |
4290 | addiu $tempreg,$tempreg,<constant> | |
4291 | For a local symbol, we want the same instruction | |
4292 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4293 | addiu instruction. | |
4294 | ||
4295 | If we have a large constant, and this is a reference to | |
4296 | an external symbol, we want | |
4297 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4298 | lui $at,<hiconstant> | |
4299 | addiu $at,$at,<loconstant> | |
4300 | addu $tempreg,$tempreg,$at | |
4301 | For a local symbol, we want the same instruction | |
4302 | sequence, but we output a BFD_RELOC_LO16 reloc on the | |
4303 | addiu instruction. */ | |
4304 | expr1.X_add_number = offset_expr.X_add_number; | |
4305 | offset_expr.X_add_number = 0; | |
4306 | frag_grow (32); | |
4307 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4308 | dbl ? "ld" : "lw", | |
4309 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
4310 | if (expr1.X_add_number == 0) | |
4311 | { | |
4312 | int off; | |
4313 | ||
4314 | if (breg == 0) | |
4315 | off = 0; | |
4316 | else | |
4317 | { | |
4318 | /* We're going to put in an addu instruction using | |
4319 | tempreg, so we may as well insert the nop right | |
4320 | now. */ | |
4321 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4322 | "nop", ""); | |
4323 | off = 4; | |
4324 | } | |
4325 | p = frag_var (rs_machine_dependent, 8 - off, 0, | |
4326 | RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0, | |
4327 | (breg == 0 | |
4328 | ? mips_opts.warn_about_macros | |
4329 | : 0)), | |
4330 | offset_expr.X_add_symbol, (offsetT) 0, | |
4331 | (char *) NULL); | |
4332 | if (breg == 0) | |
4333 | { | |
4334 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4335 | p += 4; | |
4336 | } | |
4337 | macro_build (p, &icnt, &expr1, | |
4338 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4339 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4340 | ? "addiu" : "daddiu"), |
4341 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4342 | /* FIXME: If breg == 0, and the next instruction uses | |
4343 | $tempreg, then if this variant case is used an extra | |
4344 | nop will be generated. */ | |
4345 | } | |
4346 | else if (expr1.X_add_number >= -0x8000 | |
4347 | && expr1.X_add_number < 0x8000) | |
4348 | { | |
4349 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4350 | "nop", ""); | |
4351 | macro_build ((char *) NULL, &icnt, &expr1, | |
4352 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4353 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4354 | ? "addiu" : "daddiu"), |
4355 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4356 | (void) frag_var (rs_machine_dependent, 0, 0, | |
4357 | RELAX_ENCODE (0, 0, -12, -4, 0, 0), | |
4358 | offset_expr.X_add_symbol, (offsetT) 0, | |
4359 | (char *) NULL); | |
4360 | } | |
4361 | else | |
4362 | { | |
4363 | int off1; | |
4364 | ||
4365 | /* If we are going to add in a base register, and the | |
4366 | target register and the base register are the same, | |
4367 | then we are using AT as a temporary register. Since | |
4368 | we want to load the constant into AT, we add our | |
4369 | current AT (from the global offset table) and the | |
4370 | register into the register now, and pretend we were | |
4371 | not using a base register. */ | |
4372 | if (breg != treg) | |
4373 | off1 = 0; | |
4374 | else | |
4375 | { | |
4376 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4377 | "nop", ""); | |
4378 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4379 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4380 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4381 | ? "addu" : "daddu"), |
4382 | "d,v,t", treg, AT, breg); | |
4383 | breg = 0; | |
4384 | tempreg = treg; | |
4385 | off1 = -8; | |
4386 | } | |
4387 | ||
4388 | /* Set mips_optimize around the lui instruction to avoid | |
4389 | inserting an unnecessary nop after the lw. */ | |
4390 | hold_mips_optimize = mips_optimize; | |
4391 | mips_optimize = 2; | |
4392 | macro_build_lui ((char *) NULL, &icnt, &expr1, AT); | |
4393 | mips_optimize = hold_mips_optimize; | |
4394 | ||
4395 | macro_build ((char *) NULL, &icnt, &expr1, | |
4396 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4397 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4398 | ? "addiu" : "daddiu"), |
4399 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); | |
4400 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4401 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4402 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4403 | ? "addu" : "daddu"), |
4404 | "d,v,t", tempreg, tempreg, AT); | |
4405 | (void) frag_var (rs_machine_dependent, 0, 0, | |
4406 | RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0), | |
4407 | offset_expr.X_add_symbol, (offsetT) 0, | |
4408 | (char *) NULL); | |
4409 | used_at = 1; | |
4410 | } | |
4411 | } | |
4412 | else if (mips_pic == SVR4_PIC) | |
4413 | { | |
4414 | int gpdel; | |
4415 | ||
4416 | /* This is the large GOT case. If this is a reference to an | |
4417 | external symbol, and there is no constant, we want | |
4418 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4419 | addu $tempreg,$tempreg,$gp | |
4420 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4421 | For a local symbol, we want | |
4422 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4423 | nop | |
4424 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
4425 | ||
4426 | If we have a small constant, and this is a reference to | |
4427 | an external symbol, we want | |
4428 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4429 | addu $tempreg,$tempreg,$gp | |
4430 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4431 | nop | |
4432 | addiu $tempreg,$tempreg,<constant> | |
4433 | For a local symbol, we want | |
4434 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4435 | nop | |
4436 | addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16) | |
4437 | ||
4438 | If we have a large constant, and this is a reference to | |
4439 | an external symbol, we want | |
4440 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
4441 | addu $tempreg,$tempreg,$gp | |
4442 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
4443 | lui $at,<hiconstant> | |
4444 | addiu $at,$at,<loconstant> | |
4445 | addu $tempreg,$tempreg,$at | |
4446 | For a local symbol, we want | |
4447 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4448 | lui $at,<hiconstant> | |
4449 | addiu $at,$at,<loconstant> (BFD_RELOC_LO16) | |
4450 | addu $tempreg,$tempreg,$at | |
4451 | */ | |
4452 | expr1.X_add_number = offset_expr.X_add_number; | |
4453 | offset_expr.X_add_number = 0; | |
4454 | frag_grow (52); | |
4455 | if (reg_needs_delay (GP)) | |
4456 | gpdel = 4; | |
4457 | else | |
4458 | gpdel = 0; | |
4459 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4460 | tempreg, (int) BFD_RELOC_MIPS_GOT_HI16); | |
4461 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4462 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4463 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4464 | ? "addu" : "daddu"), |
4465 | "d,v,t", tempreg, tempreg, GP); | |
4466 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4467 | dbl ? "ld" : "lw", | |
4468 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16, | |
4469 | tempreg); | |
4470 | if (expr1.X_add_number == 0) | |
4471 | { | |
4472 | int off; | |
4473 | ||
4474 | if (breg == 0) | |
4475 | off = 0; | |
4476 | else | |
4477 | { | |
4478 | /* We're going to put in an addu instruction using | |
4479 | tempreg, so we may as well insert the nop right | |
4480 | now. */ | |
4481 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4482 | "nop", ""); | |
4483 | off = 4; | |
4484 | } | |
4485 | ||
4486 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4487 | RELAX_ENCODE (12 + off, 12 + gpdel, gpdel, | |
4488 | 8 + gpdel, 0, | |
4489 | (breg == 0 | |
4490 | ? mips_opts.warn_about_macros | |
4491 | : 0)), | |
4492 | offset_expr.X_add_symbol, (offsetT) 0, | |
4493 | (char *) NULL); | |
4494 | } | |
4495 | else if (expr1.X_add_number >= -0x8000 | |
4496 | && expr1.X_add_number < 0x8000) | |
4497 | { | |
4498 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4499 | "nop", ""); | |
4500 | macro_build ((char *) NULL, &icnt, &expr1, | |
4501 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4502 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4503 | ? "addiu" : "daddiu"), |
4504 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4505 | ||
4506 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4507 | RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0, | |
4508 | (breg == 0 | |
4509 | ? mips_opts.warn_about_macros | |
4510 | : 0)), | |
4511 | offset_expr.X_add_symbol, (offsetT) 0, | |
4512 | (char *) NULL); | |
4513 | } | |
4514 | else | |
4515 | { | |
4516 | int adj, dreg; | |
4517 | ||
4518 | /* If we are going to add in a base register, and the | |
4519 | target register and the base register are the same, | |
4520 | then we are using AT as a temporary register. Since | |
4521 | we want to load the constant into AT, we add our | |
4522 | current AT (from the global offset table) and the | |
4523 | register into the register now, and pretend we were | |
4524 | not using a base register. */ | |
4525 | if (breg != treg) | |
4526 | { | |
4527 | adj = 0; | |
4528 | dreg = tempreg; | |
4529 | } | |
4530 | else | |
4531 | { | |
4532 | assert (tempreg == AT); | |
4533 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4534 | "nop", ""); | |
4535 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4536 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4537 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4538 | ? "addu" : "daddu"), |
4539 | "d,v,t", treg, AT, breg); | |
4540 | dreg = treg; | |
4541 | adj = 8; | |
4542 | } | |
4543 | ||
4544 | /* Set mips_optimize around the lui instruction to avoid | |
4545 | inserting an unnecessary nop after the lw. */ | |
4546 | hold_mips_optimize = mips_optimize; | |
4547 | mips_optimize = 2; | |
4548 | macro_build_lui ((char *) NULL, &icnt, &expr1, AT); | |
4549 | mips_optimize = hold_mips_optimize; | |
4550 | ||
4551 | macro_build ((char *) NULL, &icnt, &expr1, | |
4552 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4553 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4554 | ? "addiu" : "daddiu"), |
4555 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); | |
4556 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4557 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4558 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4559 | ? "addu" : "daddu"), |
4560 | "d,v,t", dreg, dreg, AT); | |
4561 | ||
4562 | p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0, | |
4563 | RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel, | |
4564 | 8 + gpdel, 0, | |
4565 | (breg == 0 | |
4566 | ? mips_opts.warn_about_macros | |
4567 | : 0)), | |
4568 | offset_expr.X_add_symbol, (offsetT) 0, | |
4569 | (char *) NULL); | |
4570 | ||
4571 | used_at = 1; | |
4572 | } | |
4573 | ||
4574 | if (gpdel > 0) | |
4575 | { | |
4576 | /* This is needed because this instruction uses $gp, but | |
4577 | the first instruction on the main stream does not. */ | |
4578 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4579 | p += 4; | |
4580 | } | |
4581 | macro_build (p, &icnt, &offset_expr, | |
4582 | dbl ? "ld" : "lw", | |
4583 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
4584 | p += 4; | |
4585 | if (expr1.X_add_number >= -0x8000 | |
4586 | && expr1.X_add_number < 0x8000) | |
4587 | { | |
4588 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4589 | p += 4; | |
4590 | macro_build (p, &icnt, &expr1, | |
4591 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4592 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4593 | ? "addiu" : "daddiu"), |
4594 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
4595 | /* FIXME: If add_number is 0, and there was no base | |
4596 | register, the external symbol case ended with a load, | |
4597 | so if the symbol turns out to not be external, and | |
4598 | the next instruction uses tempreg, an unnecessary nop | |
4599 | will be inserted. */ | |
4600 | } | |
4601 | else | |
4602 | { | |
4603 | if (breg == treg) | |
4604 | { | |
4605 | /* We must add in the base register now, as in the | |
4606 | external symbol case. */ | |
4607 | assert (tempreg == AT); | |
4608 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4609 | p += 4; | |
4610 | macro_build (p, &icnt, (expressionS *) NULL, | |
4611 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4612 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4613 | ? "addu" : "daddu"), |
4614 | "d,v,t", treg, AT, breg); | |
4615 | p += 4; | |
4616 | tempreg = treg; | |
4617 | /* We set breg to 0 because we have arranged to add | |
4618 | it in in both cases. */ | |
4619 | breg = 0; | |
4620 | } | |
4621 | ||
4622 | macro_build_lui (p, &icnt, &expr1, AT); | |
4623 | p += 4; | |
4624 | macro_build (p, &icnt, &expr1, | |
4625 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4626 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4627 | ? "addiu" : "daddiu"), |
4628 | "t,r,j", AT, AT, (int) BFD_RELOC_LO16); | |
4629 | p += 4; | |
4630 | macro_build (p, &icnt, (expressionS *) NULL, | |
4631 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4632 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4633 | ? "addu" : "daddu"), |
4634 | "d,v,t", tempreg, tempreg, AT); | |
4635 | p += 4; | |
4636 | } | |
4637 | } | |
4638 | else if (mips_pic == EMBEDDED_PIC) | |
4639 | { | |
4640 | /* We use | |
4641 | addiu $tempreg,$gp,<sym> (BFD_RELOC_MIPS_GPREL) | |
4642 | */ | |
4643 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4644 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4645 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4646 | ? "addiu" : "daddiu"), |
4647 | "t,r,j", tempreg, GP, (int) BFD_RELOC_MIPS_GPREL); | |
4648 | } | |
4649 | else | |
4650 | abort (); | |
4651 | ||
4652 | if (breg != 0) | |
4653 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4654 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4655 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4656 | ? "addu" : "daddu"), |
4657 | "d,v,t", treg, tempreg, breg); | |
4658 | ||
4659 | if (! used_at) | |
4660 | return; | |
4661 | ||
4662 | break; | |
4663 | ||
4664 | case M_J_A: | |
4665 | /* The j instruction may not be used in PIC code, since it | |
4666 | requires an absolute address. We convert it to a b | |
4667 | instruction. */ | |
4668 | if (mips_pic == NO_PIC) | |
4669 | macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a"); | |
4670 | else | |
4671 | macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p"); | |
4672 | return; | |
4673 | ||
4674 | /* The jal instructions must be handled as macros because when | |
4675 | generating PIC code they expand to multi-instruction | |
4676 | sequences. Normally they are simple instructions. */ | |
4677 | case M_JAL_1: | |
4678 | dreg = RA; | |
4679 | /* Fall through. */ | |
4680 | case M_JAL_2: | |
4681 | if (mips_pic == NO_PIC | |
4682 | || mips_pic == EMBEDDED_PIC) | |
4683 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", | |
4684 | "d,s", dreg, sreg); | |
4685 | else if (mips_pic == SVR4_PIC) | |
4686 | { | |
4687 | if (sreg != PIC_CALL_REG) | |
4688 | as_warn (_("MIPS PIC call to register other than $25")); | |
bdaaa2e1 | 4689 | |
252b5132 RH |
4690 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", |
4691 | "d,s", dreg, sreg); | |
4692 | if (mips_cprestore_offset < 0) | |
4693 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
4694 | else | |
4695 | { | |
4696 | expr1.X_add_number = mips_cprestore_offset; | |
4697 | macro_build ((char *) NULL, &icnt, &expr1, | |
4698 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4699 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4700 | ? "lw" : "ld"), |
4701 | "t,o(b)", GP, (int) BFD_RELOC_LO16, mips_frame_reg); | |
4702 | } | |
4703 | } | |
4704 | else | |
4705 | abort (); | |
4706 | ||
4707 | return; | |
4708 | ||
4709 | case M_JAL_A: | |
4710 | if (mips_pic == NO_PIC) | |
4711 | macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a"); | |
4712 | else if (mips_pic == SVR4_PIC) | |
4713 | { | |
4714 | /* If this is a reference to an external symbol, and we are | |
4715 | using a small GOT, we want | |
4716 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16) | |
4717 | nop | |
4718 | jalr $25 | |
4719 | nop | |
4720 | lw $gp,cprestore($sp) | |
4721 | The cprestore value is set using the .cprestore | |
4722 | pseudo-op. If we are using a big GOT, we want | |
4723 | lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16) | |
4724 | addu $25,$25,$gp | |
4725 | lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16) | |
4726 | nop | |
4727 | jalr $25 | |
4728 | nop | |
4729 | lw $gp,cprestore($sp) | |
4730 | If the symbol is not external, we want | |
4731 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
4732 | nop | |
4733 | addiu $25,$25,<sym> (BFD_RELOC_LO16) | |
4734 | jalr $25 | |
4735 | nop | |
4736 | lw $gp,cprestore($sp) */ | |
4737 | frag_grow (40); | |
4738 | if (! mips_big_got) | |
4739 | { | |
4740 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4741 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4742 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4743 | ? "lw" : "ld"), |
4744 | "t,o(b)", PIC_CALL_REG, | |
4745 | (int) BFD_RELOC_MIPS_CALL16, GP); | |
4746 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4747 | "nop", ""); | |
4748 | p = frag_var (rs_machine_dependent, 4, 0, | |
4749 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), | |
4750 | offset_expr.X_add_symbol, (offsetT) 0, | |
4751 | (char *) NULL); | |
4752 | } | |
4753 | else | |
4754 | { | |
4755 | int gpdel; | |
4756 | ||
4757 | if (reg_needs_delay (GP)) | |
4758 | gpdel = 4; | |
4759 | else | |
4760 | gpdel = 0; | |
4761 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
4762 | PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16); | |
4763 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4764 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4765 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4766 | ? "addu" : "daddu"), |
4767 | "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP); | |
4768 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
4769 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4770 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4771 | ? "lw" : "ld"), |
4772 | "t,o(b)", PIC_CALL_REG, | |
4773 | (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG); | |
4774 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4775 | "nop", ""); | |
4776 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
4777 | RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel, | |
4778 | 0, 0), | |
4779 | offset_expr.X_add_symbol, (offsetT) 0, | |
4780 | (char *) NULL); | |
4781 | if (gpdel > 0) | |
4782 | { | |
4783 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4784 | p += 4; | |
4785 | } | |
4786 | macro_build (p, &icnt, &offset_expr, | |
4787 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4788 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4789 | ? "lw" : "ld"), |
4790 | "t,o(b)", PIC_CALL_REG, | |
4791 | (int) BFD_RELOC_MIPS_GOT16, GP); | |
4792 | p += 4; | |
4793 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
4794 | p += 4; | |
bdaaa2e1 | 4795 | } |
252b5132 RH |
4796 | macro_build (p, &icnt, &offset_expr, |
4797 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4798 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4799 | ? "addiu" : "daddiu"), |
4800 | "t,r,j", PIC_CALL_REG, PIC_CALL_REG, | |
4801 | (int) BFD_RELOC_LO16); | |
4802 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4803 | "jalr", "s", PIC_CALL_REG); | |
4804 | if (mips_cprestore_offset < 0) | |
4805 | as_warn (_("No .cprestore pseudo-op used in PIC code")); | |
4806 | else | |
4807 | { | |
4808 | if (mips_opts.noreorder) | |
4809 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
4810 | "nop", ""); | |
4811 | expr1.X_add_number = mips_cprestore_offset; | |
4812 | macro_build ((char *) NULL, &icnt, &expr1, | |
4813 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 4814 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
4815 | ? "lw" : "ld"), |
4816 | "t,o(b)", GP, (int) BFD_RELOC_LO16, | |
4817 | mips_frame_reg); | |
4818 | } | |
4819 | } | |
4820 | else if (mips_pic == EMBEDDED_PIC) | |
4821 | { | |
4822 | macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p"); | |
4823 | /* The linker may expand the call to a longer sequence which | |
4824 | uses $at, so we must break rather than return. */ | |
4825 | break; | |
4826 | } | |
4827 | else | |
4828 | abort (); | |
4829 | ||
4830 | return; | |
4831 | ||
4832 | case M_LB_AB: | |
4833 | s = "lb"; | |
4834 | goto ld; | |
4835 | case M_LBU_AB: | |
4836 | s = "lbu"; | |
4837 | goto ld; | |
4838 | case M_LH_AB: | |
4839 | s = "lh"; | |
4840 | goto ld; | |
4841 | case M_LHU_AB: | |
4842 | s = "lhu"; | |
4843 | goto ld; | |
4844 | case M_LW_AB: | |
4845 | s = "lw"; | |
4846 | goto ld; | |
4847 | case M_LWC0_AB: | |
4848 | s = "lwc0"; | |
bdaaa2e1 | 4849 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4850 | coproc = 1; |
4851 | goto ld; | |
4852 | case M_LWC1_AB: | |
4853 | s = "lwc1"; | |
bdaaa2e1 | 4854 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4855 | coproc = 1; |
4856 | goto ld; | |
4857 | case M_LWC2_AB: | |
4858 | s = "lwc2"; | |
bdaaa2e1 | 4859 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4860 | coproc = 1; |
4861 | goto ld; | |
4862 | case M_LWC3_AB: | |
4863 | s = "lwc3"; | |
bdaaa2e1 | 4864 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4865 | coproc = 1; |
4866 | goto ld; | |
4867 | case M_LWL_AB: | |
4868 | s = "lwl"; | |
4869 | lr = 1; | |
4870 | goto ld; | |
4871 | case M_LWR_AB: | |
4872 | s = "lwr"; | |
4873 | lr = 1; | |
4874 | goto ld; | |
4875 | case M_LDC1_AB: | |
156c2f8b | 4876 | if (mips_cpu == CPU_R4650) |
252b5132 RH |
4877 | { |
4878 | as_bad (_("opcode not supported on this processor")); | |
4879 | return; | |
4880 | } | |
4881 | s = "ldc1"; | |
bdaaa2e1 | 4882 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4883 | coproc = 1; |
4884 | goto ld; | |
4885 | case M_LDC2_AB: | |
4886 | s = "ldc2"; | |
bdaaa2e1 | 4887 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4888 | coproc = 1; |
4889 | goto ld; | |
4890 | case M_LDC3_AB: | |
4891 | s = "ldc3"; | |
bdaaa2e1 | 4892 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4893 | coproc = 1; |
4894 | goto ld; | |
4895 | case M_LDL_AB: | |
4896 | s = "ldl"; | |
4897 | lr = 1; | |
4898 | goto ld; | |
4899 | case M_LDR_AB: | |
4900 | s = "ldr"; | |
4901 | lr = 1; | |
4902 | goto ld; | |
4903 | case M_LL_AB: | |
4904 | s = "ll"; | |
4905 | goto ld; | |
4906 | case M_LLD_AB: | |
4907 | s = "lld"; | |
4908 | goto ld; | |
4909 | case M_LWU_AB: | |
4910 | s = "lwu"; | |
4911 | ld: | |
4912 | if (breg == treg || coproc || lr) | |
4913 | { | |
4914 | tempreg = AT; | |
4915 | used_at = 1; | |
4916 | } | |
4917 | else | |
4918 | { | |
4919 | tempreg = treg; | |
4920 | used_at = 0; | |
4921 | } | |
4922 | goto ld_st; | |
4923 | case M_SB_AB: | |
4924 | s = "sb"; | |
4925 | goto st; | |
4926 | case M_SH_AB: | |
4927 | s = "sh"; | |
4928 | goto st; | |
4929 | case M_SW_AB: | |
4930 | s = "sw"; | |
4931 | goto st; | |
4932 | case M_SWC0_AB: | |
4933 | s = "swc0"; | |
bdaaa2e1 | 4934 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4935 | coproc = 1; |
4936 | goto st; | |
4937 | case M_SWC1_AB: | |
4938 | s = "swc1"; | |
bdaaa2e1 | 4939 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4940 | coproc = 1; |
4941 | goto st; | |
4942 | case M_SWC2_AB: | |
4943 | s = "swc2"; | |
bdaaa2e1 | 4944 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4945 | coproc = 1; |
4946 | goto st; | |
4947 | case M_SWC3_AB: | |
4948 | s = "swc3"; | |
bdaaa2e1 | 4949 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4950 | coproc = 1; |
4951 | goto st; | |
4952 | case M_SWL_AB: | |
4953 | s = "swl"; | |
4954 | goto st; | |
4955 | case M_SWR_AB: | |
4956 | s = "swr"; | |
4957 | goto st; | |
4958 | case M_SC_AB: | |
4959 | s = "sc"; | |
4960 | goto st; | |
4961 | case M_SCD_AB: | |
4962 | s = "scd"; | |
4963 | goto st; | |
4964 | case M_SDC1_AB: | |
156c2f8b | 4965 | if (mips_cpu == CPU_R4650) |
252b5132 RH |
4966 | { |
4967 | as_bad (_("opcode not supported on this processor")); | |
4968 | return; | |
4969 | } | |
4970 | s = "sdc1"; | |
4971 | coproc = 1; | |
bdaaa2e1 | 4972 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4973 | goto st; |
4974 | case M_SDC2_AB: | |
4975 | s = "sdc2"; | |
bdaaa2e1 | 4976 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4977 | coproc = 1; |
4978 | goto st; | |
4979 | case M_SDC3_AB: | |
4980 | s = "sdc3"; | |
bdaaa2e1 | 4981 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4982 | coproc = 1; |
4983 | goto st; | |
4984 | case M_SDL_AB: | |
4985 | s = "sdl"; | |
4986 | goto st; | |
4987 | case M_SDR_AB: | |
4988 | s = "sdr"; | |
4989 | st: | |
4990 | tempreg = AT; | |
4991 | used_at = 1; | |
4992 | ld_st: | |
bdaaa2e1 | 4993 | /* Itbl support may require additional care here. */ |
252b5132 RH |
4994 | if (mask == M_LWC1_AB |
4995 | || mask == M_SWC1_AB | |
4996 | || mask == M_LDC1_AB | |
4997 | || mask == M_SDC1_AB | |
4998 | || mask == M_L_DAB | |
4999 | || mask == M_S_DAB) | |
5000 | fmt = "T,o(b)"; | |
5001 | else if (coproc) | |
5002 | fmt = "E,o(b)"; | |
5003 | else | |
5004 | fmt = "t,o(b)"; | |
5005 | ||
5006 | if (offset_expr.X_op != O_constant | |
5007 | && offset_expr.X_op != O_symbol) | |
5008 | { | |
5009 | as_bad (_("expression too complex")); | |
5010 | offset_expr.X_op = O_constant; | |
5011 | } | |
5012 | ||
5013 | /* A constant expression in PIC code can be handled just as it | |
5014 | is in non PIC code. */ | |
5015 | if (mips_pic == NO_PIC | |
5016 | || offset_expr.X_op == O_constant) | |
5017 | { | |
5018 | /* If this is a reference to a GP relative symbol, and there | |
5019 | is no base register, we want | |
5020 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5021 | Otherwise, if there is no base register, we want | |
5022 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5023 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5024 | If we have a constant, we need two instructions anyhow, | |
5025 | so we always use the latter form. | |
5026 | ||
5027 | If we have a base register, and this is a reference to a | |
5028 | GP relative symbol, we want | |
5029 | addu $tempreg,$breg,$gp | |
5030 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL) | |
5031 | Otherwise we want | |
5032 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) | |
5033 | addu $tempreg,$tempreg,$breg | |
5034 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) | |
5035 | With a constant we always use the latter case. */ | |
5036 | if (breg == 0) | |
5037 | { | |
5038 | if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET | |
5039 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
5040 | p = NULL; | |
5041 | else | |
5042 | { | |
5043 | frag_grow (20); | |
5044 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5045 | treg, (int) BFD_RELOC_MIPS_GPREL, GP); | |
5046 | p = frag_var (rs_machine_dependent, 8, 0, | |
5047 | RELAX_ENCODE (4, 8, 0, 4, 0, | |
5048 | (mips_opts.warn_about_macros | |
5049 | || (used_at | |
5050 | && mips_opts.noat))), | |
5051 | offset_expr.X_add_symbol, (offsetT) 0, | |
5052 | (char *) NULL); | |
5053 | used_at = 0; | |
5054 | } | |
5055 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5056 | if (p != NULL) | |
5057 | p += 4; | |
5058 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5059 | (int) BFD_RELOC_LO16, tempreg); | |
5060 | } | |
5061 | else | |
5062 | { | |
5063 | if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET | |
5064 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
5065 | p = NULL; | |
5066 | else | |
5067 | { | |
5068 | frag_grow (28); | |
5069 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5070 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5071 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5072 | ? "addu" : "daddu"), |
5073 | "d,v,t", tempreg, breg, GP); | |
5074 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5075 | treg, (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5076 | p = frag_var (rs_machine_dependent, 12, 0, | |
5077 | RELAX_ENCODE (8, 12, 0, 8, 0, 0), | |
5078 | offset_expr.X_add_symbol, (offsetT) 0, | |
5079 | (char *) NULL); | |
5080 | } | |
5081 | macro_build_lui (p, &icnt, &offset_expr, tempreg); | |
5082 | if (p != NULL) | |
5083 | p += 4; | |
5084 | macro_build (p, &icnt, (expressionS *) NULL, | |
5085 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5086 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5087 | ? "addu" : "daddu"), |
5088 | "d,v,t", tempreg, tempreg, breg); | |
5089 | if (p != NULL) | |
5090 | p += 4; | |
5091 | macro_build (p, &icnt, &offset_expr, s, fmt, treg, | |
5092 | (int) BFD_RELOC_LO16, tempreg); | |
5093 | } | |
5094 | } | |
5095 | else if (mips_pic == SVR4_PIC && ! mips_big_got) | |
5096 | { | |
5097 | /* If this is a reference to an external symbol, we want | |
5098 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5099 | nop | |
5100 | <op> $treg,0($tempreg) | |
5101 | Otherwise we want | |
5102 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5103 | nop | |
5104 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5105 | <op> $treg,0($tempreg) | |
5106 | If there is a base register, we add it to $tempreg before | |
5107 | the <op>. If there is a constant, we stick it in the | |
5108 | <op> instruction. We don't handle constants larger than | |
5109 | 16 bits, because we have no way to load the upper 16 bits | |
5110 | (actually, we could handle them for the subset of cases | |
5111 | in which we are not using $at). */ | |
5112 | assert (offset_expr.X_op == O_symbol); | |
5113 | expr1.X_add_number = offset_expr.X_add_number; | |
5114 | offset_expr.X_add_number = 0; | |
5115 | if (expr1.X_add_number < -0x8000 | |
5116 | || expr1.X_add_number >= 0x8000) | |
5117 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5118 | frag_grow (20); | |
5119 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5120 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5121 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5122 | ? "lw" : "ld"), |
5123 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5124 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
bdaaa2e1 | 5125 | p = frag_var (rs_machine_dependent, 4, 0, |
252b5132 RH |
5126 | RELAX_ENCODE (0, 4, -8, 0, 0, 0), |
5127 | offset_expr.X_add_symbol, (offsetT) 0, | |
5128 | (char *) NULL); | |
5129 | macro_build (p, &icnt, &offset_expr, | |
5130 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5131 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5132 | ? "addiu" : "daddiu"), |
5133 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
5134 | if (breg != 0) | |
5135 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5136 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5137 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5138 | ? "addu" : "daddu"), |
5139 | "d,v,t", tempreg, tempreg, breg); | |
5140 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5141 | (int) BFD_RELOC_LO16, tempreg); | |
5142 | } | |
5143 | else if (mips_pic == SVR4_PIC) | |
5144 | { | |
5145 | int gpdel; | |
5146 | ||
5147 | /* If this is a reference to an external symbol, we want | |
5148 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5149 | addu $tempreg,$tempreg,$gp | |
5150 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) | |
5151 | <op> $treg,0($tempreg) | |
5152 | Otherwise we want | |
5153 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5154 | nop | |
5155 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) | |
5156 | <op> $treg,0($tempreg) | |
5157 | If there is a base register, we add it to $tempreg before | |
5158 | the <op>. If there is a constant, we stick it in the | |
5159 | <op> instruction. We don't handle constants larger than | |
5160 | 16 bits, because we have no way to load the upper 16 bits | |
5161 | (actually, we could handle them for the subset of cases | |
5162 | in which we are not using $at). */ | |
5163 | assert (offset_expr.X_op == O_symbol); | |
5164 | expr1.X_add_number = offset_expr.X_add_number; | |
5165 | offset_expr.X_add_number = 0; | |
5166 | if (expr1.X_add_number < -0x8000 | |
5167 | || expr1.X_add_number >= 0x8000) | |
5168 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5169 | if (reg_needs_delay (GP)) | |
5170 | gpdel = 4; | |
5171 | else | |
5172 | gpdel = 0; | |
5173 | frag_grow (36); | |
5174 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5175 | tempreg, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5176 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5177 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5178 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5179 | ? "addu" : "daddu"), |
5180 | "d,v,t", tempreg, tempreg, GP); | |
5181 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5182 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5183 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5184 | ? "lw" : "ld"), |
5185 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16, | |
5186 | tempreg); | |
5187 | p = frag_var (rs_machine_dependent, 12 + gpdel, 0, | |
5188 | RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0), | |
5189 | offset_expr.X_add_symbol, (offsetT) 0, (char *) NULL); | |
5190 | if (gpdel > 0) | |
5191 | { | |
5192 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5193 | p += 4; | |
5194 | } | |
5195 | macro_build (p, &icnt, &offset_expr, | |
5196 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5197 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5198 | ? "lw" : "ld"), |
5199 | "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5200 | p += 4; | |
5201 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5202 | p += 4; | |
5203 | macro_build (p, &icnt, &offset_expr, | |
5204 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5205 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5206 | ? "addiu" : "daddiu"), |
5207 | "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16); | |
5208 | if (breg != 0) | |
5209 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5210 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5211 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5212 | ? "addu" : "daddu"), |
5213 | "d,v,t", tempreg, tempreg, breg); | |
5214 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg, | |
5215 | (int) BFD_RELOC_LO16, tempreg); | |
5216 | } | |
5217 | else if (mips_pic == EMBEDDED_PIC) | |
5218 | { | |
5219 | /* If there is no base register, we want | |
5220 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5221 | If there is a base register, we want | |
5222 | addu $tempreg,$breg,$gp | |
5223 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GPREL) | |
5224 | */ | |
5225 | assert (offset_expr.X_op == O_symbol); | |
5226 | if (breg == 0) | |
5227 | { | |
5228 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5229 | treg, (int) BFD_RELOC_MIPS_GPREL, GP); | |
5230 | used_at = 0; | |
5231 | } | |
5232 | else | |
5233 | { | |
5234 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5235 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5236 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5237 | ? "addu" : "daddu"), |
5238 | "d,v,t", tempreg, breg, GP); | |
5239 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, | |
5240 | treg, (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5241 | } | |
5242 | } | |
5243 | else | |
5244 | abort (); | |
5245 | ||
5246 | if (! used_at) | |
5247 | return; | |
5248 | ||
5249 | break; | |
5250 | ||
5251 | case M_LI: | |
5252 | case M_LI_S: | |
5253 | load_register (&icnt, treg, &imm_expr, 0); | |
5254 | return; | |
5255 | ||
5256 | case M_DLI: | |
5257 | load_register (&icnt, treg, &imm_expr, 1); | |
5258 | return; | |
5259 | ||
5260 | case M_LI_SS: | |
5261 | if (imm_expr.X_op == O_constant) | |
5262 | { | |
5263 | load_register (&icnt, AT, &imm_expr, 0); | |
5264 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5265 | "mtc1", "t,G", AT, treg); | |
5266 | break; | |
5267 | } | |
5268 | else | |
5269 | { | |
5270 | assert (offset_expr.X_op == O_symbol | |
5271 | && strcmp (segment_name (S_GET_SEGMENT | |
5272 | (offset_expr.X_add_symbol)), | |
5273 | ".lit4") == 0 | |
5274 | && offset_expr.X_add_number == 0); | |
5275 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5276 | treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5277 | return; | |
5278 | } | |
5279 | ||
5280 | case M_LI_D: | |
5281 | /* If we have a constant in IMM_EXPR, then in mips3 mode it is | |
5282 | the entire value, and in mips1 mode it is the high order 32 | |
5283 | bits of the value and the low order 32 bits are either zero | |
5284 | or in offset_expr. */ | |
5285 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) | |
5286 | { | |
9ce8a5dd | 5287 | if (ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5288 | load_register (&icnt, treg, &imm_expr, 1); |
5289 | else | |
5290 | { | |
5291 | int hreg, lreg; | |
5292 | ||
5293 | if (target_big_endian) | |
5294 | { | |
5295 | hreg = treg; | |
5296 | lreg = treg + 1; | |
5297 | } | |
5298 | else | |
5299 | { | |
5300 | hreg = treg + 1; | |
5301 | lreg = treg; | |
5302 | } | |
5303 | ||
5304 | if (hreg <= 31) | |
5305 | load_register (&icnt, hreg, &imm_expr, 0); | |
5306 | if (lreg <= 31) | |
5307 | { | |
5308 | if (offset_expr.X_op == O_absent) | |
5309 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", | |
5310 | lreg, 0); | |
5311 | else | |
5312 | { | |
5313 | assert (offset_expr.X_op == O_constant); | |
5314 | load_register (&icnt, lreg, &offset_expr, 0); | |
5315 | } | |
5316 | } | |
5317 | } | |
5318 | return; | |
5319 | } | |
5320 | ||
5321 | /* We know that sym is in the .rdata section. First we get the | |
5322 | upper 16 bits of the address. */ | |
5323 | if (mips_pic == NO_PIC) | |
5324 | { | |
5325 | /* FIXME: This won't work for a 64 bit address. */ | |
5326 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5327 | } | |
5328 | else if (mips_pic == SVR4_PIC) | |
5329 | { | |
5330 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5331 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5332 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5333 | ? "lw" : "ld"), |
5334 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5335 | } | |
5336 | else if (mips_pic == EMBEDDED_PIC) | |
5337 | { | |
5338 | /* For embedded PIC we pick up the entire address off $gp in | |
5339 | a single instruction. */ | |
5340 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5341 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5342 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5343 | ? "addiu" : "daddiu"), |
5344 | "t,r,j", AT, GP, (int) BFD_RELOC_MIPS_GPREL); | |
5345 | offset_expr.X_op = O_constant; | |
5346 | offset_expr.X_add_number = 0; | |
5347 | } | |
5348 | else | |
5349 | abort (); | |
bdaaa2e1 | 5350 | |
252b5132 | 5351 | /* Now we load the register(s). */ |
9ce8a5dd | 5352 | if (ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5353 | macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)", |
5354 | treg, (int) BFD_RELOC_LO16, AT); | |
5355 | else | |
5356 | { | |
5357 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5358 | treg, (int) BFD_RELOC_LO16, AT); | |
5359 | if (treg != 31) | |
5360 | { | |
5361 | /* FIXME: How in the world do we deal with the possible | |
5362 | overflow here? */ | |
5363 | offset_expr.X_add_number += 4; | |
5364 | macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)", | |
5365 | treg + 1, (int) BFD_RELOC_LO16, AT); | |
5366 | } | |
5367 | } | |
5368 | ||
5369 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5370 | does not become a variant frag. */ | |
5371 | frag_wane (frag_now); | |
5372 | frag_new (0); | |
5373 | ||
5374 | break; | |
5375 | ||
5376 | case M_LI_DD: | |
5377 | /* If we have a constant in IMM_EXPR, then in mips3 mode it is | |
5378 | the entire value, and in mips1 mode it is the high order 32 | |
5379 | bits of the value and the low order 32 bits are either zero | |
5380 | or in offset_expr. */ | |
5381 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) | |
5382 | { | |
9ce8a5dd GRK |
5383 | load_register (&icnt, AT, &imm_expr, ISA_HAS_64BIT_REGS (mips_opts.isa)); |
5384 | if (ISA_HAS_64BIT_REGS (mips_opts.isa)) | |
252b5132 RH |
5385 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, |
5386 | "dmtc1", "t,S", AT, treg); | |
5387 | else | |
5388 | { | |
5389 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5390 | "mtc1", "t,G", AT, treg + 1); | |
5391 | if (offset_expr.X_op == O_absent) | |
5392 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5393 | "mtc1", "t,G", 0, treg); | |
5394 | else | |
5395 | { | |
5396 | assert (offset_expr.X_op == O_constant); | |
5397 | load_register (&icnt, AT, &offset_expr, 0); | |
5398 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5399 | "mtc1", "t,G", AT, treg); | |
5400 | } | |
5401 | } | |
5402 | break; | |
5403 | } | |
5404 | ||
5405 | assert (offset_expr.X_op == O_symbol | |
5406 | && offset_expr.X_add_number == 0); | |
5407 | s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol)); | |
5408 | if (strcmp (s, ".lit8") == 0) | |
5409 | { | |
9ce8a5dd | 5410 | if (mips_opts.isa != 1) |
252b5132 RH |
5411 | { |
5412 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5413 | "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP); | |
5414 | return; | |
5415 | } | |
5416 | breg = GP; | |
5417 | r = BFD_RELOC_MIPS_LITERAL; | |
5418 | goto dob; | |
5419 | } | |
5420 | else | |
5421 | { | |
5422 | assert (strcmp (s, RDATA_SECTION_NAME) == 0); | |
5423 | if (mips_pic == SVR4_PIC) | |
5424 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5425 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5426 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5427 | ? "lw" : "ld"), |
5428 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5429 | else | |
5430 | { | |
5431 | /* FIXME: This won't work for a 64 bit address. */ | |
5432 | macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT); | |
5433 | } | |
bdaaa2e1 | 5434 | |
9ce8a5dd | 5435 | if (mips_opts.isa != 1) |
252b5132 RH |
5436 | { |
5437 | macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1", | |
5438 | "T,o(b)", treg, (int) BFD_RELOC_LO16, AT); | |
5439 | ||
5440 | /* To avoid confusion in tc_gen_reloc, we must ensure | |
5441 | that this does not become a variant frag. */ | |
5442 | frag_wane (frag_now); | |
5443 | frag_new (0); | |
5444 | ||
5445 | break; | |
5446 | } | |
5447 | breg = AT; | |
5448 | r = BFD_RELOC_LO16; | |
5449 | goto dob; | |
5450 | } | |
5451 | ||
5452 | case M_L_DOB: | |
156c2f8b | 5453 | if (mips_cpu == CPU_R4650) |
252b5132 RH |
5454 | { |
5455 | as_bad (_("opcode not supported on this processor")); | |
5456 | return; | |
5457 | } | |
5458 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5459 | to adjust when loading from memory. */ | |
5460 | r = BFD_RELOC_LO16; | |
5461 | dob: | |
9ce8a5dd | 5462 | assert (mips_opts.isa == 1); |
252b5132 RH |
5463 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", |
5464 | target_big_endian ? treg + 1 : treg, | |
5465 | (int) r, breg); | |
5466 | /* FIXME: A possible overflow which I don't know how to deal | |
5467 | with. */ | |
5468 | offset_expr.X_add_number += 4; | |
5469 | macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)", | |
5470 | target_big_endian ? treg : treg + 1, | |
5471 | (int) r, breg); | |
5472 | ||
5473 | /* To avoid confusion in tc_gen_reloc, we must ensure that this | |
5474 | does not become a variant frag. */ | |
5475 | frag_wane (frag_now); | |
5476 | frag_new (0); | |
5477 | ||
5478 | if (breg != AT) | |
5479 | return; | |
5480 | break; | |
5481 | ||
5482 | case M_L_DAB: | |
5483 | /* | |
5484 | * The MIPS assembler seems to check for X_add_number not | |
5485 | * being double aligned and generating: | |
5486 | * lui at,%hi(foo+1) | |
5487 | * addu at,at,v1 | |
5488 | * addiu at,at,%lo(foo+1) | |
5489 | * lwc1 f2,0(at) | |
5490 | * lwc1 f3,4(at) | |
5491 | * But, the resulting address is the same after relocation so why | |
5492 | * generate the extra instruction? | |
5493 | */ | |
156c2f8b | 5494 | if (mips_cpu == CPU_R4650) |
252b5132 RH |
5495 | { |
5496 | as_bad (_("opcode not supported on this processor")); | |
5497 | return; | |
5498 | } | |
bdaaa2e1 | 5499 | /* Itbl support may require additional care here. */ |
252b5132 | 5500 | coproc = 1; |
9ce8a5dd | 5501 | if (mips_opts.isa != 1) |
252b5132 RH |
5502 | { |
5503 | s = "ldc1"; | |
5504 | goto ld; | |
5505 | } | |
5506 | ||
5507 | s = "lwc1"; | |
5508 | fmt = "T,o(b)"; | |
5509 | goto ldd_std; | |
5510 | ||
5511 | case M_S_DAB: | |
156c2f8b | 5512 | if (mips_cpu == CPU_R4650) |
252b5132 RH |
5513 | { |
5514 | as_bad (_("opcode not supported on this processor")); | |
5515 | return; | |
5516 | } | |
5517 | ||
9ce8a5dd | 5518 | if (mips_opts.isa != 1) |
252b5132 RH |
5519 | { |
5520 | s = "sdc1"; | |
5521 | goto st; | |
5522 | } | |
5523 | ||
5524 | s = "swc1"; | |
5525 | fmt = "T,o(b)"; | |
bdaaa2e1 | 5526 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5527 | coproc = 1; |
5528 | goto ldd_std; | |
5529 | ||
5530 | case M_LD_AB: | |
9ce8a5dd | 5531 | if (ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5532 | { |
5533 | s = "ld"; | |
5534 | goto ld; | |
5535 | } | |
5536 | ||
5537 | s = "lw"; | |
5538 | fmt = "t,o(b)"; | |
5539 | goto ldd_std; | |
5540 | ||
5541 | case M_SD_AB: | |
9ce8a5dd | 5542 | if (ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5543 | { |
5544 | s = "sd"; | |
5545 | goto st; | |
5546 | } | |
5547 | ||
5548 | s = "sw"; | |
5549 | fmt = "t,o(b)"; | |
5550 | ||
5551 | ldd_std: | |
5552 | if (offset_expr.X_op != O_symbol | |
5553 | && offset_expr.X_op != O_constant) | |
5554 | { | |
5555 | as_bad (_("expression too complex")); | |
5556 | offset_expr.X_op = O_constant; | |
5557 | } | |
5558 | ||
5559 | /* Even on a big endian machine $fn comes before $fn+1. We have | |
5560 | to adjust when loading from memory. We set coproc if we must | |
5561 | load $fn+1 first. */ | |
bdaaa2e1 | 5562 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5563 | if (! target_big_endian) |
5564 | coproc = 0; | |
5565 | ||
5566 | if (mips_pic == NO_PIC | |
5567 | || offset_expr.X_op == O_constant) | |
5568 | { | |
5569 | /* If this is a reference to a GP relative symbol, we want | |
5570 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5571 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL) | |
5572 | If we have a base register, we use this | |
5573 | addu $at,$breg,$gp | |
5574 | <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL) | |
5575 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL) | |
5576 | If this is not a GP relative symbol, we want | |
5577 | lui $at,<sym> (BFD_RELOC_HI16_S) | |
5578 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5579 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5580 | If there is a base register, we add it to $at after the | |
5581 | lui instruction. If there is a constant, we always use | |
5582 | the last case. */ | |
5583 | if ((valueT) offset_expr.X_add_number >= MAX_GPREL_OFFSET | |
5584 | || nopic_need_relax (offset_expr.X_add_symbol, 1)) | |
5585 | { | |
5586 | p = NULL; | |
5587 | used_at = 1; | |
5588 | } | |
5589 | else | |
5590 | { | |
5591 | int off; | |
5592 | ||
5593 | if (breg == 0) | |
5594 | { | |
5595 | frag_grow (28); | |
5596 | tempreg = GP; | |
5597 | off = 0; | |
5598 | used_at = 0; | |
5599 | } | |
5600 | else | |
5601 | { | |
5602 | frag_grow (36); | |
5603 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5604 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5605 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5606 | ? "addu" : "daddu"), |
5607 | "d,v,t", AT, breg, GP); | |
5608 | tempreg = AT; | |
5609 | off = 4; | |
5610 | used_at = 1; | |
5611 | } | |
5612 | ||
bdaaa2e1 | 5613 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5614 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
5615 | coproc ? treg + 1 : treg, | |
5616 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5617 | offset_expr.X_add_number += 4; | |
5618 | ||
5619 | /* Set mips_optimize to 2 to avoid inserting an | |
5620 | undesired nop. */ | |
5621 | hold_mips_optimize = mips_optimize; | |
5622 | mips_optimize = 2; | |
bdaaa2e1 | 5623 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5624 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
5625 | coproc ? treg : treg + 1, | |
5626 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5627 | mips_optimize = hold_mips_optimize; | |
5628 | ||
5629 | p = frag_var (rs_machine_dependent, 12 + off, 0, | |
5630 | RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1, | |
5631 | used_at && mips_opts.noat), | |
5632 | offset_expr.X_add_symbol, (offsetT) 0, | |
5633 | (char *) NULL); | |
5634 | ||
5635 | /* We just generated two relocs. When tc_gen_reloc | |
5636 | handles this case, it will skip the first reloc and | |
5637 | handle the second. The second reloc already has an | |
5638 | extra addend of 4, which we added above. We must | |
5639 | subtract it out, and then subtract another 4 to make | |
5640 | the first reloc come out right. The second reloc | |
5641 | will come out right because we are going to add 4 to | |
5642 | offset_expr when we build its instruction below. | |
5643 | ||
5644 | If we have a symbol, then we don't want to include | |
5645 | the offset, because it will wind up being included | |
5646 | when we generate the reloc. */ | |
5647 | ||
5648 | if (offset_expr.X_op == O_constant) | |
5649 | offset_expr.X_add_number -= 8; | |
5650 | else | |
5651 | { | |
5652 | offset_expr.X_add_number = -4; | |
5653 | offset_expr.X_op = O_constant; | |
5654 | } | |
5655 | } | |
5656 | macro_build_lui (p, &icnt, &offset_expr, AT); | |
5657 | if (p != NULL) | |
5658 | p += 4; | |
5659 | if (breg != 0) | |
5660 | { | |
5661 | macro_build (p, &icnt, (expressionS *) NULL, | |
5662 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5663 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5664 | ? "addu" : "daddu"), |
5665 | "d,v,t", AT, breg, AT); | |
5666 | if (p != NULL) | |
5667 | p += 4; | |
5668 | } | |
bdaaa2e1 | 5669 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5670 | macro_build (p, &icnt, &offset_expr, s, fmt, |
5671 | coproc ? treg + 1 : treg, | |
5672 | (int) BFD_RELOC_LO16, AT); | |
5673 | if (p != NULL) | |
5674 | p += 4; | |
5675 | /* FIXME: How do we handle overflow here? */ | |
5676 | offset_expr.X_add_number += 4; | |
bdaaa2e1 | 5677 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5678 | macro_build (p, &icnt, &offset_expr, s, fmt, |
5679 | coproc ? treg : treg + 1, | |
5680 | (int) BFD_RELOC_LO16, AT); | |
bdaaa2e1 | 5681 | } |
252b5132 RH |
5682 | else if (mips_pic == SVR4_PIC && ! mips_big_got) |
5683 | { | |
5684 | int off; | |
5685 | ||
5686 | /* If this is a reference to an external symbol, we want | |
5687 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5688 | nop | |
5689 | <op> $treg,0($at) | |
5690 | <op> $treg+1,4($at) | |
5691 | Otherwise we want | |
5692 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5693 | nop | |
5694 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5695 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5696 | If there is a base register we add it to $at before the | |
5697 | lwc1 instructions. If there is a constant we include it | |
5698 | in the lwc1 instructions. */ | |
5699 | used_at = 1; | |
5700 | expr1.X_add_number = offset_expr.X_add_number; | |
5701 | offset_expr.X_add_number = 0; | |
5702 | if (expr1.X_add_number < -0x8000 | |
5703 | || expr1.X_add_number >= 0x8000 - 4) | |
5704 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5705 | if (breg == 0) | |
5706 | off = 0; | |
5707 | else | |
5708 | off = 4; | |
5709 | frag_grow (24 + off); | |
5710 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5711 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5712 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5713 | ? "lw" : "ld"), |
5714 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5715 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
5716 | if (breg != 0) | |
5717 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5718 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5719 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5720 | ? "addu" : "daddu"), |
5721 | "d,v,t", AT, breg, AT); | |
bdaaa2e1 | 5722 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5723 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
5724 | coproc ? treg + 1 : treg, | |
5725 | (int) BFD_RELOC_LO16, AT); | |
5726 | expr1.X_add_number += 4; | |
5727 | ||
5728 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5729 | nop. */ | |
5730 | hold_mips_optimize = mips_optimize; | |
5731 | mips_optimize = 2; | |
bdaaa2e1 | 5732 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5733 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
5734 | coproc ? treg : treg + 1, | |
5735 | (int) BFD_RELOC_LO16, AT); | |
5736 | mips_optimize = hold_mips_optimize; | |
5737 | ||
5738 | (void) frag_var (rs_machine_dependent, 0, 0, | |
5739 | RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0), | |
5740 | offset_expr.X_add_symbol, (offsetT) 0, | |
5741 | (char *) NULL); | |
5742 | } | |
5743 | else if (mips_pic == SVR4_PIC) | |
5744 | { | |
5745 | int gpdel, off; | |
5746 | ||
5747 | /* If this is a reference to an external symbol, we want | |
5748 | lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16) | |
5749 | addu $at,$at,$gp | |
5750 | lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16) | |
5751 | nop | |
5752 | <op> $treg,0($at) | |
5753 | <op> $treg+1,4($at) | |
5754 | Otherwise we want | |
5755 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) | |
5756 | nop | |
5757 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) | |
5758 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) | |
5759 | If there is a base register we add it to $at before the | |
5760 | lwc1 instructions. If there is a constant we include it | |
5761 | in the lwc1 instructions. */ | |
5762 | used_at = 1; | |
5763 | expr1.X_add_number = offset_expr.X_add_number; | |
5764 | offset_expr.X_add_number = 0; | |
5765 | if (expr1.X_add_number < -0x8000 | |
5766 | || expr1.X_add_number >= 0x8000 - 4) | |
5767 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); | |
5768 | if (reg_needs_delay (GP)) | |
5769 | gpdel = 4; | |
5770 | else | |
5771 | gpdel = 0; | |
5772 | if (breg == 0) | |
5773 | off = 0; | |
5774 | else | |
5775 | off = 4; | |
5776 | frag_grow (56); | |
5777 | macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u", | |
5778 | AT, (int) BFD_RELOC_MIPS_GOT_HI16); | |
5779 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5780 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5781 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5782 | ? "addu" : "daddu"), |
5783 | "d,v,t", AT, AT, GP); | |
5784 | macro_build ((char *) NULL, &icnt, &offset_expr, | |
5785 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5786 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5787 | ? "lw" : "ld"), |
5788 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT); | |
5789 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", ""); | |
5790 | if (breg != 0) | |
5791 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5792 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5793 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5794 | ? "addu" : "daddu"), |
5795 | "d,v,t", AT, breg, AT); | |
bdaaa2e1 | 5796 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5797 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
5798 | coproc ? treg + 1 : treg, | |
5799 | (int) BFD_RELOC_LO16, AT); | |
5800 | expr1.X_add_number += 4; | |
5801 | ||
5802 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5803 | nop. */ | |
5804 | hold_mips_optimize = mips_optimize; | |
5805 | mips_optimize = 2; | |
bdaaa2e1 | 5806 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5807 | macro_build ((char *) NULL, &icnt, &expr1, s, fmt, |
5808 | coproc ? treg : treg + 1, | |
5809 | (int) BFD_RELOC_LO16, AT); | |
5810 | mips_optimize = hold_mips_optimize; | |
5811 | expr1.X_add_number -= 4; | |
5812 | ||
5813 | p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0, | |
5814 | RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel, | |
5815 | 8 + gpdel + off, 1, 0), | |
5816 | offset_expr.X_add_symbol, (offsetT) 0, | |
5817 | (char *) NULL); | |
5818 | if (gpdel > 0) | |
5819 | { | |
5820 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5821 | p += 4; | |
5822 | } | |
5823 | macro_build (p, &icnt, &offset_expr, | |
5824 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5825 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5826 | ? "lw" : "ld"), |
5827 | "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP); | |
5828 | p += 4; | |
5829 | macro_build (p, &icnt, (expressionS *) NULL, "nop", ""); | |
5830 | p += 4; | |
5831 | if (breg != 0) | |
5832 | { | |
5833 | macro_build (p, &icnt, (expressionS *) NULL, | |
5834 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5835 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5836 | ? "addu" : "daddu"), |
5837 | "d,v,t", AT, breg, AT); | |
5838 | p += 4; | |
5839 | } | |
bdaaa2e1 | 5840 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5841 | macro_build (p, &icnt, &expr1, s, fmt, |
5842 | coproc ? treg + 1 : treg, | |
5843 | (int) BFD_RELOC_LO16, AT); | |
5844 | p += 4; | |
5845 | expr1.X_add_number += 4; | |
5846 | ||
5847 | /* Set mips_optimize to 2 to avoid inserting an undesired | |
5848 | nop. */ | |
5849 | hold_mips_optimize = mips_optimize; | |
5850 | mips_optimize = 2; | |
bdaaa2e1 | 5851 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5852 | macro_build (p, &icnt, &expr1, s, fmt, |
5853 | coproc ? treg : treg + 1, | |
5854 | (int) BFD_RELOC_LO16, AT); | |
5855 | mips_optimize = hold_mips_optimize; | |
5856 | } | |
5857 | else if (mips_pic == EMBEDDED_PIC) | |
5858 | { | |
5859 | /* If there is no base register, we use | |
5860 | <op> $treg,<sym>($gp) (BFD_RELOC_MIPS_GPREL) | |
5861 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_MIPS_GPREL) | |
5862 | If we have a base register, we use | |
5863 | addu $at,$breg,$gp | |
5864 | <op> $treg,<sym>($at) (BFD_RELOC_MIPS_GPREL) | |
5865 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_MIPS_GPREL) | |
5866 | */ | |
5867 | if (breg == 0) | |
5868 | { | |
5869 | tempreg = GP; | |
5870 | used_at = 0; | |
5871 | } | |
5872 | else | |
5873 | { | |
5874 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
5875 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 5876 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
5877 | ? "addu" : "daddu"), |
5878 | "d,v,t", AT, breg, GP); | |
5879 | tempreg = AT; | |
5880 | used_at = 1; | |
5881 | } | |
5882 | ||
bdaaa2e1 | 5883 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5884 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
5885 | coproc ? treg + 1 : treg, | |
5886 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5887 | offset_expr.X_add_number += 4; | |
bdaaa2e1 | 5888 | /* Itbl support may require additional care here. */ |
252b5132 RH |
5889 | macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, |
5890 | coproc ? treg : treg + 1, | |
5891 | (int) BFD_RELOC_MIPS_GPREL, tempreg); | |
5892 | } | |
5893 | else | |
5894 | abort (); | |
5895 | ||
5896 | if (! used_at) | |
5897 | return; | |
5898 | ||
5899 | break; | |
5900 | ||
5901 | case M_LD_OB: | |
5902 | s = "lw"; | |
5903 | goto sd_ob; | |
5904 | case M_SD_OB: | |
5905 | s = "sw"; | |
5906 | sd_ob: | |
bdaaa2e1 | 5907 | assert (bfd_arch_bits_per_address (stdoutput) == 32 |
9ce8a5dd | 5908 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)); |
252b5132 RH |
5909 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, |
5910 | (int) BFD_RELOC_LO16, breg); | |
5911 | offset_expr.X_add_number += 4; | |
5912 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1, | |
5913 | (int) BFD_RELOC_LO16, breg); | |
5914 | return; | |
5915 | ||
5916 | /* New code added to support COPZ instructions. | |
5917 | This code builds table entries out of the macros in mip_opcodes. | |
5918 | R4000 uses interlocks to handle coproc delays. | |
5919 | Other chips (like the R3000) require nops to be inserted for delays. | |
5920 | ||
5921 | FIXME: Currently, we require that the user handle delays. | |
5922 | In order to fill delay slots for non-interlocked chips, | |
5923 | we must have a way to specify delays based on the coprocessor. | |
5924 | Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc. | |
5925 | What are the side-effects of the cop instruction? | |
5926 | What cache support might we have and what are its effects? | |
5927 | Both coprocessor & memory require delays. how long??? | |
bdaaa2e1 | 5928 | What registers are read/set/modified? |
252b5132 RH |
5929 | |
5930 | If an itbl is provided to interpret cop instructions, | |
bdaaa2e1 | 5931 | this knowledge can be encoded in the itbl spec. */ |
252b5132 RH |
5932 | |
5933 | case M_COP0: | |
5934 | s = "c0"; | |
5935 | goto copz; | |
5936 | case M_COP1: | |
5937 | s = "c1"; | |
5938 | goto copz; | |
5939 | case M_COP2: | |
5940 | s = "c2"; | |
5941 | goto copz; | |
5942 | case M_COP3: | |
5943 | s = "c3"; | |
5944 | copz: | |
5945 | /* For now we just do C (same as Cz). The parameter will be | |
5946 | stored in insn_opcode by mips_ip. */ | |
5947 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C", | |
5948 | ip->insn_opcode); | |
5949 | return; | |
5950 | ||
5951 | #ifdef LOSING_COMPILER | |
5952 | default: | |
5953 | /* Try and see if this is a new itbl instruction. | |
5954 | This code builds table entries out of the macros in mip_opcodes. | |
5955 | FIXME: For now we just assemble the expression and pass it's | |
5956 | value along as a 32-bit immediate. | |
bdaaa2e1 | 5957 | We may want to have the assembler assemble this value, |
252b5132 RH |
5958 | so that we gain the assembler's knowledge of delay slots, |
5959 | symbols, etc. | |
5960 | Would it be more efficient to use mask (id) here? */ | |
bdaaa2e1 | 5961 | if (itbl_have_entries |
252b5132 RH |
5962 | && (immed_expr = itbl_assemble (ip->insn_mo->name, ""))) |
5963 | { | |
5964 | s = ip->insn_mo->name; | |
5965 | s2 = "cop3"; | |
5966 | coproc = ITBL_DECODE_PNUM (immed_expr);; | |
5967 | macro_build ((char *) NULL, &icnt, &immed_expr, s, "C"); | |
5968 | return; | |
5969 | } | |
5970 | macro2 (ip); | |
5971 | return; | |
5972 | } | |
5973 | if (mips_opts.noat) | |
5974 | as_warn (_("Macro used $at after \".set noat\"")); | |
5975 | } | |
bdaaa2e1 | 5976 | |
252b5132 RH |
5977 | static void |
5978 | macro2 (ip) | |
5979 | struct mips_cl_insn *ip; | |
5980 | { | |
5981 | register int treg, sreg, dreg, breg; | |
5982 | int tempreg; | |
5983 | int mask; | |
5984 | int icnt = 0; | |
5985 | int used_at; | |
5986 | expressionS expr1; | |
5987 | const char *s; | |
5988 | const char *s2; | |
5989 | const char *fmt; | |
5990 | int likely = 0; | |
5991 | int dbl = 0; | |
5992 | int coproc = 0; | |
5993 | int lr = 0; | |
5994 | int imm = 0; | |
5995 | int off; | |
5996 | offsetT maxnum; | |
5997 | bfd_reloc_code_real_type r; | |
5998 | char *p; | |
bdaaa2e1 | 5999 | |
252b5132 RH |
6000 | treg = (ip->insn_opcode >> 16) & 0x1f; |
6001 | dreg = (ip->insn_opcode >> 11) & 0x1f; | |
6002 | sreg = breg = (ip->insn_opcode >> 21) & 0x1f; | |
6003 | mask = ip->insn_mo->mask; | |
bdaaa2e1 | 6004 | |
252b5132 RH |
6005 | expr1.X_op = O_constant; |
6006 | expr1.X_op_symbol = NULL; | |
6007 | expr1.X_add_symbol = NULL; | |
6008 | expr1.X_add_number = 1; | |
bdaaa2e1 | 6009 | |
252b5132 RH |
6010 | switch (mask) |
6011 | { | |
6012 | #endif /* LOSING_COMPILER */ | |
6013 | ||
6014 | case M_DMUL: | |
6015 | dbl = 1; | |
6016 | case M_MUL: | |
6017 | macro_build ((char *) NULL, &icnt, NULL, | |
6018 | dbl ? "dmultu" : "multu", | |
6019 | "s,t", sreg, treg); | |
6020 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6021 | return; | |
6022 | ||
6023 | case M_DMUL_I: | |
6024 | dbl = 1; | |
6025 | case M_MUL_I: | |
6026 | /* The MIPS assembler some times generates shifts and adds. I'm | |
6027 | not trying to be that fancy. GCC should do this for us | |
6028 | anyway. */ | |
6029 | load_register (&icnt, AT, &imm_expr, dbl); | |
6030 | macro_build ((char *) NULL, &icnt, NULL, | |
6031 | dbl ? "dmult" : "mult", | |
6032 | "s,t", sreg, AT); | |
6033 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6034 | break; | |
6035 | ||
6036 | case M_DMULO_I: | |
6037 | dbl = 1; | |
6038 | case M_MULO_I: | |
6039 | imm = 1; | |
6040 | goto do_mulo; | |
6041 | ||
6042 | case M_DMULO: | |
6043 | dbl = 1; | |
6044 | case M_MULO: | |
6045 | do_mulo: | |
6046 | mips_emit_delays (true); | |
6047 | ++mips_opts.noreorder; | |
6048 | mips_any_noreorder = 1; | |
6049 | if (imm) | |
6050 | load_register (&icnt, AT, &imm_expr, dbl); | |
6051 | macro_build ((char *) NULL, &icnt, NULL, | |
6052 | dbl ? "dmult" : "mult", | |
6053 | "s,t", sreg, imm ? AT : treg); | |
6054 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6055 | macro_build ((char *) NULL, &icnt, NULL, | |
6056 | dbl ? "dsra32" : "sra", | |
6057 | "d,w,<", dreg, dreg, 31); | |
6058 | macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT); | |
6059 | if (mips_trap) | |
6060 | macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", dreg, AT); | |
6061 | else | |
6062 | { | |
6063 | expr1.X_add_number = 8; | |
6064 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT); | |
6065 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
6066 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); | |
6067 | } | |
6068 | --mips_opts.noreorder; | |
6069 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6070 | break; | |
6071 | ||
6072 | case M_DMULOU_I: | |
6073 | dbl = 1; | |
6074 | case M_MULOU_I: | |
6075 | imm = 1; | |
6076 | goto do_mulou; | |
6077 | ||
6078 | case M_DMULOU: | |
6079 | dbl = 1; | |
6080 | case M_MULOU: | |
6081 | do_mulou: | |
6082 | mips_emit_delays (true); | |
6083 | ++mips_opts.noreorder; | |
6084 | mips_any_noreorder = 1; | |
6085 | if (imm) | |
6086 | load_register (&icnt, AT, &imm_expr, dbl); | |
6087 | macro_build ((char *) NULL, &icnt, NULL, | |
6088 | dbl ? "dmultu" : "multu", | |
6089 | "s,t", sreg, imm ? AT : treg); | |
6090 | macro_build ((char *) NULL, &icnt, NULL, "mfhi", "d", AT); | |
6091 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg); | |
6092 | if (mips_trap) | |
6093 | macro_build ((char *) NULL, &icnt, NULL, "tne", "s,t", AT, 0); | |
6094 | else | |
6095 | { | |
6096 | expr1.X_add_number = 8; | |
6097 | macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0); | |
6098 | macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0); | |
6099 | macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6); | |
6100 | } | |
6101 | --mips_opts.noreorder; | |
6102 | break; | |
6103 | ||
6104 | case M_ROL: | |
6105 | macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg); | |
6106 | macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", AT, sreg, AT); | |
6107 | macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", dreg, sreg, | |
6108 | treg); | |
6109 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6110 | break; | |
6111 | ||
6112 | case M_ROL_I: | |
6113 | if (imm_expr.X_op != O_constant) | |
6114 | as_bad (_("rotate count too large")); | |
6115 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", AT, sreg, | |
6116 | (int) (imm_expr.X_add_number & 0x1f)); | |
6117 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", dreg, sreg, | |
6118 | (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6119 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6120 | break; | |
6121 | ||
6122 | case M_ROR: | |
6123 | macro_build ((char *) NULL, &icnt, NULL, "subu", "d,v,t", AT, 0, treg); | |
6124 | macro_build ((char *) NULL, &icnt, NULL, "sllv", "d,t,s", AT, sreg, AT); | |
6125 | macro_build ((char *) NULL, &icnt, NULL, "srlv", "d,t,s", dreg, sreg, | |
6126 | treg); | |
6127 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6128 | break; | |
6129 | ||
6130 | case M_ROR_I: | |
6131 | if (imm_expr.X_op != O_constant) | |
6132 | as_bad (_("rotate count too large")); | |
6133 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, sreg, | |
6134 | (int) (imm_expr.X_add_number & 0x1f)); | |
6135 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", dreg, sreg, | |
6136 | (int) ((0 - imm_expr.X_add_number) & 0x1f)); | |
6137 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", dreg, dreg, AT); | |
6138 | break; | |
6139 | ||
6140 | case M_S_DOB: | |
156c2f8b | 6141 | if (mips_cpu == CPU_R4650) |
252b5132 RH |
6142 | { |
6143 | as_bad (_("opcode not supported on this processor")); | |
6144 | return; | |
6145 | } | |
9ce8a5dd | 6146 | assert (mips_opts.isa == 1); |
252b5132 RH |
6147 | /* Even on a big endian machine $fn comes before $fn+1. We have |
6148 | to adjust when storing to memory. */ | |
6149 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6150 | target_big_endian ? treg + 1 : treg, | |
6151 | (int) BFD_RELOC_LO16, breg); | |
6152 | offset_expr.X_add_number += 4; | |
6153 | macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)", | |
6154 | target_big_endian ? treg : treg + 1, | |
6155 | (int) BFD_RELOC_LO16, breg); | |
6156 | return; | |
6157 | ||
6158 | case M_SEQ: | |
6159 | if (sreg == 0) | |
6160 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6161 | treg, (int) BFD_RELOC_LO16); | |
6162 | else if (treg == 0) | |
6163 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6164 | sreg, (int) BFD_RELOC_LO16); | |
6165 | else | |
6166 | { | |
6167 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6168 | sreg, treg); | |
6169 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6170 | dreg, (int) BFD_RELOC_LO16); | |
6171 | } | |
6172 | return; | |
6173 | ||
6174 | case M_SEQ_I: | |
6175 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6176 | { | |
6177 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, | |
6178 | sreg, (int) BFD_RELOC_LO16); | |
6179 | return; | |
6180 | } | |
6181 | if (sreg == 0) | |
6182 | { | |
6183 | as_warn (_("Instruction %s: result is always false"), | |
6184 | ip->insn_mo->name); | |
6185 | macro_build ((char *) NULL, &icnt, NULL, "move", "d,s", dreg, 0); | |
6186 | return; | |
6187 | } | |
6188 | if (imm_expr.X_op == O_constant | |
6189 | && imm_expr.X_add_number >= 0 | |
6190 | && imm_expr.X_add_number < 0x10000) | |
6191 | { | |
6192 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg, | |
6193 | sreg, (int) BFD_RELOC_LO16); | |
6194 | used_at = 0; | |
6195 | } | |
6196 | else if (imm_expr.X_op == O_constant | |
6197 | && imm_expr.X_add_number > -0x8000 | |
6198 | && imm_expr.X_add_number < 0) | |
6199 | { | |
6200 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6201 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6202 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 6203 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
6204 | ? "addiu" : "daddiu"), |
6205 | "t,r,j", dreg, sreg, | |
6206 | (int) BFD_RELOC_LO16); | |
6207 | used_at = 0; | |
6208 | } | |
6209 | else | |
6210 | { | |
6211 | load_register (&icnt, AT, &imm_expr, 0); | |
6212 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6213 | sreg, AT); | |
6214 | used_at = 1; | |
6215 | } | |
6216 | macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg, | |
6217 | (int) BFD_RELOC_LO16); | |
6218 | if (used_at) | |
6219 | break; | |
6220 | return; | |
6221 | ||
6222 | case M_SGE: /* sreg >= treg <==> not (sreg < treg) */ | |
6223 | s = "slt"; | |
6224 | goto sge; | |
6225 | case M_SGEU: | |
6226 | s = "sltu"; | |
6227 | sge: | |
6228 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, sreg, treg); | |
6229 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6230 | (int) BFD_RELOC_LO16); | |
6231 | return; | |
6232 | ||
6233 | case M_SGE_I: /* sreg >= I <==> not (sreg < I) */ | |
6234 | case M_SGEU_I: | |
6235 | if (imm_expr.X_op == O_constant | |
6236 | && imm_expr.X_add_number >= -0x8000 | |
6237 | && imm_expr.X_add_number < 0x8000) | |
6238 | { | |
6239 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6240 | mask == M_SGE_I ? "slti" : "sltiu", | |
6241 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6242 | used_at = 0; | |
6243 | } | |
6244 | else | |
6245 | { | |
6246 | load_register (&icnt, AT, &imm_expr, 0); | |
6247 | macro_build ((char *) NULL, &icnt, NULL, | |
6248 | mask == M_SGE_I ? "slt" : "sltu", | |
6249 | "d,v,t", dreg, sreg, AT); | |
6250 | used_at = 1; | |
6251 | } | |
6252 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6253 | (int) BFD_RELOC_LO16); | |
6254 | if (used_at) | |
6255 | break; | |
6256 | return; | |
6257 | ||
6258 | case M_SGT: /* sreg > treg <==> treg < sreg */ | |
6259 | s = "slt"; | |
6260 | goto sgt; | |
6261 | case M_SGTU: | |
6262 | s = "sltu"; | |
6263 | sgt: | |
6264 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg); | |
6265 | return; | |
6266 | ||
6267 | case M_SGT_I: /* sreg > I <==> I < sreg */ | |
6268 | s = "slt"; | |
6269 | goto sgti; | |
6270 | case M_SGTU_I: | |
6271 | s = "sltu"; | |
6272 | sgti: | |
6273 | load_register (&icnt, AT, &imm_expr, 0); | |
6274 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg); | |
6275 | break; | |
6276 | ||
6277 | case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */ | |
6278 | s = "slt"; | |
6279 | goto sle; | |
6280 | case M_SLEU: | |
6281 | s = "sltu"; | |
6282 | sle: | |
6283 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, treg, sreg); | |
6284 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6285 | (int) BFD_RELOC_LO16); | |
6286 | return; | |
6287 | ||
6288 | case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */ | |
6289 | s = "slt"; | |
6290 | goto slei; | |
6291 | case M_SLEU_I: | |
6292 | s = "sltu"; | |
6293 | slei: | |
6294 | load_register (&icnt, AT, &imm_expr, 0); | |
6295 | macro_build ((char *) NULL, &icnt, NULL, s, "d,v,t", dreg, AT, sreg); | |
6296 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg, | |
6297 | (int) BFD_RELOC_LO16); | |
6298 | break; | |
6299 | ||
6300 | case M_SLT_I: | |
6301 | if (imm_expr.X_op == O_constant | |
6302 | && imm_expr.X_add_number >= -0x8000 | |
6303 | && imm_expr.X_add_number < 0x8000) | |
6304 | { | |
6305 | macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j", | |
6306 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6307 | return; | |
6308 | } | |
6309 | load_register (&icnt, AT, &imm_expr, 0); | |
6310 | macro_build ((char *) NULL, &icnt, NULL, "slt", "d,v,t", dreg, sreg, AT); | |
6311 | break; | |
6312 | ||
6313 | case M_SLTU_I: | |
6314 | if (imm_expr.X_op == O_constant | |
6315 | && imm_expr.X_add_number >= -0x8000 | |
6316 | && imm_expr.X_add_number < 0x8000) | |
6317 | { | |
6318 | macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j", | |
6319 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6320 | return; | |
6321 | } | |
6322 | load_register (&icnt, AT, &imm_expr, 0); | |
6323 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, sreg, | |
6324 | AT); | |
6325 | break; | |
6326 | ||
6327 | case M_SNE: | |
6328 | if (sreg == 0) | |
6329 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6330 | treg); | |
6331 | else if (treg == 0) | |
6332 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6333 | sreg); | |
6334 | else | |
6335 | { | |
6336 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6337 | sreg, treg); | |
6338 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6339 | dreg); | |
6340 | } | |
6341 | return; | |
6342 | ||
6343 | case M_SNE_I: | |
6344 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) | |
6345 | { | |
6346 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, | |
6347 | sreg); | |
6348 | return; | |
6349 | } | |
6350 | if (sreg == 0) | |
6351 | { | |
6352 | as_warn (_("Instruction %s: result is always true"), | |
6353 | ip->insn_mo->name); | |
6354 | macro_build ((char *) NULL, &icnt, &expr1, | |
6355 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 6356 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
6357 | ? "addiu" : "daddiu"), |
6358 | "t,r,j", dreg, 0, (int) BFD_RELOC_LO16); | |
6359 | return; | |
6360 | } | |
6361 | if (imm_expr.X_op == O_constant | |
6362 | && imm_expr.X_add_number >= 0 | |
6363 | && imm_expr.X_add_number < 0x10000) | |
6364 | { | |
6365 | macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", | |
6366 | dreg, sreg, (int) BFD_RELOC_LO16); | |
6367 | used_at = 0; | |
6368 | } | |
6369 | else if (imm_expr.X_op == O_constant | |
6370 | && imm_expr.X_add_number > -0x8000 | |
6371 | && imm_expr.X_add_number < 0) | |
6372 | { | |
6373 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6374 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6375 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 6376 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
6377 | ? "addiu" : "daddiu"), |
6378 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6379 | used_at = 0; | |
6380 | } | |
6381 | else | |
6382 | { | |
6383 | load_register (&icnt, AT, &imm_expr, 0); | |
6384 | macro_build ((char *) NULL, &icnt, NULL, "xor", "d,v,t", dreg, | |
6385 | sreg, AT); | |
6386 | used_at = 1; | |
6387 | } | |
6388 | macro_build ((char *) NULL, &icnt, NULL, "sltu", "d,v,t", dreg, 0, dreg); | |
6389 | if (used_at) | |
6390 | break; | |
6391 | return; | |
6392 | ||
6393 | case M_DSUB_I: | |
6394 | dbl = 1; | |
6395 | case M_SUB_I: | |
6396 | if (imm_expr.X_op == O_constant | |
6397 | && imm_expr.X_add_number > -0x8000 | |
6398 | && imm_expr.X_add_number <= 0x8000) | |
6399 | { | |
6400 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6401 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6402 | dbl ? "daddi" : "addi", | |
6403 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6404 | return; | |
6405 | } | |
6406 | load_register (&icnt, AT, &imm_expr, dbl); | |
6407 | macro_build ((char *) NULL, &icnt, NULL, | |
6408 | dbl ? "dsub" : "sub", | |
6409 | "d,v,t", dreg, sreg, AT); | |
6410 | break; | |
6411 | ||
6412 | case M_DSUBU_I: | |
6413 | dbl = 1; | |
6414 | case M_SUBU_I: | |
6415 | if (imm_expr.X_op == O_constant | |
6416 | && imm_expr.X_add_number > -0x8000 | |
6417 | && imm_expr.X_add_number <= 0x8000) | |
6418 | { | |
6419 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6420 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6421 | dbl ? "daddiu" : "addiu", | |
6422 | "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16); | |
6423 | return; | |
6424 | } | |
6425 | load_register (&icnt, AT, &imm_expr, dbl); | |
6426 | macro_build ((char *) NULL, &icnt, NULL, | |
6427 | dbl ? "dsubu" : "subu", | |
6428 | "d,v,t", dreg, sreg, AT); | |
6429 | break; | |
6430 | ||
6431 | case M_TEQ_I: | |
6432 | s = "teq"; | |
6433 | goto trap; | |
6434 | case M_TGE_I: | |
6435 | s = "tge"; | |
6436 | goto trap; | |
6437 | case M_TGEU_I: | |
6438 | s = "tgeu"; | |
6439 | goto trap; | |
6440 | case M_TLT_I: | |
6441 | s = "tlt"; | |
6442 | goto trap; | |
6443 | case M_TLTU_I: | |
6444 | s = "tltu"; | |
6445 | goto trap; | |
6446 | case M_TNE_I: | |
6447 | s = "tne"; | |
6448 | trap: | |
6449 | load_register (&icnt, AT, &imm_expr, 0); | |
6450 | macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT); | |
6451 | break; | |
6452 | ||
252b5132 | 6453 | case M_TRUNCWS: |
43841e91 | 6454 | case M_TRUNCWD: |
9ce8a5dd | 6455 | assert (mips_opts.isa == 1); |
252b5132 RH |
6456 | sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */ |
6457 | dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */ | |
6458 | ||
6459 | /* | |
6460 | * Is the double cfc1 instruction a bug in the mips assembler; | |
6461 | * or is there a reason for it? | |
6462 | */ | |
6463 | mips_emit_delays (true); | |
6464 | ++mips_opts.noreorder; | |
6465 | mips_any_noreorder = 1; | |
6466 | macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31); | |
6467 | macro_build ((char *) NULL, &icnt, NULL, "cfc1", "t,G", treg, 31); | |
6468 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6469 | expr1.X_add_number = 3; | |
6470 | macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg, | |
6471 | (int) BFD_RELOC_LO16); | |
6472 | expr1.X_add_number = 2; | |
6473 | macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT, | |
6474 | (int) BFD_RELOC_LO16); | |
6475 | macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", AT, 31); | |
6476 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6477 | macro_build ((char *) NULL, &icnt, NULL, | |
6478 | mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg); | |
6479 | macro_build ((char *) NULL, &icnt, NULL, "ctc1", "t,G", treg, 31); | |
6480 | macro_build ((char *) NULL, &icnt, NULL, "nop", ""); | |
6481 | --mips_opts.noreorder; | |
6482 | break; | |
6483 | ||
6484 | case M_ULH: | |
6485 | s = "lb"; | |
6486 | goto ulh; | |
6487 | case M_ULHU: | |
6488 | s = "lbu"; | |
6489 | ulh: | |
6490 | if (offset_expr.X_add_number >= 0x7fff) | |
6491 | as_bad (_("operand overflow")); | |
6492 | /* avoid load delay */ | |
6493 | if (! target_big_endian) | |
6494 | offset_expr.X_add_number += 1; | |
6495 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6496 | (int) BFD_RELOC_LO16, breg); | |
6497 | if (! target_big_endian) | |
6498 | offset_expr.X_add_number -= 1; | |
6499 | else | |
6500 | offset_expr.X_add_number += 1; | |
6501 | macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT, | |
6502 | (int) BFD_RELOC_LO16, breg); | |
6503 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, treg, 8); | |
6504 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, treg, AT); | |
6505 | break; | |
6506 | ||
6507 | case M_ULD: | |
6508 | s = "ldl"; | |
6509 | s2 = "ldr"; | |
6510 | off = 7; | |
6511 | goto ulw; | |
6512 | case M_ULW: | |
6513 | s = "lwl"; | |
6514 | s2 = "lwr"; | |
6515 | off = 3; | |
6516 | ulw: | |
6517 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6518 | as_bad (_("operand overflow")); | |
6519 | if (! target_big_endian) | |
6520 | offset_expr.X_add_number += off; | |
6521 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6522 | (int) BFD_RELOC_LO16, breg); | |
6523 | if (! target_big_endian) | |
6524 | offset_expr.X_add_number -= off; | |
6525 | else | |
6526 | offset_expr.X_add_number += off; | |
6527 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
6528 | (int) BFD_RELOC_LO16, breg); | |
6529 | return; | |
6530 | ||
6531 | case M_ULD_A: | |
6532 | s = "ldl"; | |
6533 | s2 = "ldr"; | |
6534 | off = 7; | |
6535 | goto ulwa; | |
6536 | case M_ULW_A: | |
6537 | s = "lwl"; | |
6538 | s2 = "lwr"; | |
6539 | off = 3; | |
6540 | ulwa: | |
6541 | load_address (&icnt, AT, &offset_expr); | |
6542 | if (breg != 0) | |
6543 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6544 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 6545 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
6546 | ? "addu" : "daddu"), |
6547 | "d,v,t", AT, AT, breg); | |
6548 | if (! target_big_endian) | |
6549 | expr1.X_add_number = off; | |
6550 | else | |
6551 | expr1.X_add_number = 0; | |
6552 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
6553 | (int) BFD_RELOC_LO16, AT); | |
6554 | if (! target_big_endian) | |
6555 | expr1.X_add_number = 0; | |
6556 | else | |
6557 | expr1.X_add_number = off; | |
6558 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
6559 | (int) BFD_RELOC_LO16, AT); | |
6560 | break; | |
6561 | ||
6562 | case M_ULH_A: | |
6563 | case M_ULHU_A: | |
6564 | load_address (&icnt, AT, &offset_expr); | |
6565 | if (breg != 0) | |
6566 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6567 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 6568 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
6569 | ? "addu" : "daddu"), |
6570 | "d,v,t", AT, AT, breg); | |
6571 | if (target_big_endian) | |
6572 | expr1.X_add_number = 0; | |
6573 | macro_build ((char *) NULL, &icnt, &expr1, | |
6574 | mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg, | |
6575 | (int) BFD_RELOC_LO16, AT); | |
6576 | if (target_big_endian) | |
6577 | expr1.X_add_number = 1; | |
6578 | else | |
6579 | expr1.X_add_number = 0; | |
6580 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
6581 | (int) BFD_RELOC_LO16, AT); | |
6582 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, | |
6583 | treg, 8); | |
6584 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, | |
6585 | treg, AT); | |
6586 | break; | |
6587 | ||
6588 | case M_USH: | |
6589 | if (offset_expr.X_add_number >= 0x7fff) | |
6590 | as_bad (_("operand overflow")); | |
6591 | if (target_big_endian) | |
6592 | offset_expr.X_add_number += 1; | |
6593 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg, | |
6594 | (int) BFD_RELOC_LO16, breg); | |
6595 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", AT, treg, 8); | |
6596 | if (target_big_endian) | |
6597 | offset_expr.X_add_number -= 1; | |
6598 | else | |
6599 | offset_expr.X_add_number += 1; | |
6600 | macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT, | |
6601 | (int) BFD_RELOC_LO16, breg); | |
6602 | break; | |
6603 | ||
6604 | case M_USD: | |
6605 | s = "sdl"; | |
6606 | s2 = "sdr"; | |
6607 | off = 7; | |
6608 | goto usw; | |
6609 | case M_USW: | |
6610 | s = "swl"; | |
6611 | s2 = "swr"; | |
6612 | off = 3; | |
6613 | usw: | |
6614 | if (offset_expr.X_add_number >= 0x8000 - off) | |
6615 | as_bad (_("operand overflow")); | |
6616 | if (! target_big_endian) | |
6617 | offset_expr.X_add_number += off; | |
6618 | macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg, | |
6619 | (int) BFD_RELOC_LO16, breg); | |
6620 | if (! target_big_endian) | |
6621 | offset_expr.X_add_number -= off; | |
6622 | else | |
6623 | offset_expr.X_add_number += off; | |
6624 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg, | |
6625 | (int) BFD_RELOC_LO16, breg); | |
6626 | return; | |
6627 | ||
6628 | case M_USD_A: | |
6629 | s = "sdl"; | |
6630 | s2 = "sdr"; | |
6631 | off = 7; | |
6632 | goto uswa; | |
6633 | case M_USW_A: | |
6634 | s = "swl"; | |
6635 | s2 = "swr"; | |
6636 | off = 3; | |
6637 | uswa: | |
6638 | load_address (&icnt, AT, &offset_expr); | |
6639 | if (breg != 0) | |
6640 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6641 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 6642 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
6643 | ? "addu" : "daddu"), |
6644 | "d,v,t", AT, AT, breg); | |
6645 | if (! target_big_endian) | |
6646 | expr1.X_add_number = off; | |
6647 | else | |
6648 | expr1.X_add_number = 0; | |
6649 | macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg, | |
6650 | (int) BFD_RELOC_LO16, AT); | |
6651 | if (! target_big_endian) | |
6652 | expr1.X_add_number = 0; | |
6653 | else | |
6654 | expr1.X_add_number = off; | |
6655 | macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg, | |
6656 | (int) BFD_RELOC_LO16, AT); | |
6657 | break; | |
6658 | ||
6659 | case M_USH_A: | |
6660 | load_address (&icnt, AT, &offset_expr); | |
6661 | if (breg != 0) | |
6662 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6663 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 6664 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
6665 | ? "addu" : "daddu"), |
6666 | "d,v,t", AT, AT, breg); | |
6667 | if (! target_big_endian) | |
6668 | expr1.X_add_number = 0; | |
6669 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
6670 | (int) BFD_RELOC_LO16, AT); | |
6671 | macro_build ((char *) NULL, &icnt, NULL, "srl", "d,w,<", treg, | |
6672 | treg, 8); | |
6673 | if (! target_big_endian) | |
6674 | expr1.X_add_number = 1; | |
6675 | else | |
6676 | expr1.X_add_number = 0; | |
6677 | macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg, | |
6678 | (int) BFD_RELOC_LO16, AT); | |
6679 | if (! target_big_endian) | |
6680 | expr1.X_add_number = 0; | |
6681 | else | |
6682 | expr1.X_add_number = 1; | |
6683 | macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT, | |
6684 | (int) BFD_RELOC_LO16, AT); | |
6685 | macro_build ((char *) NULL, &icnt, NULL, "sll", "d,w,<", treg, | |
6686 | treg, 8); | |
6687 | macro_build ((char *) NULL, &icnt, NULL, "or", "d,v,t", treg, | |
6688 | treg, AT); | |
6689 | break; | |
6690 | ||
6691 | default: | |
6692 | /* FIXME: Check if this is one of the itbl macros, since they | |
bdaaa2e1 | 6693 | are added dynamically. */ |
252b5132 RH |
6694 | as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name); |
6695 | break; | |
6696 | } | |
6697 | if (mips_opts.noat) | |
6698 | as_warn (_("Macro used $at after \".set noat\"")); | |
6699 | } | |
6700 | ||
6701 | /* Implement macros in mips16 mode. */ | |
6702 | ||
6703 | static void | |
6704 | mips16_macro (ip) | |
6705 | struct mips_cl_insn *ip; | |
6706 | { | |
6707 | int mask; | |
6708 | int xreg, yreg, zreg, tmp; | |
6709 | int icnt; | |
6710 | expressionS expr1; | |
6711 | int dbl; | |
6712 | const char *s, *s2, *s3; | |
6713 | ||
6714 | mask = ip->insn_mo->mask; | |
6715 | ||
6716 | xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX; | |
6717 | yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY; | |
6718 | zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ; | |
6719 | ||
6720 | icnt = 0; | |
6721 | ||
6722 | expr1.X_op = O_constant; | |
6723 | expr1.X_op_symbol = NULL; | |
6724 | expr1.X_add_symbol = NULL; | |
6725 | expr1.X_add_number = 1; | |
6726 | ||
6727 | dbl = 0; | |
6728 | ||
6729 | switch (mask) | |
6730 | { | |
6731 | default: | |
6732 | internalError (); | |
6733 | ||
6734 | case M_DDIV_3: | |
6735 | dbl = 1; | |
6736 | case M_DIV_3: | |
6737 | s = "mflo"; | |
6738 | goto do_div3; | |
6739 | case M_DREM_3: | |
6740 | dbl = 1; | |
6741 | case M_REM_3: | |
6742 | s = "mfhi"; | |
6743 | do_div3: | |
6744 | mips_emit_delays (true); | |
6745 | ++mips_opts.noreorder; | |
6746 | mips_any_noreorder = 1; | |
6747 | macro_build ((char *) NULL, &icnt, NULL, | |
6748 | dbl ? "ddiv" : "div", | |
6749 | "0,x,y", xreg, yreg); | |
6750 | expr1.X_add_number = 2; | |
6751 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
6752 | macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7); | |
bdaaa2e1 | 6753 | |
252b5132 RH |
6754 | /* FIXME: The normal code checks for of -1 / -0x80000000 here, |
6755 | since that causes an overflow. We should do that as well, | |
6756 | but I don't see how to do the comparisons without a temporary | |
6757 | register. */ | |
6758 | --mips_opts.noreorder; | |
6759 | macro_build ((char *) NULL, &icnt, NULL, s, "x", zreg); | |
6760 | break; | |
6761 | ||
6762 | case M_DIVU_3: | |
6763 | s = "divu"; | |
6764 | s2 = "mflo"; | |
6765 | goto do_divu3; | |
6766 | case M_REMU_3: | |
6767 | s = "divu"; | |
6768 | s2 = "mfhi"; | |
6769 | goto do_divu3; | |
6770 | case M_DDIVU_3: | |
6771 | s = "ddivu"; | |
6772 | s2 = "mflo"; | |
6773 | goto do_divu3; | |
6774 | case M_DREMU_3: | |
6775 | s = "ddivu"; | |
6776 | s2 = "mfhi"; | |
6777 | do_divu3: | |
6778 | mips_emit_delays (true); | |
6779 | ++mips_opts.noreorder; | |
6780 | mips_any_noreorder = 1; | |
6781 | macro_build ((char *) NULL, &icnt, NULL, s, "0,x,y", xreg, yreg); | |
6782 | expr1.X_add_number = 2; | |
6783 | macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg); | |
6784 | macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7); | |
6785 | --mips_opts.noreorder; | |
6786 | macro_build ((char *) NULL, &icnt, NULL, s2, "x", zreg); | |
6787 | break; | |
6788 | ||
6789 | case M_DMUL: | |
6790 | dbl = 1; | |
6791 | case M_MUL: | |
6792 | macro_build ((char *) NULL, &icnt, NULL, | |
6793 | dbl ? "dmultu" : "multu", | |
6794 | "x,y", xreg, yreg); | |
6795 | macro_build ((char *) NULL, &icnt, NULL, "mflo", "x", zreg); | |
6796 | return; | |
6797 | ||
6798 | case M_DSUBU_I: | |
6799 | dbl = 1; | |
6800 | goto do_subu; | |
6801 | case M_SUBU_I: | |
6802 | do_subu: | |
6803 | if (imm_expr.X_op != O_constant) | |
6804 | as_bad (_("Unsupported large constant")); | |
6805 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6806 | macro_build ((char *) NULL, &icnt, &imm_expr, | |
6807 | dbl ? "daddiu" : "addiu", | |
6808 | "y,x,4", yreg, xreg); | |
6809 | break; | |
6810 | ||
6811 | case M_SUBU_I_2: | |
6812 | if (imm_expr.X_op != O_constant) | |
6813 | as_bad (_("Unsupported large constant")); | |
6814 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6815 | macro_build ((char *) NULL, &icnt, &imm_expr, "addiu", | |
6816 | "x,k", xreg); | |
6817 | break; | |
6818 | ||
6819 | case M_DSUBU_I_2: | |
6820 | if (imm_expr.X_op != O_constant) | |
6821 | as_bad (_("Unsupported large constant")); | |
6822 | imm_expr.X_add_number = -imm_expr.X_add_number; | |
6823 | macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu", | |
6824 | "y,j", yreg); | |
6825 | break; | |
6826 | ||
6827 | case M_BEQ: | |
6828 | s = "cmp"; | |
6829 | s2 = "bteqz"; | |
6830 | goto do_branch; | |
6831 | case M_BNE: | |
6832 | s = "cmp"; | |
6833 | s2 = "btnez"; | |
6834 | goto do_branch; | |
6835 | case M_BLT: | |
6836 | s = "slt"; | |
6837 | s2 = "btnez"; | |
6838 | goto do_branch; | |
6839 | case M_BLTU: | |
6840 | s = "sltu"; | |
6841 | s2 = "btnez"; | |
6842 | goto do_branch; | |
6843 | case M_BLE: | |
6844 | s = "slt"; | |
6845 | s2 = "bteqz"; | |
6846 | goto do_reverse_branch; | |
6847 | case M_BLEU: | |
6848 | s = "sltu"; | |
6849 | s2 = "bteqz"; | |
6850 | goto do_reverse_branch; | |
6851 | case M_BGE: | |
6852 | s = "slt"; | |
6853 | s2 = "bteqz"; | |
6854 | goto do_branch; | |
6855 | case M_BGEU: | |
6856 | s = "sltu"; | |
6857 | s2 = "bteqz"; | |
6858 | goto do_branch; | |
6859 | case M_BGT: | |
6860 | s = "slt"; | |
6861 | s2 = "btnez"; | |
6862 | goto do_reverse_branch; | |
6863 | case M_BGTU: | |
6864 | s = "sltu"; | |
6865 | s2 = "btnez"; | |
6866 | ||
6867 | do_reverse_branch: | |
6868 | tmp = xreg; | |
6869 | xreg = yreg; | |
6870 | yreg = tmp; | |
6871 | ||
6872 | do_branch: | |
6873 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y", | |
6874 | xreg, yreg); | |
6875 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
6876 | break; | |
6877 | ||
6878 | case M_BEQ_I: | |
6879 | s = "cmpi"; | |
6880 | s2 = "bteqz"; | |
6881 | s3 = "x,U"; | |
6882 | goto do_branch_i; | |
6883 | case M_BNE_I: | |
6884 | s = "cmpi"; | |
6885 | s2 = "btnez"; | |
6886 | s3 = "x,U"; | |
6887 | goto do_branch_i; | |
6888 | case M_BLT_I: | |
6889 | s = "slti"; | |
6890 | s2 = "btnez"; | |
6891 | s3 = "x,8"; | |
6892 | goto do_branch_i; | |
6893 | case M_BLTU_I: | |
6894 | s = "sltiu"; | |
6895 | s2 = "btnez"; | |
6896 | s3 = "x,8"; | |
6897 | goto do_branch_i; | |
6898 | case M_BLE_I: | |
6899 | s = "slti"; | |
6900 | s2 = "btnez"; | |
6901 | s3 = "x,8"; | |
6902 | goto do_addone_branch_i; | |
6903 | case M_BLEU_I: | |
6904 | s = "sltiu"; | |
6905 | s2 = "btnez"; | |
6906 | s3 = "x,8"; | |
6907 | goto do_addone_branch_i; | |
6908 | case M_BGE_I: | |
6909 | s = "slti"; | |
6910 | s2 = "bteqz"; | |
6911 | s3 = "x,8"; | |
6912 | goto do_branch_i; | |
6913 | case M_BGEU_I: | |
6914 | s = "sltiu"; | |
6915 | s2 = "bteqz"; | |
6916 | s3 = "x,8"; | |
6917 | goto do_branch_i; | |
6918 | case M_BGT_I: | |
6919 | s = "slti"; | |
6920 | s2 = "bteqz"; | |
6921 | s3 = "x,8"; | |
6922 | goto do_addone_branch_i; | |
6923 | case M_BGTU_I: | |
6924 | s = "sltiu"; | |
6925 | s2 = "bteqz"; | |
6926 | s3 = "x,8"; | |
6927 | ||
6928 | do_addone_branch_i: | |
6929 | if (imm_expr.X_op != O_constant) | |
6930 | as_bad (_("Unsupported large constant")); | |
6931 | ++imm_expr.X_add_number; | |
6932 | ||
6933 | do_branch_i: | |
6934 | macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg); | |
6935 | macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p"); | |
6936 | break; | |
6937 | ||
6938 | case M_ABS: | |
6939 | expr1.X_add_number = 0; | |
6940 | macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg); | |
6941 | if (xreg != yreg) | |
6942 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6943 | "move", "y,X", xreg, yreg); | |
6944 | expr1.X_add_number = 2; | |
6945 | macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p"); | |
6946 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
6947 | "neg", "x,w", xreg, xreg); | |
6948 | } | |
6949 | } | |
6950 | ||
6951 | /* For consistency checking, verify that all bits are specified either | |
6952 | by the match/mask part of the instruction definition, or by the | |
6953 | operand list. */ | |
6954 | static int | |
6955 | validate_mips_insn (opc) | |
6956 | const struct mips_opcode *opc; | |
6957 | { | |
6958 | const char *p = opc->args; | |
6959 | char c; | |
6960 | unsigned long used_bits = opc->mask; | |
6961 | ||
6962 | if ((used_bits & opc->match) != opc->match) | |
6963 | { | |
6964 | as_bad (_("internal: bad mips opcode (mask error): %s %s"), | |
6965 | opc->name, opc->args); | |
6966 | return 0; | |
6967 | } | |
6968 | #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift))) | |
6969 | while (*p) | |
6970 | switch (c = *p++) | |
6971 | { | |
6972 | case ',': break; | |
6973 | case '(': break; | |
6974 | case ')': break; | |
6975 | case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
6976 | case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; | |
6977 | case 'A': break; | |
6978 | case 'B': USE_BITS (OP_MASK_SYSCALL, OP_SH_SYSCALL); break; | |
6979 | case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break; | |
6980 | case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break; | |
6981 | case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
6982 | case 'F': break; | |
6983 | case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
156c2f8b | 6984 | case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
252b5132 RH |
6985 | case 'I': break; |
6986 | case 'L': break; | |
6987 | case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break; | |
6988 | case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break; | |
6989 | case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break; | |
6990 | case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
6991 | case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
6992 | case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break; | |
6993 | case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break; | |
6994 | case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break; | |
6995 | case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
6996 | case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break; | |
6997 | case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break; | |
6998 | case 'f': break; | |
6999 | case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break; | |
7000 | case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
7001 | case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7002 | case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break; | |
7003 | case 'l': break; | |
156c2f8b | 7004 | case 'm': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break; |
252b5132 RH |
7005 | case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; |
7006 | case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; | |
7007 | case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break; | |
7008 | case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7009 | case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7010 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7011 | case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; | |
7012 | case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break; | |
7013 | case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break; | |
7014 | case 'x': break; | |
7015 | case 'z': break; | |
7016 | case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break; | |
7017 | default: | |
7018 | as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"), | |
7019 | c, opc->name, opc->args); | |
7020 | return 0; | |
7021 | } | |
7022 | #undef USE_BITS | |
7023 | if (used_bits != 0xffffffff) | |
7024 | { | |
7025 | as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"), | |
7026 | ~used_bits & 0xffffffff, opc->name, opc->args); | |
7027 | return 0; | |
7028 | } | |
7029 | return 1; | |
7030 | } | |
7031 | ||
7032 | /* This routine assembles an instruction into its binary format. As a | |
7033 | side effect, it sets one of the global variables imm_reloc or | |
7034 | offset_reloc to the type of relocation to do if one of the operands | |
7035 | is an address expression. */ | |
7036 | ||
7037 | static void | |
7038 | mips_ip (str, ip) | |
7039 | char *str; | |
7040 | struct mips_cl_insn *ip; | |
7041 | { | |
7042 | char *s; | |
7043 | const char *args; | |
43841e91 | 7044 | char c = 0; |
252b5132 RH |
7045 | struct mips_opcode *insn; |
7046 | char *argsStart; | |
7047 | unsigned int regno; | |
7048 | unsigned int lastregno = 0; | |
7049 | char *s_reset; | |
7050 | char save_c = 0; | |
7051 | int full_opcode_match = 1; | |
7052 | ||
7053 | insn_error = NULL; | |
7054 | ||
7055 | /* If the instruction contains a '.', we first try to match an instruction | |
7056 | including the '.'. Then we try again without the '.'. */ | |
7057 | insn = NULL; | |
d9a62219 | 7058 | for (s = str; *s != '\0' && !isspace ((unsigned char) *s); ++s) |
252b5132 RH |
7059 | continue; |
7060 | ||
7061 | /* If we stopped on whitespace, then replace the whitespace with null for | |
7062 | the call to hash_find. Save the character we replaced just in case we | |
7063 | have to re-parse the instruction. */ | |
d9a62219 | 7064 | if (isspace ((unsigned char) *s)) |
252b5132 RH |
7065 | { |
7066 | save_c = *s; | |
7067 | *s++ = '\0'; | |
7068 | } | |
bdaaa2e1 | 7069 | |
252b5132 RH |
7070 | insn = (struct mips_opcode *) hash_find (op_hash, str); |
7071 | ||
7072 | /* If we didn't find the instruction in the opcode table, try again, but | |
7073 | this time with just the instruction up to, but not including the | |
7074 | first '.'. */ | |
7075 | if (insn == NULL) | |
7076 | { | |
bdaaa2e1 | 7077 | /* Restore the character we overwrite above (if any). */ |
252b5132 RH |
7078 | if (save_c) |
7079 | *(--s) = save_c; | |
7080 | ||
7081 | /* Scan up to the first '.' or whitespace. */ | |
d9a62219 | 7082 | for (s = str; *s != '\0' && *s != '.' && !isspace ((unsigned char) *s); ++s) |
252b5132 RH |
7083 | continue; |
7084 | ||
7085 | /* If we did not find a '.', then we can quit now. */ | |
7086 | if (*s != '.') | |
7087 | { | |
7088 | insn_error = "unrecognized opcode"; | |
7089 | return; | |
7090 | } | |
7091 | ||
7092 | /* Lookup the instruction in the hash table. */ | |
7093 | *s++ = '\0'; | |
7094 | if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL) | |
7095 | { | |
7096 | insn_error = "unrecognized opcode"; | |
7097 | return; | |
7098 | } | |
7099 | ||
7100 | full_opcode_match = 0; | |
7101 | } | |
7102 | ||
7103 | argsStart = s; | |
7104 | for (;;) | |
7105 | { | |
252b5132 RH |
7106 | boolean ok; |
7107 | ||
7108 | assert (strcmp (insn->name, str) == 0); | |
7109 | ||
c97ef257 | 7110 | if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_cpu, mips_gp32)) |
252b5132 | 7111 | ok = true; |
bdaaa2e1 | 7112 | else |
252b5132 | 7113 | ok = false; |
bdaaa2e1 | 7114 | |
252b5132 RH |
7115 | if (insn->pinfo != INSN_MACRO) |
7116 | { | |
156c2f8b | 7117 | if (mips_cpu == CPU_R4650 && (insn->pinfo & FP_D) != 0) |
252b5132 RH |
7118 | ok = false; |
7119 | } | |
7120 | ||
7121 | if (! ok) | |
7122 | { | |
7123 | if (insn + 1 < &mips_opcodes[NUMOPCODES] | |
7124 | && strcmp (insn->name, insn[1].name) == 0) | |
7125 | { | |
7126 | ++insn; | |
7127 | continue; | |
7128 | } | |
252b5132 | 7129 | else |
43841e91 | 7130 | { |
252b5132 | 7131 | static char buf[100]; |
bdaaa2e1 | 7132 | sprintf (buf, |
156c2f8b NC |
7133 | _("opcode not supported on this processor: %s (MIPS%d)"), |
7134 | mips_cpu_to_str (mips_cpu), mips_opts.isa); | |
bdaaa2e1 | 7135 | |
252b5132 | 7136 | insn_error = buf; |
2bd7f1f3 | 7137 | return; |
252b5132 | 7138 | } |
252b5132 RH |
7139 | } |
7140 | ||
7141 | ip->insn_mo = insn; | |
7142 | ip->insn_opcode = insn->match; | |
7143 | for (args = insn->args;; ++args) | |
7144 | { | |
7145 | if (*s == ' ') | |
7146 | ++s; | |
7147 | switch (*args) | |
7148 | { | |
7149 | case '\0': /* end of args */ | |
7150 | if (*s == '\0') | |
7151 | return; | |
7152 | break; | |
7153 | ||
7154 | case ',': | |
7155 | if (*s++ == *args) | |
7156 | continue; | |
7157 | s--; | |
7158 | switch (*++args) | |
7159 | { | |
7160 | case 'r': | |
7161 | case 'v': | |
7162 | ip->insn_opcode |= lastregno << 21; | |
7163 | continue; | |
7164 | ||
7165 | case 'w': | |
7166 | case 'W': | |
7167 | ip->insn_opcode |= lastregno << 16; | |
7168 | continue; | |
7169 | ||
7170 | case 'V': | |
7171 | ip->insn_opcode |= lastregno << 11; | |
7172 | continue; | |
7173 | } | |
7174 | break; | |
7175 | ||
7176 | case '(': | |
7177 | /* Handle optional base register. | |
7178 | Either the base register is omitted or | |
bdaaa2e1 | 7179 | we must have a left paren. */ |
252b5132 RH |
7180 | /* This is dependent on the next operand specifier |
7181 | is a base register specification. */ | |
7182 | assert (args[1] == 'b' || args[1] == '5' | |
7183 | || args[1] == '-' || args[1] == '4'); | |
7184 | if (*s == '\0') | |
7185 | return; | |
7186 | ||
7187 | case ')': /* these must match exactly */ | |
7188 | if (*s++ == *args) | |
7189 | continue; | |
7190 | break; | |
7191 | ||
7192 | case '<': /* must be at least one digit */ | |
7193 | /* | |
7194 | * According to the manual, if the shift amount is greater | |
7195 | * than 31 or less than 0 the the shift amount should be | |
7196 | * mod 32. In reality the mips assembler issues an error. | |
7197 | * We issue a warning and mask out all but the low 5 bits. | |
7198 | */ | |
7199 | my_getExpression (&imm_expr, s); | |
7200 | check_absolute_expr (ip, &imm_expr); | |
7201 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7202 | { | |
7203 | as_warn (_("Improper shift amount (%ld)"), | |
7204 | (long) imm_expr.X_add_number); | |
7205 | imm_expr.X_add_number = imm_expr.X_add_number & 0x1f; | |
7206 | } | |
7207 | ip->insn_opcode |= imm_expr.X_add_number << 6; | |
7208 | imm_expr.X_op = O_absent; | |
7209 | s = expr_end; | |
7210 | continue; | |
7211 | ||
7212 | case '>': /* shift amount minus 32 */ | |
7213 | my_getExpression (&imm_expr, s); | |
7214 | check_absolute_expr (ip, &imm_expr); | |
7215 | if ((unsigned long) imm_expr.X_add_number < 32 | |
7216 | || (unsigned long) imm_expr.X_add_number > 63) | |
7217 | break; | |
7218 | ip->insn_opcode |= (imm_expr.X_add_number - 32) << 6; | |
7219 | imm_expr.X_op = O_absent; | |
7220 | s = expr_end; | |
7221 | continue; | |
7222 | ||
252b5132 RH |
7223 | case 'k': /* cache code */ |
7224 | case 'h': /* prefx code */ | |
7225 | my_getExpression (&imm_expr, s); | |
7226 | check_absolute_expr (ip, &imm_expr); | |
7227 | if ((unsigned long) imm_expr.X_add_number > 31) | |
7228 | { | |
7229 | as_warn (_("Invalid value for `%s' (%lu)"), | |
7230 | ip->insn_mo->name, | |
7231 | (unsigned long) imm_expr.X_add_number); | |
7232 | imm_expr.X_add_number &= 0x1f; | |
7233 | } | |
7234 | if (*args == 'k') | |
7235 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE; | |
7236 | else | |
7237 | ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX; | |
7238 | imm_expr.X_op = O_absent; | |
7239 | s = expr_end; | |
7240 | continue; | |
7241 | ||
7242 | case 'c': /* break code */ | |
7243 | my_getExpression (&imm_expr, s); | |
7244 | check_absolute_expr (ip, &imm_expr); | |
7245 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7246 | { | |
7247 | as_warn (_("Illegal break code (%ld)"), | |
7248 | (long) imm_expr.X_add_number); | |
7249 | imm_expr.X_add_number &= 0x3ff; | |
7250 | } | |
7251 | ip->insn_opcode |= imm_expr.X_add_number << 16; | |
7252 | imm_expr.X_op = O_absent; | |
7253 | s = expr_end; | |
7254 | continue; | |
7255 | ||
7256 | case 'q': /* lower break code */ | |
7257 | my_getExpression (&imm_expr, s); | |
7258 | check_absolute_expr (ip, &imm_expr); | |
7259 | if ((unsigned) imm_expr.X_add_number > 1023) | |
7260 | { | |
7261 | as_warn (_("Illegal lower break code (%ld)"), | |
7262 | (long) imm_expr.X_add_number); | |
7263 | imm_expr.X_add_number &= 0x3ff; | |
7264 | } | |
7265 | ip->insn_opcode |= imm_expr.X_add_number << 6; | |
7266 | imm_expr.X_op = O_absent; | |
7267 | s = expr_end; | |
7268 | continue; | |
7269 | ||
156c2f8b NC |
7270 | case 'm': /* Full 20 bit break code. */ |
7271 | my_getExpression (&imm_expr, s); | |
7272 | ||
7273 | check_absolute_expr (ip, &imm_expr); | |
7274 | ||
7275 | if ((unsigned) imm_expr.X_add_number > 0xfffff) | |
7276 | { | |
7277 | as_warn (_("Illegal break code (%ld)"), | |
7278 | (long) imm_expr.X_add_number); | |
7279 | imm_expr.X_add_number &= 0xfffff; | |
7280 | } | |
7281 | ||
7282 | ip->insn_opcode |= imm_expr.X_add_number << 6; | |
7283 | imm_expr.X_op = O_absent; | |
7284 | s = expr_end; | |
7285 | ||
7286 | continue; | |
7287 | ||
252b5132 RH |
7288 | case 'B': /* syscall code */ |
7289 | my_getExpression (&imm_expr, s); | |
7290 | check_absolute_expr (ip, &imm_expr); | |
7291 | if ((unsigned) imm_expr.X_add_number > 0xfffff) | |
7292 | as_warn (_("Illegal syscall code (%ld)"), | |
7293 | (long) imm_expr.X_add_number); | |
7294 | ip->insn_opcode |= imm_expr.X_add_number << 6; | |
7295 | imm_expr.X_op = O_absent; | |
7296 | s = expr_end; | |
7297 | continue; | |
7298 | ||
7299 | case 'C': /* Coprocessor code */ | |
7300 | my_getExpression (&imm_expr, s); | |
7301 | check_absolute_expr (ip, &imm_expr); | |
7302 | if ((unsigned long) imm_expr.X_add_number >= (1<<25)) | |
7303 | { | |
7304 | as_warn (_("Coproccesor code > 25 bits (%ld)"), | |
7305 | (long) imm_expr.X_add_number); | |
7306 | imm_expr.X_add_number &= ((1<<25) - 1); | |
7307 | } | |
7308 | ip->insn_opcode |= imm_expr.X_add_number; | |
7309 | imm_expr.X_op = O_absent; | |
7310 | s = expr_end; | |
7311 | continue; | |
7312 | ||
7313 | case 'P': /* Performance register */ | |
7314 | my_getExpression (&imm_expr, s); | |
7315 | check_absolute_expr (ip, &imm_expr); | |
7316 | if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1) | |
7317 | { | |
7318 | as_warn (_("Invalidate performance regster (%ld)"), | |
7319 | (long) imm_expr.X_add_number); | |
7320 | imm_expr.X_add_number &= 1; | |
7321 | } | |
7322 | ip->insn_opcode |= (imm_expr.X_add_number << 1); | |
7323 | imm_expr.X_op = O_absent; | |
7324 | s = expr_end; | |
7325 | continue; | |
7326 | ||
7327 | case 'b': /* base register */ | |
7328 | case 'd': /* destination register */ | |
7329 | case 's': /* source register */ | |
7330 | case 't': /* target register */ | |
7331 | case 'r': /* both target and source */ | |
7332 | case 'v': /* both dest and source */ | |
7333 | case 'w': /* both dest and target */ | |
7334 | case 'E': /* coprocessor target register */ | |
7335 | case 'G': /* coprocessor destination register */ | |
7336 | case 'x': /* ignore register name */ | |
7337 | case 'z': /* must be zero register */ | |
7338 | s_reset = s; | |
7339 | if (s[0] == '$') | |
7340 | { | |
7341 | ||
d9a62219 | 7342 | if (isdigit ((unsigned char) s[1])) |
252b5132 RH |
7343 | { |
7344 | ++s; | |
7345 | regno = 0; | |
7346 | do | |
7347 | { | |
7348 | regno *= 10; | |
7349 | regno += *s - '0'; | |
7350 | ++s; | |
7351 | } | |
d9a62219 | 7352 | while (isdigit ((unsigned char) *s)); |
252b5132 RH |
7353 | if (regno > 31) |
7354 | as_bad (_("Invalid register number (%d)"), regno); | |
7355 | } | |
7356 | else if (*args == 'E' || *args == 'G') | |
7357 | goto notreg; | |
7358 | else | |
7359 | { | |
7360 | if (s[1] == 'f' && s[2] == 'p') | |
7361 | { | |
7362 | s += 3; | |
7363 | regno = FP; | |
7364 | } | |
7365 | else if (s[1] == 's' && s[2] == 'p') | |
7366 | { | |
7367 | s += 3; | |
7368 | regno = SP; | |
7369 | } | |
7370 | else if (s[1] == 'g' && s[2] == 'p') | |
7371 | { | |
7372 | s += 3; | |
7373 | regno = GP; | |
7374 | } | |
7375 | else if (s[1] == 'a' && s[2] == 't') | |
7376 | { | |
7377 | s += 3; | |
7378 | regno = AT; | |
7379 | } | |
7380 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
7381 | { | |
7382 | s += 4; | |
7383 | regno = KT0; | |
7384 | } | |
7385 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
7386 | { | |
7387 | s += 4; | |
7388 | regno = KT1; | |
7389 | } | |
7390 | else if (itbl_have_entries) | |
7391 | { | |
7392 | char *p, *n; | |
d7ba4a77 | 7393 | unsigned long r; |
252b5132 | 7394 | |
d7ba4a77 | 7395 | p = s + 1; /* advance past '$' */ |
252b5132 RH |
7396 | n = itbl_get_field (&p); /* n is name */ |
7397 | ||
d7ba4a77 ILT |
7398 | /* See if this is a register defined in an |
7399 | itbl entry. */ | |
7400 | if (itbl_get_reg_val (n, &r)) | |
252b5132 RH |
7401 | { |
7402 | /* Get_field advances to the start of | |
7403 | the next field, so we need to back | |
d7ba4a77 | 7404 | rack to the end of the last field. */ |
bdaaa2e1 | 7405 | if (p) |
252b5132 | 7406 | s = p - 1; |
bdaaa2e1 | 7407 | else |
d7ba4a77 | 7408 | s = strchr (s, '\0'); |
252b5132 RH |
7409 | regno = r; |
7410 | } | |
7411 | else | |
7412 | goto notreg; | |
7413 | } | |
7414 | else | |
7415 | goto notreg; | |
7416 | } | |
7417 | if (regno == AT | |
7418 | && ! mips_opts.noat | |
7419 | && *args != 'E' | |
7420 | && *args != 'G') | |
7421 | as_warn (_("Used $at without \".set noat\"")); | |
7422 | c = *args; | |
7423 | if (*s == ' ') | |
7424 | s++; | |
7425 | if (args[1] != *s) | |
7426 | { | |
7427 | if (c == 'r' || c == 'v' || c == 'w') | |
7428 | { | |
7429 | regno = lastregno; | |
7430 | s = s_reset; | |
7431 | args++; | |
7432 | } | |
7433 | } | |
7434 | /* 'z' only matches $0. */ | |
7435 | if (c == 'z' && regno != 0) | |
7436 | break; | |
7437 | ||
bdaaa2e1 KH |
7438 | /* Now that we have assembled one operand, we use the args string |
7439 | * to figure out where it goes in the instruction. */ | |
252b5132 RH |
7440 | switch (c) |
7441 | { | |
7442 | case 'r': | |
7443 | case 's': | |
7444 | case 'v': | |
7445 | case 'b': | |
7446 | ip->insn_opcode |= regno << 21; | |
7447 | break; | |
7448 | case 'd': | |
7449 | case 'G': | |
7450 | ip->insn_opcode |= regno << 11; | |
7451 | break; | |
7452 | case 'w': | |
7453 | case 't': | |
7454 | case 'E': | |
7455 | ip->insn_opcode |= regno << 16; | |
7456 | break; | |
7457 | case 'x': | |
7458 | /* This case exists because on the r3000 trunc | |
7459 | expands into a macro which requires a gp | |
7460 | register. On the r6000 or r4000 it is | |
7461 | assembled into a single instruction which | |
7462 | ignores the register. Thus the insn version | |
7463 | is MIPS_ISA2 and uses 'x', and the macro | |
7464 | version is MIPS_ISA1 and uses 't'. */ | |
7465 | break; | |
7466 | case 'z': | |
7467 | /* This case is for the div instruction, which | |
7468 | acts differently if the destination argument | |
7469 | is $0. This only matches $0, and is checked | |
7470 | outside the switch. */ | |
7471 | break; | |
7472 | case 'D': | |
7473 | /* Itbl operand; not yet implemented. FIXME ?? */ | |
7474 | break; | |
7475 | /* What about all other operands like 'i', which | |
7476 | can be specified in the opcode table? */ | |
7477 | } | |
7478 | lastregno = regno; | |
7479 | continue; | |
7480 | } | |
7481 | notreg: | |
7482 | switch (*args++) | |
7483 | { | |
7484 | case 'r': | |
7485 | case 'v': | |
7486 | ip->insn_opcode |= lastregno << 21; | |
7487 | continue; | |
7488 | case 'w': | |
7489 | ip->insn_opcode |= lastregno << 16; | |
7490 | continue; | |
7491 | } | |
7492 | break; | |
7493 | ||
7494 | case 'D': /* floating point destination register */ | |
7495 | case 'S': /* floating point source register */ | |
7496 | case 'T': /* floating point target register */ | |
7497 | case 'R': /* floating point source register */ | |
7498 | case 'V': | |
7499 | case 'W': | |
7500 | s_reset = s; | |
d9a62219 | 7501 | if (s[0] == '$' && s[1] == 'f' && isdigit ((unsigned char) s[2])) |
252b5132 RH |
7502 | { |
7503 | s += 2; | |
7504 | regno = 0; | |
7505 | do | |
7506 | { | |
7507 | regno *= 10; | |
7508 | regno += *s - '0'; | |
7509 | ++s; | |
7510 | } | |
d9a62219 | 7511 | while (isdigit ((unsigned char) *s)); |
252b5132 RH |
7512 | |
7513 | if (regno > 31) | |
7514 | as_bad (_("Invalid float register number (%d)"), regno); | |
7515 | ||
7516 | if ((regno & 1) != 0 | |
9ce8a5dd | 7517 | && ! ISA_HAS_64BIT_REGS (mips_opts.isa) |
252b5132 RH |
7518 | && ! (strcmp (str, "mtc1") == 0 |
7519 | || strcmp (str, "mfc1") == 0 | |
7520 | || strcmp (str, "lwc1") == 0 | |
7521 | || strcmp (str, "swc1") == 0 | |
7522 | || strcmp (str, "l.s") == 0 | |
7523 | || strcmp (str, "s.s") == 0)) | |
7524 | as_warn (_("Float register should be even, was %d"), | |
7525 | regno); | |
7526 | ||
7527 | c = *args; | |
7528 | if (*s == ' ') | |
7529 | s++; | |
7530 | if (args[1] != *s) | |
7531 | { | |
7532 | if (c == 'V' || c == 'W') | |
7533 | { | |
7534 | regno = lastregno; | |
7535 | s = s_reset; | |
7536 | args++; | |
7537 | } | |
7538 | } | |
7539 | switch (c) | |
7540 | { | |
7541 | case 'D': | |
7542 | ip->insn_opcode |= regno << 6; | |
7543 | break; | |
7544 | case 'V': | |
7545 | case 'S': | |
7546 | ip->insn_opcode |= regno << 11; | |
7547 | break; | |
7548 | case 'W': | |
7549 | case 'T': | |
7550 | ip->insn_opcode |= regno << 16; | |
7551 | break; | |
7552 | case 'R': | |
7553 | ip->insn_opcode |= regno << 21; | |
7554 | break; | |
7555 | } | |
7556 | lastregno = regno; | |
7557 | continue; | |
7558 | } | |
7559 | ||
252b5132 RH |
7560 | switch (*args++) |
7561 | { | |
7562 | case 'V': | |
7563 | ip->insn_opcode |= lastregno << 11; | |
7564 | continue; | |
7565 | case 'W': | |
7566 | ip->insn_opcode |= lastregno << 16; | |
7567 | continue; | |
7568 | } | |
7569 | break; | |
7570 | ||
7571 | case 'I': | |
7572 | my_getExpression (&imm_expr, s); | |
7573 | if (imm_expr.X_op != O_big | |
7574 | && imm_expr.X_op != O_constant) | |
7575 | insn_error = _("absolute expression required"); | |
7576 | s = expr_end; | |
7577 | continue; | |
7578 | ||
7579 | case 'A': | |
7580 | my_getExpression (&offset_expr, s); | |
7581 | imm_reloc = BFD_RELOC_32; | |
7582 | s = expr_end; | |
7583 | continue; | |
7584 | ||
7585 | case 'F': | |
7586 | case 'L': | |
7587 | case 'f': | |
7588 | case 'l': | |
7589 | { | |
7590 | int f64; | |
7591 | char *save_in; | |
7592 | char *err; | |
7593 | unsigned char temp[8]; | |
7594 | int len; | |
7595 | unsigned int length; | |
7596 | segT seg; | |
7597 | subsegT subseg; | |
7598 | char *p; | |
7599 | ||
7600 | /* These only appear as the last operand in an | |
7601 | instruction, and every instruction that accepts | |
7602 | them in any variant accepts them in all variants. | |
7603 | This means we don't have to worry about backing out | |
7604 | any changes if the instruction does not match. | |
7605 | ||
7606 | The difference between them is the size of the | |
7607 | floating point constant and where it goes. For 'F' | |
7608 | and 'L' the constant is 64 bits; for 'f' and 'l' it | |
7609 | is 32 bits. Where the constant is placed is based | |
7610 | on how the MIPS assembler does things: | |
7611 | F -- .rdata | |
7612 | L -- .lit8 | |
7613 | f -- immediate value | |
7614 | l -- .lit4 | |
7615 | ||
7616 | The .lit4 and .lit8 sections are only used if | |
7617 | permitted by the -G argument. | |
7618 | ||
7619 | When generating embedded PIC code, we use the | |
7620 | .lit8 section but not the .lit4 section (we can do | |
7621 | .lit4 inline easily; we need to put .lit8 | |
7622 | somewhere in the data segment, and using .lit8 | |
7623 | permits the linker to eventually combine identical | |
7624 | .lit8 entries). */ | |
7625 | ||
7626 | f64 = *args == 'F' || *args == 'L'; | |
7627 | ||
7628 | save_in = input_line_pointer; | |
7629 | input_line_pointer = s; | |
7630 | err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len); | |
7631 | length = len; | |
7632 | s = input_line_pointer; | |
7633 | input_line_pointer = save_in; | |
7634 | if (err != NULL && *err != '\0') | |
7635 | { | |
7636 | as_bad (_("Bad floating point constant: %s"), err); | |
7637 | memset (temp, '\0', sizeof temp); | |
7638 | length = f64 ? 8 : 4; | |
7639 | } | |
7640 | ||
156c2f8b | 7641 | assert (length == (unsigned) (f64 ? 8 : 4)); |
252b5132 RH |
7642 | |
7643 | if (*args == 'f' | |
7644 | || (*args == 'l' | |
7645 | && (! USE_GLOBAL_POINTER_OPT | |
7646 | || mips_pic == EMBEDDED_PIC | |
7647 | || g_switch_value < 4 | |
7648 | || (temp[0] == 0 && temp[1] == 0) | |
7649 | || (temp[2] == 0 && temp[3] == 0)))) | |
7650 | { | |
7651 | imm_expr.X_op = O_constant; | |
7652 | if (! target_big_endian) | |
7653 | imm_expr.X_add_number = bfd_getl32 (temp); | |
7654 | else | |
7655 | imm_expr.X_add_number = bfd_getb32 (temp); | |
7656 | } | |
7657 | else if (length > 4 | |
119d663a | 7658 | && ! mips_disable_float_construction |
252b5132 RH |
7659 | && ((temp[0] == 0 && temp[1] == 0) |
7660 | || (temp[2] == 0 && temp[3] == 0)) | |
7661 | && ((temp[4] == 0 && temp[5] == 0) | |
7662 | || (temp[6] == 0 && temp[7] == 0))) | |
7663 | { | |
7664 | /* The value is simple enough to load with a | |
7665 | couple of instructions. In mips1 mode, set | |
7666 | imm_expr to the high order 32 bits and | |
7667 | offset_expr to the low order 32 bits. | |
7668 | Otherwise, set imm_expr to the entire 64 bit | |
7669 | constant. */ | |
9ce8a5dd | 7670 | if (! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
7671 | { |
7672 | imm_expr.X_op = O_constant; | |
7673 | offset_expr.X_op = O_constant; | |
7674 | if (! target_big_endian) | |
7675 | { | |
7676 | imm_expr.X_add_number = bfd_getl32 (temp + 4); | |
7677 | offset_expr.X_add_number = bfd_getl32 (temp); | |
7678 | } | |
7679 | else | |
7680 | { | |
7681 | imm_expr.X_add_number = bfd_getb32 (temp); | |
7682 | offset_expr.X_add_number = bfd_getb32 (temp + 4); | |
7683 | } | |
7684 | if (offset_expr.X_add_number == 0) | |
7685 | offset_expr.X_op = O_absent; | |
7686 | } | |
7687 | else if (sizeof (imm_expr.X_add_number) > 4) | |
7688 | { | |
7689 | imm_expr.X_op = O_constant; | |
7690 | if (! target_big_endian) | |
7691 | imm_expr.X_add_number = bfd_getl64 (temp); | |
7692 | else | |
7693 | imm_expr.X_add_number = bfd_getb64 (temp); | |
7694 | } | |
7695 | else | |
7696 | { | |
7697 | imm_expr.X_op = O_big; | |
7698 | imm_expr.X_add_number = 4; | |
7699 | if (! target_big_endian) | |
7700 | { | |
7701 | generic_bignum[0] = bfd_getl16 (temp); | |
7702 | generic_bignum[1] = bfd_getl16 (temp + 2); | |
7703 | generic_bignum[2] = bfd_getl16 (temp + 4); | |
7704 | generic_bignum[3] = bfd_getl16 (temp + 6); | |
7705 | } | |
7706 | else | |
7707 | { | |
7708 | generic_bignum[0] = bfd_getb16 (temp + 6); | |
7709 | generic_bignum[1] = bfd_getb16 (temp + 4); | |
7710 | generic_bignum[2] = bfd_getb16 (temp + 2); | |
7711 | generic_bignum[3] = bfd_getb16 (temp); | |
7712 | } | |
7713 | } | |
7714 | } | |
7715 | else | |
7716 | { | |
7717 | const char *newname; | |
7718 | segT new_seg; | |
7719 | ||
7720 | /* Switch to the right section. */ | |
7721 | seg = now_seg; | |
7722 | subseg = now_subseg; | |
7723 | switch (*args) | |
7724 | { | |
7725 | default: /* unused default case avoids warnings. */ | |
7726 | case 'L': | |
7727 | newname = RDATA_SECTION_NAME; | |
bb2d6cd7 GK |
7728 | if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8) |
7729 | || mips_pic == EMBEDDED_PIC) | |
252b5132 RH |
7730 | newname = ".lit8"; |
7731 | break; | |
7732 | case 'F': | |
bb2d6cd7 GK |
7733 | if (mips_pic == EMBEDDED_PIC) |
7734 | newname = ".lit8"; | |
7735 | else | |
7736 | newname = RDATA_SECTION_NAME; | |
252b5132 RH |
7737 | break; |
7738 | case 'l': | |
7739 | assert (!USE_GLOBAL_POINTER_OPT | |
7740 | || g_switch_value >= 4); | |
7741 | newname = ".lit4"; | |
7742 | break; | |
7743 | } | |
7744 | new_seg = subseg_new (newname, (subsegT) 0); | |
7745 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
7746 | bfd_set_section_flags (stdoutput, new_seg, | |
7747 | (SEC_ALLOC | |
7748 | | SEC_LOAD | |
7749 | | SEC_READONLY | |
7750 | | SEC_DATA)); | |
7751 | frag_align (*args == 'l' ? 2 : 3, 0, 0); | |
7752 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
7753 | && strcmp (TARGET_OS, "elf") != 0) | |
7754 | record_alignment (new_seg, 4); | |
7755 | else | |
7756 | record_alignment (new_seg, *args == 'l' ? 2 : 3); | |
7757 | if (seg == now_seg) | |
7758 | as_bad (_("Can't use floating point insn in this section")); | |
7759 | ||
7760 | /* Set the argument to the current address in the | |
7761 | section. */ | |
7762 | offset_expr.X_op = O_symbol; | |
7763 | offset_expr.X_add_symbol = | |
7764 | symbol_new ("L0\001", now_seg, | |
7765 | (valueT) frag_now_fix (), frag_now); | |
7766 | offset_expr.X_add_number = 0; | |
7767 | ||
7768 | /* Put the floating point number into the section. */ | |
7769 | p = frag_more ((int) length); | |
7770 | memcpy (p, temp, length); | |
7771 | ||
7772 | /* Switch back to the original section. */ | |
7773 | subseg_set (seg, subseg); | |
7774 | } | |
7775 | } | |
7776 | continue; | |
7777 | ||
7778 | case 'i': /* 16 bit unsigned immediate */ | |
7779 | case 'j': /* 16 bit signed immediate */ | |
7780 | imm_reloc = BFD_RELOC_LO16; | |
7781 | c = my_getSmallExpression (&imm_expr, s); | |
7782 | if (c != '\0') | |
7783 | { | |
7784 | if (c != 'l') | |
7785 | { | |
7786 | if (imm_expr.X_op == O_constant) | |
7787 | imm_expr.X_add_number = | |
7788 | (imm_expr.X_add_number >> 16) & 0xffff; | |
7789 | else if (c == 'h') | |
7790 | { | |
7791 | imm_reloc = BFD_RELOC_HI16_S; | |
7792 | imm_unmatched_hi = true; | |
7793 | } | |
7794 | else | |
7795 | imm_reloc = BFD_RELOC_HI16; | |
7796 | } | |
7797 | else if (imm_expr.X_op == O_constant) | |
7798 | imm_expr.X_add_number &= 0xffff; | |
7799 | } | |
7800 | if (*args == 'i') | |
7801 | { | |
7802 | if ((c == '\0' && imm_expr.X_op != O_constant) | |
7803 | || ((imm_expr.X_add_number < 0 | |
7804 | || imm_expr.X_add_number >= 0x10000) | |
7805 | && imm_expr.X_op == O_constant)) | |
7806 | { | |
7807 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7808 | !strcmp (insn->name, insn[1].name)) | |
7809 | break; | |
2ae7e77b AH |
7810 | if (imm_expr.X_op == O_constant |
7811 | || imm_expr.X_op == O_big) | |
252b5132 RH |
7812 | as_bad (_("16 bit expression not in range 0..65535")); |
7813 | } | |
7814 | } | |
7815 | else | |
7816 | { | |
7817 | int more; | |
7818 | offsetT max; | |
7819 | ||
7820 | /* The upper bound should be 0x8000, but | |
7821 | unfortunately the MIPS assembler accepts numbers | |
7822 | from 0x8000 to 0xffff and sign extends them, and | |
7823 | we want to be compatible. We only permit this | |
7824 | extended range for an instruction which does not | |
7825 | provide any further alternates, since those | |
7826 | alternates may handle other cases. People should | |
7827 | use the numbers they mean, rather than relying on | |
7828 | a mysterious sign extension. */ | |
7829 | more = (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7830 | strcmp (insn->name, insn[1].name) == 0); | |
7831 | if (more) | |
7832 | max = 0x8000; | |
7833 | else | |
7834 | max = 0x10000; | |
7835 | if ((c == '\0' && imm_expr.X_op != O_constant) | |
7836 | || ((imm_expr.X_add_number < -0x8000 | |
7837 | || imm_expr.X_add_number >= max) | |
7838 | && imm_expr.X_op == O_constant) | |
7839 | || (more | |
7840 | && imm_expr.X_add_number < 0 | |
9ce8a5dd | 7841 | && ISA_HAS_64BIT_REGS (mips_opts.isa) |
252b5132 RH |
7842 | && imm_expr.X_unsigned |
7843 | && sizeof (imm_expr.X_add_number) <= 4)) | |
7844 | { | |
7845 | if (more) | |
7846 | break; | |
2ae7e77b AH |
7847 | if (imm_expr.X_op == O_constant |
7848 | || imm_expr.X_op == O_big) | |
252b5132 RH |
7849 | as_bad (_("16 bit expression not in range -32768..32767")); |
7850 | } | |
7851 | } | |
7852 | s = expr_end; | |
7853 | continue; | |
7854 | ||
7855 | case 'o': /* 16 bit offset */ | |
7856 | c = my_getSmallExpression (&offset_expr, s); | |
7857 | ||
7858 | /* If this value won't fit into a 16 bit offset, then go | |
7859 | find a macro that will generate the 32 bit offset | |
7860 | code pattern. As a special hack, we accept the | |
7861 | difference of two local symbols as a constant. This | |
7862 | is required to suppose embedded PIC switches, which | |
7863 | use an instruction which looks like | |
7864 | lw $4,$L12-$LS12($4) | |
7865 | The problem with handling this in a more general | |
7866 | fashion is that the macro function doesn't expect to | |
7867 | see anything which can be handled in a single | |
7868 | constant instruction. */ | |
7869 | if (c == 0 | |
7870 | && (offset_expr.X_op != O_constant | |
7871 | || offset_expr.X_add_number >= 0x8000 | |
7872 | || offset_expr.X_add_number < -0x8000) | |
7873 | && (mips_pic != EMBEDDED_PIC | |
7874 | || offset_expr.X_op != O_subtract | |
252b5132 | 7875 | || (S_GET_SEGMENT (offset_expr.X_op_symbol) |
bb2d6cd7 | 7876 | != now_seg))) |
252b5132 RH |
7877 | break; |
7878 | ||
7879 | if (c == 'h' || c == 'H') | |
7880 | { | |
7881 | if (offset_expr.X_op != O_constant) | |
7882 | break; | |
7883 | offset_expr.X_add_number = | |
7884 | (offset_expr.X_add_number >> 16) & 0xffff; | |
7885 | } | |
7886 | offset_reloc = BFD_RELOC_LO16; | |
7887 | s = expr_end; | |
7888 | continue; | |
7889 | ||
7890 | case 'p': /* pc relative offset */ | |
7891 | offset_reloc = BFD_RELOC_16_PCREL_S2; | |
7892 | my_getExpression (&offset_expr, s); | |
7893 | s = expr_end; | |
7894 | continue; | |
7895 | ||
7896 | case 'u': /* upper 16 bits */ | |
7897 | c = my_getSmallExpression (&imm_expr, s); | |
7898 | imm_reloc = BFD_RELOC_LO16; | |
7899 | if (c) | |
7900 | { | |
7901 | if (c != 'l') | |
7902 | { | |
7903 | if (imm_expr.X_op == O_constant) | |
7904 | imm_expr.X_add_number = | |
7905 | (imm_expr.X_add_number >> 16) & 0xffff; | |
7906 | else if (c == 'h') | |
7907 | { | |
7908 | imm_reloc = BFD_RELOC_HI16_S; | |
7909 | imm_unmatched_hi = true; | |
7910 | } | |
7911 | else | |
7912 | imm_reloc = BFD_RELOC_HI16; | |
7913 | } | |
7914 | else if (imm_expr.X_op == O_constant) | |
7915 | imm_expr.X_add_number &= 0xffff; | |
7916 | } | |
7917 | if (imm_expr.X_op == O_constant | |
7918 | && (imm_expr.X_add_number < 0 | |
7919 | || imm_expr.X_add_number >= 0x10000)) | |
7920 | as_bad (_("lui expression not in range 0..65535")); | |
7921 | s = expr_end; | |
7922 | continue; | |
7923 | ||
7924 | case 'a': /* 26 bit address */ | |
7925 | my_getExpression (&offset_expr, s); | |
7926 | s = expr_end; | |
7927 | offset_reloc = BFD_RELOC_MIPS_JMP; | |
7928 | continue; | |
7929 | ||
7930 | case 'N': /* 3 bit branch condition code */ | |
7931 | case 'M': /* 3 bit compare condition code */ | |
7932 | if (strncmp (s, "$fcc", 4) != 0) | |
7933 | break; | |
7934 | s += 4; | |
7935 | regno = 0; | |
7936 | do | |
7937 | { | |
7938 | regno *= 10; | |
7939 | regno += *s - '0'; | |
7940 | ++s; | |
7941 | } | |
d9a62219 | 7942 | while (isdigit ((unsigned char) *s)); |
252b5132 RH |
7943 | if (regno > 7) |
7944 | as_bad (_("invalid condition code register $fcc%d"), regno); | |
7945 | if (*args == 'N') | |
7946 | ip->insn_opcode |= regno << OP_SH_BCC; | |
7947 | else | |
7948 | ip->insn_opcode |= regno << OP_SH_CCC; | |
7949 | continue; | |
7950 | ||
156c2f8b NC |
7951 | case 'H': |
7952 | if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) | |
7953 | s += 2; | |
7954 | if (isdigit ((unsigned char) *s)) | |
7955 | { | |
7956 | c = 0; | |
7957 | do | |
7958 | { | |
7959 | c *= 10; | |
7960 | c += *s - '0'; | |
7961 | ++s; | |
7962 | } | |
7963 | while (isdigit ((unsigned char) *s)); | |
7964 | } | |
7965 | else | |
7966 | c = 8; /* Invalid sel value. */ | |
7967 | ||
7968 | if (c > 7) | |
7969 | as_bad (_("invalid coprocessor sub-selection value (0-7)")); | |
7970 | ip->insn_opcode |= c; | |
7971 | continue; | |
7972 | ||
252b5132 RH |
7973 | default: |
7974 | as_bad (_("bad char = '%c'\n"), *args); | |
7975 | internalError (); | |
7976 | } | |
7977 | break; | |
7978 | } | |
7979 | /* Args don't match. */ | |
7980 | if (insn + 1 < &mips_opcodes[NUMOPCODES] && | |
7981 | !strcmp (insn->name, insn[1].name)) | |
7982 | { | |
7983 | ++insn; | |
7984 | s = argsStart; | |
7985 | continue; | |
7986 | } | |
7987 | insn_error = _("illegal operands"); | |
7988 | return; | |
7989 | } | |
7990 | } | |
7991 | ||
7992 | /* This routine assembles an instruction into its binary format when | |
7993 | assembling for the mips16. As a side effect, it sets one of the | |
7994 | global variables imm_reloc or offset_reloc to the type of | |
7995 | relocation to do if one of the operands is an address expression. | |
7996 | It also sets mips16_small and mips16_ext if the user explicitly | |
7997 | requested a small or extended instruction. */ | |
7998 | ||
7999 | static void | |
8000 | mips16_ip (str, ip) | |
8001 | char *str; | |
8002 | struct mips_cl_insn *ip; | |
8003 | { | |
8004 | char *s; | |
8005 | const char *args; | |
8006 | struct mips_opcode *insn; | |
8007 | char *argsstart; | |
8008 | unsigned int regno; | |
8009 | unsigned int lastregno = 0; | |
8010 | char *s_reset; | |
8011 | ||
8012 | insn_error = NULL; | |
8013 | ||
8014 | mips16_small = false; | |
8015 | mips16_ext = false; | |
8016 | ||
d9a62219 | 8017 | for (s = str; islower ((unsigned char) *s); ++s) |
252b5132 RH |
8018 | ; |
8019 | switch (*s) | |
8020 | { | |
8021 | case '\0': | |
8022 | break; | |
8023 | ||
8024 | case ' ': | |
8025 | *s++ = '\0'; | |
8026 | break; | |
8027 | ||
8028 | case '.': | |
8029 | if (s[1] == 't' && s[2] == ' ') | |
8030 | { | |
8031 | *s = '\0'; | |
8032 | mips16_small = true; | |
8033 | s += 3; | |
8034 | break; | |
8035 | } | |
8036 | else if (s[1] == 'e' && s[2] == ' ') | |
8037 | { | |
8038 | *s = '\0'; | |
8039 | mips16_ext = true; | |
8040 | s += 3; | |
8041 | break; | |
8042 | } | |
8043 | /* Fall through. */ | |
8044 | default: | |
8045 | insn_error = _("unknown opcode"); | |
8046 | return; | |
8047 | } | |
8048 | ||
8049 | if (mips_opts.noautoextend && ! mips16_ext) | |
8050 | mips16_small = true; | |
8051 | ||
8052 | if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL) | |
8053 | { | |
8054 | insn_error = _("unrecognized opcode"); | |
8055 | return; | |
8056 | } | |
8057 | ||
8058 | argsstart = s; | |
8059 | for (;;) | |
8060 | { | |
8061 | assert (strcmp (insn->name, str) == 0); | |
8062 | ||
8063 | ip->insn_mo = insn; | |
8064 | ip->insn_opcode = insn->match; | |
8065 | ip->use_extend = false; | |
8066 | imm_expr.X_op = O_absent; | |
8067 | imm_reloc = BFD_RELOC_UNUSED; | |
8068 | offset_expr.X_op = O_absent; | |
8069 | offset_reloc = BFD_RELOC_UNUSED; | |
8070 | for (args = insn->args; 1; ++args) | |
8071 | { | |
8072 | int c; | |
8073 | ||
8074 | if (*s == ' ') | |
8075 | ++s; | |
8076 | ||
8077 | /* In this switch statement we call break if we did not find | |
8078 | a match, continue if we did find a match, or return if we | |
8079 | are done. */ | |
8080 | ||
8081 | c = *args; | |
8082 | switch (c) | |
8083 | { | |
8084 | case '\0': | |
8085 | if (*s == '\0') | |
8086 | { | |
8087 | /* Stuff the immediate value in now, if we can. */ | |
8088 | if (imm_expr.X_op == O_constant | |
8089 | && imm_reloc > BFD_RELOC_UNUSED | |
8090 | && insn->pinfo != INSN_MACRO) | |
8091 | { | |
8092 | mips16_immed ((char *) NULL, 0, | |
8093 | imm_reloc - BFD_RELOC_UNUSED, | |
8094 | imm_expr.X_add_number, true, mips16_small, | |
8095 | mips16_ext, &ip->insn_opcode, | |
8096 | &ip->use_extend, &ip->extend); | |
8097 | imm_expr.X_op = O_absent; | |
8098 | imm_reloc = BFD_RELOC_UNUSED; | |
8099 | } | |
8100 | ||
8101 | return; | |
8102 | } | |
8103 | break; | |
8104 | ||
8105 | case ',': | |
8106 | if (*s++ == c) | |
8107 | continue; | |
8108 | s--; | |
8109 | switch (*++args) | |
8110 | { | |
8111 | case 'v': | |
8112 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8113 | continue; | |
8114 | case 'w': | |
8115 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8116 | continue; | |
8117 | } | |
8118 | break; | |
8119 | ||
8120 | case '(': | |
8121 | case ')': | |
8122 | if (*s++ == c) | |
8123 | continue; | |
8124 | break; | |
8125 | ||
8126 | case 'v': | |
8127 | case 'w': | |
8128 | if (s[0] != '$') | |
8129 | { | |
8130 | if (c == 'v') | |
8131 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RX; | |
8132 | else | |
8133 | ip->insn_opcode |= lastregno << MIPS16OP_SH_RY; | |
8134 | ++args; | |
8135 | continue; | |
8136 | } | |
8137 | /* Fall through. */ | |
8138 | case 'x': | |
8139 | case 'y': | |
8140 | case 'z': | |
8141 | case 'Z': | |
8142 | case '0': | |
8143 | case 'S': | |
8144 | case 'R': | |
8145 | case 'X': | |
8146 | case 'Y': | |
8147 | if (s[0] != '$') | |
8148 | break; | |
8149 | s_reset = s; | |
d9a62219 | 8150 | if (isdigit ((unsigned char) s[1])) |
252b5132 RH |
8151 | { |
8152 | ++s; | |
8153 | regno = 0; | |
8154 | do | |
8155 | { | |
8156 | regno *= 10; | |
8157 | regno += *s - '0'; | |
8158 | ++s; | |
8159 | } | |
d9a62219 | 8160 | while (isdigit ((unsigned char) *s)); |
252b5132 RH |
8161 | if (regno > 31) |
8162 | { | |
8163 | as_bad (_("invalid register number (%d)"), regno); | |
8164 | regno = 2; | |
8165 | } | |
8166 | } | |
8167 | else | |
8168 | { | |
8169 | if (s[1] == 'f' && s[2] == 'p') | |
8170 | { | |
8171 | s += 3; | |
8172 | regno = FP; | |
8173 | } | |
8174 | else if (s[1] == 's' && s[2] == 'p') | |
8175 | { | |
8176 | s += 3; | |
8177 | regno = SP; | |
8178 | } | |
8179 | else if (s[1] == 'g' && s[2] == 'p') | |
8180 | { | |
8181 | s += 3; | |
8182 | regno = GP; | |
8183 | } | |
8184 | else if (s[1] == 'a' && s[2] == 't') | |
8185 | { | |
8186 | s += 3; | |
8187 | regno = AT; | |
8188 | } | |
8189 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '0') | |
8190 | { | |
8191 | s += 4; | |
8192 | regno = KT0; | |
8193 | } | |
8194 | else if (s[1] == 'k' && s[2] == 't' && s[3] == '1') | |
8195 | { | |
8196 | s += 4; | |
8197 | regno = KT1; | |
8198 | } | |
8199 | else | |
8200 | break; | |
8201 | } | |
8202 | ||
8203 | if (*s == ' ') | |
8204 | ++s; | |
8205 | if (args[1] != *s) | |
8206 | { | |
8207 | if (c == 'v' || c == 'w') | |
8208 | { | |
8209 | regno = mips16_to_32_reg_map[lastregno]; | |
8210 | s = s_reset; | |
8211 | args++; | |
8212 | } | |
8213 | } | |
8214 | ||
8215 | switch (c) | |
8216 | { | |
8217 | case 'x': | |
8218 | case 'y': | |
8219 | case 'z': | |
8220 | case 'v': | |
8221 | case 'w': | |
8222 | case 'Z': | |
8223 | regno = mips32_to_16_reg_map[regno]; | |
8224 | break; | |
8225 | ||
8226 | case '0': | |
8227 | if (regno != 0) | |
8228 | regno = ILLEGAL_REG; | |
8229 | break; | |
8230 | ||
8231 | case 'S': | |
8232 | if (regno != SP) | |
8233 | regno = ILLEGAL_REG; | |
8234 | break; | |
8235 | ||
8236 | case 'R': | |
8237 | if (regno != RA) | |
8238 | regno = ILLEGAL_REG; | |
8239 | break; | |
8240 | ||
8241 | case 'X': | |
8242 | case 'Y': | |
8243 | if (regno == AT && ! mips_opts.noat) | |
8244 | as_warn (_("used $at without \".set noat\"")); | |
8245 | break; | |
8246 | ||
8247 | default: | |
8248 | internalError (); | |
8249 | } | |
8250 | ||
8251 | if (regno == ILLEGAL_REG) | |
8252 | break; | |
8253 | ||
8254 | switch (c) | |
8255 | { | |
8256 | case 'x': | |
8257 | case 'v': | |
8258 | ip->insn_opcode |= regno << MIPS16OP_SH_RX; | |
8259 | break; | |
8260 | case 'y': | |
8261 | case 'w': | |
8262 | ip->insn_opcode |= regno << MIPS16OP_SH_RY; | |
8263 | break; | |
8264 | case 'z': | |
8265 | ip->insn_opcode |= regno << MIPS16OP_SH_RZ; | |
8266 | break; | |
8267 | case 'Z': | |
8268 | ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z; | |
8269 | case '0': | |
8270 | case 'S': | |
8271 | case 'R': | |
8272 | break; | |
8273 | case 'X': | |
8274 | ip->insn_opcode |= regno << MIPS16OP_SH_REGR32; | |
8275 | break; | |
8276 | case 'Y': | |
8277 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); | |
8278 | ip->insn_opcode |= regno << MIPS16OP_SH_REG32R; | |
8279 | break; | |
8280 | default: | |
8281 | internalError (); | |
8282 | } | |
8283 | ||
8284 | lastregno = regno; | |
8285 | continue; | |
8286 | ||
8287 | case 'P': | |
8288 | if (strncmp (s, "$pc", 3) == 0) | |
8289 | { | |
8290 | s += 3; | |
8291 | continue; | |
8292 | } | |
8293 | break; | |
8294 | ||
8295 | case '<': | |
8296 | case '>': | |
8297 | case '[': | |
8298 | case ']': | |
8299 | case '4': | |
8300 | case '5': | |
8301 | case 'H': | |
8302 | case 'W': | |
8303 | case 'D': | |
8304 | case 'j': | |
8305 | case '8': | |
8306 | case 'V': | |
8307 | case 'C': | |
8308 | case 'U': | |
8309 | case 'k': | |
8310 | case 'K': | |
8311 | if (s[0] == '%' | |
8312 | && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0) | |
8313 | { | |
8314 | /* This is %gprel(SYMBOL). We need to read SYMBOL, | |
8315 | and generate the appropriate reloc. If the text | |
8316 | inside %gprel is not a symbol name with an | |
8317 | optional offset, then we generate a normal reloc | |
8318 | and will probably fail later. */ | |
8319 | my_getExpression (&imm_expr, s + sizeof "%gprel" - 1); | |
8320 | if (imm_expr.X_op == O_symbol) | |
8321 | { | |
8322 | mips16_ext = true; | |
8323 | imm_reloc = BFD_RELOC_MIPS16_GPREL; | |
8324 | s = expr_end; | |
8325 | ip->use_extend = true; | |
8326 | ip->extend = 0; | |
8327 | continue; | |
8328 | } | |
8329 | } | |
8330 | else | |
8331 | { | |
8332 | /* Just pick up a normal expression. */ | |
8333 | my_getExpression (&imm_expr, s); | |
8334 | } | |
8335 | ||
8336 | if (imm_expr.X_op == O_register) | |
8337 | { | |
8338 | /* What we thought was an expression turned out to | |
8339 | be a register. */ | |
8340 | ||
8341 | if (s[0] == '(' && args[1] == '(') | |
8342 | { | |
8343 | /* It looks like the expression was omitted | |
8344 | before a register indirection, which means | |
8345 | that the expression is implicitly zero. We | |
8346 | still set up imm_expr, so that we handle | |
8347 | explicit extensions correctly. */ | |
8348 | imm_expr.X_op = O_constant; | |
8349 | imm_expr.X_add_number = 0; | |
8350 | imm_reloc = (int) BFD_RELOC_UNUSED + c; | |
8351 | continue; | |
8352 | } | |
8353 | ||
8354 | break; | |
8355 | } | |
8356 | ||
8357 | /* We need to relax this instruction. */ | |
8358 | imm_reloc = (int) BFD_RELOC_UNUSED + c; | |
8359 | s = expr_end; | |
8360 | continue; | |
8361 | ||
8362 | case 'p': | |
8363 | case 'q': | |
8364 | case 'A': | |
8365 | case 'B': | |
8366 | case 'E': | |
8367 | /* We use offset_reloc rather than imm_reloc for the PC | |
8368 | relative operands. This lets macros with both | |
8369 | immediate and address operands work correctly. */ | |
8370 | my_getExpression (&offset_expr, s); | |
8371 | ||
8372 | if (offset_expr.X_op == O_register) | |
8373 | break; | |
8374 | ||
8375 | /* We need to relax this instruction. */ | |
8376 | offset_reloc = (int) BFD_RELOC_UNUSED + c; | |
8377 | s = expr_end; | |
8378 | continue; | |
8379 | ||
8380 | case '6': /* break code */ | |
8381 | my_getExpression (&imm_expr, s); | |
8382 | check_absolute_expr (ip, &imm_expr); | |
8383 | if ((unsigned long) imm_expr.X_add_number > 63) | |
8384 | { | |
8385 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8386 | ip->insn_mo->name, | |
8387 | (unsigned long) imm_expr.X_add_number); | |
8388 | imm_expr.X_add_number &= 0x3f; | |
8389 | } | |
8390 | ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6; | |
8391 | imm_expr.X_op = O_absent; | |
8392 | s = expr_end; | |
8393 | continue; | |
8394 | ||
8395 | case 'a': /* 26 bit address */ | |
8396 | my_getExpression (&offset_expr, s); | |
8397 | s = expr_end; | |
8398 | offset_reloc = BFD_RELOC_MIPS16_JMP; | |
8399 | ip->insn_opcode <<= 16; | |
8400 | continue; | |
8401 | ||
8402 | case 'l': /* register list for entry macro */ | |
8403 | case 'L': /* register list for exit macro */ | |
8404 | { | |
8405 | int mask; | |
8406 | ||
8407 | if (c == 'l') | |
8408 | mask = 0; | |
8409 | else | |
8410 | mask = 7 << 3; | |
8411 | while (*s != '\0') | |
8412 | { | |
8413 | int freg, reg1, reg2; | |
8414 | ||
8415 | while (*s == ' ' || *s == ',') | |
8416 | ++s; | |
8417 | if (*s != '$') | |
8418 | { | |
8419 | as_bad (_("can't parse register list")); | |
8420 | break; | |
8421 | } | |
8422 | ++s; | |
8423 | if (*s != 'f') | |
8424 | freg = 0; | |
8425 | else | |
8426 | { | |
8427 | freg = 1; | |
8428 | ++s; | |
8429 | } | |
8430 | reg1 = 0; | |
d9a62219 | 8431 | while (isdigit ((unsigned char) *s)) |
252b5132 RH |
8432 | { |
8433 | reg1 *= 10; | |
8434 | reg1 += *s - '0'; | |
8435 | ++s; | |
8436 | } | |
8437 | if (*s == ' ') | |
8438 | ++s; | |
8439 | if (*s != '-') | |
8440 | reg2 = reg1; | |
8441 | else | |
8442 | { | |
8443 | ++s; | |
8444 | if (*s != '$') | |
8445 | break; | |
8446 | ++s; | |
8447 | if (freg) | |
8448 | { | |
8449 | if (*s == 'f') | |
8450 | ++s; | |
8451 | else | |
8452 | { | |
8453 | as_bad (_("invalid register list")); | |
8454 | break; | |
8455 | } | |
8456 | } | |
8457 | reg2 = 0; | |
d9a62219 | 8458 | while (isdigit ((unsigned char) *s)) |
252b5132 RH |
8459 | { |
8460 | reg2 *= 10; | |
8461 | reg2 += *s - '0'; | |
8462 | ++s; | |
8463 | } | |
8464 | } | |
8465 | if (freg && reg1 == 0 && reg2 == 0 && c == 'L') | |
8466 | { | |
8467 | mask &= ~ (7 << 3); | |
8468 | mask |= 5 << 3; | |
8469 | } | |
8470 | else if (freg && reg1 == 0 && reg2 == 1 && c == 'L') | |
8471 | { | |
8472 | mask &= ~ (7 << 3); | |
8473 | mask |= 6 << 3; | |
8474 | } | |
8475 | else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L') | |
8476 | mask |= (reg2 - 3) << 3; | |
8477 | else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17) | |
8478 | mask |= (reg2 - 15) << 1; | |
8479 | else if (reg1 == 31 && reg2 == 31) | |
8480 | mask |= 1; | |
8481 | else | |
8482 | { | |
8483 | as_bad (_("invalid register list")); | |
8484 | break; | |
8485 | } | |
8486 | } | |
8487 | /* The mask is filled in in the opcode table for the | |
8488 | benefit of the disassembler. We remove it before | |
8489 | applying the actual mask. */ | |
8490 | ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6); | |
8491 | ip->insn_opcode |= mask << MIPS16OP_SH_IMM6; | |
8492 | } | |
8493 | continue; | |
8494 | ||
8495 | case 'e': /* extend code */ | |
8496 | my_getExpression (&imm_expr, s); | |
8497 | check_absolute_expr (ip, &imm_expr); | |
8498 | if ((unsigned long) imm_expr.X_add_number > 0x7ff) | |
8499 | { | |
8500 | as_warn (_("Invalid value for `%s' (%lu)"), | |
8501 | ip->insn_mo->name, | |
8502 | (unsigned long) imm_expr.X_add_number); | |
8503 | imm_expr.X_add_number &= 0x7ff; | |
8504 | } | |
8505 | ip->insn_opcode |= imm_expr.X_add_number; | |
8506 | imm_expr.X_op = O_absent; | |
8507 | s = expr_end; | |
8508 | continue; | |
8509 | ||
8510 | default: | |
8511 | internalError (); | |
8512 | } | |
8513 | break; | |
8514 | } | |
8515 | ||
8516 | /* Args don't match. */ | |
8517 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] && | |
8518 | strcmp (insn->name, insn[1].name) == 0) | |
8519 | { | |
8520 | ++insn; | |
8521 | s = argsstart; | |
8522 | continue; | |
8523 | } | |
8524 | ||
8525 | insn_error = _("illegal operands"); | |
8526 | ||
8527 | return; | |
8528 | } | |
8529 | } | |
8530 | ||
8531 | /* This structure holds information we know about a mips16 immediate | |
8532 | argument type. */ | |
8533 | ||
8534 | struct mips16_immed_operand | |
8535 | { | |
8536 | /* The type code used in the argument string in the opcode table. */ | |
8537 | int type; | |
8538 | /* The number of bits in the short form of the opcode. */ | |
8539 | int nbits; | |
8540 | /* The number of bits in the extended form of the opcode. */ | |
8541 | int extbits; | |
8542 | /* The amount by which the short form is shifted when it is used; | |
8543 | for example, the sw instruction has a shift count of 2. */ | |
8544 | int shift; | |
8545 | /* The amount by which the short form is shifted when it is stored | |
8546 | into the instruction code. */ | |
8547 | int op_shift; | |
8548 | /* Non-zero if the short form is unsigned. */ | |
8549 | int unsp; | |
8550 | /* Non-zero if the extended form is unsigned. */ | |
8551 | int extu; | |
8552 | /* Non-zero if the value is PC relative. */ | |
8553 | int pcrel; | |
8554 | }; | |
8555 | ||
8556 | /* The mips16 immediate operand types. */ | |
8557 | ||
8558 | static const struct mips16_immed_operand mips16_immed_operands[] = | |
8559 | { | |
8560 | { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
8561 | { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
8562 | { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, | |
8563 | { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 }, | |
8564 | { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 }, | |
8565 | { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8566 | { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8567 | { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8568 | { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 }, | |
8569 | { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 }, | |
8570 | { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8571 | { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8572 | { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 }, | |
8573 | { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 }, | |
8574 | { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
8575 | { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 }, | |
8576 | { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
8577 | { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, | |
8578 | { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 }, | |
8579 | { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 }, | |
8580 | { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 } | |
8581 | }; | |
8582 | ||
8583 | #define MIPS16_NUM_IMMED \ | |
8584 | (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0]) | |
8585 | ||
8586 | /* Handle a mips16 instruction with an immediate value. This or's the | |
8587 | small immediate value into *INSN. It sets *USE_EXTEND to indicate | |
8588 | whether an extended value is needed; if one is needed, it sets | |
8589 | *EXTEND to the value. The argument type is TYPE. The value is VAL. | |
8590 | If SMALL is true, an unextended opcode was explicitly requested. | |
8591 | If EXT is true, an extended opcode was explicitly requested. If | |
8592 | WARN is true, warn if EXT does not match reality. */ | |
8593 | ||
8594 | static void | |
8595 | mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend, | |
8596 | extend) | |
8597 | char *file; | |
8598 | unsigned int line; | |
8599 | int type; | |
8600 | offsetT val; | |
8601 | boolean warn; | |
8602 | boolean small; | |
8603 | boolean ext; | |
8604 | unsigned long *insn; | |
8605 | boolean *use_extend; | |
8606 | unsigned short *extend; | |
8607 | { | |
8608 | register const struct mips16_immed_operand *op; | |
8609 | int mintiny, maxtiny; | |
8610 | boolean needext; | |
8611 | ||
8612 | op = mips16_immed_operands; | |
8613 | while (op->type != type) | |
8614 | { | |
8615 | ++op; | |
8616 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
8617 | } | |
8618 | ||
8619 | if (op->unsp) | |
8620 | { | |
8621 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
8622 | { | |
8623 | mintiny = 1; | |
8624 | maxtiny = 1 << op->nbits; | |
8625 | } | |
8626 | else | |
8627 | { | |
8628 | mintiny = 0; | |
8629 | maxtiny = (1 << op->nbits) - 1; | |
8630 | } | |
8631 | } | |
8632 | else | |
8633 | { | |
8634 | mintiny = - (1 << (op->nbits - 1)); | |
8635 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
8636 | } | |
8637 | ||
8638 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
8639 | if (type == 'p' || type == 'q') | |
8640 | val /= 2; | |
8641 | ||
8642 | if ((val & ((1 << op->shift) - 1)) != 0 | |
8643 | || val < (mintiny << op->shift) | |
8644 | || val > (maxtiny << op->shift)) | |
8645 | needext = true; | |
8646 | else | |
8647 | needext = false; | |
8648 | ||
8649 | if (warn && ext && ! needext) | |
8650 | as_warn_where (file, line, _("extended operand requested but not required")); | |
8651 | if (small && needext) | |
8652 | as_bad_where (file, line, _("invalid unextended operand value")); | |
8653 | ||
8654 | if (small || (! ext && ! needext)) | |
8655 | { | |
8656 | int insnval; | |
8657 | ||
8658 | *use_extend = false; | |
8659 | insnval = ((val >> op->shift) & ((1 << op->nbits) - 1)); | |
8660 | insnval <<= op->op_shift; | |
8661 | *insn |= insnval; | |
8662 | } | |
8663 | else | |
8664 | { | |
8665 | long minext, maxext; | |
8666 | int extval; | |
8667 | ||
8668 | if (op->extu) | |
8669 | { | |
8670 | minext = 0; | |
8671 | maxext = (1 << op->extbits) - 1; | |
8672 | } | |
8673 | else | |
8674 | { | |
8675 | minext = - (1 << (op->extbits - 1)); | |
8676 | maxext = (1 << (op->extbits - 1)) - 1; | |
8677 | } | |
8678 | if (val < minext || val > maxext) | |
8679 | as_bad_where (file, line, | |
8680 | _("operand value out of range for instruction")); | |
8681 | ||
8682 | *use_extend = true; | |
8683 | if (op->extbits == 16) | |
8684 | { | |
8685 | extval = ((val >> 11) & 0x1f) | (val & 0x7e0); | |
8686 | val &= 0x1f; | |
8687 | } | |
8688 | else if (op->extbits == 15) | |
8689 | { | |
8690 | extval = ((val >> 11) & 0xf) | (val & 0x7f0); | |
8691 | val &= 0xf; | |
8692 | } | |
8693 | else | |
8694 | { | |
8695 | extval = ((val & 0x1f) << 6) | (val & 0x20); | |
8696 | val = 0; | |
8697 | } | |
8698 | ||
8699 | *extend = (unsigned short) extval; | |
8700 | *insn |= val; | |
8701 | } | |
8702 | } | |
8703 | \f | |
8704 | #define LP '(' | |
8705 | #define RP ')' | |
8706 | ||
8707 | static int | |
8708 | my_getSmallExpression (ep, str) | |
8709 | expressionS *ep; | |
8710 | char *str; | |
8711 | { | |
8712 | char *sp; | |
8713 | int c = 0; | |
8714 | ||
8715 | if (*str == ' ') | |
8716 | str++; | |
8717 | if (*str == LP | |
8718 | || (*str == '%' && | |
8719 | ((str[1] == 'h' && str[2] == 'i') | |
8720 | || (str[1] == 'H' && str[2] == 'I') | |
8721 | || (str[1] == 'l' && str[2] == 'o')) | |
8722 | && str[3] == LP)) | |
8723 | { | |
8724 | if (*str == LP) | |
8725 | c = 0; | |
8726 | else | |
8727 | { | |
8728 | c = str[1]; | |
8729 | str += 3; | |
8730 | } | |
8731 | ||
8732 | /* | |
8733 | * A small expression may be followed by a base register. | |
8734 | * Scan to the end of this operand, and then back over a possible | |
8735 | * base register. Then scan the small expression up to that | |
8736 | * point. (Based on code in sparc.c...) | |
8737 | */ | |
8738 | for (sp = str; *sp && *sp != ','; sp++) | |
8739 | ; | |
8740 | if (sp - 4 >= str && sp[-1] == RP) | |
8741 | { | |
d9a62219 | 8742 | if (isdigit ((unsigned char) sp[-2])) |
252b5132 | 8743 | { |
d9a62219 | 8744 | for (sp -= 3; sp >= str && isdigit ((unsigned char) *sp); sp--) |
252b5132 RH |
8745 | ; |
8746 | if (*sp == '$' && sp > str && sp[-1] == LP) | |
8747 | { | |
8748 | sp--; | |
8749 | goto do_it; | |
8750 | } | |
8751 | } | |
8752 | else if (sp - 5 >= str | |
8753 | && sp[-5] == LP | |
8754 | && sp[-4] == '$' | |
8755 | && ((sp[-3] == 'f' && sp[-2] == 'p') | |
8756 | || (sp[-3] == 's' && sp[-2] == 'p') | |
8757 | || (sp[-3] == 'g' && sp[-2] == 'p') | |
8758 | || (sp[-3] == 'a' && sp[-2] == 't'))) | |
8759 | { | |
8760 | sp -= 5; | |
8761 | do_it: | |
8762 | if (sp == str) | |
8763 | { | |
8764 | /* no expression means zero offset */ | |
8765 | if (c) | |
8766 | { | |
8767 | /* %xx(reg) is an error */ | |
8768 | ep->X_op = O_absent; | |
8769 | expr_end = str - 3; | |
8770 | } | |
8771 | else | |
8772 | { | |
8773 | ep->X_op = O_constant; | |
8774 | expr_end = sp; | |
8775 | } | |
8776 | ep->X_add_symbol = NULL; | |
8777 | ep->X_op_symbol = NULL; | |
8778 | ep->X_add_number = 0; | |
8779 | } | |
8780 | else | |
8781 | { | |
8782 | *sp = '\0'; | |
8783 | my_getExpression (ep, str); | |
8784 | *sp = LP; | |
8785 | } | |
8786 | return c; | |
8787 | } | |
8788 | } | |
8789 | } | |
8790 | my_getExpression (ep, str); | |
8791 | return c; /* => %hi or %lo encountered */ | |
8792 | } | |
8793 | ||
8794 | static void | |
8795 | my_getExpression (ep, str) | |
8796 | expressionS *ep; | |
8797 | char *str; | |
8798 | { | |
8799 | char *save_in; | |
8800 | ||
8801 | save_in = input_line_pointer; | |
8802 | input_line_pointer = str; | |
8803 | expression (ep); | |
8804 | expr_end = input_line_pointer; | |
8805 | input_line_pointer = save_in; | |
8806 | ||
8807 | /* If we are in mips16 mode, and this is an expression based on `.', | |
8808 | then we bump the value of the symbol by 1 since that is how other | |
8809 | text symbols are handled. We don't bother to handle complex | |
8810 | expressions, just `.' plus or minus a constant. */ | |
8811 | if (mips_opts.mips16 | |
8812 | && ep->X_op == O_symbol | |
8813 | && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0 | |
8814 | && S_GET_SEGMENT (ep->X_add_symbol) == now_seg | |
49309057 ILT |
8815 | && symbol_get_frag (ep->X_add_symbol) == frag_now |
8816 | && symbol_constant_p (ep->X_add_symbol) | |
8817 | && S_GET_VALUE (ep->X_add_symbol) == frag_now_fix ()) | |
8818 | S_SET_VALUE (ep->X_add_symbol, S_GET_VALUE (ep->X_add_symbol) + 1); | |
252b5132 RH |
8819 | } |
8820 | ||
8821 | /* Turn a string in input_line_pointer into a floating point constant | |
bc0d738a NC |
8822 | of type TYPE, and store the appropriate bytes in *LITP. The number |
8823 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
252b5132 RH |
8824 | returned, or NULL on OK. */ |
8825 | ||
8826 | char * | |
8827 | md_atof (type, litP, sizeP) | |
8828 | int type; | |
8829 | char *litP; | |
8830 | int *sizeP; | |
8831 | { | |
8832 | int prec; | |
8833 | LITTLENUM_TYPE words[4]; | |
8834 | char *t; | |
8835 | int i; | |
8836 | ||
8837 | switch (type) | |
8838 | { | |
8839 | case 'f': | |
8840 | prec = 2; | |
8841 | break; | |
8842 | ||
8843 | case 'd': | |
8844 | prec = 4; | |
8845 | break; | |
8846 | ||
8847 | default: | |
8848 | *sizeP = 0; | |
8849 | return _("bad call to md_atof"); | |
8850 | } | |
8851 | ||
8852 | t = atof_ieee (input_line_pointer, type, words); | |
8853 | if (t) | |
8854 | input_line_pointer = t; | |
8855 | ||
8856 | *sizeP = prec * 2; | |
8857 | ||
8858 | if (! target_big_endian) | |
8859 | { | |
8860 | for (i = prec - 1; i >= 0; i--) | |
8861 | { | |
8862 | md_number_to_chars (litP, (valueT) words[i], 2); | |
8863 | litP += 2; | |
8864 | } | |
8865 | } | |
8866 | else | |
8867 | { | |
8868 | for (i = 0; i < prec; i++) | |
8869 | { | |
8870 | md_number_to_chars (litP, (valueT) words[i], 2); | |
8871 | litP += 2; | |
8872 | } | |
8873 | } | |
bdaaa2e1 | 8874 | |
252b5132 RH |
8875 | return NULL; |
8876 | } | |
8877 | ||
8878 | void | |
8879 | md_number_to_chars (buf, val, n) | |
8880 | char *buf; | |
8881 | valueT val; | |
8882 | int n; | |
8883 | { | |
8884 | if (target_big_endian) | |
8885 | number_to_chars_bigendian (buf, val, n); | |
8886 | else | |
8887 | number_to_chars_littleendian (buf, val, n); | |
8888 | } | |
8889 | \f | |
8890 | CONST char *md_shortopts = "O::g::G:"; | |
8891 | ||
156c2f8b NC |
8892 | struct option md_longopts[] = |
8893 | { | |
252b5132 RH |
8894 | #define OPTION_MIPS1 (OPTION_MD_BASE + 1) |
8895 | {"mips0", no_argument, NULL, OPTION_MIPS1}, | |
8896 | {"mips1", no_argument, NULL, OPTION_MIPS1}, | |
8897 | #define OPTION_MIPS2 (OPTION_MD_BASE + 2) | |
8898 | {"mips2", no_argument, NULL, OPTION_MIPS2}, | |
8899 | #define OPTION_MIPS3 (OPTION_MD_BASE + 3) | |
8900 | {"mips3", no_argument, NULL, OPTION_MIPS3}, | |
8901 | #define OPTION_MIPS4 (OPTION_MD_BASE + 4) | |
8902 | {"mips4", no_argument, NULL, OPTION_MIPS4}, | |
8903 | #define OPTION_MCPU (OPTION_MD_BASE + 5) | |
8904 | {"mcpu", required_argument, NULL, OPTION_MCPU}, | |
8905 | #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 6) | |
8906 | {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC}, | |
156c2f8b | 8907 | #define OPTION_TRAP (OPTION_MD_BASE + 7) |
252b5132 RH |
8908 | {"trap", no_argument, NULL, OPTION_TRAP}, |
8909 | {"no-break", no_argument, NULL, OPTION_TRAP}, | |
156c2f8b | 8910 | #define OPTION_BREAK (OPTION_MD_BASE + 8) |
252b5132 RH |
8911 | {"break", no_argument, NULL, OPTION_BREAK}, |
8912 | {"no-trap", no_argument, NULL, OPTION_BREAK}, | |
156c2f8b | 8913 | #define OPTION_EB (OPTION_MD_BASE + 9) |
252b5132 | 8914 | {"EB", no_argument, NULL, OPTION_EB}, |
156c2f8b | 8915 | #define OPTION_EL (OPTION_MD_BASE + 10) |
252b5132 | 8916 | {"EL", no_argument, NULL, OPTION_EL}, |
156c2f8b | 8917 | #define OPTION_M4650 (OPTION_MD_BASE + 11) |
252b5132 | 8918 | {"m4650", no_argument, NULL, OPTION_M4650}, |
156c2f8b | 8919 | #define OPTION_NO_M4650 (OPTION_MD_BASE + 12) |
252b5132 | 8920 | {"no-m4650", no_argument, NULL, OPTION_NO_M4650}, |
156c2f8b | 8921 | #define OPTION_M4010 (OPTION_MD_BASE + 13) |
252b5132 | 8922 | {"m4010", no_argument, NULL, OPTION_M4010}, |
156c2f8b | 8923 | #define OPTION_NO_M4010 (OPTION_MD_BASE + 14) |
252b5132 | 8924 | {"no-m4010", no_argument, NULL, OPTION_NO_M4010}, |
156c2f8b | 8925 | #define OPTION_M4100 (OPTION_MD_BASE + 15) |
252b5132 | 8926 | {"m4100", no_argument, NULL, OPTION_M4100}, |
156c2f8b | 8927 | #define OPTION_NO_M4100 (OPTION_MD_BASE + 16) |
252b5132 | 8928 | {"no-m4100", no_argument, NULL, OPTION_NO_M4100}, |
156c2f8b | 8929 | #define OPTION_MIPS16 (OPTION_MD_BASE + 17) |
252b5132 | 8930 | {"mips16", no_argument, NULL, OPTION_MIPS16}, |
156c2f8b | 8931 | #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 18) |
252b5132 | 8932 | {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16}, |
156c2f8b | 8933 | #define OPTION_M3900 (OPTION_MD_BASE + 19) |
252b5132 | 8934 | {"m3900", no_argument, NULL, OPTION_M3900}, |
156c2f8b | 8935 | #define OPTION_NO_M3900 (OPTION_MD_BASE + 20) |
252b5132 | 8936 | {"no-m3900", no_argument, NULL, OPTION_NO_M3900}, |
156c2f8b | 8937 | #define OPTION_MABI (OPTION_MD_BASE + 21) |
252b5132 | 8938 | {"mabi", required_argument, NULL, OPTION_MABI}, |
156c2f8b | 8939 | #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 22) |
6b76fefe | 8940 | {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX}, |
156c2f8b | 8941 | #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 23) |
6b76fefe | 8942 | {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX}, |
156c2f8b | 8943 | #define OPTION_GP32 (OPTION_MD_BASE + 24) |
c97ef257 | 8944 | {"mgp32", no_argument, NULL, OPTION_GP32}, |
156c2f8b | 8945 | #define OPTION_GP64 (OPTION_MD_BASE + 25) |
c97ef257 | 8946 | {"mgp64", no_argument, NULL, OPTION_GP64}, |
156c2f8b | 8947 | #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 26) |
119d663a | 8948 | {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS}, |
156c2f8b | 8949 | #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 27) |
119d663a | 8950 | {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS}, |
156c2f8b NC |
8951 | #define OPTION_MIPS32 (OPTION_MD_BASE + 28) |
8952 | {"mips32", no_argument, NULL, OPTION_MIPS32}, | |
8953 | #define OPTION_NO_MIPS32 (OPTION_MD_BASE + 29) | |
8954 | {"no-mips32", no_argument, NULL, OPTION_NO_MIPS32}, | |
8955 | ||
8956 | #ifdef OBJ_ELF | |
8957 | #define OPTION_ELF_BASE (OPTION_MD_BASE + 35) | |
8958 | #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0) | |
8959 | #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1) | |
8960 | #define OPTION_XGOT (OPTION_ELF_BASE + 2) | |
8961 | #define OPTION_32 (OPTION_ELF_BASE + 3) | |
8962 | #define OPTION_64 (OPTION_ELF_BASE + 4) | |
8963 | {"KPIC", no_argument, NULL, OPTION_CALL_SHARED}, | |
8964 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, | |
8965 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, | |
8966 | {"xgot", no_argument, NULL, OPTION_XGOT}, | |
8967 | {"32", no_argument, NULL, OPTION_32}, | |
8968 | {"64", no_argument, NULL, OPTION_64}, | |
8969 | #endif | |
119d663a | 8970 | |
252b5132 RH |
8971 | {NULL, no_argument, NULL, 0} |
8972 | }; | |
156c2f8b | 8973 | size_t md_longopts_size = sizeof (md_longopts); |
252b5132 RH |
8974 | |
8975 | int | |
8976 | md_parse_option (c, arg) | |
8977 | int c; | |
8978 | char *arg; | |
8979 | { | |
8980 | switch (c) | |
8981 | { | |
119d663a NC |
8982 | case OPTION_CONSTRUCT_FLOATS: |
8983 | mips_disable_float_construction = 0; | |
8984 | break; | |
bdaaa2e1 | 8985 | |
119d663a NC |
8986 | case OPTION_NO_CONSTRUCT_FLOATS: |
8987 | mips_disable_float_construction = 1; | |
8988 | break; | |
bdaaa2e1 | 8989 | |
252b5132 RH |
8990 | case OPTION_TRAP: |
8991 | mips_trap = 1; | |
8992 | break; | |
8993 | ||
8994 | case OPTION_BREAK: | |
8995 | mips_trap = 0; | |
8996 | break; | |
8997 | ||
8998 | case OPTION_EB: | |
8999 | target_big_endian = 1; | |
9000 | break; | |
9001 | ||
9002 | case OPTION_EL: | |
9003 | target_big_endian = 0; | |
9004 | break; | |
9005 | ||
9006 | case 'O': | |
9007 | if (arg && arg[1] == '0') | |
9008 | mips_optimize = 1; | |
9009 | else | |
9010 | mips_optimize = 2; | |
9011 | break; | |
9012 | ||
9013 | case 'g': | |
9014 | if (arg == NULL) | |
9015 | mips_debug = 2; | |
9016 | else | |
9017 | mips_debug = atoi (arg); | |
9018 | /* When the MIPS assembler sees -g or -g2, it does not do | |
9019 | optimizations which limit full symbolic debugging. We take | |
9020 | that to be equivalent to -O0. */ | |
9021 | if (mips_debug == 2) | |
9022 | mips_optimize = 1; | |
9023 | break; | |
9024 | ||
9025 | case OPTION_MIPS1: | |
9026 | mips_opts.isa = 1; | |
9027 | break; | |
9028 | ||
9029 | case OPTION_MIPS2: | |
9030 | mips_opts.isa = 2; | |
9031 | break; | |
9032 | ||
9033 | case OPTION_MIPS3: | |
9034 | mips_opts.isa = 3; | |
9035 | break; | |
9036 | ||
9037 | case OPTION_MIPS4: | |
9038 | mips_opts.isa = 4; | |
9039 | break; | |
9040 | ||
9041 | case OPTION_MCPU: | |
9042 | { | |
9043 | char *p; | |
9044 | ||
9045 | /* Identify the processor type */ | |
9046 | p = arg; | |
9047 | if (strcmp (p, "default") == 0 | |
9048 | || strcmp (p, "DEFAULT") == 0) | |
9049 | mips_cpu = -1; | |
9050 | else | |
9051 | { | |
9052 | int sv = 0; | |
9053 | ||
9054 | /* We need to cope with the various "vr" prefixes for the 4300 | |
9055 | processor. */ | |
9056 | if (*p == 'v' || *p == 'V') | |
9057 | { | |
9058 | sv = 1; | |
9059 | p++; | |
9060 | } | |
9061 | ||
9062 | if (*p == 'r' || *p == 'R') | |
9063 | p++; | |
9064 | ||
9065 | mips_cpu = -1; | |
9066 | switch (*p) | |
9067 | { | |
9068 | case '1': | |
9069 | if (strcmp (p, "10000") == 0 | |
9070 | || strcmp (p, "10k") == 0 | |
9071 | || strcmp (p, "10K") == 0) | |
156c2f8b | 9072 | mips_cpu = CPU_R10000; |
252b5132 RH |
9073 | break; |
9074 | ||
9075 | case '2': | |
9076 | if (strcmp (p, "2000") == 0 | |
9077 | || strcmp (p, "2k") == 0 | |
9078 | || strcmp (p, "2K") == 0) | |
156c2f8b | 9079 | mips_cpu = CPU_R2000; |
252b5132 RH |
9080 | break; |
9081 | ||
9082 | case '3': | |
9083 | if (strcmp (p, "3000") == 0 | |
9084 | || strcmp (p, "3k") == 0 | |
9085 | || strcmp (p, "3K") == 0) | |
156c2f8b | 9086 | mips_cpu = CPU_R3000; |
252b5132 | 9087 | else if (strcmp (p, "3900") == 0) |
156c2f8b | 9088 | mips_cpu = CPU_R3900; |
252b5132 RH |
9089 | break; |
9090 | ||
9091 | case '4': | |
9092 | if (strcmp (p, "4000") == 0 | |
9093 | || strcmp (p, "4k") == 0 | |
9094 | || strcmp (p, "4K") == 0) | |
156c2f8b | 9095 | mips_cpu = CPU_R4000; |
252b5132 | 9096 | else if (strcmp (p, "4100") == 0) |
156c2f8b | 9097 | mips_cpu = CPU_VR4100; |
252b5132 | 9098 | else if (strcmp (p, "4111") == 0) |
156c2f8b | 9099 | mips_cpu = CPU_R4111; |
252b5132 | 9100 | else if (strcmp (p, "4300") == 0) |
156c2f8b | 9101 | mips_cpu = CPU_R4300; |
252b5132 | 9102 | else if (strcmp (p, "4400") == 0) |
156c2f8b | 9103 | mips_cpu = CPU_R4400; |
252b5132 | 9104 | else if (strcmp (p, "4600") == 0) |
156c2f8b | 9105 | mips_cpu = CPU_R4600; |
252b5132 | 9106 | else if (strcmp (p, "4650") == 0) |
156c2f8b | 9107 | mips_cpu = CPU_R4650; |
252b5132 | 9108 | else if (strcmp (p, "4010") == 0) |
156c2f8b NC |
9109 | mips_cpu = CPU_R4010; |
9110 | else if (strcmp (p, "4Kc") == 0 | |
9111 | || strcmp (p, "4Kp") == 0 | |
9112 | || strcmp (p, "4Km") == 0) | |
9113 | mips_cpu = CPU_MIPS32; | |
252b5132 RH |
9114 | break; |
9115 | ||
9116 | case '5': | |
9117 | if (strcmp (p, "5000") == 0 | |
9118 | || strcmp (p, "5k") == 0 | |
9119 | || strcmp (p, "5K") == 0) | |
156c2f8b | 9120 | mips_cpu = CPU_R5000; |
252b5132 RH |
9121 | break; |
9122 | ||
9123 | case '6': | |
9124 | if (strcmp (p, "6000") == 0 | |
9125 | || strcmp (p, "6k") == 0 | |
9126 | || strcmp (p, "6K") == 0) | |
156c2f8b | 9127 | mips_cpu = CPU_R6000; |
252b5132 RH |
9128 | break; |
9129 | ||
9130 | case '8': | |
9131 | if (strcmp (p, "8000") == 0 | |
9132 | || strcmp (p, "8k") == 0 | |
9133 | || strcmp (p, "8K") == 0) | |
156c2f8b | 9134 | mips_cpu = CPU_R8000; |
252b5132 RH |
9135 | break; |
9136 | ||
9137 | case 'o': | |
9138 | if (strcmp (p, "orion") == 0) | |
156c2f8b | 9139 | mips_cpu = CPU_R4600; |
252b5132 | 9140 | break; |
252b5132 | 9141 | |
b946ec34 NC |
9142 | case 'm': |
9143 | case 'M': | |
9144 | switch (atoi (p + 1)) | |
9145 | { | |
9146 | case 5200: | |
9147 | case 5230: | |
9148 | case 5231: | |
9149 | case 5261: | |
9150 | case 5721: | |
9151 | case 7000: | |
156c2f8b | 9152 | mips_cpu = CPU_R5000; |
b946ec34 NC |
9153 | break; |
9154 | default: | |
9155 | break; | |
9156 | } | |
9157 | } | |
bdaaa2e1 | 9158 | |
252b5132 | 9159 | if (sv |
156c2f8b NC |
9160 | && (mips_cpu != CPU_R4300 |
9161 | && mips_cpu != CPU_VR4100 | |
9162 | && mips_cpu != CPU_R4111 | |
9163 | && mips_cpu != CPU_R5000)) | |
252b5132 RH |
9164 | { |
9165 | as_bad (_("ignoring invalid leading 'v' in -mcpu=%s switch"), arg); | |
9166 | return 0; | |
9167 | } | |
9168 | ||
9169 | if (mips_cpu == -1) | |
9170 | { | |
9171 | as_bad (_("invalid architecture -mcpu=%s"), arg); | |
9172 | return 0; | |
9173 | } | |
9174 | } | |
9175 | } | |
9176 | break; | |
9177 | ||
9178 | case OPTION_M4650: | |
156c2f8b | 9179 | mips_cpu = CPU_R4650; |
252b5132 RH |
9180 | break; |
9181 | ||
9182 | case OPTION_NO_M4650: | |
9183 | break; | |
9184 | ||
9185 | case OPTION_M4010: | |
156c2f8b | 9186 | mips_cpu = CPU_R4010; |
252b5132 RH |
9187 | break; |
9188 | ||
9189 | case OPTION_NO_M4010: | |
9190 | break; | |
9191 | ||
9192 | case OPTION_M4100: | |
156c2f8b | 9193 | mips_cpu = CPU_VR4100; |
252b5132 RH |
9194 | break; |
9195 | ||
9196 | case OPTION_NO_M4100: | |
9197 | break; | |
9198 | ||
156c2f8b NC |
9199 | case OPTION_MIPS32: |
9200 | mips_cpu = CPU_MIPS32; | |
9201 | break; | |
9202 | ||
9203 | case OPTION_NO_MIPS32: | |
9204 | break; | |
9205 | ||
252b5132 | 9206 | case OPTION_M3900: |
156c2f8b | 9207 | mips_cpu = CPU_R3900; |
252b5132 | 9208 | break; |
bdaaa2e1 | 9209 | |
252b5132 RH |
9210 | case OPTION_NO_M3900: |
9211 | break; | |
9212 | ||
9213 | case OPTION_MIPS16: | |
9214 | mips_opts.mips16 = 1; | |
9215 | mips_no_prev_insn (false); | |
9216 | break; | |
9217 | ||
9218 | case OPTION_NO_MIPS16: | |
9219 | mips_opts.mips16 = 0; | |
9220 | mips_no_prev_insn (false); | |
9221 | break; | |
9222 | ||
9223 | case OPTION_MEMBEDDED_PIC: | |
9224 | mips_pic = EMBEDDED_PIC; | |
9225 | if (USE_GLOBAL_POINTER_OPT && g_switch_seen) | |
9226 | { | |
9227 | as_bad (_("-G may not be used with embedded PIC code")); | |
9228 | return 0; | |
9229 | } | |
9230 | g_switch_value = 0x7fffffff; | |
9231 | break; | |
9232 | ||
9233 | /* When generating ELF code, we permit -KPIC and -call_shared to | |
9234 | select SVR4_PIC, and -non_shared to select no PIC. This is | |
9235 | intended to be compatible with Irix 5. */ | |
9236 | case OPTION_CALL_SHARED: | |
9237 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9238 | { | |
9239 | as_bad (_("-call_shared is supported only for ELF format")); | |
9240 | return 0; | |
9241 | } | |
9242 | mips_pic = SVR4_PIC; | |
9243 | if (g_switch_seen && g_switch_value != 0) | |
9244 | { | |
9245 | as_bad (_("-G may not be used with SVR4 PIC code")); | |
9246 | return 0; | |
9247 | } | |
9248 | g_switch_value = 0; | |
9249 | break; | |
9250 | ||
9251 | case OPTION_NON_SHARED: | |
9252 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
9253 | { | |
9254 | as_bad (_("-non_shared is supported only for ELF format")); | |
9255 | return 0; | |
9256 | } | |
9257 | mips_pic = NO_PIC; | |
9258 | break; | |
9259 | ||
9260 | /* The -xgot option tells the assembler to use 32 offsets when | |
9261 | accessing the got in SVR4_PIC mode. It is for Irix | |
9262 | compatibility. */ | |
9263 | case OPTION_XGOT: | |
9264 | mips_big_got = 1; | |
9265 | break; | |
9266 | ||
9267 | case 'G': | |
9268 | if (! USE_GLOBAL_POINTER_OPT) | |
9269 | { | |
9270 | as_bad (_("-G is not supported for this configuration")); | |
9271 | return 0; | |
9272 | } | |
9273 | else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC) | |
9274 | { | |
9275 | as_bad (_("-G may not be used with SVR4 or embedded PIC code")); | |
9276 | return 0; | |
9277 | } | |
9278 | else | |
9279 | g_switch_value = atoi (arg); | |
9280 | g_switch_seen = 1; | |
9281 | break; | |
9282 | ||
9283 | /* The -32 and -64 options tell the assembler to output the 32 | |
9284 | bit or the 64 bit MIPS ELF format. */ | |
9285 | case OPTION_32: | |
9286 | mips_64 = 0; | |
9287 | break; | |
9288 | ||
9289 | case OPTION_64: | |
9290 | { | |
9291 | const char **list, **l; | |
9292 | ||
9293 | list = bfd_target_list (); | |
9294 | for (l = list; *l != NULL; l++) | |
9295 | if (strcmp (*l, "elf64-bigmips") == 0 | |
9296 | || strcmp (*l, "elf64-littlemips") == 0) | |
9297 | break; | |
9298 | if (*l == NULL) | |
9299 | as_fatal (_("No compiled in support for 64 bit object file format")); | |
9300 | free (list); | |
9301 | mips_64 = 1; | |
9302 | } | |
9303 | break; | |
9304 | ||
c97ef257 AH |
9305 | case OPTION_GP32: |
9306 | mips_gp32 = 1; | |
9307 | mips_64 = 0; | |
9308 | ||
9309 | /* We deliberately don't allow "-gp32" to set the MIPS_32BITMODE | |
9310 | flag in object files because to do so would make it | |
9311 | impossible to link with libraries compiled without "-gp32". | |
bdaaa2e1 | 9312 | This is unnecessarily restrictive. |
c97ef257 AH |
9313 | |
9314 | We could solve this problem by adding "-gp32" multilibs to | |
9315 | gcc, but to set this flag before gcc is built with such | |
bdaaa2e1 | 9316 | multilibs will break too many systems. */ |
c97ef257 AH |
9317 | |
9318 | /* mips_32bitmode = 1; */ | |
9319 | break; | |
9320 | ||
9321 | case OPTION_GP64: | |
9322 | mips_gp32 = 0; | |
9323 | mips_64 = 1; | |
9324 | /* mips_32bitmode = 0; */ | |
9325 | break; | |
252b5132 RH |
9326 | |
9327 | case OPTION_MABI: | |
9328 | if (strcmp (arg,"32") == 0 | |
9329 | || strcmp (arg,"n32") == 0 | |
9330 | || strcmp (arg,"64") == 0 | |
9331 | || strcmp (arg,"o64") == 0 | |
9332 | || strcmp (arg,"eabi") == 0) | |
9333 | mips_abi_string = arg; | |
9334 | break; | |
9335 | ||
6b76fefe CM |
9336 | case OPTION_M7000_HILO_FIX: |
9337 | mips_7000_hilo_fix = true; | |
9338 | break; | |
9339 | ||
9340 | case OPTION_NO_M7000_HILO_FIX: | |
9341 | mips_7000_hilo_fix = false; | |
9342 | break; | |
9343 | ||
252b5132 RH |
9344 | default: |
9345 | return 0; | |
9346 | } | |
9347 | ||
9348 | return 1; | |
9349 | } | |
9350 | ||
252b5132 RH |
9351 | static void |
9352 | show (stream, string, col_p, first_p) | |
9353 | FILE *stream; | |
9354 | char *string; | |
9355 | int *col_p; | |
9356 | int *first_p; | |
9357 | { | |
9358 | if (*first_p) | |
9359 | { | |
9360 | fprintf (stream, "%24s", ""); | |
9361 | *col_p = 24; | |
9362 | } | |
9363 | else | |
9364 | { | |
9365 | fprintf (stream, ", "); | |
9366 | *col_p += 2; | |
9367 | } | |
9368 | ||
9369 | if (*col_p + strlen (string) > 72) | |
9370 | { | |
9371 | fprintf (stream, "\n%24s", ""); | |
9372 | *col_p = 24; | |
9373 | } | |
9374 | ||
9375 | fprintf (stream, "%s", string); | |
9376 | *col_p += strlen (string); | |
9377 | ||
9378 | *first_p = 0; | |
9379 | } | |
9380 | ||
252b5132 RH |
9381 | void |
9382 | md_show_usage (stream) | |
9383 | FILE *stream; | |
9384 | { | |
9385 | int column, first; | |
9386 | ||
9387 | fprintf(stream, _("\ | |
9388 | MIPS options:\n\ | |
9389 | -membedded-pic generate embedded position independent code\n\ | |
9390 | -EB generate big endian output\n\ | |
9391 | -EL generate little endian output\n\ | |
9392 | -g, -g2 do not remove uneeded NOPs or swap branches\n\ | |
9393 | -G NUM allow referencing objects up to NUM bytes\n\ | |
9394 | implicitly with the gp register [default 8]\n")); | |
9395 | fprintf(stream, _("\ | |
9396 | -mips1 generate MIPS ISA I instructions\n\ | |
9397 | -mips2 generate MIPS ISA II instructions\n\ | |
9398 | -mips3 generate MIPS ISA III instructions\n\ | |
9399 | -mips4 generate MIPS ISA IV instructions\n\ | |
9400 | -mcpu=CPU generate code for CPU, where CPU is one of:\n")); | |
9401 | ||
9402 | first = 1; | |
9403 | ||
9404 | show (stream, "2000", &column, &first); | |
9405 | show (stream, "3000", &column, &first); | |
9406 | show (stream, "3900", &column, &first); | |
9407 | show (stream, "4000", &column, &first); | |
9408 | show (stream, "4010", &column, &first); | |
9409 | show (stream, "4100", &column, &first); | |
9410 | show (stream, "4111", &column, &first); | |
9411 | show (stream, "4300", &column, &first); | |
9412 | show (stream, "4400", &column, &first); | |
9413 | show (stream, "4600", &column, &first); | |
9414 | show (stream, "4650", &column, &first); | |
9415 | show (stream, "5000", &column, &first); | |
9416 | show (stream, "6000", &column, &first); | |
9417 | show (stream, "8000", &column, &first); | |
9418 | show (stream, "10000", &column, &first); | |
156c2f8b NC |
9419 | show (stream, "4Kc", &column, &first); |
9420 | show (stream, "4Kp", &column, &first); | |
9421 | show (stream, "4Km", &column, &first); | |
252b5132 RH |
9422 | fputc ('\n', stream); |
9423 | ||
9424 | fprintf (stream, _("\ | |
9425 | -mCPU equivalent to -mcpu=CPU.\n\ | |
9426 | -no-mCPU don't generate code specific to CPU.\n\ | |
9427 | For -mCPU and -no-mCPU, CPU must be one of:\n")); | |
9428 | ||
9429 | first = 1; | |
9430 | ||
9431 | show (stream, "3900", &column, &first); | |
9432 | show (stream, "4010", &column, &first); | |
9433 | show (stream, "4100", &column, &first); | |
9434 | show (stream, "4650", &column, &first); | |
9435 | fputc ('\n', stream); | |
9436 | ||
156c2f8b NC |
9437 | fprintf (stream, _("\ |
9438 | -mips32 generate MIPS32 instructions\n")); | |
9439 | ||
252b5132 RH |
9440 | fprintf(stream, _("\ |
9441 | -mips16 generate mips16 instructions\n\ | |
9442 | -no-mips16 do not generate mips16 instructions\n")); | |
9443 | fprintf(stream, _("\ | |
9444 | -O0 remove unneeded NOPs, do not swap branches\n\ | |
9445 | -O remove unneeded NOPs and swap branches\n\ | |
119d663a | 9446 | --[no-]construct-floats [dis]allow floating point values to be constructed\n\ |
252b5132 RH |
9447 | --trap, --no-break trap exception on div by 0 and mult overflow\n\ |
9448 | --break, --no-trap break exception on div by 0 and mult overflow\n")); | |
9449 | #ifdef OBJ_ELF | |
9450 | fprintf(stream, _("\ | |
9451 | -KPIC, -call_shared generate SVR4 position independent code\n\ | |
9452 | -non_shared do not generate position independent code\n\ | |
9453 | -xgot assume a 32 bit GOT\n\ | |
9454 | -32 create 32 bit object file (default)\n\ | |
9455 | -64 create 64 bit object file\n")); | |
9456 | #endif | |
9457 | } | |
9458 | \f | |
9459 | void | |
9460 | mips_init_after_args () | |
9461 | { | |
9462 | /* initialize opcodes */ | |
9463 | bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes; | |
9464 | mips_opcodes = (struct mips_opcode*) mips_builtin_opcodes; | |
9465 | } | |
9466 | ||
9467 | long | |
9468 | md_pcrel_from (fixP) | |
9469 | fixS *fixP; | |
9470 | { | |
9471 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour | |
9472 | && fixP->fx_addsy != (symbolS *) NULL | |
9473 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
9474 | { | |
9475 | /* This makes a branch to an undefined symbol be a branch to the | |
9476 | current location. */ | |
9477 | return 4; | |
9478 | } | |
9479 | ||
9480 | /* return the address of the delay slot */ | |
9481 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; | |
9482 | } | |
9483 | ||
9484 | /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a | |
9485 | reloc for a cons. We could use the definition there, except that | |
9486 | we want to handle 64 bit relocs specially. */ | |
9487 | ||
9488 | void | |
9489 | cons_fix_new_mips (frag, where, nbytes, exp) | |
43841e91 | 9490 | fragS *frag ATTRIBUTE_UNUSED; |
252b5132 RH |
9491 | int where; |
9492 | unsigned int nbytes; | |
9493 | expressionS *exp; | |
9494 | { | |
9495 | #ifndef OBJ_ELF | |
9496 | /* If we are assembling in 32 bit mode, turn an 8 byte reloc into a | |
9497 | 4 byte reloc. */ | |
9498 | if (nbytes == 8 && ! mips_64) | |
9499 | { | |
9500 | if (target_big_endian) | |
9501 | where += 4; | |
9502 | nbytes = 4; | |
9503 | } | |
9504 | #endif | |
9505 | ||
9506 | if (nbytes != 2 && nbytes != 4 && nbytes != 8) | |
9507 | as_bad (_("Unsupported reloc size %d"), nbytes); | |
9508 | ||
9509 | fix_new_exp (frag_now, where, (int) nbytes, exp, 0, | |
9510 | (nbytes == 2 | |
9511 | ? BFD_RELOC_16 | |
9512 | : (nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64))); | |
9513 | } | |
9514 | ||
9515 | /* This is called before the symbol table is processed. In order to | |
9516 | work with gcc when using mips-tfile, we must keep all local labels. | |
9517 | However, in other cases, we want to discard them. If we were | |
9518 | called with -g, but we didn't see any debugging information, it may | |
9519 | mean that gcc is smuggling debugging information through to | |
9520 | mips-tfile, in which case we must generate all local labels. */ | |
9521 | ||
9522 | void | |
9523 | mips_frob_file_before_adjust () | |
9524 | { | |
9525 | #ifndef NO_ECOFF_DEBUGGING | |
9526 | if (ECOFF_DEBUGGING | |
9527 | && mips_debug != 0 | |
9528 | && ! ecoff_debugging_seen) | |
9529 | flag_keep_locals = 1; | |
9530 | #endif | |
9531 | } | |
9532 | ||
9533 | /* Sort any unmatched HI16_S relocs so that they immediately precede | |
9534 | the corresponding LO reloc. This is called before md_apply_fix and | |
9535 | tc_gen_reloc. Unmatched HI16_S relocs can only be generated by | |
9536 | explicit use of the %hi modifier. */ | |
9537 | ||
9538 | void | |
9539 | mips_frob_file () | |
9540 | { | |
9541 | struct mips_hi_fixup *l; | |
9542 | ||
9543 | for (l = mips_hi_fixup_list; l != NULL; l = l->next) | |
9544 | { | |
9545 | segment_info_type *seginfo; | |
9546 | int pass; | |
9547 | ||
9548 | assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S); | |
9549 | ||
9550 | /* Check quickly whether the next fixup happens to be a matching | |
9551 | %lo. */ | |
9552 | if (l->fixp->fx_next != NULL | |
9553 | && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16 | |
9554 | && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy | |
9555 | && l->fixp->fx_offset == l->fixp->fx_next->fx_offset) | |
9556 | continue; | |
9557 | ||
9558 | /* Look through the fixups for this segment for a matching %lo. | |
9559 | When we find one, move the %hi just in front of it. We do | |
9560 | this in two passes. In the first pass, we try to find a | |
9561 | unique %lo. In the second pass, we permit multiple %hi | |
9562 | relocs for a single %lo (this is a GNU extension). */ | |
9563 | seginfo = seg_info (l->seg); | |
9564 | for (pass = 0; pass < 2; pass++) | |
9565 | { | |
9566 | fixS *f, *prev; | |
9567 | ||
9568 | prev = NULL; | |
9569 | for (f = seginfo->fix_root; f != NULL; f = f->fx_next) | |
9570 | { | |
9571 | /* Check whether this is a %lo fixup which matches l->fixp. */ | |
9572 | if (f->fx_r_type == BFD_RELOC_LO16 | |
9573 | && f->fx_addsy == l->fixp->fx_addsy | |
9574 | && f->fx_offset == l->fixp->fx_offset | |
9575 | && (pass == 1 | |
9576 | || prev == NULL | |
9577 | || prev->fx_r_type != BFD_RELOC_HI16_S | |
9578 | || prev->fx_addsy != f->fx_addsy | |
9579 | || prev->fx_offset != f->fx_offset)) | |
9580 | { | |
9581 | fixS **pf; | |
9582 | ||
9583 | /* Move l->fixp before f. */ | |
9584 | for (pf = &seginfo->fix_root; | |
9585 | *pf != l->fixp; | |
9586 | pf = &(*pf)->fx_next) | |
9587 | assert (*pf != NULL); | |
9588 | ||
9589 | *pf = l->fixp->fx_next; | |
9590 | ||
9591 | l->fixp->fx_next = f; | |
9592 | if (prev == NULL) | |
9593 | seginfo->fix_root = l->fixp; | |
9594 | else | |
9595 | prev->fx_next = l->fixp; | |
9596 | ||
9597 | break; | |
9598 | } | |
9599 | ||
9600 | prev = f; | |
9601 | } | |
9602 | ||
9603 | if (f != NULL) | |
9604 | break; | |
9605 | ||
9606 | #if 0 /* GCC code motion plus incomplete dead code elimination | |
9607 | can leave a %hi without a %lo. */ | |
9608 | if (pass == 1) | |
9609 | as_warn_where (l->fixp->fx_file, l->fixp->fx_line, | |
9610 | _("Unmatched %%hi reloc")); | |
9611 | #endif | |
9612 | } | |
9613 | } | |
9614 | } | |
9615 | ||
9616 | /* When generating embedded PIC code we need to use a special | |
9617 | relocation to represent the difference of two symbols in the .text | |
9618 | section (switch tables use a difference of this sort). See | |
9619 | include/coff/mips.h for details. This macro checks whether this | |
9620 | fixup requires the special reloc. */ | |
9621 | #define SWITCH_TABLE(fixp) \ | |
9622 | ((fixp)->fx_r_type == BFD_RELOC_32 \ | |
bb2d6cd7 | 9623 | && OUTPUT_FLAVOR != bfd_target_elf_flavour \ |
252b5132 RH |
9624 | && (fixp)->fx_addsy != NULL \ |
9625 | && (fixp)->fx_subsy != NULL \ | |
9626 | && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \ | |
9627 | && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section) | |
9628 | ||
9629 | /* When generating embedded PIC code we must keep all PC relative | |
9630 | relocations, in case the linker has to relax a call. We also need | |
9631 | to keep relocations for switch table entries. */ | |
9632 | ||
9633 | /*ARGSUSED*/ | |
9634 | int | |
9635 | mips_force_relocation (fixp) | |
9636 | fixS *fixp; | |
9637 | { | |
9638 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
9639 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
9640 | return 1; | |
9641 | ||
9642 | return (mips_pic == EMBEDDED_PIC | |
9643 | && (fixp->fx_pcrel | |
9644 | || SWITCH_TABLE (fixp) | |
9645 | || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S | |
9646 | || fixp->fx_r_type == BFD_RELOC_PCREL_LO16)); | |
9647 | } | |
9648 | ||
9649 | /* Apply a fixup to the object file. */ | |
9650 | ||
9651 | int | |
9652 | md_apply_fix (fixP, valueP) | |
9653 | fixS *fixP; | |
9654 | valueT *valueP; | |
9655 | { | |
9656 | unsigned char *buf; | |
9657 | long insn, value; | |
9658 | ||
9659 | assert (fixP->fx_size == 4 | |
9660 | || fixP->fx_r_type == BFD_RELOC_16 | |
9661 | || fixP->fx_r_type == BFD_RELOC_64 | |
9662 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
9663 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY); | |
9664 | ||
9665 | value = *valueP; | |
9666 | ||
9667 | /* If we aren't adjusting this fixup to be against the section | |
9668 | symbol, we need to adjust the value. */ | |
9669 | #ifdef OBJ_ELF | |
9670 | if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
bb2d6cd7 | 9671 | { |
bdaaa2e1 | 9672 | if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16 |
252b5132 | 9673 | || S_IS_WEAK (fixP->fx_addsy) |
49309057 ILT |
9674 | || (symbol_used_in_reloc_p (fixP->fx_addsy) |
9675 | && (((bfd_get_section_flags (stdoutput, | |
bb2d6cd7 GK |
9676 | S_GET_SEGMENT (fixP->fx_addsy)) |
9677 | & SEC_LINK_ONCE) != 0) | |
9678 | || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)), | |
9679 | ".gnu.linkonce", | |
9680 | sizeof (".gnu.linkonce") - 1)))) | |
252b5132 RH |
9681 | |
9682 | { | |
9683 | value -= S_GET_VALUE (fixP->fx_addsy); | |
9684 | if (value != 0 && ! fixP->fx_pcrel) | |
9685 | { | |
9686 | /* In this case, the bfd_install_relocation routine will | |
9687 | incorrectly add the symbol value back in. We just want | |
bdaaa2e1 | 9688 | the addend to appear in the object file. |
bb2d6cd7 | 9689 | FIXME: If this makes VALUE zero, we're toast. */ |
252b5132 RH |
9690 | value -= S_GET_VALUE (fixP->fx_addsy); |
9691 | } | |
9692 | } | |
252b5132 | 9693 | |
bb2d6cd7 GK |
9694 | /* This code was generated using trial and error and so is |
9695 | fragile and not trustworthy. If you change it, you should | |
9696 | rerun the elf-rel, elf-rel2, and empic testcases and ensure | |
9697 | they still pass. */ | |
9698 | if (fixP->fx_pcrel || fixP->fx_subsy != NULL) | |
9699 | { | |
9700 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
9701 | ||
9702 | /* BFD's REL handling, for MIPS, is _very_ weird. | |
9703 | This gives the right results, but it can't possibly | |
9704 | be the way things are supposed to work. */ | |
9705 | if (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2 | |
9706 | || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section) | |
9707 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
9708 | } | |
9709 | } | |
9710 | #endif | |
252b5132 RH |
9711 | |
9712 | fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc */ | |
9713 | ||
9714 | if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel) | |
9715 | fixP->fx_done = 1; | |
9716 | ||
9717 | switch (fixP->fx_r_type) | |
9718 | { | |
9719 | case BFD_RELOC_MIPS_JMP: | |
9720 | case BFD_RELOC_HI16: | |
9721 | case BFD_RELOC_HI16_S: | |
9722 | case BFD_RELOC_MIPS_GPREL: | |
9723 | case BFD_RELOC_MIPS_LITERAL: | |
9724 | case BFD_RELOC_MIPS_CALL16: | |
9725 | case BFD_RELOC_MIPS_GOT16: | |
9726 | case BFD_RELOC_MIPS_GPREL32: | |
9727 | case BFD_RELOC_MIPS_GOT_HI16: | |
9728 | case BFD_RELOC_MIPS_GOT_LO16: | |
9729 | case BFD_RELOC_MIPS_CALL_HI16: | |
9730 | case BFD_RELOC_MIPS_CALL_LO16: | |
9731 | case BFD_RELOC_MIPS16_GPREL: | |
9732 | if (fixP->fx_pcrel) | |
9733 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9734 | _("Invalid PC relative reloc")); | |
9735 | /* Nothing needed to do. The value comes from the reloc entry */ | |
9736 | break; | |
9737 | ||
9738 | case BFD_RELOC_MIPS16_JMP: | |
9739 | /* We currently always generate a reloc against a symbol, which | |
9740 | means that we don't want an addend even if the symbol is | |
9741 | defined. */ | |
9742 | fixP->fx_addnumber = 0; | |
9743 | break; | |
9744 | ||
9745 | case BFD_RELOC_PCREL_HI16_S: | |
9746 | /* The addend for this is tricky if it is internal, so we just | |
9747 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 9748 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
9749 | && !fixP->fx_done |
9750 | && value != 0) | |
9751 | break; | |
9752 | if (fixP->fx_addsy | |
9753 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
9754 | { |
9755 | /* For an external symbol adjust by the address to make it | |
9756 | pcrel_offset. We use the address of the RELLO reloc | |
9757 | which follows this one. */ | |
9758 | value += (fixP->fx_next->fx_frag->fr_address | |
9759 | + fixP->fx_next->fx_where); | |
9760 | } | |
9761 | if (value & 0x8000) | |
9762 | value += 0x10000; | |
9763 | value >>= 16; | |
9764 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
9765 | if (target_big_endian) | |
9766 | buf += 2; | |
9767 | md_number_to_chars (buf, value, 2); | |
9768 | break; | |
9769 | ||
9770 | case BFD_RELOC_PCREL_LO16: | |
9771 | /* The addend for this is tricky if it is internal, so we just | |
9772 | do everything here rather than in bfd_install_relocation. */ | |
bdaaa2e1 | 9773 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour |
bb2d6cd7 GK |
9774 | && !fixP->fx_done |
9775 | && value != 0) | |
9776 | break; | |
9777 | if (fixP->fx_addsy | |
9778 | && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0) | |
252b5132 RH |
9779 | value += fixP->fx_frag->fr_address + fixP->fx_where; |
9780 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
9781 | if (target_big_endian) | |
9782 | buf += 2; | |
9783 | md_number_to_chars (buf, value, 2); | |
9784 | break; | |
9785 | ||
9786 | case BFD_RELOC_64: | |
9787 | /* This is handled like BFD_RELOC_32, but we output a sign | |
9788 | extended value if we are only 32 bits. */ | |
9789 | if (fixP->fx_done | |
9790 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
9791 | { | |
9792 | if (8 <= sizeof (valueT)) | |
9793 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9794 | value, 8); | |
9795 | else | |
9796 | { | |
9797 | long w1, w2; | |
9798 | long hiv; | |
9799 | ||
9800 | w1 = w2 = fixP->fx_where; | |
9801 | if (target_big_endian) | |
9802 | w1 += 4; | |
9803 | else | |
9804 | w2 += 4; | |
9805 | md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4); | |
9806 | if ((value & 0x80000000) != 0) | |
9807 | hiv = 0xffffffff; | |
9808 | else | |
9809 | hiv = 0; | |
9810 | md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4); | |
9811 | } | |
9812 | } | |
9813 | break; | |
9814 | ||
056350c6 | 9815 | case BFD_RELOC_RVA: |
252b5132 RH |
9816 | case BFD_RELOC_32: |
9817 | /* If we are deleting this reloc entry, we must fill in the | |
9818 | value now. This can happen if we have a .word which is not | |
9819 | resolved when it appears but is later defined. We also need | |
9820 | to fill in the value if this is an embedded PIC switch table | |
9821 | entry. */ | |
9822 | if (fixP->fx_done | |
9823 | || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP))) | |
9824 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9825 | value, 4); | |
9826 | break; | |
9827 | ||
9828 | case BFD_RELOC_16: | |
9829 | /* If we are deleting this reloc entry, we must fill in the | |
9830 | value now. */ | |
9831 | assert (fixP->fx_size == 2); | |
9832 | if (fixP->fx_done) | |
9833 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, | |
9834 | value, 2); | |
9835 | break; | |
9836 | ||
9837 | case BFD_RELOC_LO16: | |
9838 | /* When handling an embedded PIC switch statement, we can wind | |
9839 | up deleting a LO16 reloc. See the 'o' case in mips_ip. */ | |
9840 | if (fixP->fx_done) | |
9841 | { | |
9842 | if (value < -0x8000 || value > 0x7fff) | |
9843 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9844 | _("relocation overflow")); | |
9845 | buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where; | |
9846 | if (target_big_endian) | |
9847 | buf += 2; | |
9848 | md_number_to_chars (buf, value, 2); | |
9849 | } | |
9850 | break; | |
9851 | ||
9852 | case BFD_RELOC_16_PCREL_S2: | |
9853 | /* | |
9854 | * We need to save the bits in the instruction since fixup_segment() | |
9855 | * might be deleting the relocation entry (i.e., a branch within | |
9856 | * the current segment). | |
9857 | */ | |
9858 | if ((value & 0x3) != 0) | |
9859 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9860 | _("Branch to odd address (%lx)"), value); | |
bb2d6cd7 GK |
9861 | |
9862 | if (!fixP->fx_done && value != 0) | |
9863 | break; | |
9864 | /* If 'value' is zero, the remaining reloc code won't actually | |
9865 | do the store, so it must be done here. This is probably | |
9866 | a bug somewhere. */ | |
9867 | if (!fixP->fx_done) | |
9868 | value -= fixP->fx_frag->fr_address + fixP->fx_where; | |
bdaaa2e1 | 9869 | |
252b5132 RH |
9870 | value >>= 2; |
9871 | ||
9872 | /* update old instruction data */ | |
9873 | buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal); | |
9874 | if (target_big_endian) | |
9875 | insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
9876 | else | |
9877 | insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | |
9878 | ||
9879 | if (value >= -0x8000 && value < 0x8000) | |
9880 | insn |= value & 0xffff; | |
9881 | else | |
9882 | { | |
9883 | /* The branch offset is too large. If this is an | |
9884 | unconditional branch, and we are not generating PIC code, | |
9885 | we can convert it to an absolute jump instruction. */ | |
9886 | if (mips_pic == NO_PIC | |
9887 | && fixP->fx_done | |
9888 | && fixP->fx_frag->fr_address >= text_section->vma | |
9889 | && (fixP->fx_frag->fr_address | |
9890 | < text_section->vma + text_section->_raw_size) | |
9891 | && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */ | |
9892 | || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */ | |
9893 | || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */ | |
9894 | { | |
9895 | if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */ | |
9896 | insn = 0x0c000000; /* jal */ | |
9897 | else | |
9898 | insn = 0x08000000; /* j */ | |
9899 | fixP->fx_r_type = BFD_RELOC_MIPS_JMP; | |
9900 | fixP->fx_done = 0; | |
9901 | fixP->fx_addsy = section_symbol (text_section); | |
9902 | fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP); | |
9903 | } | |
9904 | else | |
9905 | { | |
9906 | /* FIXME. It would be possible in principle to handle | |
9907 | conditional branches which overflow. They could be | |
9908 | transformed into a branch around a jump. This would | |
9909 | require setting up variant frags for each different | |
9910 | branch type. The native MIPS assembler attempts to | |
9911 | handle these cases, but it appears to do it | |
9912 | incorrectly. */ | |
9913 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
9914 | _("Branch out of range")); | |
9915 | } | |
9916 | } | |
9917 | ||
9918 | md_number_to_chars ((char *) buf, (valueT) insn, 4); | |
9919 | break; | |
9920 | ||
9921 | case BFD_RELOC_VTABLE_INHERIT: | |
9922 | fixP->fx_done = 0; | |
9923 | if (fixP->fx_addsy | |
9924 | && !S_IS_DEFINED (fixP->fx_addsy) | |
9925 | && !S_IS_WEAK (fixP->fx_addsy)) | |
9926 | S_SET_WEAK (fixP->fx_addsy); | |
9927 | break; | |
9928 | ||
9929 | case BFD_RELOC_VTABLE_ENTRY: | |
9930 | fixP->fx_done = 0; | |
9931 | break; | |
9932 | ||
9933 | default: | |
9934 | internalError (); | |
9935 | } | |
9936 | ||
9937 | return 1; | |
9938 | } | |
9939 | ||
9940 | #if 0 | |
9941 | void | |
9942 | printInsn (oc) | |
9943 | unsigned long oc; | |
9944 | { | |
9945 | const struct mips_opcode *p; | |
9946 | int treg, sreg, dreg, shamt; | |
9947 | short imm; | |
9948 | const char *args; | |
9949 | int i; | |
9950 | ||
9951 | for (i = 0; i < NUMOPCODES; ++i) | |
9952 | { | |
9953 | p = &mips_opcodes[i]; | |
9954 | if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO)) | |
9955 | { | |
9956 | printf ("%08lx %s\t", oc, p->name); | |
9957 | treg = (oc >> 16) & 0x1f; | |
9958 | sreg = (oc >> 21) & 0x1f; | |
9959 | dreg = (oc >> 11) & 0x1f; | |
9960 | shamt = (oc >> 6) & 0x1f; | |
9961 | imm = oc; | |
9962 | for (args = p->args;; ++args) | |
9963 | { | |
9964 | switch (*args) | |
9965 | { | |
9966 | case '\0': | |
9967 | printf ("\n"); | |
9968 | break; | |
9969 | ||
9970 | case ',': | |
9971 | case '(': | |
9972 | case ')': | |
9973 | printf ("%c", *args); | |
9974 | continue; | |
9975 | ||
9976 | case 'r': | |
9977 | assert (treg == sreg); | |
9978 | printf ("$%d,$%d", treg, sreg); | |
9979 | continue; | |
9980 | ||
9981 | case 'd': | |
9982 | case 'G': | |
9983 | printf ("$%d", dreg); | |
9984 | continue; | |
9985 | ||
9986 | case 't': | |
9987 | case 'E': | |
9988 | printf ("$%d", treg); | |
9989 | continue; | |
9990 | ||
9991 | case 'k': | |
9992 | printf ("0x%x", treg); | |
9993 | continue; | |
9994 | ||
9995 | case 'b': | |
9996 | case 's': | |
9997 | printf ("$%d", sreg); | |
9998 | continue; | |
9999 | ||
10000 | case 'a': | |
10001 | printf ("0x%08lx", oc & 0x1ffffff); | |
10002 | continue; | |
10003 | ||
10004 | case 'i': | |
10005 | case 'j': | |
10006 | case 'o': | |
10007 | case 'u': | |
10008 | printf ("%d", imm); | |
10009 | continue; | |
10010 | ||
10011 | case '<': | |
10012 | case '>': | |
10013 | printf ("$%d", shamt); | |
10014 | continue; | |
10015 | ||
10016 | default: | |
10017 | internalError (); | |
10018 | } | |
10019 | break; | |
10020 | } | |
10021 | return; | |
10022 | } | |
10023 | } | |
10024 | printf (_("%08lx UNDEFINED\n"), oc); | |
10025 | } | |
10026 | #endif | |
10027 | ||
10028 | static symbolS * | |
10029 | get_symbol () | |
10030 | { | |
10031 | int c; | |
10032 | char *name; | |
10033 | symbolS *p; | |
10034 | ||
10035 | name = input_line_pointer; | |
10036 | c = get_symbol_end (); | |
10037 | p = (symbolS *) symbol_find_or_make (name); | |
10038 | *input_line_pointer = c; | |
10039 | return p; | |
10040 | } | |
10041 | ||
10042 | /* Align the current frag to a given power of two. The MIPS assembler | |
10043 | also automatically adjusts any preceding label. */ | |
10044 | ||
10045 | static void | |
10046 | mips_align (to, fill, label) | |
10047 | int to; | |
10048 | int fill; | |
10049 | symbolS *label; | |
10050 | { | |
10051 | mips_emit_delays (false); | |
10052 | frag_align (to, fill, 0); | |
10053 | record_alignment (now_seg, to); | |
10054 | if (label != NULL) | |
10055 | { | |
10056 | assert (S_GET_SEGMENT (label) == now_seg); | |
49309057 | 10057 | symbol_set_frag (label, frag_now); |
252b5132 RH |
10058 | S_SET_VALUE (label, (valueT) frag_now_fix ()); |
10059 | } | |
10060 | } | |
10061 | ||
10062 | /* Align to a given power of two. .align 0 turns off the automatic | |
10063 | alignment used by the data creating pseudo-ops. */ | |
10064 | ||
10065 | static void | |
10066 | s_align (x) | |
43841e91 | 10067 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10068 | { |
10069 | register int temp; | |
10070 | register long temp_fill; | |
10071 | long max_alignment = 15; | |
10072 | ||
10073 | /* | |
10074 | ||
10075 | o Note that the assembler pulls down any immediately preceeding label | |
10076 | to the aligned address. | |
10077 | o It's not documented but auto alignment is reinstated by | |
10078 | a .align pseudo instruction. | |
10079 | o Note also that after auto alignment is turned off the mips assembler | |
10080 | issues an error on attempt to assemble an improperly aligned data item. | |
10081 | We don't. | |
10082 | ||
10083 | */ | |
10084 | ||
10085 | temp = get_absolute_expression (); | |
10086 | if (temp > max_alignment) | |
10087 | as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment); | |
10088 | else if (temp < 0) | |
10089 | { | |
10090 | as_warn (_("Alignment negative: 0 assumed.")); | |
10091 | temp = 0; | |
10092 | } | |
10093 | if (*input_line_pointer == ',') | |
10094 | { | |
10095 | input_line_pointer++; | |
10096 | temp_fill = get_absolute_expression (); | |
10097 | } | |
10098 | else | |
10099 | temp_fill = 0; | |
10100 | if (temp) | |
10101 | { | |
10102 | auto_align = 1; | |
10103 | mips_align (temp, (int) temp_fill, | |
10104 | insn_labels != NULL ? insn_labels->label : NULL); | |
10105 | } | |
10106 | else | |
10107 | { | |
10108 | auto_align = 0; | |
10109 | } | |
10110 | ||
10111 | demand_empty_rest_of_line (); | |
10112 | } | |
10113 | ||
10114 | void | |
10115 | mips_flush_pending_output () | |
10116 | { | |
10117 | mips_emit_delays (false); | |
10118 | mips_clear_insn_labels (); | |
10119 | } | |
10120 | ||
10121 | static void | |
10122 | s_change_sec (sec) | |
10123 | int sec; | |
10124 | { | |
10125 | segT seg; | |
10126 | ||
10127 | /* When generating embedded PIC code, we only use the .text, .lit8, | |
10128 | .sdata and .sbss sections. We change the .data and .rdata | |
10129 | pseudo-ops to use .sdata. */ | |
10130 | if (mips_pic == EMBEDDED_PIC | |
10131 | && (sec == 'd' || sec == 'r')) | |
10132 | sec = 's'; | |
10133 | ||
10134 | #ifdef OBJ_ELF | |
10135 | /* The ELF backend needs to know that we are changing sections, so | |
10136 | that .previous works correctly. We could do something like check | |
10137 | for a obj_section_change_hook macro, but that might be confusing | |
10138 | as it would not be appropriate to use it in the section changing | |
10139 | functions in read.c, since obj-elf.c intercepts those. FIXME: | |
10140 | This should be cleaner, somehow. */ | |
10141 | obj_elf_section_change_hook (); | |
10142 | #endif | |
10143 | ||
10144 | mips_emit_delays (false); | |
10145 | switch (sec) | |
10146 | { | |
10147 | case 't': | |
10148 | s_text (0); | |
10149 | break; | |
10150 | case 'd': | |
10151 | s_data (0); | |
10152 | break; | |
10153 | case 'b': | |
10154 | subseg_set (bss_section, (subsegT) get_absolute_expression ()); | |
10155 | demand_empty_rest_of_line (); | |
10156 | break; | |
10157 | ||
10158 | case 'r': | |
10159 | if (USE_GLOBAL_POINTER_OPT) | |
10160 | { | |
10161 | seg = subseg_new (RDATA_SECTION_NAME, | |
10162 | (subsegT) get_absolute_expression ()); | |
10163 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
10164 | { | |
10165 | bfd_set_section_flags (stdoutput, seg, | |
10166 | (SEC_ALLOC | |
10167 | | SEC_LOAD | |
10168 | | SEC_READONLY | |
10169 | | SEC_RELOC | |
10170 | | SEC_DATA)); | |
10171 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 10172 | record_alignment (seg, 4); |
252b5132 RH |
10173 | } |
10174 | demand_empty_rest_of_line (); | |
10175 | } | |
10176 | else | |
10177 | { | |
10178 | as_bad (_("No read only data section in this object file format")); | |
10179 | demand_empty_rest_of_line (); | |
10180 | return; | |
10181 | } | |
10182 | break; | |
10183 | ||
10184 | case 's': | |
10185 | if (USE_GLOBAL_POINTER_OPT) | |
10186 | { | |
10187 | seg = subseg_new (".sdata", (subsegT) get_absolute_expression ()); | |
10188 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
10189 | { | |
10190 | bfd_set_section_flags (stdoutput, seg, | |
10191 | SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
10192 | | SEC_DATA); | |
10193 | if (strcmp (TARGET_OS, "elf") != 0) | |
e799a695 | 10194 | record_alignment (seg, 4); |
252b5132 RH |
10195 | } |
10196 | demand_empty_rest_of_line (); | |
10197 | break; | |
10198 | } | |
10199 | else | |
10200 | { | |
10201 | as_bad (_("Global pointers not supported; recompile -G 0")); | |
10202 | demand_empty_rest_of_line (); | |
10203 | return; | |
10204 | } | |
10205 | } | |
10206 | ||
10207 | auto_align = 1; | |
10208 | } | |
10209 | ||
10210 | void | |
10211 | mips_enable_auto_align () | |
10212 | { | |
10213 | auto_align = 1; | |
10214 | } | |
10215 | ||
10216 | static void | |
10217 | s_cons (log_size) | |
10218 | int log_size; | |
10219 | { | |
10220 | symbolS *label; | |
10221 | ||
10222 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10223 | mips_emit_delays (false); | |
10224 | if (log_size > 0 && auto_align) | |
10225 | mips_align (log_size, 0, label); | |
10226 | mips_clear_insn_labels (); | |
10227 | cons (1 << log_size); | |
10228 | } | |
10229 | ||
10230 | static void | |
10231 | s_float_cons (type) | |
10232 | int type; | |
10233 | { | |
10234 | symbolS *label; | |
10235 | ||
10236 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10237 | ||
10238 | mips_emit_delays (false); | |
10239 | ||
10240 | if (auto_align) | |
49309057 ILT |
10241 | { |
10242 | if (type == 'd') | |
10243 | mips_align (3, 0, label); | |
10244 | else | |
10245 | mips_align (2, 0, label); | |
10246 | } | |
252b5132 RH |
10247 | |
10248 | mips_clear_insn_labels (); | |
10249 | ||
10250 | float_cons (type); | |
10251 | } | |
10252 | ||
10253 | /* Handle .globl. We need to override it because on Irix 5 you are | |
10254 | permitted to say | |
10255 | .globl foo .text | |
10256 | where foo is an undefined symbol, to mean that foo should be | |
10257 | considered to be the address of a function. */ | |
10258 | ||
10259 | static void | |
10260 | s_mips_globl (x) | |
43841e91 | 10261 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10262 | { |
10263 | char *name; | |
10264 | int c; | |
10265 | symbolS *symbolP; | |
10266 | flagword flag; | |
10267 | ||
10268 | name = input_line_pointer; | |
10269 | c = get_symbol_end (); | |
10270 | symbolP = symbol_find_or_make (name); | |
10271 | *input_line_pointer = c; | |
10272 | SKIP_WHITESPACE (); | |
10273 | ||
10274 | /* On Irix 5, every global symbol that is not explicitly labelled as | |
10275 | being a function is apparently labelled as being an object. */ | |
10276 | flag = BSF_OBJECT; | |
10277 | ||
10278 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
10279 | { | |
10280 | char *secname; | |
10281 | asection *sec; | |
10282 | ||
10283 | secname = input_line_pointer; | |
10284 | c = get_symbol_end (); | |
10285 | sec = bfd_get_section_by_name (stdoutput, secname); | |
10286 | if (sec == NULL) | |
10287 | as_bad (_("%s: no such section"), secname); | |
10288 | *input_line_pointer = c; | |
10289 | ||
10290 | if (sec != NULL && (sec->flags & SEC_CODE) != 0) | |
10291 | flag = BSF_FUNCTION; | |
10292 | } | |
10293 | ||
49309057 | 10294 | symbol_get_bfdsym (symbolP)->flags |= flag; |
252b5132 RH |
10295 | |
10296 | S_SET_EXTERNAL (symbolP); | |
10297 | demand_empty_rest_of_line (); | |
10298 | } | |
10299 | ||
10300 | static void | |
10301 | s_option (x) | |
43841e91 | 10302 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10303 | { |
10304 | char *opt; | |
10305 | char c; | |
10306 | ||
10307 | opt = input_line_pointer; | |
10308 | c = get_symbol_end (); | |
10309 | ||
10310 | if (*opt == 'O') | |
10311 | { | |
10312 | /* FIXME: What does this mean? */ | |
10313 | } | |
10314 | else if (strncmp (opt, "pic", 3) == 0) | |
10315 | { | |
10316 | int i; | |
10317 | ||
10318 | i = atoi (opt + 3); | |
10319 | if (i == 0) | |
10320 | mips_pic = NO_PIC; | |
10321 | else if (i == 2) | |
10322 | mips_pic = SVR4_PIC; | |
10323 | else | |
10324 | as_bad (_(".option pic%d not supported"), i); | |
10325 | ||
10326 | if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC) | |
10327 | { | |
10328 | if (g_switch_seen && g_switch_value != 0) | |
10329 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
10330 | g_switch_value = 0; | |
10331 | bfd_set_gp_size (stdoutput, 0); | |
10332 | } | |
10333 | } | |
10334 | else | |
10335 | as_warn (_("Unrecognized option \"%s\""), opt); | |
10336 | ||
10337 | *input_line_pointer = c; | |
10338 | demand_empty_rest_of_line (); | |
10339 | } | |
10340 | ||
10341 | /* This structure is used to hold a stack of .set values. */ | |
10342 | ||
10343 | struct mips_option_stack | |
10344 | { | |
10345 | struct mips_option_stack *next; | |
10346 | struct mips_set_options options; | |
10347 | }; | |
10348 | ||
10349 | static struct mips_option_stack *mips_opts_stack; | |
10350 | ||
10351 | /* Handle the .set pseudo-op. */ | |
10352 | ||
10353 | static void | |
10354 | s_mipsset (x) | |
43841e91 | 10355 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
10356 | { |
10357 | char *name = input_line_pointer, ch; | |
10358 | ||
10359 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
10360 | input_line_pointer++; | |
10361 | ch = *input_line_pointer; | |
10362 | *input_line_pointer = '\0'; | |
10363 | ||
10364 | if (strcmp (name, "reorder") == 0) | |
10365 | { | |
10366 | if (mips_opts.noreorder && prev_nop_frag != NULL) | |
10367 | { | |
10368 | /* If we still have pending nops, we can discard them. The | |
10369 | usual nop handling will insert any that are still | |
bdaaa2e1 | 10370 | needed. */ |
252b5132 RH |
10371 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds |
10372 | * (mips_opts.mips16 ? 2 : 4)); | |
10373 | prev_nop_frag = NULL; | |
10374 | } | |
10375 | mips_opts.noreorder = 0; | |
10376 | } | |
10377 | else if (strcmp (name, "noreorder") == 0) | |
10378 | { | |
10379 | mips_emit_delays (true); | |
10380 | mips_opts.noreorder = 1; | |
10381 | mips_any_noreorder = 1; | |
10382 | } | |
10383 | else if (strcmp (name, "at") == 0) | |
10384 | { | |
10385 | mips_opts.noat = 0; | |
10386 | } | |
10387 | else if (strcmp (name, "noat") == 0) | |
10388 | { | |
10389 | mips_opts.noat = 1; | |
10390 | } | |
10391 | else if (strcmp (name, "macro") == 0) | |
10392 | { | |
10393 | mips_opts.warn_about_macros = 0; | |
10394 | } | |
10395 | else if (strcmp (name, "nomacro") == 0) | |
10396 | { | |
10397 | if (mips_opts.noreorder == 0) | |
10398 | as_bad (_("`noreorder' must be set before `nomacro'")); | |
10399 | mips_opts.warn_about_macros = 1; | |
10400 | } | |
10401 | else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0) | |
10402 | { | |
10403 | mips_opts.nomove = 0; | |
10404 | } | |
10405 | else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0) | |
10406 | { | |
10407 | mips_opts.nomove = 1; | |
10408 | } | |
10409 | else if (strcmp (name, "bopt") == 0) | |
10410 | { | |
10411 | mips_opts.nobopt = 0; | |
10412 | } | |
10413 | else if (strcmp (name, "nobopt") == 0) | |
10414 | { | |
10415 | mips_opts.nobopt = 1; | |
10416 | } | |
10417 | else if (strcmp (name, "mips16") == 0 | |
10418 | || strcmp (name, "MIPS-16") == 0) | |
10419 | mips_opts.mips16 = 1; | |
10420 | else if (strcmp (name, "nomips16") == 0 | |
10421 | || strcmp (name, "noMIPS-16") == 0) | |
10422 | mips_opts.mips16 = 0; | |
10423 | else if (strncmp (name, "mips", 4) == 0) | |
10424 | { | |
10425 | int isa; | |
10426 | ||
10427 | /* Permit the user to change the ISA on the fly. Needless to | |
10428 | say, misuse can cause serious problems. */ | |
10429 | isa = atoi (name + 4); | |
10430 | if (isa == 0) | |
10431 | mips_opts.isa = file_mips_isa; | |
10432 | else if (isa < 1 || isa > 4) | |
10433 | as_bad (_("unknown ISA level")); | |
10434 | else | |
10435 | mips_opts.isa = isa; | |
10436 | } | |
10437 | else if (strcmp (name, "autoextend") == 0) | |
10438 | mips_opts.noautoextend = 0; | |
10439 | else if (strcmp (name, "noautoextend") == 0) | |
10440 | mips_opts.noautoextend = 1; | |
10441 | else if (strcmp (name, "push") == 0) | |
10442 | { | |
10443 | struct mips_option_stack *s; | |
10444 | ||
10445 | s = (struct mips_option_stack *) xmalloc (sizeof *s); | |
10446 | s->next = mips_opts_stack; | |
10447 | s->options = mips_opts; | |
10448 | mips_opts_stack = s; | |
10449 | } | |
10450 | else if (strcmp (name, "pop") == 0) | |
10451 | { | |
10452 | struct mips_option_stack *s; | |
10453 | ||
10454 | s = mips_opts_stack; | |
10455 | if (s == NULL) | |
10456 | as_bad (_(".set pop with no .set push")); | |
10457 | else | |
10458 | { | |
10459 | /* If we're changing the reorder mode we need to handle | |
10460 | delay slots correctly. */ | |
10461 | if (s->options.noreorder && ! mips_opts.noreorder) | |
10462 | mips_emit_delays (true); | |
10463 | else if (! s->options.noreorder && mips_opts.noreorder) | |
10464 | { | |
10465 | if (prev_nop_frag != NULL) | |
10466 | { | |
10467 | prev_nop_frag->fr_fix -= (prev_nop_frag_holds | |
10468 | * (mips_opts.mips16 ? 2 : 4)); | |
10469 | prev_nop_frag = NULL; | |
10470 | } | |
10471 | } | |
10472 | ||
10473 | mips_opts = s->options; | |
10474 | mips_opts_stack = s->next; | |
10475 | free (s); | |
10476 | } | |
10477 | } | |
10478 | else | |
10479 | { | |
10480 | as_warn (_("Tried to set unrecognized symbol: %s\n"), name); | |
10481 | } | |
10482 | *input_line_pointer = ch; | |
10483 | demand_empty_rest_of_line (); | |
10484 | } | |
10485 | ||
10486 | /* Handle the .abicalls pseudo-op. I believe this is equivalent to | |
10487 | .option pic2. It means to generate SVR4 PIC calls. */ | |
10488 | ||
10489 | static void | |
10490 | s_abicalls (ignore) | |
43841e91 | 10491 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10492 | { |
10493 | mips_pic = SVR4_PIC; | |
10494 | if (USE_GLOBAL_POINTER_OPT) | |
10495 | { | |
10496 | if (g_switch_seen && g_switch_value != 0) | |
10497 | as_warn (_("-G may not be used with SVR4 PIC code")); | |
10498 | g_switch_value = 0; | |
10499 | } | |
10500 | bfd_set_gp_size (stdoutput, 0); | |
10501 | demand_empty_rest_of_line (); | |
10502 | } | |
10503 | ||
10504 | /* Handle the .cpload pseudo-op. This is used when generating SVR4 | |
10505 | PIC code. It sets the $gp register for the function based on the | |
10506 | function address, which is in the register named in the argument. | |
10507 | This uses a relocation against _gp_disp, which is handled specially | |
10508 | by the linker. The result is: | |
10509 | lui $gp,%hi(_gp_disp) | |
10510 | addiu $gp,$gp,%lo(_gp_disp) | |
10511 | addu $gp,$gp,.cpload argument | |
10512 | The .cpload argument is normally $25 == $t9. */ | |
10513 | ||
10514 | static void | |
10515 | s_cpload (ignore) | |
43841e91 | 10516 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10517 | { |
10518 | expressionS ex; | |
10519 | int icnt = 0; | |
10520 | ||
10521 | /* If we are not generating SVR4 PIC code, .cpload is ignored. */ | |
10522 | if (mips_pic != SVR4_PIC) | |
10523 | { | |
10524 | s_ignore (0); | |
10525 | return; | |
10526 | } | |
10527 | ||
10528 | /* .cpload should be a in .set noreorder section. */ | |
10529 | if (mips_opts.noreorder == 0) | |
10530 | as_warn (_(".cpload not in noreorder section")); | |
10531 | ||
10532 | ex.X_op = O_symbol; | |
10533 | ex.X_add_symbol = symbol_find_or_make ("_gp_disp"); | |
10534 | ex.X_op_symbol = NULL; | |
10535 | ex.X_add_number = 0; | |
10536 | ||
10537 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ | |
49309057 | 10538 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
252b5132 RH |
10539 | |
10540 | macro_build_lui ((char *) NULL, &icnt, &ex, GP); | |
10541 | macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP, | |
10542 | (int) BFD_RELOC_LO16); | |
10543 | ||
10544 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t", | |
10545 | GP, GP, tc_get_register (0)); | |
10546 | ||
10547 | demand_empty_rest_of_line (); | |
10548 | } | |
10549 | ||
10550 | /* Handle the .cprestore pseudo-op. This stores $gp into a given | |
10551 | offset from $sp. The offset is remembered, and after making a PIC | |
10552 | call $gp is restored from that location. */ | |
10553 | ||
10554 | static void | |
10555 | s_cprestore (ignore) | |
43841e91 | 10556 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10557 | { |
10558 | expressionS ex; | |
10559 | int icnt = 0; | |
10560 | ||
10561 | /* If we are not generating SVR4 PIC code, .cprestore is ignored. */ | |
10562 | if (mips_pic != SVR4_PIC) | |
10563 | { | |
10564 | s_ignore (0); | |
10565 | return; | |
10566 | } | |
10567 | ||
10568 | mips_cprestore_offset = get_absolute_expression (); | |
10569 | ||
10570 | ex.X_op = O_constant; | |
10571 | ex.X_add_symbol = NULL; | |
10572 | ex.X_op_symbol = NULL; | |
10573 | ex.X_add_number = mips_cprestore_offset; | |
10574 | ||
10575 | macro_build ((char *) NULL, &icnt, &ex, | |
10576 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 10577 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
10578 | ? "sw" : "sd"), |
10579 | "t,o(b)", GP, (int) BFD_RELOC_LO16, SP); | |
10580 | ||
10581 | demand_empty_rest_of_line (); | |
10582 | } | |
10583 | ||
10584 | /* Handle the .gpword pseudo-op. This is used when generating PIC | |
10585 | code. It generates a 32 bit GP relative reloc. */ | |
10586 | ||
10587 | static void | |
10588 | s_gpword (ignore) | |
43841e91 | 10589 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10590 | { |
10591 | symbolS *label; | |
10592 | expressionS ex; | |
10593 | char *p; | |
10594 | ||
10595 | /* When not generating PIC code, this is treated as .word. */ | |
10596 | if (mips_pic != SVR4_PIC) | |
10597 | { | |
10598 | s_cons (2); | |
10599 | return; | |
10600 | } | |
10601 | ||
10602 | label = insn_labels != NULL ? insn_labels->label : NULL; | |
10603 | mips_emit_delays (true); | |
10604 | if (auto_align) | |
10605 | mips_align (2, 0, label); | |
10606 | mips_clear_insn_labels (); | |
10607 | ||
10608 | expression (&ex); | |
10609 | ||
10610 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
10611 | { | |
10612 | as_bad (_("Unsupported use of .gpword")); | |
10613 | ignore_rest_of_line (); | |
10614 | } | |
10615 | ||
10616 | p = frag_more (4); | |
10617 | md_number_to_chars (p, (valueT) 0, 4); | |
10618 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0, | |
10619 | BFD_RELOC_MIPS_GPREL32); | |
10620 | ||
10621 | demand_empty_rest_of_line (); | |
10622 | } | |
10623 | ||
10624 | /* Handle the .cpadd pseudo-op. This is used when dealing with switch | |
10625 | tables in SVR4 PIC code. */ | |
10626 | ||
10627 | static void | |
10628 | s_cpadd (ignore) | |
43841e91 | 10629 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10630 | { |
10631 | int icnt = 0; | |
10632 | int reg; | |
10633 | ||
10634 | /* This is ignored when not generating SVR4 PIC code. */ | |
10635 | if (mips_pic != SVR4_PIC) | |
10636 | { | |
10637 | s_ignore (0); | |
10638 | return; | |
10639 | } | |
10640 | ||
10641 | /* Add $gp to the register named as an argument. */ | |
10642 | reg = tc_get_register (0); | |
10643 | macro_build ((char *) NULL, &icnt, (expressionS *) NULL, | |
10644 | ((bfd_arch_bits_per_address (stdoutput) == 32 | |
9ce8a5dd | 10645 | || ! ISA_HAS_64BIT_REGS (mips_opts.isa)) |
252b5132 RH |
10646 | ? "addu" : "daddu"), |
10647 | "d,v,t", reg, reg, GP); | |
10648 | ||
bdaaa2e1 | 10649 | demand_empty_rest_of_line (); |
252b5132 RH |
10650 | } |
10651 | ||
10652 | /* Handle the .insn pseudo-op. This marks instruction labels in | |
10653 | mips16 mode. This permits the linker to handle them specially, | |
10654 | such as generating jalx instructions when needed. We also make | |
10655 | them odd for the duration of the assembly, in order to generate the | |
10656 | right sort of code. We will make them even in the adjust_symtab | |
10657 | routine, while leaving them marked. This is convenient for the | |
10658 | debugger and the disassembler. The linker knows to make them odd | |
10659 | again. */ | |
10660 | ||
10661 | static void | |
10662 | s_insn (ignore) | |
43841e91 | 10663 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10664 | { |
10665 | if (mips_opts.mips16) | |
10666 | mips16_mark_labels (); | |
10667 | ||
10668 | demand_empty_rest_of_line (); | |
10669 | } | |
10670 | ||
10671 | /* Handle a .stabn directive. We need these in order to mark a label | |
10672 | as being a mips16 text label correctly. Sometimes the compiler | |
10673 | will emit a label, followed by a .stabn, and then switch sections. | |
10674 | If the label and .stabn are in mips16 mode, then the label is | |
10675 | really a mips16 text label. */ | |
10676 | ||
10677 | static void | |
10678 | s_mips_stab (type) | |
10679 | int type; | |
10680 | { | |
10681 | if (type == 'n' && mips_opts.mips16) | |
10682 | mips16_mark_labels (); | |
10683 | ||
10684 | s_stab (type); | |
10685 | } | |
10686 | ||
10687 | /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. | |
10688 | */ | |
10689 | ||
10690 | static void | |
10691 | s_mips_weakext (ignore) | |
43841e91 | 10692 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
10693 | { |
10694 | char *name; | |
10695 | int c; | |
10696 | symbolS *symbolP; | |
10697 | expressionS exp; | |
10698 | ||
10699 | name = input_line_pointer; | |
10700 | c = get_symbol_end (); | |
10701 | symbolP = symbol_find_or_make (name); | |
10702 | S_SET_WEAK (symbolP); | |
10703 | *input_line_pointer = c; | |
10704 | ||
10705 | SKIP_WHITESPACE (); | |
10706 | ||
10707 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
10708 | { | |
10709 | if (S_IS_DEFINED (symbolP)) | |
10710 | { | |
10711 | as_bad ("Ignoring attempt to redefine symbol `%s'.", | |
10712 | S_GET_NAME (symbolP)); | |
10713 | ignore_rest_of_line (); | |
10714 | return; | |
10715 | } | |
bdaaa2e1 | 10716 | |
252b5132 RH |
10717 | if (*input_line_pointer == ',') |
10718 | { | |
10719 | ++input_line_pointer; | |
10720 | SKIP_WHITESPACE (); | |
10721 | } | |
bdaaa2e1 | 10722 | |
252b5132 RH |
10723 | expression (&exp); |
10724 | if (exp.X_op != O_symbol) | |
10725 | { | |
10726 | as_bad ("bad .weakext directive"); | |
10727 | ignore_rest_of_line(); | |
10728 | return; | |
10729 | } | |
49309057 | 10730 | symbol_set_value_expression (symbolP, &exp); |
252b5132 RH |
10731 | } |
10732 | ||
10733 | demand_empty_rest_of_line (); | |
10734 | } | |
10735 | ||
10736 | /* Parse a register string into a number. Called from the ECOFF code | |
10737 | to parse .frame. The argument is non-zero if this is the frame | |
10738 | register, so that we can record it in mips_frame_reg. */ | |
10739 | ||
10740 | int | |
10741 | tc_get_register (frame) | |
10742 | int frame; | |
10743 | { | |
10744 | int reg; | |
10745 | ||
10746 | SKIP_WHITESPACE (); | |
10747 | if (*input_line_pointer++ != '$') | |
10748 | { | |
10749 | as_warn (_("expected `$'")); | |
10750 | reg = 0; | |
10751 | } | |
10752 | else if (isdigit ((unsigned char) *input_line_pointer)) | |
10753 | { | |
10754 | reg = get_absolute_expression (); | |
10755 | if (reg < 0 || reg >= 32) | |
10756 | { | |
10757 | as_warn (_("Bad register number")); | |
10758 | reg = 0; | |
10759 | } | |
10760 | } | |
10761 | else | |
10762 | { | |
10763 | if (strncmp (input_line_pointer, "fp", 2) == 0) | |
10764 | reg = FP; | |
10765 | else if (strncmp (input_line_pointer, "sp", 2) == 0) | |
10766 | reg = SP; | |
10767 | else if (strncmp (input_line_pointer, "gp", 2) == 0) | |
10768 | reg = GP; | |
10769 | else if (strncmp (input_line_pointer, "at", 2) == 0) | |
10770 | reg = AT; | |
10771 | else | |
10772 | { | |
10773 | as_warn (_("Unrecognized register name")); | |
10774 | reg = 0; | |
10775 | } | |
10776 | input_line_pointer += 2; | |
10777 | } | |
10778 | if (frame) | |
10779 | mips_frame_reg = reg != 0 ? reg : SP; | |
10780 | return reg; | |
10781 | } | |
10782 | ||
10783 | valueT | |
10784 | md_section_align (seg, addr) | |
10785 | asection *seg; | |
10786 | valueT addr; | |
10787 | { | |
10788 | int align = bfd_get_section_alignment (stdoutput, seg); | |
10789 | ||
10790 | #ifdef OBJ_ELF | |
10791 | /* We don't need to align ELF sections to the full alignment. | |
10792 | However, Irix 5 may prefer that we align them at least to a 16 | |
10793 | byte boundary. We don't bother to align the sections if we are | |
10794 | targeted for an embedded system. */ | |
10795 | if (strcmp (TARGET_OS, "elf") == 0) | |
10796 | return addr; | |
10797 | if (align > 4) | |
10798 | align = 4; | |
10799 | #endif | |
10800 | ||
10801 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
10802 | } | |
10803 | ||
10804 | /* Utility routine, called from above as well. If called while the | |
10805 | input file is still being read, it's only an approximation. (For | |
10806 | example, a symbol may later become defined which appeared to be | |
10807 | undefined earlier.) */ | |
10808 | ||
10809 | static int | |
10810 | nopic_need_relax (sym, before_relaxing) | |
10811 | symbolS *sym; | |
10812 | int before_relaxing; | |
10813 | { | |
10814 | if (sym == 0) | |
10815 | return 0; | |
10816 | ||
10817 | if (USE_GLOBAL_POINTER_OPT) | |
10818 | { | |
10819 | const char *symname; | |
10820 | int change; | |
10821 | ||
10822 | /* Find out whether this symbol can be referenced off the GP | |
10823 | register. It can be if it is smaller than the -G size or if | |
10824 | it is in the .sdata or .sbss section. Certain symbols can | |
10825 | not be referenced off the GP, although it appears as though | |
10826 | they can. */ | |
10827 | symname = S_GET_NAME (sym); | |
10828 | if (symname != (const char *) NULL | |
10829 | && (strcmp (symname, "eprol") == 0 | |
10830 | || strcmp (symname, "etext") == 0 | |
10831 | || strcmp (symname, "_gp") == 0 | |
10832 | || strcmp (symname, "edata") == 0 | |
10833 | || strcmp (symname, "_fbss") == 0 | |
10834 | || strcmp (symname, "_fdata") == 0 | |
10835 | || strcmp (symname, "_ftext") == 0 | |
10836 | || strcmp (symname, "end") == 0 | |
10837 | || strcmp (symname, "_gp_disp") == 0)) | |
10838 | change = 1; | |
10839 | else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym)) | |
10840 | && (0 | |
10841 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 ILT |
10842 | || (symbol_get_obj (sym)->ecoff_extern_size != 0 |
10843 | && (symbol_get_obj (sym)->ecoff_extern_size | |
10844 | <= g_switch_value)) | |
252b5132 RH |
10845 | #endif |
10846 | /* We must defer this decision until after the whole | |
10847 | file has been read, since there might be a .extern | |
10848 | after the first use of this symbol. */ | |
10849 | || (before_relaxing | |
10850 | #ifndef NO_ECOFF_DEBUGGING | |
49309057 | 10851 | && symbol_get_obj (sym)->ecoff_extern_size == 0 |
252b5132 RH |
10852 | #endif |
10853 | && S_GET_VALUE (sym) == 0) | |
10854 | || (S_GET_VALUE (sym) != 0 | |
10855 | && S_GET_VALUE (sym) <= g_switch_value))) | |
10856 | change = 0; | |
10857 | else | |
10858 | { | |
10859 | const char *segname; | |
10860 | ||
10861 | segname = segment_name (S_GET_SEGMENT (sym)); | |
10862 | assert (strcmp (segname, ".lit8") != 0 | |
10863 | && strcmp (segname, ".lit4") != 0); | |
10864 | change = (strcmp (segname, ".sdata") != 0 | |
fba2b7f9 GK |
10865 | && strcmp (segname, ".sbss") != 0 |
10866 | && strncmp (segname, ".sdata.", 7) != 0 | |
10867 | && strncmp (segname, ".gnu.linkonce.s.", 16) != 0); | |
252b5132 RH |
10868 | } |
10869 | return change; | |
10870 | } | |
10871 | else | |
10872 | /* We are not optimizing for the GP register. */ | |
10873 | return 1; | |
10874 | } | |
10875 | ||
10876 | /* Given a mips16 variant frag FRAGP, return non-zero if it needs an | |
10877 | extended opcode. SEC is the section the frag is in. */ | |
10878 | ||
10879 | static int | |
10880 | mips16_extended_frag (fragp, sec, stretch) | |
10881 | fragS *fragp; | |
10882 | asection *sec; | |
10883 | long stretch; | |
10884 | { | |
10885 | int type; | |
10886 | register const struct mips16_immed_operand *op; | |
10887 | offsetT val; | |
10888 | int mintiny, maxtiny; | |
10889 | segT symsec; | |
10890 | ||
10891 | if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) | |
10892 | return 0; | |
10893 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) | |
10894 | return 1; | |
10895 | ||
10896 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
10897 | op = mips16_immed_operands; | |
10898 | while (op->type != type) | |
10899 | { | |
10900 | ++op; | |
10901 | assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); | |
10902 | } | |
10903 | ||
10904 | if (op->unsp) | |
10905 | { | |
10906 | if (type == '<' || type == '>' || type == '[' || type == ']') | |
10907 | { | |
10908 | mintiny = 1; | |
10909 | maxtiny = 1 << op->nbits; | |
10910 | } | |
10911 | else | |
10912 | { | |
10913 | mintiny = 0; | |
10914 | maxtiny = (1 << op->nbits) - 1; | |
10915 | } | |
10916 | } | |
10917 | else | |
10918 | { | |
10919 | mintiny = - (1 << (op->nbits - 1)); | |
10920 | maxtiny = (1 << (op->nbits - 1)) - 1; | |
10921 | } | |
10922 | ||
49309057 ILT |
10923 | /* We can't always call S_GET_VALUE here, because we don't want to |
10924 | lock in a particular frag address. */ | |
10925 | if (symbol_constant_p (fragp->fr_symbol)) | |
252b5132 | 10926 | { |
49309057 ILT |
10927 | val = (S_GET_VALUE (fragp->fr_symbol) |
10928 | + symbol_get_frag (fragp->fr_symbol)->fr_address); | |
252b5132 RH |
10929 | symsec = S_GET_SEGMENT (fragp->fr_symbol); |
10930 | } | |
49309057 ILT |
10931 | else if (symbol_equated_p (fragp->fr_symbol) |
10932 | && (symbol_constant_p | |
10933 | (symbol_get_value_expression (fragp->fr_symbol)->X_add_symbol))) | |
252b5132 | 10934 | { |
49309057 ILT |
10935 | symbolS *eqsym; |
10936 | ||
10937 | eqsym = symbol_get_value_expression (fragp->fr_symbol)->X_add_symbol; | |
10938 | val = (S_GET_VALUE (eqsym) | |
10939 | + symbol_get_frag (eqsym)->fr_address | |
10940 | + symbol_get_value_expression (fragp->fr_symbol)->X_add_number | |
10941 | + symbol_get_frag (fragp->fr_symbol)->fr_address); | |
10942 | symsec = S_GET_SEGMENT (eqsym); | |
252b5132 RH |
10943 | } |
10944 | else | |
10945 | return 1; | |
10946 | ||
10947 | if (op->pcrel) | |
10948 | { | |
10949 | addressT addr; | |
10950 | ||
10951 | /* We won't have the section when we are called from | |
10952 | mips_relax_frag. However, we will always have been called | |
10953 | from md_estimate_size_before_relax first. If this is a | |
10954 | branch to a different section, we mark it as such. If SEC is | |
10955 | NULL, and the frag is not marked, then it must be a branch to | |
10956 | the same section. */ | |
10957 | if (sec == NULL) | |
10958 | { | |
10959 | if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype)) | |
10960 | return 1; | |
10961 | } | |
10962 | else | |
10963 | { | |
10964 | if (symsec != sec) | |
10965 | { | |
10966 | fragp->fr_subtype = | |
10967 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
10968 | ||
10969 | /* FIXME: We should support this, and let the linker | |
10970 | catch branches and loads that are out of range. */ | |
10971 | as_bad_where (fragp->fr_file, fragp->fr_line, | |
10972 | _("unsupported PC relative reference to different section")); | |
10973 | ||
10974 | return 1; | |
10975 | } | |
10976 | } | |
10977 | ||
10978 | /* In this case, we know for sure that the symbol fragment is in | |
10979 | the same section. If the fr_address of the symbol fragment | |
10980 | is greater then the address of this fragment we want to add | |
10981 | in STRETCH in order to get a better estimate of the address. | |
10982 | This particularly matters because of the shift bits. */ | |
10983 | if (stretch != 0 | |
49309057 ILT |
10984 | && (symbol_get_frag (fragp->fr_symbol)->fr_address |
10985 | >= fragp->fr_address)) | |
252b5132 RH |
10986 | { |
10987 | fragS *f; | |
10988 | ||
10989 | /* Adjust stretch for any alignment frag. Note that if have | |
10990 | been expanding the earlier code, the symbol may be | |
10991 | defined in what appears to be an earlier frag. FIXME: | |
10992 | This doesn't handle the fr_subtype field, which specifies | |
10993 | a maximum number of bytes to skip when doing an | |
10994 | alignment. */ | |
10995 | for (f = fragp; | |
49309057 | 10996 | f != NULL && f != symbol_get_frag (fragp->fr_symbol); |
252b5132 RH |
10997 | f = f->fr_next) |
10998 | { | |
10999 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
11000 | { | |
11001 | if (stretch < 0) | |
11002 | stretch = - ((- stretch) | |
11003 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
11004 | else | |
11005 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
11006 | if (stretch == 0) | |
11007 | break; | |
11008 | } | |
11009 | } | |
11010 | if (f != NULL) | |
11011 | val += stretch; | |
11012 | } | |
11013 | ||
11014 | addr = fragp->fr_address + fragp->fr_fix; | |
11015 | ||
11016 | /* The base address rules are complicated. The base address of | |
11017 | a branch is the following instruction. The base address of a | |
11018 | PC relative load or add is the instruction itself, but if it | |
11019 | is in a delay slot (in which case it can not be extended) use | |
11020 | the address of the instruction whose delay slot it is in. */ | |
11021 | if (type == 'p' || type == 'q') | |
11022 | { | |
11023 | addr += 2; | |
11024 | ||
11025 | /* If we are currently assuming that this frag should be | |
11026 | extended, then, the current address is two bytes | |
bdaaa2e1 | 11027 | higher. */ |
252b5132 RH |
11028 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
11029 | addr += 2; | |
11030 | ||
11031 | /* Ignore the low bit in the target, since it will be set | |
11032 | for a text label. */ | |
11033 | if ((val & 1) != 0) | |
11034 | --val; | |
11035 | } | |
11036 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
11037 | addr -= 4; | |
11038 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
11039 | addr -= 2; | |
11040 | ||
11041 | val -= addr & ~ ((1 << op->shift) - 1); | |
11042 | ||
11043 | /* Branch offsets have an implicit 0 in the lowest bit. */ | |
11044 | if (type == 'p' || type == 'q') | |
11045 | val /= 2; | |
11046 | ||
11047 | /* If any of the shifted bits are set, we must use an extended | |
11048 | opcode. If the address depends on the size of this | |
11049 | instruction, this can lead to a loop, so we arrange to always | |
11050 | use an extended opcode. We only check this when we are in | |
11051 | the main relaxation loop, when SEC is NULL. */ | |
11052 | if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL) | |
11053 | { | |
11054 | fragp->fr_subtype = | |
11055 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11056 | return 1; | |
11057 | } | |
11058 | ||
11059 | /* If we are about to mark a frag as extended because the value | |
11060 | is precisely maxtiny + 1, then there is a chance of an | |
11061 | infinite loop as in the following code: | |
11062 | la $4,foo | |
11063 | .skip 1020 | |
11064 | .align 2 | |
11065 | foo: | |
11066 | In this case when the la is extended, foo is 0x3fc bytes | |
11067 | away, so the la can be shrunk, but then foo is 0x400 away, so | |
11068 | the la must be extended. To avoid this loop, we mark the | |
11069 | frag as extended if it was small, and is about to become | |
11070 | extended with a value of maxtiny + 1. */ | |
11071 | if (val == ((maxtiny + 1) << op->shift) | |
11072 | && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype) | |
11073 | && sec == NULL) | |
11074 | { | |
11075 | fragp->fr_subtype = | |
11076 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); | |
11077 | return 1; | |
11078 | } | |
11079 | } | |
11080 | else if (symsec != absolute_section && sec != NULL) | |
11081 | as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation")); | |
11082 | ||
11083 | if ((val & ((1 << op->shift) - 1)) != 0 | |
11084 | || val < (mintiny << op->shift) | |
11085 | || val > (maxtiny << op->shift)) | |
11086 | return 1; | |
11087 | else | |
11088 | return 0; | |
11089 | } | |
11090 | ||
11091 | /* Estimate the size of a frag before relaxing. Unless this is the | |
11092 | mips16, we are not really relaxing here, and the final size is | |
11093 | encoded in the subtype information. For the mips16, we have to | |
11094 | decide whether we are using an extended opcode or not. */ | |
11095 | ||
11096 | /*ARGSUSED*/ | |
11097 | int | |
11098 | md_estimate_size_before_relax (fragp, segtype) | |
11099 | fragS *fragp; | |
11100 | asection *segtype; | |
11101 | { | |
43841e91 | 11102 | int change = 0; |
8614eeee | 11103 | boolean linkonce = false; |
252b5132 RH |
11104 | |
11105 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
11106 | { | |
11107 | if (mips16_extended_frag (fragp, segtype, 0)) | |
11108 | { | |
11109 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
11110 | return 4; | |
11111 | } | |
11112 | else | |
11113 | { | |
11114 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
11115 | return 2; | |
11116 | } | |
11117 | } | |
11118 | ||
11119 | if (mips_pic == NO_PIC) | |
11120 | { | |
11121 | change = nopic_need_relax (fragp->fr_symbol, 0); | |
11122 | } | |
11123 | else if (mips_pic == SVR4_PIC) | |
11124 | { | |
11125 | symbolS *sym; | |
11126 | asection *symsec; | |
11127 | ||
11128 | sym = fragp->fr_symbol; | |
11129 | ||
11130 | /* Handle the case of a symbol equated to another symbol. */ | |
49309057 | 11131 | while (symbol_equated_p (sym) |
252b5132 RH |
11132 | && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) |
11133 | { | |
11134 | symbolS *n; | |
11135 | ||
11136 | /* It's possible to get a loop here in a badly written | |
11137 | program. */ | |
49309057 | 11138 | n = symbol_get_value_expression (sym)->X_add_symbol; |
252b5132 RH |
11139 | if (n == sym) |
11140 | break; | |
11141 | sym = n; | |
11142 | } | |
11143 | ||
11144 | symsec = S_GET_SEGMENT (sym); | |
11145 | ||
8614eeee UC |
11146 | /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */ |
11147 | if (symsec != segtype && ! S_IS_LOCAL (sym)) | |
11148 | { | |
11149 | if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) | |
11150 | != 0) | |
11151 | linkonce = true; | |
11152 | ||
11153 | /* The GNU toolchain uses an extension for ELF: a section | |
11154 | beginning with the magic string .gnu.linkonce is a linkonce | |
11155 | section. */ | |
11156 | if (strncmp (segment_name (symsec), ".gnu.linkonce", | |
11157 | sizeof ".gnu.linkonce" - 1) == 0) | |
11158 | linkonce = true; | |
11159 | } | |
11160 | ||
252b5132 RH |
11161 | /* This must duplicate the test in adjust_reloc_syms. */ |
11162 | change = (symsec != &bfd_und_section | |
11163 | && symsec != &bfd_abs_section | |
426b0403 | 11164 | && ! bfd_is_com_section (symsec) |
8614eeee | 11165 | && !linkonce |
426b0403 AM |
11166 | #ifdef OBJ_ELF |
11167 | /* A weak symbol is treated as external. */ | |
11168 | && ! S_IS_WEAK (sym) | |
11169 | #endif | |
11170 | ); | |
252b5132 RH |
11171 | } |
11172 | else | |
11173 | abort (); | |
11174 | ||
11175 | if (change) | |
11176 | { | |
11177 | /* Record the offset to the first reloc in the fr_opcode field. | |
11178 | This lets md_convert_frag and tc_gen_reloc know that the code | |
11179 | must be expanded. */ | |
11180 | fragp->fr_opcode = (fragp->fr_literal | |
11181 | + fragp->fr_fix | |
11182 | - RELAX_OLD (fragp->fr_subtype) | |
11183 | + RELAX_RELOC1 (fragp->fr_subtype)); | |
11184 | /* FIXME: This really needs as_warn_where. */ | |
11185 | if (RELAX_WARN (fragp->fr_subtype)) | |
11186 | as_warn (_("AT used after \".set noat\" or macro used after \".set nomacro\"")); | |
11187 | } | |
11188 | ||
11189 | if (! change) | |
11190 | return 0; | |
11191 | else | |
11192 | return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype); | |
11193 | } | |
11194 | ||
11195 | /* This is called to see whether a reloc against a defined symbol | |
11196 | should be converted into a reloc against a section. Don't adjust | |
11197 | MIPS16 jump relocations, so we don't have to worry about the format | |
11198 | of the offset in the .o file. Don't adjust relocations against | |
11199 | mips16 symbols, so that the linker can find them if it needs to set | |
11200 | up a stub. */ | |
11201 | ||
11202 | int | |
11203 | mips_fix_adjustable (fixp) | |
11204 | fixS *fixp; | |
11205 | { | |
11206 | if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP) | |
11207 | return 0; | |
11208 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
11209 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
11210 | return 0; | |
11211 | if (fixp->fx_addsy == NULL) | |
11212 | return 1; | |
11213 | #ifdef OBJ_ELF | |
11214 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour | |
11215 | && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16 | |
11216 | && fixp->fx_subsy == NULL) | |
11217 | return 0; | |
11218 | #endif | |
11219 | return 1; | |
11220 | } | |
11221 | ||
11222 | /* Translate internal representation of relocation info to BFD target | |
11223 | format. */ | |
11224 | ||
11225 | arelent ** | |
11226 | tc_gen_reloc (section, fixp) | |
43841e91 | 11227 | asection *section ATTRIBUTE_UNUSED; |
252b5132 RH |
11228 | fixS *fixp; |
11229 | { | |
11230 | static arelent *retval[4]; | |
11231 | arelent *reloc; | |
11232 | bfd_reloc_code_real_type code; | |
11233 | ||
11234 | reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent)); | |
11235 | retval[1] = NULL; | |
11236 | ||
49309057 ILT |
11237 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
11238 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
11239 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
11240 | ||
11241 | if (mips_pic == EMBEDDED_PIC | |
11242 | && SWITCH_TABLE (fixp)) | |
11243 | { | |
11244 | /* For a switch table entry we use a special reloc. The addend | |
11245 | is actually the difference between the reloc address and the | |
11246 | subtrahend. */ | |
11247 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); | |
11248 | if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour) | |
11249 | as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc")); | |
11250 | fixp->fx_r_type = BFD_RELOC_GPREL32; | |
11251 | } | |
bb2d6cd7 GK |
11252 | else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour) |
11253 | reloc->addend = fixp->fx_addnumber; | |
252b5132 RH |
11254 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16) |
11255 | { | |
11256 | /* We use a special addend for an internal RELLO reloc. */ | |
49309057 | 11257 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
11258 | reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy); |
11259 | else | |
11260 | reloc->addend = fixp->fx_addnumber + reloc->address; | |
11261 | } | |
11262 | else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S) | |
11263 | { | |
11264 | assert (fixp->fx_next != NULL | |
11265 | && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16); | |
11266 | /* We use a special addend for an internal RELHI reloc. The | |
11267 | reloc is relative to the RELLO; adjust the addend | |
11268 | accordingly. */ | |
49309057 | 11269 | if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
11270 | reloc->addend = (fixp->fx_next->fx_frag->fr_address |
11271 | + fixp->fx_next->fx_where | |
11272 | - S_GET_VALUE (fixp->fx_subsy)); | |
11273 | else | |
11274 | reloc->addend = (fixp->fx_addnumber | |
11275 | + fixp->fx_next->fx_frag->fr_address | |
11276 | + fixp->fx_next->fx_where); | |
11277 | } | |
252b5132 RH |
11278 | else |
11279 | { | |
11280 | if (OUTPUT_FLAVOR != bfd_target_aout_flavour) | |
11281 | /* A gruesome hack which is a result of the gruesome gas reloc | |
11282 | handling. */ | |
11283 | reloc->addend = reloc->address; | |
11284 | else | |
11285 | reloc->addend = -reloc->address; | |
11286 | } | |
11287 | ||
11288 | /* If this is a variant frag, we may need to adjust the existing | |
11289 | reloc and generate a new one. */ | |
11290 | if (fixp->fx_frag->fr_opcode != NULL | |
11291 | && (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL | |
11292 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16 | |
11293 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16 | |
11294 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
11295 | || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16 | |
11296 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
11297 | || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)) | |
11298 | { | |
11299 | arelent *reloc2; | |
11300 | ||
11301 | assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype)); | |
11302 | ||
11303 | /* If this is not the last reloc in this frag, then we have two | |
11304 | GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a | |
11305 | CALL_HI16/CALL_LO16, both of which are being replaced. Let | |
11306 | the second one handle all of them. */ | |
11307 | if (fixp->fx_next != NULL | |
11308 | && fixp->fx_frag == fixp->fx_next->fx_frag) | |
11309 | { | |
11310 | assert ((fixp->fx_r_type == BFD_RELOC_MIPS_GPREL | |
11311 | && fixp->fx_next->fx_r_type == BFD_RELOC_MIPS_GPREL) | |
11312 | || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16 | |
11313 | && (fixp->fx_next->fx_r_type | |
11314 | == BFD_RELOC_MIPS_GOT_LO16)) | |
11315 | || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16 | |
11316 | && (fixp->fx_next->fx_r_type | |
11317 | == BFD_RELOC_MIPS_CALL_LO16))); | |
11318 | retval[0] = NULL; | |
11319 | return retval; | |
11320 | } | |
11321 | ||
11322 | fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal; | |
11323 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
11324 | reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent)); | |
11325 | retval[2] = NULL; | |
49309057 ILT |
11326 | reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
11327 | *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
11328 | reloc2->address = (reloc->address |
11329 | + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype) | |
11330 | - RELAX_RELOC1 (fixp->fx_frag->fr_subtype))); | |
11331 | reloc2->addend = fixp->fx_addnumber; | |
11332 | reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16); | |
11333 | assert (reloc2->howto != NULL); | |
11334 | ||
11335 | if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype)) | |
11336 | { | |
11337 | arelent *reloc3; | |
11338 | ||
11339 | reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent)); | |
11340 | retval[3] = NULL; | |
11341 | *reloc3 = *reloc2; | |
11342 | reloc3->address += 4; | |
11343 | } | |
11344 | ||
11345 | if (mips_pic == NO_PIC) | |
11346 | { | |
11347 | assert (fixp->fx_r_type == BFD_RELOC_MIPS_GPREL); | |
11348 | fixp->fx_r_type = BFD_RELOC_HI16_S; | |
11349 | } | |
11350 | else if (mips_pic == SVR4_PIC) | |
11351 | { | |
11352 | switch (fixp->fx_r_type) | |
11353 | { | |
11354 | default: | |
11355 | abort (); | |
11356 | case BFD_RELOC_MIPS_GOT16: | |
11357 | break; | |
11358 | case BFD_RELOC_MIPS_CALL16: | |
11359 | case BFD_RELOC_MIPS_GOT_LO16: | |
11360 | case BFD_RELOC_MIPS_CALL_LO16: | |
11361 | fixp->fx_r_type = BFD_RELOC_MIPS_GOT16; | |
11362 | break; | |
11363 | } | |
11364 | } | |
11365 | else | |
11366 | abort (); | |
11367 | } | |
11368 | ||
11369 | /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry | |
11370 | to be used in the relocation's section offset. */ | |
11371 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
11372 | { | |
11373 | reloc->address = reloc->addend; | |
11374 | reloc->addend = 0; | |
11375 | } | |
11376 | ||
11377 | /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that | |
11378 | fixup_segment converted a non-PC relative reloc into a PC | |
11379 | relative reloc. In such a case, we need to convert the reloc | |
11380 | code. */ | |
11381 | code = fixp->fx_r_type; | |
11382 | if (fixp->fx_pcrel) | |
11383 | { | |
11384 | switch (code) | |
11385 | { | |
11386 | case BFD_RELOC_8: | |
11387 | code = BFD_RELOC_8_PCREL; | |
11388 | break; | |
11389 | case BFD_RELOC_16: | |
11390 | code = BFD_RELOC_16_PCREL; | |
11391 | break; | |
11392 | case BFD_RELOC_32: | |
11393 | code = BFD_RELOC_32_PCREL; | |
11394 | break; | |
11395 | case BFD_RELOC_64: | |
11396 | code = BFD_RELOC_64_PCREL; | |
11397 | break; | |
11398 | case BFD_RELOC_8_PCREL: | |
11399 | case BFD_RELOC_16_PCREL: | |
11400 | case BFD_RELOC_32_PCREL: | |
11401 | case BFD_RELOC_64_PCREL: | |
11402 | case BFD_RELOC_16_PCREL_S2: | |
11403 | case BFD_RELOC_PCREL_HI16_S: | |
11404 | case BFD_RELOC_PCREL_LO16: | |
11405 | break; | |
11406 | default: | |
11407 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
11408 | _("Cannot make %s relocation PC relative"), | |
11409 | bfd_get_reloc_code_name (code)); | |
11410 | } | |
11411 | } | |
11412 | ||
11413 | /* To support a PC relative reloc when generating embedded PIC code | |
11414 | for ECOFF, we use a Cygnus extension. We check for that here to | |
11415 | make sure that we don't let such a reloc escape normally. */ | |
bb2d6cd7 GK |
11416 | if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
11417 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
252b5132 RH |
11418 | && code == BFD_RELOC_16_PCREL_S2 |
11419 | && mips_pic != EMBEDDED_PIC) | |
11420 | reloc->howto = NULL; | |
11421 | else | |
11422 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
11423 | ||
11424 | if (reloc->howto == NULL) | |
11425 | { | |
11426 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
11427 | _("Can not represent %s relocation in this object file format"), | |
11428 | bfd_get_reloc_code_name (code)); | |
11429 | retval[0] = NULL; | |
11430 | } | |
11431 | ||
11432 | return retval; | |
11433 | } | |
11434 | ||
11435 | /* Relax a machine dependent frag. This returns the amount by which | |
11436 | the current size of the frag should change. */ | |
11437 | ||
11438 | int | |
11439 | mips_relax_frag (fragp, stretch) | |
11440 | fragS *fragp; | |
11441 | long stretch; | |
11442 | { | |
11443 | if (! RELAX_MIPS16_P (fragp->fr_subtype)) | |
11444 | return 0; | |
11445 | ||
11446 | if (mips16_extended_frag (fragp, (asection *) NULL, stretch)) | |
11447 | { | |
11448 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11449 | return 0; | |
11450 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); | |
11451 | return 2; | |
11452 | } | |
11453 | else | |
11454 | { | |
11455 | if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11456 | return 0; | |
11457 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); | |
11458 | return -2; | |
11459 | } | |
11460 | ||
11461 | return 0; | |
11462 | } | |
11463 | ||
11464 | /* Convert a machine dependent frag. */ | |
11465 | ||
11466 | void | |
11467 | md_convert_frag (abfd, asec, fragp) | |
43841e91 | 11468 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
11469 | segT asec; |
11470 | fragS *fragp; | |
11471 | { | |
11472 | int old, new; | |
11473 | char *fixptr; | |
11474 | ||
11475 | if (RELAX_MIPS16_P (fragp->fr_subtype)) | |
11476 | { | |
11477 | int type; | |
11478 | register const struct mips16_immed_operand *op; | |
11479 | boolean small, ext; | |
11480 | offsetT val; | |
11481 | bfd_byte *buf; | |
11482 | unsigned long insn; | |
11483 | boolean use_extend; | |
11484 | unsigned short extend; | |
11485 | ||
11486 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); | |
11487 | op = mips16_immed_operands; | |
11488 | while (op->type != type) | |
11489 | ++op; | |
11490 | ||
11491 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) | |
11492 | { | |
11493 | small = false; | |
11494 | ext = true; | |
11495 | } | |
11496 | else | |
11497 | { | |
11498 | small = true; | |
11499 | ext = false; | |
11500 | } | |
11501 | ||
11502 | resolve_symbol_value (fragp->fr_symbol, 1); | |
11503 | val = S_GET_VALUE (fragp->fr_symbol); | |
11504 | if (op->pcrel) | |
11505 | { | |
11506 | addressT addr; | |
11507 | ||
11508 | addr = fragp->fr_address + fragp->fr_fix; | |
11509 | ||
11510 | /* The rules for the base address of a PC relative reloc are | |
11511 | complicated; see mips16_extended_frag. */ | |
11512 | if (type == 'p' || type == 'q') | |
11513 | { | |
11514 | addr += 2; | |
11515 | if (ext) | |
11516 | addr += 2; | |
11517 | /* Ignore the low bit in the target, since it will be | |
11518 | set for a text label. */ | |
11519 | if ((val & 1) != 0) | |
11520 | --val; | |
11521 | } | |
11522 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) | |
11523 | addr -= 4; | |
11524 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) | |
11525 | addr -= 2; | |
11526 | ||
11527 | addr &= ~ (addressT) ((1 << op->shift) - 1); | |
11528 | val -= addr; | |
11529 | ||
11530 | /* Make sure the section winds up with the alignment we have | |
11531 | assumed. */ | |
11532 | if (op->shift > 0) | |
11533 | record_alignment (asec, op->shift); | |
11534 | } | |
11535 | ||
11536 | if (ext | |
11537 | && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype) | |
11538 | || RELAX_MIPS16_DSLOT (fragp->fr_subtype))) | |
11539 | as_warn_where (fragp->fr_file, fragp->fr_line, | |
11540 | _("extended instruction in delay slot")); | |
11541 | ||
11542 | buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix); | |
11543 | ||
11544 | if (target_big_endian) | |
11545 | insn = bfd_getb16 (buf); | |
11546 | else | |
11547 | insn = bfd_getl16 (buf); | |
11548 | ||
11549 | mips16_immed (fragp->fr_file, fragp->fr_line, type, val, | |
11550 | RELAX_MIPS16_USER_EXT (fragp->fr_subtype), | |
11551 | small, ext, &insn, &use_extend, &extend); | |
11552 | ||
11553 | if (use_extend) | |
11554 | { | |
11555 | md_number_to_chars (buf, 0xf000 | extend, 2); | |
11556 | fragp->fr_fix += 2; | |
11557 | buf += 2; | |
11558 | } | |
11559 | ||
11560 | md_number_to_chars (buf, insn, 2); | |
11561 | fragp->fr_fix += 2; | |
11562 | buf += 2; | |
11563 | } | |
11564 | else | |
11565 | { | |
11566 | if (fragp->fr_opcode == NULL) | |
11567 | return; | |
11568 | ||
11569 | old = RELAX_OLD (fragp->fr_subtype); | |
11570 | new = RELAX_NEW (fragp->fr_subtype); | |
11571 | fixptr = fragp->fr_literal + fragp->fr_fix; | |
11572 | ||
11573 | if (new > 0) | |
11574 | memcpy (fixptr - old, fixptr, new); | |
11575 | ||
11576 | fragp->fr_fix += new - old; | |
11577 | } | |
11578 | } | |
11579 | ||
11580 | #ifdef OBJ_ELF | |
11581 | ||
11582 | /* This function is called after the relocs have been generated. | |
11583 | We've been storing mips16 text labels as odd. Here we convert them | |
11584 | back to even for the convenience of the debugger. */ | |
11585 | ||
11586 | void | |
11587 | mips_frob_file_after_relocs () | |
11588 | { | |
11589 | asymbol **syms; | |
11590 | unsigned int count, i; | |
11591 | ||
11592 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) | |
11593 | return; | |
11594 | ||
11595 | syms = bfd_get_outsymbols (stdoutput); | |
11596 | count = bfd_get_symcount (stdoutput); | |
11597 | for (i = 0; i < count; i++, syms++) | |
11598 | { | |
11599 | if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16 | |
11600 | && ((*syms)->value & 1) != 0) | |
11601 | { | |
11602 | (*syms)->value &= ~1; | |
11603 | /* If the symbol has an odd size, it was probably computed | |
11604 | incorrectly, so adjust that as well. */ | |
11605 | if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0) | |
11606 | ++elf_symbol (*syms)->internal_elf_sym.st_size; | |
11607 | } | |
11608 | } | |
11609 | } | |
11610 | ||
11611 | #endif | |
11612 | ||
11613 | /* This function is called whenever a label is defined. It is used | |
11614 | when handling branch delays; if a branch has a label, we assume we | |
11615 | can not move it. */ | |
11616 | ||
11617 | void | |
11618 | mips_define_label (sym) | |
11619 | symbolS *sym; | |
11620 | { | |
11621 | struct insn_label_list *l; | |
11622 | ||
11623 | if (free_insn_labels == NULL) | |
11624 | l = (struct insn_label_list *) xmalloc (sizeof *l); | |
11625 | else | |
11626 | { | |
11627 | l = free_insn_labels; | |
11628 | free_insn_labels = l->next; | |
11629 | } | |
11630 | ||
11631 | l->label = sym; | |
11632 | l->next = insn_labels; | |
11633 | insn_labels = l; | |
11634 | } | |
11635 | \f | |
11636 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) | |
11637 | ||
11638 | /* Some special processing for a MIPS ELF file. */ | |
11639 | ||
11640 | void | |
11641 | mips_elf_final_processing () | |
11642 | { | |
11643 | /* Write out the register information. */ | |
11644 | if (! mips_64) | |
11645 | { | |
11646 | Elf32_RegInfo s; | |
11647 | ||
11648 | s.ri_gprmask = mips_gprmask; | |
11649 | s.ri_cprmask[0] = mips_cprmask[0]; | |
11650 | s.ri_cprmask[1] = mips_cprmask[1]; | |
11651 | s.ri_cprmask[2] = mips_cprmask[2]; | |
11652 | s.ri_cprmask[3] = mips_cprmask[3]; | |
11653 | /* The gp_value field is set by the MIPS ELF backend. */ | |
11654 | ||
11655 | bfd_mips_elf32_swap_reginfo_out (stdoutput, &s, | |
11656 | ((Elf32_External_RegInfo *) | |
11657 | mips_regmask_frag)); | |
11658 | } | |
11659 | else | |
11660 | { | |
11661 | Elf64_Internal_RegInfo s; | |
11662 | ||
11663 | s.ri_gprmask = mips_gprmask; | |
11664 | s.ri_pad = 0; | |
11665 | s.ri_cprmask[0] = mips_cprmask[0]; | |
11666 | s.ri_cprmask[1] = mips_cprmask[1]; | |
11667 | s.ri_cprmask[2] = mips_cprmask[2]; | |
11668 | s.ri_cprmask[3] = mips_cprmask[3]; | |
11669 | /* The gp_value field is set by the MIPS ELF backend. */ | |
11670 | ||
11671 | bfd_mips_elf64_swap_reginfo_out (stdoutput, &s, | |
11672 | ((Elf64_External_RegInfo *) | |
11673 | mips_regmask_frag)); | |
11674 | } | |
11675 | ||
11676 | /* Set the MIPS ELF flag bits. FIXME: There should probably be some | |
11677 | sort of BFD interface for this. */ | |
11678 | if (mips_any_noreorder) | |
11679 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER; | |
11680 | if (mips_pic != NO_PIC) | |
11681 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC; | |
11682 | ||
bdaaa2e1 | 11683 | /* Set the MIPS ELF ABI flags. */ |
252b5132 RH |
11684 | if (mips_abi_string == 0) |
11685 | ; | |
11686 | else if (strcmp (mips_abi_string,"32") == 0) | |
11687 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32; | |
11688 | else if (strcmp (mips_abi_string,"o64") == 0) | |
11689 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64; | |
11690 | else if (strcmp (mips_abi_string,"eabi") == 0) | |
11691 | { | |
11692 | if (mips_eabi64) | |
11693 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64; | |
11694 | else | |
11695 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32; | |
11696 | } | |
11697 | ||
11698 | if (mips_32bitmode) | |
11699 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE; | |
11700 | } | |
11701 | ||
11702 | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ | |
11703 | \f | |
11704 | typedef struct proc | |
11705 | { | |
49309057 | 11706 | symbolS *isym; |
252b5132 RH |
11707 | unsigned long reg_mask; |
11708 | unsigned long reg_offset; | |
11709 | unsigned long fpreg_mask; | |
11710 | unsigned long fpreg_offset; | |
11711 | unsigned long frame_offset; | |
11712 | unsigned long frame_reg; | |
11713 | unsigned long pc_reg; | |
11714 | } | |
11715 | procS; | |
11716 | ||
11717 | static procS cur_proc; | |
11718 | static procS *cur_proc_ptr; | |
11719 | static int numprocs; | |
11720 | ||
a19d8eb0 CP |
11721 | /* When we align code in the .text section of mips16, use the correct two |
11722 | byte nop pattern of 0x6500 (move $0,$0) */ | |
11723 | ||
11724 | int | |
11725 | mips_do_align (n, fill, len, max) | |
11726 | int n; | |
11727 | const char *fill; | |
43841e91 | 11728 | int len ATTRIBUTE_UNUSED; |
a19d8eb0 CP |
11729 | int max; |
11730 | { | |
11731 | if (fill == NULL | |
11732 | && subseg_text_p (now_seg) | |
11733 | && n > 1 | |
11734 | && mips_opts.mips16) | |
11735 | { | |
11736 | static const unsigned char be_nop[] = { 0x65, 0x00 }; | |
11737 | static const unsigned char le_nop[] = { 0x00, 0x65 }; | |
11738 | ||
11739 | frag_align (1, 0, 0); | |
11740 | ||
11741 | if (target_big_endian) | |
bdaaa2e1 | 11742 | frag_align_pattern (n, be_nop, 2, max); |
a19d8eb0 | 11743 | else |
bdaaa2e1 | 11744 | frag_align_pattern (n, le_nop, 2, max); |
a19d8eb0 CP |
11745 | return 1; |
11746 | } | |
11747 | ||
11748 | return 0; | |
11749 | } | |
11750 | ||
252b5132 RH |
11751 | static void |
11752 | md_obj_begin () | |
11753 | { | |
11754 | } | |
11755 | ||
11756 | static void | |
11757 | md_obj_end () | |
11758 | { | |
11759 | /* check for premature end, nesting errors, etc */ | |
11760 | if (cur_proc_ptr) | |
11761 | as_warn (_("missing `.end' at end of assembly")); | |
11762 | } | |
11763 | ||
11764 | static long | |
11765 | get_number () | |
11766 | { | |
11767 | int negative = 0; | |
11768 | long val = 0; | |
11769 | ||
11770 | if (*input_line_pointer == '-') | |
11771 | { | |
11772 | ++input_line_pointer; | |
11773 | negative = 1; | |
11774 | } | |
d9a62219 | 11775 | if (!isdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11776 | as_bad (_("Expected simple number.")); |
11777 | if (input_line_pointer[0] == '0') | |
11778 | { | |
11779 | if (input_line_pointer[1] == 'x') | |
11780 | { | |
11781 | input_line_pointer += 2; | |
d9a62219 | 11782 | while (isxdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11783 | { |
11784 | val <<= 4; | |
11785 | val |= hex_value (*input_line_pointer++); | |
11786 | } | |
11787 | return negative ? -val : val; | |
11788 | } | |
11789 | else | |
11790 | { | |
11791 | ++input_line_pointer; | |
d9a62219 | 11792 | while (isdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11793 | { |
11794 | val <<= 3; | |
11795 | val |= *input_line_pointer++ - '0'; | |
11796 | } | |
11797 | return negative ? -val : val; | |
11798 | } | |
11799 | } | |
d9a62219 | 11800 | if (!isdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11801 | { |
11802 | printf (_(" *input_line_pointer == '%c' 0x%02x\n"), | |
11803 | *input_line_pointer, *input_line_pointer); | |
11804 | as_warn (_("Invalid number")); | |
11805 | return -1; | |
11806 | } | |
d9a62219 | 11807 | while (isdigit ((unsigned char) *input_line_pointer)) |
252b5132 RH |
11808 | { |
11809 | val *= 10; | |
11810 | val += *input_line_pointer++ - '0'; | |
11811 | } | |
11812 | return negative ? -val : val; | |
11813 | } | |
11814 | ||
11815 | /* The .file directive; just like the usual .file directive, but there | |
11816 | is an initial number which is the ECOFF file index. */ | |
11817 | ||
11818 | static void | |
11819 | s_file (x) | |
43841e91 | 11820 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11821 | { |
11822 | int line; | |
11823 | ||
11824 | line = get_number (); | |
11825 | s_app_file (0); | |
11826 | } | |
11827 | ||
252b5132 RH |
11828 | /* The .end directive. */ |
11829 | ||
11830 | static void | |
11831 | s_mips_end (x) | |
43841e91 | 11832 | int x ATTRIBUTE_UNUSED; |
252b5132 RH |
11833 | { |
11834 | symbolS *p; | |
11835 | int maybe_text; | |
11836 | ||
11837 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
11838 | { | |
11839 | p = get_symbol (); | |
11840 | demand_empty_rest_of_line (); | |
11841 | } | |
11842 | else | |
11843 | p = NULL; | |
11844 | ||
11845 | #ifdef BFD_ASSEMBLER | |
11846 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
11847 | maybe_text = 1; | |
11848 | else | |
11849 | maybe_text = 0; | |
11850 | #else | |
11851 | if (now_seg != data_section && now_seg != bss_section) | |
11852 | maybe_text = 1; | |
11853 | else | |
11854 | maybe_text = 0; | |
11855 | #endif | |
11856 | ||
11857 | if (!maybe_text) | |
11858 | as_warn (_(".end not in text section")); | |
11859 | ||
11860 | if (!cur_proc_ptr) | |
11861 | { | |
11862 | as_warn (_(".end directive without a preceding .ent directive.")); | |
11863 | demand_empty_rest_of_line (); | |
11864 | return; | |
11865 | } | |
11866 | ||
11867 | if (p != NULL) | |
11868 | { | |
11869 | assert (S_GET_NAME (p)); | |
11870 | if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym))) | |
11871 | as_warn (_(".end symbol does not match .ent symbol.")); | |
11872 | } | |
11873 | else | |
11874 | as_warn (_(".end directive missing or unknown symbol")); | |
11875 | ||
11876 | #ifdef MIPS_STABS_ELF | |
11877 | { | |
11878 | segT saved_seg = now_seg; | |
11879 | subsegT saved_subseg = now_subseg; | |
11880 | fragS *saved_frag = frag_now; | |
11881 | valueT dot; | |
11882 | segT seg; | |
11883 | expressionS exp; | |
11884 | char *fragp; | |
11885 | ||
11886 | dot = frag_now_fix (); | |
11887 | ||
11888 | #ifdef md_flush_pending_output | |
11889 | md_flush_pending_output (); | |
11890 | #endif | |
11891 | ||
11892 | assert (pdr_seg); | |
11893 | subseg_set (pdr_seg, 0); | |
11894 | ||
11895 | /* Write the symbol */ | |
11896 | exp.X_op = O_symbol; | |
11897 | exp.X_add_symbol = p; | |
11898 | exp.X_add_number = 0; | |
11899 | emit_expr (&exp, 4); | |
11900 | ||
11901 | fragp = frag_more (7*4); | |
11902 | ||
11903 | md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4); | |
11904 | md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4); | |
11905 | md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4); | |
11906 | md_number_to_chars (fragp +12, (valueT) cur_proc_ptr->fpreg_offset, 4); | |
11907 | md_number_to_chars (fragp +16, (valueT) cur_proc_ptr->frame_offset, 4); | |
11908 | md_number_to_chars (fragp +20, (valueT) cur_proc_ptr->frame_reg, 4); | |
11909 | md_number_to_chars (fragp +24, (valueT) cur_proc_ptr->pc_reg, 4); | |
11910 | ||
11911 | subseg_set (saved_seg, saved_subseg); | |
11912 | } | |
11913 | #endif | |
11914 | ||
11915 | cur_proc_ptr = NULL; | |
11916 | } | |
11917 | ||
11918 | /* The .aent and .ent directives. */ | |
11919 | ||
11920 | static void | |
11921 | s_mips_ent (aent) | |
11922 | int aent; | |
11923 | { | |
11924 | int number = 0; | |
11925 | symbolS *symbolP; | |
11926 | int maybe_text; | |
11927 | ||
11928 | symbolP = get_symbol (); | |
11929 | if (*input_line_pointer == ',') | |
11930 | input_line_pointer++; | |
11931 | SKIP_WHITESPACE (); | |
d9a62219 DE |
11932 | if (isdigit ((unsigned char) *input_line_pointer) |
11933 | || *input_line_pointer == '-') | |
252b5132 RH |
11934 | number = get_number (); |
11935 | ||
11936 | #ifdef BFD_ASSEMBLER | |
11937 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
11938 | maybe_text = 1; | |
11939 | else | |
11940 | maybe_text = 0; | |
11941 | #else | |
11942 | if (now_seg != data_section && now_seg != bss_section) | |
11943 | maybe_text = 1; | |
11944 | else | |
11945 | maybe_text = 0; | |
11946 | #endif | |
11947 | ||
11948 | if (!maybe_text) | |
11949 | as_warn (_(".ent or .aent not in text section.")); | |
11950 | ||
11951 | if (!aent && cur_proc_ptr) | |
11952 | as_warn (_("missing `.end'")); | |
11953 | ||
11954 | if (!aent) | |
11955 | { | |
11956 | cur_proc_ptr = &cur_proc; | |
11957 | memset (cur_proc_ptr, '\0', sizeof (procS)); | |
11958 | ||
11959 | cur_proc_ptr->isym = symbolP; | |
11960 | ||
49309057 | 11961 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
11962 | |
11963 | numprocs++; | |
11964 | } | |
11965 | ||
11966 | demand_empty_rest_of_line (); | |
11967 | } | |
11968 | ||
11969 | /* The .frame directive. If the mdebug section is present (IRIX 5 native) | |
bdaaa2e1 | 11970 | then ecoff.c (ecoff_directive_frame) is used. For embedded targets, |
252b5132 | 11971 | s_mips_frame is used so that we can set the PDR information correctly. |
bdaaa2e1 | 11972 | We can't use the ecoff routines because they make reference to the ecoff |
252b5132 RH |
11973 | symbol table (in the mdebug section). */ |
11974 | ||
11975 | static void | |
11976 | s_mips_frame (ignore) | |
11977 | int ignore; | |
11978 | { | |
11979 | #ifdef MIPS_STABS_ELF | |
11980 | ||
11981 | long val; | |
11982 | ||
11983 | if (cur_proc_ptr == (procS *) NULL) | |
11984 | { | |
11985 | as_warn (_(".frame outside of .ent")); | |
11986 | demand_empty_rest_of_line (); | |
11987 | return; | |
11988 | } | |
11989 | ||
11990 | cur_proc_ptr->frame_reg = tc_get_register (1); | |
11991 | ||
11992 | SKIP_WHITESPACE (); | |
11993 | if (*input_line_pointer++ != ',' | |
11994 | || get_absolute_expression_and_terminator (&val) != ',') | |
11995 | { | |
11996 | as_warn (_("Bad .frame directive")); | |
11997 | --input_line_pointer; | |
11998 | demand_empty_rest_of_line (); | |
11999 | return; | |
12000 | } | |
12001 | ||
12002 | cur_proc_ptr->frame_offset = val; | |
12003 | cur_proc_ptr->pc_reg = tc_get_register (0); | |
12004 | ||
12005 | demand_empty_rest_of_line (); | |
12006 | #else | |
12007 | s_ignore (ignore); | |
12008 | #endif /* MIPS_STABS_ELF */ | |
12009 | } | |
12010 | ||
bdaaa2e1 KH |
12011 | /* The .fmask and .mask directives. If the mdebug section is present |
12012 | (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For | |
252b5132 | 12013 | embedded targets, s_mips_mask is used so that we can set the PDR |
bdaaa2e1 | 12014 | information correctly. We can't use the ecoff routines because they |
252b5132 RH |
12015 | make reference to the ecoff symbol table (in the mdebug section). */ |
12016 | ||
12017 | static void | |
12018 | s_mips_mask (reg_type) | |
12019 | char reg_type; | |
12020 | { | |
12021 | #ifdef MIPS_STABS_ELF | |
12022 | long mask, off; | |
bdaaa2e1 | 12023 | |
252b5132 RH |
12024 | if (cur_proc_ptr == (procS *) NULL) |
12025 | { | |
12026 | as_warn (_(".mask/.fmask outside of .ent")); | |
12027 | demand_empty_rest_of_line (); | |
12028 | return; | |
12029 | } | |
12030 | ||
12031 | if (get_absolute_expression_and_terminator (&mask) != ',') | |
12032 | { | |
12033 | as_warn (_("Bad .mask/.fmask directive")); | |
12034 | --input_line_pointer; | |
12035 | demand_empty_rest_of_line (); | |
12036 | return; | |
12037 | } | |
12038 | ||
12039 | off = get_absolute_expression (); | |
12040 | ||
12041 | if (reg_type == 'F') | |
12042 | { | |
12043 | cur_proc_ptr->fpreg_mask = mask; | |
12044 | cur_proc_ptr->fpreg_offset = off; | |
12045 | } | |
12046 | else | |
12047 | { | |
12048 | cur_proc_ptr->reg_mask = mask; | |
12049 | cur_proc_ptr->reg_offset = off; | |
12050 | } | |
12051 | ||
12052 | demand_empty_rest_of_line (); | |
12053 | #else | |
12054 | s_ignore (reg_type); | |
12055 | #endif /* MIPS_STABS_ELF */ | |
12056 | } | |
12057 | ||
12058 | /* The .loc directive. */ | |
12059 | ||
12060 | #if 0 | |
12061 | static void | |
12062 | s_loc (x) | |
12063 | int x; | |
12064 | { | |
12065 | symbolS *symbolP; | |
12066 | int lineno; | |
12067 | int addroff; | |
12068 | ||
12069 | assert (now_seg == text_section); | |
12070 | ||
12071 | lineno = get_number (); | |
12072 | addroff = frag_now_fix (); | |
12073 | ||
12074 | symbolP = symbol_new ("", N_SLINE, addroff, frag_now); | |
12075 | S_SET_TYPE (symbolP, N_SLINE); | |
12076 | S_SET_OTHER (symbolP, 0); | |
12077 | S_SET_DESC (symbolP, lineno); | |
12078 | symbolP->sy_segment = now_seg; | |
12079 | } | |
12080 | #endif |