| 1 | /* tc-mips.c -- assemble code for a MIPS chip. |
| 2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
| 3 | 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
| 4 | Free Software Foundation, Inc. |
| 5 | Contributed by the OSF and Ralph Campbell. |
| 6 | Written by Keith Knowles and Ralph Campbell, working independently. |
| 7 | Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus |
| 8 | Support. |
| 9 | |
| 10 | This file is part of GAS. |
| 11 | |
| 12 | GAS is free software; you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation; either version 3, or (at your option) |
| 15 | any later version. |
| 16 | |
| 17 | GAS is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with GAS; see the file COPYING. If not, write to the Free |
| 24 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
| 25 | 02110-1301, USA. */ |
| 26 | |
| 27 | #include "as.h" |
| 28 | #include "config.h" |
| 29 | #include "subsegs.h" |
| 30 | #include "safe-ctype.h" |
| 31 | |
| 32 | #include "opcode/mips.h" |
| 33 | #include "itbl-ops.h" |
| 34 | #include "dwarf2dbg.h" |
| 35 | #include "dw2gencfi.h" |
| 36 | |
| 37 | #ifdef DEBUG |
| 38 | #define DBG(x) printf x |
| 39 | #else |
| 40 | #define DBG(x) |
| 41 | #endif |
| 42 | |
| 43 | #ifdef OBJ_MAYBE_ELF |
| 44 | /* Clean up namespace so we can include obj-elf.h too. */ |
| 45 | static int mips_output_flavor (void); |
| 46 | static int mips_output_flavor (void) { return OUTPUT_FLAVOR; } |
| 47 | #undef OBJ_PROCESS_STAB |
| 48 | #undef OUTPUT_FLAVOR |
| 49 | #undef S_GET_ALIGN |
| 50 | #undef S_GET_SIZE |
| 51 | #undef S_SET_ALIGN |
| 52 | #undef S_SET_SIZE |
| 53 | #undef obj_frob_file |
| 54 | #undef obj_frob_file_after_relocs |
| 55 | #undef obj_frob_symbol |
| 56 | #undef obj_pop_insert |
| 57 | #undef obj_sec_sym_ok_for_reloc |
| 58 | #undef OBJ_COPY_SYMBOL_ATTRIBUTES |
| 59 | |
| 60 | #include "obj-elf.h" |
| 61 | /* Fix any of them that we actually care about. */ |
| 62 | #undef OUTPUT_FLAVOR |
| 63 | #define OUTPUT_FLAVOR mips_output_flavor() |
| 64 | #endif |
| 65 | |
| 66 | #if defined (OBJ_ELF) |
| 67 | #include "elf/mips.h" |
| 68 | #endif |
| 69 | |
| 70 | #ifndef ECOFF_DEBUGGING |
| 71 | #define NO_ECOFF_DEBUGGING |
| 72 | #define ECOFF_DEBUGGING 0 |
| 73 | #endif |
| 74 | |
| 75 | int mips_flag_mdebug = -1; |
| 76 | |
| 77 | /* Control generation of .pdr sections. Off by default on IRIX: the native |
| 78 | linker doesn't know about and discards them, but relocations against them |
| 79 | remain, leading to rld crashes. */ |
| 80 | #ifdef TE_IRIX |
| 81 | int mips_flag_pdr = FALSE; |
| 82 | #else |
| 83 | int mips_flag_pdr = TRUE; |
| 84 | #endif |
| 85 | |
| 86 | #include "ecoff.h" |
| 87 | |
| 88 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
| 89 | static char *mips_regmask_frag; |
| 90 | #endif |
| 91 | |
| 92 | #define ZERO 0 |
| 93 | #define ATREG 1 |
| 94 | #define S0 16 |
| 95 | #define S7 23 |
| 96 | #define TREG 24 |
| 97 | #define PIC_CALL_REG 25 |
| 98 | #define KT0 26 |
| 99 | #define KT1 27 |
| 100 | #define GP 28 |
| 101 | #define SP 29 |
| 102 | #define FP 30 |
| 103 | #define RA 31 |
| 104 | |
| 105 | #define ILLEGAL_REG (32) |
| 106 | |
| 107 | #define AT mips_opts.at |
| 108 | |
| 109 | /* Allow override of standard little-endian ECOFF format. */ |
| 110 | |
| 111 | #ifndef ECOFF_LITTLE_FORMAT |
| 112 | #define ECOFF_LITTLE_FORMAT "ecoff-littlemips" |
| 113 | #endif |
| 114 | |
| 115 | extern int target_big_endian; |
| 116 | |
| 117 | /* The name of the readonly data section. */ |
| 118 | #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \ |
| 119 | ? ".rdata" \ |
| 120 | : OUTPUT_FLAVOR == bfd_target_coff_flavour \ |
| 121 | ? ".rdata" \ |
| 122 | : OUTPUT_FLAVOR == bfd_target_elf_flavour \ |
| 123 | ? ".rodata" \ |
| 124 | : (abort (), "")) |
| 125 | |
| 126 | /* Ways in which an instruction can be "appended" to the output. */ |
| 127 | enum append_method { |
| 128 | /* Just add it normally. */ |
| 129 | APPEND_ADD, |
| 130 | |
| 131 | /* Add it normally and then add a nop. */ |
| 132 | APPEND_ADD_WITH_NOP, |
| 133 | |
| 134 | /* Turn an instruction with a delay slot into a "compact" version. */ |
| 135 | APPEND_ADD_COMPACT, |
| 136 | |
| 137 | /* Insert the instruction before the last one. */ |
| 138 | APPEND_SWAP |
| 139 | }; |
| 140 | |
| 141 | /* Information about an instruction, including its format, operands |
| 142 | and fixups. */ |
| 143 | struct mips_cl_insn |
| 144 | { |
| 145 | /* The opcode's entry in mips_opcodes or mips16_opcodes. */ |
| 146 | const struct mips_opcode *insn_mo; |
| 147 | |
| 148 | /* The 16-bit or 32-bit bitstring of the instruction itself. This is |
| 149 | a copy of INSN_MO->match with the operands filled in. If we have |
| 150 | decided to use an extended MIPS16 instruction, this includes the |
| 151 | extension. */ |
| 152 | unsigned long insn_opcode; |
| 153 | |
| 154 | /* The frag that contains the instruction. */ |
| 155 | struct frag *frag; |
| 156 | |
| 157 | /* The offset into FRAG of the first instruction byte. */ |
| 158 | long where; |
| 159 | |
| 160 | /* The relocs associated with the instruction, if any. */ |
| 161 | fixS *fixp[3]; |
| 162 | |
| 163 | /* True if this entry cannot be moved from its current position. */ |
| 164 | unsigned int fixed_p : 1; |
| 165 | |
| 166 | /* True if this instruction occurred in a .set noreorder block. */ |
| 167 | unsigned int noreorder_p : 1; |
| 168 | |
| 169 | /* True for mips16 instructions that jump to an absolute address. */ |
| 170 | unsigned int mips16_absolute_jump_p : 1; |
| 171 | |
| 172 | /* True if this instruction is complete. */ |
| 173 | unsigned int complete_p : 1; |
| 174 | }; |
| 175 | |
| 176 | /* The ABI to use. */ |
| 177 | enum mips_abi_level |
| 178 | { |
| 179 | NO_ABI = 0, |
| 180 | O32_ABI, |
| 181 | O64_ABI, |
| 182 | N32_ABI, |
| 183 | N64_ABI, |
| 184 | EABI_ABI |
| 185 | }; |
| 186 | |
| 187 | /* MIPS ABI we are using for this output file. */ |
| 188 | static enum mips_abi_level mips_abi = NO_ABI; |
| 189 | |
| 190 | /* Whether or not we have code that can call pic code. */ |
| 191 | int mips_abicalls = FALSE; |
| 192 | |
| 193 | /* Whether or not we have code which can be put into a shared |
| 194 | library. */ |
| 195 | static bfd_boolean mips_in_shared = TRUE; |
| 196 | |
| 197 | /* This is the set of options which may be modified by the .set |
| 198 | pseudo-op. We use a struct so that .set push and .set pop are more |
| 199 | reliable. */ |
| 200 | |
| 201 | struct mips_set_options |
| 202 | { |
| 203 | /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 |
| 204 | if it has not been initialized. Changed by `.set mipsN', and the |
| 205 | -mipsN command line option, and the default CPU. */ |
| 206 | int isa; |
| 207 | /* Enabled Application Specific Extensions (ASEs). These are set to -1 |
| 208 | if they have not been initialized. Changed by `.set <asename>', by |
| 209 | command line options, and based on the default architecture. */ |
| 210 | int ase_mips3d; |
| 211 | int ase_mdmx; |
| 212 | int ase_smartmips; |
| 213 | int ase_dsp; |
| 214 | int ase_dspr2; |
| 215 | int ase_mt; |
| 216 | int ase_mcu; |
| 217 | /* Whether we are assembling for the mips16 processor. 0 if we are |
| 218 | not, 1 if we are, and -1 if the value has not been initialized. |
| 219 | Changed by `.set mips16' and `.set nomips16', and the -mips16 and |
| 220 | -nomips16 command line options, and the default CPU. */ |
| 221 | int mips16; |
| 222 | /* Whether we are assembling for the mipsMIPS ASE. 0 if we are not, |
| 223 | 1 if we are, and -1 if the value has not been initialized. Changed |
| 224 | by `.set micromips' and `.set nomicromips', and the -mmicromips |
| 225 | and -mno-micromips command line options, and the default CPU. */ |
| 226 | int micromips; |
| 227 | /* Non-zero if we should not reorder instructions. Changed by `.set |
| 228 | reorder' and `.set noreorder'. */ |
| 229 | int noreorder; |
| 230 | /* Non-zero if we should not permit the register designated "assembler |
| 231 | temporary" to be used in instructions. The value is the register |
| 232 | number, normally $at ($1). Changed by `.set at=REG', `.set noat' |
| 233 | (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */ |
| 234 | unsigned int at; |
| 235 | /* Non-zero if we should warn when a macro instruction expands into |
| 236 | more than one machine instruction. Changed by `.set nomacro' and |
| 237 | `.set macro'. */ |
| 238 | int warn_about_macros; |
| 239 | /* Non-zero if we should not move instructions. Changed by `.set |
| 240 | move', `.set volatile', `.set nomove', and `.set novolatile'. */ |
| 241 | int nomove; |
| 242 | /* Non-zero if we should not optimize branches by moving the target |
| 243 | of the branch into the delay slot. Actually, we don't perform |
| 244 | this optimization anyhow. Changed by `.set bopt' and `.set |
| 245 | nobopt'. */ |
| 246 | int nobopt; |
| 247 | /* Non-zero if we should not autoextend mips16 instructions. |
| 248 | Changed by `.set autoextend' and `.set noautoextend'. */ |
| 249 | int noautoextend; |
| 250 | /* Restrict general purpose registers and floating point registers |
| 251 | to 32 bit. This is initially determined when -mgp32 or -mfp32 |
| 252 | is passed but can changed if the assembler code uses .set mipsN. */ |
| 253 | int gp32; |
| 254 | int fp32; |
| 255 | /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march |
| 256 | command line option, and the default CPU. */ |
| 257 | int arch; |
| 258 | /* True if ".set sym32" is in effect. */ |
| 259 | bfd_boolean sym32; |
| 260 | /* True if floating-point operations are not allowed. Changed by .set |
| 261 | softfloat or .set hardfloat, by command line options -msoft-float or |
| 262 | -mhard-float. The default is false. */ |
| 263 | bfd_boolean soft_float; |
| 264 | |
| 265 | /* True if only single-precision floating-point operations are allowed. |
| 266 | Changed by .set singlefloat or .set doublefloat, command-line options |
| 267 | -msingle-float or -mdouble-float. The default is false. */ |
| 268 | bfd_boolean single_float; |
| 269 | }; |
| 270 | |
| 271 | /* This is the struct we use to hold the current set of options. Note |
| 272 | that we must set the isa field to ISA_UNKNOWN and the ASE fields to |
| 273 | -1 to indicate that they have not been initialized. */ |
| 274 | |
| 275 | /* True if -mgp32 was passed. */ |
| 276 | static int file_mips_gp32 = -1; |
| 277 | |
| 278 | /* True if -mfp32 was passed. */ |
| 279 | static int file_mips_fp32 = -1; |
| 280 | |
| 281 | /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */ |
| 282 | static int file_mips_soft_float = 0; |
| 283 | |
| 284 | /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */ |
| 285 | static int file_mips_single_float = 0; |
| 286 | |
| 287 | static struct mips_set_options mips_opts = |
| 288 | { |
| 289 | /* isa */ ISA_UNKNOWN, /* ase_mips3d */ -1, /* ase_mdmx */ -1, |
| 290 | /* ase_smartmips */ 0, /* ase_dsp */ -1, /* ase_dspr2 */ -1, /* ase_mt */ -1, |
| 291 | /* ase_mcu */ -1, /* mips16 */ -1, /* micromips */ -1, /* noreorder */ 0, |
| 292 | /* at */ ATREG, /* warn_about_macros */ 0, /* nomove */ 0, /* nobopt */ 0, |
| 293 | /* noautoextend */ 0, /* gp32 */ 0, /* fp32 */ 0, /* arch */ CPU_UNKNOWN, |
| 294 | /* sym32 */ FALSE, /* soft_float */ FALSE, /* single_float */ FALSE |
| 295 | }; |
| 296 | |
| 297 | /* These variables are filled in with the masks of registers used. |
| 298 | The object format code reads them and puts them in the appropriate |
| 299 | place. */ |
| 300 | unsigned long mips_gprmask; |
| 301 | unsigned long mips_cprmask[4]; |
| 302 | |
| 303 | /* MIPS ISA we are using for this output file. */ |
| 304 | static int file_mips_isa = ISA_UNKNOWN; |
| 305 | |
| 306 | /* True if any MIPS16 code was produced. */ |
| 307 | static int file_ase_mips16; |
| 308 | |
| 309 | #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \ |
| 310 | || mips_opts.isa == ISA_MIPS32R2 \ |
| 311 | || mips_opts.isa == ISA_MIPS64 \ |
| 312 | || mips_opts.isa == ISA_MIPS64R2) |
| 313 | |
| 314 | /* True if any microMIPS code was produced. */ |
| 315 | static int file_ase_micromips; |
| 316 | |
| 317 | /* True if we want to create R_MIPS_JALR for jalr $25. */ |
| 318 | #ifdef TE_IRIX |
| 319 | #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI |
| 320 | #else |
| 321 | /* As a GNU extension, we use R_MIPS_JALR for o32 too. However, |
| 322 | because there's no place for any addend, the only acceptable |
| 323 | expression is a bare symbol. */ |
| 324 | #define MIPS_JALR_HINT_P(EXPR) \ |
| 325 | (!HAVE_IN_PLACE_ADDENDS \ |
| 326 | || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0)) |
| 327 | #endif |
| 328 | |
| 329 | /* True if -mips3d was passed or implied by arguments passed on the |
| 330 | command line (e.g., by -march). */ |
| 331 | static int file_ase_mips3d; |
| 332 | |
| 333 | /* True if -mdmx was passed or implied by arguments passed on the |
| 334 | command line (e.g., by -march). */ |
| 335 | static int file_ase_mdmx; |
| 336 | |
| 337 | /* True if -msmartmips was passed or implied by arguments passed on the |
| 338 | command line (e.g., by -march). */ |
| 339 | static int file_ase_smartmips; |
| 340 | |
| 341 | #define ISA_SUPPORTS_SMARTMIPS (mips_opts.isa == ISA_MIPS32 \ |
| 342 | || mips_opts.isa == ISA_MIPS32R2) |
| 343 | |
| 344 | /* True if -mdsp was passed or implied by arguments passed on the |
| 345 | command line (e.g., by -march). */ |
| 346 | static int file_ase_dsp; |
| 347 | |
| 348 | #define ISA_SUPPORTS_DSP_ASE (mips_opts.isa == ISA_MIPS32R2 \ |
| 349 | || mips_opts.isa == ISA_MIPS64R2 \ |
| 350 | || mips_opts.micromips) |
| 351 | |
| 352 | #define ISA_SUPPORTS_DSP64_ASE (mips_opts.isa == ISA_MIPS64R2) |
| 353 | |
| 354 | /* True if -mdspr2 was passed or implied by arguments passed on the |
| 355 | command line (e.g., by -march). */ |
| 356 | static int file_ase_dspr2; |
| 357 | |
| 358 | #define ISA_SUPPORTS_DSPR2_ASE (mips_opts.isa == ISA_MIPS32R2 \ |
| 359 | || mips_opts.isa == ISA_MIPS64R2 \ |
| 360 | || mips_opts.micromips) |
| 361 | |
| 362 | /* True if -mmt was passed or implied by arguments passed on the |
| 363 | command line (e.g., by -march). */ |
| 364 | static int file_ase_mt; |
| 365 | |
| 366 | #define ISA_SUPPORTS_MT_ASE (mips_opts.isa == ISA_MIPS32R2 \ |
| 367 | || mips_opts.isa == ISA_MIPS64R2) |
| 368 | |
| 369 | #define ISA_SUPPORTS_MCU_ASE (mips_opts.isa == ISA_MIPS32R2 \ |
| 370 | || mips_opts.isa == ISA_MIPS64R2 \ |
| 371 | || mips_opts.micromips) |
| 372 | |
| 373 | /* The argument of the -march= flag. The architecture we are assembling. */ |
| 374 | static int file_mips_arch = CPU_UNKNOWN; |
| 375 | static const char *mips_arch_string; |
| 376 | |
| 377 | /* The argument of the -mtune= flag. The architecture for which we |
| 378 | are optimizing. */ |
| 379 | static int mips_tune = CPU_UNKNOWN; |
| 380 | static const char *mips_tune_string; |
| 381 | |
| 382 | /* True when generating 32-bit code for a 64-bit processor. */ |
| 383 | static int mips_32bitmode = 0; |
| 384 | |
| 385 | /* True if the given ABI requires 32-bit registers. */ |
| 386 | #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI) |
| 387 | |
| 388 | /* Likewise 64-bit registers. */ |
| 389 | #define ABI_NEEDS_64BIT_REGS(ABI) \ |
| 390 | ((ABI) == N32_ABI \ |
| 391 | || (ABI) == N64_ABI \ |
| 392 | || (ABI) == O64_ABI) |
| 393 | |
| 394 | /* Return true if ISA supports 64 bit wide gp registers. */ |
| 395 | #define ISA_HAS_64BIT_REGS(ISA) \ |
| 396 | ((ISA) == ISA_MIPS3 \ |
| 397 | || (ISA) == ISA_MIPS4 \ |
| 398 | || (ISA) == ISA_MIPS5 \ |
| 399 | || (ISA) == ISA_MIPS64 \ |
| 400 | || (ISA) == ISA_MIPS64R2) |
| 401 | |
| 402 | /* Return true if ISA supports 64 bit wide float registers. */ |
| 403 | #define ISA_HAS_64BIT_FPRS(ISA) \ |
| 404 | ((ISA) == ISA_MIPS3 \ |
| 405 | || (ISA) == ISA_MIPS4 \ |
| 406 | || (ISA) == ISA_MIPS5 \ |
| 407 | || (ISA) == ISA_MIPS32R2 \ |
| 408 | || (ISA) == ISA_MIPS64 \ |
| 409 | || (ISA) == ISA_MIPS64R2) |
| 410 | |
| 411 | /* Return true if ISA supports 64-bit right rotate (dror et al.) |
| 412 | instructions. */ |
| 413 | #define ISA_HAS_DROR(ISA) \ |
| 414 | ((ISA) == ISA_MIPS64R2 \ |
| 415 | || (mips_opts.micromips \ |
| 416 | && ISA_HAS_64BIT_REGS (ISA)) \ |
| 417 | ) |
| 418 | |
| 419 | /* Return true if ISA supports 32-bit right rotate (ror et al.) |
| 420 | instructions. */ |
| 421 | #define ISA_HAS_ROR(ISA) \ |
| 422 | ((ISA) == ISA_MIPS32R2 \ |
| 423 | || (ISA) == ISA_MIPS64R2 \ |
| 424 | || mips_opts.ase_smartmips \ |
| 425 | || mips_opts.micromips \ |
| 426 | ) |
| 427 | |
| 428 | /* Return true if ISA supports single-precision floats in odd registers. */ |
| 429 | #define ISA_HAS_ODD_SINGLE_FPR(ISA) \ |
| 430 | ((ISA) == ISA_MIPS32 \ |
| 431 | || (ISA) == ISA_MIPS32R2 \ |
| 432 | || (ISA) == ISA_MIPS64 \ |
| 433 | || (ISA) == ISA_MIPS64R2) |
| 434 | |
| 435 | /* Return true if ISA supports move to/from high part of a 64-bit |
| 436 | floating-point register. */ |
| 437 | #define ISA_HAS_MXHC1(ISA) \ |
| 438 | ((ISA) == ISA_MIPS32R2 \ |
| 439 | || (ISA) == ISA_MIPS64R2) |
| 440 | |
| 441 | #define HAVE_32BIT_GPRS \ |
| 442 | (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa)) |
| 443 | |
| 444 | #define HAVE_32BIT_FPRS \ |
| 445 | (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa)) |
| 446 | |
| 447 | #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS) |
| 448 | #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS) |
| 449 | |
| 450 | #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI) |
| 451 | |
| 452 | #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI) |
| 453 | |
| 454 | /* True if relocations are stored in-place. */ |
| 455 | #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI) |
| 456 | |
| 457 | /* The ABI-derived address size. */ |
| 458 | #define HAVE_64BIT_ADDRESSES \ |
| 459 | (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI)) |
| 460 | #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES) |
| 461 | |
| 462 | /* The size of symbolic constants (i.e., expressions of the form |
| 463 | "SYMBOL" or "SYMBOL + OFFSET"). */ |
| 464 | #define HAVE_32BIT_SYMBOLS \ |
| 465 | (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32) |
| 466 | #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS) |
| 467 | |
| 468 | /* Addresses are loaded in different ways, depending on the address size |
| 469 | in use. The n32 ABI Documentation also mandates the use of additions |
| 470 | with overflow checking, but existing implementations don't follow it. */ |
| 471 | #define ADDRESS_ADD_INSN \ |
| 472 | (HAVE_32BIT_ADDRESSES ? "addu" : "daddu") |
| 473 | |
| 474 | #define ADDRESS_ADDI_INSN \ |
| 475 | (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu") |
| 476 | |
| 477 | #define ADDRESS_LOAD_INSN \ |
| 478 | (HAVE_32BIT_ADDRESSES ? "lw" : "ld") |
| 479 | |
| 480 | #define ADDRESS_STORE_INSN \ |
| 481 | (HAVE_32BIT_ADDRESSES ? "sw" : "sd") |
| 482 | |
| 483 | /* Return true if the given CPU supports the MIPS16 ASE. */ |
| 484 | #define CPU_HAS_MIPS16(cpu) \ |
| 485 | (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \ |
| 486 | || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0) |
| 487 | |
| 488 | /* Return true if the given CPU supports the microMIPS ASE. */ |
| 489 | #define CPU_HAS_MICROMIPS(cpu) 0 |
| 490 | |
| 491 | /* True if CPU has a dror instruction. */ |
| 492 | #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500) |
| 493 | |
| 494 | /* True if CPU has a ror instruction. */ |
| 495 | #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU) |
| 496 | |
| 497 | /* True if CPU is in the Octeon family */ |
| 498 | #define CPU_IS_OCTEON(CPU) ((CPU) == CPU_OCTEON || (CPU) == CPU_OCTEONP || (CPU) == CPU_OCTEON2) |
| 499 | |
| 500 | /* True if CPU has seq/sne and seqi/snei instructions. */ |
| 501 | #define CPU_HAS_SEQ(CPU) (CPU_IS_OCTEON (CPU)) |
| 502 | |
| 503 | /* True if mflo and mfhi can be immediately followed by instructions |
| 504 | which write to the HI and LO registers. |
| 505 | |
| 506 | According to MIPS specifications, MIPS ISAs I, II, and III need |
| 507 | (at least) two instructions between the reads of HI/LO and |
| 508 | instructions which write them, and later ISAs do not. Contradicting |
| 509 | the MIPS specifications, some MIPS IV processor user manuals (e.g. |
| 510 | the UM for the NEC Vr5000) document needing the instructions between |
| 511 | HI/LO reads and writes, as well. Therefore, we declare only MIPS32, |
| 512 | MIPS64 and later ISAs to have the interlocks, plus any specific |
| 513 | earlier-ISA CPUs for which CPU documentation declares that the |
| 514 | instructions are really interlocked. */ |
| 515 | #define hilo_interlocks \ |
| 516 | (mips_opts.isa == ISA_MIPS32 \ |
| 517 | || mips_opts.isa == ISA_MIPS32R2 \ |
| 518 | || mips_opts.isa == ISA_MIPS64 \ |
| 519 | || mips_opts.isa == ISA_MIPS64R2 \ |
| 520 | || mips_opts.arch == CPU_R4010 \ |
| 521 | || mips_opts.arch == CPU_R10000 \ |
| 522 | || mips_opts.arch == CPU_R12000 \ |
| 523 | || mips_opts.arch == CPU_R14000 \ |
| 524 | || mips_opts.arch == CPU_R16000 \ |
| 525 | || mips_opts.arch == CPU_RM7000 \ |
| 526 | || mips_opts.arch == CPU_VR5500 \ |
| 527 | || mips_opts.micromips \ |
| 528 | ) |
| 529 | |
| 530 | /* Whether the processor uses hardware interlocks to protect reads |
| 531 | from the GPRs after they are loaded from memory, and thus does not |
| 532 | require nops to be inserted. This applies to instructions marked |
| 533 | INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA |
| 534 | level I and microMIPS mode instructions are always interlocked. */ |
| 535 | #define gpr_interlocks \ |
| 536 | (mips_opts.isa != ISA_MIPS1 \ |
| 537 | || mips_opts.arch == CPU_R3900 \ |
| 538 | || mips_opts.micromips \ |
| 539 | ) |
| 540 | |
| 541 | /* Whether the processor uses hardware interlocks to avoid delays |
| 542 | required by coprocessor instructions, and thus does not require |
| 543 | nops to be inserted. This applies to instructions marked |
| 544 | INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays |
| 545 | between instructions marked INSN_WRITE_COND_CODE and ones marked |
| 546 | INSN_READ_COND_CODE. These nops are only required at MIPS ISA |
| 547 | levels I, II, and III and microMIPS mode instructions are always |
| 548 | interlocked. */ |
| 549 | /* Itbl support may require additional care here. */ |
| 550 | #define cop_interlocks \ |
| 551 | ((mips_opts.isa != ISA_MIPS1 \ |
| 552 | && mips_opts.isa != ISA_MIPS2 \ |
| 553 | && mips_opts.isa != ISA_MIPS3) \ |
| 554 | || mips_opts.arch == CPU_R4300 \ |
| 555 | || mips_opts.micromips \ |
| 556 | ) |
| 557 | |
| 558 | /* Whether the processor uses hardware interlocks to protect reads |
| 559 | from coprocessor registers after they are loaded from memory, and |
| 560 | thus does not require nops to be inserted. This applies to |
| 561 | instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only |
| 562 | requires at MIPS ISA level I and microMIPS mode instructions are |
| 563 | always interlocked. */ |
| 564 | #define cop_mem_interlocks \ |
| 565 | (mips_opts.isa != ISA_MIPS1 \ |
| 566 | || mips_opts.micromips \ |
| 567 | ) |
| 568 | |
| 569 | /* Is this a mfhi or mflo instruction? */ |
| 570 | #define MF_HILO_INSN(PINFO) \ |
| 571 | ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO)) |
| 572 | |
| 573 | /* Whether code compression (either of the MIPS16 or the microMIPS ASEs) |
| 574 | has been selected. This implies, in particular, that addresses of text |
| 575 | labels have their LSB set. */ |
| 576 | #define HAVE_CODE_COMPRESSION \ |
| 577 | ((mips_opts.mips16 | mips_opts.micromips) != 0) |
| 578 | |
| 579 | /* MIPS PIC level. */ |
| 580 | |
| 581 | enum mips_pic_level mips_pic; |
| 582 | |
| 583 | /* 1 if we should generate 32 bit offsets from the $gp register in |
| 584 | SVR4_PIC mode. Currently has no meaning in other modes. */ |
| 585 | static int mips_big_got = 0; |
| 586 | |
| 587 | /* 1 if trap instructions should used for overflow rather than break |
| 588 | instructions. */ |
| 589 | static int mips_trap = 0; |
| 590 | |
| 591 | /* 1 if double width floating point constants should not be constructed |
| 592 | by assembling two single width halves into two single width floating |
| 593 | point registers which just happen to alias the double width destination |
| 594 | register. On some architectures this aliasing can be disabled by a bit |
| 595 | in the status register, and the setting of this bit cannot be determined |
| 596 | automatically at assemble time. */ |
| 597 | static int mips_disable_float_construction; |
| 598 | |
| 599 | /* Non-zero if any .set noreorder directives were used. */ |
| 600 | |
| 601 | static int mips_any_noreorder; |
| 602 | |
| 603 | /* Non-zero if nops should be inserted when the register referenced in |
| 604 | an mfhi/mflo instruction is read in the next two instructions. */ |
| 605 | static int mips_7000_hilo_fix; |
| 606 | |
| 607 | /* The size of objects in the small data section. */ |
| 608 | static unsigned int g_switch_value = 8; |
| 609 | /* Whether the -G option was used. */ |
| 610 | static int g_switch_seen = 0; |
| 611 | |
| 612 | #define N_RMASK 0xc4 |
| 613 | #define N_VFP 0xd4 |
| 614 | |
| 615 | /* If we can determine in advance that GP optimization won't be |
| 616 | possible, we can skip the relaxation stuff that tries to produce |
| 617 | GP-relative references. This makes delay slot optimization work |
| 618 | better. |
| 619 | |
| 620 | This function can only provide a guess, but it seems to work for |
| 621 | gcc output. It needs to guess right for gcc, otherwise gcc |
| 622 | will put what it thinks is a GP-relative instruction in a branch |
| 623 | delay slot. |
| 624 | |
| 625 | I don't know if a fix is needed for the SVR4_PIC mode. I've only |
| 626 | fixed it for the non-PIC mode. KR 95/04/07 */ |
| 627 | static int nopic_need_relax (symbolS *, int); |
| 628 | |
| 629 | /* handle of the OPCODE hash table */ |
| 630 | static struct hash_control *op_hash = NULL; |
| 631 | |
| 632 | /* The opcode hash table we use for the mips16. */ |
| 633 | static struct hash_control *mips16_op_hash = NULL; |
| 634 | |
| 635 | /* The opcode hash table we use for the microMIPS ASE. */ |
| 636 | static struct hash_control *micromips_op_hash = NULL; |
| 637 | |
| 638 | /* This array holds the chars that always start a comment. If the |
| 639 | pre-processor is disabled, these aren't very useful */ |
| 640 | const char comment_chars[] = "#"; |
| 641 | |
| 642 | /* This array holds the chars that only start a comment at the beginning of |
| 643 | a line. If the line seems to have the form '# 123 filename' |
| 644 | .line and .file directives will appear in the pre-processed output */ |
| 645 | /* Note that input_file.c hand checks for '#' at the beginning of the |
| 646 | first line of the input file. This is because the compiler outputs |
| 647 | #NO_APP at the beginning of its output. */ |
| 648 | /* Also note that C style comments are always supported. */ |
| 649 | const char line_comment_chars[] = "#"; |
| 650 | |
| 651 | /* This array holds machine specific line separator characters. */ |
| 652 | const char line_separator_chars[] = ";"; |
| 653 | |
| 654 | /* Chars that can be used to separate mant from exp in floating point nums */ |
| 655 | const char EXP_CHARS[] = "eE"; |
| 656 | |
| 657 | /* Chars that mean this number is a floating point constant */ |
| 658 | /* As in 0f12.456 */ |
| 659 | /* or 0d1.2345e12 */ |
| 660 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; |
| 661 | |
| 662 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be |
| 663 | changed in read.c . Ideally it shouldn't have to know about it at all, |
| 664 | but nothing is ideal around here. |
| 665 | */ |
| 666 | |
| 667 | static char *insn_error; |
| 668 | |
| 669 | static int auto_align = 1; |
| 670 | |
| 671 | /* When outputting SVR4 PIC code, the assembler needs to know the |
| 672 | offset in the stack frame from which to restore the $gp register. |
| 673 | This is set by the .cprestore pseudo-op, and saved in this |
| 674 | variable. */ |
| 675 | static offsetT mips_cprestore_offset = -1; |
| 676 | |
| 677 | /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some |
| 678 | more optimizations, it can use a register value instead of a memory-saved |
| 679 | offset and even an other register than $gp as global pointer. */ |
| 680 | static offsetT mips_cpreturn_offset = -1; |
| 681 | static int mips_cpreturn_register = -1; |
| 682 | static int mips_gp_register = GP; |
| 683 | static int mips_gprel_offset = 0; |
| 684 | |
| 685 | /* Whether mips_cprestore_offset has been set in the current function |
| 686 | (or whether it has already been warned about, if not). */ |
| 687 | static int mips_cprestore_valid = 0; |
| 688 | |
| 689 | /* This is the register which holds the stack frame, as set by the |
| 690 | .frame pseudo-op. This is needed to implement .cprestore. */ |
| 691 | static int mips_frame_reg = SP; |
| 692 | |
| 693 | /* Whether mips_frame_reg has been set in the current function |
| 694 | (or whether it has already been warned about, if not). */ |
| 695 | static int mips_frame_reg_valid = 0; |
| 696 | |
| 697 | /* To output NOP instructions correctly, we need to keep information |
| 698 | about the previous two instructions. */ |
| 699 | |
| 700 | /* Whether we are optimizing. The default value of 2 means to remove |
| 701 | unneeded NOPs and swap branch instructions when possible. A value |
| 702 | of 1 means to not swap branches. A value of 0 means to always |
| 703 | insert NOPs. */ |
| 704 | static int mips_optimize = 2; |
| 705 | |
| 706 | /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is |
| 707 | equivalent to seeing no -g option at all. */ |
| 708 | static int mips_debug = 0; |
| 709 | |
| 710 | /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */ |
| 711 | #define MAX_VR4130_NOPS 4 |
| 712 | |
| 713 | /* The maximum number of NOPs needed to fill delay slots. */ |
| 714 | #define MAX_DELAY_NOPS 2 |
| 715 | |
| 716 | /* The maximum number of NOPs needed for any purpose. */ |
| 717 | #define MAX_NOPS 4 |
| 718 | |
| 719 | /* A list of previous instructions, with index 0 being the most recent. |
| 720 | We need to look back MAX_NOPS instructions when filling delay slots |
| 721 | or working around processor errata. We need to look back one |
| 722 | instruction further if we're thinking about using history[0] to |
| 723 | fill a branch delay slot. */ |
| 724 | static struct mips_cl_insn history[1 + MAX_NOPS]; |
| 725 | |
| 726 | /* Nop instructions used by emit_nop. */ |
| 727 | static struct mips_cl_insn nop_insn; |
| 728 | static struct mips_cl_insn mips16_nop_insn; |
| 729 | static struct mips_cl_insn micromips_nop16_insn; |
| 730 | static struct mips_cl_insn micromips_nop32_insn; |
| 731 | |
| 732 | /* The appropriate nop for the current mode. */ |
| 733 | #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn \ |
| 734 | : (mips_opts.micromips ? µmips_nop16_insn : &nop_insn)) |
| 735 | |
| 736 | /* The size of NOP_INSN in bytes. */ |
| 737 | #define NOP_INSN_SIZE (HAVE_CODE_COMPRESSION ? 2 : 4) |
| 738 | |
| 739 | /* If this is set, it points to a frag holding nop instructions which |
| 740 | were inserted before the start of a noreorder section. If those |
| 741 | nops turn out to be unnecessary, the size of the frag can be |
| 742 | decreased. */ |
| 743 | static fragS *prev_nop_frag; |
| 744 | |
| 745 | /* The number of nop instructions we created in prev_nop_frag. */ |
| 746 | static int prev_nop_frag_holds; |
| 747 | |
| 748 | /* The number of nop instructions that we know we need in |
| 749 | prev_nop_frag. */ |
| 750 | static int prev_nop_frag_required; |
| 751 | |
| 752 | /* The number of instructions we've seen since prev_nop_frag. */ |
| 753 | static int prev_nop_frag_since; |
| 754 | |
| 755 | /* For ECOFF and ELF, relocations against symbols are done in two |
| 756 | parts, with a HI relocation and a LO relocation. Each relocation |
| 757 | has only 16 bits of space to store an addend. This means that in |
| 758 | order for the linker to handle carries correctly, it must be able |
| 759 | to locate both the HI and the LO relocation. This means that the |
| 760 | relocations must appear in order in the relocation table. |
| 761 | |
| 762 | In order to implement this, we keep track of each unmatched HI |
| 763 | relocation. We then sort them so that they immediately precede the |
| 764 | corresponding LO relocation. */ |
| 765 | |
| 766 | struct mips_hi_fixup |
| 767 | { |
| 768 | /* Next HI fixup. */ |
| 769 | struct mips_hi_fixup *next; |
| 770 | /* This fixup. */ |
| 771 | fixS *fixp; |
| 772 | /* The section this fixup is in. */ |
| 773 | segT seg; |
| 774 | }; |
| 775 | |
| 776 | /* The list of unmatched HI relocs. */ |
| 777 | |
| 778 | static struct mips_hi_fixup *mips_hi_fixup_list; |
| 779 | |
| 780 | /* The frag containing the last explicit relocation operator. |
| 781 | Null if explicit relocations have not been used. */ |
| 782 | |
| 783 | static fragS *prev_reloc_op_frag; |
| 784 | |
| 785 | /* Map normal MIPS register numbers to mips16 register numbers. */ |
| 786 | |
| 787 | #define X ILLEGAL_REG |
| 788 | static const int mips32_to_16_reg_map[] = |
| 789 | { |
| 790 | X, X, 2, 3, 4, 5, 6, 7, |
| 791 | X, X, X, X, X, X, X, X, |
| 792 | 0, 1, X, X, X, X, X, X, |
| 793 | X, X, X, X, X, X, X, X |
| 794 | }; |
| 795 | #undef X |
| 796 | |
| 797 | /* Map mips16 register numbers to normal MIPS register numbers. */ |
| 798 | |
| 799 | static const unsigned int mips16_to_32_reg_map[] = |
| 800 | { |
| 801 | 16, 17, 2, 3, 4, 5, 6, 7 |
| 802 | }; |
| 803 | |
| 804 | /* Map normal MIPS register numbers to microMIPS register numbers. */ |
| 805 | |
| 806 | #define mips32_to_micromips_reg_b_map mips32_to_16_reg_map |
| 807 | #define mips32_to_micromips_reg_c_map mips32_to_16_reg_map |
| 808 | #define mips32_to_micromips_reg_d_map mips32_to_16_reg_map |
| 809 | #define mips32_to_micromips_reg_e_map mips32_to_16_reg_map |
| 810 | #define mips32_to_micromips_reg_f_map mips32_to_16_reg_map |
| 811 | #define mips32_to_micromips_reg_g_map mips32_to_16_reg_map |
| 812 | #define mips32_to_micromips_reg_l_map mips32_to_16_reg_map |
| 813 | |
| 814 | #define X ILLEGAL_REG |
| 815 | /* reg type h: 4, 5, 6. */ |
| 816 | static const int mips32_to_micromips_reg_h_map[] = |
| 817 | { |
| 818 | X, X, X, X, 4, 5, 6, X, |
| 819 | X, X, X, X, X, X, X, X, |
| 820 | X, X, X, X, X, X, X, X, |
| 821 | X, X, X, X, X, X, X, X |
| 822 | }; |
| 823 | |
| 824 | /* reg type m: 0, 17, 2, 3, 16, 18, 19, 20. */ |
| 825 | static const int mips32_to_micromips_reg_m_map[] = |
| 826 | { |
| 827 | 0, X, 2, 3, X, X, X, X, |
| 828 | X, X, X, X, X, X, X, X, |
| 829 | 4, 1, 5, 6, 7, X, X, X, |
| 830 | X, X, X, X, X, X, X, X |
| 831 | }; |
| 832 | |
| 833 | /* reg type q: 0, 2-7. 17. */ |
| 834 | static const int mips32_to_micromips_reg_q_map[] = |
| 835 | { |
| 836 | 0, X, 2, 3, 4, 5, 6, 7, |
| 837 | X, X, X, X, X, X, X, X, |
| 838 | X, 1, X, X, X, X, X, X, |
| 839 | X, X, X, X, X, X, X, X |
| 840 | }; |
| 841 | |
| 842 | #define mips32_to_micromips_reg_n_map mips32_to_micromips_reg_m_map |
| 843 | #undef X |
| 844 | |
| 845 | /* Map microMIPS register numbers to normal MIPS register numbers. */ |
| 846 | |
| 847 | #define micromips_to_32_reg_b_map mips16_to_32_reg_map |
| 848 | #define micromips_to_32_reg_c_map mips16_to_32_reg_map |
| 849 | #define micromips_to_32_reg_d_map mips16_to_32_reg_map |
| 850 | #define micromips_to_32_reg_e_map mips16_to_32_reg_map |
| 851 | #define micromips_to_32_reg_f_map mips16_to_32_reg_map |
| 852 | #define micromips_to_32_reg_g_map mips16_to_32_reg_map |
| 853 | |
| 854 | /* The microMIPS registers with type h. */ |
| 855 | static const unsigned int micromips_to_32_reg_h_map[] = |
| 856 | { |
| 857 | 5, 5, 6, 4, 4, 4, 4, 4 |
| 858 | }; |
| 859 | |
| 860 | /* The microMIPS registers with type i. */ |
| 861 | static const unsigned int micromips_to_32_reg_i_map[] = |
| 862 | { |
| 863 | 6, 7, 7, 21, 22, 5, 6, 7 |
| 864 | }; |
| 865 | |
| 866 | #define micromips_to_32_reg_l_map mips16_to_32_reg_map |
| 867 | |
| 868 | /* The microMIPS registers with type m. */ |
| 869 | static const unsigned int micromips_to_32_reg_m_map[] = |
| 870 | { |
| 871 | 0, 17, 2, 3, 16, 18, 19, 20 |
| 872 | }; |
| 873 | |
| 874 | #define micromips_to_32_reg_n_map micromips_to_32_reg_m_map |
| 875 | |
| 876 | /* The microMIPS registers with type q. */ |
| 877 | static const unsigned int micromips_to_32_reg_q_map[] = |
| 878 | { |
| 879 | 0, 17, 2, 3, 4, 5, 6, 7 |
| 880 | }; |
| 881 | |
| 882 | /* microMIPS imm type B. */ |
| 883 | static const int micromips_imm_b_map[] = |
| 884 | { |
| 885 | 1, 4, 8, 12, 16, 20, 24, -1 |
| 886 | }; |
| 887 | |
| 888 | /* microMIPS imm type C. */ |
| 889 | static const int micromips_imm_c_map[] = |
| 890 | { |
| 891 | 128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 255, 32768, 65535 |
| 892 | }; |
| 893 | |
| 894 | /* Classifies the kind of instructions we're interested in when |
| 895 | implementing -mfix-vr4120. */ |
| 896 | enum fix_vr4120_class |
| 897 | { |
| 898 | FIX_VR4120_MACC, |
| 899 | FIX_VR4120_DMACC, |
| 900 | FIX_VR4120_MULT, |
| 901 | FIX_VR4120_DMULT, |
| 902 | FIX_VR4120_DIV, |
| 903 | FIX_VR4120_MTHILO, |
| 904 | NUM_FIX_VR4120_CLASSES |
| 905 | }; |
| 906 | |
| 907 | /* ...likewise -mfix-loongson2f-jump. */ |
| 908 | static bfd_boolean mips_fix_loongson2f_jump; |
| 909 | |
| 910 | /* ...likewise -mfix-loongson2f-nop. */ |
| 911 | static bfd_boolean mips_fix_loongson2f_nop; |
| 912 | |
| 913 | /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed. */ |
| 914 | static bfd_boolean mips_fix_loongson2f; |
| 915 | |
| 916 | /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if |
| 917 | there must be at least one other instruction between an instruction |
| 918 | of type X and an instruction of type Y. */ |
| 919 | static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES]; |
| 920 | |
| 921 | /* True if -mfix-vr4120 is in force. */ |
| 922 | static int mips_fix_vr4120; |
| 923 | |
| 924 | /* ...likewise -mfix-vr4130. */ |
| 925 | static int mips_fix_vr4130; |
| 926 | |
| 927 | /* ...likewise -mfix-24k. */ |
| 928 | static int mips_fix_24k; |
| 929 | |
| 930 | /* ...likewise -mfix-cn63xxp1 */ |
| 931 | static bfd_boolean mips_fix_cn63xxp1; |
| 932 | |
| 933 | /* We don't relax branches by default, since this causes us to expand |
| 934 | `la .l2 - .l1' if there's a branch between .l1 and .l2, because we |
| 935 | fail to compute the offset before expanding the macro to the most |
| 936 | efficient expansion. */ |
| 937 | |
| 938 | static int mips_relax_branch; |
| 939 | \f |
| 940 | /* The expansion of many macros depends on the type of symbol that |
| 941 | they refer to. For example, when generating position-dependent code, |
| 942 | a macro that refers to a symbol may have two different expansions, |
| 943 | one which uses GP-relative addresses and one which uses absolute |
| 944 | addresses. When generating SVR4-style PIC, a macro may have |
| 945 | different expansions for local and global symbols. |
| 946 | |
| 947 | We handle these situations by generating both sequences and putting |
| 948 | them in variant frags. In position-dependent code, the first sequence |
| 949 | will be the GP-relative one and the second sequence will be the |
| 950 | absolute one. In SVR4 PIC, the first sequence will be for global |
| 951 | symbols and the second will be for local symbols. |
| 952 | |
| 953 | The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and |
| 954 | SECOND are the lengths of the two sequences in bytes. These fields |
| 955 | can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition, |
| 956 | the subtype has the following flags: |
| 957 | |
| 958 | RELAX_USE_SECOND |
| 959 | Set if it has been decided that we should use the second |
| 960 | sequence instead of the first. |
| 961 | |
| 962 | RELAX_SECOND_LONGER |
| 963 | Set in the first variant frag if the macro's second implementation |
| 964 | is longer than its first. This refers to the macro as a whole, |
| 965 | not an individual relaxation. |
| 966 | |
| 967 | RELAX_NOMACRO |
| 968 | Set in the first variant frag if the macro appeared in a .set nomacro |
| 969 | block and if one alternative requires a warning but the other does not. |
| 970 | |
| 971 | RELAX_DELAY_SLOT |
| 972 | Like RELAX_NOMACRO, but indicates that the macro appears in a branch |
| 973 | delay slot. |
| 974 | |
| 975 | RELAX_DELAY_SLOT_16BIT |
| 976 | Like RELAX_DELAY_SLOT, but indicates that the delay slot requires a |
| 977 | 16-bit instruction. |
| 978 | |
| 979 | RELAX_DELAY_SLOT_SIZE_FIRST |
| 980 | Like RELAX_DELAY_SLOT, but indicates that the first implementation of |
| 981 | the macro is of the wrong size for the branch delay slot. |
| 982 | |
| 983 | RELAX_DELAY_SLOT_SIZE_SECOND |
| 984 | Like RELAX_DELAY_SLOT, but indicates that the second implementation of |
| 985 | the macro is of the wrong size for the branch delay slot. |
| 986 | |
| 987 | The frag's "opcode" points to the first fixup for relaxable code. |
| 988 | |
| 989 | Relaxable macros are generated using a sequence such as: |
| 990 | |
| 991 | relax_start (SYMBOL); |
| 992 | ... generate first expansion ... |
| 993 | relax_switch (); |
| 994 | ... generate second expansion ... |
| 995 | relax_end (); |
| 996 | |
| 997 | The code and fixups for the unwanted alternative are discarded |
| 998 | by md_convert_frag. */ |
| 999 | #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND)) |
| 1000 | |
| 1001 | #define RELAX_FIRST(X) (((X) >> 8) & 0xff) |
| 1002 | #define RELAX_SECOND(X) ((X) & 0xff) |
| 1003 | #define RELAX_USE_SECOND 0x10000 |
| 1004 | #define RELAX_SECOND_LONGER 0x20000 |
| 1005 | #define RELAX_NOMACRO 0x40000 |
| 1006 | #define RELAX_DELAY_SLOT 0x80000 |
| 1007 | #define RELAX_DELAY_SLOT_16BIT 0x100000 |
| 1008 | #define RELAX_DELAY_SLOT_SIZE_FIRST 0x200000 |
| 1009 | #define RELAX_DELAY_SLOT_SIZE_SECOND 0x400000 |
| 1010 | |
| 1011 | /* Branch without likely bit. If label is out of range, we turn: |
| 1012 | |
| 1013 | beq reg1, reg2, label |
| 1014 | delay slot |
| 1015 | |
| 1016 | into |
| 1017 | |
| 1018 | bne reg1, reg2, 0f |
| 1019 | nop |
| 1020 | j label |
| 1021 | 0: delay slot |
| 1022 | |
| 1023 | with the following opcode replacements: |
| 1024 | |
| 1025 | beq <-> bne |
| 1026 | blez <-> bgtz |
| 1027 | bltz <-> bgez |
| 1028 | bc1f <-> bc1t |
| 1029 | |
| 1030 | bltzal <-> bgezal (with jal label instead of j label) |
| 1031 | |
| 1032 | Even though keeping the delay slot instruction in the delay slot of |
| 1033 | the branch would be more efficient, it would be very tricky to do |
| 1034 | correctly, because we'd have to introduce a variable frag *after* |
| 1035 | the delay slot instruction, and expand that instead. Let's do it |
| 1036 | the easy way for now, even if the branch-not-taken case now costs |
| 1037 | one additional instruction. Out-of-range branches are not supposed |
| 1038 | to be common, anyway. |
| 1039 | |
| 1040 | Branch likely. If label is out of range, we turn: |
| 1041 | |
| 1042 | beql reg1, reg2, label |
| 1043 | delay slot (annulled if branch not taken) |
| 1044 | |
| 1045 | into |
| 1046 | |
| 1047 | beql reg1, reg2, 1f |
| 1048 | nop |
| 1049 | beql $0, $0, 2f |
| 1050 | nop |
| 1051 | 1: j[al] label |
| 1052 | delay slot (executed only if branch taken) |
| 1053 | 2: |
| 1054 | |
| 1055 | It would be possible to generate a shorter sequence by losing the |
| 1056 | likely bit, generating something like: |
| 1057 | |
| 1058 | bne reg1, reg2, 0f |
| 1059 | nop |
| 1060 | j[al] label |
| 1061 | delay slot (executed only if branch taken) |
| 1062 | 0: |
| 1063 | |
| 1064 | beql -> bne |
| 1065 | bnel -> beq |
| 1066 | blezl -> bgtz |
| 1067 | bgtzl -> blez |
| 1068 | bltzl -> bgez |
| 1069 | bgezl -> bltz |
| 1070 | bc1fl -> bc1t |
| 1071 | bc1tl -> bc1f |
| 1072 | |
| 1073 | bltzall -> bgezal (with jal label instead of j label) |
| 1074 | bgezall -> bltzal (ditto) |
| 1075 | |
| 1076 | |
| 1077 | but it's not clear that it would actually improve performance. */ |
| 1078 | #define RELAX_BRANCH_ENCODE(at, uncond, likely, link, toofar) \ |
| 1079 | ((relax_substateT) \ |
| 1080 | (0xc0000000 \ |
| 1081 | | ((at) & 0x1f) \ |
| 1082 | | ((toofar) ? 0x20 : 0) \ |
| 1083 | | ((link) ? 0x40 : 0) \ |
| 1084 | | ((likely) ? 0x80 : 0) \ |
| 1085 | | ((uncond) ? 0x100 : 0))) |
| 1086 | #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000) |
| 1087 | #define RELAX_BRANCH_UNCOND(i) (((i) & 0x100) != 0) |
| 1088 | #define RELAX_BRANCH_LIKELY(i) (((i) & 0x80) != 0) |
| 1089 | #define RELAX_BRANCH_LINK(i) (((i) & 0x40) != 0) |
| 1090 | #define RELAX_BRANCH_TOOFAR(i) (((i) & 0x20) != 0) |
| 1091 | #define RELAX_BRANCH_AT(i) ((i) & 0x1f) |
| 1092 | |
| 1093 | /* For mips16 code, we use an entirely different form of relaxation. |
| 1094 | mips16 supports two versions of most instructions which take |
| 1095 | immediate values: a small one which takes some small value, and a |
| 1096 | larger one which takes a 16 bit value. Since branches also follow |
| 1097 | this pattern, relaxing these values is required. |
| 1098 | |
| 1099 | We can assemble both mips16 and normal MIPS code in a single |
| 1100 | object. Therefore, we need to support this type of relaxation at |
| 1101 | the same time that we support the relaxation described above. We |
| 1102 | use the high bit of the subtype field to distinguish these cases. |
| 1103 | |
| 1104 | The information we store for this type of relaxation is the |
| 1105 | argument code found in the opcode file for this relocation, whether |
| 1106 | the user explicitly requested a small or extended form, and whether |
| 1107 | the relocation is in a jump or jal delay slot. That tells us the |
| 1108 | size of the value, and how it should be stored. We also store |
| 1109 | whether the fragment is considered to be extended or not. We also |
| 1110 | store whether this is known to be a branch to a different section, |
| 1111 | whether we have tried to relax this frag yet, and whether we have |
| 1112 | ever extended a PC relative fragment because of a shift count. */ |
| 1113 | #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \ |
| 1114 | (0x80000000 \ |
| 1115 | | ((type) & 0xff) \ |
| 1116 | | ((small) ? 0x100 : 0) \ |
| 1117 | | ((ext) ? 0x200 : 0) \ |
| 1118 | | ((dslot) ? 0x400 : 0) \ |
| 1119 | | ((jal_dslot) ? 0x800 : 0)) |
| 1120 | #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000) |
| 1121 | #define RELAX_MIPS16_TYPE(i) ((i) & 0xff) |
| 1122 | #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0) |
| 1123 | #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0) |
| 1124 | #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0) |
| 1125 | #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0) |
| 1126 | #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0) |
| 1127 | #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000) |
| 1128 | #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000) |
| 1129 | #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0) |
| 1130 | #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000) |
| 1131 | #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000) |
| 1132 | |
| 1133 | /* For microMIPS code, we use relaxation similar to one we use for |
| 1134 | MIPS16 code. Some instructions that take immediate values support |
| 1135 | two encodings: a small one which takes some small value, and a |
| 1136 | larger one which takes a 16 bit value. As some branches also follow |
| 1137 | this pattern, relaxing these values is required. |
| 1138 | |
| 1139 | We can assemble both microMIPS and normal MIPS code in a single |
| 1140 | object. Therefore, we need to support this type of relaxation at |
| 1141 | the same time that we support the relaxation described above. We |
| 1142 | use one of the high bits of the subtype field to distinguish these |
| 1143 | cases. |
| 1144 | |
| 1145 | The information we store for this type of relaxation is the argument |
| 1146 | code found in the opcode file for this relocation, the register |
| 1147 | selected as the assembler temporary, whether the branch is |
| 1148 | unconditional, whether it is compact, whether it stores the link |
| 1149 | address implicitly in $ra, whether relaxation of out-of-range 32-bit |
| 1150 | branches to a sequence of instructions is enabled, and whether the |
| 1151 | displacement of a branch is too large to fit as an immediate argument |
| 1152 | of a 16-bit and a 32-bit branch, respectively. */ |
| 1153 | #define RELAX_MICROMIPS_ENCODE(type, at, uncond, compact, link, \ |
| 1154 | relax32, toofar16, toofar32) \ |
| 1155 | (0x40000000 \ |
| 1156 | | ((type) & 0xff) \ |
| 1157 | | (((at) & 0x1f) << 8) \ |
| 1158 | | ((uncond) ? 0x2000 : 0) \ |
| 1159 | | ((compact) ? 0x4000 : 0) \ |
| 1160 | | ((link) ? 0x8000 : 0) \ |
| 1161 | | ((relax32) ? 0x10000 : 0) \ |
| 1162 | | ((toofar16) ? 0x20000 : 0) \ |
| 1163 | | ((toofar32) ? 0x40000 : 0)) |
| 1164 | #define RELAX_MICROMIPS_P(i) (((i) & 0xc0000000) == 0x40000000) |
| 1165 | #define RELAX_MICROMIPS_TYPE(i) ((i) & 0xff) |
| 1166 | #define RELAX_MICROMIPS_AT(i) (((i) >> 8) & 0x1f) |
| 1167 | #define RELAX_MICROMIPS_UNCOND(i) (((i) & 0x2000) != 0) |
| 1168 | #define RELAX_MICROMIPS_COMPACT(i) (((i) & 0x4000) != 0) |
| 1169 | #define RELAX_MICROMIPS_LINK(i) (((i) & 0x8000) != 0) |
| 1170 | #define RELAX_MICROMIPS_RELAX32(i) (((i) & 0x10000) != 0) |
| 1171 | |
| 1172 | #define RELAX_MICROMIPS_TOOFAR16(i) (((i) & 0x20000) != 0) |
| 1173 | #define RELAX_MICROMIPS_MARK_TOOFAR16(i) ((i) | 0x20000) |
| 1174 | #define RELAX_MICROMIPS_CLEAR_TOOFAR16(i) ((i) & ~0x20000) |
| 1175 | #define RELAX_MICROMIPS_TOOFAR32(i) (((i) & 0x40000) != 0) |
| 1176 | #define RELAX_MICROMIPS_MARK_TOOFAR32(i) ((i) | 0x40000) |
| 1177 | #define RELAX_MICROMIPS_CLEAR_TOOFAR32(i) ((i) & ~0x40000) |
| 1178 | |
| 1179 | /* Sign-extend 16-bit value X. */ |
| 1180 | #define SEXT_16BIT(X) ((((X) + 0x8000) & 0xffff) - 0x8000) |
| 1181 | |
| 1182 | /* Is the given value a sign-extended 32-bit value? */ |
| 1183 | #define IS_SEXT_32BIT_NUM(x) \ |
| 1184 | (((x) &~ (offsetT) 0x7fffffff) == 0 \ |
| 1185 | || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff)) |
| 1186 | |
| 1187 | /* Is the given value a sign-extended 16-bit value? */ |
| 1188 | #define IS_SEXT_16BIT_NUM(x) \ |
| 1189 | (((x) &~ (offsetT) 0x7fff) == 0 \ |
| 1190 | || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff)) |
| 1191 | |
| 1192 | /* Is the given value a sign-extended 12-bit value? */ |
| 1193 | #define IS_SEXT_12BIT_NUM(x) \ |
| 1194 | (((((x) & 0xfff) ^ 0x800LL) - 0x800LL) == (x)) |
| 1195 | |
| 1196 | /* Is the given value a zero-extended 32-bit value? Or a negated one? */ |
| 1197 | #define IS_ZEXT_32BIT_NUM(x) \ |
| 1198 | (((x) &~ (offsetT) 0xffffffff) == 0 \ |
| 1199 | || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff)) |
| 1200 | |
| 1201 | /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in |
| 1202 | VALUE << SHIFT. VALUE is evaluated exactly once. */ |
| 1203 | #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \ |
| 1204 | (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \ |
| 1205 | | (((VALUE) & (MASK)) << (SHIFT))) |
| 1206 | |
| 1207 | /* Extract bits MASK << SHIFT from STRUCT and shift them right |
| 1208 | SHIFT places. */ |
| 1209 | #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \ |
| 1210 | (((STRUCT) >> (SHIFT)) & (MASK)) |
| 1211 | |
| 1212 | /* Change INSN's opcode so that the operand given by FIELD has value VALUE. |
| 1213 | INSN is a mips_cl_insn structure and VALUE is evaluated exactly once. |
| 1214 | |
| 1215 | include/opcode/mips.h specifies operand fields using the macros |
| 1216 | OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start |
| 1217 | with "MIPS16OP" instead of "OP". */ |
| 1218 | #define INSERT_OPERAND(MICROMIPS, FIELD, INSN, VALUE) \ |
| 1219 | do \ |
| 1220 | if (!(MICROMIPS)) \ |
| 1221 | INSERT_BITS ((INSN).insn_opcode, VALUE, \ |
| 1222 | OP_MASK_##FIELD, OP_SH_##FIELD); \ |
| 1223 | else \ |
| 1224 | INSERT_BITS ((INSN).insn_opcode, VALUE, \ |
| 1225 | MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD); \ |
| 1226 | while (0) |
| 1227 | #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \ |
| 1228 | INSERT_BITS ((INSN).insn_opcode, VALUE, \ |
| 1229 | MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD) |
| 1230 | |
| 1231 | /* Extract the operand given by FIELD from mips_cl_insn INSN. */ |
| 1232 | #define EXTRACT_OPERAND(MICROMIPS, FIELD, INSN) \ |
| 1233 | (!(MICROMIPS) \ |
| 1234 | ? EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD) \ |
| 1235 | : EXTRACT_BITS ((INSN).insn_opcode, \ |
| 1236 | MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD)) |
| 1237 | #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \ |
| 1238 | EXTRACT_BITS ((INSN).insn_opcode, \ |
| 1239 | MIPS16OP_MASK_##FIELD, \ |
| 1240 | MIPS16OP_SH_##FIELD) |
| 1241 | |
| 1242 | /* The MIPS16 EXTEND opcode, shifted left 16 places. */ |
| 1243 | #define MIPS16_EXTEND (0xf000U << 16) |
| 1244 | \f |
| 1245 | /* Whether or not we are emitting a branch-likely macro. */ |
| 1246 | static bfd_boolean emit_branch_likely_macro = FALSE; |
| 1247 | |
| 1248 | /* Global variables used when generating relaxable macros. See the |
| 1249 | comment above RELAX_ENCODE for more details about how relaxation |
| 1250 | is used. */ |
| 1251 | static struct { |
| 1252 | /* 0 if we're not emitting a relaxable macro. |
| 1253 | 1 if we're emitting the first of the two relaxation alternatives. |
| 1254 | 2 if we're emitting the second alternative. */ |
| 1255 | int sequence; |
| 1256 | |
| 1257 | /* The first relaxable fixup in the current frag. (In other words, |
| 1258 | the first fixup that refers to relaxable code.) */ |
| 1259 | fixS *first_fixup; |
| 1260 | |
| 1261 | /* sizes[0] says how many bytes of the first alternative are stored in |
| 1262 | the current frag. Likewise sizes[1] for the second alternative. */ |
| 1263 | unsigned int sizes[2]; |
| 1264 | |
| 1265 | /* The symbol on which the choice of sequence depends. */ |
| 1266 | symbolS *symbol; |
| 1267 | } mips_relax; |
| 1268 | \f |
| 1269 | /* Global variables used to decide whether a macro needs a warning. */ |
| 1270 | static struct { |
| 1271 | /* True if the macro is in a branch delay slot. */ |
| 1272 | bfd_boolean delay_slot_p; |
| 1273 | |
| 1274 | /* Set to the length in bytes required if the macro is in a delay slot |
| 1275 | that requires a specific length of instruction, otherwise zero. */ |
| 1276 | unsigned int delay_slot_length; |
| 1277 | |
| 1278 | /* For relaxable macros, sizes[0] is the length of the first alternative |
| 1279 | in bytes and sizes[1] is the length of the second alternative. |
| 1280 | For non-relaxable macros, both elements give the length of the |
| 1281 | macro in bytes. */ |
| 1282 | unsigned int sizes[2]; |
| 1283 | |
| 1284 | /* For relaxable macros, first_insn_sizes[0] is the length of the first |
| 1285 | instruction of the first alternative in bytes and first_insn_sizes[1] |
| 1286 | is the length of the first instruction of the second alternative. |
| 1287 | For non-relaxable macros, both elements give the length of the first |
| 1288 | instruction in bytes. |
| 1289 | |
| 1290 | Set to zero if we haven't yet seen the first instruction. */ |
| 1291 | unsigned int first_insn_sizes[2]; |
| 1292 | |
| 1293 | /* For relaxable macros, insns[0] is the number of instructions for the |
| 1294 | first alternative and insns[1] is the number of instructions for the |
| 1295 | second alternative. |
| 1296 | |
| 1297 | For non-relaxable macros, both elements give the number of |
| 1298 | instructions for the macro. */ |
| 1299 | unsigned int insns[2]; |
| 1300 | |
| 1301 | /* The first variant frag for this macro. */ |
| 1302 | fragS *first_frag; |
| 1303 | } mips_macro_warning; |
| 1304 | \f |
| 1305 | /* Prototypes for static functions. */ |
| 1306 | |
| 1307 | #define internalError() \ |
| 1308 | as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__) |
| 1309 | |
| 1310 | enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG }; |
| 1311 | |
| 1312 | static void append_insn |
| 1313 | (struct mips_cl_insn *, expressionS *, bfd_reloc_code_real_type *, |
| 1314 | bfd_boolean expansionp); |
| 1315 | static void mips_no_prev_insn (void); |
| 1316 | static void macro_build (expressionS *, const char *, const char *, ...); |
| 1317 | static void mips16_macro_build |
| 1318 | (expressionS *, const char *, const char *, va_list *); |
| 1319 | static void load_register (int, expressionS *, int); |
| 1320 | static void macro_start (void); |
| 1321 | static void macro_end (void); |
| 1322 | static void macro (struct mips_cl_insn * ip); |
| 1323 | static void mips16_macro (struct mips_cl_insn * ip); |
| 1324 | static void mips_ip (char *str, struct mips_cl_insn * ip); |
| 1325 | static void mips16_ip (char *str, struct mips_cl_insn * ip); |
| 1326 | static void mips16_immed |
| 1327 | (char *, unsigned int, int, bfd_reloc_code_real_type, offsetT, |
| 1328 | unsigned int, unsigned long *); |
| 1329 | static size_t my_getSmallExpression |
| 1330 | (expressionS *, bfd_reloc_code_real_type *, char *); |
| 1331 | static void my_getExpression (expressionS *, char *); |
| 1332 | static void s_align (int); |
| 1333 | static void s_change_sec (int); |
| 1334 | static void s_change_section (int); |
| 1335 | static void s_cons (int); |
| 1336 | static void s_float_cons (int); |
| 1337 | static void s_mips_globl (int); |
| 1338 | static void s_option (int); |
| 1339 | static void s_mipsset (int); |
| 1340 | static void s_abicalls (int); |
| 1341 | static void s_cpload (int); |
| 1342 | static void s_cpsetup (int); |
| 1343 | static void s_cplocal (int); |
| 1344 | static void s_cprestore (int); |
| 1345 | static void s_cpreturn (int); |
| 1346 | static void s_dtprelword (int); |
| 1347 | static void s_dtpreldword (int); |
| 1348 | static void s_tprelword (int); |
| 1349 | static void s_tpreldword (int); |
| 1350 | static void s_gpvalue (int); |
| 1351 | static void s_gpword (int); |
| 1352 | static void s_gpdword (int); |
| 1353 | static void s_cpadd (int); |
| 1354 | static void s_insn (int); |
| 1355 | static void md_obj_begin (void); |
| 1356 | static void md_obj_end (void); |
| 1357 | static void s_mips_ent (int); |
| 1358 | static void s_mips_end (int); |
| 1359 | static void s_mips_frame (int); |
| 1360 | static void s_mips_mask (int reg_type); |
| 1361 | static void s_mips_stab (int); |
| 1362 | static void s_mips_weakext (int); |
| 1363 | static void s_mips_file (int); |
| 1364 | static void s_mips_loc (int); |
| 1365 | static bfd_boolean pic_need_relax (symbolS *, asection *); |
| 1366 | static int relaxed_branch_length (fragS *, asection *, int); |
| 1367 | static int validate_mips_insn (const struct mips_opcode *); |
| 1368 | static int validate_micromips_insn (const struct mips_opcode *); |
| 1369 | static int relaxed_micromips_16bit_branch_length (fragS *, asection *, int); |
| 1370 | static int relaxed_micromips_32bit_branch_length (fragS *, asection *, int); |
| 1371 | |
| 1372 | /* Table and functions used to map between CPU/ISA names, and |
| 1373 | ISA levels, and CPU numbers. */ |
| 1374 | |
| 1375 | struct mips_cpu_info |
| 1376 | { |
| 1377 | const char *name; /* CPU or ISA name. */ |
| 1378 | int flags; /* ASEs available, or ISA flag. */ |
| 1379 | int isa; /* ISA level. */ |
| 1380 | int cpu; /* CPU number (default CPU if ISA). */ |
| 1381 | }; |
| 1382 | |
| 1383 | #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */ |
| 1384 | #define MIPS_CPU_ASE_SMARTMIPS 0x0002 /* CPU implements SmartMIPS ASE */ |
| 1385 | #define MIPS_CPU_ASE_DSP 0x0004 /* CPU implements DSP ASE */ |
| 1386 | #define MIPS_CPU_ASE_MT 0x0008 /* CPU implements MT ASE */ |
| 1387 | #define MIPS_CPU_ASE_MIPS3D 0x0010 /* CPU implements MIPS-3D ASE */ |
| 1388 | #define MIPS_CPU_ASE_MDMX 0x0020 /* CPU implements MDMX ASE */ |
| 1389 | #define MIPS_CPU_ASE_DSPR2 0x0040 /* CPU implements DSP R2 ASE */ |
| 1390 | #define MIPS_CPU_ASE_MCU 0x0080 /* CPU implements MCU ASE */ |
| 1391 | |
| 1392 | static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *); |
| 1393 | static const struct mips_cpu_info *mips_cpu_info_from_isa (int); |
| 1394 | static const struct mips_cpu_info *mips_cpu_info_from_arch (int); |
| 1395 | \f |
| 1396 | /* Pseudo-op table. |
| 1397 | |
| 1398 | The following pseudo-ops from the Kane and Heinrich MIPS book |
| 1399 | should be defined here, but are currently unsupported: .alias, |
| 1400 | .galive, .gjaldef, .gjrlive, .livereg, .noalias. |
| 1401 | |
| 1402 | The following pseudo-ops from the Kane and Heinrich MIPS book are |
| 1403 | specific to the type of debugging information being generated, and |
| 1404 | should be defined by the object format: .aent, .begin, .bend, |
| 1405 | .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp, |
| 1406 | .vreg. |
| 1407 | |
| 1408 | The following pseudo-ops from the Kane and Heinrich MIPS book are |
| 1409 | not MIPS CPU specific, but are also not specific to the object file |
| 1410 | format. This file is probably the best place to define them, but |
| 1411 | they are not currently supported: .asm0, .endr, .lab, .struct. */ |
| 1412 | |
| 1413 | static const pseudo_typeS mips_pseudo_table[] = |
| 1414 | { |
| 1415 | /* MIPS specific pseudo-ops. */ |
| 1416 | {"option", s_option, 0}, |
| 1417 | {"set", s_mipsset, 0}, |
| 1418 | {"rdata", s_change_sec, 'r'}, |
| 1419 | {"sdata", s_change_sec, 's'}, |
| 1420 | {"livereg", s_ignore, 0}, |
| 1421 | {"abicalls", s_abicalls, 0}, |
| 1422 | {"cpload", s_cpload, 0}, |
| 1423 | {"cpsetup", s_cpsetup, 0}, |
| 1424 | {"cplocal", s_cplocal, 0}, |
| 1425 | {"cprestore", s_cprestore, 0}, |
| 1426 | {"cpreturn", s_cpreturn, 0}, |
| 1427 | {"dtprelword", s_dtprelword, 0}, |
| 1428 | {"dtpreldword", s_dtpreldword, 0}, |
| 1429 | {"tprelword", s_tprelword, 0}, |
| 1430 | {"tpreldword", s_tpreldword, 0}, |
| 1431 | {"gpvalue", s_gpvalue, 0}, |
| 1432 | {"gpword", s_gpword, 0}, |
| 1433 | {"gpdword", s_gpdword, 0}, |
| 1434 | {"cpadd", s_cpadd, 0}, |
| 1435 | {"insn", s_insn, 0}, |
| 1436 | |
| 1437 | /* Relatively generic pseudo-ops that happen to be used on MIPS |
| 1438 | chips. */ |
| 1439 | {"asciiz", stringer, 8 + 1}, |
| 1440 | {"bss", s_change_sec, 'b'}, |
| 1441 | {"err", s_err, 0}, |
| 1442 | {"half", s_cons, 1}, |
| 1443 | {"dword", s_cons, 3}, |
| 1444 | {"weakext", s_mips_weakext, 0}, |
| 1445 | {"origin", s_org, 0}, |
| 1446 | {"repeat", s_rept, 0}, |
| 1447 | |
| 1448 | /* For MIPS this is non-standard, but we define it for consistency. */ |
| 1449 | {"sbss", s_change_sec, 'B'}, |
| 1450 | |
| 1451 | /* These pseudo-ops are defined in read.c, but must be overridden |
| 1452 | here for one reason or another. */ |
| 1453 | {"align", s_align, 0}, |
| 1454 | {"byte", s_cons, 0}, |
| 1455 | {"data", s_change_sec, 'd'}, |
| 1456 | {"double", s_float_cons, 'd'}, |
| 1457 | {"float", s_float_cons, 'f'}, |
| 1458 | {"globl", s_mips_globl, 0}, |
| 1459 | {"global", s_mips_globl, 0}, |
| 1460 | {"hword", s_cons, 1}, |
| 1461 | {"int", s_cons, 2}, |
| 1462 | {"long", s_cons, 2}, |
| 1463 | {"octa", s_cons, 4}, |
| 1464 | {"quad", s_cons, 3}, |
| 1465 | {"section", s_change_section, 0}, |
| 1466 | {"short", s_cons, 1}, |
| 1467 | {"single", s_float_cons, 'f'}, |
| 1468 | {"stabn", s_mips_stab, 'n'}, |
| 1469 | {"text", s_change_sec, 't'}, |
| 1470 | {"word", s_cons, 2}, |
| 1471 | |
| 1472 | { "extern", ecoff_directive_extern, 0}, |
| 1473 | |
| 1474 | { NULL, NULL, 0 }, |
| 1475 | }; |
| 1476 | |
| 1477 | static const pseudo_typeS mips_nonecoff_pseudo_table[] = |
| 1478 | { |
| 1479 | /* These pseudo-ops should be defined by the object file format. |
| 1480 | However, a.out doesn't support them, so we have versions here. */ |
| 1481 | {"aent", s_mips_ent, 1}, |
| 1482 | {"bgnb", s_ignore, 0}, |
| 1483 | {"end", s_mips_end, 0}, |
| 1484 | {"endb", s_ignore, 0}, |
| 1485 | {"ent", s_mips_ent, 0}, |
| 1486 | {"file", s_mips_file, 0}, |
| 1487 | {"fmask", s_mips_mask, 'F'}, |
| 1488 | {"frame", s_mips_frame, 0}, |
| 1489 | {"loc", s_mips_loc, 0}, |
| 1490 | {"mask", s_mips_mask, 'R'}, |
| 1491 | {"verstamp", s_ignore, 0}, |
| 1492 | { NULL, NULL, 0 }, |
| 1493 | }; |
| 1494 | |
| 1495 | /* Export the ABI address size for use by TC_ADDRESS_BYTES for the |
| 1496 | purpose of the `.dc.a' internal pseudo-op. */ |
| 1497 | |
| 1498 | int |
| 1499 | mips_address_bytes (void) |
| 1500 | { |
| 1501 | return HAVE_64BIT_ADDRESSES ? 8 : 4; |
| 1502 | } |
| 1503 | |
| 1504 | extern void pop_insert (const pseudo_typeS *); |
| 1505 | |
| 1506 | void |
| 1507 | mips_pop_insert (void) |
| 1508 | { |
| 1509 | pop_insert (mips_pseudo_table); |
| 1510 | if (! ECOFF_DEBUGGING) |
| 1511 | pop_insert (mips_nonecoff_pseudo_table); |
| 1512 | } |
| 1513 | \f |
| 1514 | /* Symbols labelling the current insn. */ |
| 1515 | |
| 1516 | struct insn_label_list |
| 1517 | { |
| 1518 | struct insn_label_list *next; |
| 1519 | symbolS *label; |
| 1520 | }; |
| 1521 | |
| 1522 | static struct insn_label_list *free_insn_labels; |
| 1523 | #define label_list tc_segment_info_data.labels |
| 1524 | |
| 1525 | static void mips_clear_insn_labels (void); |
| 1526 | static void mips_mark_labels (void); |
| 1527 | static void mips_compressed_mark_labels (void); |
| 1528 | |
| 1529 | static inline void |
| 1530 | mips_clear_insn_labels (void) |
| 1531 | { |
| 1532 | register struct insn_label_list **pl; |
| 1533 | segment_info_type *si; |
| 1534 | |
| 1535 | if (now_seg) |
| 1536 | { |
| 1537 | for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next) |
| 1538 | ; |
| 1539 | |
| 1540 | si = seg_info (now_seg); |
| 1541 | *pl = si->label_list; |
| 1542 | si->label_list = NULL; |
| 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | /* Mark instruction labels in MIPS16/microMIPS mode. */ |
| 1547 | |
| 1548 | static inline void |
| 1549 | mips_mark_labels (void) |
| 1550 | { |
| 1551 | if (HAVE_CODE_COMPRESSION) |
| 1552 | mips_compressed_mark_labels (); |
| 1553 | } |
| 1554 | \f |
| 1555 | static char *expr_end; |
| 1556 | |
| 1557 | /* Expressions which appear in instructions. These are set by |
| 1558 | mips_ip. */ |
| 1559 | |
| 1560 | static expressionS imm_expr; |
| 1561 | static expressionS imm2_expr; |
| 1562 | static expressionS offset_expr; |
| 1563 | |
| 1564 | /* Relocs associated with imm_expr and offset_expr. */ |
| 1565 | |
| 1566 | static bfd_reloc_code_real_type imm_reloc[3] |
| 1567 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; |
| 1568 | static bfd_reloc_code_real_type offset_reloc[3] |
| 1569 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; |
| 1570 | |
| 1571 | /* This is set to the resulting size of the instruction to be produced |
| 1572 | by mips16_ip if an explicit extension is used or by mips_ip if an |
| 1573 | explicit size is supplied. */ |
| 1574 | |
| 1575 | static unsigned int forced_insn_length; |
| 1576 | |
| 1577 | /* True if we are assembling an instruction. All dot symbols defined during |
| 1578 | this time should be treated as code labels. */ |
| 1579 | |
| 1580 | static bfd_boolean mips_assembling_insn; |
| 1581 | |
| 1582 | #ifdef OBJ_ELF |
| 1583 | /* The pdr segment for per procedure frame/regmask info. Not used for |
| 1584 | ECOFF debugging. */ |
| 1585 | |
| 1586 | static segT pdr_seg; |
| 1587 | #endif |
| 1588 | |
| 1589 | /* The default target format to use. */ |
| 1590 | |
| 1591 | #if defined (TE_FreeBSD) |
| 1592 | #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips-freebsd" |
| 1593 | #elif defined (TE_TMIPS) |
| 1594 | #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips" |
| 1595 | #else |
| 1596 | #define ELF_TARGET(PREFIX, ENDIAN) PREFIX ENDIAN "mips" |
| 1597 | #endif |
| 1598 | |
| 1599 | const char * |
| 1600 | mips_target_format (void) |
| 1601 | { |
| 1602 | switch (OUTPUT_FLAVOR) |
| 1603 | { |
| 1604 | case bfd_target_ecoff_flavour: |
| 1605 | return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT; |
| 1606 | case bfd_target_coff_flavour: |
| 1607 | return "pe-mips"; |
| 1608 | case bfd_target_elf_flavour: |
| 1609 | #ifdef TE_VXWORKS |
| 1610 | if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI) |
| 1611 | return (target_big_endian |
| 1612 | ? "elf32-bigmips-vxworks" |
| 1613 | : "elf32-littlemips-vxworks"); |
| 1614 | #endif |
| 1615 | return (target_big_endian |
| 1616 | ? (HAVE_64BIT_OBJECTS |
| 1617 | ? ELF_TARGET ("elf64-", "big") |
| 1618 | : (HAVE_NEWABI |
| 1619 | ? ELF_TARGET ("elf32-n", "big") |
| 1620 | : ELF_TARGET ("elf32-", "big"))) |
| 1621 | : (HAVE_64BIT_OBJECTS |
| 1622 | ? ELF_TARGET ("elf64-", "little") |
| 1623 | : (HAVE_NEWABI |
| 1624 | ? ELF_TARGET ("elf32-n", "little") |
| 1625 | : ELF_TARGET ("elf32-", "little")))); |
| 1626 | default: |
| 1627 | abort (); |
| 1628 | return NULL; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | /* Return the length of a microMIPS instruction in bytes. If bits of |
| 1633 | the mask beyond the low 16 are 0, then it is a 16-bit instruction. |
| 1634 | Otherwise assume a 32-bit instruction; 48-bit instructions (0x1f |
| 1635 | major opcode) will require further modifications to the opcode |
| 1636 | table. */ |
| 1637 | |
| 1638 | static inline unsigned int |
| 1639 | micromips_insn_length (const struct mips_opcode *mo) |
| 1640 | { |
| 1641 | return (mo->mask >> 16) == 0 ? 2 : 4; |
| 1642 | } |
| 1643 | |
| 1644 | /* Return the length of MIPS16 instruction OPCODE. */ |
| 1645 | |
| 1646 | static inline unsigned int |
| 1647 | mips16_opcode_length (unsigned long opcode) |
| 1648 | { |
| 1649 | return (opcode >> 16) == 0 ? 2 : 4; |
| 1650 | } |
| 1651 | |
| 1652 | /* Return the length of instruction INSN. */ |
| 1653 | |
| 1654 | static inline unsigned int |
| 1655 | insn_length (const struct mips_cl_insn *insn) |
| 1656 | { |
| 1657 | if (mips_opts.micromips) |
| 1658 | return micromips_insn_length (insn->insn_mo); |
| 1659 | else if (mips_opts.mips16) |
| 1660 | return mips16_opcode_length (insn->insn_opcode); |
| 1661 | else |
| 1662 | return 4; |
| 1663 | } |
| 1664 | |
| 1665 | /* Initialise INSN from opcode entry MO. Leave its position unspecified. */ |
| 1666 | |
| 1667 | static void |
| 1668 | create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo) |
| 1669 | { |
| 1670 | size_t i; |
| 1671 | |
| 1672 | insn->insn_mo = mo; |
| 1673 | insn->insn_opcode = mo->match; |
| 1674 | insn->frag = NULL; |
| 1675 | insn->where = 0; |
| 1676 | for (i = 0; i < ARRAY_SIZE (insn->fixp); i++) |
| 1677 | insn->fixp[i] = NULL; |
| 1678 | insn->fixed_p = (mips_opts.noreorder > 0); |
| 1679 | insn->noreorder_p = (mips_opts.noreorder > 0); |
| 1680 | insn->mips16_absolute_jump_p = 0; |
| 1681 | insn->complete_p = 0; |
| 1682 | } |
| 1683 | |
| 1684 | /* Record the current MIPS16/microMIPS mode in now_seg. */ |
| 1685 | |
| 1686 | static void |
| 1687 | mips_record_compressed_mode (void) |
| 1688 | { |
| 1689 | segment_info_type *si; |
| 1690 | |
| 1691 | si = seg_info (now_seg); |
| 1692 | if (si->tc_segment_info_data.mips16 != mips_opts.mips16) |
| 1693 | si->tc_segment_info_data.mips16 = mips_opts.mips16; |
| 1694 | if (si->tc_segment_info_data.micromips != mips_opts.micromips) |
| 1695 | si->tc_segment_info_data.micromips = mips_opts.micromips; |
| 1696 | } |
| 1697 | |
| 1698 | /* Read a standard MIPS instruction from BUF. */ |
| 1699 | |
| 1700 | static unsigned long |
| 1701 | read_insn (char *buf) |
| 1702 | { |
| 1703 | if (target_big_endian) |
| 1704 | return bfd_getb32 ((bfd_byte *) buf); |
| 1705 | else |
| 1706 | return bfd_getl32 ((bfd_byte *) buf); |
| 1707 | } |
| 1708 | |
| 1709 | /* Write standard MIPS instruction INSN to BUF. Return a pointer to |
| 1710 | the next byte. */ |
| 1711 | |
| 1712 | static char * |
| 1713 | write_insn (char *buf, unsigned int insn) |
| 1714 | { |
| 1715 | md_number_to_chars (buf, insn, 4); |
| 1716 | return buf + 4; |
| 1717 | } |
| 1718 | |
| 1719 | /* Read a microMIPS or MIPS16 opcode from BUF, given that it |
| 1720 | has length LENGTH. */ |
| 1721 | |
| 1722 | static unsigned long |
| 1723 | read_compressed_insn (char *buf, unsigned int length) |
| 1724 | { |
| 1725 | unsigned long insn; |
| 1726 | unsigned int i; |
| 1727 | |
| 1728 | insn = 0; |
| 1729 | for (i = 0; i < length; i += 2) |
| 1730 | { |
| 1731 | insn <<= 16; |
| 1732 | if (target_big_endian) |
| 1733 | insn |= bfd_getb16 ((char *) buf); |
| 1734 | else |
| 1735 | insn |= bfd_getl16 ((char *) buf); |
| 1736 | buf += 2; |
| 1737 | } |
| 1738 | return insn; |
| 1739 | } |
| 1740 | |
| 1741 | /* Write microMIPS or MIPS16 instruction INSN to BUF, given that the |
| 1742 | instruction is LENGTH bytes long. Return a pointer to the next byte. */ |
| 1743 | |
| 1744 | static char * |
| 1745 | write_compressed_insn (char *buf, unsigned int insn, unsigned int length) |
| 1746 | { |
| 1747 | unsigned int i; |
| 1748 | |
| 1749 | for (i = 0; i < length; i += 2) |
| 1750 | md_number_to_chars (buf + i, insn >> ((length - i - 2) * 8), 2); |
| 1751 | return buf + length; |
| 1752 | } |
| 1753 | |
| 1754 | /* Install INSN at the location specified by its "frag" and "where" fields. */ |
| 1755 | |
| 1756 | static void |
| 1757 | install_insn (const struct mips_cl_insn *insn) |
| 1758 | { |
| 1759 | char *f = insn->frag->fr_literal + insn->where; |
| 1760 | if (HAVE_CODE_COMPRESSION) |
| 1761 | write_compressed_insn (f, insn->insn_opcode, insn_length (insn)); |
| 1762 | else |
| 1763 | write_insn (f, insn->insn_opcode); |
| 1764 | mips_record_compressed_mode (); |
| 1765 | } |
| 1766 | |
| 1767 | /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly |
| 1768 | and install the opcode in the new location. */ |
| 1769 | |
| 1770 | static void |
| 1771 | move_insn (struct mips_cl_insn *insn, fragS *frag, long where) |
| 1772 | { |
| 1773 | size_t i; |
| 1774 | |
| 1775 | insn->frag = frag; |
| 1776 | insn->where = where; |
| 1777 | for (i = 0; i < ARRAY_SIZE (insn->fixp); i++) |
| 1778 | if (insn->fixp[i] != NULL) |
| 1779 | { |
| 1780 | insn->fixp[i]->fx_frag = frag; |
| 1781 | insn->fixp[i]->fx_where = where; |
| 1782 | } |
| 1783 | install_insn (insn); |
| 1784 | } |
| 1785 | |
| 1786 | /* Add INSN to the end of the output. */ |
| 1787 | |
| 1788 | static void |
| 1789 | add_fixed_insn (struct mips_cl_insn *insn) |
| 1790 | { |
| 1791 | char *f = frag_more (insn_length (insn)); |
| 1792 | move_insn (insn, frag_now, f - frag_now->fr_literal); |
| 1793 | } |
| 1794 | |
| 1795 | /* Start a variant frag and move INSN to the start of the variant part, |
| 1796 | marking it as fixed. The other arguments are as for frag_var. */ |
| 1797 | |
| 1798 | static void |
| 1799 | add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var, |
| 1800 | relax_substateT subtype, symbolS *symbol, offsetT offset) |
| 1801 | { |
| 1802 | frag_grow (max_chars); |
| 1803 | move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal); |
| 1804 | insn->fixed_p = 1; |
| 1805 | frag_var (rs_machine_dependent, max_chars, var, |
| 1806 | subtype, symbol, offset, NULL); |
| 1807 | } |
| 1808 | |
| 1809 | /* Insert N copies of INSN into the history buffer, starting at |
| 1810 | position FIRST. Neither FIRST nor N need to be clipped. */ |
| 1811 | |
| 1812 | static void |
| 1813 | insert_into_history (unsigned int first, unsigned int n, |
| 1814 | const struct mips_cl_insn *insn) |
| 1815 | { |
| 1816 | if (mips_relax.sequence != 2) |
| 1817 | { |
| 1818 | unsigned int i; |
| 1819 | |
| 1820 | for (i = ARRAY_SIZE (history); i-- > first;) |
| 1821 | if (i >= first + n) |
| 1822 | history[i] = history[i - n]; |
| 1823 | else |
| 1824 | history[i] = *insn; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | /* Initialize vr4120_conflicts. There is a bit of duplication here: |
| 1829 | the idea is to make it obvious at a glance that each errata is |
| 1830 | included. */ |
| 1831 | |
| 1832 | static void |
| 1833 | init_vr4120_conflicts (void) |
| 1834 | { |
| 1835 | #define CONFLICT(FIRST, SECOND) \ |
| 1836 | vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND |
| 1837 | |
| 1838 | /* Errata 21 - [D]DIV[U] after [D]MACC */ |
| 1839 | CONFLICT (MACC, DIV); |
| 1840 | CONFLICT (DMACC, DIV); |
| 1841 | |
| 1842 | /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */ |
| 1843 | CONFLICT (DMULT, DMULT); |
| 1844 | CONFLICT (DMULT, DMACC); |
| 1845 | CONFLICT (DMACC, DMULT); |
| 1846 | CONFLICT (DMACC, DMACC); |
| 1847 | |
| 1848 | /* Errata 24 - MT{LO,HI} after [D]MACC */ |
| 1849 | CONFLICT (MACC, MTHILO); |
| 1850 | CONFLICT (DMACC, MTHILO); |
| 1851 | |
| 1852 | /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU |
| 1853 | instruction is executed immediately after a MACC or DMACC |
| 1854 | instruction, the result of [either instruction] is incorrect." */ |
| 1855 | CONFLICT (MACC, MULT); |
| 1856 | CONFLICT (MACC, DMULT); |
| 1857 | CONFLICT (DMACC, MULT); |
| 1858 | CONFLICT (DMACC, DMULT); |
| 1859 | |
| 1860 | /* VR4181A errata MD(4): "If a MACC or DMACC instruction is |
| 1861 | executed immediately after a DMULT, DMULTU, DIV, DIVU, |
| 1862 | DDIV or DDIVU instruction, the result of the MACC or |
| 1863 | DMACC instruction is incorrect.". */ |
| 1864 | CONFLICT (DMULT, MACC); |
| 1865 | CONFLICT (DMULT, DMACC); |
| 1866 | CONFLICT (DIV, MACC); |
| 1867 | CONFLICT (DIV, DMACC); |
| 1868 | |
| 1869 | #undef CONFLICT |
| 1870 | } |
| 1871 | |
| 1872 | struct regname { |
| 1873 | const char *name; |
| 1874 | unsigned int num; |
| 1875 | }; |
| 1876 | |
| 1877 | #define RTYPE_MASK 0x1ff00 |
| 1878 | #define RTYPE_NUM 0x00100 |
| 1879 | #define RTYPE_FPU 0x00200 |
| 1880 | #define RTYPE_FCC 0x00400 |
| 1881 | #define RTYPE_VEC 0x00800 |
| 1882 | #define RTYPE_GP 0x01000 |
| 1883 | #define RTYPE_CP0 0x02000 |
| 1884 | #define RTYPE_PC 0x04000 |
| 1885 | #define RTYPE_ACC 0x08000 |
| 1886 | #define RTYPE_CCC 0x10000 |
| 1887 | #define RNUM_MASK 0x000ff |
| 1888 | #define RWARN 0x80000 |
| 1889 | |
| 1890 | #define GENERIC_REGISTER_NUMBERS \ |
| 1891 | {"$0", RTYPE_NUM | 0}, \ |
| 1892 | {"$1", RTYPE_NUM | 1}, \ |
| 1893 | {"$2", RTYPE_NUM | 2}, \ |
| 1894 | {"$3", RTYPE_NUM | 3}, \ |
| 1895 | {"$4", RTYPE_NUM | 4}, \ |
| 1896 | {"$5", RTYPE_NUM | 5}, \ |
| 1897 | {"$6", RTYPE_NUM | 6}, \ |
| 1898 | {"$7", RTYPE_NUM | 7}, \ |
| 1899 | {"$8", RTYPE_NUM | 8}, \ |
| 1900 | {"$9", RTYPE_NUM | 9}, \ |
| 1901 | {"$10", RTYPE_NUM | 10}, \ |
| 1902 | {"$11", RTYPE_NUM | 11}, \ |
| 1903 | {"$12", RTYPE_NUM | 12}, \ |
| 1904 | {"$13", RTYPE_NUM | 13}, \ |
| 1905 | {"$14", RTYPE_NUM | 14}, \ |
| 1906 | {"$15", RTYPE_NUM | 15}, \ |
| 1907 | {"$16", RTYPE_NUM | 16}, \ |
| 1908 | {"$17", RTYPE_NUM | 17}, \ |
| 1909 | {"$18", RTYPE_NUM | 18}, \ |
| 1910 | {"$19", RTYPE_NUM | 19}, \ |
| 1911 | {"$20", RTYPE_NUM | 20}, \ |
| 1912 | {"$21", RTYPE_NUM | 21}, \ |
| 1913 | {"$22", RTYPE_NUM | 22}, \ |
| 1914 | {"$23", RTYPE_NUM | 23}, \ |
| 1915 | {"$24", RTYPE_NUM | 24}, \ |
| 1916 | {"$25", RTYPE_NUM | 25}, \ |
| 1917 | {"$26", RTYPE_NUM | 26}, \ |
| 1918 | {"$27", RTYPE_NUM | 27}, \ |
| 1919 | {"$28", RTYPE_NUM | 28}, \ |
| 1920 | {"$29", RTYPE_NUM | 29}, \ |
| 1921 | {"$30", RTYPE_NUM | 30}, \ |
| 1922 | {"$31", RTYPE_NUM | 31} |
| 1923 | |
| 1924 | #define FPU_REGISTER_NAMES \ |
| 1925 | {"$f0", RTYPE_FPU | 0}, \ |
| 1926 | {"$f1", RTYPE_FPU | 1}, \ |
| 1927 | {"$f2", RTYPE_FPU | 2}, \ |
| 1928 | {"$f3", RTYPE_FPU | 3}, \ |
| 1929 | {"$f4", RTYPE_FPU | 4}, \ |
| 1930 | {"$f5", RTYPE_FPU | 5}, \ |
| 1931 | {"$f6", RTYPE_FPU | 6}, \ |
| 1932 | {"$f7", RTYPE_FPU | 7}, \ |
| 1933 | {"$f8", RTYPE_FPU | 8}, \ |
| 1934 | {"$f9", RTYPE_FPU | 9}, \ |
| 1935 | {"$f10", RTYPE_FPU | 10}, \ |
| 1936 | {"$f11", RTYPE_FPU | 11}, \ |
| 1937 | {"$f12", RTYPE_FPU | 12}, \ |
| 1938 | {"$f13", RTYPE_FPU | 13}, \ |
| 1939 | {"$f14", RTYPE_FPU | 14}, \ |
| 1940 | {"$f15", RTYPE_FPU | 15}, \ |
| 1941 | {"$f16", RTYPE_FPU | 16}, \ |
| 1942 | {"$f17", RTYPE_FPU | 17}, \ |
| 1943 | {"$f18", RTYPE_FPU | 18}, \ |
| 1944 | {"$f19", RTYPE_FPU | 19}, \ |
| 1945 | {"$f20", RTYPE_FPU | 20}, \ |
| 1946 | {"$f21", RTYPE_FPU | 21}, \ |
| 1947 | {"$f22", RTYPE_FPU | 22}, \ |
| 1948 | {"$f23", RTYPE_FPU | 23}, \ |
| 1949 | {"$f24", RTYPE_FPU | 24}, \ |
| 1950 | {"$f25", RTYPE_FPU | 25}, \ |
| 1951 | {"$f26", RTYPE_FPU | 26}, \ |
| 1952 | {"$f27", RTYPE_FPU | 27}, \ |
| 1953 | {"$f28", RTYPE_FPU | 28}, \ |
| 1954 | {"$f29", RTYPE_FPU | 29}, \ |
| 1955 | {"$f30", RTYPE_FPU | 30}, \ |
| 1956 | {"$f31", RTYPE_FPU | 31} |
| 1957 | |
| 1958 | #define FPU_CONDITION_CODE_NAMES \ |
| 1959 | {"$fcc0", RTYPE_FCC | 0}, \ |
| 1960 | {"$fcc1", RTYPE_FCC | 1}, \ |
| 1961 | {"$fcc2", RTYPE_FCC | 2}, \ |
| 1962 | {"$fcc3", RTYPE_FCC | 3}, \ |
| 1963 | {"$fcc4", RTYPE_FCC | 4}, \ |
| 1964 | {"$fcc5", RTYPE_FCC | 5}, \ |
| 1965 | {"$fcc6", RTYPE_FCC | 6}, \ |
| 1966 | {"$fcc7", RTYPE_FCC | 7} |
| 1967 | |
| 1968 | #define COPROC_CONDITION_CODE_NAMES \ |
| 1969 | {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \ |
| 1970 | {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \ |
| 1971 | {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \ |
| 1972 | {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \ |
| 1973 | {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \ |
| 1974 | {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \ |
| 1975 | {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \ |
| 1976 | {"$cc7", RTYPE_FCC | RTYPE_CCC | 7} |
| 1977 | |
| 1978 | #define N32N64_SYMBOLIC_REGISTER_NAMES \ |
| 1979 | {"$a4", RTYPE_GP | 8}, \ |
| 1980 | {"$a5", RTYPE_GP | 9}, \ |
| 1981 | {"$a6", RTYPE_GP | 10}, \ |
| 1982 | {"$a7", RTYPE_GP | 11}, \ |
| 1983 | {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \ |
| 1984 | {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \ |
| 1985 | {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \ |
| 1986 | {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \ |
| 1987 | {"$t0", RTYPE_GP | 12}, \ |
| 1988 | {"$t1", RTYPE_GP | 13}, \ |
| 1989 | {"$t2", RTYPE_GP | 14}, \ |
| 1990 | {"$t3", RTYPE_GP | 15} |
| 1991 | |
| 1992 | #define O32_SYMBOLIC_REGISTER_NAMES \ |
| 1993 | {"$t0", RTYPE_GP | 8}, \ |
| 1994 | {"$t1", RTYPE_GP | 9}, \ |
| 1995 | {"$t2", RTYPE_GP | 10}, \ |
| 1996 | {"$t3", RTYPE_GP | 11}, \ |
| 1997 | {"$t4", RTYPE_GP | 12}, \ |
| 1998 | {"$t5", RTYPE_GP | 13}, \ |
| 1999 | {"$t6", RTYPE_GP | 14}, \ |
| 2000 | {"$t7", RTYPE_GP | 15}, \ |
| 2001 | {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \ |
| 2002 | {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \ |
| 2003 | {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \ |
| 2004 | {"$ta3", RTYPE_GP | 15} /* alias for $t7 */ |
| 2005 | |
| 2006 | /* Remaining symbolic register names */ |
| 2007 | #define SYMBOLIC_REGISTER_NAMES \ |
| 2008 | {"$zero", RTYPE_GP | 0}, \ |
| 2009 | {"$at", RTYPE_GP | 1}, \ |
| 2010 | {"$AT", RTYPE_GP | 1}, \ |
| 2011 | {"$v0", RTYPE_GP | 2}, \ |
| 2012 | {"$v1", RTYPE_GP | 3}, \ |
| 2013 | {"$a0", RTYPE_GP | 4}, \ |
| 2014 | {"$a1", RTYPE_GP | 5}, \ |
| 2015 | {"$a2", RTYPE_GP | 6}, \ |
| 2016 | {"$a3", RTYPE_GP | 7}, \ |
| 2017 | {"$s0", RTYPE_GP | 16}, \ |
| 2018 | {"$s1", RTYPE_GP | 17}, \ |
| 2019 | {"$s2", RTYPE_GP | 18}, \ |
| 2020 | {"$s3", RTYPE_GP | 19}, \ |
| 2021 | {"$s4", RTYPE_GP | 20}, \ |
| 2022 | {"$s5", RTYPE_GP | 21}, \ |
| 2023 | {"$s6", RTYPE_GP | 22}, \ |
| 2024 | {"$s7", RTYPE_GP | 23}, \ |
| 2025 | {"$t8", RTYPE_GP | 24}, \ |
| 2026 | {"$t9", RTYPE_GP | 25}, \ |
| 2027 | {"$k0", RTYPE_GP | 26}, \ |
| 2028 | {"$kt0", RTYPE_GP | 26}, \ |
| 2029 | {"$k1", RTYPE_GP | 27}, \ |
| 2030 | {"$kt1", RTYPE_GP | 27}, \ |
| 2031 | {"$gp", RTYPE_GP | 28}, \ |
| 2032 | {"$sp", RTYPE_GP | 29}, \ |
| 2033 | {"$s8", RTYPE_GP | 30}, \ |
| 2034 | {"$fp", RTYPE_GP | 30}, \ |
| 2035 | {"$ra", RTYPE_GP | 31} |
| 2036 | |
| 2037 | #define MIPS16_SPECIAL_REGISTER_NAMES \ |
| 2038 | {"$pc", RTYPE_PC | 0} |
| 2039 | |
| 2040 | #define MDMX_VECTOR_REGISTER_NAMES \ |
| 2041 | /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \ |
| 2042 | /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \ |
| 2043 | {"$v2", RTYPE_VEC | 2}, \ |
| 2044 | {"$v3", RTYPE_VEC | 3}, \ |
| 2045 | {"$v4", RTYPE_VEC | 4}, \ |
| 2046 | {"$v5", RTYPE_VEC | 5}, \ |
| 2047 | {"$v6", RTYPE_VEC | 6}, \ |
| 2048 | {"$v7", RTYPE_VEC | 7}, \ |
| 2049 | {"$v8", RTYPE_VEC | 8}, \ |
| 2050 | {"$v9", RTYPE_VEC | 9}, \ |
| 2051 | {"$v10", RTYPE_VEC | 10}, \ |
| 2052 | {"$v11", RTYPE_VEC | 11}, \ |
| 2053 | {"$v12", RTYPE_VEC | 12}, \ |
| 2054 | {"$v13", RTYPE_VEC | 13}, \ |
| 2055 | {"$v14", RTYPE_VEC | 14}, \ |
| 2056 | {"$v15", RTYPE_VEC | 15}, \ |
| 2057 | {"$v16", RTYPE_VEC | 16}, \ |
| 2058 | {"$v17", RTYPE_VEC | 17}, \ |
| 2059 | {"$v18", RTYPE_VEC | 18}, \ |
| 2060 | {"$v19", RTYPE_VEC | 19}, \ |
| 2061 | {"$v20", RTYPE_VEC | 20}, \ |
| 2062 | {"$v21", RTYPE_VEC | 21}, \ |
| 2063 | {"$v22", RTYPE_VEC | 22}, \ |
| 2064 | {"$v23", RTYPE_VEC | 23}, \ |
| 2065 | {"$v24", RTYPE_VEC | 24}, \ |
| 2066 | {"$v25", RTYPE_VEC | 25}, \ |
| 2067 | {"$v26", RTYPE_VEC | 26}, \ |
| 2068 | {"$v27", RTYPE_VEC | 27}, \ |
| 2069 | {"$v28", RTYPE_VEC | 28}, \ |
| 2070 | {"$v29", RTYPE_VEC | 29}, \ |
| 2071 | {"$v30", RTYPE_VEC | 30}, \ |
| 2072 | {"$v31", RTYPE_VEC | 31} |
| 2073 | |
| 2074 | #define MIPS_DSP_ACCUMULATOR_NAMES \ |
| 2075 | {"$ac0", RTYPE_ACC | 0}, \ |
| 2076 | {"$ac1", RTYPE_ACC | 1}, \ |
| 2077 | {"$ac2", RTYPE_ACC | 2}, \ |
| 2078 | {"$ac3", RTYPE_ACC | 3} |
| 2079 | |
| 2080 | static const struct regname reg_names[] = { |
| 2081 | GENERIC_REGISTER_NUMBERS, |
| 2082 | FPU_REGISTER_NAMES, |
| 2083 | FPU_CONDITION_CODE_NAMES, |
| 2084 | COPROC_CONDITION_CODE_NAMES, |
| 2085 | |
| 2086 | /* The $txx registers depends on the abi, |
| 2087 | these will be added later into the symbol table from |
| 2088 | one of the tables below once mips_abi is set after |
| 2089 | parsing of arguments from the command line. */ |
| 2090 | SYMBOLIC_REGISTER_NAMES, |
| 2091 | |
| 2092 | MIPS16_SPECIAL_REGISTER_NAMES, |
| 2093 | MDMX_VECTOR_REGISTER_NAMES, |
| 2094 | MIPS_DSP_ACCUMULATOR_NAMES, |
| 2095 | {0, 0} |
| 2096 | }; |
| 2097 | |
| 2098 | static const struct regname reg_names_o32[] = { |
| 2099 | O32_SYMBOLIC_REGISTER_NAMES, |
| 2100 | {0, 0} |
| 2101 | }; |
| 2102 | |
| 2103 | static const struct regname reg_names_n32n64[] = { |
| 2104 | N32N64_SYMBOLIC_REGISTER_NAMES, |
| 2105 | {0, 0} |
| 2106 | }; |
| 2107 | |
| 2108 | /* Check if S points at a valid register specifier according to TYPES. |
| 2109 | If so, then return 1, advance S to consume the specifier and store |
| 2110 | the register's number in REGNOP, otherwise return 0. */ |
| 2111 | |
| 2112 | static int |
| 2113 | reg_lookup (char **s, unsigned int types, unsigned int *regnop) |
| 2114 | { |
| 2115 | symbolS *symbolP; |
| 2116 | char *e; |
| 2117 | char save_c; |
| 2118 | int reg = -1; |
| 2119 | |
| 2120 | /* Find end of name. */ |
| 2121 | e = *s; |
| 2122 | if (is_name_beginner (*e)) |
| 2123 | ++e; |
| 2124 | while (is_part_of_name (*e)) |
| 2125 | ++e; |
| 2126 | |
| 2127 | /* Terminate name. */ |
| 2128 | save_c = *e; |
| 2129 | *e = '\0'; |
| 2130 | |
| 2131 | /* Look for a register symbol. */ |
| 2132 | if ((symbolP = symbol_find (*s)) && S_GET_SEGMENT (symbolP) == reg_section) |
| 2133 | { |
| 2134 | int r = S_GET_VALUE (symbolP); |
| 2135 | if (r & types) |
| 2136 | reg = r & RNUM_MASK; |
| 2137 | else if ((types & RTYPE_VEC) && (r & ~1) == (RTYPE_GP | 2)) |
| 2138 | /* Convert GP reg $v0/1 to MDMX reg $v0/1! */ |
| 2139 | reg = (r & RNUM_MASK) - 2; |
| 2140 | } |
| 2141 | /* Else see if this is a register defined in an itbl entry. */ |
| 2142 | else if ((types & RTYPE_GP) && itbl_have_entries) |
| 2143 | { |
| 2144 | char *n = *s; |
| 2145 | unsigned long r; |
| 2146 | |
| 2147 | if (*n == '$') |
| 2148 | ++n; |
| 2149 | if (itbl_get_reg_val (n, &r)) |
| 2150 | reg = r & RNUM_MASK; |
| 2151 | } |
| 2152 | |
| 2153 | /* Advance to next token if a register was recognised. */ |
| 2154 | if (reg >= 0) |
| 2155 | *s = e; |
| 2156 | else if (types & RWARN) |
| 2157 | as_warn (_("Unrecognized register name `%s'"), *s); |
| 2158 | |
| 2159 | *e = save_c; |
| 2160 | if (regnop) |
| 2161 | *regnop = reg; |
| 2162 | return reg >= 0; |
| 2163 | } |
| 2164 | |
| 2165 | /* Check if S points at a valid register list according to TYPES. |
| 2166 | If so, then return 1, advance S to consume the list and store |
| 2167 | the registers present on the list as a bitmask of ones in REGLISTP, |
| 2168 | otherwise return 0. A valid list comprises a comma-separated |
| 2169 | enumeration of valid single registers and/or dash-separated |
| 2170 | contiguous register ranges as determined by their numbers. |
| 2171 | |
| 2172 | As a special exception if one of s0-s7 registers is specified as |
| 2173 | the range's lower delimiter and s8 (fp) is its upper one, then no |
| 2174 | registers whose numbers place them between s7 and s8 (i.e. $24-$29) |
| 2175 | are selected; they have to be listed separately if needed. */ |
| 2176 | |
| 2177 | static int |
| 2178 | reglist_lookup (char **s, unsigned int types, unsigned int *reglistp) |
| 2179 | { |
| 2180 | unsigned int reglist = 0; |
| 2181 | unsigned int lastregno; |
| 2182 | bfd_boolean ok = TRUE; |
| 2183 | unsigned int regmask; |
| 2184 | char *s_endlist = *s; |
| 2185 | char *s_reset = *s; |
| 2186 | unsigned int regno; |
| 2187 | |
| 2188 | while (reg_lookup (s, types, ®no)) |
| 2189 | { |
| 2190 | lastregno = regno; |
| 2191 | if (**s == '-') |
| 2192 | { |
| 2193 | (*s)++; |
| 2194 | ok = reg_lookup (s, types, &lastregno); |
| 2195 | if (ok && lastregno < regno) |
| 2196 | ok = FALSE; |
| 2197 | if (!ok) |
| 2198 | break; |
| 2199 | } |
| 2200 | |
| 2201 | if (lastregno == FP && regno >= S0 && regno <= S7) |
| 2202 | { |
| 2203 | lastregno = S7; |
| 2204 | reglist |= 1 << FP; |
| 2205 | } |
| 2206 | regmask = 1 << lastregno; |
| 2207 | regmask = (regmask << 1) - 1; |
| 2208 | regmask ^= (1 << regno) - 1; |
| 2209 | reglist |= regmask; |
| 2210 | |
| 2211 | s_endlist = *s; |
| 2212 | if (**s != ',') |
| 2213 | break; |
| 2214 | (*s)++; |
| 2215 | } |
| 2216 | |
| 2217 | if (ok) |
| 2218 | *s = s_endlist; |
| 2219 | else |
| 2220 | *s = s_reset; |
| 2221 | if (reglistp) |
| 2222 | *reglistp = reglist; |
| 2223 | return ok && reglist != 0; |
| 2224 | } |
| 2225 | |
| 2226 | /* Return TRUE if opcode MO is valid on the currently selected ISA and |
| 2227 | architecture. Use is_opcode_valid_16 for MIPS16 opcodes. */ |
| 2228 | |
| 2229 | static bfd_boolean |
| 2230 | is_opcode_valid (const struct mips_opcode *mo) |
| 2231 | { |
| 2232 | int isa = mips_opts.isa; |
| 2233 | int fp_s, fp_d; |
| 2234 | |
| 2235 | if (mips_opts.ase_mdmx) |
| 2236 | isa |= INSN_MDMX; |
| 2237 | if (mips_opts.ase_dsp) |
| 2238 | isa |= INSN_DSP; |
| 2239 | if (mips_opts.ase_dsp && ISA_SUPPORTS_DSP64_ASE) |
| 2240 | isa |= INSN_DSP64; |
| 2241 | if (mips_opts.ase_dspr2) |
| 2242 | isa |= INSN_DSPR2; |
| 2243 | if (mips_opts.ase_mt) |
| 2244 | isa |= INSN_MT; |
| 2245 | if (mips_opts.ase_mips3d) |
| 2246 | isa |= INSN_MIPS3D; |
| 2247 | if (mips_opts.ase_smartmips) |
| 2248 | isa |= INSN_SMARTMIPS; |
| 2249 | if (mips_opts.ase_mcu) |
| 2250 | isa |= INSN_MCU; |
| 2251 | |
| 2252 | if (!opcode_is_member (mo, isa, mips_opts.arch)) |
| 2253 | return FALSE; |
| 2254 | |
| 2255 | /* Check whether the instruction or macro requires single-precision or |
| 2256 | double-precision floating-point support. Note that this information is |
| 2257 | stored differently in the opcode table for insns and macros. */ |
| 2258 | if (mo->pinfo == INSN_MACRO) |
| 2259 | { |
| 2260 | fp_s = mo->pinfo2 & INSN2_M_FP_S; |
| 2261 | fp_d = mo->pinfo2 & INSN2_M_FP_D; |
| 2262 | } |
| 2263 | else |
| 2264 | { |
| 2265 | fp_s = mo->pinfo & FP_S; |
| 2266 | fp_d = mo->pinfo & FP_D; |
| 2267 | } |
| 2268 | |
| 2269 | if (fp_d && (mips_opts.soft_float || mips_opts.single_float)) |
| 2270 | return FALSE; |
| 2271 | |
| 2272 | if (fp_s && mips_opts.soft_float) |
| 2273 | return FALSE; |
| 2274 | |
| 2275 | return TRUE; |
| 2276 | } |
| 2277 | |
| 2278 | /* Return TRUE if the MIPS16 opcode MO is valid on the currently |
| 2279 | selected ISA and architecture. */ |
| 2280 | |
| 2281 | static bfd_boolean |
| 2282 | is_opcode_valid_16 (const struct mips_opcode *mo) |
| 2283 | { |
| 2284 | return opcode_is_member (mo, mips_opts.isa, mips_opts.arch); |
| 2285 | } |
| 2286 | |
| 2287 | /* Return TRUE if the size of the microMIPS opcode MO matches one |
| 2288 | explicitly requested. Always TRUE in the standard MIPS mode. */ |
| 2289 | |
| 2290 | static bfd_boolean |
| 2291 | is_size_valid (const struct mips_opcode *mo) |
| 2292 | { |
| 2293 | if (!mips_opts.micromips) |
| 2294 | return TRUE; |
| 2295 | |
| 2296 | if (!forced_insn_length) |
| 2297 | return TRUE; |
| 2298 | if (mo->pinfo == INSN_MACRO) |
| 2299 | return FALSE; |
| 2300 | return forced_insn_length == micromips_insn_length (mo); |
| 2301 | } |
| 2302 | |
| 2303 | /* Return TRUE if the microMIPS opcode MO is valid for the delay slot |
| 2304 | of the preceding instruction. Always TRUE in the standard MIPS mode. |
| 2305 | |
| 2306 | We don't accept macros in 16-bit delay slots to avoid a case where |
| 2307 | a macro expansion fails because it relies on a preceding 32-bit real |
| 2308 | instruction to have matched and does not handle the operands correctly. |
| 2309 | The only macros that may expand to 16-bit instructions are JAL that |
| 2310 | cannot be placed in a delay slot anyway, and corner cases of BALIGN |
| 2311 | and BGT (that likewise cannot be placed in a delay slot) that decay to |
| 2312 | a NOP. In all these cases the macros precede any corresponding real |
| 2313 | instruction definitions in the opcode table, so they will match in the |
| 2314 | second pass where the size of the delay slot is ignored and therefore |
| 2315 | produce correct code. */ |
| 2316 | |
| 2317 | static bfd_boolean |
| 2318 | is_delay_slot_valid (const struct mips_opcode *mo) |
| 2319 | { |
| 2320 | if (!mips_opts.micromips) |
| 2321 | return TRUE; |
| 2322 | |
| 2323 | if (mo->pinfo == INSN_MACRO) |
| 2324 | return ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) == 0 |
| 2325 | ? TRUE : FALSE); |
| 2326 | if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0 |
| 2327 | && micromips_insn_length (mo) != 4) |
| 2328 | return FALSE; |
| 2329 | if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 |
| 2330 | && micromips_insn_length (mo) != 2) |
| 2331 | return FALSE; |
| 2332 | |
| 2333 | return TRUE; |
| 2334 | } |
| 2335 | |
| 2336 | /* This function is called once, at assembler startup time. It should set up |
| 2337 | all the tables, etc. that the MD part of the assembler will need. */ |
| 2338 | |
| 2339 | void |
| 2340 | md_begin (void) |
| 2341 | { |
| 2342 | const char *retval = NULL; |
| 2343 | int i = 0; |
| 2344 | int broken = 0; |
| 2345 | |
| 2346 | if (mips_pic != NO_PIC) |
| 2347 | { |
| 2348 | if (g_switch_seen && g_switch_value != 0) |
| 2349 | as_bad (_("-G may not be used in position-independent code")); |
| 2350 | g_switch_value = 0; |
| 2351 | } |
| 2352 | |
| 2353 | if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch)) |
| 2354 | as_warn (_("Could not set architecture and machine")); |
| 2355 | |
| 2356 | op_hash = hash_new (); |
| 2357 | |
| 2358 | for (i = 0; i < NUMOPCODES;) |
| 2359 | { |
| 2360 | const char *name = mips_opcodes[i].name; |
| 2361 | |
| 2362 | retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]); |
| 2363 | if (retval != NULL) |
| 2364 | { |
| 2365 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), |
| 2366 | mips_opcodes[i].name, retval); |
| 2367 | /* Probably a memory allocation problem? Give up now. */ |
| 2368 | as_fatal (_("Broken assembler. No assembly attempted.")); |
| 2369 | } |
| 2370 | do |
| 2371 | { |
| 2372 | if (mips_opcodes[i].pinfo != INSN_MACRO) |
| 2373 | { |
| 2374 | if (!validate_mips_insn (&mips_opcodes[i])) |
| 2375 | broken = 1; |
| 2376 | if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0) |
| 2377 | { |
| 2378 | create_insn (&nop_insn, mips_opcodes + i); |
| 2379 | if (mips_fix_loongson2f_nop) |
| 2380 | nop_insn.insn_opcode = LOONGSON2F_NOP_INSN; |
| 2381 | nop_insn.fixed_p = 1; |
| 2382 | } |
| 2383 | } |
| 2384 | ++i; |
| 2385 | } |
| 2386 | while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name)); |
| 2387 | } |
| 2388 | |
| 2389 | mips16_op_hash = hash_new (); |
| 2390 | |
| 2391 | i = 0; |
| 2392 | while (i < bfd_mips16_num_opcodes) |
| 2393 | { |
| 2394 | const char *name = mips16_opcodes[i].name; |
| 2395 | |
| 2396 | retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]); |
| 2397 | if (retval != NULL) |
| 2398 | as_fatal (_("internal: can't hash `%s': %s"), |
| 2399 | mips16_opcodes[i].name, retval); |
| 2400 | do |
| 2401 | { |
| 2402 | if (mips16_opcodes[i].pinfo != INSN_MACRO |
| 2403 | && ((mips16_opcodes[i].match & mips16_opcodes[i].mask) |
| 2404 | != mips16_opcodes[i].match)) |
| 2405 | { |
| 2406 | fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"), |
| 2407 | mips16_opcodes[i].name, mips16_opcodes[i].args); |
| 2408 | broken = 1; |
| 2409 | } |
| 2410 | if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0) |
| 2411 | { |
| 2412 | create_insn (&mips16_nop_insn, mips16_opcodes + i); |
| 2413 | mips16_nop_insn.fixed_p = 1; |
| 2414 | } |
| 2415 | ++i; |
| 2416 | } |
| 2417 | while (i < bfd_mips16_num_opcodes |
| 2418 | && strcmp (mips16_opcodes[i].name, name) == 0); |
| 2419 | } |
| 2420 | |
| 2421 | micromips_op_hash = hash_new (); |
| 2422 | |
| 2423 | i = 0; |
| 2424 | while (i < bfd_micromips_num_opcodes) |
| 2425 | { |
| 2426 | const char *name = micromips_opcodes[i].name; |
| 2427 | |
| 2428 | retval = hash_insert (micromips_op_hash, name, |
| 2429 | (void *) µmips_opcodes[i]); |
| 2430 | if (retval != NULL) |
| 2431 | as_fatal (_("internal: can't hash `%s': %s"), |
| 2432 | micromips_opcodes[i].name, retval); |
| 2433 | do |
| 2434 | if (micromips_opcodes[i].pinfo != INSN_MACRO) |
| 2435 | { |
| 2436 | struct mips_cl_insn *micromips_nop_insn; |
| 2437 | |
| 2438 | if (!validate_micromips_insn (µmips_opcodes[i])) |
| 2439 | broken = 1; |
| 2440 | |
| 2441 | if (micromips_insn_length (micromips_opcodes + i) == 2) |
| 2442 | micromips_nop_insn = µmips_nop16_insn; |
| 2443 | else if (micromips_insn_length (micromips_opcodes + i) == 4) |
| 2444 | micromips_nop_insn = µmips_nop32_insn; |
| 2445 | else |
| 2446 | continue; |
| 2447 | |
| 2448 | if (micromips_nop_insn->insn_mo == NULL |
| 2449 | && strcmp (name, "nop") == 0) |
| 2450 | { |
| 2451 | create_insn (micromips_nop_insn, micromips_opcodes + i); |
| 2452 | micromips_nop_insn->fixed_p = 1; |
| 2453 | } |
| 2454 | } |
| 2455 | while (++i < bfd_micromips_num_opcodes |
| 2456 | && strcmp (micromips_opcodes[i].name, name) == 0); |
| 2457 | } |
| 2458 | |
| 2459 | if (broken) |
| 2460 | as_fatal (_("Broken assembler. No assembly attempted.")); |
| 2461 | |
| 2462 | /* We add all the general register names to the symbol table. This |
| 2463 | helps us detect invalid uses of them. */ |
| 2464 | for (i = 0; reg_names[i].name; i++) |
| 2465 | symbol_table_insert (symbol_new (reg_names[i].name, reg_section, |
| 2466 | reg_names[i].num, /* & RNUM_MASK, */ |
| 2467 | &zero_address_frag)); |
| 2468 | if (HAVE_NEWABI) |
| 2469 | for (i = 0; reg_names_n32n64[i].name; i++) |
| 2470 | symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section, |
| 2471 | reg_names_n32n64[i].num, /* & RNUM_MASK, */ |
| 2472 | &zero_address_frag)); |
| 2473 | else |
| 2474 | for (i = 0; reg_names_o32[i].name; i++) |
| 2475 | symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section, |
| 2476 | reg_names_o32[i].num, /* & RNUM_MASK, */ |
| 2477 | &zero_address_frag)); |
| 2478 | |
| 2479 | mips_no_prev_insn (); |
| 2480 | |
| 2481 | mips_gprmask = 0; |
| 2482 | mips_cprmask[0] = 0; |
| 2483 | mips_cprmask[1] = 0; |
| 2484 | mips_cprmask[2] = 0; |
| 2485 | mips_cprmask[3] = 0; |
| 2486 | |
| 2487 | /* set the default alignment for the text section (2**2) */ |
| 2488 | record_alignment (text_section, 2); |
| 2489 | |
| 2490 | bfd_set_gp_size (stdoutput, g_switch_value); |
| 2491 | |
| 2492 | #ifdef OBJ_ELF |
| 2493 | if (IS_ELF) |
| 2494 | { |
| 2495 | /* On a native system other than VxWorks, sections must be aligned |
| 2496 | to 16 byte boundaries. When configured for an embedded ELF |
| 2497 | target, we don't bother. */ |
| 2498 | if (strncmp (TARGET_OS, "elf", 3) != 0 |
| 2499 | && strncmp (TARGET_OS, "vxworks", 7) != 0) |
| 2500 | { |
| 2501 | (void) bfd_set_section_alignment (stdoutput, text_section, 4); |
| 2502 | (void) bfd_set_section_alignment (stdoutput, data_section, 4); |
| 2503 | (void) bfd_set_section_alignment (stdoutput, bss_section, 4); |
| 2504 | } |
| 2505 | |
| 2506 | /* Create a .reginfo section for register masks and a .mdebug |
| 2507 | section for debugging information. */ |
| 2508 | { |
| 2509 | segT seg; |
| 2510 | subsegT subseg; |
| 2511 | flagword flags; |
| 2512 | segT sec; |
| 2513 | |
| 2514 | seg = now_seg; |
| 2515 | subseg = now_subseg; |
| 2516 | |
| 2517 | /* The ABI says this section should be loaded so that the |
| 2518 | running program can access it. However, we don't load it |
| 2519 | if we are configured for an embedded target */ |
| 2520 | flags = SEC_READONLY | SEC_DATA; |
| 2521 | if (strncmp (TARGET_OS, "elf", 3) != 0) |
| 2522 | flags |= SEC_ALLOC | SEC_LOAD; |
| 2523 | |
| 2524 | if (mips_abi != N64_ABI) |
| 2525 | { |
| 2526 | sec = subseg_new (".reginfo", (subsegT) 0); |
| 2527 | |
| 2528 | bfd_set_section_flags (stdoutput, sec, flags); |
| 2529 | bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2); |
| 2530 | |
| 2531 | mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo)); |
| 2532 | } |
| 2533 | else |
| 2534 | { |
| 2535 | /* The 64-bit ABI uses a .MIPS.options section rather than |
| 2536 | .reginfo section. */ |
| 2537 | sec = subseg_new (".MIPS.options", (subsegT) 0); |
| 2538 | bfd_set_section_flags (stdoutput, sec, flags); |
| 2539 | bfd_set_section_alignment (stdoutput, sec, 3); |
| 2540 | |
| 2541 | /* Set up the option header. */ |
| 2542 | { |
| 2543 | Elf_Internal_Options opthdr; |
| 2544 | char *f; |
| 2545 | |
| 2546 | opthdr.kind = ODK_REGINFO; |
| 2547 | opthdr.size = (sizeof (Elf_External_Options) |
| 2548 | + sizeof (Elf64_External_RegInfo)); |
| 2549 | opthdr.section = 0; |
| 2550 | opthdr.info = 0; |
| 2551 | f = frag_more (sizeof (Elf_External_Options)); |
| 2552 | bfd_mips_elf_swap_options_out (stdoutput, &opthdr, |
| 2553 | (Elf_External_Options *) f); |
| 2554 | |
| 2555 | mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo)); |
| 2556 | } |
| 2557 | } |
| 2558 | |
| 2559 | if (ECOFF_DEBUGGING) |
| 2560 | { |
| 2561 | sec = subseg_new (".mdebug", (subsegT) 0); |
| 2562 | (void) bfd_set_section_flags (stdoutput, sec, |
| 2563 | SEC_HAS_CONTENTS | SEC_READONLY); |
| 2564 | (void) bfd_set_section_alignment (stdoutput, sec, 2); |
| 2565 | } |
| 2566 | else if (mips_flag_pdr) |
| 2567 | { |
| 2568 | pdr_seg = subseg_new (".pdr", (subsegT) 0); |
| 2569 | (void) bfd_set_section_flags (stdoutput, pdr_seg, |
| 2570 | SEC_READONLY | SEC_RELOC |
| 2571 | | SEC_DEBUGGING); |
| 2572 | (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2); |
| 2573 | } |
| 2574 | |
| 2575 | subseg_set (seg, subseg); |
| 2576 | } |
| 2577 | } |
| 2578 | #endif /* OBJ_ELF */ |
| 2579 | |
| 2580 | if (! ECOFF_DEBUGGING) |
| 2581 | md_obj_begin (); |
| 2582 | |
| 2583 | if (mips_fix_vr4120) |
| 2584 | init_vr4120_conflicts (); |
| 2585 | } |
| 2586 | |
| 2587 | void |
| 2588 | md_mips_end (void) |
| 2589 | { |
| 2590 | mips_emit_delays (); |
| 2591 | if (! ECOFF_DEBUGGING) |
| 2592 | md_obj_end (); |
| 2593 | } |
| 2594 | |
| 2595 | void |
| 2596 | md_assemble (char *str) |
| 2597 | { |
| 2598 | struct mips_cl_insn insn; |
| 2599 | bfd_reloc_code_real_type unused_reloc[3] |
| 2600 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; |
| 2601 | |
| 2602 | imm_expr.X_op = O_absent; |
| 2603 | imm2_expr.X_op = O_absent; |
| 2604 | offset_expr.X_op = O_absent; |
| 2605 | imm_reloc[0] = BFD_RELOC_UNUSED; |
| 2606 | imm_reloc[1] = BFD_RELOC_UNUSED; |
| 2607 | imm_reloc[2] = BFD_RELOC_UNUSED; |
| 2608 | offset_reloc[0] = BFD_RELOC_UNUSED; |
| 2609 | offset_reloc[1] = BFD_RELOC_UNUSED; |
| 2610 | offset_reloc[2] = BFD_RELOC_UNUSED; |
| 2611 | |
| 2612 | mips_mark_labels (); |
| 2613 | mips_assembling_insn = TRUE; |
| 2614 | |
| 2615 | if (mips_opts.mips16) |
| 2616 | mips16_ip (str, &insn); |
| 2617 | else |
| 2618 | { |
| 2619 | mips_ip (str, &insn); |
| 2620 | DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), |
| 2621 | str, insn.insn_opcode)); |
| 2622 | } |
| 2623 | |
| 2624 | if (insn_error) |
| 2625 | as_bad ("%s `%s'", insn_error, str); |
| 2626 | else if (insn.insn_mo->pinfo == INSN_MACRO) |
| 2627 | { |
| 2628 | macro_start (); |
| 2629 | if (mips_opts.mips16) |
| 2630 | mips16_macro (&insn); |
| 2631 | else |
| 2632 | macro (&insn); |
| 2633 | macro_end (); |
| 2634 | } |
| 2635 | else |
| 2636 | { |
| 2637 | if (imm_expr.X_op != O_absent) |
| 2638 | append_insn (&insn, &imm_expr, imm_reloc, FALSE); |
| 2639 | else if (offset_expr.X_op != O_absent) |
| 2640 | append_insn (&insn, &offset_expr, offset_reloc, FALSE); |
| 2641 | else |
| 2642 | append_insn (&insn, NULL, unused_reloc, FALSE); |
| 2643 | } |
| 2644 | |
| 2645 | mips_assembling_insn = FALSE; |
| 2646 | } |
| 2647 | |
| 2648 | /* Convenience functions for abstracting away the differences between |
| 2649 | MIPS16 and non-MIPS16 relocations. */ |
| 2650 | |
| 2651 | static inline bfd_boolean |
| 2652 | mips16_reloc_p (bfd_reloc_code_real_type reloc) |
| 2653 | { |
| 2654 | switch (reloc) |
| 2655 | { |
| 2656 | case BFD_RELOC_MIPS16_JMP: |
| 2657 | case BFD_RELOC_MIPS16_GPREL: |
| 2658 | case BFD_RELOC_MIPS16_GOT16: |
| 2659 | case BFD_RELOC_MIPS16_CALL16: |
| 2660 | case BFD_RELOC_MIPS16_HI16_S: |
| 2661 | case BFD_RELOC_MIPS16_HI16: |
| 2662 | case BFD_RELOC_MIPS16_LO16: |
| 2663 | return TRUE; |
| 2664 | |
| 2665 | default: |
| 2666 | return FALSE; |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | static inline bfd_boolean |
| 2671 | micromips_reloc_p (bfd_reloc_code_real_type reloc) |
| 2672 | { |
| 2673 | switch (reloc) |
| 2674 | { |
| 2675 | case BFD_RELOC_MICROMIPS_7_PCREL_S1: |
| 2676 | case BFD_RELOC_MICROMIPS_10_PCREL_S1: |
| 2677 | case BFD_RELOC_MICROMIPS_16_PCREL_S1: |
| 2678 | case BFD_RELOC_MICROMIPS_GPREL16: |
| 2679 | case BFD_RELOC_MICROMIPS_JMP: |
| 2680 | case BFD_RELOC_MICROMIPS_HI16: |
| 2681 | case BFD_RELOC_MICROMIPS_HI16_S: |
| 2682 | case BFD_RELOC_MICROMIPS_LO16: |
| 2683 | case BFD_RELOC_MICROMIPS_LITERAL: |
| 2684 | case BFD_RELOC_MICROMIPS_GOT16: |
| 2685 | case BFD_RELOC_MICROMIPS_CALL16: |
| 2686 | case BFD_RELOC_MICROMIPS_GOT_HI16: |
| 2687 | case BFD_RELOC_MICROMIPS_GOT_LO16: |
| 2688 | case BFD_RELOC_MICROMIPS_CALL_HI16: |
| 2689 | case BFD_RELOC_MICROMIPS_CALL_LO16: |
| 2690 | case BFD_RELOC_MICROMIPS_SUB: |
| 2691 | case BFD_RELOC_MICROMIPS_GOT_PAGE: |
| 2692 | case BFD_RELOC_MICROMIPS_GOT_OFST: |
| 2693 | case BFD_RELOC_MICROMIPS_GOT_DISP: |
| 2694 | case BFD_RELOC_MICROMIPS_HIGHEST: |
| 2695 | case BFD_RELOC_MICROMIPS_HIGHER: |
| 2696 | case BFD_RELOC_MICROMIPS_SCN_DISP: |
| 2697 | case BFD_RELOC_MICROMIPS_JALR: |
| 2698 | return TRUE; |
| 2699 | |
| 2700 | default: |
| 2701 | return FALSE; |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | static inline bfd_boolean |
| 2706 | jmp_reloc_p (bfd_reloc_code_real_type reloc) |
| 2707 | { |
| 2708 | return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP; |
| 2709 | } |
| 2710 | |
| 2711 | static inline bfd_boolean |
| 2712 | got16_reloc_p (bfd_reloc_code_real_type reloc) |
| 2713 | { |
| 2714 | return (reloc == BFD_RELOC_MIPS_GOT16 || reloc == BFD_RELOC_MIPS16_GOT16 |
| 2715 | || reloc == BFD_RELOC_MICROMIPS_GOT16); |
| 2716 | } |
| 2717 | |
| 2718 | static inline bfd_boolean |
| 2719 | hi16_reloc_p (bfd_reloc_code_real_type reloc) |
| 2720 | { |
| 2721 | return (reloc == BFD_RELOC_HI16_S || reloc == BFD_RELOC_MIPS16_HI16_S |
| 2722 | || reloc == BFD_RELOC_MICROMIPS_HI16_S); |
| 2723 | } |
| 2724 | |
| 2725 | static inline bfd_boolean |
| 2726 | lo16_reloc_p (bfd_reloc_code_real_type reloc) |
| 2727 | { |
| 2728 | return (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_MIPS16_LO16 |
| 2729 | || reloc == BFD_RELOC_MICROMIPS_LO16); |
| 2730 | } |
| 2731 | |
| 2732 | static inline bfd_boolean |
| 2733 | jalr_reloc_p (bfd_reloc_code_real_type reloc) |
| 2734 | { |
| 2735 | return reloc == BFD_RELOC_MIPS_JALR || reloc == BFD_RELOC_MICROMIPS_JALR; |
| 2736 | } |
| 2737 | |
| 2738 | /* Return true if the given relocation might need a matching %lo(). |
| 2739 | This is only "might" because SVR4 R_MIPS_GOT16 relocations only |
| 2740 | need a matching %lo() when applied to local symbols. */ |
| 2741 | |
| 2742 | static inline bfd_boolean |
| 2743 | reloc_needs_lo_p (bfd_reloc_code_real_type reloc) |
| 2744 | { |
| 2745 | return (HAVE_IN_PLACE_ADDENDS |
| 2746 | && (hi16_reloc_p (reloc) |
| 2747 | /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo(); |
| 2748 | all GOT16 relocations evaluate to "G". */ |
| 2749 | || (got16_reloc_p (reloc) && mips_pic != VXWORKS_PIC))); |
| 2750 | } |
| 2751 | |
| 2752 | /* Return the type of %lo() reloc needed by RELOC, given that |
| 2753 | reloc_needs_lo_p. */ |
| 2754 | |
| 2755 | static inline bfd_reloc_code_real_type |
| 2756 | matching_lo_reloc (bfd_reloc_code_real_type reloc) |
| 2757 | { |
| 2758 | return (mips16_reloc_p (reloc) ? BFD_RELOC_MIPS16_LO16 |
| 2759 | : (micromips_reloc_p (reloc) ? BFD_RELOC_MICROMIPS_LO16 |
| 2760 | : BFD_RELOC_LO16)); |
| 2761 | } |
| 2762 | |
| 2763 | /* Return true if the given fixup is followed by a matching R_MIPS_LO16 |
| 2764 | relocation. */ |
| 2765 | |
| 2766 | static inline bfd_boolean |
| 2767 | fixup_has_matching_lo_p (fixS *fixp) |
| 2768 | { |
| 2769 | return (fixp->fx_next != NULL |
| 2770 | && fixp->fx_next->fx_r_type == matching_lo_reloc (fixp->fx_r_type) |
| 2771 | && fixp->fx_addsy == fixp->fx_next->fx_addsy |
| 2772 | && fixp->fx_offset == fixp->fx_next->fx_offset); |
| 2773 | } |
| 2774 | |
| 2775 | /* This function returns true if modifying a register requires a |
| 2776 | delay. */ |
| 2777 | |
| 2778 | static int |
| 2779 | reg_needs_delay (unsigned int reg) |
| 2780 | { |
| 2781 | unsigned long prev_pinfo; |
| 2782 | |
| 2783 | prev_pinfo = history[0].insn_mo->pinfo; |
| 2784 | if (! mips_opts.noreorder |
| 2785 | && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY) |
| 2786 | && ! gpr_interlocks) |
| 2787 | || ((prev_pinfo & INSN_LOAD_COPROC_DELAY) |
| 2788 | && ! cop_interlocks))) |
| 2789 | { |
| 2790 | /* A load from a coprocessor or from memory. All load delays |
| 2791 | delay the use of general register rt for one instruction. */ |
| 2792 | /* Itbl support may require additional care here. */ |
| 2793 | know (prev_pinfo & INSN_WRITE_GPR_T); |
| 2794 | if (reg == EXTRACT_OPERAND (mips_opts.micromips, RT, history[0])) |
| 2795 | return 1; |
| 2796 | } |
| 2797 | |
| 2798 | return 0; |
| 2799 | } |
| 2800 | |
| 2801 | /* Move all labels in LABELS to the current insertion point. TEXT_P |
| 2802 | says whether the labels refer to text or data. */ |
| 2803 | |
| 2804 | static void |
| 2805 | mips_move_labels (struct insn_label_list *labels, bfd_boolean text_p) |
| 2806 | { |
| 2807 | struct insn_label_list *l; |
| 2808 | valueT val; |
| 2809 | |
| 2810 | for (l = labels; l != NULL; l = l->next) |
| 2811 | { |
| 2812 | gas_assert (S_GET_SEGMENT (l->label) == now_seg); |
| 2813 | symbol_set_frag (l->label, frag_now); |
| 2814 | val = (valueT) frag_now_fix (); |
| 2815 | /* MIPS16/microMIPS text labels are stored as odd. */ |
| 2816 | if (text_p && HAVE_CODE_COMPRESSION) |
| 2817 | ++val; |
| 2818 | S_SET_VALUE (l->label, val); |
| 2819 | } |
| 2820 | } |
| 2821 | |
| 2822 | /* Move all labels in insn_labels to the current insertion point |
| 2823 | and treat them as text labels. */ |
| 2824 | |
| 2825 | static void |
| 2826 | mips_move_text_labels (void) |
| 2827 | { |
| 2828 | mips_move_labels (seg_info (now_seg)->label_list, TRUE); |
| 2829 | } |
| 2830 | |
| 2831 | static bfd_boolean |
| 2832 | s_is_linkonce (symbolS *sym, segT from_seg) |
| 2833 | { |
| 2834 | bfd_boolean linkonce = FALSE; |
| 2835 | segT symseg = S_GET_SEGMENT (sym); |
| 2836 | |
| 2837 | if (symseg != from_seg && !S_IS_LOCAL (sym)) |
| 2838 | { |
| 2839 | if ((bfd_get_section_flags (stdoutput, symseg) & SEC_LINK_ONCE)) |
| 2840 | linkonce = TRUE; |
| 2841 | #ifdef OBJ_ELF |
| 2842 | /* The GNU toolchain uses an extension for ELF: a section |
| 2843 | beginning with the magic string .gnu.linkonce is a |
| 2844 | linkonce section. */ |
| 2845 | if (strncmp (segment_name (symseg), ".gnu.linkonce", |
| 2846 | sizeof ".gnu.linkonce" - 1) == 0) |
| 2847 | linkonce = TRUE; |
| 2848 | #endif |
| 2849 | } |
| 2850 | return linkonce; |
| 2851 | } |
| 2852 | |
| 2853 | /* Mark MIPS16 or microMIPS instruction label LABEL. This permits the |
| 2854 | linker to handle them specially, such as generating jalx instructions |
| 2855 | when needed. We also make them odd for the duration of the assembly, |
| 2856 | in order to generate the right sort of code. We will make them even |
| 2857 | in the adjust_symtab routine, while leaving them marked. This is |
| 2858 | convenient for the debugger and the disassembler. The linker knows |
| 2859 | to make them odd again. */ |
| 2860 | |
| 2861 | static void |
| 2862 | mips_compressed_mark_label (symbolS *label) |
| 2863 | { |
| 2864 | gas_assert (HAVE_CODE_COMPRESSION); |
| 2865 | |
| 2866 | #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF) |
| 2867 | if (IS_ELF) |
| 2868 | { |
| 2869 | if (mips_opts.mips16) |
| 2870 | S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label))); |
| 2871 | else |
| 2872 | S_SET_OTHER (label, ELF_ST_SET_MICROMIPS (S_GET_OTHER (label))); |
| 2873 | } |
| 2874 | #endif |
| 2875 | if ((S_GET_VALUE (label) & 1) == 0 |
| 2876 | /* Don't adjust the address if the label is global or weak, or |
| 2877 | in a link-once section, since we'll be emitting symbol reloc |
| 2878 | references to it which will be patched up by the linker, and |
| 2879 | the final value of the symbol may or may not be MIPS16/microMIPS. */ |
| 2880 | && !S_IS_WEAK (label) |
| 2881 | && !S_IS_EXTERNAL (label) |
| 2882 | && !s_is_linkonce (label, now_seg)) |
| 2883 | S_SET_VALUE (label, S_GET_VALUE (label) | 1); |
| 2884 | } |
| 2885 | |
| 2886 | /* Mark preceding MIPS16 or microMIPS instruction labels. */ |
| 2887 | |
| 2888 | static void |
| 2889 | mips_compressed_mark_labels (void) |
| 2890 | { |
| 2891 | struct insn_label_list *l; |
| 2892 | |
| 2893 | for (l = seg_info (now_seg)->label_list; l != NULL; l = l->next) |
| 2894 | mips_compressed_mark_label (l->label); |
| 2895 | } |
| 2896 | |
| 2897 | /* End the current frag. Make it a variant frag and record the |
| 2898 | relaxation info. */ |
| 2899 | |
| 2900 | static void |
| 2901 | relax_close_frag (void) |
| 2902 | { |
| 2903 | mips_macro_warning.first_frag = frag_now; |
| 2904 | frag_var (rs_machine_dependent, 0, 0, |
| 2905 | RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]), |
| 2906 | mips_relax.symbol, 0, (char *) mips_relax.first_fixup); |
| 2907 | |
| 2908 | memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes)); |
| 2909 | mips_relax.first_fixup = 0; |
| 2910 | } |
| 2911 | |
| 2912 | /* Start a new relaxation sequence whose expansion depends on SYMBOL. |
| 2913 | See the comment above RELAX_ENCODE for more details. */ |
| 2914 | |
| 2915 | static void |
| 2916 | relax_start (symbolS *symbol) |
| 2917 | { |
| 2918 | gas_assert (mips_relax.sequence == 0); |
| 2919 | mips_relax.sequence = 1; |
| 2920 | mips_relax.symbol = symbol; |
| 2921 | } |
| 2922 | |
| 2923 | /* Start generating the second version of a relaxable sequence. |
| 2924 | See the comment above RELAX_ENCODE for more details. */ |
| 2925 | |
| 2926 | static void |
| 2927 | relax_switch (void) |
| 2928 | { |
| 2929 | gas_assert (mips_relax.sequence == 1); |
| 2930 | mips_relax.sequence = 2; |
| 2931 | } |
| 2932 | |
| 2933 | /* End the current relaxable sequence. */ |
| 2934 | |
| 2935 | static void |
| 2936 | relax_end (void) |
| 2937 | { |
| 2938 | gas_assert (mips_relax.sequence == 2); |
| 2939 | relax_close_frag (); |
| 2940 | mips_relax.sequence = 0; |
| 2941 | } |
| 2942 | |
| 2943 | /* Return true if IP is a delayed branch or jump. */ |
| 2944 | |
| 2945 | static inline bfd_boolean |
| 2946 | delayed_branch_p (const struct mips_cl_insn *ip) |
| 2947 | { |
| 2948 | return (ip->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY |
| 2949 | | INSN_COND_BRANCH_DELAY |
| 2950 | | INSN_COND_BRANCH_LIKELY)) != 0; |
| 2951 | } |
| 2952 | |
| 2953 | /* Return true if IP is a compact branch or jump. */ |
| 2954 | |
| 2955 | static inline bfd_boolean |
| 2956 | compact_branch_p (const struct mips_cl_insn *ip) |
| 2957 | { |
| 2958 | if (mips_opts.mips16) |
| 2959 | return (ip->insn_mo->pinfo & (MIPS16_INSN_UNCOND_BRANCH |
| 2960 | | MIPS16_INSN_COND_BRANCH)) != 0; |
| 2961 | else |
| 2962 | return (ip->insn_mo->pinfo2 & (INSN2_UNCOND_BRANCH |
| 2963 | | INSN2_COND_BRANCH)) != 0; |
| 2964 | } |
| 2965 | |
| 2966 | /* Return true if IP is an unconditional branch or jump. */ |
| 2967 | |
| 2968 | static inline bfd_boolean |
| 2969 | uncond_branch_p (const struct mips_cl_insn *ip) |
| 2970 | { |
| 2971 | return ((ip->insn_mo->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0 |
| 2972 | || (mips_opts.mips16 |
| 2973 | ? (ip->insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH) != 0 |
| 2974 | : (ip->insn_mo->pinfo2 & INSN2_UNCOND_BRANCH) != 0)); |
| 2975 | } |
| 2976 | |
| 2977 | /* Return true if IP is a branch-likely instruction. */ |
| 2978 | |
| 2979 | static inline bfd_boolean |
| 2980 | branch_likely_p (const struct mips_cl_insn *ip) |
| 2981 | { |
| 2982 | return (ip->insn_mo->pinfo & INSN_COND_BRANCH_LIKELY) != 0; |
| 2983 | } |
| 2984 | |
| 2985 | /* Return the type of nop that should be used to fill the delay slot |
| 2986 | of delayed branch IP. */ |
| 2987 | |
| 2988 | static struct mips_cl_insn * |
| 2989 | get_delay_slot_nop (const struct mips_cl_insn *ip) |
| 2990 | { |
| 2991 | if (mips_opts.micromips |
| 2992 | && (ip->insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) |
| 2993 | return µmips_nop32_insn; |
| 2994 | return NOP_INSN; |
| 2995 | } |
| 2996 | |
| 2997 | /* Return the mask of core registers that IP reads or writes. */ |
| 2998 | |
| 2999 | static unsigned int |
| 3000 | gpr_mod_mask (const struct mips_cl_insn *ip) |
| 3001 | { |
| 3002 | unsigned long pinfo2; |
| 3003 | unsigned int mask; |
| 3004 | |
| 3005 | mask = 0; |
| 3006 | pinfo2 = ip->insn_mo->pinfo2; |
| 3007 | if (mips_opts.micromips) |
| 3008 | { |
| 3009 | if (pinfo2 & INSN2_MOD_GPR_MD) |
| 3010 | mask |= 1 << micromips_to_32_reg_d_map[EXTRACT_OPERAND (1, MD, *ip)]; |
| 3011 | if (pinfo2 & INSN2_MOD_GPR_MF) |
| 3012 | mask |= 1 << micromips_to_32_reg_f_map[EXTRACT_OPERAND (1, MF, *ip)]; |
| 3013 | if (pinfo2 & INSN2_MOD_SP) |
| 3014 | mask |= 1 << SP; |
| 3015 | } |
| 3016 | return mask; |
| 3017 | } |
| 3018 | |
| 3019 | /* Return the mask of core registers that IP reads. */ |
| 3020 | |
| 3021 | static unsigned int |
| 3022 | gpr_read_mask (const struct mips_cl_insn *ip) |
| 3023 | { |
| 3024 | unsigned long pinfo, pinfo2; |
| 3025 | unsigned int mask; |
| 3026 | |
| 3027 | mask = gpr_mod_mask (ip); |
| 3028 | pinfo = ip->insn_mo->pinfo; |
| 3029 | pinfo2 = ip->insn_mo->pinfo2; |
| 3030 | if (mips_opts.mips16) |
| 3031 | { |
| 3032 | if (pinfo & MIPS16_INSN_READ_X) |
| 3033 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)]; |
| 3034 | if (pinfo & MIPS16_INSN_READ_Y) |
| 3035 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)]; |
| 3036 | if (pinfo & MIPS16_INSN_READ_T) |
| 3037 | mask |= 1 << TREG; |
| 3038 | if (pinfo & MIPS16_INSN_READ_SP) |
| 3039 | mask |= 1 << SP; |
| 3040 | if (pinfo & MIPS16_INSN_READ_31) |
| 3041 | mask |= 1 << RA; |
| 3042 | if (pinfo & MIPS16_INSN_READ_Z) |
| 3043 | mask |= 1 << (mips16_to_32_reg_map |
| 3044 | [MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]); |
| 3045 | if (pinfo & MIPS16_INSN_READ_GPR_X) |
| 3046 | mask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip); |
| 3047 | } |
| 3048 | else |
| 3049 | { |
| 3050 | if (pinfo2 & INSN2_READ_GPR_D) |
| 3051 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip); |
| 3052 | if (pinfo & INSN_READ_GPR_T) |
| 3053 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip); |
| 3054 | if (pinfo & INSN_READ_GPR_S) |
| 3055 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip); |
| 3056 | if (pinfo2 & INSN2_READ_GP) |
| 3057 | mask |= 1 << GP; |
| 3058 | if (pinfo2 & INSN2_READ_GPR_31) |
| 3059 | mask |= 1 << RA; |
| 3060 | if (pinfo2 & INSN2_READ_GPR_Z) |
| 3061 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip); |
| 3062 | } |
| 3063 | if (mips_opts.micromips) |
| 3064 | { |
| 3065 | if (pinfo2 & INSN2_READ_GPR_MC) |
| 3066 | mask |= 1 << micromips_to_32_reg_c_map[EXTRACT_OPERAND (1, MC, *ip)]; |
| 3067 | if (pinfo2 & INSN2_READ_GPR_ME) |
| 3068 | mask |= 1 << micromips_to_32_reg_e_map[EXTRACT_OPERAND (1, ME, *ip)]; |
| 3069 | if (pinfo2 & INSN2_READ_GPR_MG) |
| 3070 | mask |= 1 << micromips_to_32_reg_g_map[EXTRACT_OPERAND (1, MG, *ip)]; |
| 3071 | if (pinfo2 & INSN2_READ_GPR_MJ) |
| 3072 | mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip); |
| 3073 | if (pinfo2 & INSN2_READ_GPR_MMN) |
| 3074 | { |
| 3075 | mask |= 1 << micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)]; |
| 3076 | mask |= 1 << micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)]; |
| 3077 | } |
| 3078 | if (pinfo2 & INSN2_READ_GPR_MP) |
| 3079 | mask |= 1 << EXTRACT_OPERAND (1, MP, *ip); |
| 3080 | if (pinfo2 & INSN2_READ_GPR_MQ) |
| 3081 | mask |= 1 << micromips_to_32_reg_q_map[EXTRACT_OPERAND (1, MQ, *ip)]; |
| 3082 | } |
| 3083 | /* Don't include register 0. */ |
| 3084 | return mask & ~1; |
| 3085 | } |
| 3086 | |
| 3087 | /* Return the mask of core registers that IP writes. */ |
| 3088 | |
| 3089 | static unsigned int |
| 3090 | gpr_write_mask (const struct mips_cl_insn *ip) |
| 3091 | { |
| 3092 | unsigned long pinfo, pinfo2; |
| 3093 | unsigned int mask; |
| 3094 | |
| 3095 | mask = gpr_mod_mask (ip); |
| 3096 | pinfo = ip->insn_mo->pinfo; |
| 3097 | pinfo2 = ip->insn_mo->pinfo2; |
| 3098 | if (mips_opts.mips16) |
| 3099 | { |
| 3100 | if (pinfo & MIPS16_INSN_WRITE_X) |
| 3101 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)]; |
| 3102 | if (pinfo & MIPS16_INSN_WRITE_Y) |
| 3103 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)]; |
| 3104 | if (pinfo & MIPS16_INSN_WRITE_Z) |
| 3105 | mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RZ, *ip)]; |
| 3106 | if (pinfo & MIPS16_INSN_WRITE_T) |
| 3107 | mask |= 1 << TREG; |
| 3108 | if (pinfo & MIPS16_INSN_WRITE_SP) |
| 3109 | mask |= 1 << SP; |
| 3110 | if (pinfo & MIPS16_INSN_WRITE_31) |
| 3111 | mask |= 1 << RA; |
| 3112 | if (pinfo & MIPS16_INSN_WRITE_GPR_Y) |
| 3113 | mask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode); |
| 3114 | } |
| 3115 | else |
| 3116 | { |
| 3117 | if (pinfo & INSN_WRITE_GPR_D) |
| 3118 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip); |
| 3119 | if (pinfo & INSN_WRITE_GPR_T) |
| 3120 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip); |
| 3121 | if (pinfo & INSN_WRITE_GPR_S) |
| 3122 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip); |
| 3123 | if (pinfo & INSN_WRITE_GPR_31) |
| 3124 | mask |= 1 << RA; |
| 3125 | if (pinfo2 & INSN2_WRITE_GPR_Z) |
| 3126 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip); |
| 3127 | } |
| 3128 | if (mips_opts.micromips) |
| 3129 | { |
| 3130 | if (pinfo2 & INSN2_WRITE_GPR_MB) |
| 3131 | mask |= 1 << micromips_to_32_reg_b_map[EXTRACT_OPERAND (1, MB, *ip)]; |
| 3132 | if (pinfo2 & INSN2_WRITE_GPR_MHI) |
| 3133 | { |
| 3134 | mask |= 1 << micromips_to_32_reg_h_map[EXTRACT_OPERAND (1, MH, *ip)]; |
| 3135 | mask |= 1 << micromips_to_32_reg_i_map[EXTRACT_OPERAND (1, MI, *ip)]; |
| 3136 | } |
| 3137 | if (pinfo2 & INSN2_WRITE_GPR_MJ) |
| 3138 | mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip); |
| 3139 | if (pinfo2 & INSN2_WRITE_GPR_MP) |
| 3140 | mask |= 1 << EXTRACT_OPERAND (1, MP, *ip); |
| 3141 | } |
| 3142 | /* Don't include register 0. */ |
| 3143 | return mask & ~1; |
| 3144 | } |
| 3145 | |
| 3146 | /* Return the mask of floating-point registers that IP reads. */ |
| 3147 | |
| 3148 | static unsigned int |
| 3149 | fpr_read_mask (const struct mips_cl_insn *ip) |
| 3150 | { |
| 3151 | unsigned long pinfo, pinfo2; |
| 3152 | unsigned int mask; |
| 3153 | |
| 3154 | mask = 0; |
| 3155 | pinfo = ip->insn_mo->pinfo; |
| 3156 | pinfo2 = ip->insn_mo->pinfo2; |
| 3157 | if (!mips_opts.mips16) |
| 3158 | { |
| 3159 | if (pinfo2 & INSN2_READ_FPR_D) |
| 3160 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip); |
| 3161 | if (pinfo & INSN_READ_FPR_S) |
| 3162 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip); |
| 3163 | if (pinfo & INSN_READ_FPR_T) |
| 3164 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip); |
| 3165 | if (pinfo & INSN_READ_FPR_R) |
| 3166 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FR, *ip); |
| 3167 | if (pinfo2 & INSN2_READ_FPR_Z) |
| 3168 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip); |
| 3169 | } |
| 3170 | /* Conservatively treat all operands to an FP_D instruction are doubles. |
| 3171 | (This is overly pessimistic for things like cvt.d.s.) */ |
| 3172 | if (HAVE_32BIT_FPRS && (pinfo & FP_D)) |
| 3173 | mask |= mask << 1; |
| 3174 | return mask; |
| 3175 | } |
| 3176 | |
| 3177 | /* Return the mask of floating-point registers that IP writes. */ |
| 3178 | |
| 3179 | static unsigned int |
| 3180 | fpr_write_mask (const struct mips_cl_insn *ip) |
| 3181 | { |
| 3182 | unsigned long pinfo, pinfo2; |
| 3183 | unsigned int mask; |
| 3184 | |
| 3185 | mask = 0; |
| 3186 | pinfo = ip->insn_mo->pinfo; |
| 3187 | pinfo2 = ip->insn_mo->pinfo2; |
| 3188 | if (!mips_opts.mips16) |
| 3189 | { |
| 3190 | if (pinfo & INSN_WRITE_FPR_D) |
| 3191 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip); |
| 3192 | if (pinfo & INSN_WRITE_FPR_S) |
| 3193 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip); |
| 3194 | if (pinfo & INSN_WRITE_FPR_T) |
| 3195 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip); |
| 3196 | if (pinfo2 & INSN2_WRITE_FPR_Z) |
| 3197 | mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip); |
| 3198 | } |
| 3199 | /* Conservatively treat all operands to an FP_D instruction are doubles. |
| 3200 | (This is overly pessimistic for things like cvt.s.d.) */ |
| 3201 | if (HAVE_32BIT_FPRS && (pinfo & FP_D)) |
| 3202 | mask |= mask << 1; |
| 3203 | return mask; |
| 3204 | } |
| 3205 | |
| 3206 | /* Classify an instruction according to the FIX_VR4120_* enumeration. |
| 3207 | Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected |
| 3208 | by VR4120 errata. */ |
| 3209 | |
| 3210 | static unsigned int |
| 3211 | classify_vr4120_insn (const char *name) |
| 3212 | { |
| 3213 | if (strncmp (name, "macc", 4) == 0) |
| 3214 | return FIX_VR4120_MACC; |
| 3215 | if (strncmp (name, "dmacc", 5) == 0) |
| 3216 | return FIX_VR4120_DMACC; |
| 3217 | if (strncmp (name, "mult", 4) == 0) |
| 3218 | return FIX_VR4120_MULT; |
| 3219 | if (strncmp (name, "dmult", 5) == 0) |
| 3220 | return FIX_VR4120_DMULT; |
| 3221 | if (strstr (name, "div")) |
| 3222 | return FIX_VR4120_DIV; |
| 3223 | if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0) |
| 3224 | return FIX_VR4120_MTHILO; |
| 3225 | return NUM_FIX_VR4120_CLASSES; |
| 3226 | } |
| 3227 | |
| 3228 | #define INSN_ERET 0x42000018 |
| 3229 | #define INSN_DERET 0x4200001f |
| 3230 | |
| 3231 | /* Return the number of instructions that must separate INSN1 and INSN2, |
| 3232 | where INSN1 is the earlier instruction. Return the worst-case value |
| 3233 | for any INSN2 if INSN2 is null. */ |
| 3234 | |
| 3235 | static unsigned int |
| 3236 | insns_between (const struct mips_cl_insn *insn1, |
| 3237 | const struct mips_cl_insn *insn2) |
| 3238 | { |
| 3239 | unsigned long pinfo1, pinfo2; |
| 3240 | unsigned int mask; |
| 3241 | |
| 3242 | /* This function needs to know which pinfo flags are set for INSN2 |
| 3243 | and which registers INSN2 uses. The former is stored in PINFO2 and |
| 3244 | the latter is tested via INSN2_USES_GPR. If INSN2 is null, PINFO2 |
| 3245 | will have every flag set and INSN2_USES_GPR will always return true. */ |
| 3246 | pinfo1 = insn1->insn_mo->pinfo; |
| 3247 | pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U; |
| 3248 | |
| 3249 | #define INSN2_USES_GPR(REG) \ |
| 3250 | (insn2 == NULL || (gpr_read_mask (insn2) & (1U << (REG))) != 0) |
| 3251 | |
| 3252 | /* For most targets, write-after-read dependencies on the HI and LO |
| 3253 | registers must be separated by at least two instructions. */ |
| 3254 | if (!hilo_interlocks) |
| 3255 | { |
| 3256 | if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO)) |
| 3257 | return 2; |
| 3258 | if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI)) |
| 3259 | return 2; |
| 3260 | } |
| 3261 | |
| 3262 | /* If we're working around r7000 errata, there must be two instructions |
| 3263 | between an mfhi or mflo and any instruction that uses the result. */ |
| 3264 | if (mips_7000_hilo_fix |
| 3265 | && !mips_opts.micromips |
| 3266 | && MF_HILO_INSN (pinfo1) |
| 3267 | && INSN2_USES_GPR (EXTRACT_OPERAND (0, RD, *insn1))) |
| 3268 | return 2; |
| 3269 | |
| 3270 | /* If we're working around 24K errata, one instruction is required |
| 3271 | if an ERET or DERET is followed by a branch instruction. */ |
| 3272 | if (mips_fix_24k && !mips_opts.micromips) |
| 3273 | { |
| 3274 | if (insn1->insn_opcode == INSN_ERET |
| 3275 | || insn1->insn_opcode == INSN_DERET) |
| 3276 | { |
| 3277 | if (insn2 == NULL |
| 3278 | || insn2->insn_opcode == INSN_ERET |
| 3279 | || insn2->insn_opcode == INSN_DERET |
| 3280 | || delayed_branch_p (insn2)) |
| 3281 | return 1; |
| 3282 | } |
| 3283 | } |
| 3284 | |
| 3285 | /* If working around VR4120 errata, check for combinations that need |
| 3286 | a single intervening instruction. */ |
| 3287 | if (mips_fix_vr4120 && !mips_opts.micromips) |
| 3288 | { |
| 3289 | unsigned int class1, class2; |
| 3290 | |
| 3291 | class1 = classify_vr4120_insn (insn1->insn_mo->name); |
| 3292 | if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0) |
| 3293 | { |
| 3294 | if (insn2 == NULL) |
| 3295 | return 1; |
| 3296 | class2 = classify_vr4120_insn (insn2->insn_mo->name); |
| 3297 | if (vr4120_conflicts[class1] & (1 << class2)) |
| 3298 | return 1; |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | if (!HAVE_CODE_COMPRESSION) |
| 3303 | { |
| 3304 | /* Check for GPR or coprocessor load delays. All such delays |
| 3305 | are on the RT register. */ |
| 3306 | /* Itbl support may require additional care here. */ |
| 3307 | if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY)) |
| 3308 | || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY))) |
| 3309 | { |
| 3310 | know (pinfo1 & INSN_WRITE_GPR_T); |
| 3311 | if (INSN2_USES_GPR (EXTRACT_OPERAND (0, RT, *insn1))) |
| 3312 | return 1; |
| 3313 | } |
| 3314 | |
| 3315 | /* Check for generic coprocessor hazards. |
| 3316 | |
| 3317 | This case is not handled very well. There is no special |
| 3318 | knowledge of CP0 handling, and the coprocessors other than |
| 3319 | the floating point unit are not distinguished at all. */ |
| 3320 | /* Itbl support may require additional care here. FIXME! |
| 3321 | Need to modify this to include knowledge about |
| 3322 | user specified delays! */ |
| 3323 | else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY)) |
| 3324 | || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY))) |
| 3325 | { |
| 3326 | /* Handle cases where INSN1 writes to a known general coprocessor |
| 3327 | register. There must be a one instruction delay before INSN2 |
| 3328 | if INSN2 reads that register, otherwise no delay is needed. */ |
| 3329 | mask = fpr_write_mask (insn1); |
| 3330 | if (mask != 0) |
| 3331 | { |
| 3332 | if (!insn2 || (mask & fpr_read_mask (insn2)) != 0) |
| 3333 | return 1; |
| 3334 | } |
| 3335 | else |
| 3336 | { |
| 3337 | /* Read-after-write dependencies on the control registers |
| 3338 | require a two-instruction gap. */ |
| 3339 | if ((pinfo1 & INSN_WRITE_COND_CODE) |
| 3340 | && (pinfo2 & INSN_READ_COND_CODE)) |
| 3341 | return 2; |
| 3342 | |
| 3343 | /* We don't know exactly what INSN1 does. If INSN2 is |
| 3344 | also a coprocessor instruction, assume there must be |
| 3345 | a one instruction gap. */ |
| 3346 | if (pinfo2 & INSN_COP) |
| 3347 | return 1; |
| 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | /* Check for read-after-write dependencies on the coprocessor |
| 3352 | control registers in cases where INSN1 does not need a general |
| 3353 | coprocessor delay. This means that INSN1 is a floating point |
| 3354 | comparison instruction. */ |
| 3355 | /* Itbl support may require additional care here. */ |
| 3356 | else if (!cop_interlocks |
| 3357 | && (pinfo1 & INSN_WRITE_COND_CODE) |
| 3358 | && (pinfo2 & INSN_READ_COND_CODE)) |
| 3359 | return 1; |
| 3360 | } |
| 3361 | |
| 3362 | #undef INSN2_USES_GPR |
| 3363 | |
| 3364 | return 0; |
| 3365 | } |
| 3366 | |
| 3367 | /* Return the number of nops that would be needed to work around the |
| 3368 | VR4130 mflo/mfhi errata if instruction INSN immediately followed |
| 3369 | the MAX_VR4130_NOPS instructions described by HIST. Ignore hazards |
| 3370 | that are contained within the first IGNORE instructions of HIST. */ |
| 3371 | |
| 3372 | static int |
| 3373 | nops_for_vr4130 (int ignore, const struct mips_cl_insn *hist, |
| 3374 | const struct mips_cl_insn *insn) |
| 3375 | { |
| 3376 | int i, j; |
| 3377 | unsigned int mask; |
| 3378 | |
| 3379 | /* Check if the instruction writes to HI or LO. MTHI and MTLO |
| 3380 | are not affected by the errata. */ |
| 3381 | if (insn != 0 |
| 3382 | && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0 |
| 3383 | || strcmp (insn->insn_mo->name, "mtlo") == 0 |
| 3384 | || strcmp (insn->insn_mo->name, "mthi") == 0)) |
| 3385 | return 0; |
| 3386 | |
| 3387 | /* Search for the first MFLO or MFHI. */ |
| 3388 | for (i = 0; i < MAX_VR4130_NOPS; i++) |
| 3389 | if (MF_HILO_INSN (hist[i].insn_mo->pinfo)) |
| 3390 | { |
| 3391 | /* Extract the destination register. */ |
| 3392 | mask = gpr_write_mask (&hist[i]); |
| 3393 | |
| 3394 | /* No nops are needed if INSN reads that register. */ |
| 3395 | if (insn != NULL && (gpr_read_mask (insn) & mask) != 0) |
| 3396 | return 0; |
| 3397 | |
| 3398 | /* ...or if any of the intervening instructions do. */ |
| 3399 | for (j = 0; j < i; j++) |
| 3400 | if (gpr_read_mask (&hist[j]) & mask) |
| 3401 | return 0; |
| 3402 | |
| 3403 | if (i >= ignore) |
| 3404 | return MAX_VR4130_NOPS - i; |
| 3405 | } |
| 3406 | return 0; |
| 3407 | } |
| 3408 | |
| 3409 | #define BASE_REG_EQ(INSN1, INSN2) \ |
| 3410 | ((((INSN1) >> OP_SH_RS) & OP_MASK_RS) \ |
| 3411 | == (((INSN2) >> OP_SH_RS) & OP_MASK_RS)) |
| 3412 | |
| 3413 | /* Return the minimum alignment for this store instruction. */ |
| 3414 | |
| 3415 | static int |
| 3416 | fix_24k_align_to (const struct mips_opcode *mo) |
| 3417 | { |
| 3418 | if (strcmp (mo->name, "sh") == 0) |
| 3419 | return 2; |
| 3420 | |
| 3421 | if (strcmp (mo->name, "swc1") == 0 |
| 3422 | || strcmp (mo->name, "swc2") == 0 |
| 3423 | || strcmp (mo->name, "sw") == 0 |
| 3424 | || strcmp (mo->name, "sc") == 0 |
| 3425 | || strcmp (mo->name, "s.s") == 0) |
| 3426 | return 4; |
| 3427 | |
| 3428 | if (strcmp (mo->name, "sdc1") == 0 |
| 3429 | || strcmp (mo->name, "sdc2") == 0 |
| 3430 | || strcmp (mo->name, "s.d") == 0) |
| 3431 | return 8; |
| 3432 | |
| 3433 | /* sb, swl, swr */ |
| 3434 | return 1; |
| 3435 | } |
| 3436 | |
| 3437 | struct fix_24k_store_info |
| 3438 | { |
| 3439 | /* Immediate offset, if any, for this store instruction. */ |
| 3440 | short off; |
| 3441 | /* Alignment required by this store instruction. */ |
| 3442 | int align_to; |
| 3443 | /* True for register offsets. */ |
| 3444 | int register_offset; |
| 3445 | }; |
| 3446 | |
| 3447 | /* Comparison function used by qsort. */ |
| 3448 | |
| 3449 | static int |
| 3450 | fix_24k_sort (const void *a, const void *b) |
| 3451 | { |
| 3452 | const struct fix_24k_store_info *pos1 = a; |
| 3453 | const struct fix_24k_store_info *pos2 = b; |
| 3454 | |
| 3455 | return (pos1->off - pos2->off); |
| 3456 | } |
| 3457 | |
| 3458 | /* INSN is a store instruction. Try to record the store information |
| 3459 | in STINFO. Return false if the information isn't known. */ |
| 3460 | |
| 3461 | static bfd_boolean |
| 3462 | fix_24k_record_store_info (struct fix_24k_store_info *stinfo, |
| 3463 | const struct mips_cl_insn *insn) |
| 3464 | { |
| 3465 | /* The instruction must have a known offset. */ |
| 3466 | if (!insn->complete_p || !strstr (insn->insn_mo->args, "o(")) |
| 3467 | return FALSE; |
| 3468 | |
| 3469 | stinfo->off = (insn->insn_opcode >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE; |
| 3470 | stinfo->align_to = fix_24k_align_to (insn->insn_mo); |
| 3471 | return TRUE; |
| 3472 | } |
| 3473 | |
| 3474 | /* Return the number of nops that would be needed to work around the 24k |
| 3475 | "lost data on stores during refill" errata if instruction INSN |
| 3476 | immediately followed the 2 instructions described by HIST. |
| 3477 | Ignore hazards that are contained within the first IGNORE |
| 3478 | instructions of HIST. |
| 3479 | |
| 3480 | Problem: The FSB (fetch store buffer) acts as an intermediate buffer |
| 3481 | for the data cache refills and store data. The following describes |
| 3482 | the scenario where the store data could be lost. |
| 3483 | |
| 3484 | * A data cache miss, due to either a load or a store, causing fill |
| 3485 | data to be supplied by the memory subsystem |
| 3486 | * The first three doublewords of fill data are returned and written |
| 3487 | into the cache |
| 3488 | * A sequence of four stores occurs in consecutive cycles around the |
| 3489 | final doubleword of the fill: |
| 3490 | * Store A |
| 3491 | * Store B |
| 3492 | * Store C |
| 3493 | * Zero, One or more instructions |
| 3494 | * Store D |
| 3495 | |
| 3496 | The four stores A-D must be to different doublewords of the line that |
| 3497 | is being filled. The fourth instruction in the sequence above permits |
| 3498 | the fill of the final doubleword to be transferred from the FSB into |
| 3499 | the cache. In the sequence above, the stores may be either integer |
| 3500 | (sb, sh, sw, swr, swl, sc) or coprocessor (swc1/swc2, sdc1/sdc2, |
| 3501 | swxc1, sdxc1, suxc1) stores, as long as the four stores are to |
| 3502 | different doublewords on the line. If the floating point unit is |
| 3503 | running in 1:2 mode, it is not possible to create the sequence above |
| 3504 | using only floating point store instructions. |
| 3505 | |
| 3506 | In this case, the cache line being filled is incorrectly marked |
| 3507 | invalid, thereby losing the data from any store to the line that |
| 3508 | occurs between the original miss and the completion of the five |
| 3509 | cycle sequence shown above. |
| 3510 | |
| 3511 | The workarounds are: |
| 3512 | |
| 3513 | * Run the data cache in write-through mode. |
| 3514 | * Insert a non-store instruction between |
| 3515 | Store A and Store B or Store B and Store C. */ |
| 3516 | |
| 3517 | static int |
| 3518 | nops_for_24k (int ignore, const struct mips_cl_insn *hist, |
| 3519 | const struct mips_cl_insn *insn) |
| 3520 | { |
| 3521 | struct fix_24k_store_info pos[3]; |
| 3522 | int align, i, base_offset; |
| 3523 | |
| 3524 | if (ignore >= 2) |
| 3525 | return 0; |
| 3526 | |
| 3527 | /* If the previous instruction wasn't a store, there's nothing to |
| 3528 | worry about. */ |
| 3529 | if ((hist[0].insn_mo->pinfo & INSN_STORE_MEMORY) == 0) |
| 3530 | return 0; |
| 3531 | |
| 3532 | /* If the instructions after the previous one are unknown, we have |
| 3533 | to assume the worst. */ |
| 3534 | if (!insn) |
| 3535 | return 1; |
| 3536 | |
| 3537 | /* Check whether we are dealing with three consecutive stores. */ |
| 3538 | if ((insn->insn_mo->pinfo & INSN_STORE_MEMORY) == 0 |
| 3539 | || (hist[1].insn_mo->pinfo & INSN_STORE_MEMORY) == 0) |
| 3540 | return 0; |
| 3541 | |
| 3542 | /* If we don't know the relationship between the store addresses, |
| 3543 | assume the worst. */ |
| 3544 | if (!BASE_REG_EQ (insn->insn_opcode, hist[0].insn_opcode) |
| 3545 | || !BASE_REG_EQ (insn->insn_opcode, hist[1].insn_opcode)) |
| 3546 | return 1; |
| 3547 | |
| 3548 | if (!fix_24k_record_store_info (&pos[0], insn) |
| 3549 | || !fix_24k_record_store_info (&pos[1], &hist[0]) |
| 3550 | || !fix_24k_record_store_info (&pos[2], &hist[1])) |
| 3551 | return 1; |
| 3552 | |
| 3553 | qsort (&pos, 3, sizeof (struct fix_24k_store_info), fix_24k_sort); |
| 3554 | |
| 3555 | /* Pick a value of ALIGN and X such that all offsets are adjusted by |
| 3556 | X bytes and such that the base register + X is known to be aligned |
| 3557 | to align bytes. */ |
| 3558 | |
| 3559 | if (((insn->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == SP) |
| 3560 | align = 8; |
| 3561 | else |
| 3562 | { |
| 3563 | align = pos[0].align_to; |
| 3564 | base_offset = pos[0].off; |
| 3565 | for (i = 1; i < 3; i++) |
| 3566 | if (align < pos[i].align_to) |
| 3567 | { |
| 3568 | align = pos[i].align_to; |
| 3569 | base_offset = pos[i].off; |
| 3570 | } |
| 3571 | for (i = 0; i < 3; i++) |
| 3572 | pos[i].off -= base_offset; |
| 3573 | } |
| 3574 | |
| 3575 | pos[0].off &= ~align + 1; |
| 3576 | pos[1].off &= ~align + 1; |
| 3577 | pos[2].off &= ~align + 1; |
| 3578 | |
| 3579 | /* If any two stores write to the same chunk, they also write to the |
| 3580 | same doubleword. The offsets are still sorted at this point. */ |
| 3581 | if (pos[0].off == pos[1].off || pos[1].off == pos[2].off) |
| 3582 | return 0; |
| 3583 | |
| 3584 | /* A range of at least 9 bytes is needed for the stores to be in |
| 3585 | non-overlapping doublewords. */ |
| 3586 | if (pos[2].off - pos[0].off <= 8) |
| 3587 | return 0; |
| 3588 | |
| 3589 | if (pos[2].off - pos[1].off >= 24 |
| 3590 | || pos[1].off - pos[0].off >= 24 |
| 3591 | || pos[2].off - pos[0].off >= 32) |
| 3592 | return 0; |
| 3593 | |
| 3594 | return 1; |
| 3595 | } |
| 3596 | |
| 3597 | /* Return the number of nops that would be needed if instruction INSN |
| 3598 | immediately followed the MAX_NOPS instructions given by HIST, |
| 3599 | where HIST[0] is the most recent instruction. Ignore hazards |
| 3600 | between INSN and the first IGNORE instructions in HIST. |
| 3601 | |
| 3602 | If INSN is null, return the worse-case number of nops for any |
| 3603 | instruction. */ |
| 3604 | |
| 3605 | static int |
| 3606 | nops_for_insn (int ignore, const struct mips_cl_insn *hist, |
| 3607 | const struct mips_cl_insn *insn) |
| 3608 | { |
| 3609 | int i, nops, tmp_nops; |
| 3610 | |
| 3611 | nops = 0; |
| 3612 | for (i = ignore; i < MAX_DELAY_NOPS; i++) |
| 3613 | { |
| 3614 | tmp_nops = insns_between (hist + i, insn) - i; |
| 3615 | if (tmp_nops > nops) |
| 3616 | nops = tmp_nops; |
| 3617 | } |
| 3618 | |
| 3619 | if (mips_fix_vr4130 && !mips_opts.micromips) |
| 3620 | { |
| 3621 | tmp_nops = nops_for_vr4130 (ignore, hist, insn); |
| 3622 | if (tmp_nops > nops) |
| 3623 | nops = tmp_nops; |
| 3624 | } |
| 3625 | |
| 3626 | if (mips_fix_24k && !mips_opts.micromips) |
| 3627 | { |
| 3628 | tmp_nops = nops_for_24k (ignore, hist, insn); |
| 3629 | if (tmp_nops > nops) |
| 3630 | nops = tmp_nops; |
| 3631 | } |
| 3632 | |
| 3633 | return nops; |
| 3634 | } |
| 3635 | |
| 3636 | /* The variable arguments provide NUM_INSNS extra instructions that |
| 3637 | might be added to HIST. Return the largest number of nops that |
| 3638 | would be needed after the extended sequence, ignoring hazards |
| 3639 | in the first IGNORE instructions. */ |
| 3640 | |
| 3641 | static int |
| 3642 | nops_for_sequence (int num_insns, int ignore, |
| 3643 | const struct mips_cl_insn *hist, ...) |
| 3644 | { |
| 3645 | va_list args; |
| 3646 | struct mips_cl_insn buffer[MAX_NOPS]; |
| 3647 | struct mips_cl_insn *cursor; |
| 3648 | int nops; |
| 3649 | |
| 3650 | va_start (args, hist); |
| 3651 | cursor = buffer + num_insns; |
| 3652 | memcpy (cursor, hist, (MAX_NOPS - num_insns) * sizeof (*cursor)); |
| 3653 | while (cursor > buffer) |
| 3654 | *--cursor = *va_arg (args, const struct mips_cl_insn *); |
| 3655 | |
| 3656 | nops = nops_for_insn (ignore, buffer, NULL); |
| 3657 | va_end (args); |
| 3658 | return nops; |
| 3659 | } |
| 3660 | |
| 3661 | /* Like nops_for_insn, but if INSN is a branch, take into account the |
| 3662 | worst-case delay for the branch target. */ |
| 3663 | |
| 3664 | static int |
| 3665 | nops_for_insn_or_target (int ignore, const struct mips_cl_insn *hist, |
| 3666 | const struct mips_cl_insn *insn) |
| 3667 | { |
| 3668 | int nops, tmp_nops; |
| 3669 | |
| 3670 | nops = nops_for_insn (ignore, hist, insn); |
| 3671 | if (delayed_branch_p (insn)) |
| 3672 | { |
| 3673 | tmp_nops = nops_for_sequence (2, ignore ? ignore + 2 : 0, |
| 3674 | hist, insn, get_delay_slot_nop (insn)); |
| 3675 | if (tmp_nops > nops) |
| 3676 | nops = tmp_nops; |
| 3677 | } |
| 3678 | else if (compact_branch_p (insn)) |
| 3679 | { |
| 3680 | tmp_nops = nops_for_sequence (1, ignore ? ignore + 1 : 0, hist, insn); |
| 3681 | if (tmp_nops > nops) |
| 3682 | nops = tmp_nops; |
| 3683 | } |
| 3684 | return nops; |
| 3685 | } |
| 3686 | |
| 3687 | /* Fix NOP issue: Replace nops by "or at,at,zero". */ |
| 3688 | |
| 3689 | static void |
| 3690 | fix_loongson2f_nop (struct mips_cl_insn * ip) |
| 3691 | { |
| 3692 | gas_assert (!HAVE_CODE_COMPRESSION); |
| 3693 | if (strcmp (ip->insn_mo->name, "nop") == 0) |
| 3694 | ip->insn_opcode = LOONGSON2F_NOP_INSN; |
| 3695 | } |
| 3696 | |
| 3697 | /* Fix Jump Issue: Eliminate instruction fetch from outside 256M region |
| 3698 | jr target pc &= 'hffff_ffff_cfff_ffff. */ |
| 3699 | |
| 3700 | static void |
| 3701 | fix_loongson2f_jump (struct mips_cl_insn * ip) |
| 3702 | { |
| 3703 | gas_assert (!HAVE_CODE_COMPRESSION); |
| 3704 | if (strcmp (ip->insn_mo->name, "j") == 0 |
| 3705 | || strcmp (ip->insn_mo->name, "jr") == 0 |
| 3706 | || strcmp (ip->insn_mo->name, "jalr") == 0) |
| 3707 | { |
| 3708 | int sreg; |
| 3709 | expressionS ep; |
| 3710 | |
| 3711 | if (! mips_opts.at) |
| 3712 | return; |
| 3713 | |
| 3714 | sreg = EXTRACT_OPERAND (0, RS, *ip); |
| 3715 | if (sreg == ZERO || sreg == KT0 || sreg == KT1 || sreg == ATREG) |
| 3716 | return; |
| 3717 | |
| 3718 | ep.X_op = O_constant; |
| 3719 | ep.X_add_number = 0xcfff0000; |
| 3720 | macro_build (&ep, "lui", "t,u", ATREG, BFD_RELOC_HI16); |
| 3721 | ep.X_add_number = 0xffff; |
| 3722 | macro_build (&ep, "ori", "t,r,i", ATREG, ATREG, BFD_RELOC_LO16); |
| 3723 | macro_build (NULL, "and", "d,v,t", sreg, sreg, ATREG); |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | static void |
| 3728 | fix_loongson2f (struct mips_cl_insn * ip) |
| 3729 | { |
| 3730 | if (mips_fix_loongson2f_nop) |
| 3731 | fix_loongson2f_nop (ip); |
| 3732 | |
| 3733 | if (mips_fix_loongson2f_jump) |
| 3734 | fix_loongson2f_jump (ip); |
| 3735 | } |
| 3736 | |
| 3737 | /* IP is a branch that has a delay slot, and we need to fill it |
| 3738 | automatically. Return true if we can do that by swapping IP |
| 3739 | with the previous instruction. */ |
| 3740 | |
| 3741 | static bfd_boolean |
| 3742 | can_swap_branch_p (struct mips_cl_insn *ip) |
| 3743 | { |
| 3744 | unsigned long pinfo, pinfo2, prev_pinfo, prev_pinfo2; |
| 3745 | unsigned int gpr_read, gpr_write, prev_gpr_read, prev_gpr_write; |
| 3746 | |
| 3747 | /* -O2 and above is required for this optimization. */ |
| 3748 | if (mips_optimize < 2) |
| 3749 | return FALSE; |
| 3750 | |
| 3751 | /* If we have seen .set volatile or .set nomove, don't optimize. */ |
| 3752 | if (mips_opts.nomove) |
| 3753 | return FALSE; |
| 3754 | |
| 3755 | /* We can't swap if the previous instruction's position is fixed. */ |
| 3756 | if (history[0].fixed_p) |
| 3757 | return FALSE; |
| 3758 | |
| 3759 | /* If the previous previous insn was in a .set noreorder, we can't |
| 3760 | swap. Actually, the MIPS assembler will swap in this situation. |
| 3761 | However, gcc configured -with-gnu-as will generate code like |
| 3762 | |
| 3763 | .set noreorder |
| 3764 | lw $4,XXX |
| 3765 | .set reorder |
| 3766 | INSN |
| 3767 | bne $4,$0,foo |
| 3768 | |
| 3769 | in which we can not swap the bne and INSN. If gcc is not configured |
| 3770 | -with-gnu-as, it does not output the .set pseudo-ops. */ |
| 3771 | if (history[1].noreorder_p) |
| 3772 | return FALSE; |
| 3773 | |
| 3774 | /* If the previous instruction had a fixup in mips16 mode, we can not swap. |
| 3775 | This means that the previous instruction was a 4-byte one anyhow. */ |
| 3776 | if (mips_opts.mips16 && history[0].fixp[0]) |
| 3777 | return FALSE; |
| 3778 | |
| 3779 | /* If the branch is itself the target of a branch, we can not swap. |
| 3780 | We cheat on this; all we check for is whether there is a label on |
| 3781 | this instruction. If there are any branches to anything other than |
| 3782 | a label, users must use .set noreorder. */ |
| 3783 | if (seg_info (now_seg)->label_list) |
| 3784 | return FALSE; |
| 3785 | |
| 3786 | /* If the previous instruction is in a variant frag other than this |
| 3787 | branch's one, we cannot do the swap. This does not apply to |
| 3788 | MIPS16 code, which uses variant frags for different purposes. */ |
| 3789 | if (!mips_opts.mips16 |
| 3790 | && history[0].frag |
| 3791 | && history[0].frag->fr_type == rs_machine_dependent) |
| 3792 | return FALSE; |
| 3793 | |
| 3794 | /* We do not swap with instructions that cannot architecturally |
| 3795 | be placed in a branch delay slot, such as SYNC or ERET. We |
| 3796 | also refrain from swapping with a trap instruction, since it |
| 3797 | complicates trap handlers to have the trap instruction be in |
| 3798 | a delay slot. */ |
| 3799 | prev_pinfo = history[0].insn_mo->pinfo; |
| 3800 | if (prev_pinfo & INSN_NO_DELAY_SLOT) |
| 3801 | return FALSE; |
| 3802 | |
| 3803 | /* Check for conflicts between the branch and the instructions |
| 3804 | before the candidate delay slot. */ |
| 3805 | if (nops_for_insn (0, history + 1, ip) > 0) |
| 3806 | return FALSE; |
| 3807 | |
| 3808 | /* Check for conflicts between the swapped sequence and the |
| 3809 | target of the branch. */ |
| 3810 | if (nops_for_sequence (2, 0, history + 1, ip, history) > 0) |
| 3811 | return FALSE; |
| 3812 | |
| 3813 | /* If the branch reads a register that the previous |
| 3814 | instruction sets, we can not swap. */ |
| 3815 | gpr_read = gpr_read_mask (ip); |
| 3816 | prev_gpr_write = gpr_write_mask (&history[0]); |
| 3817 | if (gpr_read & prev_gpr_write) |
| 3818 | return FALSE; |
| 3819 | |
| 3820 | /* If the branch writes a register that the previous |
| 3821 | instruction sets, we can not swap. */ |
| 3822 | gpr_write = gpr_write_mask (ip); |
| 3823 | if (gpr_write & prev_gpr_write) |
| 3824 | return FALSE; |
| 3825 | |
| 3826 | /* If the branch writes a register that the previous |
| 3827 | instruction reads, we can not swap. */ |
| 3828 | prev_gpr_read = gpr_read_mask (&history[0]); |
| 3829 | if (gpr_write & prev_gpr_read) |
| 3830 | return FALSE; |
| 3831 | |
| 3832 | /* If one instruction sets a condition code and the |
| 3833 | other one uses a condition code, we can not swap. */ |
| 3834 | pinfo = ip->insn_mo->pinfo; |
| 3835 | if ((pinfo & INSN_READ_COND_CODE) |
| 3836 | && (prev_pinfo & INSN_WRITE_COND_CODE)) |
| 3837 | return FALSE; |
| 3838 | if ((pinfo & INSN_WRITE_COND_CODE) |
| 3839 | && (prev_pinfo & INSN_READ_COND_CODE)) |
| 3840 | return FALSE; |
| 3841 | |
| 3842 | /* If the previous instruction uses the PC, we can not swap. */ |
| 3843 | prev_pinfo2 = history[0].insn_mo->pinfo2; |
| 3844 | if (mips_opts.mips16 && (prev_pinfo & MIPS16_INSN_READ_PC)) |
| 3845 | return FALSE; |
| 3846 | if (mips_opts.micromips && (prev_pinfo2 & INSN2_READ_PC)) |
| 3847 | return FALSE; |
| 3848 | |
| 3849 | /* If the previous instruction has an incorrect size for a fixed |
| 3850 | branch delay slot in microMIPS mode, we cannot swap. */ |
| 3851 | pinfo2 = ip->insn_mo->pinfo2; |
| 3852 | if (mips_opts.micromips |
| 3853 | && (pinfo2 & INSN2_BRANCH_DELAY_16BIT) |
| 3854 | && insn_length (history) != 2) |
| 3855 | return FALSE; |
| 3856 | if (mips_opts.micromips |
| 3857 | && (pinfo2 & INSN2_BRANCH_DELAY_32BIT) |
| 3858 | && insn_length (history) != 4) |
| 3859 | return FALSE; |
| 3860 | |
| 3861 | return TRUE; |
| 3862 | } |
| 3863 | |
| 3864 | /* Decide how we should add IP to the instruction stream. */ |
| 3865 | |
| 3866 | static enum append_method |
| 3867 | get_append_method (struct mips_cl_insn *ip) |
| 3868 | { |
| 3869 | unsigned long pinfo; |
| 3870 | |
| 3871 | /* The relaxed version of a macro sequence must be inherently |
| 3872 | hazard-free. */ |
| 3873 | if (mips_relax.sequence == 2) |
| 3874 | return APPEND_ADD; |
| 3875 | |
| 3876 | /* We must not dabble with instructions in a ".set norerorder" block. */ |
| 3877 | if (mips_opts.noreorder) |
| 3878 | return APPEND_ADD; |
| 3879 | |
| 3880 | /* Otherwise, it's our responsibility to fill branch delay slots. */ |
| 3881 | if (delayed_branch_p (ip)) |
| 3882 | { |
| 3883 | if (!branch_likely_p (ip) && can_swap_branch_p (ip)) |
| 3884 | return APPEND_SWAP; |
| 3885 | |
| 3886 | pinfo = ip->insn_mo->pinfo; |
| 3887 | if (mips_opts.mips16 |
| 3888 | && ISA_SUPPORTS_MIPS16E |
| 3889 | && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31))) |
| 3890 | return APPEND_ADD_COMPACT; |
| 3891 | |
| 3892 | return APPEND_ADD_WITH_NOP; |
| 3893 | } |
| 3894 | |
| 3895 | return APPEND_ADD; |
| 3896 | } |
| 3897 | |
| 3898 | /* IP is a MIPS16 instruction whose opcode we have just changed. |
| 3899 | Point IP->insn_mo to the new opcode's definition. */ |
| 3900 | |
| 3901 | static void |
| 3902 | find_altered_mips16_opcode (struct mips_cl_insn *ip) |
| 3903 | { |
| 3904 | const struct mips_opcode *mo, *end; |
| 3905 | |
| 3906 | end = &mips16_opcodes[bfd_mips16_num_opcodes]; |
| 3907 | for (mo = ip->insn_mo; mo < end; mo++) |
| 3908 | if ((ip->insn_opcode & mo->mask) == mo->match) |
| 3909 | { |
| 3910 | ip->insn_mo = mo; |
| 3911 | return; |
| 3912 | } |
| 3913 | abort (); |
| 3914 | } |
| 3915 | |
| 3916 | /* For microMIPS macros, we need to generate a local number label |
| 3917 | as the target of branches. */ |
| 3918 | #define MICROMIPS_LABEL_CHAR '\037' |
| 3919 | static unsigned long micromips_target_label; |
| 3920 | static char micromips_target_name[32]; |
| 3921 | |
| 3922 | static char * |
| 3923 | micromips_label_name (void) |
| 3924 | { |
| 3925 | char *p = micromips_target_name; |
| 3926 | char symbol_name_temporary[24]; |
| 3927 | unsigned long l; |
| 3928 | int i; |
| 3929 | |
| 3930 | if (*p) |
| 3931 | return p; |
| 3932 | |
| 3933 | i = 0; |
| 3934 | l = micromips_target_label; |
| 3935 | #ifdef LOCAL_LABEL_PREFIX |
| 3936 | *p++ = LOCAL_LABEL_PREFIX; |
| 3937 | #endif |
| 3938 | *p++ = 'L'; |
| 3939 | *p++ = MICROMIPS_LABEL_CHAR; |
| 3940 | do |
| 3941 | { |
| 3942 | symbol_name_temporary[i++] = l % 10 + '0'; |
| 3943 | l /= 10; |
| 3944 | } |
| 3945 | while (l != 0); |
| 3946 | while (i > 0) |
| 3947 | *p++ = symbol_name_temporary[--i]; |
| 3948 | *p = '\0'; |
| 3949 | |
| 3950 | return micromips_target_name; |
| 3951 | } |
| 3952 | |
| 3953 | static void |
| 3954 | micromips_label_expr (expressionS *label_expr) |
| 3955 | { |
| 3956 | label_expr->X_op = O_symbol; |
| 3957 | label_expr->X_add_symbol = symbol_find_or_make (micromips_label_name ()); |
| 3958 | label_expr->X_add_number = 0; |
| 3959 | } |
| 3960 | |
| 3961 | static void |
| 3962 | micromips_label_inc (void) |
| 3963 | { |
| 3964 | micromips_target_label++; |
| 3965 | *micromips_target_name = '\0'; |
| 3966 | } |
| 3967 | |
| 3968 | static void |
| 3969 | micromips_add_label (void) |
| 3970 | { |
| 3971 | symbolS *s; |
| 3972 | |
| 3973 | s = colon (micromips_label_name ()); |
| 3974 | micromips_label_inc (); |
| 3975 | #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF) |
| 3976 | if (IS_ELF) |
| 3977 | S_SET_OTHER (s, ELF_ST_SET_MICROMIPS (S_GET_OTHER (s))); |
| 3978 | #else |
| 3979 | (void) s; |
| 3980 | #endif |
| 3981 | } |
| 3982 | |
| 3983 | /* If assembling microMIPS code, then return the microMIPS reloc |
| 3984 | corresponding to the requested one if any. Otherwise return |
| 3985 | the reloc unchanged. */ |
| 3986 | |
| 3987 | static bfd_reloc_code_real_type |
| 3988 | micromips_map_reloc (bfd_reloc_code_real_type reloc) |
| 3989 | { |
| 3990 | static const bfd_reloc_code_real_type relocs[][2] = |
| 3991 | { |
| 3992 | /* Keep sorted incrementally by the left-hand key. */ |
| 3993 | { BFD_RELOC_16_PCREL_S2, BFD_RELOC_MICROMIPS_16_PCREL_S1 }, |
| 3994 | { BFD_RELOC_GPREL16, BFD_RELOC_MICROMIPS_GPREL16 }, |
| 3995 | { BFD_RELOC_MIPS_JMP, BFD_RELOC_MICROMIPS_JMP }, |
| 3996 | { BFD_RELOC_HI16, BFD_RELOC_MICROMIPS_HI16 }, |
| 3997 | { BFD_RELOC_HI16_S, BFD_RELOC_MICROMIPS_HI16_S }, |
| 3998 | { BFD_RELOC_LO16, BFD_RELOC_MICROMIPS_LO16 }, |
| 3999 | { BFD_RELOC_MIPS_LITERAL, BFD_RELOC_MICROMIPS_LITERAL }, |
| 4000 | { BFD_RELOC_MIPS_GOT16, BFD_RELOC_MICROMIPS_GOT16 }, |
| 4001 | { BFD_RELOC_MIPS_CALL16, BFD_RELOC_MICROMIPS_CALL16 }, |
| 4002 | { BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MICROMIPS_GOT_HI16 }, |
| 4003 | { BFD_RELOC_MIPS_GOT_LO16, BFD_RELOC_MICROMIPS_GOT_LO16 }, |
| 4004 | { BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MICROMIPS_CALL_HI16 }, |
| 4005 | { BFD_RELOC_MIPS_CALL_LO16, BFD_RELOC_MICROMIPS_CALL_LO16 }, |
| 4006 | { BFD_RELOC_MIPS_SUB, BFD_RELOC_MICROMIPS_SUB }, |
| 4007 | { BFD_RELOC_MIPS_GOT_PAGE, BFD_RELOC_MICROMIPS_GOT_PAGE }, |
| 4008 | { BFD_RELOC_MIPS_GOT_OFST, BFD_RELOC_MICROMIPS_GOT_OFST }, |
| 4009 | { BFD_RELOC_MIPS_GOT_DISP, BFD_RELOC_MICROMIPS_GOT_DISP }, |
| 4010 | { BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MICROMIPS_HIGHEST }, |
| 4011 | { BFD_RELOC_MIPS_HIGHER, BFD_RELOC_MICROMIPS_HIGHER }, |
| 4012 | { BFD_RELOC_MIPS_SCN_DISP, BFD_RELOC_MICROMIPS_SCN_DISP }, |
| 4013 | { BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MICROMIPS_TLS_GD }, |
| 4014 | { BFD_RELOC_MIPS_TLS_LDM, BFD_RELOC_MICROMIPS_TLS_LDM }, |
| 4015 | { BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16 }, |
| 4016 | { BFD_RELOC_MIPS_TLS_DTPREL_LO16, BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16 }, |
| 4017 | { BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MICROMIPS_TLS_GOTTPREL }, |
| 4018 | { BFD_RELOC_MIPS_TLS_TPREL_HI16, BFD_RELOC_MICROMIPS_TLS_TPREL_HI16 }, |
| 4019 | { BFD_RELOC_MIPS_TLS_TPREL_LO16, BFD_RELOC_MICROMIPS_TLS_TPREL_LO16 } |
| 4020 | }; |
| 4021 | bfd_reloc_code_real_type r; |
| 4022 | size_t i; |
| 4023 | |
| 4024 | if (!mips_opts.micromips) |
| 4025 | return reloc; |
| 4026 | for (i = 0; i < ARRAY_SIZE (relocs); i++) |
| 4027 | { |
| 4028 | r = relocs[i][0]; |
| 4029 | if (r > reloc) |
| 4030 | return reloc; |
| 4031 | if (r == reloc) |
| 4032 | return relocs[i][1]; |
| 4033 | } |
| 4034 | return reloc; |
| 4035 | } |
| 4036 | |
| 4037 | /* Try to resolve relocation RELOC against constant OPERAND at assembly time. |
| 4038 | Return true on success, storing the resolved value in RESULT. */ |
| 4039 | |
| 4040 | static bfd_boolean |
| 4041 | calculate_reloc (bfd_reloc_code_real_type reloc, offsetT operand, |
| 4042 | offsetT *result) |
| 4043 | { |
| 4044 | switch (reloc) |
| 4045 | { |
| 4046 | case BFD_RELOC_MIPS_HIGHEST: |
| 4047 | case BFD_RELOC_MICROMIPS_HIGHEST: |
| 4048 | *result = ((operand + 0x800080008000ull) >> 48) & 0xffff; |
| 4049 | return TRUE; |
| 4050 | |
| 4051 | case BFD_RELOC_MIPS_HIGHER: |
| 4052 | case BFD_RELOC_MICROMIPS_HIGHER: |
| 4053 | *result = ((operand + 0x80008000ull) >> 32) & 0xffff; |
| 4054 | return TRUE; |
| 4055 | |
| 4056 | case BFD_RELOC_HI16_S: |
| 4057 | case BFD_RELOC_MICROMIPS_HI16_S: |
| 4058 | case BFD_RELOC_MIPS16_HI16_S: |
| 4059 | *result = ((operand + 0x8000) >> 16) & 0xffff; |
| 4060 | return TRUE; |
| 4061 | |
| 4062 | case BFD_RELOC_HI16: |
| 4063 | case BFD_RELOC_MICROMIPS_HI16: |
| 4064 | case BFD_RELOC_MIPS16_HI16: |
| 4065 | *result = (operand >> 16) & 0xffff; |
| 4066 | return TRUE; |
| 4067 | |
| 4068 | case BFD_RELOC_LO16: |
| 4069 | case BFD_RELOC_MICROMIPS_LO16: |
| 4070 | case BFD_RELOC_MIPS16_LO16: |
| 4071 | *result = operand & 0xffff; |
| 4072 | return TRUE; |
| 4073 | |
| 4074 | case BFD_RELOC_UNUSED: |
| 4075 | *result = operand; |
| 4076 | return TRUE; |
| 4077 | |
| 4078 | default: |
| 4079 | return FALSE; |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | /* Output an instruction. IP is the instruction information. |
| 4084 | ADDRESS_EXPR is an operand of the instruction to be used with |
| 4085 | RELOC_TYPE. EXPANSIONP is true if the instruction is part of |
| 4086 | a macro expansion. */ |
| 4087 | |
| 4088 | static void |
| 4089 | append_insn (struct mips_cl_insn *ip, expressionS *address_expr, |
| 4090 | bfd_reloc_code_real_type *reloc_type, bfd_boolean expansionp) |
| 4091 | { |
| 4092 | unsigned long prev_pinfo2, pinfo; |
| 4093 | bfd_boolean relaxed_branch = FALSE; |
| 4094 | enum append_method method; |
| 4095 | bfd_boolean relax32; |
| 4096 | int branch_disp; |
| 4097 | |
| 4098 | if (mips_fix_loongson2f && !HAVE_CODE_COMPRESSION) |
| 4099 | fix_loongson2f (ip); |
| 4100 | |
| 4101 | file_ase_mips16 |= mips_opts.mips16; |
| 4102 | file_ase_micromips |= mips_opts.micromips; |
| 4103 | |
| 4104 | prev_pinfo2 = history[0].insn_mo->pinfo2; |
| 4105 | pinfo = ip->insn_mo->pinfo; |
| 4106 | |
| 4107 | if (mips_opts.micromips |
| 4108 | && !expansionp |
| 4109 | && (((prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 |
| 4110 | && micromips_insn_length (ip->insn_mo) != 2) |
| 4111 | || ((prev_pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0 |
| 4112 | && micromips_insn_length (ip->insn_mo) != 4))) |
| 4113 | as_warn (_("Wrong size instruction in a %u-bit branch delay slot"), |
| 4114 | (prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 ? 16 : 32); |
| 4115 | |
| 4116 | if (address_expr == NULL) |
| 4117 | ip->complete_p = 1; |
| 4118 | else if (reloc_type[0] <= BFD_RELOC_UNUSED |
| 4119 | && reloc_type[1] == BFD_RELOC_UNUSED |
| 4120 | && reloc_type[2] == BFD_RELOC_UNUSED |
| 4121 | && address_expr->X_op == O_constant) |
| 4122 | { |
| 4123 | switch (*reloc_type) |
| 4124 | { |
| 4125 | case BFD_RELOC_MIPS_JMP: |
| 4126 | { |
| 4127 | int shift; |
| 4128 | |
| 4129 | shift = mips_opts.micromips ? 1 : 2; |
| 4130 | if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0) |
| 4131 | as_bad (_("jump to misaligned address (0x%lx)"), |
| 4132 | (unsigned long) address_expr->X_add_number); |
| 4133 | ip->insn_opcode |= ((address_expr->X_add_number >> shift) |
| 4134 | & 0x3ffffff); |
| 4135 | ip->complete_p = 1; |
| 4136 | } |
| 4137 | break; |
| 4138 | |
| 4139 | case BFD_RELOC_MIPS16_JMP: |
| 4140 | if ((address_expr->X_add_number & 3) != 0) |
| 4141 | as_bad (_("jump to misaligned address (0x%lx)"), |
| 4142 | (unsigned long) address_expr->X_add_number); |
| 4143 | ip->insn_opcode |= |
| 4144 | (((address_expr->X_add_number & 0x7c0000) << 3) |
| 4145 | | ((address_expr->X_add_number & 0xf800000) >> 7) |
| 4146 | | ((address_expr->X_add_number & 0x3fffc) >> 2)); |
| 4147 | ip->complete_p = 1; |
| 4148 | break; |
| 4149 | |
| 4150 | case BFD_RELOC_16_PCREL_S2: |
| 4151 | { |
| 4152 | int shift; |
| 4153 | |
| 4154 | shift = mips_opts.micromips ? 1 : 2; |
| 4155 | if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0) |
| 4156 | as_bad (_("branch to misaligned address (0x%lx)"), |
| 4157 | (unsigned long) address_expr->X_add_number); |
| 4158 | if (!mips_relax_branch) |
| 4159 | { |
| 4160 | if ((address_expr->X_add_number + (1 << (shift + 15))) |
| 4161 | & ~((1 << (shift + 16)) - 1)) |
| 4162 | as_bad (_("branch address range overflow (0x%lx)"), |
| 4163 | (unsigned long) address_expr->X_add_number); |
| 4164 | ip->insn_opcode |= ((address_expr->X_add_number >> shift) |
| 4165 | & 0xffff); |
| 4166 | } |
| 4167 | } |
| 4168 | break; |
| 4169 | |
| 4170 | default: |
| 4171 | { |
| 4172 | offsetT value; |
| 4173 | |
| 4174 | if (calculate_reloc (*reloc_type, address_expr->X_add_number, |
| 4175 | &value)) |
| 4176 | { |
| 4177 | ip->insn_opcode |= value & 0xffff; |
| 4178 | ip->complete_p = 1; |
| 4179 | } |
| 4180 | } |
| 4181 | break; |
| 4182 | } |
| 4183 | } |
| 4184 | |
| 4185 | if (mips_relax.sequence != 2 && !mips_opts.noreorder) |
| 4186 | { |
| 4187 | /* There are a lot of optimizations we could do that we don't. |
| 4188 | In particular, we do not, in general, reorder instructions. |
| 4189 | If you use gcc with optimization, it will reorder |
| 4190 | instructions and generally do much more optimization then we |
| 4191 | do here; repeating all that work in the assembler would only |
| 4192 | benefit hand written assembly code, and does not seem worth |
| 4193 | it. */ |
| 4194 | int nops = (mips_optimize == 0 |
| 4195 | ? nops_for_insn (0, history, NULL) |
| 4196 | : nops_for_insn_or_target (0, history, ip)); |
| 4197 | if (nops > 0) |
| 4198 | { |
| 4199 | fragS *old_frag; |
| 4200 | unsigned long old_frag_offset; |
| 4201 | int i; |
| 4202 | |
| 4203 | old_frag = frag_now; |
| 4204 | old_frag_offset = frag_now_fix (); |
| 4205 | |
| 4206 | for (i = 0; i < nops; i++) |
| 4207 | add_fixed_insn (NOP_INSN); |
| 4208 | insert_into_history (0, nops, NOP_INSN); |
| 4209 | |
| 4210 | if (listing) |
| 4211 | { |
| 4212 | listing_prev_line (); |
| 4213 | /* We may be at the start of a variant frag. In case we |
| 4214 | are, make sure there is enough space for the frag |
| 4215 | after the frags created by listing_prev_line. The |
| 4216 | argument to frag_grow here must be at least as large |
| 4217 | as the argument to all other calls to frag_grow in |
| 4218 | this file. We don't have to worry about being in the |
| 4219 | middle of a variant frag, because the variants insert |
| 4220 | all needed nop instructions themselves. */ |
| 4221 | frag_grow (40); |
| 4222 | } |
| 4223 | |
| 4224 | mips_move_text_labels (); |
| 4225 | |
| 4226 | #ifndef NO_ECOFF_DEBUGGING |
| 4227 | if (ECOFF_DEBUGGING) |
| 4228 | ecoff_fix_loc (old_frag, old_frag_offset); |
| 4229 | #endif |
| 4230 | } |
| 4231 | } |
| 4232 | else if (mips_relax.sequence != 2 && prev_nop_frag != NULL) |
| 4233 | { |
| 4234 | int nops; |
| 4235 | |
| 4236 | /* Work out how many nops in prev_nop_frag are needed by IP, |
| 4237 | ignoring hazards generated by the first prev_nop_frag_since |
| 4238 | instructions. */ |
| 4239 | nops = nops_for_insn_or_target (prev_nop_frag_since, history, ip); |
| 4240 | gas_assert (nops <= prev_nop_frag_holds); |
| 4241 | |
| 4242 | /* Enforce NOPS as a minimum. */ |
| 4243 | if (nops > prev_nop_frag_required) |
| 4244 | prev_nop_frag_required = nops; |
| 4245 | |
| 4246 | if (prev_nop_frag_holds == prev_nop_frag_required) |
| 4247 | { |
| 4248 | /* Settle for the current number of nops. Update the history |
| 4249 | accordingly (for the benefit of any future .set reorder code). */ |
| 4250 | prev_nop_frag = NULL; |
| 4251 | insert_into_history (prev_nop_frag_since, |
| 4252 | prev_nop_frag_holds, NOP_INSN); |
| 4253 | } |
| 4254 | else |
| 4255 | { |
| 4256 | /* Allow this instruction to replace one of the nops that was |
| 4257 | tentatively added to prev_nop_frag. */ |
| 4258 | prev_nop_frag->fr_fix -= NOP_INSN_SIZE; |
| 4259 | prev_nop_frag_holds--; |
| 4260 | prev_nop_frag_since++; |
| 4261 | } |
| 4262 | } |
| 4263 | |
| 4264 | method = get_append_method (ip); |
| 4265 | branch_disp = method == APPEND_SWAP ? insn_length (history) : 0; |
| 4266 | |
| 4267 | #ifdef OBJ_ELF |
| 4268 | /* The value passed to dwarf2_emit_insn is the distance between |
| 4269 | the beginning of the current instruction and the address that |
| 4270 | should be recorded in the debug tables. This is normally the |
| 4271 | current address. |
| 4272 | |
| 4273 | For MIPS16/microMIPS debug info we want to use ISA-encoded |
| 4274 | addresses, so we use -1 for an address higher by one than the |
| 4275 | current one. |
| 4276 | |
| 4277 | If the instruction produced is a branch that we will swap with |
| 4278 | the preceding instruction, then we add the displacement by which |
| 4279 | the branch will be moved backwards. This is more appropriate |
| 4280 | and for MIPS16/microMIPS code also prevents a debugger from |
| 4281 | placing a breakpoint in the middle of the branch (and corrupting |
| 4282 | code if software breakpoints are used). */ |
| 4283 | dwarf2_emit_insn ((HAVE_CODE_COMPRESSION ? -1 : 0) + branch_disp); |
| 4284 | #endif |
| 4285 | |
| 4286 | relax32 = (mips_relax_branch |
| 4287 | /* Don't try branch relaxation within .set nomacro, or within |
| 4288 | .set noat if we use $at for PIC computations. If it turns |
| 4289 | out that the branch was out-of-range, we'll get an error. */ |
| 4290 | && !mips_opts.warn_about_macros |
| 4291 | && (mips_opts.at || mips_pic == NO_PIC) |
| 4292 | /* Don't relax BPOSGE32/64 as they have no complementing |
| 4293 | branches. */ |
| 4294 | && !(ip->insn_mo->membership & (INSN_DSP64 | INSN_DSP))); |
| 4295 | |
| 4296 | if (!HAVE_CODE_COMPRESSION |
| 4297 | && address_expr |
| 4298 | && relax32 |
| 4299 | && *reloc_type == BFD_RELOC_16_PCREL_S2 |
| 4300 | && delayed_branch_p (ip)) |
| 4301 | { |
| 4302 | relaxed_branch = TRUE; |
| 4303 | add_relaxed_insn (ip, (relaxed_branch_length |
| 4304 | (NULL, NULL, |
| 4305 | uncond_branch_p (ip) ? -1 |
| 4306 | : branch_likely_p (ip) ? 1 |
| 4307 | : 0)), 4, |
| 4308 | RELAX_BRANCH_ENCODE |
| 4309 | (AT, |
| 4310 | uncond_branch_p (ip), |
| 4311 | branch_likely_p (ip), |
| 4312 | pinfo & INSN_WRITE_GPR_31, |
| 4313 | 0), |
| 4314 | address_expr->X_add_symbol, |
| 4315 | address_expr->X_add_number); |
| 4316 | *reloc_type = BFD_RELOC_UNUSED; |
| 4317 | } |
| 4318 | else if (mips_opts.micromips |
| 4319 | && address_expr |
| 4320 | && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2) |
| 4321 | || *reloc_type > BFD_RELOC_UNUSED) |
| 4322 | && (delayed_branch_p (ip) || compact_branch_p (ip)) |
| 4323 | /* Don't try branch relaxation when users specify |
| 4324 | 16-bit/32-bit instructions. */ |
| 4325 | && !forced_insn_length) |
| 4326 | { |
| 4327 | bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED; |
| 4328 | int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0; |
| 4329 | int uncond = uncond_branch_p (ip) ? -1 : 0; |
| 4330 | int compact = compact_branch_p (ip); |
| 4331 | int al = pinfo & INSN_WRITE_GPR_31; |
| 4332 | int length32; |
| 4333 | |
| 4334 | gas_assert (address_expr != NULL); |
| 4335 | gas_assert (!mips_relax.sequence); |
| 4336 | |
| 4337 | relaxed_branch = TRUE; |
| 4338 | length32 = relaxed_micromips_32bit_branch_length (NULL, NULL, uncond); |
| 4339 | add_relaxed_insn (ip, relax32 ? length32 : 4, relax16 ? 2 : 4, |
| 4340 | RELAX_MICROMIPS_ENCODE (type, AT, uncond, compact, al, |
| 4341 | relax32, 0, 0), |
| 4342 | address_expr->X_add_symbol, |
| 4343 | address_expr->X_add_number); |
| 4344 | *reloc_type = BFD_RELOC_UNUSED; |
| 4345 | } |
| 4346 | else if (mips_opts.mips16 && *reloc_type > BFD_RELOC_UNUSED) |
| 4347 | { |
| 4348 | /* We need to set up a variant frag. */ |
| 4349 | gas_assert (address_expr != NULL); |
| 4350 | add_relaxed_insn (ip, 4, 0, |
| 4351 | RELAX_MIPS16_ENCODE |
| 4352 | (*reloc_type - BFD_RELOC_UNUSED, |
| 4353 | forced_insn_length == 2, forced_insn_length == 4, |
| 4354 | delayed_branch_p (&history[0]), |
| 4355 | history[0].mips16_absolute_jump_p), |
| 4356 | make_expr_symbol (address_expr), 0); |
| 4357 | } |
| 4358 | else if (mips_opts.mips16 && insn_length (ip) == 2) |
| 4359 | { |
| 4360 | if (!delayed_branch_p (ip)) |
| 4361 | /* Make sure there is enough room to swap this instruction with |
| 4362 | a following jump instruction. */ |
| 4363 | frag_grow (6); |
| 4364 | add_fixed_insn (ip); |
| 4365 | } |
| 4366 | else |
| 4367 | { |
| 4368 | if (mips_opts.mips16 |
| 4369 | && mips_opts.noreorder |
| 4370 | && delayed_branch_p (&history[0])) |
| 4371 | as_warn (_("extended instruction in delay slot")); |
| 4372 | |
| 4373 | if (mips_relax.sequence) |
| 4374 | { |
| 4375 | /* If we've reached the end of this frag, turn it into a variant |
| 4376 | frag and record the information for the instructions we've |
| 4377 | written so far. */ |
| 4378 | if (frag_room () < 4) |
| 4379 | relax_close_frag (); |
| 4380 | mips_relax.sizes[mips_relax.sequence - 1] += insn_length (ip); |
| 4381 | } |
| 4382 | |
| 4383 | if (mips_relax.sequence != 2) |
| 4384 | { |
| 4385 | if (mips_macro_warning.first_insn_sizes[0] == 0) |
| 4386 | mips_macro_warning.first_insn_sizes[0] = insn_length (ip); |
| 4387 | mips_macro_warning.sizes[0] += insn_length (ip); |
| 4388 | mips_macro_warning.insns[0]++; |
| 4389 | } |
| 4390 | if (mips_relax.sequence != 1) |
| 4391 | { |
| 4392 | if (mips_macro_warning.first_insn_sizes[1] == 0) |
| 4393 | mips_macro_warning.first_insn_sizes[1] = insn_length (ip); |
| 4394 | mips_macro_warning.sizes[1] += insn_length (ip); |
| 4395 | mips_macro_warning.insns[1]++; |
| 4396 | } |
| 4397 | |
| 4398 | if (mips_opts.mips16) |
| 4399 | { |
| 4400 | ip->fixed_p = 1; |
| 4401 | ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP); |
| 4402 | } |
| 4403 | add_fixed_insn (ip); |
| 4404 | } |
| 4405 | |
| 4406 | if (!ip->complete_p && *reloc_type < BFD_RELOC_UNUSED) |
| 4407 | { |
| 4408 | bfd_reloc_code_real_type final_type[3]; |
| 4409 | reloc_howto_type *howto0; |
| 4410 | reloc_howto_type *howto; |
| 4411 | int i; |
| 4412 | |
| 4413 | /* Perform any necessary conversion to microMIPS relocations |
| 4414 | and find out how many relocations there actually are. */ |
| 4415 | for (i = 0; i < 3 && reloc_type[i] != BFD_RELOC_UNUSED; i++) |
| 4416 | final_type[i] = micromips_map_reloc (reloc_type[i]); |
| 4417 | |
| 4418 | /* In a compound relocation, it is the final (outermost) |
| 4419 | operator that determines the relocated field. */ |
| 4420 | howto = howto0 = bfd_reloc_type_lookup (stdoutput, final_type[i - 1]); |
| 4421 | |
| 4422 | if (howto == NULL) |
| 4423 | { |
| 4424 | /* To reproduce this failure try assembling gas/testsuites/ |
| 4425 | gas/mips/mips16-intermix.s with a mips-ecoff targeted |
| 4426 | assembler. */ |
| 4427 | as_bad (_("Unsupported MIPS relocation number %d"), |
| 4428 | final_type[i - 1]); |
| 4429 | howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16); |
| 4430 | } |
| 4431 | |
| 4432 | if (i > 1) |
| 4433 | howto0 = bfd_reloc_type_lookup (stdoutput, final_type[0]); |
| 4434 | ip->fixp[0] = fix_new_exp (ip->frag, ip->where, |
| 4435 | bfd_get_reloc_size (howto), |
| 4436 | address_expr, |
| 4437 | howto0 && howto0->pc_relative, |
| 4438 | final_type[0]); |
| 4439 | |
| 4440 | /* Tag symbols that have a R_MIPS16_26 relocation against them. */ |
| 4441 | if (final_type[0] == BFD_RELOC_MIPS16_JMP && ip->fixp[0]->fx_addsy) |
| 4442 | *symbol_get_tc (ip->fixp[0]->fx_addsy) = 1; |
| 4443 | |
| 4444 | /* These relocations can have an addend that won't fit in |
| 4445 | 4 octets for 64bit assembly. */ |
| 4446 | if (HAVE_64BIT_GPRS |
| 4447 | && ! howto->partial_inplace |
| 4448 | && (reloc_type[0] == BFD_RELOC_16 |
| 4449 | || reloc_type[0] == BFD_RELOC_32 |
| 4450 | || reloc_type[0] == BFD_RELOC_MIPS_JMP |
| 4451 | || reloc_type[0] == BFD_RELOC_GPREL16 |
| 4452 | || reloc_type[0] == BFD_RELOC_MIPS_LITERAL |
| 4453 | || reloc_type[0] == BFD_RELOC_GPREL32 |
| 4454 | || reloc_type[0] == BFD_RELOC_64 |
| 4455 | || reloc_type[0] == BFD_RELOC_CTOR |
| 4456 | || reloc_type[0] == BFD_RELOC_MIPS_SUB |
| 4457 | || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST |
| 4458 | || reloc_type[0] == BFD_RELOC_MIPS_HIGHER |
| 4459 | || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP |
| 4460 | || reloc_type[0] == BFD_RELOC_MIPS_REL16 |
| 4461 | || reloc_type[0] == BFD_RELOC_MIPS_RELGOT |
| 4462 | || reloc_type[0] == BFD_RELOC_MIPS16_GPREL |
| 4463 | || hi16_reloc_p (reloc_type[0]) |
| 4464 | || lo16_reloc_p (reloc_type[0]))) |
| 4465 | ip->fixp[0]->fx_no_overflow = 1; |
| 4466 | |
| 4467 | if (mips_relax.sequence) |
| 4468 | { |
| 4469 | if (mips_relax.first_fixup == 0) |
| 4470 | mips_relax.first_fixup = ip->fixp[0]; |
| 4471 | } |
| 4472 | else if (reloc_needs_lo_p (*reloc_type)) |
| 4473 | { |
| 4474 | struct mips_hi_fixup *hi_fixup; |
| 4475 | |
| 4476 | /* Reuse the last entry if it already has a matching %lo. */ |
| 4477 | hi_fixup = mips_hi_fixup_list; |
| 4478 | if (hi_fixup == 0 |
| 4479 | || !fixup_has_matching_lo_p (hi_fixup->fixp)) |
| 4480 | { |
| 4481 | hi_fixup = ((struct mips_hi_fixup *) |
| 4482 | xmalloc (sizeof (struct mips_hi_fixup))); |
| 4483 | hi_fixup->next = mips_hi_fixup_list; |
| 4484 | mips_hi_fixup_list = hi_fixup; |
| 4485 | } |
| 4486 | hi_fixup->fixp = ip->fixp[0]; |
| 4487 | hi_fixup->seg = now_seg; |
| 4488 | } |
| 4489 | |
| 4490 | /* Add fixups for the second and third relocations, if given. |
| 4491 | Note that the ABI allows the second relocation to be |
| 4492 | against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the |
| 4493 | moment we only use RSS_UNDEF, but we could add support |
| 4494 | for the others if it ever becomes necessary. */ |
| 4495 | for (i = 1; i < 3; i++) |
| 4496 | if (reloc_type[i] != BFD_RELOC_UNUSED) |
| 4497 | { |
| 4498 | ip->fixp[i] = fix_new (ip->frag, ip->where, |
| 4499 | ip->fixp[0]->fx_size, NULL, 0, |
| 4500 | FALSE, final_type[i]); |
| 4501 | |
| 4502 | /* Use fx_tcbit to mark compound relocs. */ |
| 4503 | ip->fixp[0]->fx_tcbit = 1; |
| 4504 | ip->fixp[i]->fx_tcbit = 1; |
| 4505 | } |
| 4506 | } |
| 4507 | install_insn (ip); |
| 4508 | |
| 4509 | /* Update the register mask information. */ |
| 4510 | mips_gprmask |= gpr_read_mask (ip) | gpr_write_mask (ip); |
| 4511 | mips_cprmask[1] |= fpr_read_mask (ip) | fpr_write_mask (ip); |
| 4512 | |
| 4513 | switch (method) |
| 4514 | { |
| 4515 | case APPEND_ADD: |
| 4516 | insert_into_history (0, 1, ip); |
| 4517 | break; |
| 4518 | |
| 4519 | case APPEND_ADD_WITH_NOP: |
| 4520 | { |
| 4521 | struct mips_cl_insn *nop; |
| 4522 | |
| 4523 | insert_into_history (0, 1, ip); |
| 4524 | nop = get_delay_slot_nop (ip); |
| 4525 | add_fixed_insn (nop); |
| 4526 | insert_into_history (0, 1, nop); |
| 4527 | if (mips_relax.sequence) |
| 4528 | mips_relax.sizes[mips_relax.sequence - 1] += insn_length (nop); |
| 4529 | } |
| 4530 | break; |
| 4531 | |
| 4532 | case APPEND_ADD_COMPACT: |
| 4533 | /* Convert MIPS16 jr/jalr into a "compact" jump. */ |
| 4534 | gas_assert (mips_opts.mips16); |
| 4535 | ip->insn_opcode |= 0x0080; |
| 4536 | find_altered_mips16_opcode (ip); |
| 4537 | install_insn (ip); |
| 4538 | insert_into_history (0, 1, ip); |
| 4539 | break; |
| 4540 | |
| 4541 | case APPEND_SWAP: |
| 4542 | { |
| 4543 | struct mips_cl_insn delay = history[0]; |
| 4544 | if (mips_opts.mips16) |
| 4545 | { |
| 4546 | know (delay.frag == ip->frag); |
| 4547 | move_insn (ip, delay.frag, delay.where); |
| 4548 | move_insn (&delay, ip->frag, ip->where + insn_length (ip)); |
| 4549 | } |
| 4550 | else if (relaxed_branch || delay.frag != ip->frag) |
| 4551 | { |
| 4552 | /* Add the delay slot instruction to the end of the |
| 4553 | current frag and shrink the fixed part of the |
| 4554 | original frag. If the branch occupies the tail of |
| 4555 | the latter, move it backwards to cover the gap. */ |
| 4556 | delay.frag->fr_fix -= branch_disp; |
| 4557 | if (delay.frag == ip->frag) |
| 4558 | move_insn (ip, ip->frag, ip->where - branch_disp); |
| 4559 | add_fixed_insn (&delay); |
| 4560 | } |
| 4561 | else |
| 4562 | { |
| 4563 | move_insn (&delay, ip->frag, |
| 4564 | ip->where - branch_disp + insn_length (ip)); |
| 4565 | move_insn (ip, history[0].frag, history[0].where); |
| 4566 | } |
| 4567 | history[0] = *ip; |
| 4568 | delay.fixed_p = 1; |
| 4569 | insert_into_history (0, 1, &delay); |
| 4570 | } |
| 4571 | break; |
| 4572 | } |
| 4573 | |
| 4574 | /* If we have just completed an unconditional branch, clear the history. */ |
| 4575 | if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1])) |
| 4576 | || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0]))) |
| 4577 | mips_no_prev_insn (); |
| 4578 | |
| 4579 | /* We need to emit a label at the end of branch-likely macros. */ |
| 4580 | if (emit_branch_likely_macro) |
| 4581 | { |
| 4582 | emit_branch_likely_macro = FALSE; |
| 4583 | micromips_add_label (); |
| 4584 | } |
| 4585 | |
| 4586 | /* We just output an insn, so the next one doesn't have a label. */ |
| 4587 | mips_clear_insn_labels (); |
| 4588 | } |
| 4589 | |
| 4590 | /* Forget that there was any previous instruction or label. */ |
| 4591 | |
| 4592 | static void |
| 4593 | mips_no_prev_insn (void) |
| 4594 | { |
| 4595 | prev_nop_frag = NULL; |
| 4596 | insert_into_history (0, ARRAY_SIZE (history), NOP_INSN); |
| 4597 | mips_clear_insn_labels (); |
| 4598 | } |
| 4599 | |
| 4600 | /* This function must be called before we emit something other than |
| 4601 | instructions. It is like mips_no_prev_insn except that it inserts |
| 4602 | any NOPS that might be needed by previous instructions. */ |
| 4603 | |
| 4604 | void |
| 4605 | mips_emit_delays (void) |
| 4606 | { |
| 4607 | if (! mips_opts.noreorder) |
| 4608 | { |
| 4609 | int nops = nops_for_insn (0, history, NULL); |
| 4610 | if (nops > 0) |
| 4611 | { |
| 4612 | while (nops-- > 0) |
| 4613 | add_fixed_insn (NOP_INSN); |
| 4614 | mips_move_text_labels (); |
| 4615 | } |
| 4616 | } |
| 4617 | mips_no_prev_insn (); |
| 4618 | } |
| 4619 | |
| 4620 | /* Start a (possibly nested) noreorder block. */ |
| 4621 | |
| 4622 | static void |
| 4623 | start_noreorder (void) |
| 4624 | { |
| 4625 | if (mips_opts.noreorder == 0) |
| 4626 | { |
| 4627 | unsigned int i; |
| 4628 | int nops; |
| 4629 | |
| 4630 | /* None of the instructions before the .set noreorder can be moved. */ |
| 4631 | for (i = 0; i < ARRAY_SIZE (history); i++) |
| 4632 | history[i].fixed_p = 1; |
| 4633 | |
| 4634 | /* Insert any nops that might be needed between the .set noreorder |
| 4635 | block and the previous instructions. We will later remove any |
| 4636 | nops that turn out not to be needed. */ |
| 4637 | nops = nops_for_insn (0, history, NULL); |
| 4638 | if (nops > 0) |
| 4639 | { |
| 4640 | if (mips_optimize != 0) |
| 4641 | { |
| 4642 | /* Record the frag which holds the nop instructions, so |
| 4643 | that we can remove them if we don't need them. */ |
| 4644 | frag_grow (nops * NOP_INSN_SIZE); |
| 4645 | prev_nop_frag = frag_now; |
| 4646 | prev_nop_frag_holds = nops; |
| 4647 | prev_nop_frag_required = 0; |
| 4648 | prev_nop_frag_since = 0; |
| 4649 | } |
| 4650 | |
| 4651 | for (; nops > 0; --nops) |
| 4652 | add_fixed_insn (NOP_INSN); |
| 4653 | |
| 4654 | /* Move on to a new frag, so that it is safe to simply |
| 4655 | decrease the size of prev_nop_frag. */ |
| 4656 | frag_wane (frag_now); |
| 4657 | frag_new (0); |
| 4658 | mips_move_text_labels (); |
| 4659 | } |
| 4660 | mips_mark_labels (); |
| 4661 | mips_clear_insn_labels (); |
| 4662 | } |
| 4663 | mips_opts.noreorder++; |
| 4664 | mips_any_noreorder = 1; |
| 4665 | } |
| 4666 | |
| 4667 | /* End a nested noreorder block. */ |
| 4668 | |
| 4669 | static void |
| 4670 | end_noreorder (void) |
| 4671 | { |
| 4672 | mips_opts.noreorder--; |
| 4673 | if (mips_opts.noreorder == 0 && prev_nop_frag != NULL) |
| 4674 | { |
| 4675 | /* Commit to inserting prev_nop_frag_required nops and go back to |
| 4676 | handling nop insertion the .set reorder way. */ |
| 4677 | prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required) |
| 4678 | * NOP_INSN_SIZE); |
| 4679 | insert_into_history (prev_nop_frag_since, |
| 4680 | prev_nop_frag_required, NOP_INSN); |
| 4681 | prev_nop_frag = NULL; |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | /* Set up global variables for the start of a new macro. */ |
| 4686 | |
| 4687 | static void |
| 4688 | macro_start (void) |
| 4689 | { |
| 4690 | memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes)); |
| 4691 | memset (&mips_macro_warning.first_insn_sizes, 0, |
| 4692 | sizeof (mips_macro_warning.first_insn_sizes)); |
| 4693 | memset (&mips_macro_warning.insns, 0, sizeof (mips_macro_warning.insns)); |
| 4694 | mips_macro_warning.delay_slot_p = (mips_opts.noreorder |
| 4695 | && delayed_branch_p (&history[0])); |
| 4696 | switch (history[0].insn_mo->pinfo2 |
| 4697 | & (INSN2_BRANCH_DELAY_32BIT | INSN2_BRANCH_DELAY_16BIT)) |
| 4698 | { |
| 4699 | case INSN2_BRANCH_DELAY_32BIT: |
| 4700 | mips_macro_warning.delay_slot_length = 4; |
| 4701 | break; |
| 4702 | case INSN2_BRANCH_DELAY_16BIT: |
| 4703 | mips_macro_warning.delay_slot_length = 2; |
| 4704 | break; |
| 4705 | default: |
| 4706 | mips_macro_warning.delay_slot_length = 0; |
| 4707 | break; |
| 4708 | } |
| 4709 | mips_macro_warning.first_frag = NULL; |
| 4710 | } |
| 4711 | |
| 4712 | /* Given that a macro is longer than one instruction or of the wrong size, |
| 4713 | return the appropriate warning for it. Return null if no warning is |
| 4714 | needed. SUBTYPE is a bitmask of RELAX_DELAY_SLOT, RELAX_DELAY_SLOT_16BIT, |
| 4715 | RELAX_DELAY_SLOT_SIZE_FIRST, RELAX_DELAY_SLOT_SIZE_SECOND, |
| 4716 | and RELAX_NOMACRO. */ |
| 4717 | |
| 4718 | static const char * |
| 4719 | macro_warning (relax_substateT subtype) |
| 4720 | { |
| 4721 | if (subtype & RELAX_DELAY_SLOT) |
| 4722 | return _("Macro instruction expanded into multiple instructions" |
| 4723 | " in a branch delay slot"); |
| 4724 | else if (subtype & RELAX_NOMACRO) |
| 4725 | return _("Macro instruction expanded into multiple instructions"); |
| 4726 | else if (subtype & (RELAX_DELAY_SLOT_SIZE_FIRST |
| 4727 | | RELAX_DELAY_SLOT_SIZE_SECOND)) |
| 4728 | return ((subtype & RELAX_DELAY_SLOT_16BIT) |
| 4729 | ? _("Macro instruction expanded into a wrong size instruction" |
| 4730 | " in a 16-bit branch delay slot") |
| 4731 | : _("Macro instruction expanded into a wrong size instruction" |
| 4732 | " in a 32-bit branch delay slot")); |
| 4733 | else |
| 4734 | return 0; |
| 4735 | } |
| 4736 | |
| 4737 | /* Finish up a macro. Emit warnings as appropriate. */ |
| 4738 | |
| 4739 | static void |
| 4740 | macro_end (void) |
| 4741 | { |
| 4742 | /* Relaxation warning flags. */ |
| 4743 | relax_substateT subtype = 0; |
| 4744 | |
| 4745 | /* Check delay slot size requirements. */ |
| 4746 | if (mips_macro_warning.delay_slot_length == 2) |
| 4747 | subtype |= RELAX_DELAY_SLOT_16BIT; |
| 4748 | if (mips_macro_warning.delay_slot_length != 0) |
| 4749 | { |
| 4750 | if (mips_macro_warning.delay_slot_length |
| 4751 | != mips_macro_warning.first_insn_sizes[0]) |
| 4752 | subtype |= RELAX_DELAY_SLOT_SIZE_FIRST; |
| 4753 | if (mips_macro_warning.delay_slot_length |
| 4754 | != mips_macro_warning.first_insn_sizes[1]) |
| 4755 | subtype |= RELAX_DELAY_SLOT_SIZE_SECOND; |
| 4756 | } |
| 4757 | |
| 4758 | /* Check instruction count requirements. */ |
| 4759 | if (mips_macro_warning.insns[0] > 1 || mips_macro_warning.insns[1] > 1) |
| 4760 | { |
| 4761 | if (mips_macro_warning.insns[1] > mips_macro_warning.insns[0]) |
| 4762 | subtype |= RELAX_SECOND_LONGER; |
| 4763 | if (mips_opts.warn_about_macros) |
| 4764 | subtype |= RELAX_NOMACRO; |
| 4765 | if (mips_macro_warning.delay_slot_p) |
| 4766 | subtype |= RELAX_DELAY_SLOT; |
| 4767 | } |
| 4768 | |
| 4769 | /* If both alternatives fail to fill a delay slot correctly, |
| 4770 | emit the warning now. */ |
| 4771 | if ((subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0 |
| 4772 | && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0) |
| 4773 | { |
| 4774 | relax_substateT s; |
| 4775 | const char *msg; |
| 4776 | |
| 4777 | s = subtype & (RELAX_DELAY_SLOT_16BIT |
| 4778 | | RELAX_DELAY_SLOT_SIZE_FIRST |
| 4779 | | RELAX_DELAY_SLOT_SIZE_SECOND); |
| 4780 | msg = macro_warning (s); |
| 4781 | if (msg != NULL) |
| 4782 | as_warn ("%s", msg); |
| 4783 | subtype &= ~s; |
| 4784 | } |
| 4785 | |
| 4786 | /* If both implementations are longer than 1 instruction, then emit the |
| 4787 | warning now. */ |
| 4788 | if (mips_macro_warning.insns[0] > 1 && mips_macro_warning.insns[1] > 1) |
| 4789 | { |
| 4790 | relax_substateT s; |
| 4791 | const char *msg; |
| 4792 | |
| 4793 | s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT); |
| 4794 | msg = macro_warning (s); |
| 4795 | if (msg != NULL) |
| 4796 | as_warn ("%s", msg); |
| 4797 | subtype &= ~s; |
| 4798 | } |
| 4799 | |
| 4800 | /* If any flags still set, then one implementation might need a warning |
| 4801 | and the other either will need one of a different kind or none at all. |
| 4802 | Pass any remaining flags over to relaxation. */ |
| 4803 | if (mips_macro_warning.first_frag != NULL) |
| 4804 | mips_macro_warning.first_frag->fr_subtype |= subtype; |
| 4805 | } |
| 4806 | |
| 4807 | /* Instruction operand formats used in macros that vary between |
| 4808 | standard MIPS and microMIPS code. */ |
| 4809 | |
| 4810 | static const char * const brk_fmt[2] = { "c", "mF" }; |
| 4811 | static const char * const cop12_fmt[2] = { "E,o(b)", "E,~(b)" }; |
| 4812 | static const char * const jalr_fmt[2] = { "d,s", "t,s" }; |
| 4813 | static const char * const lui_fmt[2] = { "t,u", "s,u" }; |
| 4814 | static const char * const mem12_fmt[2] = { "t,o(b)", "t,~(b)" }; |
| 4815 | static const char * const mfhl_fmt[2] = { "d", "mj" }; |
| 4816 | static const char * const shft_fmt[2] = { "d,w,<", "t,r,<" }; |
| 4817 | static const char * const trap_fmt[2] = { "s,t,q", "s,t,|" }; |
| 4818 | |
| 4819 | #define BRK_FMT (brk_fmt[mips_opts.micromips]) |
| 4820 | #define COP12_FMT (cop12_fmt[mips_opts.micromips]) |
| 4821 | #define JALR_FMT (jalr_fmt[mips_opts.micromips]) |
| 4822 | #define LUI_FMT (lui_fmt[mips_opts.micromips]) |
| 4823 | #define MEM12_FMT (mem12_fmt[mips_opts.micromips]) |
| 4824 | #define MFHL_FMT (mfhl_fmt[mips_opts.micromips]) |
| 4825 | #define SHFT_FMT (shft_fmt[mips_opts.micromips]) |
| 4826 | #define TRAP_FMT (trap_fmt[mips_opts.micromips]) |
| 4827 | |
| 4828 | /* Read a macro's relocation codes from *ARGS and store them in *R. |
| 4829 | The first argument in *ARGS will be either the code for a single |
| 4830 | relocation or -1 followed by the three codes that make up a |
| 4831 | composite relocation. */ |
| 4832 | |
| 4833 | static void |
| 4834 | macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r) |
| 4835 | { |
| 4836 | int i, next; |
| 4837 | |
| 4838 | next = va_arg (*args, int); |
| 4839 | if (next >= 0) |
| 4840 | r[0] = (bfd_reloc_code_real_type) next; |
| 4841 | else |
| 4842 | for (i = 0; i < 3; i++) |
| 4843 | r[i] = (bfd_reloc_code_real_type) va_arg (*args, int); |
| 4844 | } |
| 4845 | |
| 4846 | /* Build an instruction created by a macro expansion. This is passed |
| 4847 | a pointer to the count of instructions created so far, an |
| 4848 | expression, the name of the instruction to build, an operand format |
| 4849 | string, and corresponding arguments. */ |
| 4850 | |
| 4851 | static void |
| 4852 | macro_build (expressionS *ep, const char *name, const char *fmt, ...) |
| 4853 | { |
| 4854 | const struct mips_opcode *mo = NULL; |
| 4855 | bfd_reloc_code_real_type r[3]; |
| 4856 | const struct mips_opcode *amo; |
| 4857 | struct hash_control *hash; |
| 4858 | struct mips_cl_insn insn; |
| 4859 | va_list args; |
| 4860 | |
| 4861 | va_start (args, fmt); |
| 4862 | |
| 4863 | if (mips_opts.mips16) |
| 4864 | { |
| 4865 | mips16_macro_build (ep, name, fmt, &args); |
| 4866 | va_end (args); |
| 4867 | return; |
| 4868 | } |
| 4869 | |
| 4870 | r[0] = BFD_RELOC_UNUSED; |
| 4871 | r[1] = BFD_RELOC_UNUSED; |
| 4872 | r[2] = BFD_RELOC_UNUSED; |
| 4873 | hash = mips_opts.micromips ? micromips_op_hash : op_hash; |
| 4874 | amo = (struct mips_opcode *) hash_find (hash, name); |
| 4875 | gas_assert (amo); |
| 4876 | gas_assert (strcmp (name, amo->name) == 0); |
| 4877 | |
| 4878 | do |
| 4879 | { |
| 4880 | /* Search until we get a match for NAME. It is assumed here that |
| 4881 | macros will never generate MDMX, MIPS-3D, or MT instructions. |
| 4882 | We try to match an instruction that fulfils the branch delay |
| 4883 | slot instruction length requirement (if any) of the previous |
| 4884 | instruction. While doing this we record the first instruction |
| 4885 | seen that matches all the other conditions and use it anyway |
| 4886 | if the requirement cannot be met; we will issue an appropriate |
| 4887 | warning later on. */ |
| 4888 | if (strcmp (fmt, amo->args) == 0 |
| 4889 | && amo->pinfo != INSN_MACRO |
| 4890 | && is_opcode_valid (amo) |
| 4891 | && is_size_valid (amo)) |
| 4892 | { |
| 4893 | if (is_delay_slot_valid (amo)) |
| 4894 | { |
| 4895 | mo = amo; |
| 4896 | break; |
| 4897 | } |
| 4898 | else if (!mo) |
| 4899 | mo = amo; |
| 4900 | } |
| 4901 | |
| 4902 | ++amo; |
| 4903 | gas_assert (amo->name); |
| 4904 | } |
| 4905 | while (strcmp (name, amo->name) == 0); |
| 4906 | |
| 4907 | gas_assert (mo); |
| 4908 | create_insn (&insn, mo); |
| 4909 | for (;;) |
| 4910 | { |
| 4911 | switch (*fmt++) |
| 4912 | { |
| 4913 | case '\0': |
| 4914 | break; |
| 4915 | |
| 4916 | case ',': |
| 4917 | case '(': |
| 4918 | case ')': |
| 4919 | continue; |
| 4920 | |
| 4921 | case '+': |
| 4922 | switch (*fmt++) |
| 4923 | { |
| 4924 | case 'A': |
| 4925 | case 'E': |
| 4926 | INSERT_OPERAND (mips_opts.micromips, |
| 4927 | EXTLSB, insn, va_arg (args, int)); |
| 4928 | continue; |
| 4929 | |
| 4930 | case 'B': |
| 4931 | case 'F': |
| 4932 | /* Note that in the macro case, these arguments are already |
| 4933 | in MSB form. (When handling the instruction in the |
| 4934 | non-macro case, these arguments are sizes from which |
| 4935 | MSB values must be calculated.) */ |
| 4936 | INSERT_OPERAND (mips_opts.micromips, |
| 4937 | INSMSB, insn, va_arg (args, int)); |
| 4938 | continue; |
| 4939 | |
| 4940 | case 'C': |
| 4941 | case 'G': |
| 4942 | case 'H': |
| 4943 | /* Note that in the macro case, these arguments are already |
| 4944 | in MSBD form. (When handling the instruction in the |
| 4945 | non-macro case, these arguments are sizes from which |
| 4946 | MSBD values must be calculated.) */ |
| 4947 | INSERT_OPERAND (mips_opts.micromips, |
| 4948 | EXTMSBD, insn, va_arg (args, int)); |
| 4949 | continue; |
| 4950 | |
| 4951 | case 'Q': |
| 4952 | gas_assert (!mips_opts.micromips); |
| 4953 | INSERT_OPERAND (0, SEQI, insn, va_arg (args, int)); |
| 4954 | continue; |
| 4955 | |
| 4956 | default: |
| 4957 | internalError (); |
| 4958 | } |
| 4959 | continue; |
| 4960 | |
| 4961 | case '2': |
| 4962 | INSERT_OPERAND (mips_opts.micromips, BP, insn, va_arg (args, int)); |
| 4963 | continue; |
| 4964 | |
| 4965 | case 'n': |
| 4966 | gas_assert (mips_opts.micromips); |
| 4967 | case 't': |
| 4968 | case 'w': |
| 4969 | case 'E': |
| 4970 | INSERT_OPERAND (mips_opts.micromips, RT, insn, va_arg (args, int)); |
| 4971 | continue; |
| 4972 | |
| 4973 | case 'c': |
| 4974 | gas_assert (!mips_opts.micromips); |
| 4975 | INSERT_OPERAND (0, CODE, insn, va_arg (args, int)); |
| 4976 | continue; |
| 4977 | |
| 4978 | case 'W': |
| 4979 | gas_assert (!mips_opts.micromips); |
| 4980 | case 'T': |
| 4981 | INSERT_OPERAND (mips_opts.micromips, FT, insn, va_arg (args, int)); |
| 4982 | continue; |
| 4983 | |
| 4984 | case 'G': |
| 4985 | if (mips_opts.micromips) |
| 4986 | INSERT_OPERAND (1, RS, insn, va_arg (args, int)); |
| 4987 | else |
| 4988 | INSERT_OPERAND (0, RD, insn, va_arg (args, int)); |
| 4989 | continue; |
| 4990 | |
| 4991 | case 'K': |
| 4992 | gas_assert (!mips_opts.micromips); |
| 4993 | case 'd': |
| 4994 | INSERT_OPERAND (mips_opts.micromips, RD, insn, va_arg (args, int)); |
| 4995 | continue; |
| 4996 | |
| 4997 | case 'U': |
| 4998 | gas_assert (!mips_opts.micromips); |
| 4999 | { |
| 5000 | int tmp = va_arg (args, int); |
| 5001 | |
| 5002 | INSERT_OPERAND (0, RT, insn, tmp); |
| 5003 | INSERT_OPERAND (0, RD, insn, tmp); |
| 5004 | } |
| 5005 | continue; |
| 5006 | |
| 5007 | case 'V': |
| 5008 | case 'S': |
| 5009 | gas_assert (!mips_opts.micromips); |
| 5010 | INSERT_OPERAND (0, FS, insn, va_arg (args, int)); |
| 5011 | continue; |
| 5012 | |
| 5013 | case 'z': |
| 5014 | continue; |
| 5015 | |
| 5016 | case '<': |
| 5017 | INSERT_OPERAND (mips_opts.micromips, |
| 5018 | SHAMT, insn, va_arg (args, int)); |
| 5019 | continue; |
| 5020 | |
| 5021 | case 'D': |
| 5022 | gas_assert (!mips_opts.micromips); |
| 5023 | INSERT_OPERAND (0, FD, insn, va_arg (args, int)); |
| 5024 | continue; |
| 5025 | |
| 5026 | case 'B': |
| 5027 | gas_assert (!mips_opts.micromips); |
| 5028 | INSERT_OPERAND (0, CODE20, insn, va_arg (args, int)); |
| 5029 | continue; |
| 5030 | |
| 5031 | case 'J': |
| 5032 | gas_assert (!mips_opts.micromips); |
| 5033 | INSERT_OPERAND (0, CODE19, insn, va_arg (args, int)); |
| 5034 | continue; |
| 5035 | |
| 5036 | case 'q': |
| 5037 | gas_assert (!mips_opts.micromips); |
| 5038 | INSERT_OPERAND (0, CODE2, insn, va_arg (args, int)); |
| 5039 | continue; |
| 5040 | |
| 5041 | case 'b': |
| 5042 | case 's': |
| 5043 | case 'r': |
| 5044 | case 'v': |
| 5045 | INSERT_OPERAND (mips_opts.micromips, RS, insn, va_arg (args, int)); |
| 5046 | continue; |
| 5047 | |
| 5048 | case 'i': |
| 5049 | case 'j': |
| 5050 | macro_read_relocs (&args, r); |
| 5051 | gas_assert (*r == BFD_RELOC_GPREL16 |
| 5052 | || *r == BFD_RELOC_MIPS_HIGHER |
| 5053 | || *r == BFD_RELOC_HI16_S |
| 5054 | || *r == BFD_RELOC_LO16 |
| 5055 | || *r == BFD_RELOC_MIPS_GOT_OFST); |
| 5056 | continue; |
| 5057 | |
| 5058 | case 'o': |
| 5059 | macro_read_relocs (&args, r); |
| 5060 | continue; |
| 5061 | |
| 5062 | case 'u': |
| 5063 | macro_read_relocs (&args, r); |
| 5064 | gas_assert (ep != NULL |
| 5065 | && (ep->X_op == O_constant |
| 5066 | || (ep->X_op == O_symbol |
| 5067 | && (*r == BFD_RELOC_MIPS_HIGHEST |
| 5068 | || *r == BFD_RELOC_HI16_S |
| 5069 | || *r == BFD_RELOC_HI16 |
| 5070 | || *r == BFD_RELOC_GPREL16 |
| 5071 | || *r == BFD_RELOC_MIPS_GOT_HI16 |
| 5072 | || *r == BFD_RELOC_MIPS_CALL_HI16)))); |
| 5073 | continue; |
| 5074 | |
| 5075 | case 'p': |
| 5076 | gas_assert (ep != NULL); |
| 5077 | |
| 5078 | /* |
| 5079 | * This allows macro() to pass an immediate expression for |
| 5080 | * creating short branches without creating a symbol. |
| 5081 | * |
| 5082 | * We don't allow branch relaxation for these branches, as |
| 5083 | * they should only appear in ".set nomacro" anyway. |
| 5084 | */ |
| 5085 | if (ep->X_op == O_constant) |
| 5086 | { |
| 5087 | /* For microMIPS we always use relocations for branches. |
| 5088 | So we should not resolve immediate values. */ |
| 5089 | gas_assert (!mips_opts.micromips); |
| 5090 | |
| 5091 | if ((ep->X_add_number & 3) != 0) |
| 5092 | as_bad (_("branch to misaligned address (0x%lx)"), |
| 5093 | (unsigned long) ep->X_add_number); |
| 5094 | if ((ep->X_add_number + 0x20000) & ~0x3ffff) |
| 5095 | as_bad (_("branch address range overflow (0x%lx)"), |
| 5096 | (unsigned long) ep->X_add_number); |
| 5097 | insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff; |
| 5098 | ep = NULL; |
| 5099 | } |
| 5100 | else |
| 5101 | *r = BFD_RELOC_16_PCREL_S2; |
| 5102 | continue; |
| 5103 | |
| 5104 | case 'a': |
| 5105 | gas_assert (ep != NULL); |
| 5106 | *r = BFD_RELOC_MIPS_JMP; |
| 5107 | continue; |
| 5108 | |
| 5109 | case 'C': |
| 5110 | gas_assert (!mips_opts.micromips); |
| 5111 | INSERT_OPERAND (0, COPZ, insn, va_arg (args, unsigned long)); |
| 5112 | continue; |
| 5113 | |
| 5114 | case 'k': |
| 5115 | INSERT_OPERAND (mips_opts.micromips, |
| 5116 | CACHE, insn, va_arg (args, unsigned long)); |
| 5117 | continue; |
| 5118 | |
| 5119 | case '|': |
| 5120 | gas_assert (mips_opts.micromips); |
| 5121 | INSERT_OPERAND (1, TRAP, insn, va_arg (args, int)); |
| 5122 | continue; |
| 5123 | |
| 5124 | case '.': |
| 5125 | gas_assert (mips_opts.micromips); |
| 5126 | INSERT_OPERAND (1, OFFSET10, insn, va_arg (args, int)); |
| 5127 | continue; |
| 5128 | |
| 5129 | case '\\': |
| 5130 | INSERT_OPERAND (mips_opts.micromips, |
| 5131 | 3BITPOS, insn, va_arg (args, unsigned int)); |
| 5132 | continue; |
| 5133 | |
| 5134 | case '~': |
| 5135 | INSERT_OPERAND (mips_opts.micromips, |
| 5136 | OFFSET12, insn, va_arg (args, unsigned long)); |
| 5137 | continue; |
| 5138 | |
| 5139 | case 'N': |
| 5140 | gas_assert (mips_opts.micromips); |
| 5141 | INSERT_OPERAND (1, BCC, insn, va_arg (args, int)); |
| 5142 | continue; |
| 5143 | |
| 5144 | case 'm': /* Opcode extension character. */ |
| 5145 | gas_assert (mips_opts.micromips); |
| 5146 | switch (*fmt++) |
| 5147 | { |
| 5148 | case 'j': |
| 5149 | INSERT_OPERAND (1, MJ, insn, va_arg (args, int)); |
| 5150 | break; |
| 5151 | |
| 5152 | case 'p': |
| 5153 | INSERT_OPERAND (1, MP, insn, va_arg (args, int)); |
| 5154 | break; |
| 5155 | |
| 5156 | case 'F': |
| 5157 | INSERT_OPERAND (1, IMMF, insn, va_arg (args, int)); |
| 5158 | break; |
| 5159 | |
| 5160 | default: |
| 5161 | internalError (); |
| 5162 | } |
| 5163 | continue; |
| 5164 | |
| 5165 | default: |
| 5166 | internalError (); |
| 5167 | } |
| 5168 | break; |
| 5169 | } |
| 5170 | va_end (args); |
| 5171 | gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
| 5172 | |
| 5173 | append_insn (&insn, ep, r, TRUE); |
| 5174 | } |
| 5175 | |
| 5176 | static void |
| 5177 | mips16_macro_build (expressionS *ep, const char *name, const char *fmt, |
| 5178 | va_list *args) |
| 5179 | { |
| 5180 | struct mips_opcode *mo; |
| 5181 | struct mips_cl_insn insn; |
| 5182 | bfd_reloc_code_real_type r[3] |
| 5183 | = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED}; |
| 5184 | |
| 5185 | mo = (struct mips_opcode *) hash_find (mips16_op_hash, name); |
| 5186 | gas_assert (mo); |
| 5187 | gas_assert (strcmp (name, mo->name) == 0); |
| 5188 | |
| 5189 | while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO) |
| 5190 | { |
| 5191 | ++mo; |
| 5192 | gas_assert (mo->name); |
| 5193 | gas_assert (strcmp (name, mo->name) == 0); |
| 5194 | } |
| 5195 | |
| 5196 | create_insn (&insn, mo); |
| 5197 | for (;;) |
| 5198 | { |
| 5199 | int c; |
| 5200 | |
| 5201 | c = *fmt++; |
| 5202 | switch (c) |
| 5203 | { |
| 5204 | case '\0': |
| 5205 | break; |
| 5206 | |
| 5207 | case ',': |
| 5208 | case '(': |
| 5209 | case ')': |
| 5210 | continue; |
| 5211 | |
| 5212 | case 'y': |
| 5213 | case 'w': |
| 5214 | MIPS16_INSERT_OPERAND (RY, insn, va_arg (*args, int)); |
| 5215 | continue; |
| 5216 | |
| 5217 | case 'x': |
| 5218 | case 'v': |
| 5219 | MIPS16_INSERT_OPERAND (RX, insn, va_arg (*args, int)); |
| 5220 | continue; |
| 5221 | |
| 5222 | case 'z': |
| 5223 | MIPS16_INSERT_OPERAND (RZ, insn, va_arg (*args, int)); |
| 5224 | continue; |
| 5225 | |
| 5226 | case 'Z': |
| 5227 | MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (*args, int)); |
| 5228 | continue; |
| 5229 | |
| 5230 | case '0': |
| 5231 | case 'S': |
| 5232 | case 'P': |
| 5233 | case 'R': |
| 5234 | continue; |
| 5235 | |
| 5236 | case 'X': |
| 5237 | MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (*args, int)); |
| 5238 | continue; |
| 5239 | |
| 5240 | case 'Y': |
| 5241 | { |
| 5242 | int regno; |
| 5243 | |
| 5244 | regno = va_arg (*args, int); |
| 5245 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); |
| 5246 | MIPS16_INSERT_OPERAND (REG32R, insn, regno); |
| 5247 | } |
| 5248 | continue; |
| 5249 | |
| 5250 | case '<': |
| 5251 | case '>': |
| 5252 | case '4': |
| 5253 | case '5': |
| 5254 | case 'H': |
| 5255 | case 'W': |
| 5256 | case 'D': |
| 5257 | case 'j': |
| 5258 | case '8': |
| 5259 | case 'V': |
| 5260 | case 'C': |
| 5261 | case 'U': |
| 5262 | case 'k': |
| 5263 | case 'K': |
| 5264 | case 'p': |
| 5265 | case 'q': |
| 5266 | { |
| 5267 | offsetT value; |
| 5268 | |
| 5269 | gas_assert (ep != NULL); |
| 5270 | |
| 5271 | if (ep->X_op != O_constant) |
| 5272 | *r = (int) BFD_RELOC_UNUSED + c; |
| 5273 | else if (calculate_reloc (*r, ep->X_add_number, &value)) |
| 5274 | { |
| 5275 | mips16_immed (NULL, 0, c, *r, value, 0, &insn.insn_opcode); |
| 5276 | ep = NULL; |
| 5277 | *r = BFD_RELOC_UNUSED; |
| 5278 | } |
| 5279 | } |
| 5280 | continue; |
| 5281 | |
| 5282 | case '6': |
| 5283 | MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (*args, int)); |
| 5284 | continue; |
| 5285 | } |
| 5286 | |
| 5287 | break; |
| 5288 | } |
| 5289 | |
| 5290 | gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL); |
| 5291 | |
| 5292 | append_insn (&insn, ep, r, TRUE); |
| 5293 | } |
| 5294 | |
| 5295 | /* |
| 5296 | * Sign-extend 32-bit mode constants that have bit 31 set and all |
| 5297 | * higher bits unset. |
| 5298 | */ |
| 5299 | static void |
| 5300 | normalize_constant_expr (expressionS *ex) |
| 5301 | { |
| 5302 | if (ex->X_op == O_constant |
| 5303 | && IS_ZEXT_32BIT_NUM (ex->X_add_number)) |
| 5304 | ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000) |
| 5305 | - 0x80000000); |
| 5306 | } |
| 5307 | |
| 5308 | /* |
| 5309 | * Sign-extend 32-bit mode address offsets that have bit 31 set and |
| 5310 | * all higher bits unset. |
| 5311 | */ |
| 5312 | static void |
| 5313 | normalize_address_expr (expressionS *ex) |
| 5314 | { |
| 5315 | if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES) |
| 5316 | || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS)) |
| 5317 | && IS_ZEXT_32BIT_NUM (ex->X_add_number)) |
| 5318 | ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000) |
| 5319 | - 0x80000000); |
| 5320 | } |
| 5321 | |
| 5322 | /* |
| 5323 | * Generate a "jalr" instruction with a relocation hint to the called |
| 5324 | * function. This occurs in NewABI PIC code. |
| 5325 | */ |
| 5326 | static void |
| 5327 | macro_build_jalr (expressionS *ep, int cprestore) |
| 5328 | { |
| 5329 | static const bfd_reloc_code_real_type jalr_relocs[2] |
| 5330 | = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR }; |
| 5331 | bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips]; |
| 5332 | const char *jalr; |
| 5333 | char *f = NULL; |
| 5334 | |
| 5335 | if (MIPS_JALR_HINT_P (ep)) |
| 5336 | { |
| 5337 | frag_grow (8); |
| 5338 | f = frag_more (0); |
| 5339 | } |
| 5340 | if (mips_opts.micromips) |
| 5341 | { |
| 5342 | jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs"; |
| 5343 | if (MIPS_JALR_HINT_P (ep) |
| 5344 | || (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) |
| 5345 | macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG); |
| 5346 | else |
| 5347 | macro_build (NULL, jalr, "mj", PIC_CALL_REG); |
| 5348 | } |
| 5349 | else |
| 5350 | macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG); |
| 5351 | if (MIPS_JALR_HINT_P (ep)) |
| 5352 | fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc); |
| 5353 | } |
| 5354 | |
| 5355 | /* |
| 5356 | * Generate a "lui" instruction. |
| 5357 | */ |
| 5358 | static void |
| 5359 | macro_build_lui (expressionS *ep, int regnum) |
| 5360 | { |
| 5361 | gas_assert (! mips_opts.mips16); |
| 5362 | |
| 5363 | if (ep->X_op != O_constant) |
| 5364 | { |
| 5365 | gas_assert (ep->X_op == O_symbol); |
| 5366 | /* _gp_disp is a special case, used from s_cpload. |
| 5367 | __gnu_local_gp is used if mips_no_shared. */ |
| 5368 | gas_assert (mips_pic == NO_PIC |
| 5369 | || (! HAVE_NEWABI |
| 5370 | && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0) |
| 5371 | || (! mips_in_shared |
| 5372 | && strcmp (S_GET_NAME (ep->X_add_symbol), |
| 5373 | "__gnu_local_gp") == 0)); |
| 5374 | } |
| 5375 | |
| 5376 | macro_build (ep, "lui", LUI_FMT, regnum, BFD_RELOC_HI16_S); |
| 5377 | } |
| 5378 | |
| 5379 | /* Generate a sequence of instructions to do a load or store from a constant |
| 5380 | offset off of a base register (breg) into/from a target register (treg), |
| 5381 | using AT if necessary. */ |
| 5382 | static void |
| 5383 | macro_build_ldst_constoffset (expressionS *ep, const char *op, |
| 5384 | int treg, int breg, int dbl) |
| 5385 | { |
| 5386 | gas_assert (ep->X_op == O_constant); |
| 5387 | |
| 5388 | /* Sign-extending 32-bit constants makes their handling easier. */ |
| 5389 | if (!dbl) |
| 5390 | normalize_constant_expr (ep); |
| 5391 | |
| 5392 | /* Right now, this routine can only handle signed 32-bit constants. */ |
| 5393 | if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000)) |
| 5394 | as_warn (_("operand overflow")); |
| 5395 | |
| 5396 | if (IS_SEXT_16BIT_NUM(ep->X_add_number)) |
| 5397 | { |
| 5398 | /* Signed 16-bit offset will fit in the op. Easy! */ |
| 5399 | macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg); |
| 5400 | } |
| 5401 | else |
| 5402 | { |
| 5403 | /* 32-bit offset, need multiple instructions and AT, like: |
| 5404 | lui $tempreg,const_hi (BFD_RELOC_HI16_S) |
| 5405 | addu $tempreg,$tempreg,$breg |
| 5406 | <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16) |
| 5407 | to handle the complete offset. */ |
| 5408 | macro_build_lui (ep, AT); |
| 5409 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg); |
| 5410 | macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT); |
| 5411 | |
| 5412 | if (!mips_opts.at) |
| 5413 | as_bad (_("Macro used $at after \".set noat\"")); |
| 5414 | } |
| 5415 | } |
| 5416 | |
| 5417 | /* set_at() |
| 5418 | * Generates code to set the $at register to true (one) |
| 5419 | * if reg is less than the immediate expression. |
| 5420 | */ |
| 5421 | static void |
| 5422 | set_at (int reg, int unsignedp) |
| 5423 | { |
| 5424 | if (imm_expr.X_op == O_constant |
| 5425 | && imm_expr.X_add_number >= -0x8000 |
| 5426 | && imm_expr.X_add_number < 0x8000) |
| 5427 | macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j", |
| 5428 | AT, reg, BFD_RELOC_LO16); |
| 5429 | else |
| 5430 | { |
| 5431 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 5432 | macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT); |
| 5433 | } |
| 5434 | } |
| 5435 | |
| 5436 | /* Warn if an expression is not a constant. */ |
| 5437 | |
| 5438 | static void |
| 5439 | check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex) |
| 5440 | { |
| 5441 | if (ex->X_op == O_big) |
| 5442 | as_bad (_("unsupported large constant")); |
| 5443 | else if (ex->X_op != O_constant) |
| 5444 | as_bad (_("Instruction %s requires absolute expression"), |
| 5445 | ip->insn_mo->name); |
| 5446 | |
| 5447 | if (HAVE_32BIT_GPRS) |
| 5448 | normalize_constant_expr (ex); |
| 5449 | } |
| 5450 | |
| 5451 | /* Count the leading zeroes by performing a binary chop. This is a |
| 5452 | bulky bit of source, but performance is a LOT better for the |
| 5453 | majority of values than a simple loop to count the bits: |
| 5454 | for (lcnt = 0; (lcnt < 32); lcnt++) |
| 5455 | if ((v) & (1 << (31 - lcnt))) |
| 5456 | break; |
| 5457 | However it is not code size friendly, and the gain will drop a bit |
| 5458 | on certain cached systems. |
| 5459 | */ |
| 5460 | #define COUNT_TOP_ZEROES(v) \ |
| 5461 | (((v) & ~0xffff) == 0 \ |
| 5462 | ? ((v) & ~0xff) == 0 \ |
| 5463 | ? ((v) & ~0xf) == 0 \ |
| 5464 | ? ((v) & ~0x3) == 0 \ |
| 5465 | ? ((v) & ~0x1) == 0 \ |
| 5466 | ? !(v) \ |
| 5467 | ? 32 \ |
| 5468 | : 31 \ |
| 5469 | : 30 \ |
| 5470 | : ((v) & ~0x7) == 0 \ |
| 5471 | ? 29 \ |
| 5472 | : 28 \ |
| 5473 | : ((v) & ~0x3f) == 0 \ |
| 5474 | ? ((v) & ~0x1f) == 0 \ |
| 5475 | ? 27 \ |
| 5476 | : 26 \ |
| 5477 | : ((v) & ~0x7f) == 0 \ |
| 5478 | ? 25 \ |
| 5479 | : 24 \ |
| 5480 | : ((v) & ~0xfff) == 0 \ |
| 5481 | ? ((v) & ~0x3ff) == 0 \ |
| 5482 | ? ((v) & ~0x1ff) == 0 \ |
| 5483 | ? 23 \ |
| 5484 | : 22 \ |
| 5485 | : ((v) & ~0x7ff) == 0 \ |
| 5486 | ? 21 \ |
| 5487 | : 20 \ |
| 5488 | : ((v) & ~0x3fff) == 0 \ |
| 5489 | ? ((v) & ~0x1fff) == 0 \ |
| 5490 | ? 19 \ |
| 5491 | : 18 \ |
| 5492 | : ((v) & ~0x7fff) == 0 \ |
| 5493 | ? 17 \ |
| 5494 | : 16 \ |
| 5495 | : ((v) & ~0xffffff) == 0 \ |
| 5496 | ? ((v) & ~0xfffff) == 0 \ |
| 5497 | ? ((v) & ~0x3ffff) == 0 \ |
| 5498 | ? ((v) & ~0x1ffff) == 0 \ |
| 5499 | ? 15 \ |
| 5500 | : 14 \ |
| 5501 | : ((v) & ~0x7ffff) == 0 \ |
| 5502 | ? 13 \ |
| 5503 | : 12 \ |
| 5504 | : ((v) & ~0x3fffff) == 0 \ |
| 5505 | ? ((v) & ~0x1fffff) == 0 \ |
| 5506 | ? 11 \ |
| 5507 | : 10 \ |
| 5508 | : ((v) & ~0x7fffff) == 0 \ |
| 5509 | ? 9 \ |
| 5510 | : 8 \ |
| 5511 | : ((v) & ~0xfffffff) == 0 \ |
| 5512 | ? ((v) & ~0x3ffffff) == 0 \ |
| 5513 | ? ((v) & ~0x1ffffff) == 0 \ |
| 5514 | ? 7 \ |
| 5515 | : 6 \ |
| 5516 | : ((v) & ~0x7ffffff) == 0 \ |
| 5517 | ? 5 \ |
| 5518 | : 4 \ |
| 5519 | : ((v) & ~0x3fffffff) == 0 \ |
| 5520 | ? ((v) & ~0x1fffffff) == 0 \ |
| 5521 | ? 3 \ |
| 5522 | : 2 \ |
| 5523 | : ((v) & ~0x7fffffff) == 0 \ |
| 5524 | ? 1 \ |
| 5525 | : 0) |
| 5526 | |
| 5527 | /* load_register() |
| 5528 | * This routine generates the least number of instructions necessary to load |
| 5529 | * an absolute expression value into a register. |
| 5530 | */ |
| 5531 | static void |
| 5532 | load_register (int reg, expressionS *ep, int dbl) |
| 5533 | { |
| 5534 | int freg; |
| 5535 | expressionS hi32, lo32; |
| 5536 | |
| 5537 | if (ep->X_op != O_big) |
| 5538 | { |
| 5539 | gas_assert (ep->X_op == O_constant); |
| 5540 | |
| 5541 | /* Sign-extending 32-bit constants makes their handling easier. */ |
| 5542 | if (!dbl) |
| 5543 | normalize_constant_expr (ep); |
| 5544 | |
| 5545 | if (IS_SEXT_16BIT_NUM (ep->X_add_number)) |
| 5546 | { |
| 5547 | /* We can handle 16 bit signed values with an addiu to |
| 5548 | $zero. No need to ever use daddiu here, since $zero and |
| 5549 | the result are always correct in 32 bit mode. */ |
| 5550 | macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16); |
| 5551 | return; |
| 5552 | } |
| 5553 | else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000) |
| 5554 | { |
| 5555 | /* We can handle 16 bit unsigned values with an ori to |
| 5556 | $zero. */ |
| 5557 | macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16); |
| 5558 | return; |
| 5559 | } |
| 5560 | else if ((IS_SEXT_32BIT_NUM (ep->X_add_number))) |
| 5561 | { |
| 5562 | /* 32 bit values require an lui. */ |
| 5563 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_HI16); |
| 5564 | if ((ep->X_add_number & 0xffff) != 0) |
| 5565 | macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16); |
| 5566 | return; |
| 5567 | } |
| 5568 | } |
| 5569 | |
| 5570 | /* The value is larger than 32 bits. */ |
| 5571 | |
| 5572 | if (!dbl || HAVE_32BIT_GPRS) |
| 5573 | { |
| 5574 | char value[32]; |
| 5575 | |
| 5576 | sprintf_vma (value, ep->X_add_number); |
| 5577 | as_bad (_("Number (0x%s) larger than 32 bits"), value); |
| 5578 | macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16); |
| 5579 | return; |
| 5580 | } |
| 5581 | |
| 5582 | if (ep->X_op != O_big) |
| 5583 | { |
| 5584 | hi32 = *ep; |
| 5585 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; |
| 5586 | hi32.X_add_number = (valueT) hi32.X_add_number >> 16; |
| 5587 | hi32.X_add_number &= 0xffffffff; |
| 5588 | lo32 = *ep; |
| 5589 | lo32.X_add_number &= 0xffffffff; |
| 5590 | } |
| 5591 | else |
| 5592 | { |
| 5593 | gas_assert (ep->X_add_number > 2); |
| 5594 | if (ep->X_add_number == 3) |
| 5595 | generic_bignum[3] = 0; |
| 5596 | else if (ep->X_add_number > 4) |
| 5597 | as_bad (_("Number larger than 64 bits")); |
| 5598 | lo32.X_op = O_constant; |
| 5599 | lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16); |
| 5600 | hi32.X_op = O_constant; |
| 5601 | hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16); |
| 5602 | } |
| 5603 | |
| 5604 | if (hi32.X_add_number == 0) |
| 5605 | freg = 0; |
| 5606 | else |
| 5607 | { |
| 5608 | int shift, bit; |
| 5609 | unsigned long hi, lo; |
| 5610 | |
| 5611 | if (hi32.X_add_number == (offsetT) 0xffffffff) |
| 5612 | { |
| 5613 | if ((lo32.X_add_number & 0xffff8000) == 0xffff8000) |
| 5614 | { |
| 5615 | macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16); |
| 5616 | return; |
| 5617 | } |
| 5618 | if (lo32.X_add_number & 0x80000000) |
| 5619 | { |
| 5620 | macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16); |
| 5621 | if (lo32.X_add_number & 0xffff) |
| 5622 | macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16); |
| 5623 | return; |
| 5624 | } |
| 5625 | } |
| 5626 | |
| 5627 | /* Check for 16bit shifted constant. We know that hi32 is |
| 5628 | non-zero, so start the mask on the first bit of the hi32 |
| 5629 | value. */ |
| 5630 | shift = 17; |
| 5631 | do |
| 5632 | { |
| 5633 | unsigned long himask, lomask; |
| 5634 | |
| 5635 | if (shift < 32) |
| 5636 | { |
| 5637 | himask = 0xffff >> (32 - shift); |
| 5638 | lomask = (0xffff << shift) & 0xffffffff; |
| 5639 | } |
| 5640 | else |
| 5641 | { |
| 5642 | himask = 0xffff << (shift - 32); |
| 5643 | lomask = 0; |
| 5644 | } |
| 5645 | if ((hi32.X_add_number & ~(offsetT) himask) == 0 |
| 5646 | && (lo32.X_add_number & ~(offsetT) lomask) == 0) |
| 5647 | { |
| 5648 | expressionS tmp; |
| 5649 | |
| 5650 | tmp.X_op = O_constant; |
| 5651 | if (shift < 32) |
| 5652 | tmp.X_add_number = ((hi32.X_add_number << (32 - shift)) |
| 5653 | | (lo32.X_add_number >> shift)); |
| 5654 | else |
| 5655 | tmp.X_add_number = hi32.X_add_number >> (shift - 32); |
| 5656 | macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16); |
| 5657 | macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", SHFT_FMT, |
| 5658 | reg, reg, (shift >= 32) ? shift - 32 : shift); |
| 5659 | return; |
| 5660 | } |
| 5661 | ++shift; |
| 5662 | } |
| 5663 | while (shift <= (64 - 16)); |
| 5664 | |
| 5665 | /* Find the bit number of the lowest one bit, and store the |
| 5666 | shifted value in hi/lo. */ |
| 5667 | hi = (unsigned long) (hi32.X_add_number & 0xffffffff); |
| 5668 | lo = (unsigned long) (lo32.X_add_number & 0xffffffff); |
| 5669 | if (lo != 0) |
| 5670 | { |
| 5671 | bit = 0; |
| 5672 | while ((lo & 1) == 0) |
| 5673 | { |
| 5674 | lo >>= 1; |
| 5675 | ++bit; |
| 5676 | } |
| 5677 | lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit); |
| 5678 | hi >>= bit; |
| 5679 | } |
| 5680 | else |
| 5681 | { |
| 5682 | bit = 32; |
| 5683 | while ((hi & 1) == 0) |
| 5684 | { |
| 5685 | hi >>= 1; |
| 5686 | ++bit; |
| 5687 | } |
| 5688 | lo = hi; |
| 5689 | hi = 0; |
| 5690 | } |
| 5691 | |
| 5692 | /* Optimize if the shifted value is a (power of 2) - 1. */ |
| 5693 | if ((hi == 0 && ((lo + 1) & lo) == 0) |
| 5694 | || (lo == 0xffffffff && ((hi + 1) & hi) == 0)) |
| 5695 | { |
| 5696 | shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number); |
| 5697 | if (shift != 0) |
| 5698 | { |
| 5699 | expressionS tmp; |
| 5700 | |
| 5701 | /* This instruction will set the register to be all |
| 5702 | ones. */ |
| 5703 | tmp.X_op = O_constant; |
| 5704 | tmp.X_add_number = (offsetT) -1; |
| 5705 | macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16); |
| 5706 | if (bit != 0) |
| 5707 | { |
| 5708 | bit += shift; |
| 5709 | macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", SHFT_FMT, |
| 5710 | reg, reg, (bit >= 32) ? bit - 32 : bit); |
| 5711 | } |
| 5712 | macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", SHFT_FMT, |
| 5713 | reg, reg, (shift >= 32) ? shift - 32 : shift); |
| 5714 | return; |
| 5715 | } |
| 5716 | } |
| 5717 | |
| 5718 | /* Sign extend hi32 before calling load_register, because we can |
| 5719 | generally get better code when we load a sign extended value. */ |
| 5720 | if ((hi32.X_add_number & 0x80000000) != 0) |
| 5721 | hi32.X_add_number |= ~(offsetT) 0xffffffff; |
| 5722 | load_register (reg, &hi32, 0); |
| 5723 | freg = reg; |
| 5724 | } |
| 5725 | if ((lo32.X_add_number & 0xffff0000) == 0) |
| 5726 | { |
| 5727 | if (freg != 0) |
| 5728 | { |
| 5729 | macro_build (NULL, "dsll32", SHFT_FMT, reg, freg, 0); |
| 5730 | freg = reg; |
| 5731 | } |
| 5732 | } |
| 5733 | else |
| 5734 | { |
| 5735 | expressionS mid16; |
| 5736 | |
| 5737 | if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff)) |
| 5738 | { |
| 5739 | macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16); |
| 5740 | macro_build (NULL, "dsrl32", SHFT_FMT, reg, reg, 0); |
| 5741 | return; |
| 5742 | } |
| 5743 | |
| 5744 | if (freg != 0) |
| 5745 | { |
| 5746 | macro_build (NULL, "dsll", SHFT_FMT, reg, freg, 16); |
| 5747 | freg = reg; |
| 5748 | } |
| 5749 | mid16 = lo32; |
| 5750 | mid16.X_add_number >>= 16; |
| 5751 | macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16); |
| 5752 | macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16); |
| 5753 | freg = reg; |
| 5754 | } |
| 5755 | if ((lo32.X_add_number & 0xffff) != 0) |
| 5756 | macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16); |
| 5757 | } |
| 5758 | |
| 5759 | static inline void |
| 5760 | load_delay_nop (void) |
| 5761 | { |
| 5762 | if (!gpr_interlocks) |
| 5763 | macro_build (NULL, "nop", ""); |
| 5764 | } |
| 5765 | |
| 5766 | /* Load an address into a register. */ |
| 5767 | |
| 5768 | static void |
| 5769 | load_address (int reg, expressionS *ep, int *used_at) |
| 5770 | { |
| 5771 | if (ep->X_op != O_constant |
| 5772 | && ep->X_op != O_symbol) |
| 5773 | { |
| 5774 | as_bad (_("expression too complex")); |
| 5775 | ep->X_op = O_constant; |
| 5776 | } |
| 5777 | |
| 5778 | if (ep->X_op == O_constant) |
| 5779 | { |
| 5780 | load_register (reg, ep, HAVE_64BIT_ADDRESSES); |
| 5781 | return; |
| 5782 | } |
| 5783 | |
| 5784 | if (mips_pic == NO_PIC) |
| 5785 | { |
| 5786 | /* If this is a reference to a GP relative symbol, we want |
| 5787 | addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16) |
| 5788 | Otherwise we want |
| 5789 | lui $reg,<sym> (BFD_RELOC_HI16_S) |
| 5790 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) |
| 5791 | If we have an addend, we always use the latter form. |
| 5792 | |
| 5793 | With 64bit address space and a usable $at we want |
| 5794 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) |
| 5795 | lui $at,<sym> (BFD_RELOC_HI16_S) |
| 5796 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) |
| 5797 | daddiu $at,<sym> (BFD_RELOC_LO16) |
| 5798 | dsll32 $reg,0 |
| 5799 | daddu $reg,$reg,$at |
| 5800 | |
| 5801 | If $at is already in use, we use a path which is suboptimal |
| 5802 | on superscalar processors. |
| 5803 | lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST) |
| 5804 | daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER) |
| 5805 | dsll $reg,16 |
| 5806 | daddiu $reg,<sym> (BFD_RELOC_HI16_S) |
| 5807 | dsll $reg,16 |
| 5808 | daddiu $reg,<sym> (BFD_RELOC_LO16) |
| 5809 | |
| 5810 | For GP relative symbols in 64bit address space we can use |
| 5811 | the same sequence as in 32bit address space. */ |
| 5812 | if (HAVE_64BIT_SYMBOLS) |
| 5813 | { |
| 5814 | if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET |
| 5815 | && !nopic_need_relax (ep->X_add_symbol, 1)) |
| 5816 | { |
| 5817 | relax_start (ep->X_add_symbol); |
| 5818 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, |
| 5819 | mips_gp_register, BFD_RELOC_GPREL16); |
| 5820 | relax_switch (); |
| 5821 | } |
| 5822 | |
| 5823 | if (*used_at == 0 && mips_opts.at) |
| 5824 | { |
| 5825 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST); |
| 5826 | macro_build (ep, "lui", LUI_FMT, AT, BFD_RELOC_HI16_S); |
| 5827 | macro_build (ep, "daddiu", "t,r,j", reg, reg, |
| 5828 | BFD_RELOC_MIPS_HIGHER); |
| 5829 | macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16); |
| 5830 | macro_build (NULL, "dsll32", SHFT_FMT, reg, reg, 0); |
| 5831 | macro_build (NULL, "daddu", "d,v,t", reg, reg, AT); |
| 5832 | *used_at = 1; |
| 5833 | } |
| 5834 | else |
| 5835 | { |
| 5836 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST); |
| 5837 | macro_build (ep, "daddiu", "t,r,j", reg, reg, |
| 5838 | BFD_RELOC_MIPS_HIGHER); |
| 5839 | macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16); |
| 5840 | macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S); |
| 5841 | macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16); |
| 5842 | macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16); |
| 5843 | } |
| 5844 | |
| 5845 | if (mips_relax.sequence) |
| 5846 | relax_end (); |
| 5847 | } |
| 5848 | else |
| 5849 | { |
| 5850 | if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET |
| 5851 | && !nopic_need_relax (ep->X_add_symbol, 1)) |
| 5852 | { |
| 5853 | relax_start (ep->X_add_symbol); |
| 5854 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, |
| 5855 | mips_gp_register, BFD_RELOC_GPREL16); |
| 5856 | relax_switch (); |
| 5857 | } |
| 5858 | macro_build_lui (ep, reg); |
| 5859 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", |
| 5860 | reg, reg, BFD_RELOC_LO16); |
| 5861 | if (mips_relax.sequence) |
| 5862 | relax_end (); |
| 5863 | } |
| 5864 | } |
| 5865 | else if (!mips_big_got) |
| 5866 | { |
| 5867 | expressionS ex; |
| 5868 | |
| 5869 | /* If this is a reference to an external symbol, we want |
| 5870 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 5871 | Otherwise we want |
| 5872 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 5873 | nop |
| 5874 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) |
| 5875 | If there is a constant, it must be added in after. |
| 5876 | |
| 5877 | If we have NewABI, we want |
| 5878 | lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP) |
| 5879 | unless we're referencing a global symbol with a non-zero |
| 5880 | offset, in which case cst must be added separately. */ |
| 5881 | if (HAVE_NEWABI) |
| 5882 | { |
| 5883 | if (ep->X_add_number) |
| 5884 | { |
| 5885 | ex.X_add_number = ep->X_add_number; |
| 5886 | ep->X_add_number = 0; |
| 5887 | relax_start (ep->X_add_symbol); |
| 5888 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
| 5889 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); |
| 5890 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) |
| 5891 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 5892 | ex.X_op = O_constant; |
| 5893 | macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", |
| 5894 | reg, reg, BFD_RELOC_LO16); |
| 5895 | ep->X_add_number = ex.X_add_number; |
| 5896 | relax_switch (); |
| 5897 | } |
| 5898 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
| 5899 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); |
| 5900 | if (mips_relax.sequence) |
| 5901 | relax_end (); |
| 5902 | } |
| 5903 | else |
| 5904 | { |
| 5905 | ex.X_add_number = ep->X_add_number; |
| 5906 | ep->X_add_number = 0; |
| 5907 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
| 5908 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 5909 | load_delay_nop (); |
| 5910 | relax_start (ep->X_add_symbol); |
| 5911 | relax_switch (); |
| 5912 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
| 5913 | BFD_RELOC_LO16); |
| 5914 | relax_end (); |
| 5915 | |
| 5916 | if (ex.X_add_number != 0) |
| 5917 | { |
| 5918 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) |
| 5919 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 5920 | ex.X_op = O_constant; |
| 5921 | macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", |
| 5922 | reg, reg, BFD_RELOC_LO16); |
| 5923 | } |
| 5924 | } |
| 5925 | } |
| 5926 | else if (mips_big_got) |
| 5927 | { |
| 5928 | expressionS ex; |
| 5929 | |
| 5930 | /* This is the large GOT case. If this is a reference to an |
| 5931 | external symbol, we want |
| 5932 | lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 5933 | addu $reg,$reg,$gp |
| 5934 | lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16) |
| 5935 | |
| 5936 | Otherwise, for a reference to a local symbol in old ABI, we want |
| 5937 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 5938 | nop |
| 5939 | addiu $reg,$reg,<sym> (BFD_RELOC_LO16) |
| 5940 | If there is a constant, it must be added in after. |
| 5941 | |
| 5942 | In the NewABI, for local symbols, with or without offsets, we want: |
| 5943 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) |
| 5944 | addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST) |
| 5945 | */ |
| 5946 | if (HAVE_NEWABI) |
| 5947 | { |
| 5948 | ex.X_add_number = ep->X_add_number; |
| 5949 | ep->X_add_number = 0; |
| 5950 | relax_start (ep->X_add_symbol); |
| 5951 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16); |
| 5952 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 5953 | reg, reg, mips_gp_register); |
| 5954 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", |
| 5955 | reg, BFD_RELOC_MIPS_GOT_LO16, reg); |
| 5956 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) |
| 5957 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 5958 | else if (ex.X_add_number) |
| 5959 | { |
| 5960 | ex.X_op = O_constant; |
| 5961 | macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
| 5962 | BFD_RELOC_LO16); |
| 5963 | } |
| 5964 | |
| 5965 | ep->X_add_number = ex.X_add_number; |
| 5966 | relax_switch (); |
| 5967 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
| 5968 | BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); |
| 5969 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
| 5970 | BFD_RELOC_MIPS_GOT_OFST); |
| 5971 | relax_end (); |
| 5972 | } |
| 5973 | else |
| 5974 | { |
| 5975 | ex.X_add_number = ep->X_add_number; |
| 5976 | ep->X_add_number = 0; |
| 5977 | relax_start (ep->X_add_symbol); |
| 5978 | macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16); |
| 5979 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 5980 | reg, reg, mips_gp_register); |
| 5981 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", |
| 5982 | reg, BFD_RELOC_MIPS_GOT_LO16, reg); |
| 5983 | relax_switch (); |
| 5984 | if (reg_needs_delay (mips_gp_register)) |
| 5985 | { |
| 5986 | /* We need a nop before loading from $gp. This special |
| 5987 | check is required because the lui which starts the main |
| 5988 | instruction stream does not refer to $gp, and so will not |
| 5989 | insert the nop which may be required. */ |
| 5990 | macro_build (NULL, "nop", ""); |
| 5991 | } |
| 5992 | macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg, |
| 5993 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 5994 | load_delay_nop (); |
| 5995 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
| 5996 | BFD_RELOC_LO16); |
| 5997 | relax_end (); |
| 5998 | |
| 5999 | if (ex.X_add_number != 0) |
| 6000 | { |
| 6001 | if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000) |
| 6002 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 6003 | ex.X_op = O_constant; |
| 6004 | macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg, |
| 6005 | BFD_RELOC_LO16); |
| 6006 | } |
| 6007 | } |
| 6008 | } |
| 6009 | else |
| 6010 | abort (); |
| 6011 | |
| 6012 | if (!mips_opts.at && *used_at == 1) |
| 6013 | as_bad (_("Macro used $at after \".set noat\"")); |
| 6014 | } |
| 6015 | |
| 6016 | /* Move the contents of register SOURCE into register DEST. */ |
| 6017 | |
| 6018 | static void |
| 6019 | move_register (int dest, int source) |
| 6020 | { |
| 6021 | /* Prefer to use a 16-bit microMIPS instruction unless the previous |
| 6022 | instruction specifically requires a 32-bit one. */ |
| 6023 | if (mips_opts.micromips |
| 6024 | && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) |
| 6025 | macro_build (NULL, "move", "mp,mj", dest, source); |
| 6026 | else |
| 6027 | macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t", |
| 6028 | dest, source, 0); |
| 6029 | } |
| 6030 | |
| 6031 | /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where |
| 6032 | LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement. |
| 6033 | The two alternatives are: |
| 6034 | |
| 6035 | Global symbol Local sybmol |
| 6036 | ------------- ------------ |
| 6037 | lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET) |
| 6038 | ... ... |
| 6039 | addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET) |
| 6040 | |
| 6041 | load_got_offset emits the first instruction and add_got_offset |
| 6042 | emits the second for a 16-bit offset or add_got_offset_hilo emits |
| 6043 | a sequence to add a 32-bit offset using a scratch register. */ |
| 6044 | |
| 6045 | static void |
| 6046 | load_got_offset (int dest, expressionS *local) |
| 6047 | { |
| 6048 | expressionS global; |
| 6049 | |
| 6050 | global = *local; |
| 6051 | global.X_add_number = 0; |
| 6052 | |
| 6053 | relax_start (local->X_add_symbol); |
| 6054 | macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest, |
| 6055 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 6056 | relax_switch (); |
| 6057 | macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest, |
| 6058 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 6059 | relax_end (); |
| 6060 | } |
| 6061 | |
| 6062 | static void |
| 6063 | add_got_offset (int dest, expressionS *local) |
| 6064 | { |
| 6065 | expressionS global; |
| 6066 | |
| 6067 | global.X_op = O_constant; |
| 6068 | global.X_op_symbol = NULL; |
| 6069 | global.X_add_symbol = NULL; |
| 6070 | global.X_add_number = local->X_add_number; |
| 6071 | |
| 6072 | relax_start (local->X_add_symbol); |
| 6073 | macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j", |
| 6074 | dest, dest, BFD_RELOC_LO16); |
| 6075 | relax_switch (); |
| 6076 | macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16); |
| 6077 | relax_end (); |
| 6078 | } |
| 6079 | |
| 6080 | static void |
| 6081 | add_got_offset_hilo (int dest, expressionS *local, int tmp) |
| 6082 | { |
| 6083 | expressionS global; |
| 6084 | int hold_mips_optimize; |
| 6085 | |
| 6086 | global.X_op = O_constant; |
| 6087 | global.X_op_symbol = NULL; |
| 6088 | global.X_add_symbol = NULL; |
| 6089 | global.X_add_number = local->X_add_number; |
| 6090 | |
| 6091 | relax_start (local->X_add_symbol); |
| 6092 | load_register (tmp, &global, HAVE_64BIT_ADDRESSES); |
| 6093 | relax_switch (); |
| 6094 | /* Set mips_optimize around the lui instruction to avoid |
| 6095 | inserting an unnecessary nop after the lw. */ |
| 6096 | hold_mips_optimize = mips_optimize; |
| 6097 | mips_optimize = 2; |
| 6098 | macro_build_lui (&global, tmp); |
| 6099 | mips_optimize = hold_mips_optimize; |
| 6100 | macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16); |
| 6101 | relax_end (); |
| 6102 | |
| 6103 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp); |
| 6104 | } |
| 6105 | |
| 6106 | /* Emit a sequence of instructions to emulate a branch likely operation. |
| 6107 | BR is an ordinary branch corresponding to one to be emulated. BRNEG |
| 6108 | is its complementing branch with the original condition negated. |
| 6109 | CALL is set if the original branch specified the link operation. |
| 6110 | EP, FMT, SREG and TREG specify the usual macro_build() parameters. |
| 6111 | |
| 6112 | Code like this is produced in the noreorder mode: |
| 6113 | |
| 6114 | BRNEG <args>, 1f |
| 6115 | nop |
| 6116 | b <sym> |
| 6117 | delay slot (executed only if branch taken) |
| 6118 | 1: |
| 6119 | |
| 6120 | or, if CALL is set: |
| 6121 | |
| 6122 | BRNEG <args>, 1f |
| 6123 | nop |
| 6124 | bal <sym> |
| 6125 | delay slot (executed only if branch taken) |
| 6126 | 1: |
| 6127 | |
| 6128 | In the reorder mode the delay slot would be filled with a nop anyway, |
| 6129 | so code produced is simply: |
| 6130 | |
| 6131 | BR <args>, <sym> |
| 6132 | nop |
| 6133 | |
| 6134 | This function is used when producing code for the microMIPS ASE that |
| 6135 | does not implement branch likely instructions in hardware. */ |
| 6136 | |
| 6137 | static void |
| 6138 | macro_build_branch_likely (const char *br, const char *brneg, |
| 6139 | int call, expressionS *ep, const char *fmt, |
| 6140 | unsigned int sreg, unsigned int treg) |
| 6141 | { |
| 6142 | int noreorder = mips_opts.noreorder; |
| 6143 | expressionS expr1; |
| 6144 | |
| 6145 | gas_assert (mips_opts.micromips); |
| 6146 | start_noreorder (); |
| 6147 | if (noreorder) |
| 6148 | { |
| 6149 | micromips_label_expr (&expr1); |
| 6150 | macro_build (&expr1, brneg, fmt, sreg, treg); |
| 6151 | macro_build (NULL, "nop", ""); |
| 6152 | macro_build (ep, call ? "bal" : "b", "p"); |
| 6153 | |
| 6154 | /* Set to true so that append_insn adds a label. */ |
| 6155 | emit_branch_likely_macro = TRUE; |
| 6156 | } |
| 6157 | else |
| 6158 | { |
| 6159 | macro_build (ep, br, fmt, sreg, treg); |
| 6160 | macro_build (NULL, "nop", ""); |
| 6161 | } |
| 6162 | end_noreorder (); |
| 6163 | } |
| 6164 | |
| 6165 | /* Emit a coprocessor branch-likely macro specified by TYPE, using CC as |
| 6166 | the condition code tested. EP specifies the branch target. */ |
| 6167 | |
| 6168 | static void |
| 6169 | macro_build_branch_ccl (int type, expressionS *ep, unsigned int cc) |
| 6170 | { |
| 6171 | const int call = 0; |
| 6172 | const char *brneg; |
| 6173 | const char *br; |
| 6174 | |
| 6175 | switch (type) |
| 6176 | { |
| 6177 | case M_BC1FL: |
| 6178 | br = "bc1f"; |
| 6179 | brneg = "bc1t"; |
| 6180 | break; |
| 6181 | case M_BC1TL: |
| 6182 | br = "bc1t"; |
| 6183 | brneg = "bc1f"; |
| 6184 | break; |
| 6185 | case M_BC2FL: |
| 6186 | br = "bc2f"; |
| 6187 | brneg = "bc2t"; |
| 6188 | break; |
| 6189 | case M_BC2TL: |
| 6190 | br = "bc2t"; |
| 6191 | brneg = "bc2f"; |
| 6192 | break; |
| 6193 | default: |
| 6194 | abort (); |
| 6195 | } |
| 6196 | macro_build_branch_likely (br, brneg, call, ep, "N,p", cc, ZERO); |
| 6197 | } |
| 6198 | |
| 6199 | /* Emit a two-argument branch macro specified by TYPE, using SREG as |
| 6200 | the register tested. EP specifies the branch target. */ |
| 6201 | |
| 6202 | static void |
| 6203 | macro_build_branch_rs (int type, expressionS *ep, unsigned int sreg) |
| 6204 | { |
| 6205 | const char *brneg = NULL; |
| 6206 | const char *br; |
| 6207 | int call = 0; |
| 6208 | |
| 6209 | switch (type) |
| 6210 | { |
| 6211 | case M_BGEZ: |
| 6212 | br = "bgez"; |
| 6213 | break; |
| 6214 | case M_BGEZL: |
| 6215 | br = mips_opts.micromips ? "bgez" : "bgezl"; |
| 6216 | brneg = "bltz"; |
| 6217 | break; |
| 6218 | case M_BGEZALL: |
| 6219 | gas_assert (mips_opts.micromips); |
| 6220 | br = "bgezals"; |
| 6221 | brneg = "bltz"; |
| 6222 | call = 1; |
| 6223 | break; |
| 6224 | case M_BGTZ: |
| 6225 | br = "bgtz"; |
| 6226 | break; |
| 6227 | case M_BGTZL: |
| 6228 | br = mips_opts.micromips ? "bgtz" : "bgtzl"; |
| 6229 | brneg = "blez"; |
| 6230 | break; |
| 6231 | case M_BLEZ: |
| 6232 | br = "blez"; |
| 6233 | break; |
| 6234 | case M_BLEZL: |
| 6235 | br = mips_opts.micromips ? "blez" : "blezl"; |
| 6236 | brneg = "bgtz"; |
| 6237 | break; |
| 6238 | case M_BLTZ: |
| 6239 | br = "bltz"; |
| 6240 | break; |
| 6241 | case M_BLTZL: |
| 6242 | br = mips_opts.micromips ? "bltz" : "bltzl"; |
| 6243 | brneg = "bgez"; |
| 6244 | break; |
| 6245 | case M_BLTZALL: |
| 6246 | gas_assert (mips_opts.micromips); |
| 6247 | br = "bltzals"; |
| 6248 | brneg = "bgez"; |
| 6249 | call = 1; |
| 6250 | break; |
| 6251 | default: |
| 6252 | abort (); |
| 6253 | } |
| 6254 | if (mips_opts.micromips && brneg) |
| 6255 | macro_build_branch_likely (br, brneg, call, ep, "s,p", sreg, ZERO); |
| 6256 | else |
| 6257 | macro_build (ep, br, "s,p", sreg); |
| 6258 | } |
| 6259 | |
| 6260 | /* Emit a three-argument branch macro specified by TYPE, using SREG and |
| 6261 | TREG as the registers tested. EP specifies the branch target. */ |
| 6262 | |
| 6263 | static void |
| 6264 | macro_build_branch_rsrt (int type, expressionS *ep, |
| 6265 | unsigned int sreg, unsigned int treg) |
| 6266 | { |
| 6267 | const char *brneg = NULL; |
| 6268 | const int call = 0; |
| 6269 | const char *br; |
| 6270 | |
| 6271 | switch (type) |
| 6272 | { |
| 6273 | case M_BEQ: |
| 6274 | case M_BEQ_I: |
| 6275 | br = "beq"; |
| 6276 | break; |
| 6277 | case M_BEQL: |
| 6278 | case M_BEQL_I: |
| 6279 | br = mips_opts.micromips ? "beq" : "beql"; |
| 6280 | brneg = "bne"; |
| 6281 | break; |
| 6282 | case M_BNE: |
| 6283 | case M_BNE_I: |
| 6284 | br = "bne"; |
| 6285 | break; |
| 6286 | case M_BNEL: |
| 6287 | case M_BNEL_I: |
| 6288 | br = mips_opts.micromips ? "bne" : "bnel"; |
| 6289 | brneg = "beq"; |
| 6290 | break; |
| 6291 | default: |
| 6292 | abort (); |
| 6293 | } |
| 6294 | if (mips_opts.micromips && brneg) |
| 6295 | macro_build_branch_likely (br, brneg, call, ep, "s,t,p", sreg, treg); |
| 6296 | else |
| 6297 | macro_build (ep, br, "s,t,p", sreg, treg); |
| 6298 | } |
| 6299 | |
| 6300 | /* |
| 6301 | * Build macros |
| 6302 | * This routine implements the seemingly endless macro or synthesized |
| 6303 | * instructions and addressing modes in the mips assembly language. Many |
| 6304 | * of these macros are simple and are similar to each other. These could |
| 6305 | * probably be handled by some kind of table or grammar approach instead of |
| 6306 | * this verbose method. Others are not simple macros but are more like |
| 6307 | * optimizing code generation. |
| 6308 | * One interesting optimization is when several store macros appear |
| 6309 | * consecutively that would load AT with the upper half of the same address. |
| 6310 | * The ensuing load upper instructions are ommited. This implies some kind |
| 6311 | * of global optimization. We currently only optimize within a single macro. |
| 6312 | * For many of the load and store macros if the address is specified as a |
| 6313 | * constant expression in the first 64k of memory (ie ld $2,0x4000c) we |
| 6314 | * first load register 'at' with zero and use it as the base register. The |
| 6315 | * mips assembler simply uses register $zero. Just one tiny optimization |
| 6316 | * we're missing. |
| 6317 | */ |
| 6318 | static void |
| 6319 | macro (struct mips_cl_insn *ip) |
| 6320 | { |
| 6321 | unsigned int treg, sreg, dreg, breg; |
| 6322 | unsigned int tempreg; |
| 6323 | int mask; |
| 6324 | int used_at = 0; |
| 6325 | expressionS label_expr; |
| 6326 | expressionS expr1; |
| 6327 | expressionS *ep; |
| 6328 | const char *s; |
| 6329 | const char *s2; |
| 6330 | const char *fmt; |
| 6331 | int likely = 0; |
| 6332 | int coproc = 0; |
| 6333 | int off12 = 0; |
| 6334 | int call = 0; |
| 6335 | int jals = 0; |
| 6336 | int dbl = 0; |
| 6337 | int imm = 0; |
| 6338 | int ust = 0; |
| 6339 | int lp = 0; |
| 6340 | int ab = 0; |
| 6341 | int off0 = 0; |
| 6342 | int off; |
| 6343 | offsetT maxnum; |
| 6344 | bfd_reloc_code_real_type r; |
| 6345 | int hold_mips_optimize; |
| 6346 | |
| 6347 | gas_assert (! mips_opts.mips16); |
| 6348 | |
| 6349 | treg = EXTRACT_OPERAND (mips_opts.micromips, RT, *ip); |
| 6350 | dreg = EXTRACT_OPERAND (mips_opts.micromips, RD, *ip); |
| 6351 | sreg = breg = EXTRACT_OPERAND (mips_opts.micromips, RS, *ip); |
| 6352 | mask = ip->insn_mo->mask; |
| 6353 | |
| 6354 | label_expr.X_op = O_constant; |
| 6355 | label_expr.X_op_symbol = NULL; |
| 6356 | label_expr.X_add_symbol = NULL; |
| 6357 | label_expr.X_add_number = 0; |
| 6358 | |
| 6359 | expr1.X_op = O_constant; |
| 6360 | expr1.X_op_symbol = NULL; |
| 6361 | expr1.X_add_symbol = NULL; |
| 6362 | expr1.X_add_number = 1; |
| 6363 | |
| 6364 | switch (mask) |
| 6365 | { |
| 6366 | case M_DABS: |
| 6367 | dbl = 1; |
| 6368 | case M_ABS: |
| 6369 | /* bgez $a0,1f |
| 6370 | move v0,$a0 |
| 6371 | sub v0,$zero,$a0 |
| 6372 | 1: |
| 6373 | */ |
| 6374 | |
| 6375 | start_noreorder (); |
| 6376 | |
| 6377 | if (mips_opts.micromips) |
| 6378 | micromips_label_expr (&label_expr); |
| 6379 | else |
| 6380 | label_expr.X_add_number = 8; |
| 6381 | macro_build (&label_expr, "bgez", "s,p", sreg); |
| 6382 | if (dreg == sreg) |
| 6383 | macro_build (NULL, "nop", ""); |
| 6384 | else |
| 6385 | move_register (dreg, sreg); |
| 6386 | macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg); |
| 6387 | if (mips_opts.micromips) |
| 6388 | micromips_add_label (); |
| 6389 | |
| 6390 | end_noreorder (); |
| 6391 | break; |
| 6392 | |
| 6393 | case M_ADD_I: |
| 6394 | s = "addi"; |
| 6395 | s2 = "add"; |
| 6396 | goto do_addi; |
| 6397 | case M_ADDU_I: |
| 6398 | s = "addiu"; |
| 6399 | s2 = "addu"; |
| 6400 | goto do_addi; |
| 6401 | case M_DADD_I: |
| 6402 | dbl = 1; |
| 6403 | s = "daddi"; |
| 6404 | s2 = "dadd"; |
| 6405 | if (!mips_opts.micromips) |
| 6406 | goto do_addi; |
| 6407 | if (imm_expr.X_op == O_constant |
| 6408 | && imm_expr.X_add_number >= -0x200 |
| 6409 | && imm_expr.X_add_number < 0x200) |
| 6410 | { |
| 6411 | macro_build (NULL, s, "t,r,.", treg, sreg, imm_expr.X_add_number); |
| 6412 | break; |
| 6413 | } |
| 6414 | goto do_addi_i; |
| 6415 | case M_DADDU_I: |
| 6416 | dbl = 1; |
| 6417 | s = "daddiu"; |
| 6418 | s2 = "daddu"; |
| 6419 | do_addi: |
| 6420 | if (imm_expr.X_op == O_constant |
| 6421 | && imm_expr.X_add_number >= -0x8000 |
| 6422 | && imm_expr.X_add_number < 0x8000) |
| 6423 | { |
| 6424 | macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16); |
| 6425 | break; |
| 6426 | } |
| 6427 | do_addi_i: |
| 6428 | used_at = 1; |
| 6429 | load_register (AT, &imm_expr, dbl); |
| 6430 | macro_build (NULL, s2, "d,v,t", treg, sreg, AT); |
| 6431 | break; |
| 6432 | |
| 6433 | case M_AND_I: |
| 6434 | s = "andi"; |
| 6435 | s2 = "and"; |
| 6436 | goto do_bit; |
| 6437 | case M_OR_I: |
| 6438 | s = "ori"; |
| 6439 | s2 = "or"; |
| 6440 | goto do_bit; |
| 6441 | case M_NOR_I: |
| 6442 | s = ""; |
| 6443 | s2 = "nor"; |
| 6444 | goto do_bit; |
| 6445 | case M_XOR_I: |
| 6446 | s = "xori"; |
| 6447 | s2 = "xor"; |
| 6448 | do_bit: |
| 6449 | if (imm_expr.X_op == O_constant |
| 6450 | && imm_expr.X_add_number >= 0 |
| 6451 | && imm_expr.X_add_number < 0x10000) |
| 6452 | { |
| 6453 | if (mask != M_NOR_I) |
| 6454 | macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16); |
| 6455 | else |
| 6456 | { |
| 6457 | macro_build (&imm_expr, "ori", "t,r,i", |
| 6458 | treg, sreg, BFD_RELOC_LO16); |
| 6459 | macro_build (NULL, "nor", "d,v,t", treg, treg, 0); |
| 6460 | } |
| 6461 | break; |
| 6462 | } |
| 6463 | |
| 6464 | used_at = 1; |
| 6465 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 6466 | macro_build (NULL, s2, "d,v,t", treg, sreg, AT); |
| 6467 | break; |
| 6468 | |
| 6469 | case M_BALIGN: |
| 6470 | switch (imm_expr.X_add_number) |
| 6471 | { |
| 6472 | case 0: |
| 6473 | macro_build (NULL, "nop", ""); |
| 6474 | break; |
| 6475 | case 2: |
| 6476 | macro_build (NULL, "packrl.ph", "d,s,t", treg, treg, sreg); |
| 6477 | break; |
| 6478 | case 1: |
| 6479 | case 3: |
| 6480 | macro_build (NULL, "balign", "t,s,2", treg, sreg, |
| 6481 | (int) imm_expr.X_add_number); |
| 6482 | break; |
| 6483 | default: |
| 6484 | as_bad (_("BALIGN immediate not 0, 1, 2 or 3 (%lu)"), |
| 6485 | (unsigned long) imm_expr.X_add_number); |
| 6486 | break; |
| 6487 | } |
| 6488 | break; |
| 6489 | |
| 6490 | case M_BC1FL: |
| 6491 | case M_BC1TL: |
| 6492 | case M_BC2FL: |
| 6493 | case M_BC2TL: |
| 6494 | gas_assert (mips_opts.micromips); |
| 6495 | macro_build_branch_ccl (mask, &offset_expr, |
| 6496 | EXTRACT_OPERAND (1, BCC, *ip)); |
| 6497 | break; |
| 6498 | |
| 6499 | case M_BEQ_I: |
| 6500 | case M_BEQL_I: |
| 6501 | case M_BNE_I: |
| 6502 | case M_BNEL_I: |
| 6503 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
| 6504 | treg = 0; |
| 6505 | else |
| 6506 | { |
| 6507 | treg = AT; |
| 6508 | used_at = 1; |
| 6509 | load_register (treg, &imm_expr, HAVE_64BIT_GPRS); |
| 6510 | } |
| 6511 | /* Fall through. */ |
| 6512 | case M_BEQL: |
| 6513 | case M_BNEL: |
| 6514 | macro_build_branch_rsrt (mask, &offset_expr, sreg, treg); |
| 6515 | break; |
| 6516 | |
| 6517 | case M_BGEL: |
| 6518 | likely = 1; |
| 6519 | case M_BGE: |
| 6520 | if (treg == 0) |
| 6521 | macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, sreg); |
| 6522 | else if (sreg == 0) |
| 6523 | macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, treg); |
| 6524 | else |
| 6525 | { |
| 6526 | used_at = 1; |
| 6527 | macro_build (NULL, "slt", "d,v,t", AT, sreg, treg); |
| 6528 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6529 | &offset_expr, AT, ZERO); |
| 6530 | } |
| 6531 | break; |
| 6532 | |
| 6533 | case M_BGEZL: |
| 6534 | case M_BGEZALL: |
| 6535 | case M_BGTZL: |
| 6536 | case M_BLEZL: |
| 6537 | case M_BLTZL: |
| 6538 | case M_BLTZALL: |
| 6539 | macro_build_branch_rs (mask, &offset_expr, sreg); |
| 6540 | break; |
| 6541 | |
| 6542 | case M_BGTL_I: |
| 6543 | likely = 1; |
| 6544 | case M_BGT_I: |
| 6545 | /* Check for > max integer. */ |
| 6546 | maxnum = 0x7fffffff; |
| 6547 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
| 6548 | { |
| 6549 | maxnum <<= 16; |
| 6550 | maxnum |= 0xffff; |
| 6551 | maxnum <<= 16; |
| 6552 | maxnum |= 0xffff; |
| 6553 | } |
| 6554 | if (imm_expr.X_op == O_constant |
| 6555 | && imm_expr.X_add_number >= maxnum |
| 6556 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
| 6557 | { |
| 6558 | do_false: |
| 6559 | /* Result is always false. */ |
| 6560 | if (! likely) |
| 6561 | macro_build (NULL, "nop", ""); |
| 6562 | else |
| 6563 | macro_build_branch_rsrt (M_BNEL, &offset_expr, ZERO, ZERO); |
| 6564 | break; |
| 6565 | } |
| 6566 | if (imm_expr.X_op != O_constant) |
| 6567 | as_bad (_("Unsupported large constant")); |
| 6568 | ++imm_expr.X_add_number; |
| 6569 | /* FALLTHROUGH */ |
| 6570 | case M_BGE_I: |
| 6571 | case M_BGEL_I: |
| 6572 | if (mask == M_BGEL_I) |
| 6573 | likely = 1; |
| 6574 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
| 6575 | { |
| 6576 | macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, |
| 6577 | &offset_expr, sreg); |
| 6578 | break; |
| 6579 | } |
| 6580 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) |
| 6581 | { |
| 6582 | macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, |
| 6583 | &offset_expr, sreg); |
| 6584 | break; |
| 6585 | } |
| 6586 | maxnum = 0x7fffffff; |
| 6587 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
| 6588 | { |
| 6589 | maxnum <<= 16; |
| 6590 | maxnum |= 0xffff; |
| 6591 | maxnum <<= 16; |
| 6592 | maxnum |= 0xffff; |
| 6593 | } |
| 6594 | maxnum = - maxnum - 1; |
| 6595 | if (imm_expr.X_op == O_constant |
| 6596 | && imm_expr.X_add_number <= maxnum |
| 6597 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
| 6598 | { |
| 6599 | do_true: |
| 6600 | /* result is always true */ |
| 6601 | as_warn (_("Branch %s is always true"), ip->insn_mo->name); |
| 6602 | macro_build (&offset_expr, "b", "p"); |
| 6603 | break; |
| 6604 | } |
| 6605 | used_at = 1; |
| 6606 | set_at (sreg, 0); |
| 6607 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6608 | &offset_expr, AT, ZERO); |
| 6609 | break; |
| 6610 | |
| 6611 | case M_BGEUL: |
| 6612 | likely = 1; |
| 6613 | case M_BGEU: |
| 6614 | if (treg == 0) |
| 6615 | goto do_true; |
| 6616 | else if (sreg == 0) |
| 6617 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6618 | &offset_expr, ZERO, treg); |
| 6619 | else |
| 6620 | { |
| 6621 | used_at = 1; |
| 6622 | macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg); |
| 6623 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6624 | &offset_expr, AT, ZERO); |
| 6625 | } |
| 6626 | break; |
| 6627 | |
| 6628 | case M_BGTUL_I: |
| 6629 | likely = 1; |
| 6630 | case M_BGTU_I: |
| 6631 | if (sreg == 0 |
| 6632 | || (HAVE_32BIT_GPRS |
| 6633 | && imm_expr.X_op == O_constant |
| 6634 | && imm_expr.X_add_number == -1)) |
| 6635 | goto do_false; |
| 6636 | if (imm_expr.X_op != O_constant) |
| 6637 | as_bad (_("Unsupported large constant")); |
| 6638 | ++imm_expr.X_add_number; |
| 6639 | /* FALLTHROUGH */ |
| 6640 | case M_BGEU_I: |
| 6641 | case M_BGEUL_I: |
| 6642 | if (mask == M_BGEUL_I) |
| 6643 | likely = 1; |
| 6644 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
| 6645 | goto do_true; |
| 6646 | else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) |
| 6647 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6648 | &offset_expr, sreg, ZERO); |
| 6649 | else |
| 6650 | { |
| 6651 | used_at = 1; |
| 6652 | set_at (sreg, 1); |
| 6653 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6654 | &offset_expr, AT, ZERO); |
| 6655 | } |
| 6656 | break; |
| 6657 | |
| 6658 | case M_BGTL: |
| 6659 | likely = 1; |
| 6660 | case M_BGT: |
| 6661 | if (treg == 0) |
| 6662 | macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, sreg); |
| 6663 | else if (sreg == 0) |
| 6664 | macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, treg); |
| 6665 | else |
| 6666 | { |
| 6667 | used_at = 1; |
| 6668 | macro_build (NULL, "slt", "d,v,t", AT, treg, sreg); |
| 6669 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6670 | &offset_expr, AT, ZERO); |
| 6671 | } |
| 6672 | break; |
| 6673 | |
| 6674 | case M_BGTUL: |
| 6675 | likely = 1; |
| 6676 | case M_BGTU: |
| 6677 | if (treg == 0) |
| 6678 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6679 | &offset_expr, sreg, ZERO); |
| 6680 | else if (sreg == 0) |
| 6681 | goto do_false; |
| 6682 | else |
| 6683 | { |
| 6684 | used_at = 1; |
| 6685 | macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg); |
| 6686 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6687 | &offset_expr, AT, ZERO); |
| 6688 | } |
| 6689 | break; |
| 6690 | |
| 6691 | case M_BLEL: |
| 6692 | likely = 1; |
| 6693 | case M_BLE: |
| 6694 | if (treg == 0) |
| 6695 | macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg); |
| 6696 | else if (sreg == 0) |
| 6697 | macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, treg); |
| 6698 | else |
| 6699 | { |
| 6700 | used_at = 1; |
| 6701 | macro_build (NULL, "slt", "d,v,t", AT, treg, sreg); |
| 6702 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6703 | &offset_expr, AT, ZERO); |
| 6704 | } |
| 6705 | break; |
| 6706 | |
| 6707 | case M_BLEL_I: |
| 6708 | likely = 1; |
| 6709 | case M_BLE_I: |
| 6710 | maxnum = 0x7fffffff; |
| 6711 | if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4) |
| 6712 | { |
| 6713 | maxnum <<= 16; |
| 6714 | maxnum |= 0xffff; |
| 6715 | maxnum <<= 16; |
| 6716 | maxnum |= 0xffff; |
| 6717 | } |
| 6718 | if (imm_expr.X_op == O_constant |
| 6719 | && imm_expr.X_add_number >= maxnum |
| 6720 | && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4)) |
| 6721 | goto do_true; |
| 6722 | if (imm_expr.X_op != O_constant) |
| 6723 | as_bad (_("Unsupported large constant")); |
| 6724 | ++imm_expr.X_add_number; |
| 6725 | /* FALLTHROUGH */ |
| 6726 | case M_BLT_I: |
| 6727 | case M_BLTL_I: |
| 6728 | if (mask == M_BLTL_I) |
| 6729 | likely = 1; |
| 6730 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
| 6731 | macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg); |
| 6732 | else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) |
| 6733 | macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg); |
| 6734 | else |
| 6735 | { |
| 6736 | used_at = 1; |
| 6737 | set_at (sreg, 0); |
| 6738 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6739 | &offset_expr, AT, ZERO); |
| 6740 | } |
| 6741 | break; |
| 6742 | |
| 6743 | case M_BLEUL: |
| 6744 | likely = 1; |
| 6745 | case M_BLEU: |
| 6746 | if (treg == 0) |
| 6747 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6748 | &offset_expr, sreg, ZERO); |
| 6749 | else if (sreg == 0) |
| 6750 | goto do_true; |
| 6751 | else |
| 6752 | { |
| 6753 | used_at = 1; |
| 6754 | macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg); |
| 6755 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6756 | &offset_expr, AT, ZERO); |
| 6757 | } |
| 6758 | break; |
| 6759 | |
| 6760 | case M_BLEUL_I: |
| 6761 | likely = 1; |
| 6762 | case M_BLEU_I: |
| 6763 | if (sreg == 0 |
| 6764 | || (HAVE_32BIT_GPRS |
| 6765 | && imm_expr.X_op == O_constant |
| 6766 | && imm_expr.X_add_number == -1)) |
| 6767 | goto do_true; |
| 6768 | if (imm_expr.X_op != O_constant) |
| 6769 | as_bad (_("Unsupported large constant")); |
| 6770 | ++imm_expr.X_add_number; |
| 6771 | /* FALLTHROUGH */ |
| 6772 | case M_BLTU_I: |
| 6773 | case M_BLTUL_I: |
| 6774 | if (mask == M_BLTUL_I) |
| 6775 | likely = 1; |
| 6776 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
| 6777 | goto do_false; |
| 6778 | else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) |
| 6779 | macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ, |
| 6780 | &offset_expr, sreg, ZERO); |
| 6781 | else |
| 6782 | { |
| 6783 | used_at = 1; |
| 6784 | set_at (sreg, 1); |
| 6785 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6786 | &offset_expr, AT, ZERO); |
| 6787 | } |
| 6788 | break; |
| 6789 | |
| 6790 | case M_BLTL: |
| 6791 | likely = 1; |
| 6792 | case M_BLT: |
| 6793 | if (treg == 0) |
| 6794 | macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg); |
| 6795 | else if (sreg == 0) |
| 6796 | macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, treg); |
| 6797 | else |
| 6798 | { |
| 6799 | used_at = 1; |
| 6800 | macro_build (NULL, "slt", "d,v,t", AT, sreg, treg); |
| 6801 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6802 | &offset_expr, AT, ZERO); |
| 6803 | } |
| 6804 | break; |
| 6805 | |
| 6806 | case M_BLTUL: |
| 6807 | likely = 1; |
| 6808 | case M_BLTU: |
| 6809 | if (treg == 0) |
| 6810 | goto do_false; |
| 6811 | else if (sreg == 0) |
| 6812 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6813 | &offset_expr, ZERO, treg); |
| 6814 | else |
| 6815 | { |
| 6816 | used_at = 1; |
| 6817 | macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg); |
| 6818 | macro_build_branch_rsrt (likely ? M_BNEL : M_BNE, |
| 6819 | &offset_expr, AT, ZERO); |
| 6820 | } |
| 6821 | break; |
| 6822 | |
| 6823 | case M_DEXT: |
| 6824 | { |
| 6825 | /* Use unsigned arithmetic. */ |
| 6826 | addressT pos; |
| 6827 | addressT size; |
| 6828 | |
| 6829 | if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant) |
| 6830 | { |
| 6831 | as_bad (_("Unsupported large constant")); |
| 6832 | pos = size = 1; |
| 6833 | } |
| 6834 | else |
| 6835 | { |
| 6836 | pos = imm_expr.X_add_number; |
| 6837 | size = imm2_expr.X_add_number; |
| 6838 | } |
| 6839 | |
| 6840 | if (pos > 63) |
| 6841 | { |
| 6842 | as_bad (_("Improper position (%lu)"), (unsigned long) pos); |
| 6843 | pos = 1; |
| 6844 | } |
| 6845 | if (size == 0 || size > 64 || (pos + size - 1) > 63) |
| 6846 | { |
| 6847 | as_bad (_("Improper extract size (%lu, position %lu)"), |
| 6848 | (unsigned long) size, (unsigned long) pos); |
| 6849 | size = 1; |
| 6850 | } |
| 6851 | |
| 6852 | if (size <= 32 && pos < 32) |
| 6853 | { |
| 6854 | s = "dext"; |
| 6855 | fmt = "t,r,+A,+C"; |
| 6856 | } |
| 6857 | else if (size <= 32) |
| 6858 | { |
| 6859 | s = "dextu"; |
| 6860 | fmt = "t,r,+E,+H"; |
| 6861 | } |
| 6862 | else |
| 6863 | { |
| 6864 | s = "dextm"; |
| 6865 | fmt = "t,r,+A,+G"; |
| 6866 | } |
| 6867 | macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos, |
| 6868 | (int) (size - 1)); |
| 6869 | } |
| 6870 | break; |
| 6871 | |
| 6872 | case M_DINS: |
| 6873 | { |
| 6874 | /* Use unsigned arithmetic. */ |
| 6875 | addressT pos; |
| 6876 | addressT size; |
| 6877 | |
| 6878 | if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant) |
| 6879 | { |
| 6880 | as_bad (_("Unsupported large constant")); |
| 6881 | pos = size = 1; |
| 6882 | } |
| 6883 | else |
| 6884 | { |
| 6885 | pos = imm_expr.X_add_number; |
| 6886 | size = imm2_expr.X_add_number; |
| 6887 | } |
| 6888 | |
| 6889 | if (pos > 63) |
| 6890 | { |
| 6891 | as_bad (_("Improper position (%lu)"), (unsigned long) pos); |
| 6892 | pos = 1; |
| 6893 | } |
| 6894 | if (size == 0 || size > 64 || (pos + size - 1) > 63) |
| 6895 | { |
| 6896 | as_bad (_("Improper insert size (%lu, position %lu)"), |
| 6897 | (unsigned long) size, (unsigned long) pos); |
| 6898 | size = 1; |
| 6899 | } |
| 6900 | |
| 6901 | if (pos < 32 && (pos + size - 1) < 32) |
| 6902 | { |
| 6903 | s = "dins"; |
| 6904 | fmt = "t,r,+A,+B"; |
| 6905 | } |
| 6906 | else if (pos >= 32) |
| 6907 | { |
| 6908 | s = "dinsu"; |
| 6909 | fmt = "t,r,+E,+F"; |
| 6910 | } |
| 6911 | else |
| 6912 | { |
| 6913 | s = "dinsm"; |
| 6914 | fmt = "t,r,+A,+F"; |
| 6915 | } |
| 6916 | macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos, |
| 6917 | (int) (pos + size - 1)); |
| 6918 | } |
| 6919 | break; |
| 6920 | |
| 6921 | case M_DDIV_3: |
| 6922 | dbl = 1; |
| 6923 | case M_DIV_3: |
| 6924 | s = "mflo"; |
| 6925 | goto do_div3; |
| 6926 | case M_DREM_3: |
| 6927 | dbl = 1; |
| 6928 | case M_REM_3: |
| 6929 | s = "mfhi"; |
| 6930 | do_div3: |
| 6931 | if (treg == 0) |
| 6932 | { |
| 6933 | as_warn (_("Divide by zero.")); |
| 6934 | if (mips_trap) |
| 6935 | macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7); |
| 6936 | else |
| 6937 | macro_build (NULL, "break", BRK_FMT, 7); |
| 6938 | break; |
| 6939 | } |
| 6940 | |
| 6941 | start_noreorder (); |
| 6942 | if (mips_trap) |
| 6943 | { |
| 6944 | macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7); |
| 6945 | macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
| 6946 | } |
| 6947 | else |
| 6948 | { |
| 6949 | if (mips_opts.micromips) |
| 6950 | micromips_label_expr (&label_expr); |
| 6951 | else |
| 6952 | label_expr.X_add_number = 8; |
| 6953 | macro_build (&label_expr, "bne", "s,t,p", treg, ZERO); |
| 6954 | macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg); |
| 6955 | macro_build (NULL, "break", BRK_FMT, 7); |
| 6956 | if (mips_opts.micromips) |
| 6957 | micromips_add_label (); |
| 6958 | } |
| 6959 | expr1.X_add_number = -1; |
| 6960 | used_at = 1; |
| 6961 | load_register (AT, &expr1, dbl); |
| 6962 | if (mips_opts.micromips) |
| 6963 | micromips_label_expr (&label_expr); |
| 6964 | else |
| 6965 | label_expr.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16); |
| 6966 | macro_build (&label_expr, "bne", "s,t,p", treg, AT); |
| 6967 | if (dbl) |
| 6968 | { |
| 6969 | expr1.X_add_number = 1; |
| 6970 | load_register (AT, &expr1, dbl); |
| 6971 | macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31); |
| 6972 | } |
| 6973 | else |
| 6974 | { |
| 6975 | expr1.X_add_number = 0x80000000; |
| 6976 | macro_build (&expr1, "lui", LUI_FMT, AT, BFD_RELOC_HI16); |
| 6977 | } |
| 6978 | if (mips_trap) |
| 6979 | { |
| 6980 | macro_build (NULL, "teq", TRAP_FMT, sreg, AT, 6); |
| 6981 | /* We want to close the noreorder block as soon as possible, so |
| 6982 | that later insns are available for delay slot filling. */ |
| 6983 | end_noreorder (); |
| 6984 | } |
| 6985 | else |
| 6986 | { |
| 6987 | if (mips_opts.micromips) |
| 6988 | micromips_label_expr (&label_expr); |
| 6989 | else |
| 6990 | label_expr.X_add_number = 8; |
| 6991 | macro_build (&label_expr, "bne", "s,t,p", sreg, AT); |
| 6992 | macro_build (NULL, "nop", ""); |
| 6993 | |
| 6994 | /* We want to close the noreorder block as soon as possible, so |
| 6995 | that later insns are available for delay slot filling. */ |
| 6996 | end_noreorder (); |
| 6997 | |
| 6998 | macro_build (NULL, "break", BRK_FMT, 6); |
| 6999 | } |
| 7000 | if (mips_opts.micromips) |
| 7001 | micromips_add_label (); |
| 7002 | macro_build (NULL, s, MFHL_FMT, dreg); |
| 7003 | break; |
| 7004 | |
| 7005 | case M_DIV_3I: |
| 7006 | s = "div"; |
| 7007 | s2 = "mflo"; |
| 7008 | goto do_divi; |
| 7009 | case M_DIVU_3I: |
| 7010 | s = "divu"; |
| 7011 | s2 = "mflo"; |
| 7012 | goto do_divi; |
| 7013 | case M_REM_3I: |
| 7014 | s = "div"; |
| 7015 | s2 = "mfhi"; |
| 7016 | goto do_divi; |
| 7017 | case M_REMU_3I: |
| 7018 | s = "divu"; |
| 7019 | s2 = "mfhi"; |
| 7020 | goto do_divi; |
| 7021 | case M_DDIV_3I: |
| 7022 | dbl = 1; |
| 7023 | s = "ddiv"; |
| 7024 | s2 = "mflo"; |
| 7025 | goto do_divi; |
| 7026 | case M_DDIVU_3I: |
| 7027 | dbl = 1; |
| 7028 | s = "ddivu"; |
| 7029 | s2 = "mflo"; |
| 7030 | goto do_divi; |
| 7031 | case M_DREM_3I: |
| 7032 | dbl = 1; |
| 7033 | s = "ddiv"; |
| 7034 | s2 = "mfhi"; |
| 7035 | goto do_divi; |
| 7036 | case M_DREMU_3I: |
| 7037 | dbl = 1; |
| 7038 | s = "ddivu"; |
| 7039 | s2 = "mfhi"; |
| 7040 | do_divi: |
| 7041 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
| 7042 | { |
| 7043 | as_warn (_("Divide by zero.")); |
| 7044 | if (mips_trap) |
| 7045 | macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7); |
| 7046 | else |
| 7047 | macro_build (NULL, "break", BRK_FMT, 7); |
| 7048 | break; |
| 7049 | } |
| 7050 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1) |
| 7051 | { |
| 7052 | if (strcmp (s2, "mflo") == 0) |
| 7053 | move_register (dreg, sreg); |
| 7054 | else |
| 7055 | move_register (dreg, ZERO); |
| 7056 | break; |
| 7057 | } |
| 7058 | if (imm_expr.X_op == O_constant |
| 7059 | && imm_expr.X_add_number == -1 |
| 7060 | && s[strlen (s) - 1] != 'u') |
| 7061 | { |
| 7062 | if (strcmp (s2, "mflo") == 0) |
| 7063 | { |
| 7064 | macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg); |
| 7065 | } |
| 7066 | else |
| 7067 | move_register (dreg, ZERO); |
| 7068 | break; |
| 7069 | } |
| 7070 | |
| 7071 | used_at = 1; |
| 7072 | load_register (AT, &imm_expr, dbl); |
| 7073 | macro_build (NULL, s, "z,s,t", sreg, AT); |
| 7074 | macro_build (NULL, s2, MFHL_FMT, dreg); |
| 7075 | break; |
| 7076 | |
| 7077 | case M_DIVU_3: |
| 7078 | s = "divu"; |
| 7079 | s2 = "mflo"; |
| 7080 | goto do_divu3; |
| 7081 | case M_REMU_3: |
| 7082 | s = "divu"; |
| 7083 | s2 = "mfhi"; |
| 7084 | goto do_divu3; |
| 7085 | case M_DDIVU_3: |
| 7086 | s = "ddivu"; |
| 7087 | s2 = "mflo"; |
| 7088 | goto do_divu3; |
| 7089 | case M_DREMU_3: |
| 7090 | s = "ddivu"; |
| 7091 | s2 = "mfhi"; |
| 7092 | do_divu3: |
| 7093 | start_noreorder (); |
| 7094 | if (mips_trap) |
| 7095 | { |
| 7096 | macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7); |
| 7097 | macro_build (NULL, s, "z,s,t", sreg, treg); |
| 7098 | /* We want to close the noreorder block as soon as possible, so |
| 7099 | that later insns are available for delay slot filling. */ |
| 7100 | end_noreorder (); |
| 7101 | } |
| 7102 | else |
| 7103 | { |
| 7104 | if (mips_opts.micromips) |
| 7105 | micromips_label_expr (&label_expr); |
| 7106 | else |
| 7107 | label_expr.X_add_number = 8; |
| 7108 | macro_build (&label_expr, "bne", "s,t,p", treg, ZERO); |
| 7109 | macro_build (NULL, s, "z,s,t", sreg, treg); |
| 7110 | |
| 7111 | /* We want to close the noreorder block as soon as possible, so |
| 7112 | that later insns are available for delay slot filling. */ |
| 7113 | end_noreorder (); |
| 7114 | macro_build (NULL, "break", BRK_FMT, 7); |
| 7115 | if (mips_opts.micromips) |
| 7116 | micromips_add_label (); |
| 7117 | } |
| 7118 | macro_build (NULL, s2, MFHL_FMT, dreg); |
| 7119 | break; |
| 7120 | |
| 7121 | case M_DLCA_AB: |
| 7122 | dbl = 1; |
| 7123 | case M_LCA_AB: |
| 7124 | call = 1; |
| 7125 | goto do_la; |
| 7126 | case M_DLA_AB: |
| 7127 | dbl = 1; |
| 7128 | case M_LA_AB: |
| 7129 | do_la: |
| 7130 | /* Load the address of a symbol into a register. If breg is not |
| 7131 | zero, we then add a base register to it. */ |
| 7132 | |
| 7133 | if (dbl && HAVE_32BIT_GPRS) |
| 7134 | as_warn (_("dla used to load 32-bit register")); |
| 7135 | |
| 7136 | if (!dbl && HAVE_64BIT_OBJECTS) |
| 7137 | as_warn (_("la used to load 64-bit address")); |
| 7138 | |
| 7139 | if (offset_expr.X_op == O_constant |
| 7140 | && offset_expr.X_add_number >= -0x8000 |
| 7141 | && offset_expr.X_add_number < 0x8000) |
| 7142 | { |
| 7143 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, |
| 7144 | "t,r,j", treg, sreg, BFD_RELOC_LO16); |
| 7145 | break; |
| 7146 | } |
| 7147 | |
| 7148 | if (mips_opts.at && (treg == breg)) |
| 7149 | { |
| 7150 | tempreg = AT; |
| 7151 | used_at = 1; |
| 7152 | } |
| 7153 | else |
| 7154 | { |
| 7155 | tempreg = treg; |
| 7156 | } |
| 7157 | |
| 7158 | if (offset_expr.X_op != O_symbol |
| 7159 | && offset_expr.X_op != O_constant) |
| 7160 | { |
| 7161 | as_bad (_("Expression too complex")); |
| 7162 | offset_expr.X_op = O_constant; |
| 7163 | } |
| 7164 | |
| 7165 | if (offset_expr.X_op == O_constant) |
| 7166 | load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES); |
| 7167 | else if (mips_pic == NO_PIC) |
| 7168 | { |
| 7169 | /* If this is a reference to a GP relative symbol, we want |
| 7170 | addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16) |
| 7171 | Otherwise we want |
| 7172 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) |
| 7173 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) |
| 7174 | If we have a constant, we need two instructions anyhow, |
| 7175 | so we may as well always use the latter form. |
| 7176 | |
| 7177 | With 64bit address space and a usable $at we want |
| 7178 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) |
| 7179 | lui $at,<sym> (BFD_RELOC_HI16_S) |
| 7180 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) |
| 7181 | daddiu $at,<sym> (BFD_RELOC_LO16) |
| 7182 | dsll32 $tempreg,0 |
| 7183 | daddu $tempreg,$tempreg,$at |
| 7184 | |
| 7185 | If $at is already in use, we use a path which is suboptimal |
| 7186 | on superscalar processors. |
| 7187 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) |
| 7188 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) |
| 7189 | dsll $tempreg,16 |
| 7190 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) |
| 7191 | dsll $tempreg,16 |
| 7192 | daddiu $tempreg,<sym> (BFD_RELOC_LO16) |
| 7193 | |
| 7194 | For GP relative symbols in 64bit address space we can use |
| 7195 | the same sequence as in 32bit address space. */ |
| 7196 | if (HAVE_64BIT_SYMBOLS) |
| 7197 | { |
| 7198 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
| 7199 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
| 7200 | { |
| 7201 | relax_start (offset_expr.X_add_symbol); |
| 7202 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 7203 | tempreg, mips_gp_register, BFD_RELOC_GPREL16); |
| 7204 | relax_switch (); |
| 7205 | } |
| 7206 | |
| 7207 | if (used_at == 0 && mips_opts.at) |
| 7208 | { |
| 7209 | macro_build (&offset_expr, "lui", LUI_FMT, |
| 7210 | tempreg, BFD_RELOC_MIPS_HIGHEST); |
| 7211 | macro_build (&offset_expr, "lui", LUI_FMT, |
| 7212 | AT, BFD_RELOC_HI16_S); |
| 7213 | macro_build (&offset_expr, "daddiu", "t,r,j", |
| 7214 | tempreg, tempreg, BFD_RELOC_MIPS_HIGHER); |
| 7215 | macro_build (&offset_expr, "daddiu", "t,r,j", |
| 7216 | AT, AT, BFD_RELOC_LO16); |
| 7217 | macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0); |
| 7218 | macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT); |
| 7219 | used_at = 1; |
| 7220 | } |
| 7221 | else |
| 7222 | { |
| 7223 | macro_build (&offset_expr, "lui", LUI_FMT, |
| 7224 | tempreg, BFD_RELOC_MIPS_HIGHEST); |
| 7225 | macro_build (&offset_expr, "daddiu", "t,r,j", |
| 7226 | tempreg, tempreg, BFD_RELOC_MIPS_HIGHER); |
| 7227 | macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16); |
| 7228 | macro_build (&offset_expr, "daddiu", "t,r,j", |
| 7229 | tempreg, tempreg, BFD_RELOC_HI16_S); |
| 7230 | macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16); |
| 7231 | macro_build (&offset_expr, "daddiu", "t,r,j", |
| 7232 | tempreg, tempreg, BFD_RELOC_LO16); |
| 7233 | } |
| 7234 | |
| 7235 | if (mips_relax.sequence) |
| 7236 | relax_end (); |
| 7237 | } |
| 7238 | else |
| 7239 | { |
| 7240 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
| 7241 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
| 7242 | { |
| 7243 | relax_start (offset_expr.X_add_symbol); |
| 7244 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 7245 | tempreg, mips_gp_register, BFD_RELOC_GPREL16); |
| 7246 | relax_switch (); |
| 7247 | } |
| 7248 | if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number)) |
| 7249 | as_bad (_("Offset too large")); |
| 7250 | macro_build_lui (&offset_expr, tempreg); |
| 7251 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 7252 | tempreg, tempreg, BFD_RELOC_LO16); |
| 7253 | if (mips_relax.sequence) |
| 7254 | relax_end (); |
| 7255 | } |
| 7256 | } |
| 7257 | else if (!mips_big_got && !HAVE_NEWABI) |
| 7258 | { |
| 7259 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
| 7260 | |
| 7261 | /* If this is a reference to an external symbol, and there |
| 7262 | is no constant, we want |
| 7263 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 7264 | or for lca or if tempreg is PIC_CALL_REG |
| 7265 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16) |
| 7266 | For a local symbol, we want |
| 7267 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 7268 | nop |
| 7269 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) |
| 7270 | |
| 7271 | If we have a small constant, and this is a reference to |
| 7272 | an external symbol, we want |
| 7273 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 7274 | nop |
| 7275 | addiu $tempreg,$tempreg,<constant> |
| 7276 | For a local symbol, we want the same instruction |
| 7277 | sequence, but we output a BFD_RELOC_LO16 reloc on the |
| 7278 | addiu instruction. |
| 7279 | |
| 7280 | If we have a large constant, and this is a reference to |
| 7281 | an external symbol, we want |
| 7282 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 7283 | lui $at,<hiconstant> |
| 7284 | addiu $at,$at,<loconstant> |
| 7285 | addu $tempreg,$tempreg,$at |
| 7286 | For a local symbol, we want the same instruction |
| 7287 | sequence, but we output a BFD_RELOC_LO16 reloc on the |
| 7288 | addiu instruction. |
| 7289 | */ |
| 7290 | |
| 7291 | if (offset_expr.X_add_number == 0) |
| 7292 | { |
| 7293 | if (mips_pic == SVR4_PIC |
| 7294 | && breg == 0 |
| 7295 | && (call || tempreg == PIC_CALL_REG)) |
| 7296 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16; |
| 7297 | |
| 7298 | relax_start (offset_expr.X_add_symbol); |
| 7299 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 7300 | lw_reloc_type, mips_gp_register); |
| 7301 | if (breg != 0) |
| 7302 | { |
| 7303 | /* We're going to put in an addu instruction using |
| 7304 | tempreg, so we may as well insert the nop right |
| 7305 | now. */ |
| 7306 | load_delay_nop (); |
| 7307 | } |
| 7308 | relax_switch (); |
| 7309 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7310 | tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 7311 | load_delay_nop (); |
| 7312 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 7313 | tempreg, tempreg, BFD_RELOC_LO16); |
| 7314 | relax_end (); |
| 7315 | /* FIXME: If breg == 0, and the next instruction uses |
| 7316 | $tempreg, then if this variant case is used an extra |
| 7317 | nop will be generated. */ |
| 7318 | } |
| 7319 | else if (offset_expr.X_add_number >= -0x8000 |
| 7320 | && offset_expr.X_add_number < 0x8000) |
| 7321 | { |
| 7322 | load_got_offset (tempreg, &offset_expr); |
| 7323 | load_delay_nop (); |
| 7324 | add_got_offset (tempreg, &offset_expr); |
| 7325 | } |
| 7326 | else |
| 7327 | { |
| 7328 | expr1.X_add_number = offset_expr.X_add_number; |
| 7329 | offset_expr.X_add_number = |
| 7330 | SEXT_16BIT (offset_expr.X_add_number); |
| 7331 | load_got_offset (tempreg, &offset_expr); |
| 7332 | offset_expr.X_add_number = expr1.X_add_number; |
| 7333 | /* If we are going to add in a base register, and the |
| 7334 | target register and the base register are the same, |
| 7335 | then we are using AT as a temporary register. Since |
| 7336 | we want to load the constant into AT, we add our |
| 7337 | current AT (from the global offset table) and the |
| 7338 | register into the register now, and pretend we were |
| 7339 | not using a base register. */ |
| 7340 | if (breg == treg) |
| 7341 | { |
| 7342 | load_delay_nop (); |
| 7343 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7344 | treg, AT, breg); |
| 7345 | breg = 0; |
| 7346 | tempreg = treg; |
| 7347 | } |
| 7348 | add_got_offset_hilo (tempreg, &offset_expr, AT); |
| 7349 | used_at = 1; |
| 7350 | } |
| 7351 | } |
| 7352 | else if (!mips_big_got && HAVE_NEWABI) |
| 7353 | { |
| 7354 | int add_breg_early = 0; |
| 7355 | |
| 7356 | /* If this is a reference to an external, and there is no |
| 7357 | constant, or local symbol (*), with or without a |
| 7358 | constant, we want |
| 7359 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) |
| 7360 | or for lca or if tempreg is PIC_CALL_REG |
| 7361 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16) |
| 7362 | |
| 7363 | If we have a small constant, and this is a reference to |
| 7364 | an external symbol, we want |
| 7365 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) |
| 7366 | addiu $tempreg,$tempreg,<constant> |
| 7367 | |
| 7368 | If we have a large constant, and this is a reference to |
| 7369 | an external symbol, we want |
| 7370 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP) |
| 7371 | lui $at,<hiconstant> |
| 7372 | addiu $at,$at,<loconstant> |
| 7373 | addu $tempreg,$tempreg,$at |
| 7374 | |
| 7375 | (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for |
| 7376 | local symbols, even though it introduces an additional |
| 7377 | instruction. */ |
| 7378 | |
| 7379 | if (offset_expr.X_add_number) |
| 7380 | { |
| 7381 | expr1.X_add_number = offset_expr.X_add_number; |
| 7382 | offset_expr.X_add_number = 0; |
| 7383 | |
| 7384 | relax_start (offset_expr.X_add_symbol); |
| 7385 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 7386 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); |
| 7387 | |
| 7388 | if (expr1.X_add_number >= -0x8000 |
| 7389 | && expr1.X_add_number < 0x8000) |
| 7390 | { |
| 7391 | macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j", |
| 7392 | tempreg, tempreg, BFD_RELOC_LO16); |
| 7393 | } |
| 7394 | else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000)) |
| 7395 | { |
| 7396 | /* If we are going to add in a base register, and the |
| 7397 | target register and the base register are the same, |
| 7398 | then we are using AT as a temporary register. Since |
| 7399 | we want to load the constant into AT, we add our |
| 7400 | current AT (from the global offset table) and the |
| 7401 | register into the register now, and pretend we were |
| 7402 | not using a base register. */ |
| 7403 | if (breg != treg) |
| 7404 | dreg = tempreg; |
| 7405 | else |
| 7406 | { |
| 7407 | gas_assert (tempreg == AT); |
| 7408 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7409 | treg, AT, breg); |
| 7410 | dreg = treg; |
| 7411 | add_breg_early = 1; |
| 7412 | } |
| 7413 | |
| 7414 | load_register (AT, &expr1, HAVE_64BIT_ADDRESSES); |
| 7415 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7416 | dreg, dreg, AT); |
| 7417 | |
| 7418 | used_at = 1; |
| 7419 | } |
| 7420 | else |
| 7421 | as_bad (_("PIC code offset overflow (max 32 signed bits)")); |
| 7422 | |
| 7423 | relax_switch (); |
| 7424 | offset_expr.X_add_number = expr1.X_add_number; |
| 7425 | |
| 7426 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 7427 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); |
| 7428 | if (add_breg_early) |
| 7429 | { |
| 7430 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7431 | treg, tempreg, breg); |
| 7432 | breg = 0; |
| 7433 | tempreg = treg; |
| 7434 | } |
| 7435 | relax_end (); |
| 7436 | } |
| 7437 | else if (breg == 0 && (call || tempreg == PIC_CALL_REG)) |
| 7438 | { |
| 7439 | relax_start (offset_expr.X_add_symbol); |
| 7440 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 7441 | BFD_RELOC_MIPS_CALL16, mips_gp_register); |
| 7442 | relax_switch (); |
| 7443 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 7444 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); |
| 7445 | relax_end (); |
| 7446 | } |
| 7447 | else |
| 7448 | { |
| 7449 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 7450 | BFD_RELOC_MIPS_GOT_DISP, mips_gp_register); |
| 7451 | } |
| 7452 | } |
| 7453 | else if (mips_big_got && !HAVE_NEWABI) |
| 7454 | { |
| 7455 | int gpdelay; |
| 7456 | int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16; |
| 7457 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16; |
| 7458 | int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
| 7459 | |
| 7460 | /* This is the large GOT case. If this is a reference to an |
| 7461 | external symbol, and there is no constant, we want |
| 7462 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 7463 | addu $tempreg,$tempreg,$gp |
| 7464 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) |
| 7465 | or for lca or if tempreg is PIC_CALL_REG |
| 7466 | lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16) |
| 7467 | addu $tempreg,$tempreg,$gp |
| 7468 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16) |
| 7469 | For a local symbol, we want |
| 7470 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 7471 | nop |
| 7472 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) |
| 7473 | |
| 7474 | If we have a small constant, and this is a reference to |
| 7475 | an external symbol, we want |
| 7476 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 7477 | addu $tempreg,$tempreg,$gp |
| 7478 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) |
| 7479 | nop |
| 7480 | addiu $tempreg,$tempreg,<constant> |
| 7481 | For a local symbol, we want |
| 7482 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 7483 | nop |
| 7484 | addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16) |
| 7485 | |
| 7486 | If we have a large constant, and this is a reference to |
| 7487 | an external symbol, we want |
| 7488 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 7489 | addu $tempreg,$tempreg,$gp |
| 7490 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) |
| 7491 | lui $at,<hiconstant> |
| 7492 | addiu $at,$at,<loconstant> |
| 7493 | addu $tempreg,$tempreg,$at |
| 7494 | For a local symbol, we want |
| 7495 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 7496 | lui $at,<hiconstant> |
| 7497 | addiu $at,$at,<loconstant> (BFD_RELOC_LO16) |
| 7498 | addu $tempreg,$tempreg,$at |
| 7499 | */ |
| 7500 | |
| 7501 | expr1.X_add_number = offset_expr.X_add_number; |
| 7502 | offset_expr.X_add_number = 0; |
| 7503 | relax_start (offset_expr.X_add_symbol); |
| 7504 | gpdelay = reg_needs_delay (mips_gp_register); |
| 7505 | if (expr1.X_add_number == 0 && breg == 0 |
| 7506 | && (call || tempreg == PIC_CALL_REG)) |
| 7507 | { |
| 7508 | lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16; |
| 7509 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16; |
| 7510 | } |
| 7511 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type); |
| 7512 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7513 | tempreg, tempreg, mips_gp_register); |
| 7514 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7515 | tempreg, lw_reloc_type, tempreg); |
| 7516 | if (expr1.X_add_number == 0) |
| 7517 | { |
| 7518 | if (breg != 0) |
| 7519 | { |
| 7520 | /* We're going to put in an addu instruction using |
| 7521 | tempreg, so we may as well insert the nop right |
| 7522 | now. */ |
| 7523 | load_delay_nop (); |
| 7524 | } |
| 7525 | } |
| 7526 | else if (expr1.X_add_number >= -0x8000 |
| 7527 | && expr1.X_add_number < 0x8000) |
| 7528 | { |
| 7529 | load_delay_nop (); |
| 7530 | macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j", |
| 7531 | tempreg, tempreg, BFD_RELOC_LO16); |
| 7532 | } |
| 7533 | else |
| 7534 | { |
| 7535 | /* If we are going to add in a base register, and the |
| 7536 | target register and the base register are the same, |
| 7537 | then we are using AT as a temporary register. Since |
| 7538 | we want to load the constant into AT, we add our |
| 7539 | current AT (from the global offset table) and the |
| 7540 | register into the register now, and pretend we were |
| 7541 | not using a base register. */ |
| 7542 | if (breg != treg) |
| 7543 | dreg = tempreg; |
| 7544 | else |
| 7545 | { |
| 7546 | gas_assert (tempreg == AT); |
| 7547 | load_delay_nop (); |
| 7548 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7549 | treg, AT, breg); |
| 7550 | dreg = treg; |
| 7551 | } |
| 7552 | |
| 7553 | load_register (AT, &expr1, HAVE_64BIT_ADDRESSES); |
| 7554 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT); |
| 7555 | |
| 7556 | used_at = 1; |
| 7557 | } |
| 7558 | offset_expr.X_add_number = SEXT_16BIT (expr1.X_add_number); |
| 7559 | relax_switch (); |
| 7560 | |
| 7561 | if (gpdelay) |
| 7562 | { |
| 7563 | /* This is needed because this instruction uses $gp, but |
| 7564 | the first instruction on the main stream does not. */ |
| 7565 | macro_build (NULL, "nop", ""); |
| 7566 | } |
| 7567 | |
| 7568 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 7569 | local_reloc_type, mips_gp_register); |
| 7570 | if (expr1.X_add_number >= -0x8000 |
| 7571 | && expr1.X_add_number < 0x8000) |
| 7572 | { |
| 7573 | load_delay_nop (); |
| 7574 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 7575 | tempreg, tempreg, BFD_RELOC_LO16); |
| 7576 | /* FIXME: If add_number is 0, and there was no base |
| 7577 | register, the external symbol case ended with a load, |
| 7578 | so if the symbol turns out to not be external, and |
| 7579 | the next instruction uses tempreg, an unnecessary nop |
| 7580 | will be inserted. */ |
| 7581 | } |
| 7582 | else |
| 7583 | { |
| 7584 | if (breg == treg) |
| 7585 | { |
| 7586 | /* We must add in the base register now, as in the |
| 7587 | external symbol case. */ |
| 7588 | gas_assert (tempreg == AT); |
| 7589 | load_delay_nop (); |
| 7590 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7591 | treg, AT, breg); |
| 7592 | tempreg = treg; |
| 7593 | /* We set breg to 0 because we have arranged to add |
| 7594 | it in in both cases. */ |
| 7595 | breg = 0; |
| 7596 | } |
| 7597 | |
| 7598 | macro_build_lui (&expr1, AT); |
| 7599 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 7600 | AT, AT, BFD_RELOC_LO16); |
| 7601 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7602 | tempreg, tempreg, AT); |
| 7603 | used_at = 1; |
| 7604 | } |
| 7605 | relax_end (); |
| 7606 | } |
| 7607 | else if (mips_big_got && HAVE_NEWABI) |
| 7608 | { |
| 7609 | int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16; |
| 7610 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16; |
| 7611 | int add_breg_early = 0; |
| 7612 | |
| 7613 | /* This is the large GOT case. If this is a reference to an |
| 7614 | external symbol, and there is no constant, we want |
| 7615 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 7616 | add $tempreg,$tempreg,$gp |
| 7617 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) |
| 7618 | or for lca or if tempreg is PIC_CALL_REG |
| 7619 | lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16) |
| 7620 | add $tempreg,$tempreg,$gp |
| 7621 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16) |
| 7622 | |
| 7623 | If we have a small constant, and this is a reference to |
| 7624 | an external symbol, we want |
| 7625 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 7626 | add $tempreg,$tempreg,$gp |
| 7627 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) |
| 7628 | addi $tempreg,$tempreg,<constant> |
| 7629 | |
| 7630 | If we have a large constant, and this is a reference to |
| 7631 | an external symbol, we want |
| 7632 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 7633 | addu $tempreg,$tempreg,$gp |
| 7634 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) |
| 7635 | lui $at,<hiconstant> |
| 7636 | addi $at,$at,<loconstant> |
| 7637 | add $tempreg,$tempreg,$at |
| 7638 | |
| 7639 | If we have NewABI, and we know it's a local symbol, we want |
| 7640 | lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) |
| 7641 | addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST) |
| 7642 | otherwise we have to resort to GOT_HI16/GOT_LO16. */ |
| 7643 | |
| 7644 | relax_start (offset_expr.X_add_symbol); |
| 7645 | |
| 7646 | expr1.X_add_number = offset_expr.X_add_number; |
| 7647 | offset_expr.X_add_number = 0; |
| 7648 | |
| 7649 | if (expr1.X_add_number == 0 && breg == 0 |
| 7650 | && (call || tempreg == PIC_CALL_REG)) |
| 7651 | { |
| 7652 | lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16; |
| 7653 | lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16; |
| 7654 | } |
| 7655 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type); |
| 7656 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7657 | tempreg, tempreg, mips_gp_register); |
| 7658 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7659 | tempreg, lw_reloc_type, tempreg); |
| 7660 | |
| 7661 | if (expr1.X_add_number == 0) |
| 7662 | ; |
| 7663 | else if (expr1.X_add_number >= -0x8000 |
| 7664 | && expr1.X_add_number < 0x8000) |
| 7665 | { |
| 7666 | macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j", |
| 7667 | tempreg, tempreg, BFD_RELOC_LO16); |
| 7668 | } |
| 7669 | else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000)) |
| 7670 | { |
| 7671 | /* If we are going to add in a base register, and the |
| 7672 | target register and the base register are the same, |
| 7673 | then we are using AT as a temporary register. Since |
| 7674 | we want to load the constant into AT, we add our |
| 7675 | current AT (from the global offset table) and the |
| 7676 | register into the register now, and pretend we were |
| 7677 | not using a base register. */ |
| 7678 | if (breg != treg) |
| 7679 | dreg = tempreg; |
| 7680 | else |
| 7681 | { |
| 7682 | gas_assert (tempreg == AT); |
| 7683 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7684 | treg, AT, breg); |
| 7685 | dreg = treg; |
| 7686 | add_breg_early = 1; |
| 7687 | } |
| 7688 | |
| 7689 | load_register (AT, &expr1, HAVE_64BIT_ADDRESSES); |
| 7690 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT); |
| 7691 | |
| 7692 | used_at = 1; |
| 7693 | } |
| 7694 | else |
| 7695 | as_bad (_("PIC code offset overflow (max 32 signed bits)")); |
| 7696 | |
| 7697 | relax_switch (); |
| 7698 | offset_expr.X_add_number = expr1.X_add_number; |
| 7699 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 7700 | BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); |
| 7701 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg, |
| 7702 | tempreg, BFD_RELOC_MIPS_GOT_OFST); |
| 7703 | if (add_breg_early) |
| 7704 | { |
| 7705 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 7706 | treg, tempreg, breg); |
| 7707 | breg = 0; |
| 7708 | tempreg = treg; |
| 7709 | } |
| 7710 | relax_end (); |
| 7711 | } |
| 7712 | else |
| 7713 | abort (); |
| 7714 | |
| 7715 | if (breg != 0) |
| 7716 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg); |
| 7717 | break; |
| 7718 | |
| 7719 | case M_MSGSND: |
| 7720 | gas_assert (!mips_opts.micromips); |
| 7721 | { |
| 7722 | unsigned long temp = (treg << 16) | (0x01); |
| 7723 | macro_build (NULL, "c2", "C", temp); |
| 7724 | } |
| 7725 | break; |
| 7726 | |
| 7727 | case M_MSGLD: |
| 7728 | gas_assert (!mips_opts.micromips); |
| 7729 | { |
| 7730 | unsigned long temp = (0x02); |
| 7731 | macro_build (NULL, "c2", "C", temp); |
| 7732 | } |
| 7733 | break; |
| 7734 | |
| 7735 | case M_MSGLD_T: |
| 7736 | gas_assert (!mips_opts.micromips); |
| 7737 | { |
| 7738 | unsigned long temp = (treg << 16) | (0x02); |
| 7739 | macro_build (NULL, "c2", "C", temp); |
| 7740 | } |
| 7741 | break; |
| 7742 | |
| 7743 | case M_MSGWAIT: |
| 7744 | gas_assert (!mips_opts.micromips); |
| 7745 | macro_build (NULL, "c2", "C", 3); |
| 7746 | break; |
| 7747 | |
| 7748 | case M_MSGWAIT_T: |
| 7749 | gas_assert (!mips_opts.micromips); |
| 7750 | { |
| 7751 | unsigned long temp = (treg << 16) | 0x03; |
| 7752 | macro_build (NULL, "c2", "C", temp); |
| 7753 | } |
| 7754 | break; |
| 7755 | |
| 7756 | case M_J_A: |
| 7757 | /* The j instruction may not be used in PIC code, since it |
| 7758 | requires an absolute address. We convert it to a b |
| 7759 | instruction. */ |
| 7760 | if (mips_pic == NO_PIC) |
| 7761 | macro_build (&offset_expr, "j", "a"); |
| 7762 | else |
| 7763 | macro_build (&offset_expr, "b", "p"); |
| 7764 | break; |
| 7765 | |
| 7766 | /* The jal instructions must be handled as macros because when |
| 7767 | generating PIC code they expand to multi-instruction |
| 7768 | sequences. Normally they are simple instructions. */ |
| 7769 | case M_JALS_1: |
| 7770 | dreg = RA; |
| 7771 | /* Fall through. */ |
| 7772 | case M_JALS_2: |
| 7773 | gas_assert (mips_opts.micromips); |
| 7774 | jals = 1; |
| 7775 | goto jal; |
| 7776 | case M_JAL_1: |
| 7777 | dreg = RA; |
| 7778 | /* Fall through. */ |
| 7779 | case M_JAL_2: |
| 7780 | jal: |
| 7781 | if (mips_pic == NO_PIC) |
| 7782 | { |
| 7783 | s = jals ? "jalrs" : "jalr"; |
| 7784 | if (mips_opts.micromips |
| 7785 | && dreg == RA |
| 7786 | && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) |
| 7787 | macro_build (NULL, s, "mj", sreg); |
| 7788 | else |
| 7789 | macro_build (NULL, s, JALR_FMT, dreg, sreg); |
| 7790 | } |
| 7791 | else |
| 7792 | { |
| 7793 | int cprestore = (mips_pic == SVR4_PIC && !HAVE_NEWABI |
| 7794 | && mips_cprestore_offset >= 0); |
| 7795 | |
| 7796 | if (sreg != PIC_CALL_REG) |
| 7797 | as_warn (_("MIPS PIC call to register other than $25")); |
| 7798 | |
| 7799 | s = (mips_opts.micromips && (!mips_opts.noreorder || cprestore) |
| 7800 | ? "jalrs" : "jalr"); |
| 7801 | if (mips_opts.micromips |
| 7802 | && dreg == RA |
| 7803 | && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT)) |
| 7804 | macro_build (NULL, s, "mj", sreg); |
| 7805 | else |
| 7806 | macro_build (NULL, s, JALR_FMT, dreg, sreg); |
| 7807 | if (mips_pic == SVR4_PIC && !HAVE_NEWABI) |
| 7808 | { |
| 7809 | if (mips_cprestore_offset < 0) |
| 7810 | as_warn (_("No .cprestore pseudo-op used in PIC code")); |
| 7811 | else |
| 7812 | { |
| 7813 | if (!mips_frame_reg_valid) |
| 7814 | { |
| 7815 | as_warn (_("No .frame pseudo-op used in PIC code")); |
| 7816 | /* Quiet this warning. */ |
| 7817 | mips_frame_reg_valid = 1; |
| 7818 | } |
| 7819 | if (!mips_cprestore_valid) |
| 7820 | { |
| 7821 | as_warn (_("No .cprestore pseudo-op used in PIC code")); |
| 7822 | /* Quiet this warning. */ |
| 7823 | mips_cprestore_valid = 1; |
| 7824 | } |
| 7825 | if (mips_opts.noreorder) |
| 7826 | macro_build (NULL, "nop", ""); |
| 7827 | expr1.X_add_number = mips_cprestore_offset; |
| 7828 | macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN, |
| 7829 | mips_gp_register, |
| 7830 | mips_frame_reg, |
| 7831 | HAVE_64BIT_ADDRESSES); |
| 7832 | } |
| 7833 | } |
| 7834 | } |
| 7835 | |
| 7836 | break; |
| 7837 | |
| 7838 | case M_JALS_A: |
| 7839 | gas_assert (mips_opts.micromips); |
| 7840 | jals = 1; |
| 7841 | /* Fall through. */ |
| 7842 | case M_JAL_A: |
| 7843 | if (mips_pic == NO_PIC) |
| 7844 | macro_build (&offset_expr, jals ? "jals" : "jal", "a"); |
| 7845 | else if (mips_pic == SVR4_PIC) |
| 7846 | { |
| 7847 | /* If this is a reference to an external symbol, and we are |
| 7848 | using a small GOT, we want |
| 7849 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16) |
| 7850 | nop |
| 7851 | jalr $ra,$25 |
| 7852 | nop |
| 7853 | lw $gp,cprestore($sp) |
| 7854 | The cprestore value is set using the .cprestore |
| 7855 | pseudo-op. If we are using a big GOT, we want |
| 7856 | lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16) |
| 7857 | addu $25,$25,$gp |
| 7858 | lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16) |
| 7859 | nop |
| 7860 | jalr $ra,$25 |
| 7861 | nop |
| 7862 | lw $gp,cprestore($sp) |
| 7863 | If the symbol is not external, we want |
| 7864 | lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 7865 | nop |
| 7866 | addiu $25,$25,<sym> (BFD_RELOC_LO16) |
| 7867 | jalr $ra,$25 |
| 7868 | nop |
| 7869 | lw $gp,cprestore($sp) |
| 7870 | |
| 7871 | For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16 |
| 7872 | sequences above, minus nops, unless the symbol is local, |
| 7873 | which enables us to use GOT_PAGE/GOT_OFST (big got) or |
| 7874 | GOT_DISP. */ |
| 7875 | if (HAVE_NEWABI) |
| 7876 | { |
| 7877 | if (!mips_big_got) |
| 7878 | { |
| 7879 | relax_start (offset_expr.X_add_symbol); |
| 7880 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7881 | PIC_CALL_REG, BFD_RELOC_MIPS_CALL16, |
| 7882 | mips_gp_register); |
| 7883 | relax_switch (); |
| 7884 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7885 | PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP, |
| 7886 | mips_gp_register); |
| 7887 | relax_end (); |
| 7888 | } |
| 7889 | else |
| 7890 | { |
| 7891 | relax_start (offset_expr.X_add_symbol); |
| 7892 | macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG, |
| 7893 | BFD_RELOC_MIPS_CALL_HI16); |
| 7894 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG, |
| 7895 | PIC_CALL_REG, mips_gp_register); |
| 7896 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7897 | PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16, |
| 7898 | PIC_CALL_REG); |
| 7899 | relax_switch (); |
| 7900 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7901 | PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE, |
| 7902 | mips_gp_register); |
| 7903 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 7904 | PIC_CALL_REG, PIC_CALL_REG, |
| 7905 | BFD_RELOC_MIPS_GOT_OFST); |
| 7906 | relax_end (); |
| 7907 | } |
| 7908 | |
| 7909 | macro_build_jalr (&offset_expr, 0); |
| 7910 | } |
| 7911 | else |
| 7912 | { |
| 7913 | relax_start (offset_expr.X_add_symbol); |
| 7914 | if (!mips_big_got) |
| 7915 | { |
| 7916 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7917 | PIC_CALL_REG, BFD_RELOC_MIPS_CALL16, |
| 7918 | mips_gp_register); |
| 7919 | load_delay_nop (); |
| 7920 | relax_switch (); |
| 7921 | } |
| 7922 | else |
| 7923 | { |
| 7924 | int gpdelay; |
| 7925 | |
| 7926 | gpdelay = reg_needs_delay (mips_gp_register); |
| 7927 | macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG, |
| 7928 | BFD_RELOC_MIPS_CALL_HI16); |
| 7929 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG, |
| 7930 | PIC_CALL_REG, mips_gp_register); |
| 7931 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7932 | PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16, |
| 7933 | PIC_CALL_REG); |
| 7934 | load_delay_nop (); |
| 7935 | relax_switch (); |
| 7936 | if (gpdelay) |
| 7937 | macro_build (NULL, "nop", ""); |
| 7938 | } |
| 7939 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 7940 | PIC_CALL_REG, BFD_RELOC_MIPS_GOT16, |
| 7941 | mips_gp_register); |
| 7942 | load_delay_nop (); |
| 7943 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 7944 | PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16); |
| 7945 | relax_end (); |
| 7946 | macro_build_jalr (&offset_expr, mips_cprestore_offset >= 0); |
| 7947 | |
| 7948 | if (mips_cprestore_offset < 0) |
| 7949 | as_warn (_("No .cprestore pseudo-op used in PIC code")); |
| 7950 | else |
| 7951 | { |
| 7952 | if (!mips_frame_reg_valid) |
| 7953 | { |
| 7954 | as_warn (_("No .frame pseudo-op used in PIC code")); |
| 7955 | /* Quiet this warning. */ |
| 7956 | mips_frame_reg_valid = 1; |
| 7957 | } |
| 7958 | if (!mips_cprestore_valid) |
| 7959 | { |
| 7960 | as_warn (_("No .cprestore pseudo-op used in PIC code")); |
| 7961 | /* Quiet this warning. */ |
| 7962 | mips_cprestore_valid = 1; |
| 7963 | } |
| 7964 | if (mips_opts.noreorder) |
| 7965 | macro_build (NULL, "nop", ""); |
| 7966 | expr1.X_add_number = mips_cprestore_offset; |
| 7967 | macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN, |
| 7968 | mips_gp_register, |
| 7969 | mips_frame_reg, |
| 7970 | HAVE_64BIT_ADDRESSES); |
| 7971 | } |
| 7972 | } |
| 7973 | } |
| 7974 | else if (mips_pic == VXWORKS_PIC) |
| 7975 | as_bad (_("Non-PIC jump used in PIC library")); |
| 7976 | else |
| 7977 | abort (); |
| 7978 | |
| 7979 | break; |
| 7980 | |
| 7981 | case M_ACLR_AB: |
| 7982 | ab = 1; |
| 7983 | case M_ACLR_OB: |
| 7984 | s = "aclr"; |
| 7985 | treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip); |
| 7986 | fmt = "\\,~(b)"; |
| 7987 | off12 = 1; |
| 7988 | goto ld_st; |
| 7989 | case M_ASET_AB: |
| 7990 | ab = 1; |
| 7991 | case M_ASET_OB: |
| 7992 | s = "aset"; |
| 7993 | treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip); |
| 7994 | fmt = "\\,~(b)"; |
| 7995 | off12 = 1; |
| 7996 | goto ld_st; |
| 7997 | case M_LB_AB: |
| 7998 | ab = 1; |
| 7999 | s = "lb"; |
| 8000 | fmt = "t,o(b)"; |
| 8001 | goto ld; |
| 8002 | case M_LBU_AB: |
| 8003 | ab = 1; |
| 8004 | s = "lbu"; |
| 8005 | fmt = "t,o(b)"; |
| 8006 | goto ld; |
| 8007 | case M_LH_AB: |
| 8008 | ab = 1; |
| 8009 | s = "lh"; |
| 8010 | fmt = "t,o(b)"; |
| 8011 | goto ld; |
| 8012 | case M_LHU_AB: |
| 8013 | ab = 1; |
| 8014 | s = "lhu"; |
| 8015 | fmt = "t,o(b)"; |
| 8016 | goto ld; |
| 8017 | case M_LW_AB: |
| 8018 | ab = 1; |
| 8019 | s = "lw"; |
| 8020 | fmt = "t,o(b)"; |
| 8021 | goto ld; |
| 8022 | case M_LWC0_AB: |
| 8023 | ab = 1; |
| 8024 | gas_assert (!mips_opts.micromips); |
| 8025 | s = "lwc0"; |
| 8026 | fmt = "E,o(b)"; |
| 8027 | /* Itbl support may require additional care here. */ |
| 8028 | coproc = 1; |
| 8029 | goto ld_st; |
| 8030 | case M_LWC1_AB: |
| 8031 | ab = 1; |
| 8032 | s = "lwc1"; |
| 8033 | fmt = "T,o(b)"; |
| 8034 | /* Itbl support may require additional care here. */ |
| 8035 | coproc = 1; |
| 8036 | goto ld_st; |
| 8037 | case M_LWC2_AB: |
| 8038 | ab = 1; |
| 8039 | case M_LWC2_OB: |
| 8040 | s = "lwc2"; |
| 8041 | fmt = COP12_FMT; |
| 8042 | off12 = mips_opts.micromips; |
| 8043 | /* Itbl support may require additional care here. */ |
| 8044 | coproc = 1; |
| 8045 | goto ld_st; |
| 8046 | case M_LWC3_AB: |
| 8047 | ab = 1; |
| 8048 | gas_assert (!mips_opts.micromips); |
| 8049 | s = "lwc3"; |
| 8050 | fmt = "E,o(b)"; |
| 8051 | /* Itbl support may require additional care here. */ |
| 8052 | coproc = 1; |
| 8053 | goto ld_st; |
| 8054 | case M_LWL_AB: |
| 8055 | ab = 1; |
| 8056 | case M_LWL_OB: |
| 8057 | s = "lwl"; |
| 8058 | fmt = MEM12_FMT; |
| 8059 | off12 = mips_opts.micromips; |
| 8060 | goto ld_st; |
| 8061 | case M_LWR_AB: |
| 8062 | ab = 1; |
| 8063 | case M_LWR_OB: |
| 8064 | s = "lwr"; |
| 8065 | fmt = MEM12_FMT; |
| 8066 | off12 = mips_opts.micromips; |
| 8067 | goto ld_st; |
| 8068 | case M_LDC1_AB: |
| 8069 | ab = 1; |
| 8070 | s = "ldc1"; |
| 8071 | fmt = "T,o(b)"; |
| 8072 | /* Itbl support may require additional care here. */ |
| 8073 | coproc = 1; |
| 8074 | goto ld_st; |
| 8075 | case M_LDC2_AB: |
| 8076 | ab = 1; |
| 8077 | case M_LDC2_OB: |
| 8078 | s = "ldc2"; |
| 8079 | fmt = COP12_FMT; |
| 8080 | off12 = mips_opts.micromips; |
| 8081 | /* Itbl support may require additional care here. */ |
| 8082 | coproc = 1; |
| 8083 | goto ld_st; |
| 8084 | case M_LDC3_AB: |
| 8085 | ab = 1; |
| 8086 | s = "ldc3"; |
| 8087 | fmt = "E,o(b)"; |
| 8088 | /* Itbl support may require additional care here. */ |
| 8089 | coproc = 1; |
| 8090 | goto ld_st; |
| 8091 | case M_LDL_AB: |
| 8092 | ab = 1; |
| 8093 | case M_LDL_OB: |
| 8094 | s = "ldl"; |
| 8095 | fmt = MEM12_FMT; |
| 8096 | off12 = mips_opts.micromips; |
| 8097 | goto ld_st; |
| 8098 | case M_LDR_AB: |
| 8099 | ab = 1; |
| 8100 | case M_LDR_OB: |
| 8101 | s = "ldr"; |
| 8102 | fmt = MEM12_FMT; |
| 8103 | off12 = mips_opts.micromips; |
| 8104 | goto ld_st; |
| 8105 | case M_LL_AB: |
| 8106 | ab = 1; |
| 8107 | case M_LL_OB: |
| 8108 | s = "ll"; |
| 8109 | fmt = MEM12_FMT; |
| 8110 | off12 = mips_opts.micromips; |
| 8111 | goto ld; |
| 8112 | case M_LLD_AB: |
| 8113 | ab = 1; |
| 8114 | case M_LLD_OB: |
| 8115 | s = "lld"; |
| 8116 | fmt = MEM12_FMT; |
| 8117 | off12 = mips_opts.micromips; |
| 8118 | goto ld; |
| 8119 | case M_LWU_AB: |
| 8120 | ab = 1; |
| 8121 | case M_LWU_OB: |
| 8122 | s = "lwu"; |
| 8123 | fmt = MEM12_FMT; |
| 8124 | off12 = mips_opts.micromips; |
| 8125 | goto ld; |
| 8126 | case M_LWP_AB: |
| 8127 | ab = 1; |
| 8128 | case M_LWP_OB: |
| 8129 | gas_assert (mips_opts.micromips); |
| 8130 | s = "lwp"; |
| 8131 | fmt = "t,~(b)"; |
| 8132 | off12 = 1; |
| 8133 | lp = 1; |
| 8134 | goto ld; |
| 8135 | case M_LDP_AB: |
| 8136 | ab = 1; |
| 8137 | case M_LDP_OB: |
| 8138 | gas_assert (mips_opts.micromips); |
| 8139 | s = "ldp"; |
| 8140 | fmt = "t,~(b)"; |
| 8141 | off12 = 1; |
| 8142 | lp = 1; |
| 8143 | goto ld; |
| 8144 | case M_LWM_AB: |
| 8145 | ab = 1; |
| 8146 | case M_LWM_OB: |
| 8147 | gas_assert (mips_opts.micromips); |
| 8148 | s = "lwm"; |
| 8149 | fmt = "n,~(b)"; |
| 8150 | off12 = 1; |
| 8151 | goto ld_st; |
| 8152 | case M_LDM_AB: |
| 8153 | ab = 1; |
| 8154 | case M_LDM_OB: |
| 8155 | gas_assert (mips_opts.micromips); |
| 8156 | s = "ldm"; |
| 8157 | fmt = "n,~(b)"; |
| 8158 | off12 = 1; |
| 8159 | goto ld_st; |
| 8160 | |
| 8161 | ld: |
| 8162 | if (breg == treg + lp) |
| 8163 | goto ld_st; |
| 8164 | else |
| 8165 | tempreg = treg + lp; |
| 8166 | goto ld_noat; |
| 8167 | |
| 8168 | case M_SB_AB: |
| 8169 | ab = 1; |
| 8170 | s = "sb"; |
| 8171 | fmt = "t,o(b)"; |
| 8172 | goto ld_st; |
| 8173 | case M_SH_AB: |
| 8174 | ab = 1; |
| 8175 | s = "sh"; |
| 8176 | fmt = "t,o(b)"; |
| 8177 | goto ld_st; |
| 8178 | case M_SW_AB: |
| 8179 | ab = 1; |
| 8180 | s = "sw"; |
| 8181 | fmt = "t,o(b)"; |
| 8182 | goto ld_st; |
| 8183 | case M_SWC0_AB: |
| 8184 | ab = 1; |
| 8185 | gas_assert (!mips_opts.micromips); |
| 8186 | s = "swc0"; |
| 8187 | fmt = "E,o(b)"; |
| 8188 | /* Itbl support may require additional care here. */ |
| 8189 | coproc = 1; |
| 8190 | goto ld_st; |
| 8191 | case M_SWC1_AB: |
| 8192 | ab = 1; |
| 8193 | s = "swc1"; |
| 8194 | fmt = "T,o(b)"; |
| 8195 | /* Itbl support may require additional care here. */ |
| 8196 | coproc = 1; |
| 8197 | goto ld_st; |
| 8198 | case M_SWC2_AB: |
| 8199 | ab = 1; |
| 8200 | case M_SWC2_OB: |
| 8201 | s = "swc2"; |
| 8202 | fmt = COP12_FMT; |
| 8203 | off12 = mips_opts.micromips; |
| 8204 | /* Itbl support may require additional care here. */ |
| 8205 | coproc = 1; |
| 8206 | goto ld_st; |
| 8207 | case M_SWC3_AB: |
| 8208 | ab = 1; |
| 8209 | gas_assert (!mips_opts.micromips); |
| 8210 | s = "swc3"; |
| 8211 | fmt = "E,o(b)"; |
| 8212 | /* Itbl support may require additional care here. */ |
| 8213 | coproc = 1; |
| 8214 | goto ld_st; |
| 8215 | case M_SWL_AB: |
| 8216 | ab = 1; |
| 8217 | case M_SWL_OB: |
| 8218 | s = "swl"; |
| 8219 | fmt = MEM12_FMT; |
| 8220 | off12 = mips_opts.micromips; |
| 8221 | goto ld_st; |
| 8222 | case M_SWR_AB: |
| 8223 | ab = 1; |
| 8224 | case M_SWR_OB: |
| 8225 | s = "swr"; |
| 8226 | fmt = MEM12_FMT; |
| 8227 | off12 = mips_opts.micromips; |
| 8228 | goto ld_st; |
| 8229 | case M_SC_AB: |
| 8230 | ab = 1; |
| 8231 | case M_SC_OB: |
| 8232 | s = "sc"; |
| 8233 | fmt = MEM12_FMT; |
| 8234 | off12 = mips_opts.micromips; |
| 8235 | goto ld_st; |
| 8236 | case M_SCD_AB: |
| 8237 | ab = 1; |
| 8238 | case M_SCD_OB: |
| 8239 | s = "scd"; |
| 8240 | fmt = MEM12_FMT; |
| 8241 | off12 = mips_opts.micromips; |
| 8242 | goto ld_st; |
| 8243 | case M_CACHE_AB: |
| 8244 | ab = 1; |
| 8245 | case M_CACHE_OB: |
| 8246 | s = "cache"; |
| 8247 | fmt = mips_opts.micromips ? "k,~(b)" : "k,o(b)"; |
| 8248 | off12 = mips_opts.micromips; |
| 8249 | goto ld_st; |
| 8250 | case M_PREF_AB: |
| 8251 | ab = 1; |
| 8252 | case M_PREF_OB: |
| 8253 | s = "pref"; |
| 8254 | fmt = !mips_opts.micromips ? "k,o(b)" : "k,~(b)"; |
| 8255 | off12 = mips_opts.micromips; |
| 8256 | goto ld_st; |
| 8257 | case M_SDC1_AB: |
| 8258 | ab = 1; |
| 8259 | s = "sdc1"; |
| 8260 | fmt = "T,o(b)"; |
| 8261 | coproc = 1; |
| 8262 | /* Itbl support may require additional care here. */ |
| 8263 | goto ld_st; |
| 8264 | case M_SDC2_AB: |
| 8265 | ab = 1; |
| 8266 | case M_SDC2_OB: |
| 8267 | s = "sdc2"; |
| 8268 | fmt = COP12_FMT; |
| 8269 | off12 = mips_opts.micromips; |
| 8270 | /* Itbl support may require additional care here. */ |
| 8271 | coproc = 1; |
| 8272 | goto ld_st; |
| 8273 | case M_SDC3_AB: |
| 8274 | ab = 1; |
| 8275 | gas_assert (!mips_opts.micromips); |
| 8276 | s = "sdc3"; |
| 8277 | fmt = "E,o(b)"; |
| 8278 | /* Itbl support may require additional care here. */ |
| 8279 | coproc = 1; |
| 8280 | goto ld_st; |
| 8281 | case M_SDL_AB: |
| 8282 | ab = 1; |
| 8283 | case M_SDL_OB: |
| 8284 | s = "sdl"; |
| 8285 | fmt = MEM12_FMT; |
| 8286 | off12 = mips_opts.micromips; |
| 8287 | goto ld_st; |
| 8288 | case M_SDR_AB: |
| 8289 | ab = 1; |
| 8290 | case M_SDR_OB: |
| 8291 | s = "sdr"; |
| 8292 | fmt = MEM12_FMT; |
| 8293 | off12 = mips_opts.micromips; |
| 8294 | goto ld_st; |
| 8295 | case M_SWP_AB: |
| 8296 | ab = 1; |
| 8297 | case M_SWP_OB: |
| 8298 | gas_assert (mips_opts.micromips); |
| 8299 | s = "swp"; |
| 8300 | fmt = "t,~(b)"; |
| 8301 | off12 = 1; |
| 8302 | goto ld_st; |
| 8303 | case M_SDP_AB: |
| 8304 | ab = 1; |
| 8305 | case M_SDP_OB: |
| 8306 | gas_assert (mips_opts.micromips); |
| 8307 | s = "sdp"; |
| 8308 | fmt = "t,~(b)"; |
| 8309 | off12 = 1; |
| 8310 | goto ld_st; |
| 8311 | case M_SWM_AB: |
| 8312 | ab = 1; |
| 8313 | case M_SWM_OB: |
| 8314 | gas_assert (mips_opts.micromips); |
| 8315 | s = "swm"; |
| 8316 | fmt = "n,~(b)"; |
| 8317 | off12 = 1; |
| 8318 | goto ld_st; |
| 8319 | case M_SDM_AB: |
| 8320 | ab = 1; |
| 8321 | case M_SDM_OB: |
| 8322 | gas_assert (mips_opts.micromips); |
| 8323 | s = "sdm"; |
| 8324 | fmt = "n,~(b)"; |
| 8325 | off12 = 1; |
| 8326 | |
| 8327 | ld_st: |
| 8328 | tempreg = AT; |
| 8329 | used_at = 1; |
| 8330 | ld_noat: |
| 8331 | if (offset_expr.X_op != O_constant |
| 8332 | && offset_expr.X_op != O_symbol) |
| 8333 | { |
| 8334 | as_bad (_("Expression too complex")); |
| 8335 | offset_expr.X_op = O_constant; |
| 8336 | } |
| 8337 | |
| 8338 | if (HAVE_32BIT_ADDRESSES |
| 8339 | && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number)) |
| 8340 | { |
| 8341 | char value [32]; |
| 8342 | |
| 8343 | sprintf_vma (value, offset_expr.X_add_number); |
| 8344 | as_bad (_("Number (0x%s) larger than 32 bits"), value); |
| 8345 | } |
| 8346 | |
| 8347 | /* A constant expression in PIC code can be handled just as it |
| 8348 | is in non PIC code. */ |
| 8349 | if (offset_expr.X_op == O_constant) |
| 8350 | { |
| 8351 | int hipart = 0; |
| 8352 | |
| 8353 | expr1.X_add_number = offset_expr.X_add_number; |
| 8354 | normalize_address_expr (&expr1); |
| 8355 | if (!off12 && !IS_SEXT_16BIT_NUM (expr1.X_add_number)) |
| 8356 | { |
| 8357 | expr1.X_add_number = ((expr1.X_add_number + 0x8000) |
| 8358 | & ~(bfd_vma) 0xffff); |
| 8359 | hipart = 1; |
| 8360 | } |
| 8361 | else if (off12 && !IS_SEXT_12BIT_NUM (expr1.X_add_number)) |
| 8362 | { |
| 8363 | expr1.X_add_number = ((expr1.X_add_number + 0x800) |
| 8364 | & ~(bfd_vma) 0xfff); |
| 8365 | hipart = 1; |
| 8366 | } |
| 8367 | if (hipart) |
| 8368 | { |
| 8369 | load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES); |
| 8370 | if (breg != 0) |
| 8371 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8372 | tempreg, tempreg, breg); |
| 8373 | breg = tempreg; |
| 8374 | } |
| 8375 | if (off0) |
| 8376 | { |
| 8377 | if (offset_expr.X_add_number == 0) |
| 8378 | tempreg = breg; |
| 8379 | else |
| 8380 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, |
| 8381 | "t,r,j", tempreg, breg, BFD_RELOC_LO16); |
| 8382 | macro_build (NULL, s, fmt, treg, tempreg); |
| 8383 | } |
| 8384 | else if (!off12) |
| 8385 | macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, breg); |
| 8386 | else |
| 8387 | macro_build (NULL, s, fmt, |
| 8388 | treg, (unsigned long) offset_expr.X_add_number, breg); |
| 8389 | } |
| 8390 | else if (off12 || off0) |
| 8391 | { |
| 8392 | /* A 12-bit or 0-bit offset field is too narrow to be used |
| 8393 | for a low-part relocation, so load the whole address into |
| 8394 | the auxillary register. In the case of "A(b)" addresses, |
| 8395 | we first load absolute address "A" into the register and |
| 8396 | then add base register "b". In the case of "o(b)" addresses, |
| 8397 | we simply need to add 16-bit offset "o" to base register "b", and |
| 8398 | offset_reloc already contains the relocations associated |
| 8399 | with "o". */ |
| 8400 | if (ab) |
| 8401 | { |
| 8402 | load_address (tempreg, &offset_expr, &used_at); |
| 8403 | if (breg != 0) |
| 8404 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8405 | tempreg, tempreg, breg); |
| 8406 | } |
| 8407 | else |
| 8408 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", |
| 8409 | tempreg, breg, -1, |
| 8410 | offset_reloc[0], offset_reloc[1], offset_reloc[2]); |
| 8411 | expr1.X_add_number = 0; |
| 8412 | if (off0) |
| 8413 | macro_build (NULL, s, fmt, treg, tempreg); |
| 8414 | else |
| 8415 | macro_build (NULL, s, fmt, |
| 8416 | treg, (unsigned long) expr1.X_add_number, tempreg); |
| 8417 | } |
| 8418 | else if (mips_pic == NO_PIC) |
| 8419 | { |
| 8420 | /* If this is a reference to a GP relative symbol, and there |
| 8421 | is no base register, we want |
| 8422 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
| 8423 | Otherwise, if there is no base register, we want |
| 8424 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) |
| 8425 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) |
| 8426 | If we have a constant, we need two instructions anyhow, |
| 8427 | so we always use the latter form. |
| 8428 | |
| 8429 | If we have a base register, and this is a reference to a |
| 8430 | GP relative symbol, we want |
| 8431 | addu $tempreg,$breg,$gp |
| 8432 | <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16) |
| 8433 | Otherwise we want |
| 8434 | lui $tempreg,<sym> (BFD_RELOC_HI16_S) |
| 8435 | addu $tempreg,$tempreg,$breg |
| 8436 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) |
| 8437 | With a constant we always use the latter case. |
| 8438 | |
| 8439 | With 64bit address space and no base register and $at usable, |
| 8440 | we want |
| 8441 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) |
| 8442 | lui $at,<sym> (BFD_RELOC_HI16_S) |
| 8443 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) |
| 8444 | dsll32 $tempreg,0 |
| 8445 | daddu $tempreg,$at |
| 8446 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) |
| 8447 | If we have a base register, we want |
| 8448 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) |
| 8449 | lui $at,<sym> (BFD_RELOC_HI16_S) |
| 8450 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) |
| 8451 | daddu $at,$breg |
| 8452 | dsll32 $tempreg,0 |
| 8453 | daddu $tempreg,$at |
| 8454 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) |
| 8455 | |
| 8456 | Without $at we can't generate the optimal path for superscalar |
| 8457 | processors here since this would require two temporary registers. |
| 8458 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) |
| 8459 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) |
| 8460 | dsll $tempreg,16 |
| 8461 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) |
| 8462 | dsll $tempreg,16 |
| 8463 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) |
| 8464 | If we have a base register, we want |
| 8465 | lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST) |
| 8466 | daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER) |
| 8467 | dsll $tempreg,16 |
| 8468 | daddiu $tempreg,<sym> (BFD_RELOC_HI16_S) |
| 8469 | dsll $tempreg,16 |
| 8470 | daddu $tempreg,$tempreg,$breg |
| 8471 | <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16) |
| 8472 | |
| 8473 | For GP relative symbols in 64bit address space we can use |
| 8474 | the same sequence as in 32bit address space. */ |
| 8475 | if (HAVE_64BIT_SYMBOLS) |
| 8476 | { |
| 8477 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
| 8478 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
| 8479 | { |
| 8480 | relax_start (offset_expr.X_add_symbol); |
| 8481 | if (breg == 0) |
| 8482 | { |
| 8483 | macro_build (&offset_expr, s, fmt, treg, |
| 8484 | BFD_RELOC_GPREL16, mips_gp_register); |
| 8485 | } |
| 8486 | else |
| 8487 | { |
| 8488 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8489 | tempreg, breg, mips_gp_register); |
| 8490 | macro_build (&offset_expr, s, fmt, treg, |
| 8491 | BFD_RELOC_GPREL16, tempreg); |
| 8492 | } |
| 8493 | relax_switch (); |
| 8494 | } |
| 8495 | |
| 8496 | if (used_at == 0 && mips_opts.at) |
| 8497 | { |
| 8498 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, |
| 8499 | BFD_RELOC_MIPS_HIGHEST); |
| 8500 | macro_build (&offset_expr, "lui", LUI_FMT, AT, |
| 8501 | BFD_RELOC_HI16_S); |
| 8502 | macro_build (&offset_expr, "daddiu", "t,r,j", tempreg, |
| 8503 | tempreg, BFD_RELOC_MIPS_HIGHER); |
| 8504 | if (breg != 0) |
| 8505 | macro_build (NULL, "daddu", "d,v,t", AT, AT, breg); |
| 8506 | macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0); |
| 8507 | macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT); |
| 8508 | macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, |
| 8509 | tempreg); |
| 8510 | used_at = 1; |
| 8511 | } |
| 8512 | else |
| 8513 | { |
| 8514 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, |
| 8515 | BFD_RELOC_MIPS_HIGHEST); |
| 8516 | macro_build (&offset_expr, "daddiu", "t,r,j", tempreg, |
| 8517 | tempreg, BFD_RELOC_MIPS_HIGHER); |
| 8518 | macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16); |
| 8519 | macro_build (&offset_expr, "daddiu", "t,r,j", tempreg, |
| 8520 | tempreg, BFD_RELOC_HI16_S); |
| 8521 | macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16); |
| 8522 | if (breg != 0) |
| 8523 | macro_build (NULL, "daddu", "d,v,t", |
| 8524 | tempreg, tempreg, breg); |
| 8525 | macro_build (&offset_expr, s, fmt, treg, |
| 8526 | BFD_RELOC_LO16, tempreg); |
| 8527 | } |
| 8528 | |
| 8529 | if (mips_relax.sequence) |
| 8530 | relax_end (); |
| 8531 | break; |
| 8532 | } |
| 8533 | |
| 8534 | if (breg == 0) |
| 8535 | { |
| 8536 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
| 8537 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
| 8538 | { |
| 8539 | relax_start (offset_expr.X_add_symbol); |
| 8540 | macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16, |
| 8541 | mips_gp_register); |
| 8542 | relax_switch (); |
| 8543 | } |
| 8544 | macro_build_lui (&offset_expr, tempreg); |
| 8545 | macro_build (&offset_expr, s, fmt, treg, |
| 8546 | BFD_RELOC_LO16, tempreg); |
| 8547 | if (mips_relax.sequence) |
| 8548 | relax_end (); |
| 8549 | } |
| 8550 | else |
| 8551 | { |
| 8552 | if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
| 8553 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
| 8554 | { |
| 8555 | relax_start (offset_expr.X_add_symbol); |
| 8556 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8557 | tempreg, breg, mips_gp_register); |
| 8558 | macro_build (&offset_expr, s, fmt, treg, |
| 8559 | BFD_RELOC_GPREL16, tempreg); |
| 8560 | relax_switch (); |
| 8561 | } |
| 8562 | macro_build_lui (&offset_expr, tempreg); |
| 8563 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8564 | tempreg, tempreg, breg); |
| 8565 | macro_build (&offset_expr, s, fmt, treg, |
| 8566 | BFD_RELOC_LO16, tempreg); |
| 8567 | if (mips_relax.sequence) |
| 8568 | relax_end (); |
| 8569 | } |
| 8570 | } |
| 8571 | else if (!mips_big_got) |
| 8572 | { |
| 8573 | int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16; |
| 8574 | |
| 8575 | /* If this is a reference to an external symbol, we want |
| 8576 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 8577 | nop |
| 8578 | <op> $treg,0($tempreg) |
| 8579 | Otherwise we want |
| 8580 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 8581 | nop |
| 8582 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) |
| 8583 | <op> $treg,0($tempreg) |
| 8584 | |
| 8585 | For NewABI, we want |
| 8586 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) |
| 8587 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) |
| 8588 | |
| 8589 | If there is a base register, we add it to $tempreg before |
| 8590 | the <op>. If there is a constant, we stick it in the |
| 8591 | <op> instruction. We don't handle constants larger than |
| 8592 | 16 bits, because we have no way to load the upper 16 bits |
| 8593 | (actually, we could handle them for the subset of cases |
| 8594 | in which we are not using $at). */ |
| 8595 | gas_assert (offset_expr.X_op == O_symbol); |
| 8596 | if (HAVE_NEWABI) |
| 8597 | { |
| 8598 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 8599 | BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); |
| 8600 | if (breg != 0) |
| 8601 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8602 | tempreg, tempreg, breg); |
| 8603 | macro_build (&offset_expr, s, fmt, treg, |
| 8604 | BFD_RELOC_MIPS_GOT_OFST, tempreg); |
| 8605 | break; |
| 8606 | } |
| 8607 | expr1.X_add_number = offset_expr.X_add_number; |
| 8608 | offset_expr.X_add_number = 0; |
| 8609 | if (expr1.X_add_number < -0x8000 |
| 8610 | || expr1.X_add_number >= 0x8000) |
| 8611 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 8612 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 8613 | lw_reloc_type, mips_gp_register); |
| 8614 | load_delay_nop (); |
| 8615 | relax_start (offset_expr.X_add_symbol); |
| 8616 | relax_switch (); |
| 8617 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg, |
| 8618 | tempreg, BFD_RELOC_LO16); |
| 8619 | relax_end (); |
| 8620 | if (breg != 0) |
| 8621 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8622 | tempreg, tempreg, breg); |
| 8623 | macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg); |
| 8624 | } |
| 8625 | else if (mips_big_got && !HAVE_NEWABI) |
| 8626 | { |
| 8627 | int gpdelay; |
| 8628 | |
| 8629 | /* If this is a reference to an external symbol, we want |
| 8630 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 8631 | addu $tempreg,$tempreg,$gp |
| 8632 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) |
| 8633 | <op> $treg,0($tempreg) |
| 8634 | Otherwise we want |
| 8635 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 8636 | nop |
| 8637 | addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16) |
| 8638 | <op> $treg,0($tempreg) |
| 8639 | If there is a base register, we add it to $tempreg before |
| 8640 | the <op>. If there is a constant, we stick it in the |
| 8641 | <op> instruction. We don't handle constants larger than |
| 8642 | 16 bits, because we have no way to load the upper 16 bits |
| 8643 | (actually, we could handle them for the subset of cases |
| 8644 | in which we are not using $at). */ |
| 8645 | gas_assert (offset_expr.X_op == O_symbol); |
| 8646 | expr1.X_add_number = offset_expr.X_add_number; |
| 8647 | offset_expr.X_add_number = 0; |
| 8648 | if (expr1.X_add_number < -0x8000 |
| 8649 | || expr1.X_add_number >= 0x8000) |
| 8650 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 8651 | gpdelay = reg_needs_delay (mips_gp_register); |
| 8652 | relax_start (offset_expr.X_add_symbol); |
| 8653 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, |
| 8654 | BFD_RELOC_MIPS_GOT_HI16); |
| 8655 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, |
| 8656 | mips_gp_register); |
| 8657 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 8658 | BFD_RELOC_MIPS_GOT_LO16, tempreg); |
| 8659 | relax_switch (); |
| 8660 | if (gpdelay) |
| 8661 | macro_build (NULL, "nop", ""); |
| 8662 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 8663 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 8664 | load_delay_nop (); |
| 8665 | macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg, |
| 8666 | tempreg, BFD_RELOC_LO16); |
| 8667 | relax_end (); |
| 8668 | |
| 8669 | if (breg != 0) |
| 8670 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8671 | tempreg, tempreg, breg); |
| 8672 | macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg); |
| 8673 | } |
| 8674 | else if (mips_big_got && HAVE_NEWABI) |
| 8675 | { |
| 8676 | /* If this is a reference to an external symbol, we want |
| 8677 | lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 8678 | add $tempreg,$tempreg,$gp |
| 8679 | lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16) |
| 8680 | <op> $treg,<ofst>($tempreg) |
| 8681 | Otherwise, for local symbols, we want: |
| 8682 | lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE) |
| 8683 | <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */ |
| 8684 | gas_assert (offset_expr.X_op == O_symbol); |
| 8685 | expr1.X_add_number = offset_expr.X_add_number; |
| 8686 | offset_expr.X_add_number = 0; |
| 8687 | if (expr1.X_add_number < -0x8000 |
| 8688 | || expr1.X_add_number >= 0x8000) |
| 8689 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 8690 | relax_start (offset_expr.X_add_symbol); |
| 8691 | macro_build (&offset_expr, "lui", LUI_FMT, tempreg, |
| 8692 | BFD_RELOC_MIPS_GOT_HI16); |
| 8693 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg, |
| 8694 | mips_gp_register); |
| 8695 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 8696 | BFD_RELOC_MIPS_GOT_LO16, tempreg); |
| 8697 | if (breg != 0) |
| 8698 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8699 | tempreg, tempreg, breg); |
| 8700 | macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg); |
| 8701 | |
| 8702 | relax_switch (); |
| 8703 | offset_expr.X_add_number = expr1.X_add_number; |
| 8704 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg, |
| 8705 | BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register); |
| 8706 | if (breg != 0) |
| 8707 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 8708 | tempreg, tempreg, breg); |
| 8709 | macro_build (&offset_expr, s, fmt, treg, |
| 8710 | BFD_RELOC_MIPS_GOT_OFST, tempreg); |
| 8711 | relax_end (); |
| 8712 | } |
| 8713 | else |
| 8714 | abort (); |
| 8715 | |
| 8716 | break; |
| 8717 | |
| 8718 | case M_LI: |
| 8719 | case M_LI_S: |
| 8720 | load_register (treg, &imm_expr, 0); |
| 8721 | break; |
| 8722 | |
| 8723 | case M_DLI: |
| 8724 | load_register (treg, &imm_expr, 1); |
| 8725 | break; |
| 8726 | |
| 8727 | case M_LI_SS: |
| 8728 | if (imm_expr.X_op == O_constant) |
| 8729 | { |
| 8730 | used_at = 1; |
| 8731 | load_register (AT, &imm_expr, 0); |
| 8732 | macro_build (NULL, "mtc1", "t,G", AT, treg); |
| 8733 | break; |
| 8734 | } |
| 8735 | else |
| 8736 | { |
| 8737 | gas_assert (offset_expr.X_op == O_symbol |
| 8738 | && strcmp (segment_name (S_GET_SEGMENT |
| 8739 | (offset_expr.X_add_symbol)), |
| 8740 | ".lit4") == 0 |
| 8741 | && offset_expr.X_add_number == 0); |
| 8742 | macro_build (&offset_expr, "lwc1", "T,o(b)", treg, |
| 8743 | BFD_RELOC_MIPS_LITERAL, mips_gp_register); |
| 8744 | break; |
| 8745 | } |
| 8746 | |
| 8747 | case M_LI_D: |
| 8748 | /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits |
| 8749 | wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high |
| 8750 | order 32 bits of the value and the low order 32 bits are either |
| 8751 | zero or in OFFSET_EXPR. */ |
| 8752 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
| 8753 | { |
| 8754 | if (HAVE_64BIT_GPRS) |
| 8755 | load_register (treg, &imm_expr, 1); |
| 8756 | else |
| 8757 | { |
| 8758 | int hreg, lreg; |
| 8759 | |
| 8760 | if (target_big_endian) |
| 8761 | { |
| 8762 | hreg = treg; |
| 8763 | lreg = treg + 1; |
| 8764 | } |
| 8765 | else |
| 8766 | { |
| 8767 | hreg = treg + 1; |
| 8768 | lreg = treg; |
| 8769 | } |
| 8770 | |
| 8771 | if (hreg <= 31) |
| 8772 | load_register (hreg, &imm_expr, 0); |
| 8773 | if (lreg <= 31) |
| 8774 | { |
| 8775 | if (offset_expr.X_op == O_absent) |
| 8776 | move_register (lreg, 0); |
| 8777 | else |
| 8778 | { |
| 8779 | gas_assert (offset_expr.X_op == O_constant); |
| 8780 | load_register (lreg, &offset_expr, 0); |
| 8781 | } |
| 8782 | } |
| 8783 | } |
| 8784 | break; |
| 8785 | } |
| 8786 | |
| 8787 | /* We know that sym is in the .rdata section. First we get the |
| 8788 | upper 16 bits of the address. */ |
| 8789 | if (mips_pic == NO_PIC) |
| 8790 | { |
| 8791 | macro_build_lui (&offset_expr, AT); |
| 8792 | used_at = 1; |
| 8793 | } |
| 8794 | else |
| 8795 | { |
| 8796 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT, |
| 8797 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 8798 | used_at = 1; |
| 8799 | } |
| 8800 | |
| 8801 | /* Now we load the register(s). */ |
| 8802 | if (HAVE_64BIT_GPRS) |
| 8803 | { |
| 8804 | used_at = 1; |
| 8805 | macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT); |
| 8806 | } |
| 8807 | else |
| 8808 | { |
| 8809 | used_at = 1; |
| 8810 | macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT); |
| 8811 | if (treg != RA) |
| 8812 | { |
| 8813 | /* FIXME: How in the world do we deal with the possible |
| 8814 | overflow here? */ |
| 8815 | offset_expr.X_add_number += 4; |
| 8816 | macro_build (&offset_expr, "lw", "t,o(b)", |
| 8817 | treg + 1, BFD_RELOC_LO16, AT); |
| 8818 | } |
| 8819 | } |
| 8820 | break; |
| 8821 | |
| 8822 | case M_LI_DD: |
| 8823 | /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits |
| 8824 | wide, IMM_EXPR is the entire value and the GPRs are known to be 64 |
| 8825 | bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of |
| 8826 | the value and the low order 32 bits are either zero or in |
| 8827 | OFFSET_EXPR. */ |
| 8828 | if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big) |
| 8829 | { |
| 8830 | used_at = 1; |
| 8831 | load_register (AT, &imm_expr, HAVE_64BIT_FPRS); |
| 8832 | if (HAVE_64BIT_FPRS) |
| 8833 | { |
| 8834 | gas_assert (HAVE_64BIT_GPRS); |
| 8835 | macro_build (NULL, "dmtc1", "t,S", AT, treg); |
| 8836 | } |
| 8837 | else |
| 8838 | { |
| 8839 | macro_build (NULL, "mtc1", "t,G", AT, treg + 1); |
| 8840 | if (offset_expr.X_op == O_absent) |
| 8841 | macro_build (NULL, "mtc1", "t,G", 0, treg); |
| 8842 | else |
| 8843 | { |
| 8844 | gas_assert (offset_expr.X_op == O_constant); |
| 8845 | load_register (AT, &offset_expr, 0); |
| 8846 | macro_build (NULL, "mtc1", "t,G", AT, treg); |
| 8847 | } |
| 8848 | } |
| 8849 | break; |
| 8850 | } |
| 8851 | |
| 8852 | gas_assert (offset_expr.X_op == O_symbol |
| 8853 | && offset_expr.X_add_number == 0); |
| 8854 | s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol)); |
| 8855 | if (strcmp (s, ".lit8") == 0) |
| 8856 | { |
| 8857 | if (mips_opts.isa != ISA_MIPS1 || mips_opts.micromips) |
| 8858 | { |
| 8859 | macro_build (&offset_expr, "ldc1", "T,o(b)", treg, |
| 8860 | BFD_RELOC_MIPS_LITERAL, mips_gp_register); |
| 8861 | break; |
| 8862 | } |
| 8863 | breg = mips_gp_register; |
| 8864 | r = BFD_RELOC_MIPS_LITERAL; |
| 8865 | goto dob; |
| 8866 | } |
| 8867 | else |
| 8868 | { |
| 8869 | gas_assert (strcmp (s, RDATA_SECTION_NAME) == 0); |
| 8870 | used_at = 1; |
| 8871 | if (mips_pic != NO_PIC) |
| 8872 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT, |
| 8873 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 8874 | else |
| 8875 | { |
| 8876 | /* FIXME: This won't work for a 64 bit address. */ |
| 8877 | macro_build_lui (&offset_expr, AT); |
| 8878 | } |
| 8879 | |
| 8880 | if (mips_opts.isa != ISA_MIPS1 || mips_opts.micromips) |
| 8881 | { |
| 8882 | macro_build (&offset_expr, "ldc1", "T,o(b)", |
| 8883 | treg, BFD_RELOC_LO16, AT); |
| 8884 | break; |
| 8885 | } |
| 8886 | breg = AT; |
| 8887 | r = BFD_RELOC_LO16; |
| 8888 | goto dob; |
| 8889 | } |
| 8890 | |
| 8891 | case M_L_DOB: |
| 8892 | /* Even on a big endian machine $fn comes before $fn+1. We have |
| 8893 | to adjust when loading from memory. */ |
| 8894 | r = BFD_RELOC_LO16; |
| 8895 | dob: |
| 8896 | gas_assert (!mips_opts.micromips); |
| 8897 | gas_assert (mips_opts.isa == ISA_MIPS1); |
| 8898 | macro_build (&offset_expr, "lwc1", "T,o(b)", |
| 8899 | target_big_endian ? treg + 1 : treg, r, breg); |
| 8900 | /* FIXME: A possible overflow which I don't know how to deal |
| 8901 | with. */ |
| 8902 | offset_expr.X_add_number += 4; |
| 8903 | macro_build (&offset_expr, "lwc1", "T,o(b)", |
| 8904 | target_big_endian ? treg : treg + 1, r, breg); |
| 8905 | break; |
| 8906 | |
| 8907 | case M_S_DOB: |
| 8908 | gas_assert (!mips_opts.micromips); |
| 8909 | gas_assert (mips_opts.isa == ISA_MIPS1); |
| 8910 | /* Even on a big endian machine $fn comes before $fn+1. We have |
| 8911 | to adjust when storing to memory. */ |
| 8912 | macro_build (&offset_expr, "swc1", "T,o(b)", |
| 8913 | target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg); |
| 8914 | offset_expr.X_add_number += 4; |
| 8915 | macro_build (&offset_expr, "swc1", "T,o(b)", |
| 8916 | target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg); |
| 8917 | break; |
| 8918 | |
| 8919 | case M_L_DAB: |
| 8920 | gas_assert (!mips_opts.micromips); |
| 8921 | /* |
| 8922 | * The MIPS assembler seems to check for X_add_number not |
| 8923 | * being double aligned and generating: |
| 8924 | * lui at,%hi(foo+1) |
| 8925 | * addu at,at,v1 |
| 8926 | * addiu at,at,%lo(foo+1) |
| 8927 | * lwc1 f2,0(at) |
| 8928 | * lwc1 f3,4(at) |
| 8929 | * But, the resulting address is the same after relocation so why |
| 8930 | * generate the extra instruction? |
| 8931 | */ |
| 8932 | /* Itbl support may require additional care here. */ |
| 8933 | coproc = 1; |
| 8934 | fmt = "T,o(b)"; |
| 8935 | if (mips_opts.isa != ISA_MIPS1) |
| 8936 | { |
| 8937 | s = "ldc1"; |
| 8938 | goto ld_st; |
| 8939 | } |
| 8940 | s = "lwc1"; |
| 8941 | goto ldd_std; |
| 8942 | |
| 8943 | case M_S_DAB: |
| 8944 | gas_assert (!mips_opts.micromips); |
| 8945 | /* Itbl support may require additional care here. */ |
| 8946 | coproc = 1; |
| 8947 | fmt = "T,o(b)"; |
| 8948 | if (mips_opts.isa != ISA_MIPS1) |
| 8949 | { |
| 8950 | s = "sdc1"; |
| 8951 | goto ld_st; |
| 8952 | } |
| 8953 | s = "swc1"; |
| 8954 | goto ldd_std; |
| 8955 | |
| 8956 | case M_LD_AB: |
| 8957 | fmt = "t,o(b)"; |
| 8958 | if (HAVE_64BIT_GPRS) |
| 8959 | { |
| 8960 | s = "ld"; |
| 8961 | goto ld; |
| 8962 | } |
| 8963 | s = "lw"; |
| 8964 | goto ldd_std; |
| 8965 | |
| 8966 | case M_SD_AB: |
| 8967 | fmt = "t,o(b)"; |
| 8968 | if (HAVE_64BIT_GPRS) |
| 8969 | { |
| 8970 | s = "sd"; |
| 8971 | goto ld_st; |
| 8972 | } |
| 8973 | s = "sw"; |
| 8974 | |
| 8975 | ldd_std: |
| 8976 | if (offset_expr.X_op != O_symbol |
| 8977 | && offset_expr.X_op != O_constant) |
| 8978 | { |
| 8979 | as_bad (_("Expression too complex")); |
| 8980 | offset_expr.X_op = O_constant; |
| 8981 | } |
| 8982 | |
| 8983 | if (HAVE_32BIT_ADDRESSES |
| 8984 | && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number)) |
| 8985 | { |
| 8986 | char value [32]; |
| 8987 | |
| 8988 | sprintf_vma (value, offset_expr.X_add_number); |
| 8989 | as_bad (_("Number (0x%s) larger than 32 bits"), value); |
| 8990 | } |
| 8991 | |
| 8992 | /* Even on a big endian machine $fn comes before $fn+1. We have |
| 8993 | to adjust when loading from memory. We set coproc if we must |
| 8994 | load $fn+1 first. */ |
| 8995 | /* Itbl support may require additional care here. */ |
| 8996 | if (!target_big_endian) |
| 8997 | coproc = 0; |
| 8998 | |
| 8999 | if (mips_pic == NO_PIC || offset_expr.X_op == O_constant) |
| 9000 | { |
| 9001 | /* If this is a reference to a GP relative symbol, we want |
| 9002 | <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16) |
| 9003 | <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16) |
| 9004 | If we have a base register, we use this |
| 9005 | addu $at,$breg,$gp |
| 9006 | <op> $treg,<sym>($at) (BFD_RELOC_GPREL16) |
| 9007 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16) |
| 9008 | If this is not a GP relative symbol, we want |
| 9009 | lui $at,<sym> (BFD_RELOC_HI16_S) |
| 9010 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) |
| 9011 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) |
| 9012 | If there is a base register, we add it to $at after the |
| 9013 | lui instruction. If there is a constant, we always use |
| 9014 | the last case. */ |
| 9015 | if (offset_expr.X_op == O_symbol |
| 9016 | && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET |
| 9017 | && !nopic_need_relax (offset_expr.X_add_symbol, 1)) |
| 9018 | { |
| 9019 | relax_start (offset_expr.X_add_symbol); |
| 9020 | if (breg == 0) |
| 9021 | { |
| 9022 | tempreg = mips_gp_register; |
| 9023 | } |
| 9024 | else |
| 9025 | { |
| 9026 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 9027 | AT, breg, mips_gp_register); |
| 9028 | tempreg = AT; |
| 9029 | used_at = 1; |
| 9030 | } |
| 9031 | |
| 9032 | /* Itbl support may require additional care here. */ |
| 9033 | macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg, |
| 9034 | BFD_RELOC_GPREL16, tempreg); |
| 9035 | offset_expr.X_add_number += 4; |
| 9036 | |
| 9037 | /* Set mips_optimize to 2 to avoid inserting an |
| 9038 | undesired nop. */ |
| 9039 | hold_mips_optimize = mips_optimize; |
| 9040 | mips_optimize = 2; |
| 9041 | /* Itbl support may require additional care here. */ |
| 9042 | macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1, |
| 9043 | BFD_RELOC_GPREL16, tempreg); |
| 9044 | mips_optimize = hold_mips_optimize; |
| 9045 | |
| 9046 | relax_switch (); |
| 9047 | |
| 9048 | offset_expr.X_add_number -= 4; |
| 9049 | } |
| 9050 | used_at = 1; |
| 9051 | macro_build_lui (&offset_expr, AT); |
| 9052 | if (breg != 0) |
| 9053 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT); |
| 9054 | /* Itbl support may require additional care here. */ |
| 9055 | macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg, |
| 9056 | BFD_RELOC_LO16, AT); |
| 9057 | /* FIXME: How do we handle overflow here? */ |
| 9058 | offset_expr.X_add_number += 4; |
| 9059 | /* Itbl support may require additional care here. */ |
| 9060 | macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1, |
| 9061 | BFD_RELOC_LO16, AT); |
| 9062 | if (mips_relax.sequence) |
| 9063 | relax_end (); |
| 9064 | } |
| 9065 | else if (!mips_big_got) |
| 9066 | { |
| 9067 | /* If this is a reference to an external symbol, we want |
| 9068 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 9069 | nop |
| 9070 | <op> $treg,0($at) |
| 9071 | <op> $treg+1,4($at) |
| 9072 | Otherwise we want |
| 9073 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 9074 | nop |
| 9075 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) |
| 9076 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) |
| 9077 | If there is a base register we add it to $at before the |
| 9078 | lwc1 instructions. If there is a constant we include it |
| 9079 | in the lwc1 instructions. */ |
| 9080 | used_at = 1; |
| 9081 | expr1.X_add_number = offset_expr.X_add_number; |
| 9082 | if (expr1.X_add_number < -0x8000 |
| 9083 | || expr1.X_add_number >= 0x8000 - 4) |
| 9084 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 9085 | load_got_offset (AT, &offset_expr); |
| 9086 | load_delay_nop (); |
| 9087 | if (breg != 0) |
| 9088 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT); |
| 9089 | |
| 9090 | /* Set mips_optimize to 2 to avoid inserting an undesired |
| 9091 | nop. */ |
| 9092 | hold_mips_optimize = mips_optimize; |
| 9093 | mips_optimize = 2; |
| 9094 | |
| 9095 | /* Itbl support may require additional care here. */ |
| 9096 | relax_start (offset_expr.X_add_symbol); |
| 9097 | macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg, |
| 9098 | BFD_RELOC_LO16, AT); |
| 9099 | expr1.X_add_number += 4; |
| 9100 | macro_build (&expr1, s, fmt, coproc ? treg : treg + 1, |
| 9101 | BFD_RELOC_LO16, AT); |
| 9102 | relax_switch (); |
| 9103 | macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg, |
| 9104 | BFD_RELOC_LO16, AT); |
| 9105 | offset_expr.X_add_number += 4; |
| 9106 | macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1, |
| 9107 | BFD_RELOC_LO16, AT); |
| 9108 | relax_end (); |
| 9109 | |
| 9110 | mips_optimize = hold_mips_optimize; |
| 9111 | } |
| 9112 | else if (mips_big_got) |
| 9113 | { |
| 9114 | int gpdelay; |
| 9115 | |
| 9116 | /* If this is a reference to an external symbol, we want |
| 9117 | lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16) |
| 9118 | addu $at,$at,$gp |
| 9119 | lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16) |
| 9120 | nop |
| 9121 | <op> $treg,0($at) |
| 9122 | <op> $treg+1,4($at) |
| 9123 | Otherwise we want |
| 9124 | lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16) |
| 9125 | nop |
| 9126 | <op> $treg,<sym>($at) (BFD_RELOC_LO16) |
| 9127 | <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16) |
| 9128 | If there is a base register we add it to $at before the |
| 9129 | lwc1 instructions. If there is a constant we include it |
| 9130 | in the lwc1 instructions. */ |
| 9131 | used_at = 1; |
| 9132 | expr1.X_add_number = offset_expr.X_add_number; |
| 9133 | offset_expr.X_add_number = 0; |
| 9134 | if (expr1.X_add_number < -0x8000 |
| 9135 | || expr1.X_add_number >= 0x8000 - 4) |
| 9136 | as_bad (_("PIC code offset overflow (max 16 signed bits)")); |
| 9137 | gpdelay = reg_needs_delay (mips_gp_register); |
| 9138 | relax_start (offset_expr.X_add_symbol); |
| 9139 | macro_build (&offset_expr, "lui", LUI_FMT, |
| 9140 | AT, BFD_RELOC_MIPS_GOT_HI16); |
| 9141 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 9142 | AT, AT, mips_gp_register); |
| 9143 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", |
| 9144 | AT, BFD_RELOC_MIPS_GOT_LO16, AT); |
| 9145 | load_delay_nop (); |
| 9146 | if (breg != 0) |
| 9147 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT); |
| 9148 | /* Itbl support may require additional care here. */ |
| 9149 | macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg, |
| 9150 | BFD_RELOC_LO16, AT); |
| 9151 | expr1.X_add_number += 4; |
| 9152 | |
| 9153 | /* Set mips_optimize to 2 to avoid inserting an undesired |
| 9154 | nop. */ |
| 9155 | hold_mips_optimize = mips_optimize; |
| 9156 | mips_optimize = 2; |
| 9157 | /* Itbl support may require additional care here. */ |
| 9158 | macro_build (&expr1, s, fmt, coproc ? treg : treg + 1, |
| 9159 | BFD_RELOC_LO16, AT); |
| 9160 | mips_optimize = hold_mips_optimize; |
| 9161 | expr1.X_add_number -= 4; |
| 9162 | |
| 9163 | relax_switch (); |
| 9164 | offset_expr.X_add_number = expr1.X_add_number; |
| 9165 | if (gpdelay) |
| 9166 | macro_build (NULL, "nop", ""); |
| 9167 | macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT, |
| 9168 | BFD_RELOC_MIPS_GOT16, mips_gp_register); |
| 9169 | load_delay_nop (); |
| 9170 | if (breg != 0) |
| 9171 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT); |
| 9172 | /* Itbl support may require additional care here. */ |
| 9173 | macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg, |
| 9174 | BFD_RELOC_LO16, AT); |
| 9175 | offset_expr.X_add_number += 4; |
| 9176 | |
| 9177 | /* Set mips_optimize to 2 to avoid inserting an undesired |
| 9178 | nop. */ |
| 9179 | hold_mips_optimize = mips_optimize; |
| 9180 | mips_optimize = 2; |
| 9181 | /* Itbl support may require additional care here. */ |
| 9182 | macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1, |
| 9183 | BFD_RELOC_LO16, AT); |
| 9184 | mips_optimize = hold_mips_optimize; |
| 9185 | relax_end (); |
| 9186 | } |
| 9187 | else |
| 9188 | abort (); |
| 9189 | |
| 9190 | break; |
| 9191 | |
| 9192 | case M_LD_OB: |
| 9193 | s = HAVE_64BIT_GPRS ? "ld" : "lw"; |
| 9194 | goto sd_ob; |
| 9195 | case M_SD_OB: |
| 9196 | s = HAVE_64BIT_GPRS ? "sd" : "sw"; |
| 9197 | sd_ob: |
| 9198 | macro_build (&offset_expr, s, "t,o(b)", treg, |
| 9199 | -1, offset_reloc[0], offset_reloc[1], offset_reloc[2], |
| 9200 | breg); |
| 9201 | if (!HAVE_64BIT_GPRS) |
| 9202 | { |
| 9203 | offset_expr.X_add_number += 4; |
| 9204 | macro_build (&offset_expr, s, "t,o(b)", treg + 1, |
| 9205 | -1, offset_reloc[0], offset_reloc[1], offset_reloc[2], |
| 9206 | breg); |
| 9207 | } |
| 9208 | break; |
| 9209 | |
| 9210 | |
| 9211 | case M_SAA_AB: |
| 9212 | ab = 1; |
| 9213 | case M_SAA_OB: |
| 9214 | s = "saa"; |
| 9215 | off0 = 1; |
| 9216 | fmt = "t,(b)"; |
| 9217 | goto ld_st; |
| 9218 | case M_SAAD_AB: |
| 9219 | ab = 1; |
| 9220 | case M_SAAD_OB: |
| 9221 | s = "saad"; |
| 9222 | off0 = 1; |
| 9223 | fmt = "t,(b)"; |
| 9224 | goto ld_st; |
| 9225 | |
| 9226 | /* New code added to support COPZ instructions. |
| 9227 | This code builds table entries out of the macros in mip_opcodes. |
| 9228 | R4000 uses interlocks to handle coproc delays. |
| 9229 | Other chips (like the R3000) require nops to be inserted for delays. |
| 9230 | |
| 9231 | FIXME: Currently, we require that the user handle delays. |
| 9232 | In order to fill delay slots for non-interlocked chips, |
| 9233 | we must have a way to specify delays based on the coprocessor. |
| 9234 | Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc. |
| 9235 | What are the side-effects of the cop instruction? |
| 9236 | What cache support might we have and what are its effects? |
| 9237 | Both coprocessor & memory require delays. how long??? |
| 9238 | What registers are read/set/modified? |
| 9239 | |
| 9240 | If an itbl is provided to interpret cop instructions, |
| 9241 | this knowledge can be encoded in the itbl spec. */ |
| 9242 | |
| 9243 | case M_COP0: |
| 9244 | s = "c0"; |
| 9245 | goto copz; |
| 9246 | case M_COP1: |
| 9247 | s = "c1"; |
| 9248 | goto copz; |
| 9249 | case M_COP2: |
| 9250 | s = "c2"; |
| 9251 | goto copz; |
| 9252 | case M_COP3: |
| 9253 | s = "c3"; |
| 9254 | copz: |
| 9255 | gas_assert (!mips_opts.micromips); |
| 9256 | /* For now we just do C (same as Cz). The parameter will be |
| 9257 | stored in insn_opcode by mips_ip. */ |
| 9258 | macro_build (NULL, s, "C", ip->insn_opcode); |
| 9259 | break; |
| 9260 | |
| 9261 | case M_MOVE: |
| 9262 | move_register (dreg, sreg); |
| 9263 | break; |
| 9264 | |
| 9265 | case M_DMUL: |
| 9266 | dbl = 1; |
| 9267 | case M_MUL: |
| 9268 | macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg); |
| 9269 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
| 9270 | break; |
| 9271 | |
| 9272 | case M_DMUL_I: |
| 9273 | dbl = 1; |
| 9274 | case M_MUL_I: |
| 9275 | /* The MIPS assembler some times generates shifts and adds. I'm |
| 9276 | not trying to be that fancy. GCC should do this for us |
| 9277 | anyway. */ |
| 9278 | used_at = 1; |
| 9279 | load_register (AT, &imm_expr, dbl); |
| 9280 | macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT); |
| 9281 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
| 9282 | break; |
| 9283 | |
| 9284 | case M_DMULO_I: |
| 9285 | dbl = 1; |
| 9286 | case M_MULO_I: |
| 9287 | imm = 1; |
| 9288 | goto do_mulo; |
| 9289 | |
| 9290 | case M_DMULO: |
| 9291 | dbl = 1; |
| 9292 | case M_MULO: |
| 9293 | do_mulo: |
| 9294 | start_noreorder (); |
| 9295 | used_at = 1; |
| 9296 | if (imm) |
| 9297 | load_register (AT, &imm_expr, dbl); |
| 9298 | macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg); |
| 9299 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
| 9300 | macro_build (NULL, dbl ? "dsra32" : "sra", SHFT_FMT, dreg, dreg, RA); |
| 9301 | macro_build (NULL, "mfhi", MFHL_FMT, AT); |
| 9302 | if (mips_trap) |
| 9303 | macro_build (NULL, "tne", TRAP_FMT, dreg, AT, 6); |
| 9304 | else |
| 9305 | { |
| 9306 | if (mips_opts.micromips) |
| 9307 | micromips_label_expr (&label_expr); |
| 9308 | else |
| 9309 | label_expr.X_add_number = 8; |
| 9310 | macro_build (&label_expr, "beq", "s,t,p", dreg, AT); |
| 9311 | macro_build (NULL, "nop", ""); |
| 9312 | macro_build (NULL, "break", BRK_FMT, 6); |
| 9313 | if (mips_opts.micromips) |
| 9314 | micromips_add_label (); |
| 9315 | } |
| 9316 | end_noreorder (); |
| 9317 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
| 9318 | break; |
| 9319 | |
| 9320 | case M_DMULOU_I: |
| 9321 | dbl = 1; |
| 9322 | case M_MULOU_I: |
| 9323 | imm = 1; |
| 9324 | goto do_mulou; |
| 9325 | |
| 9326 | case M_DMULOU: |
| 9327 | dbl = 1; |
| 9328 | case M_MULOU: |
| 9329 | do_mulou: |
| 9330 | start_noreorder (); |
| 9331 | used_at = 1; |
| 9332 | if (imm) |
| 9333 | load_register (AT, &imm_expr, dbl); |
| 9334 | macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", |
| 9335 | sreg, imm ? AT : treg); |
| 9336 | macro_build (NULL, "mfhi", MFHL_FMT, AT); |
| 9337 | macro_build (NULL, "mflo", MFHL_FMT, dreg); |
| 9338 | if (mips_trap) |
| 9339 | macro_build (NULL, "tne", TRAP_FMT, AT, ZERO, 6); |
| 9340 | else |
| 9341 | { |
| 9342 | if (mips_opts.micromips) |
| 9343 | micromips_label_expr (&label_expr); |
| 9344 | else |
| 9345 | label_expr.X_add_number = 8; |
| 9346 | macro_build (&label_expr, "beq", "s,t,p", AT, ZERO); |
| 9347 | macro_build (NULL, "nop", ""); |
| 9348 | macro_build (NULL, "break", BRK_FMT, 6); |
| 9349 | if (mips_opts.micromips) |
| 9350 | micromips_add_label (); |
| 9351 | } |
| 9352 | end_noreorder (); |
| 9353 | break; |
| 9354 | |
| 9355 | case M_DROL: |
| 9356 | if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch)) |
| 9357 | { |
| 9358 | if (dreg == sreg) |
| 9359 | { |
| 9360 | tempreg = AT; |
| 9361 | used_at = 1; |
| 9362 | } |
| 9363 | else |
| 9364 | { |
| 9365 | tempreg = dreg; |
| 9366 | } |
| 9367 | macro_build (NULL, "dnegu", "d,w", tempreg, treg); |
| 9368 | macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg); |
| 9369 | break; |
| 9370 | } |
| 9371 | used_at = 1; |
| 9372 | macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg); |
| 9373 | macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT); |
| 9374 | macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg); |
| 9375 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
| 9376 | break; |
| 9377 | |
| 9378 | case M_ROL: |
| 9379 | if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch)) |
| 9380 | { |
| 9381 | if (dreg == sreg) |
| 9382 | { |
| 9383 | tempreg = AT; |
| 9384 | used_at = 1; |
| 9385 | } |
| 9386 | else |
| 9387 | { |
| 9388 | tempreg = dreg; |
| 9389 | } |
| 9390 | macro_build (NULL, "negu", "d,w", tempreg, treg); |
| 9391 | macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg); |
| 9392 | break; |
| 9393 | } |
| 9394 | used_at = 1; |
| 9395 | macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg); |
| 9396 | macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT); |
| 9397 | macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg); |
| 9398 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
| 9399 | break; |
| 9400 | |
| 9401 | case M_DROL_I: |
| 9402 | { |
| 9403 | unsigned int rot; |
| 9404 | char *l; |
| 9405 | char *rr; |
| 9406 | |
| 9407 | if (imm_expr.X_op != O_constant) |
| 9408 | as_bad (_("Improper rotate count")); |
| 9409 | rot = imm_expr.X_add_number & 0x3f; |
| 9410 | if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch)) |
| 9411 | { |
| 9412 | rot = (64 - rot) & 0x3f; |
| 9413 | if (rot >= 32) |
| 9414 | macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32); |
| 9415 | else |
| 9416 | macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot); |
| 9417 | break; |
| 9418 | } |
| 9419 | if (rot == 0) |
| 9420 | { |
| 9421 | macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0); |
| 9422 | break; |
| 9423 | } |
| 9424 | l = (rot < 0x20) ? "dsll" : "dsll32"; |
| 9425 | rr = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32"; |
| 9426 | rot &= 0x1f; |
| 9427 | used_at = 1; |
| 9428 | macro_build (NULL, l, SHFT_FMT, AT, sreg, rot); |
| 9429 | macro_build (NULL, rr, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f); |
| 9430 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
| 9431 | } |
| 9432 | break; |
| 9433 | |
| 9434 | case M_ROL_I: |
| 9435 | { |
| 9436 | unsigned int rot; |
| 9437 | |
| 9438 | if (imm_expr.X_op != O_constant) |
| 9439 | as_bad (_("Improper rotate count")); |
| 9440 | rot = imm_expr.X_add_number & 0x1f; |
| 9441 | if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch)) |
| 9442 | { |
| 9443 | macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, (32 - rot) & 0x1f); |
| 9444 | break; |
| 9445 | } |
| 9446 | if (rot == 0) |
| 9447 | { |
| 9448 | macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0); |
| 9449 | break; |
| 9450 | } |
| 9451 | used_at = 1; |
| 9452 | macro_build (NULL, "sll", SHFT_FMT, AT, sreg, rot); |
| 9453 | macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f); |
| 9454 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
| 9455 | } |
| 9456 | break; |
| 9457 | |
| 9458 | case M_DROR: |
| 9459 | if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch)) |
| 9460 | { |
| 9461 | macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg); |
| 9462 | break; |
| 9463 | } |
| 9464 | used_at = 1; |
| 9465 | macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg); |
| 9466 | macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT); |
| 9467 | macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg); |
| 9468 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
| 9469 | break; |
| 9470 | |
| 9471 | case M_ROR: |
| 9472 | if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch)) |
| 9473 | { |
| 9474 | macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg); |
| 9475 | break; |
| 9476 | } |
| 9477 | used_at = 1; |
| 9478 | macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg); |
| 9479 | macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT); |
| 9480 | macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg); |
| 9481 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
| 9482 | break; |
| 9483 | |
| 9484 | case M_DROR_I: |
| 9485 | { |
| 9486 | unsigned int rot; |
| 9487 | char *l; |
| 9488 | char *rr; |
| 9489 | |
| 9490 | if (imm_expr.X_op != O_constant) |
| 9491 | as_bad (_("Improper rotate count")); |
| 9492 | rot = imm_expr.X_add_number & 0x3f; |
| 9493 | if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch)) |
| 9494 | { |
| 9495 | if (rot >= 32) |
| 9496 | macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32); |
| 9497 | else |
| 9498 | macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot); |
| 9499 | break; |
| 9500 | } |
| 9501 | if (rot == 0) |
| 9502 | { |
| 9503 | macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0); |
| 9504 | break; |
| 9505 | } |
| 9506 | rr = (rot < 0x20) ? "dsrl" : "dsrl32"; |
| 9507 | l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32"; |
| 9508 | rot &= 0x1f; |
| 9509 | used_at = 1; |
| 9510 | macro_build (NULL, rr, SHFT_FMT, AT, sreg, rot); |
| 9511 | macro_build (NULL, l, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f); |
| 9512 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
| 9513 | } |
| 9514 | break; |
| 9515 | |
| 9516 | case M_ROR_I: |
| 9517 | { |
| 9518 | unsigned int rot; |
| 9519 | |
| 9520 | if (imm_expr.X_op != O_constant) |
| 9521 | as_bad (_("Improper rotate count")); |
| 9522 | rot = imm_expr.X_add_number & 0x1f; |
| 9523 | if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch)) |
| 9524 | { |
| 9525 | macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, rot); |
| 9526 | break; |
| 9527 | } |
| 9528 | if (rot == 0) |
| 9529 | { |
| 9530 | macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0); |
| 9531 | break; |
| 9532 | } |
| 9533 | used_at = 1; |
| 9534 | macro_build (NULL, "srl", SHFT_FMT, AT, sreg, rot); |
| 9535 | macro_build (NULL, "sll", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f); |
| 9536 | macro_build (NULL, "or", "d,v,t", dreg, dreg, AT); |
| 9537 | } |
| 9538 | break; |
| 9539 | |
| 9540 | case M_SEQ: |
| 9541 | if (sreg == 0) |
| 9542 | macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16); |
| 9543 | else if (treg == 0) |
| 9544 | macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
| 9545 | else |
| 9546 | { |
| 9547 | macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg); |
| 9548 | macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16); |
| 9549 | } |
| 9550 | break; |
| 9551 | |
| 9552 | case M_SEQ_I: |
| 9553 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
| 9554 | { |
| 9555 | macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
| 9556 | break; |
| 9557 | } |
| 9558 | if (sreg == 0) |
| 9559 | { |
| 9560 | as_warn (_("Instruction %s: result is always false"), |
| 9561 | ip->insn_mo->name); |
| 9562 | move_register (dreg, 0); |
| 9563 | break; |
| 9564 | } |
| 9565 | if (CPU_HAS_SEQ (mips_opts.arch) |
| 9566 | && -512 <= imm_expr.X_add_number |
| 9567 | && imm_expr.X_add_number < 512) |
| 9568 | { |
| 9569 | macro_build (NULL, "seqi", "t,r,+Q", dreg, sreg, |
| 9570 | (int) imm_expr.X_add_number); |
| 9571 | break; |
| 9572 | } |
| 9573 | if (imm_expr.X_op == O_constant |
| 9574 | && imm_expr.X_add_number >= 0 |
| 9575 | && imm_expr.X_add_number < 0x10000) |
| 9576 | { |
| 9577 | macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16); |
| 9578 | } |
| 9579 | else if (imm_expr.X_op == O_constant |
| 9580 | && imm_expr.X_add_number > -0x8000 |
| 9581 | && imm_expr.X_add_number < 0) |
| 9582 | { |
| 9583 | imm_expr.X_add_number = -imm_expr.X_add_number; |
| 9584 | macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
| 9585 | "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
| 9586 | } |
| 9587 | else if (CPU_HAS_SEQ (mips_opts.arch)) |
| 9588 | { |
| 9589 | used_at = 1; |
| 9590 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9591 | macro_build (NULL, "seq", "d,v,t", dreg, sreg, AT); |
| 9592 | break; |
| 9593 | } |
| 9594 | else |
| 9595 | { |
| 9596 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9597 | macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT); |
| 9598 | used_at = 1; |
| 9599 | } |
| 9600 | macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16); |
| 9601 | break; |
| 9602 | |
| 9603 | case M_SGE: /* sreg >= treg <==> not (sreg < treg) */ |
| 9604 | s = "slt"; |
| 9605 | goto sge; |
| 9606 | case M_SGEU: |
| 9607 | s = "sltu"; |
| 9608 | sge: |
| 9609 | macro_build (NULL, s, "d,v,t", dreg, sreg, treg); |
| 9610 | macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16); |
| 9611 | break; |
| 9612 | |
| 9613 | case M_SGE_I: /* sreg >= I <==> not (sreg < I) */ |
| 9614 | case M_SGEU_I: |
| 9615 | if (imm_expr.X_op == O_constant |
| 9616 | && imm_expr.X_add_number >= -0x8000 |
| 9617 | && imm_expr.X_add_number < 0x8000) |
| 9618 | { |
| 9619 | macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j", |
| 9620 | dreg, sreg, BFD_RELOC_LO16); |
| 9621 | } |
| 9622 | else |
| 9623 | { |
| 9624 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9625 | macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t", |
| 9626 | dreg, sreg, AT); |
| 9627 | used_at = 1; |
| 9628 | } |
| 9629 | macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16); |
| 9630 | break; |
| 9631 | |
| 9632 | case M_SGT: /* sreg > treg <==> treg < sreg */ |
| 9633 | s = "slt"; |
| 9634 | goto sgt; |
| 9635 | case M_SGTU: |
| 9636 | s = "sltu"; |
| 9637 | sgt: |
| 9638 | macro_build (NULL, s, "d,v,t", dreg, treg, sreg); |
| 9639 | break; |
| 9640 | |
| 9641 | case M_SGT_I: /* sreg > I <==> I < sreg */ |
| 9642 | s = "slt"; |
| 9643 | goto sgti; |
| 9644 | case M_SGTU_I: |
| 9645 | s = "sltu"; |
| 9646 | sgti: |
| 9647 | used_at = 1; |
| 9648 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9649 | macro_build (NULL, s, "d,v,t", dreg, AT, sreg); |
| 9650 | break; |
| 9651 | |
| 9652 | case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */ |
| 9653 | s = "slt"; |
| 9654 | goto sle; |
| 9655 | case M_SLEU: |
| 9656 | s = "sltu"; |
| 9657 | sle: |
| 9658 | macro_build (NULL, s, "d,v,t", dreg, treg, sreg); |
| 9659 | macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16); |
| 9660 | break; |
| 9661 | |
| 9662 | case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */ |
| 9663 | s = "slt"; |
| 9664 | goto slei; |
| 9665 | case M_SLEU_I: |
| 9666 | s = "sltu"; |
| 9667 | slei: |
| 9668 | used_at = 1; |
| 9669 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9670 | macro_build (NULL, s, "d,v,t", dreg, AT, sreg); |
| 9671 | macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16); |
| 9672 | break; |
| 9673 | |
| 9674 | case M_SLT_I: |
| 9675 | if (imm_expr.X_op == O_constant |
| 9676 | && imm_expr.X_add_number >= -0x8000 |
| 9677 | && imm_expr.X_add_number < 0x8000) |
| 9678 | { |
| 9679 | macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
| 9680 | break; |
| 9681 | } |
| 9682 | used_at = 1; |
| 9683 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9684 | macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT); |
| 9685 | break; |
| 9686 | |
| 9687 | case M_SLTU_I: |
| 9688 | if (imm_expr.X_op == O_constant |
| 9689 | && imm_expr.X_add_number >= -0x8000 |
| 9690 | && imm_expr.X_add_number < 0x8000) |
| 9691 | { |
| 9692 | macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg, |
| 9693 | BFD_RELOC_LO16); |
| 9694 | break; |
| 9695 | } |
| 9696 | used_at = 1; |
| 9697 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9698 | macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT); |
| 9699 | break; |
| 9700 | |
| 9701 | case M_SNE: |
| 9702 | if (sreg == 0) |
| 9703 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg); |
| 9704 | else if (treg == 0) |
| 9705 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg); |
| 9706 | else |
| 9707 | { |
| 9708 | macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg); |
| 9709 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg); |
| 9710 | } |
| 9711 | break; |
| 9712 | |
| 9713 | case M_SNE_I: |
| 9714 | if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0) |
| 9715 | { |
| 9716 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg); |
| 9717 | break; |
| 9718 | } |
| 9719 | if (sreg == 0) |
| 9720 | { |
| 9721 | as_warn (_("Instruction %s: result is always true"), |
| 9722 | ip->insn_mo->name); |
| 9723 | macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j", |
| 9724 | dreg, 0, BFD_RELOC_LO16); |
| 9725 | break; |
| 9726 | } |
| 9727 | if (CPU_HAS_SEQ (mips_opts.arch) |
| 9728 | && -512 <= imm_expr.X_add_number |
| 9729 | && imm_expr.X_add_number < 512) |
| 9730 | { |
| 9731 | macro_build (NULL, "snei", "t,r,+Q", dreg, sreg, |
| 9732 | (int) imm_expr.X_add_number); |
| 9733 | break; |
| 9734 | } |
| 9735 | if (imm_expr.X_op == O_constant |
| 9736 | && imm_expr.X_add_number >= 0 |
| 9737 | && imm_expr.X_add_number < 0x10000) |
| 9738 | { |
| 9739 | macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16); |
| 9740 | } |
| 9741 | else if (imm_expr.X_op == O_constant |
| 9742 | && imm_expr.X_add_number > -0x8000 |
| 9743 | && imm_expr.X_add_number < 0) |
| 9744 | { |
| 9745 | imm_expr.X_add_number = -imm_expr.X_add_number; |
| 9746 | macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu", |
| 9747 | "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
| 9748 | } |
| 9749 | else if (CPU_HAS_SEQ (mips_opts.arch)) |
| 9750 | { |
| 9751 | used_at = 1; |
| 9752 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9753 | macro_build (NULL, "sne", "d,v,t", dreg, sreg, AT); |
| 9754 | break; |
| 9755 | } |
| 9756 | else |
| 9757 | { |
| 9758 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9759 | macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT); |
| 9760 | used_at = 1; |
| 9761 | } |
| 9762 | macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg); |
| 9763 | break; |
| 9764 | |
| 9765 | case M_SUB_I: |
| 9766 | s = "addi"; |
| 9767 | s2 = "sub"; |
| 9768 | goto do_subi; |
| 9769 | case M_SUBU_I: |
| 9770 | s = "addiu"; |
| 9771 | s2 = "subu"; |
| 9772 | goto do_subi; |
| 9773 | case M_DSUB_I: |
| 9774 | dbl = 1; |
| 9775 | s = "daddi"; |
| 9776 | s2 = "dsub"; |
| 9777 | if (!mips_opts.micromips) |
| 9778 | goto do_subi; |
| 9779 | if (imm_expr.X_op == O_constant |
| 9780 | && imm_expr.X_add_number > -0x200 |
| 9781 | && imm_expr.X_add_number <= 0x200) |
| 9782 | { |
| 9783 | macro_build (NULL, s, "t,r,.", dreg, sreg, -imm_expr.X_add_number); |
| 9784 | break; |
| 9785 | } |
| 9786 | goto do_subi_i; |
| 9787 | case M_DSUBU_I: |
| 9788 | dbl = 1; |
| 9789 | s = "daddiu"; |
| 9790 | s2 = "dsubu"; |
| 9791 | do_subi: |
| 9792 | if (imm_expr.X_op == O_constant |
| 9793 | && imm_expr.X_add_number > -0x8000 |
| 9794 | && imm_expr.X_add_number <= 0x8000) |
| 9795 | { |
| 9796 | imm_expr.X_add_number = -imm_expr.X_add_number; |
| 9797 | macro_build (&imm_expr, s, "t,r,j", dreg, sreg, BFD_RELOC_LO16); |
| 9798 | break; |
| 9799 | } |
| 9800 | do_subi_i: |
| 9801 | used_at = 1; |
| 9802 | load_register (AT, &imm_expr, dbl); |
| 9803 | macro_build (NULL, s2, "d,v,t", dreg, sreg, AT); |
| 9804 | break; |
| 9805 | |
| 9806 | case M_TEQ_I: |
| 9807 | s = "teq"; |
| 9808 | goto trap; |
| 9809 | case M_TGE_I: |
| 9810 | s = "tge"; |
| 9811 | goto trap; |
| 9812 | case M_TGEU_I: |
| 9813 | s = "tgeu"; |
| 9814 | goto trap; |
| 9815 | case M_TLT_I: |
| 9816 | s = "tlt"; |
| 9817 | goto trap; |
| 9818 | case M_TLTU_I: |
| 9819 | s = "tltu"; |
| 9820 | goto trap; |
| 9821 | case M_TNE_I: |
| 9822 | s = "tne"; |
| 9823 | trap: |
| 9824 | used_at = 1; |
| 9825 | load_register (AT, &imm_expr, HAVE_64BIT_GPRS); |
| 9826 | macro_build (NULL, s, "s,t", sreg, AT); |
| 9827 | break; |
| 9828 | |
| 9829 | case M_TRUNCWS: |
| 9830 | case M_TRUNCWD: |
| 9831 | gas_assert (!mips_opts.micromips); |
| 9832 | gas_assert (mips_opts.isa == ISA_MIPS1); |
| 9833 | used_at = 1; |
| 9834 | sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */ |
| 9835 | dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */ |
| 9836 | |
| 9837 | /* |
| 9838 | * Is the double cfc1 instruction a bug in the mips assembler; |
| 9839 | * or is there a reason for it? |
| 9840 | */ |
| 9841 | start_noreorder (); |
| 9842 | macro_build (NULL, "cfc1", "t,G", treg, RA); |
| 9843 | macro_build (NULL, "cfc1", "t,G", treg, RA); |
| 9844 | macro_build (NULL, "nop", ""); |
| 9845 | expr1.X_add_number = 3; |
| 9846 | macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16); |
| 9847 | expr1.X_add_number = 2; |
| 9848 | macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16); |
| 9849 | macro_build (NULL, "ctc1", "t,G", AT, RA); |
| 9850 | macro_build (NULL, "nop", ""); |
| 9851 | macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", |
| 9852 | dreg, sreg); |
| 9853 | macro_build (NULL, "ctc1", "t,G", treg, RA); |
| 9854 | macro_build (NULL, "nop", ""); |
| 9855 | end_noreorder (); |
| 9856 | break; |
| 9857 | |
| 9858 | case M_ULH_A: |
| 9859 | ab = 1; |
| 9860 | case M_ULH: |
| 9861 | s = "lb"; |
| 9862 | s2 = "lbu"; |
| 9863 | off = 1; |
| 9864 | goto uld_st; |
| 9865 | case M_ULHU_A: |
| 9866 | ab = 1; |
| 9867 | case M_ULHU: |
| 9868 | s = "lbu"; |
| 9869 | s2 = "lbu"; |
| 9870 | off = 1; |
| 9871 | goto uld_st; |
| 9872 | case M_ULW_A: |
| 9873 | ab = 1; |
| 9874 | case M_ULW: |
| 9875 | s = "lwl"; |
| 9876 | s2 = "lwr"; |
| 9877 | off12 = mips_opts.micromips; |
| 9878 | off = 3; |
| 9879 | goto uld_st; |
| 9880 | case M_ULD_A: |
| 9881 | ab = 1; |
| 9882 | case M_ULD: |
| 9883 | s = "ldl"; |
| 9884 | s2 = "ldr"; |
| 9885 | off12 = mips_opts.micromips; |
| 9886 | off = 7; |
| 9887 | goto uld_st; |
| 9888 | case M_USH_A: |
| 9889 | ab = 1; |
| 9890 | case M_USH: |
| 9891 | s = "sb"; |
| 9892 | s2 = "sb"; |
| 9893 | off = 1; |
| 9894 | ust = 1; |
| 9895 | goto uld_st; |
| 9896 | case M_USW_A: |
| 9897 | ab = 1; |
| 9898 | case M_USW: |
| 9899 | s = "swl"; |
| 9900 | s2 = "swr"; |
| 9901 | off12 = mips_opts.micromips; |
| 9902 | off = 3; |
| 9903 | ust = 1; |
| 9904 | goto uld_st; |
| 9905 | case M_USD_A: |
| 9906 | ab = 1; |
| 9907 | case M_USD: |
| 9908 | s = "sdl"; |
| 9909 | s2 = "sdr"; |
| 9910 | off12 = mips_opts.micromips; |
| 9911 | off = 7; |
| 9912 | ust = 1; |
| 9913 | |
| 9914 | uld_st: |
| 9915 | if (!ab && offset_expr.X_add_number >= 0x8000 - off) |
| 9916 | as_bad (_("Operand overflow")); |
| 9917 | |
| 9918 | ep = &offset_expr; |
| 9919 | expr1.X_add_number = 0; |
| 9920 | if (ab) |
| 9921 | { |
| 9922 | used_at = 1; |
| 9923 | tempreg = AT; |
| 9924 | load_address (tempreg, ep, &used_at); |
| 9925 | if (breg != 0) |
| 9926 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", |
| 9927 | tempreg, tempreg, breg); |
| 9928 | breg = tempreg; |
| 9929 | tempreg = treg; |
| 9930 | ep = &expr1; |
| 9931 | } |
| 9932 | else if (off12 |
| 9933 | && (offset_expr.X_op != O_constant |
| 9934 | || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number) |
| 9935 | || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number + off))) |
| 9936 | { |
| 9937 | used_at = 1; |
| 9938 | tempreg = AT; |
| 9939 | macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", tempreg, breg, |
| 9940 | -1, offset_reloc[0], offset_reloc[1], offset_reloc[2]); |
| 9941 | breg = tempreg; |
| 9942 | tempreg = treg; |
| 9943 | ep = &expr1; |
| 9944 | } |
| 9945 | else if (!ust && treg == breg) |
| 9946 | { |
| 9947 | used_at = 1; |
| 9948 | tempreg = AT; |
| 9949 | } |
| 9950 | else |
| 9951 | tempreg = treg; |
| 9952 | |
| 9953 | if (off == 1) |
| 9954 | goto ulh_sh; |
| 9955 | |
| 9956 | if (!target_big_endian) |
| 9957 | ep->X_add_number += off; |
| 9958 | if (!off12) |
| 9959 | macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg); |
| 9960 | else |
| 9961 | macro_build (NULL, s, "t,~(b)", |
| 9962 | tempreg, (unsigned long) ep->X_add_number, breg); |
| 9963 | |
| 9964 | if (!target_big_endian) |
| 9965 | ep->X_add_number -= off; |
| 9966 | else |
| 9967 | ep->X_add_number += off; |
| 9968 | if (!off12) |
| 9969 | macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg); |
| 9970 | else |
| 9971 | macro_build (NULL, s2, "t,~(b)", |
| 9972 | tempreg, (unsigned long) ep->X_add_number, breg); |
| 9973 | |
| 9974 | /* If necessary, move the result in tempreg to the final destination. */ |
| 9975 | if (!ust && treg != tempreg) |
| 9976 | { |
| 9977 | /* Protect second load's delay slot. */ |
| 9978 | load_delay_nop (); |
| 9979 | move_register (treg, tempreg); |
| 9980 | } |
| 9981 | break; |
| 9982 | |
| 9983 | ulh_sh: |
| 9984 | used_at = 1; |
| 9985 | if (target_big_endian == ust) |
| 9986 | ep->X_add_number += off; |
| 9987 | tempreg = ust || ab ? treg : AT; |
| 9988 | macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg); |
| 9989 | |
| 9990 | /* For halfword transfers we need a temporary register to shuffle |
| 9991 | bytes. Unfortunately for M_USH_A we have none available before |
| 9992 | the next store as AT holds the base address. We deal with this |
| 9993 | case by clobbering TREG and then restoring it as with ULH. */ |
| 9994 | tempreg = ust == ab ? treg : AT; |
| 9995 | if (ust) |
| 9996 | macro_build (NULL, "srl", SHFT_FMT, tempreg, treg, 8); |
| 9997 | |
| 9998 | if (target_big_endian == ust) |
| 9999 | ep->X_add_number -= off; |
| 10000 | else |
| 10001 | ep->X_add_number += off; |
| 10002 | macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg); |
| 10003 | |
| 10004 | /* For M_USH_A re-retrieve the LSB. */ |
| 10005 | if (ust && ab) |
| 10006 | { |
| 10007 | if (target_big_endian) |
| 10008 | ep->X_add_number += off; |
| 10009 | else |
| 10010 | ep->X_add_number -= off; |
| 10011 | macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT); |
| 10012 | } |
| 10013 | /* For ULH and M_USH_A OR the LSB in. */ |
| 10014 | if (!ust || ab) |
| 10015 | { |
| 10016 | tempreg = !ab ? AT : treg; |
| 10017 | macro_build (NULL, "sll", SHFT_FMT, tempreg, tempreg, 8); |
| 10018 | macro_build (NULL, "or", "d,v,t", treg, treg, AT); |
| 10019 | } |
| 10020 | break; |
| 10021 | |
| 10022 | default: |
| 10023 | /* FIXME: Check if this is one of the itbl macros, since they |
| 10024 | are added dynamically. */ |
| 10025 | as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name); |
| 10026 | break; |
| 10027 | } |
| 10028 | if (!mips_opts.at && used_at) |
| 10029 | as_bad (_("Macro used $at after \".set noat\"")); |
| 10030 | } |
| 10031 | |
| 10032 | /* Implement macros in mips16 mode. */ |
| 10033 | |
| 10034 | static void |
| 10035 | mips16_macro (struct mips_cl_insn *ip) |
| 10036 | { |
| 10037 | int mask; |
| 10038 | int xreg, yreg, zreg, tmp; |
| 10039 | expressionS expr1; |
| 10040 | int dbl; |
| 10041 | const char *s, *s2, *s3; |
| 10042 | |
| 10043 | mask = ip->insn_mo->mask; |
| 10044 | |
| 10045 | xreg = MIPS16_EXTRACT_OPERAND (RX, *ip); |
| 10046 | yreg = MIPS16_EXTRACT_OPERAND (RY, *ip); |
| 10047 | zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip); |
| 10048 | |
| 10049 | expr1.X_op = O_constant; |
| 10050 | expr1.X_op_symbol = NULL; |
| 10051 | expr1.X_add_symbol = NULL; |
| 10052 | expr1.X_add_number = 1; |
| 10053 | |
| 10054 | dbl = 0; |
| 10055 | |
| 10056 | switch (mask) |
| 10057 | { |
| 10058 | default: |
| 10059 | internalError (); |
| 10060 | |
| 10061 | case M_DDIV_3: |
| 10062 | dbl = 1; |
| 10063 | case M_DIV_3: |
| 10064 | s = "mflo"; |
| 10065 | goto do_div3; |
| 10066 | case M_DREM_3: |
| 10067 | dbl = 1; |
| 10068 | case M_REM_3: |
| 10069 | s = "mfhi"; |
| 10070 | do_div3: |
| 10071 | start_noreorder (); |
| 10072 | macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg); |
| 10073 | expr1.X_add_number = 2; |
| 10074 | macro_build (&expr1, "bnez", "x,p", yreg); |
| 10075 | macro_build (NULL, "break", "6", 7); |
| 10076 | |
| 10077 | /* FIXME: The normal code checks for of -1 / -0x80000000 here, |
| 10078 | since that causes an overflow. We should do that as well, |
| 10079 | but I don't see how to do the comparisons without a temporary |
| 10080 | register. */ |
| 10081 | end_noreorder (); |
| 10082 | macro_build (NULL, s, "x", zreg); |
| 10083 | break; |
| 10084 | |
| 10085 | case M_DIVU_3: |
| 10086 | s = "divu"; |
| 10087 | s2 = "mflo"; |
| 10088 | goto do_divu3; |
| 10089 | case M_REMU_3: |
| 10090 | s = "divu"; |
| 10091 | s2 = "mfhi"; |
| 10092 | goto do_divu3; |
| 10093 | case M_DDIVU_3: |
| 10094 | s = "ddivu"; |
| 10095 | s2 = "mflo"; |
| 10096 | goto do_divu3; |
| 10097 | case M_DREMU_3: |
| 10098 | s = "ddivu"; |
| 10099 | s2 = "mfhi"; |
| 10100 | do_divu3: |
| 10101 | start_noreorder (); |
| 10102 | macro_build (NULL, s, "0,x,y", xreg, yreg); |
| 10103 | expr1.X_add_number = 2; |
| 10104 | macro_build (&expr1, "bnez", "x,p", yreg); |
| 10105 | macro_build (NULL, "break", "6", 7); |
| 10106 | end_noreorder (); |
| 10107 | macro_build (NULL, s2, "x", zreg); |
| 10108 | break; |
| 10109 | |
| 10110 | case M_DMUL: |
| 10111 | dbl = 1; |
| 10112 | case M_MUL: |
| 10113 | macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg); |
| 10114 | macro_build (NULL, "mflo", "x", zreg); |
| 10115 | break; |
| 10116 | |
| 10117 | case M_DSUBU_I: |
| 10118 | dbl = 1; |
| 10119 | goto do_subu; |
| 10120 | case M_SUBU_I: |
| 10121 | do_subu: |
| 10122 | if (imm_expr.X_op != O_constant) |
| 10123 | as_bad (_("Unsupported large constant")); |
| 10124 | imm_expr.X_add_number = -imm_expr.X_add_number; |
| 10125 | macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg); |
| 10126 | break; |
| 10127 | |
| 10128 | case M_SUBU_I_2: |
| 10129 | if (imm_expr.X_op != O_constant) |
| 10130 | as_bad (_("Unsupported large constant")); |
| 10131 | imm_expr.X_add_number = -imm_expr.X_add_number; |
| 10132 | macro_build (&imm_expr, "addiu", "x,k", xreg); |
| 10133 | break; |
| 10134 | |
| 10135 | case M_DSUBU_I_2: |
| 10136 | if (imm_expr.X_op != O_constant) |
| 10137 | as_bad (_("Unsupported large constant")); |
| 10138 | imm_expr.X_add_number = -imm_expr.X_add_number; |
| 10139 | macro_build (&imm_expr, "daddiu", "y,j", yreg); |
| 10140 | break; |
| 10141 | |
| 10142 | case M_BEQ: |
| 10143 | s = "cmp"; |
| 10144 | s2 = "bteqz"; |
| 10145 | goto do_branch; |
| 10146 | case M_BNE: |
| 10147 | s = "cmp"; |
| 10148 | s2 = "btnez"; |
| 10149 | goto do_branch; |
| 10150 | case M_BLT: |
| 10151 | s = "slt"; |
| 10152 | s2 = "btnez"; |
| 10153 | goto do_branch; |
| 10154 | case M_BLTU: |
| 10155 | s = "sltu"; |
| 10156 | s2 = "btnez"; |
| 10157 | goto do_branch; |
| 10158 | case M_BLE: |
| 10159 | s = "slt"; |
| 10160 | s2 = "bteqz"; |
| 10161 | goto do_reverse_branch; |
| 10162 | case M_BLEU: |
| 10163 | s = "sltu"; |
| 10164 | s2 = "bteqz"; |
| 10165 | goto do_reverse_branch; |
| 10166 | case M_BGE: |
| 10167 | s = "slt"; |
| 10168 | s2 = "bteqz"; |
| 10169 | goto do_branch; |
| 10170 | case M_BGEU: |
| 10171 | s = "sltu"; |
| 10172 | s2 = "bteqz"; |
| 10173 | goto do_branch; |
| 10174 | case M_BGT: |
| 10175 | s = "slt"; |
| 10176 | s2 = "btnez"; |
| 10177 | goto do_reverse_branch; |
| 10178 | case M_BGTU: |
| 10179 | s = "sltu"; |
| 10180 | s2 = "btnez"; |
| 10181 | |
| 10182 | do_reverse_branch: |
| 10183 | tmp = xreg; |
| 10184 | xreg = yreg; |
| 10185 | yreg = tmp; |
| 10186 | |
| 10187 | do_branch: |
| 10188 | macro_build (NULL, s, "x,y", xreg, yreg); |
| 10189 | macro_build (&offset_expr, s2, "p"); |
| 10190 | break; |
| 10191 | |
| 10192 | case M_BEQ_I: |
| 10193 | s = "cmpi"; |
| 10194 | s2 = "bteqz"; |
| 10195 | s3 = "x,U"; |
| 10196 | goto do_branch_i; |
| 10197 | case M_BNE_I: |
| 10198 | s = "cmpi"; |
| 10199 | s2 = "btnez"; |
| 10200 | s3 = "x,U"; |
| 10201 | goto do_branch_i; |
| 10202 | case M_BLT_I: |
| 10203 | s = "slti"; |
| 10204 | s2 = "btnez"; |
| 10205 | s3 = "x,8"; |
| 10206 | goto do_branch_i; |
| 10207 | case M_BLTU_I: |
| 10208 | s = "sltiu"; |
| 10209 | s2 = "btnez"; |
| 10210 | s3 = "x,8"; |
| 10211 | goto do_branch_i; |
| 10212 | case M_BLE_I: |
| 10213 | s = "slti"; |
| 10214 | s2 = "btnez"; |
| 10215 | s3 = "x,8"; |
| 10216 | goto do_addone_branch_i; |
| 10217 | case M_BLEU_I: |
| 10218 | s = "sltiu"; |
| 10219 | s2 = "btnez"; |
| 10220 | s3 = "x,8"; |
| 10221 | goto do_addone_branch_i; |
| 10222 | case M_BGE_I: |
| 10223 | s = "slti"; |
| 10224 | s2 = "bteqz"; |
| 10225 | s3 = "x,8"; |
| 10226 | goto do_branch_i; |
| 10227 | case M_BGEU_I: |
| 10228 | s = "sltiu"; |
| 10229 | s2 = "bteqz"; |
| 10230 | s3 = "x,8"; |
| 10231 | goto do_branch_i; |
| 10232 | case M_BGT_I: |
| 10233 | s = "slti"; |
| 10234 | s2 = "bteqz"; |
| 10235 | s3 = "x,8"; |
| 10236 | goto do_addone_branch_i; |
| 10237 | case M_BGTU_I: |
| 10238 | s = "sltiu"; |
| 10239 | s2 = "bteqz"; |
| 10240 | s3 = "x,8"; |
| 10241 | |
| 10242 | do_addone_branch_i: |
| 10243 | if (imm_expr.X_op != O_constant) |
| 10244 | as_bad (_("Unsupported large constant")); |
| 10245 | ++imm_expr.X_add_number; |
| 10246 | |
| 10247 | do_branch_i: |
| 10248 | macro_build (&imm_expr, s, s3, xreg); |
| 10249 | macro_build (&offset_expr, s2, "p"); |
| 10250 | break; |
| 10251 | |
| 10252 | case M_ABS: |
| 10253 | expr1.X_add_number = 0; |
| 10254 | macro_build (&expr1, "slti", "x,8", yreg); |
| 10255 | if (xreg != yreg) |
| 10256 | move_register (xreg, yreg); |
| 10257 | expr1.X_add_number = 2; |
| 10258 | macro_build (&expr1, "bteqz", "p"); |
| 10259 | macro_build (NULL, "neg", "x,w", xreg, xreg); |
| 10260 | } |
| 10261 | } |
| 10262 | |
| 10263 | /* For consistency checking, verify that all bits are specified either |
| 10264 | by the match/mask part of the instruction definition, or by the |
| 10265 | operand list. */ |
| 10266 | static int |
| 10267 | validate_mips_insn (const struct mips_opcode *opc) |
| 10268 | { |
| 10269 | const char *p = opc->args; |
| 10270 | char c; |
| 10271 | unsigned long used_bits = opc->mask; |
| 10272 | |
| 10273 | if ((used_bits & opc->match) != opc->match) |
| 10274 | { |
| 10275 | as_bad (_("internal: bad mips opcode (mask error): %s %s"), |
| 10276 | opc->name, opc->args); |
| 10277 | return 0; |
| 10278 | } |
| 10279 | #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift))) |
| 10280 | while (*p) |
| 10281 | switch (c = *p++) |
| 10282 | { |
| 10283 | case ',': break; |
| 10284 | case '(': break; |
| 10285 | case ')': break; |
| 10286 | case '+': |
| 10287 | switch (c = *p++) |
| 10288 | { |
| 10289 | case '1': USE_BITS (OP_MASK_UDI1, OP_SH_UDI1); break; |
| 10290 | case '2': USE_BITS (OP_MASK_UDI2, OP_SH_UDI2); break; |
| 10291 | case '3': USE_BITS (OP_MASK_UDI3, OP_SH_UDI3); break; |
| 10292 | case '4': USE_BITS (OP_MASK_UDI4, OP_SH_UDI4); break; |
| 10293 | case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
| 10294 | case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break; |
| 10295 | case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break; |
| 10296 | case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD); |
| 10297 | USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
| 10298 | case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
| 10299 | case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break; |
| 10300 | case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break; |
| 10301 | case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break; |
| 10302 | case 'I': break; |
| 10303 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; |
| 10304 | case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT); |
| 10305 | USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
| 10306 | case 'x': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break; |
| 10307 | case 'X': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break; |
| 10308 | case 'p': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break; |
| 10309 | case 'P': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break; |
| 10310 | case 'Q': USE_BITS (OP_MASK_SEQI, OP_SH_SEQI); break; |
| 10311 | case 's': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break; |
| 10312 | case 'S': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break; |
| 10313 | case 'z': USE_BITS (OP_MASK_RZ, OP_SH_RZ); break; |
| 10314 | case 'Z': USE_BITS (OP_MASK_FZ, OP_SH_FZ); break; |
| 10315 | case 'a': USE_BITS (OP_MASK_OFFSET_A, OP_SH_OFFSET_A); break; |
| 10316 | case 'b': USE_BITS (OP_MASK_OFFSET_B, OP_SH_OFFSET_B); break; |
| 10317 | case 'c': USE_BITS (OP_MASK_OFFSET_C, OP_SH_OFFSET_C); break; |
| 10318 | |
| 10319 | default: |
| 10320 | as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"), |
| 10321 | c, opc->name, opc->args); |
| 10322 | return 0; |
| 10323 | } |
| 10324 | break; |
| 10325 | case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
| 10326 | case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
| 10327 | case 'A': break; |
| 10328 | case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break; |
| 10329 | case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break; |
| 10330 | case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break; |
| 10331 | case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break; |
| 10332 | case 'F': break; |
| 10333 | case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break; |
| 10334 | case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break; |
| 10335 | case 'I': break; |
| 10336 | case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break; |
| 10337 | case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break; |
| 10338 | case 'L': break; |
| 10339 | case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break; |
| 10340 | case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break; |
| 10341 | case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break; |
| 10342 | case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL); |
| 10343 | USE_BITS (OP_MASK_FT, OP_SH_FT); break; |
| 10344 | case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break; |
| 10345 | case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break; |
| 10346 | case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break; |
| 10347 | case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break; |
| 10348 | case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break; |
| 10349 | case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break; |
| 10350 | case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break; |
| 10351 | case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break; |
| 10352 | case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break; |
| 10353 | case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break; |
| 10354 | case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break; |
| 10355 | case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break; |
| 10356 | case 'f': break; |
| 10357 | case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break; |
| 10358 | case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; |
| 10359 | case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; |
| 10360 | case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break; |
| 10361 | case 'l': break; |
| 10362 | case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; |
| 10363 | case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break; |
| 10364 | case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break; |
| 10365 | case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break; |
| 10366 | case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break; |
| 10367 | case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break; |
| 10368 | case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break; |
| 10369 | case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break; |
| 10370 | case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break; |
| 10371 | case 'x': break; |
| 10372 | case 'z': break; |
| 10373 | case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break; |
| 10374 | case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD); |
| 10375 | USE_BITS (OP_MASK_RT, OP_SH_RT); break; |
| 10376 | case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break; |
| 10377 | case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break; |
| 10378 | case '[': break; |
| 10379 | case ']': break; |
| 10380 | case '1': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break; |
| 10381 | case '2': USE_BITS (OP_MASK_BP, OP_SH_BP); break; |
| 10382 | case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break; |
| 10383 | case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break; |
| 10384 | case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break; |
| 10385 | case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break; |
| 10386 | case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break; |
| 10387 | case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break; |
| 10388 | case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break; |
| 10389 | case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break; |
| 10390 | case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break; |
| 10391 | case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break; |
| 10392 | case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break; |
| 10393 | case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break; |
| 10394 | case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break; |
| 10395 | case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break; |
| 10396 | case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break; |
| 10397 | case '\\': USE_BITS (OP_MASK_3BITPOS, OP_SH_3BITPOS); break; |
| 10398 | case '~': USE_BITS (OP_MASK_OFFSET12, OP_SH_OFFSET12); break; |
| 10399 | case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break; |
| 10400 | default: |
| 10401 | as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"), |
| 10402 | c, opc->name, opc->args); |
| 10403 | return 0; |
| 10404 | } |
| 10405 | #undef USE_BITS |
| 10406 | if (used_bits != 0xffffffff) |
| 10407 | { |
| 10408 | as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"), |
| 10409 | ~used_bits & 0xffffffff, opc->name, opc->args); |
| 10410 | return 0; |
| 10411 | } |
| 10412 | return 1; |
| 10413 | } |
| 10414 | |
| 10415 | /* For consistency checking, verify that the length implied matches the |
| 10416 | major opcode and that all bits are specified either by the match/mask |
| 10417 | part of the instruction definition, or by the operand list. */ |
| 10418 | |
| 10419 | static int |
| 10420 | validate_micromips_insn (const struct mips_opcode *opc) |
| 10421 | { |
| 10422 | unsigned long match = opc->match; |
| 10423 | unsigned long mask = opc->mask; |
| 10424 | const char *p = opc->args; |
| 10425 | unsigned long insn_bits; |
| 10426 | unsigned long used_bits; |
| 10427 | unsigned long major; |
| 10428 | unsigned int length; |
| 10429 | char e; |
| 10430 | char c; |
| 10431 | |
| 10432 | if ((mask & match) != match) |
| 10433 | { |
| 10434 | as_bad (_("Internal error: bad microMIPS opcode (mask error): %s %s"), |
| 10435 | opc->name, opc->args); |
| 10436 | return 0; |
| 10437 | } |
| 10438 | length = micromips_insn_length (opc); |
| 10439 | if (length != 2 && length != 4) |
| 10440 | { |
| 10441 | as_bad (_("Internal error: bad microMIPS opcode (incorrect length: %u): " |
| 10442 | "%s %s"), length, opc->name, opc->args); |
| 10443 | return 0; |
| 10444 | } |
| 10445 | major = match >> (10 + 8 * (length - 2)); |
| 10446 | if ((length == 2 && (major & 7) != 1 && (major & 6) != 2) |
| 10447 | || (length == 4 && (major & 7) != 0 && (major & 4) != 4)) |
| 10448 | { |
| 10449 | as_bad (_("Internal error: bad microMIPS opcode " |
| 10450 | "(opcode/length mismatch): %s %s"), opc->name, opc->args); |
| 10451 | return 0; |
| 10452 | } |
| 10453 | |
| 10454 | /* Shift piecewise to avoid an overflow where unsigned long is 32-bit. */ |
| 10455 | insn_bits = 1 << 4 * length; |
| 10456 | insn_bits <<= 4 * length; |
| 10457 | insn_bits -= 1; |
| 10458 | used_bits = mask; |
| 10459 | #define USE_BITS(field) \ |
| 10460 | (used_bits |= MICROMIPSOP_MASK_##field << MICROMIPSOP_SH_##field) |
| 10461 | while (*p) |
| 10462 | switch (c = *p++) |
| 10463 | { |
| 10464 | case ',': break; |
| 10465 | case '(': break; |
| 10466 | case ')': break; |
| 10467 | case '+': |
| 10468 | e = c; |
| 10469 | switch (c = *p++) |
| 10470 | { |
| 10471 | case 'A': USE_BITS (EXTLSB); break; |
| 10472 | case 'B': USE_BITS (INSMSB); break; |
| 10473 | case 'C': USE_BITS (EXTMSBD); break; |
| 10474 | case 'D': USE_BITS (RS); USE_BITS (SEL); break; |
| 10475 | case 'E': USE_BITS (EXTLSB); break; |
| 10476 | case 'F': USE_BITS (INSMSB); break; |
| 10477 | case 'G': USE_BITS (EXTMSBD); break; |
| 10478 | case 'H': USE_BITS (EXTMSBD); break; |
| 10479 | default: |
| 10480 | as_bad (_("Internal error: bad mips opcode " |
| 10481 | "(unknown extension operand type `%c%c'): %s %s"), |
| 10482 | e, c, opc->name, opc->args); |
| 10483 | return 0; |
| 10484 | } |
| 10485 | break; |
| 10486 | case 'm': |
| 10487 | e = c; |
| 10488 | switch (c = *p++) |
| 10489 | { |
| 10490 | case 'A': USE_BITS (IMMA); break; |
| 10491 | case 'B': USE_BITS (IMMB); break; |
| 10492 | case 'C': USE_BITS (IMMC); break; |
| 10493 | case 'D': USE_BITS (IMMD); break; |
| 10494 | case 'E': USE_BITS (IMME); break; |
| 10495 | case 'F': USE_BITS (IMMF); break; |
| 10496 | case 'G': USE_BITS (IMMG); break; |
| 10497 | case 'H': USE_BITS (IMMH); break; |
| 10498 | case 'I': USE_BITS (IMMI); break; |
| 10499 | case 'J': USE_BITS (IMMJ); break; |
| 10500 | case 'L': USE_BITS (IMML); break; |
| 10501 | case 'M': USE_BITS (IMMM); break; |
| 10502 | case 'N': USE_BITS (IMMN); break; |
| 10503 | case 'O': USE_BITS (IMMO); break; |
| 10504 | case 'P': USE_BITS (IMMP); break; |
| 10505 | case 'Q': USE_BITS (IMMQ); break; |
| 10506 | case 'U': USE_BITS (IMMU); break; |
| 10507 | case 'W': USE_BITS (IMMW); break; |
| 10508 | case 'X': USE_BITS (IMMX); break; |
| 10509 | case 'Y': USE_BITS (IMMY); break; |
| 10510 | case 'Z': break; |
| 10511 | case 'a': break; |
| 10512 | case 'b': USE_BITS (MB); break; |
| 10513 | case 'c': USE_BITS (MC); break; |
| 10514 | case 'd': USE_BITS (MD); break; |
| 10515 | case 'e': USE_BITS (ME); break; |
| 10516 | case 'f': USE_BITS (MF); break; |
| 10517 | case 'g': USE_BITS (MG); break; |
| 10518 | case 'h': USE_BITS (MH); break; |
| 10519 | case 'i': USE_BITS (MI); break; |
| 10520 | case 'j': USE_BITS (MJ); break; |
| 10521 | case 'l': USE_BITS (ML); break; |
| 10522 | case 'm': USE_BITS (MM); break; |
| 10523 | case 'n': USE_BITS (MN); break; |
| 10524 | case 'p': USE_BITS (MP); break; |
| 10525 | case 'q': USE_BITS (MQ); break; |
| 10526 | case 'r': break; |
| 10527 | case 's': break; |
| 10528 | case 't': break; |
| 10529 | case 'x': break; |
| 10530 | case 'y': break; |
| 10531 | case 'z': break; |
| 10532 | default: |
| 10533 | as_bad (_("Internal error: bad mips opcode " |
| 10534 | "(unknown extension operand type `%c%c'): %s %s"), |
| 10535 | e, c, opc->name, opc->args); |
| 10536 | return 0; |
| 10537 | } |
| 10538 | break; |
| 10539 | case '.': USE_BITS (OFFSET10); break; |
| 10540 | case '1': USE_BITS (STYPE); break; |
| 10541 | case '2': USE_BITS (BP); break; |
| 10542 | case '3': USE_BITS (SA3); break; |
| 10543 | case '4': USE_BITS (SA4); break; |
| 10544 | case '5': USE_BITS (IMM8); break; |
| 10545 | case '6': USE_BITS (RS); break; |
| 10546 | case '7': USE_BITS (DSPACC); break; |
| 10547 | case '8': USE_BITS (WRDSP); break; |
| 10548 | case '0': USE_BITS (DSPSFT); break; |
| 10549 | case '<': USE_BITS (SHAMT); break; |
| 10550 | case '>': USE_BITS (SHAMT); break; |
| 10551 | case '@': USE_BITS (IMM10); break; |
| 10552 | case 'B': USE_BITS (CODE10); break; |
| 10553 | case 'C': USE_BITS (COPZ); break; |
| 10554 | case 'D': USE_BITS (FD); break; |
| 10555 | case 'E': USE_BITS (RT); break; |
| 10556 | case 'G': USE_BITS (RS); break; |
| 10557 | case 'H': USE_BITS (SEL); break; |
| 10558 | case 'K': USE_BITS (RS); break; |
| 10559 | case 'M': USE_BITS (CCC); break; |
| 10560 | case 'N': USE_BITS (BCC); break; |
| 10561 | case 'R': USE_BITS (FR); break; |
| 10562 | case 'S': USE_BITS (FS); break; |
| 10563 | case 'T': USE_BITS (FT); break; |
| 10564 | case 'V': USE_BITS (FS); break; |
| 10565 | case '\\': USE_BITS (3BITPOS); break; |
| 10566 | case '^': USE_BITS (RD); break; |
| 10567 | case 'a': USE_BITS (TARGET); break; |
| 10568 | case 'b': USE_BITS (RS); break; |
| 10569 | case 'c': USE_BITS (CODE); break; |
| 10570 | case 'd': USE_BITS (RD); break; |
| 10571 | case 'h': USE_BITS (PREFX); break; |
| 10572 | case 'i': USE_BITS (IMMEDIATE); break; |
| 10573 | case 'j': USE_BITS (DELTA); break; |
| 10574 | case 'k': USE_BITS (CACHE); break; |
| 10575 | case 'n': USE_BITS (RT); break; |
| 10576 | case 'o': USE_BITS (DELTA); break; |
| 10577 | case 'p': USE_BITS (DELTA); break; |
| 10578 | case 'q': USE_BITS (CODE2); break; |
| 10579 | case 'r': USE_BITS (RS); break; |
| 10580 | case 's': USE_BITS (RS); break; |
| 10581 | case 't': USE_BITS (RT); break; |
| 10582 | case 'u': USE_BITS (IMMEDIATE); break; |
| 10583 | case 'v': USE_BITS (RS); break; |
| 10584 | case 'w': USE_BITS (RT); break; |
| 10585 | case 'y': USE_BITS (RS3); break; |
| 10586 | case 'z': break; |
| 10587 | case '|': USE_BITS (TRAP); break; |
| 10588 | case '~': USE_BITS (OFFSET12); break; |
| 10589 | default: |
| 10590 | as_bad (_("Internal error: bad microMIPS opcode " |
| 10591 | "(unknown operand type `%c'): %s %s"), |
| 10592 | c, opc->name, opc->args); |
| 10593 | return 0; |
| 10594 | } |
| 10595 | #undef USE_BITS |
| 10596 | if (used_bits != insn_bits) |
| 10597 | { |
| 10598 | if (~used_bits & insn_bits) |
| 10599 | as_bad (_("Internal error: bad microMIPS opcode " |
| 10600 | "(bits 0x%lx undefined): %s %s"), |
| 10601 | ~used_bits & insn_bits, opc->name, opc->args); |
| 10602 | if (used_bits & ~insn_bits) |
| 10603 | as_bad (_("Internal error: bad microMIPS opcode " |
| 10604 | "(bits 0x%lx defined): %s %s"), |
| 10605 | used_bits & ~insn_bits, opc->name, opc->args); |
| 10606 | return 0; |
| 10607 | } |
| 10608 | return 1; |
| 10609 | } |
| 10610 | |
| 10611 | /* UDI immediates. */ |
| 10612 | struct mips_immed { |
| 10613 | char type; |
| 10614 | unsigned int shift; |
| 10615 | unsigned long mask; |
| 10616 | const char * desc; |
| 10617 | }; |
| 10618 | |
| 10619 | static const struct mips_immed mips_immed[] = { |
| 10620 | { '1', OP_SH_UDI1, OP_MASK_UDI1, 0}, |
| 10621 | { '2', OP_SH_UDI2, OP_MASK_UDI2, 0}, |
| 10622 | { '3', OP_SH_UDI3, OP_MASK_UDI3, 0}, |
| 10623 | { '4', OP_SH_UDI4, OP_MASK_UDI4, 0}, |
| 10624 | { 0,0,0,0 } |
| 10625 | }; |
| 10626 | |
| 10627 | /* Check whether an odd floating-point register is allowed. */ |
| 10628 | static int |
| 10629 | mips_oddfpreg_ok (const struct mips_opcode *insn, int argnum) |
| 10630 | { |
| 10631 | const char *s = insn->name; |
| 10632 | |
| 10633 | if (insn->pinfo == INSN_MACRO) |
| 10634 | /* Let a macro pass, we'll catch it later when it is expanded. */ |
| 10635 | return 1; |
| 10636 | |
| 10637 | if (ISA_HAS_ODD_SINGLE_FPR (mips_opts.isa)) |
| 10638 | { |
| 10639 | /* Allow odd registers for single-precision ops. */ |
| 10640 | switch (insn->pinfo & (FP_S | FP_D)) |
| 10641 | { |
| 10642 | case FP_S: |
| 10643 | case 0: |
| 10644 | return 1; /* both single precision - ok */ |
| 10645 | case FP_D: |
| 10646 | return 0; /* both double precision - fail */ |
| 10647 | default: |
| 10648 | break; |
| 10649 | } |
| 10650 | |
| 10651 | /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */ |
| 10652 | s = strchr (insn->name, '.'); |
| 10653 | if (argnum == 2) |
| 10654 | s = s != NULL ? strchr (s + 1, '.') : NULL; |
| 10655 | return (s != NULL && (s[1] == 'w' || s[1] == 's')); |
| 10656 | } |
| 10657 | |
| 10658 | /* Single-precision coprocessor loads and moves are OK too. */ |
| 10659 | if ((insn->pinfo & FP_S) |
| 10660 | && (insn->pinfo & (INSN_COPROC_MEMORY_DELAY | INSN_STORE_MEMORY |
| 10661 | | INSN_LOAD_COPROC_DELAY | INSN_COPROC_MOVE_DELAY))) |
| 10662 | return 1; |
| 10663 | |
| 10664 | return 0; |
| 10665 | } |
| 10666 | |
| 10667 | /* Check if EXPR is a constant between MIN (inclusive) and MAX (exclusive) |
| 10668 | taking bits from BIT up. */ |
| 10669 | static int |
| 10670 | expr_const_in_range (expressionS *ep, offsetT min, offsetT max, int bit) |
| 10671 | { |
| 10672 | return (ep->X_op == O_constant |
| 10673 | && (ep->X_add_number & ((1 << bit) - 1)) == 0 |
| 10674 | && ep->X_add_number >= min << bit |
| 10675 | && ep->X_add_number < max << bit); |
| 10676 | } |
| 10677 | |
| 10678 | /* This routine assembles an instruction into its binary format. As a |
| 10679 | side effect, it sets one of the global variables imm_reloc or |
| 10680 | offset_reloc to the type of relocation to do if one of the operands |
| 10681 | is an address expression. */ |
| 10682 | |
| 10683 | static void |
| 10684 | mips_ip (char *str, struct mips_cl_insn *ip) |
| 10685 | { |
| 10686 | bfd_boolean wrong_delay_slot_insns = FALSE; |
| 10687 | bfd_boolean need_delay_slot_ok = TRUE; |
| 10688 | struct mips_opcode *firstinsn = NULL; |
| 10689 | const struct mips_opcode *past; |
| 10690 | struct hash_control *hash; |
| 10691 | char *s; |
| 10692 | const char *args; |
| 10693 | char c = 0; |
| 10694 | struct mips_opcode *insn; |
| 10695 | char *argsStart; |
| 10696 | unsigned int regno; |
| 10697 | unsigned int lastregno; |
| 10698 | unsigned int destregno = 0; |
| 10699 | unsigned int lastpos = 0; |
| 10700 | unsigned int limlo, limhi; |
| 10701 | char *s_reset; |
| 10702 | offsetT min_range, max_range; |
| 10703 | long opend; |
| 10704 | char *name; |
| 10705 | int argnum; |
| 10706 | unsigned int rtype; |
| 10707 | char *dot; |
| 10708 | long end; |
| 10709 | |
| 10710 | insn_error = NULL; |
| 10711 | |
| 10712 | if (mips_opts.micromips) |
| 10713 | { |
| 10714 | hash = micromips_op_hash; |
| 10715 | past = µmips_opcodes[bfd_micromips_num_opcodes]; |
| 10716 | } |
| 10717 | else |
| 10718 | { |
| 10719 | hash = op_hash; |
| 10720 | past = &mips_opcodes[NUMOPCODES]; |
| 10721 | } |
| 10722 | forced_insn_length = 0; |
| 10723 | insn = NULL; |
| 10724 | |
| 10725 | /* We first try to match an instruction up to a space or to the end. */ |
| 10726 | for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++) |
| 10727 | continue; |
| 10728 | |
| 10729 | /* Make a copy of the instruction so that we can fiddle with it. */ |
| 10730 | name = alloca (end + 1); |
| 10731 | memcpy (name, str, end); |
| 10732 | name[end] = '\0'; |
| 10733 | |
| 10734 | for (;;) |
| 10735 | { |
| 10736 | insn = (struct mips_opcode *) hash_find (hash, name); |
| 10737 | |
| 10738 | if (insn != NULL || !mips_opts.micromips) |
| 10739 | break; |
| 10740 | if (forced_insn_length) |
| 10741 | break; |
| 10742 | |
| 10743 | /* See if there's an instruction size override suffix, |
| 10744 | either `16' or `32', at the end of the mnemonic proper, |
| 10745 | that defines the operation, i.e. before the first `.' |
| 10746 | character if any. Strip it and retry. */ |
| 10747 | dot = strchr (name, '.'); |
| 10748 | opend = dot != NULL ? dot - name : end; |
| 10749 | if (opend < 3) |
| 10750 | break; |
| 10751 | if (name[opend - 2] == '1' && name[opend - 1] == '6') |
| 10752 | forced_insn_length = 2; |
| 10753 | else if (name[opend - 2] == '3' && name[opend - 1] == '2') |
| 10754 | forced_insn_length = 4; |
| 10755 | else |
| 10756 | break; |
| 10757 | memcpy (name + opend - 2, name + opend, end - opend + 1); |
| 10758 | } |
| 10759 | if (insn == NULL) |
| 10760 | { |
| 10761 | insn_error = _("Unrecognized opcode"); |
| 10762 | return; |
| 10763 | } |
| 10764 | |
| 10765 | /* For microMIPS instructions placed in a fixed-length branch delay slot |
| 10766 | we make up to two passes over the relevant fragment of the opcode |
| 10767 | table. First we try instructions that meet the delay slot's length |
| 10768 | requirement. If none matched, then we retry with the remaining ones |
| 10769 | and if one matches, then we use it and then issue an appropriate |
| 10770 | warning later on. */ |
| 10771 | argsStart = s = str + end; |
| 10772 | for (;;) |
| 10773 | { |
| 10774 | bfd_boolean delay_slot_ok; |
| 10775 | bfd_boolean size_ok; |
| 10776 | bfd_boolean ok; |
| 10777 | |
| 10778 | gas_assert (strcmp (insn->name, name) == 0); |
| 10779 | |
| 10780 | ok = is_opcode_valid (insn); |
| 10781 | size_ok = is_size_valid (insn); |
| 10782 | delay_slot_ok = is_delay_slot_valid (insn); |
| 10783 | if (!delay_slot_ok && !wrong_delay_slot_insns) |
| 10784 | { |
| 10785 | firstinsn = insn; |
| 10786 | wrong_delay_slot_insns = TRUE; |
| 10787 | } |
| 10788 | if (!ok || !size_ok || delay_slot_ok != need_delay_slot_ok) |
| 10789 | { |
| 10790 | static char buf[256]; |
| 10791 | |
| 10792 | if (insn + 1 < past && strcmp (insn->name, insn[1].name) == 0) |
| 10793 | { |
| 10794 | ++insn; |
| 10795 | continue; |
| 10796 | } |
| 10797 | if (wrong_delay_slot_insns && need_delay_slot_ok) |
| 10798 | { |
| 10799 | gas_assert (firstinsn); |
| 10800 | need_delay_slot_ok = FALSE; |
| 10801 | past = insn + 1; |
| 10802 | insn = firstinsn; |
| 10803 | continue; |
| 10804 | } |
| 10805 | |
| 10806 | if (insn_error) |
| 10807 | return; |
| 10808 | |
| 10809 | if (!ok) |
| 10810 | sprintf (buf, _("Opcode not supported on this processor: %s (%s)"), |
| 10811 | mips_cpu_info_from_arch (mips_opts.arch)->name, |
| 10812 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 10813 | else |
| 10814 | sprintf (buf, _("Unrecognized %u-bit version of microMIPS opcode"), |
| 10815 | 8 * forced_insn_length); |
| 10816 | insn_error = buf; |
| 10817 | |
| 10818 | return; |
| 10819 | } |
| 10820 | |
| 10821 | create_insn (ip, insn); |
| 10822 | insn_error = NULL; |
| 10823 | argnum = 1; |
| 10824 | lastregno = 0xffffffff; |
| 10825 | for (args = insn->args;; ++args) |
| 10826 | { |
| 10827 | int is_mdmx; |
| 10828 | |
| 10829 | s += strspn (s, " \t"); |
| 10830 | is_mdmx = 0; |
| 10831 | switch (*args) |
| 10832 | { |
| 10833 | case '\0': /* end of args */ |
| 10834 | if (*s == '\0') |
| 10835 | return; |
| 10836 | break; |
| 10837 | |
| 10838 | case '2': |
| 10839 | /* DSP 2-bit unsigned immediate in bit 11 (for standard MIPS |
| 10840 | code) or 14 (for microMIPS code). */ |
| 10841 | my_getExpression (&imm_expr, s); |
| 10842 | check_absolute_expr (ip, &imm_expr); |
| 10843 | if ((unsigned long) imm_expr.X_add_number != 1 |
| 10844 | && (unsigned long) imm_expr.X_add_number != 3) |
| 10845 | { |
| 10846 | as_bad (_("BALIGN immediate not 1 or 3 (%lu)"), |
| 10847 | (unsigned long) imm_expr.X_add_number); |
| 10848 | } |
| 10849 | INSERT_OPERAND (mips_opts.micromips, |
| 10850 | BP, *ip, imm_expr.X_add_number); |
| 10851 | imm_expr.X_op = O_absent; |
| 10852 | s = expr_end; |
| 10853 | continue; |
| 10854 | |
| 10855 | case '3': |
| 10856 | /* DSP 3-bit unsigned immediate in bit 13 (for standard MIPS |
| 10857 | code) or 21 (for microMIPS code). */ |
| 10858 | { |
| 10859 | unsigned long mask = (mips_opts.micromips |
| 10860 | ? MICROMIPSOP_MASK_SA3 : OP_MASK_SA3); |
| 10861 | |
| 10862 | my_getExpression (&imm_expr, s); |
| 10863 | check_absolute_expr (ip, &imm_expr); |
| 10864 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 10865 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), |
| 10866 | mask, (unsigned long) imm_expr.X_add_number); |
| 10867 | INSERT_OPERAND (mips_opts.micromips, |
| 10868 | SA3, *ip, imm_expr.X_add_number); |
| 10869 | imm_expr.X_op = O_absent; |
| 10870 | s = expr_end; |
| 10871 | } |
| 10872 | continue; |
| 10873 | |
| 10874 | case '4': |
| 10875 | /* DSP 4-bit unsigned immediate in bit 12 (for standard MIPS |
| 10876 | code) or 21 (for microMIPS code). */ |
| 10877 | { |
| 10878 | unsigned long mask = (mips_opts.micromips |
| 10879 | ? MICROMIPSOP_MASK_SA4 : OP_MASK_SA4); |
| 10880 | |
| 10881 | my_getExpression (&imm_expr, s); |
| 10882 | check_absolute_expr (ip, &imm_expr); |
| 10883 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 10884 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), |
| 10885 | mask, (unsigned long) imm_expr.X_add_number); |
| 10886 | INSERT_OPERAND (mips_opts.micromips, |
| 10887 | SA4, *ip, imm_expr.X_add_number); |
| 10888 | imm_expr.X_op = O_absent; |
| 10889 | s = expr_end; |
| 10890 | } |
| 10891 | continue; |
| 10892 | |
| 10893 | case '5': |
| 10894 | /* DSP 8-bit unsigned immediate in bit 13 (for standard MIPS |
| 10895 | code) or 16 (for microMIPS code). */ |
| 10896 | { |
| 10897 | unsigned long mask = (mips_opts.micromips |
| 10898 | ? MICROMIPSOP_MASK_IMM8 : OP_MASK_IMM8); |
| 10899 | |
| 10900 | my_getExpression (&imm_expr, s); |
| 10901 | check_absolute_expr (ip, &imm_expr); |
| 10902 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 10903 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), |
| 10904 | mask, (unsigned long) imm_expr.X_add_number); |
| 10905 | INSERT_OPERAND (mips_opts.micromips, |
| 10906 | IMM8, *ip, imm_expr.X_add_number); |
| 10907 | imm_expr.X_op = O_absent; |
| 10908 | s = expr_end; |
| 10909 | } |
| 10910 | continue; |
| 10911 | |
| 10912 | case '6': |
| 10913 | /* DSP 5-bit unsigned immediate in bit 16 (for standard MIPS |
| 10914 | code) or 21 (for microMIPS code). */ |
| 10915 | { |
| 10916 | unsigned long mask = (mips_opts.micromips |
| 10917 | ? MICROMIPSOP_MASK_RS : OP_MASK_RS); |
| 10918 | |
| 10919 | my_getExpression (&imm_expr, s); |
| 10920 | check_absolute_expr (ip, &imm_expr); |
| 10921 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 10922 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), |
| 10923 | mask, (unsigned long) imm_expr.X_add_number); |
| 10924 | INSERT_OPERAND (mips_opts.micromips, |
| 10925 | RS, *ip, imm_expr.X_add_number); |
| 10926 | imm_expr.X_op = O_absent; |
| 10927 | s = expr_end; |
| 10928 | } |
| 10929 | continue; |
| 10930 | |
| 10931 | case '7': /* Four DSP accumulators in bits 11,12. */ |
| 10932 | if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' |
| 10933 | && s[3] >= '0' && s[3] <= '3') |
| 10934 | { |
| 10935 | regno = s[3] - '0'; |
| 10936 | s += 4; |
| 10937 | INSERT_OPERAND (mips_opts.micromips, DSPACC, *ip, regno); |
| 10938 | continue; |
| 10939 | } |
| 10940 | else |
| 10941 | as_bad (_("Invalid dsp acc register")); |
| 10942 | break; |
| 10943 | |
| 10944 | case '8': |
| 10945 | /* DSP 6-bit unsigned immediate in bit 11 (for standard MIPS |
| 10946 | code) or 14 (for microMIPS code). */ |
| 10947 | { |
| 10948 | unsigned long mask = (mips_opts.micromips |
| 10949 | ? MICROMIPSOP_MASK_WRDSP |
| 10950 | : OP_MASK_WRDSP); |
| 10951 | |
| 10952 | my_getExpression (&imm_expr, s); |
| 10953 | check_absolute_expr (ip, &imm_expr); |
| 10954 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 10955 | as_bad (_("DSP immediate not in range 0..%lu (%lu)"), |
| 10956 | mask, (unsigned long) imm_expr.X_add_number); |
| 10957 | INSERT_OPERAND (mips_opts.micromips, |
| 10958 | WRDSP, *ip, imm_expr.X_add_number); |
| 10959 | imm_expr.X_op = O_absent; |
| 10960 | s = expr_end; |
| 10961 | } |
| 10962 | continue; |
| 10963 | |
| 10964 | case '9': /* Four DSP accumulators in bits 21,22. */ |
| 10965 | gas_assert (!mips_opts.micromips); |
| 10966 | if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' |
| 10967 | && s[3] >= '0' && s[3] <= '3') |
| 10968 | { |
| 10969 | regno = s[3] - '0'; |
| 10970 | s += 4; |
| 10971 | INSERT_OPERAND (0, DSPACC_S, *ip, regno); |
| 10972 | continue; |
| 10973 | } |
| 10974 | else |
| 10975 | as_bad (_("Invalid dsp acc register")); |
| 10976 | break; |
| 10977 | |
| 10978 | case '0': |
| 10979 | /* DSP 6-bit signed immediate in bit 16 (for standard MIPS |
| 10980 | code) or 20 (for microMIPS code). */ |
| 10981 | { |
| 10982 | long mask = (mips_opts.micromips |
| 10983 | ? MICROMIPSOP_MASK_DSPSFT : OP_MASK_DSPSFT); |
| 10984 | |
| 10985 | my_getExpression (&imm_expr, s); |
| 10986 | check_absolute_expr (ip, &imm_expr); |
| 10987 | min_range = -((mask + 1) >> 1); |
| 10988 | max_range = ((mask + 1) >> 1) - 1; |
| 10989 | if (imm_expr.X_add_number < min_range |
| 10990 | || imm_expr.X_add_number > max_range) |
| 10991 | as_bad (_("DSP immediate not in range %ld..%ld (%ld)"), |
| 10992 | (long) min_range, (long) max_range, |
| 10993 | (long) imm_expr.X_add_number); |
| 10994 | INSERT_OPERAND (mips_opts.micromips, |
| 10995 | DSPSFT, *ip, imm_expr.X_add_number); |
| 10996 | imm_expr.X_op = O_absent; |
| 10997 | s = expr_end; |
| 10998 | } |
| 10999 | continue; |
| 11000 | |
| 11001 | case '\'': /* DSP 6-bit unsigned immediate in bit 16. */ |
| 11002 | gas_assert (!mips_opts.micromips); |
| 11003 | my_getExpression (&imm_expr, s); |
| 11004 | check_absolute_expr (ip, &imm_expr); |
| 11005 | if (imm_expr.X_add_number & ~OP_MASK_RDDSP) |
| 11006 | { |
| 11007 | as_bad (_("DSP immediate not in range 0..%d (%lu)"), |
| 11008 | OP_MASK_RDDSP, |
| 11009 | (unsigned long) imm_expr.X_add_number); |
| 11010 | } |
| 11011 | INSERT_OPERAND (0, RDDSP, *ip, imm_expr.X_add_number); |
| 11012 | imm_expr.X_op = O_absent; |
| 11013 | s = expr_end; |
| 11014 | continue; |
| 11015 | |
| 11016 | case ':': /* DSP 7-bit signed immediate in bit 19. */ |
| 11017 | gas_assert (!mips_opts.micromips); |
| 11018 | my_getExpression (&imm_expr, s); |
| 11019 | check_absolute_expr (ip, &imm_expr); |
| 11020 | min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1); |
| 11021 | max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1; |
| 11022 | if (imm_expr.X_add_number < min_range || |
| 11023 | imm_expr.X_add_number > max_range) |
| 11024 | { |
| 11025 | as_bad (_("DSP immediate not in range %ld..%ld (%ld)"), |
| 11026 | (long) min_range, (long) max_range, |
| 11027 | (long) imm_expr.X_add_number); |
| 11028 | } |
| 11029 | INSERT_OPERAND (0, DSPSFT_7, *ip, imm_expr.X_add_number); |
| 11030 | imm_expr.X_op = O_absent; |
| 11031 | s = expr_end; |
| 11032 | continue; |
| 11033 | |
| 11034 | case '@': /* DSP 10-bit signed immediate in bit 16. */ |
| 11035 | { |
| 11036 | long mask = (mips_opts.micromips |
| 11037 | ? MICROMIPSOP_MASK_IMM10 : OP_MASK_IMM10); |
| 11038 | |
| 11039 | my_getExpression (&imm_expr, s); |
| 11040 | check_absolute_expr (ip, &imm_expr); |
| 11041 | min_range = -((mask + 1) >> 1); |
| 11042 | max_range = ((mask + 1) >> 1) - 1; |
| 11043 | if (imm_expr.X_add_number < min_range |
| 11044 | || imm_expr.X_add_number > max_range) |
| 11045 | as_bad (_("DSP immediate not in range %ld..%ld (%ld)"), |
| 11046 | (long) min_range, (long) max_range, |
| 11047 | (long) imm_expr.X_add_number); |
| 11048 | INSERT_OPERAND (mips_opts.micromips, |
| 11049 | IMM10, *ip, imm_expr.X_add_number); |
| 11050 | imm_expr.X_op = O_absent; |
| 11051 | s = expr_end; |
| 11052 | } |
| 11053 | continue; |
| 11054 | |
| 11055 | case '^': /* DSP 5-bit unsigned immediate in bit 11. */ |
| 11056 | gas_assert (mips_opts.micromips); |
| 11057 | my_getExpression (&imm_expr, s); |
| 11058 | check_absolute_expr (ip, &imm_expr); |
| 11059 | if (imm_expr.X_add_number & ~MICROMIPSOP_MASK_RD) |
| 11060 | as_bad (_("DSP immediate not in range 0..%d (%lu)"), |
| 11061 | MICROMIPSOP_MASK_RD, |
| 11062 | (unsigned long) imm_expr.X_add_number); |
| 11063 | INSERT_OPERAND (1, RD, *ip, imm_expr.X_add_number); |
| 11064 | imm_expr.X_op = O_absent; |
| 11065 | s = expr_end; |
| 11066 | continue; |
| 11067 | |
| 11068 | case '!': /* MT usermode flag bit. */ |
| 11069 | gas_assert (!mips_opts.micromips); |
| 11070 | my_getExpression (&imm_expr, s); |
| 11071 | check_absolute_expr (ip, &imm_expr); |
| 11072 | if (imm_expr.X_add_number & ~OP_MASK_MT_U) |
| 11073 | as_bad (_("MT usermode bit not 0 or 1 (%lu)"), |
| 11074 | (unsigned long) imm_expr.X_add_number); |
| 11075 | INSERT_OPERAND (0, MT_U, *ip, imm_expr.X_add_number); |
| 11076 | imm_expr.X_op = O_absent; |
| 11077 | s = expr_end; |
| 11078 | continue; |
| 11079 | |
| 11080 | case '$': /* MT load high flag bit. */ |
| 11081 | gas_assert (!mips_opts.micromips); |
| 11082 | my_getExpression (&imm_expr, s); |
| 11083 | check_absolute_expr (ip, &imm_expr); |
| 11084 | if (imm_expr.X_add_number & ~OP_MASK_MT_H) |
| 11085 | as_bad (_("MT load high bit not 0 or 1 (%lu)"), |
| 11086 | (unsigned long) imm_expr.X_add_number); |
| 11087 | INSERT_OPERAND (0, MT_H, *ip, imm_expr.X_add_number); |
| 11088 | imm_expr.X_op = O_absent; |
| 11089 | s = expr_end; |
| 11090 | continue; |
| 11091 | |
| 11092 | case '*': /* Four DSP accumulators in bits 18,19. */ |
| 11093 | gas_assert (!mips_opts.micromips); |
| 11094 | if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' && |
| 11095 | s[3] >= '0' && s[3] <= '3') |
| 11096 | { |
| 11097 | regno = s[3] - '0'; |
| 11098 | s += 4; |
| 11099 | INSERT_OPERAND (0, MTACC_T, *ip, regno); |
| 11100 | continue; |
| 11101 | } |
| 11102 | else |
| 11103 | as_bad (_("Invalid dsp/smartmips acc register")); |
| 11104 | break; |
| 11105 | |
| 11106 | case '&': /* Four DSP accumulators in bits 13,14. */ |
| 11107 | gas_assert (!mips_opts.micromips); |
| 11108 | if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' && |
| 11109 | s[3] >= '0' && s[3] <= '3') |
| 11110 | { |
| 11111 | regno = s[3] - '0'; |
| 11112 | s += 4; |
| 11113 | INSERT_OPERAND (0, MTACC_D, *ip, regno); |
| 11114 | continue; |
| 11115 | } |
| 11116 | else |
| 11117 | as_bad (_("Invalid dsp/smartmips acc register")); |
| 11118 | break; |
| 11119 | |
| 11120 | case '\\': /* 3-bit bit position. */ |
| 11121 | { |
| 11122 | unsigned long mask = (mips_opts.micromips |
| 11123 | ? MICROMIPSOP_MASK_3BITPOS |
| 11124 | : OP_MASK_3BITPOS); |
| 11125 | |
| 11126 | my_getExpression (&imm_expr, s); |
| 11127 | check_absolute_expr (ip, &imm_expr); |
| 11128 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 11129 | as_warn (_("Bit position for %s not in range 0..%lu (%lu)"), |
| 11130 | ip->insn_mo->name, |
| 11131 | mask, (unsigned long) imm_expr.X_add_number); |
| 11132 | INSERT_OPERAND (mips_opts.micromips, |
| 11133 | 3BITPOS, *ip, imm_expr.X_add_number); |
| 11134 | imm_expr.X_op = O_absent; |
| 11135 | s = expr_end; |
| 11136 | } |
| 11137 | continue; |
| 11138 | |
| 11139 | case ',': |
| 11140 | ++argnum; |
| 11141 | if (*s++ == *args) |
| 11142 | continue; |
| 11143 | s--; |
| 11144 | switch (*++args) |
| 11145 | { |
| 11146 | case 'r': |
| 11147 | case 'v': |
| 11148 | INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno); |
| 11149 | continue; |
| 11150 | |
| 11151 | case 'w': |
| 11152 | INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno); |
| 11153 | continue; |
| 11154 | |
| 11155 | case 'W': |
| 11156 | gas_assert (!mips_opts.micromips); |
| 11157 | INSERT_OPERAND (0, FT, *ip, lastregno); |
| 11158 | continue; |
| 11159 | |
| 11160 | case 'V': |
| 11161 | INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno); |
| 11162 | continue; |
| 11163 | } |
| 11164 | break; |
| 11165 | |
| 11166 | case '(': |
| 11167 | /* Handle optional base register. |
| 11168 | Either the base register is omitted or |
| 11169 | we must have a left paren. */ |
| 11170 | /* This is dependent on the next operand specifier |
| 11171 | is a base register specification. */ |
| 11172 | gas_assert (args[1] == 'b' |
| 11173 | || (mips_opts.micromips |
| 11174 | && args[1] == 'm' |
| 11175 | && (args[2] == 'l' || args[2] == 'n' |
| 11176 | || args[2] == 's' || args[2] == 'a'))); |
| 11177 | if (*s == '\0' && args[1] == 'b') |
| 11178 | return; |
| 11179 | /* Fall through. */ |
| 11180 | |
| 11181 | case ')': /* These must match exactly. */ |
| 11182 | if (*s++ == *args) |
| 11183 | continue; |
| 11184 | break; |
| 11185 | |
| 11186 | case '[': /* These must match exactly. */ |
| 11187 | case ']': |
| 11188 | gas_assert (!mips_opts.micromips); |
| 11189 | if (*s++ == *args) |
| 11190 | continue; |
| 11191 | break; |
| 11192 | |
| 11193 | case '+': /* Opcode extension character. */ |
| 11194 | switch (*++args) |
| 11195 | { |
| 11196 | case '1': /* UDI immediates. */ |
| 11197 | case '2': |
| 11198 | case '3': |
| 11199 | case '4': |
| 11200 | gas_assert (!mips_opts.micromips); |
| 11201 | { |
| 11202 | const struct mips_immed *imm = mips_immed; |
| 11203 | |
| 11204 | while (imm->type && imm->type != *args) |
| 11205 | ++imm; |
| 11206 | if (! imm->type) |
| 11207 | internalError (); |
| 11208 | my_getExpression (&imm_expr, s); |
| 11209 | check_absolute_expr (ip, &imm_expr); |
| 11210 | if ((unsigned long) imm_expr.X_add_number & ~imm->mask) |
| 11211 | { |
| 11212 | as_warn (_("Illegal %s number (%lu, 0x%lx)"), |
| 11213 | imm->desc ? imm->desc : ip->insn_mo->name, |
| 11214 | (unsigned long) imm_expr.X_add_number, |
| 11215 | (unsigned long) imm_expr.X_add_number); |
| 11216 | imm_expr.X_add_number &= imm->mask; |
| 11217 | } |
| 11218 | ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number |
| 11219 | << imm->shift); |
| 11220 | imm_expr.X_op = O_absent; |
| 11221 | s = expr_end; |
| 11222 | } |
| 11223 | continue; |
| 11224 | |
| 11225 | case 'A': /* ins/ext position, becomes LSB. */ |
| 11226 | limlo = 0; |
| 11227 | limhi = 31; |
| 11228 | goto do_lsb; |
| 11229 | case 'E': |
| 11230 | limlo = 32; |
| 11231 | limhi = 63; |
| 11232 | goto do_lsb; |
| 11233 | do_lsb: |
| 11234 | my_getExpression (&imm_expr, s); |
| 11235 | check_absolute_expr (ip, &imm_expr); |
| 11236 | if ((unsigned long) imm_expr.X_add_number < limlo |
| 11237 | || (unsigned long) imm_expr.X_add_number > limhi) |
| 11238 | { |
| 11239 | as_bad (_("Improper position (%lu)"), |
| 11240 | (unsigned long) imm_expr.X_add_number); |
| 11241 | imm_expr.X_add_number = limlo; |
| 11242 | } |
| 11243 | lastpos = imm_expr.X_add_number; |
| 11244 | INSERT_OPERAND (mips_opts.micromips, |
| 11245 | EXTLSB, *ip, imm_expr.X_add_number); |
| 11246 | imm_expr.X_op = O_absent; |
| 11247 | s = expr_end; |
| 11248 | continue; |
| 11249 | |
| 11250 | case 'B': /* ins size, becomes MSB. */ |
| 11251 | limlo = 1; |
| 11252 | limhi = 32; |
| 11253 | goto do_msb; |
| 11254 | case 'F': |
| 11255 | limlo = 33; |
| 11256 | limhi = 64; |
| 11257 | goto do_msb; |
| 11258 | do_msb: |
| 11259 | my_getExpression (&imm_expr, s); |
| 11260 | check_absolute_expr (ip, &imm_expr); |
| 11261 | /* Check for negative input so that small negative numbers |
| 11262 | will not succeed incorrectly. The checks against |
| 11263 | (pos+size) transitively check "size" itself, |
| 11264 | assuming that "pos" is reasonable. */ |
| 11265 | if ((long) imm_expr.X_add_number < 0 |
| 11266 | || ((unsigned long) imm_expr.X_add_number |
| 11267 | + lastpos) < limlo |
| 11268 | || ((unsigned long) imm_expr.X_add_number |
| 11269 | + lastpos) > limhi) |
| 11270 | { |
| 11271 | as_bad (_("Improper insert size (%lu, position %lu)"), |
| 11272 | (unsigned long) imm_expr.X_add_number, |
| 11273 | (unsigned long) lastpos); |
| 11274 | imm_expr.X_add_number = limlo - lastpos; |
| 11275 | } |
| 11276 | INSERT_OPERAND (mips_opts.micromips, INSMSB, *ip, |
| 11277 | lastpos + imm_expr.X_add_number - 1); |
| 11278 | imm_expr.X_op = O_absent; |
| 11279 | s = expr_end; |
| 11280 | continue; |
| 11281 | |
| 11282 | case 'C': /* ext size, becomes MSBD. */ |
| 11283 | limlo = 1; |
| 11284 | limhi = 32; |
| 11285 | goto do_msbd; |
| 11286 | case 'G': |
| 11287 | limlo = 33; |
| 11288 | limhi = 64; |
| 11289 | goto do_msbd; |
| 11290 | case 'H': |
| 11291 | limlo = 33; |
| 11292 | limhi = 64; |
| 11293 | goto do_msbd; |
| 11294 | do_msbd: |
| 11295 | my_getExpression (&imm_expr, s); |
| 11296 | check_absolute_expr (ip, &imm_expr); |
| 11297 | /* Check for negative input so that small negative numbers |
| 11298 | will not succeed incorrectly. The checks against |
| 11299 | (pos+size) transitively check "size" itself, |
| 11300 | assuming that "pos" is reasonable. */ |
| 11301 | if ((long) imm_expr.X_add_number < 0 |
| 11302 | || ((unsigned long) imm_expr.X_add_number |
| 11303 | + lastpos) < limlo |
| 11304 | || ((unsigned long) imm_expr.X_add_number |
| 11305 | + lastpos) > limhi) |
| 11306 | { |
| 11307 | as_bad (_("Improper extract size (%lu, position %lu)"), |
| 11308 | (unsigned long) imm_expr.X_add_number, |
| 11309 | (unsigned long) lastpos); |
| 11310 | imm_expr.X_add_number = limlo - lastpos; |
| 11311 | } |
| 11312 | INSERT_OPERAND (mips_opts.micromips, |
| 11313 | EXTMSBD, *ip, imm_expr.X_add_number - 1); |
| 11314 | imm_expr.X_op = O_absent; |
| 11315 | s = expr_end; |
| 11316 | continue; |
| 11317 | |
| 11318 | case 'D': |
| 11319 | /* +D is for disassembly only; never match. */ |
| 11320 | break; |
| 11321 | |
| 11322 | case 'I': |
| 11323 | /* "+I" is like "I", except that imm2_expr is used. */ |
| 11324 | my_getExpression (&imm2_expr, s); |
| 11325 | if (imm2_expr.X_op != O_big |
| 11326 | && imm2_expr.X_op != O_constant) |
| 11327 | insn_error = _("absolute expression required"); |
| 11328 | if (HAVE_32BIT_GPRS) |
| 11329 | normalize_constant_expr (&imm2_expr); |
| 11330 | s = expr_end; |
| 11331 | continue; |
| 11332 | |
| 11333 | case 'T': /* Coprocessor register. */ |
| 11334 | gas_assert (!mips_opts.micromips); |
| 11335 | /* +T is for disassembly only; never match. */ |
| 11336 | break; |
| 11337 | |
| 11338 | case 't': /* Coprocessor register number. */ |
| 11339 | gas_assert (!mips_opts.micromips); |
| 11340 | if (s[0] == '$' && ISDIGIT (s[1])) |
| 11341 | { |
| 11342 | ++s; |
| 11343 | regno = 0; |
| 11344 | do |
| 11345 | { |
| 11346 | regno *= 10; |
| 11347 | regno += *s - '0'; |
| 11348 | ++s; |
| 11349 | } |
| 11350 | while (ISDIGIT (*s)); |
| 11351 | if (regno > 31) |
| 11352 | as_bad (_("Invalid register number (%d)"), regno); |
| 11353 | else |
| 11354 | { |
| 11355 | INSERT_OPERAND (0, RT, *ip, regno); |
| 11356 | continue; |
| 11357 | } |
| 11358 | } |
| 11359 | else |
| 11360 | as_bad (_("Invalid coprocessor 0 register number")); |
| 11361 | break; |
| 11362 | |
| 11363 | case 'x': |
| 11364 | /* bbit[01] and bbit[01]32 bit index. Give error if index |
| 11365 | is not in the valid range. */ |
| 11366 | gas_assert (!mips_opts.micromips); |
| 11367 | my_getExpression (&imm_expr, s); |
| 11368 | check_absolute_expr (ip, &imm_expr); |
| 11369 | if ((unsigned) imm_expr.X_add_number > 31) |
| 11370 | { |
| 11371 | as_bad (_("Improper bit index (%lu)"), |
| 11372 | (unsigned long) imm_expr.X_add_number); |
| 11373 | imm_expr.X_add_number = 0; |
| 11374 | } |
| 11375 | INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number); |
| 11376 | imm_expr.X_op = O_absent; |
| 11377 | s = expr_end; |
| 11378 | continue; |
| 11379 | |
| 11380 | case 'X': |
| 11381 | /* bbit[01] bit index when bbit is used but we generate |
| 11382 | bbit[01]32 because the index is over 32. Move to the |
| 11383 | next candidate if index is not in the valid range. */ |
| 11384 | gas_assert (!mips_opts.micromips); |
| 11385 | my_getExpression (&imm_expr, s); |
| 11386 | check_absolute_expr (ip, &imm_expr); |
| 11387 | if ((unsigned) imm_expr.X_add_number < 32 |
| 11388 | || (unsigned) imm_expr.X_add_number > 63) |
| 11389 | break; |
| 11390 | INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number - 32); |
| 11391 | imm_expr.X_op = O_absent; |
| 11392 | s = expr_end; |
| 11393 | continue; |
| 11394 | |
| 11395 | case 'p': |
| 11396 | /* cins, cins32, exts and exts32 position field. Give error |
| 11397 | if it's not in the valid range. */ |
| 11398 | gas_assert (!mips_opts.micromips); |
| 11399 | my_getExpression (&imm_expr, s); |
| 11400 | check_absolute_expr (ip, &imm_expr); |
| 11401 | if ((unsigned) imm_expr.X_add_number > 31) |
| 11402 | { |
| 11403 | as_bad (_("Improper position (%lu)"), |
| 11404 | (unsigned long) imm_expr.X_add_number); |
| 11405 | imm_expr.X_add_number = 0; |
| 11406 | } |
| 11407 | /* Make the pos explicit to simplify +S. */ |
| 11408 | lastpos = imm_expr.X_add_number + 32; |
| 11409 | INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number); |
| 11410 | imm_expr.X_op = O_absent; |
| 11411 | s = expr_end; |
| 11412 | continue; |
| 11413 | |
| 11414 | case 'P': |
| 11415 | /* cins, cins32, exts and exts32 position field. Move to |
| 11416 | the next candidate if it's not in the valid range. */ |
| 11417 | gas_assert (!mips_opts.micromips); |
| 11418 | my_getExpression (&imm_expr, s); |
| 11419 | check_absolute_expr (ip, &imm_expr); |
| 11420 | if ((unsigned) imm_expr.X_add_number < 32 |
| 11421 | || (unsigned) imm_expr.X_add_number > 63) |
| 11422 | break; |
| 11423 | lastpos = imm_expr.X_add_number; |
| 11424 | INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number - 32); |
| 11425 | imm_expr.X_op = O_absent; |
| 11426 | s = expr_end; |
| 11427 | continue; |
| 11428 | |
| 11429 | case 's': |
| 11430 | /* cins and exts length-minus-one field. */ |
| 11431 | gas_assert (!mips_opts.micromips); |
| 11432 | my_getExpression (&imm_expr, s); |
| 11433 | check_absolute_expr (ip, &imm_expr); |
| 11434 | if ((unsigned long) imm_expr.X_add_number > 31) |
| 11435 | { |
| 11436 | as_bad (_("Improper size (%lu)"), |
| 11437 | (unsigned long) imm_expr.X_add_number); |
| 11438 | imm_expr.X_add_number = 0; |
| 11439 | } |
| 11440 | INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number); |
| 11441 | imm_expr.X_op = O_absent; |
| 11442 | s = expr_end; |
| 11443 | continue; |
| 11444 | |
| 11445 | case 'S': |
| 11446 | /* cins32/exts32 and cins/exts aliasing cint32/exts32 |
| 11447 | length-minus-one field. */ |
| 11448 | gas_assert (!mips_opts.micromips); |
| 11449 | my_getExpression (&imm_expr, s); |
| 11450 | check_absolute_expr (ip, &imm_expr); |
| 11451 | if ((long) imm_expr.X_add_number < 0 |
| 11452 | || (unsigned long) imm_expr.X_add_number + lastpos > 63) |
| 11453 | { |
| 11454 | as_bad (_("Improper size (%lu)"), |
| 11455 | (unsigned long) imm_expr.X_add_number); |
| 11456 | imm_expr.X_add_number = 0; |
| 11457 | } |
| 11458 | INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number); |
| 11459 | imm_expr.X_op = O_absent; |
| 11460 | s = expr_end; |
| 11461 | continue; |
| 11462 | |
| 11463 | case 'Q': |
| 11464 | /* seqi/snei immediate field. */ |
| 11465 | gas_assert (!mips_opts.micromips); |
| 11466 | my_getExpression (&imm_expr, s); |
| 11467 | check_absolute_expr (ip, &imm_expr); |
| 11468 | if ((long) imm_expr.X_add_number < -512 |
| 11469 | || (long) imm_expr.X_add_number >= 512) |
| 11470 | { |
| 11471 | as_bad (_("Improper immediate (%ld)"), |
| 11472 | (long) imm_expr.X_add_number); |
| 11473 | imm_expr.X_add_number = 0; |
| 11474 | } |
| 11475 | INSERT_OPERAND (0, SEQI, *ip, imm_expr.X_add_number); |
| 11476 | imm_expr.X_op = O_absent; |
| 11477 | s = expr_end; |
| 11478 | continue; |
| 11479 | |
| 11480 | case 'a': /* 8-bit signed offset in bit 6 */ |
| 11481 | gas_assert (!mips_opts.micromips); |
| 11482 | my_getExpression (&imm_expr, s); |
| 11483 | check_absolute_expr (ip, &imm_expr); |
| 11484 | min_range = -((OP_MASK_OFFSET_A + 1) >> 1); |
| 11485 | max_range = ((OP_MASK_OFFSET_A + 1) >> 1) - 1; |
| 11486 | if (imm_expr.X_add_number < min_range |
| 11487 | || imm_expr.X_add_number > max_range) |
| 11488 | { |
| 11489 | as_bad (_("Offset not in range %ld..%ld (%ld)"), |
| 11490 | (long) min_range, (long) max_range, |
| 11491 | (long) imm_expr.X_add_number); |
| 11492 | } |
| 11493 | INSERT_OPERAND (0, OFFSET_A, *ip, imm_expr.X_add_number); |
| 11494 | imm_expr.X_op = O_absent; |
| 11495 | s = expr_end; |
| 11496 | continue; |
| 11497 | |
| 11498 | case 'b': /* 8-bit signed offset in bit 3 */ |
| 11499 | gas_assert (!mips_opts.micromips); |
| 11500 | my_getExpression (&imm_expr, s); |
| 11501 | check_absolute_expr (ip, &imm_expr); |
| 11502 | min_range = -((OP_MASK_OFFSET_B + 1) >> 1); |
| 11503 | max_range = ((OP_MASK_OFFSET_B + 1) >> 1) - 1; |
| 11504 | if (imm_expr.X_add_number < min_range |
| 11505 | || imm_expr.X_add_number > max_range) |
| 11506 | { |
| 11507 | as_bad (_("Offset not in range %ld..%ld (%ld)"), |
| 11508 | (long) min_range, (long) max_range, |
| 11509 | (long) imm_expr.X_add_number); |
| 11510 | } |
| 11511 | INSERT_OPERAND (0, OFFSET_B, *ip, imm_expr.X_add_number); |
| 11512 | imm_expr.X_op = O_absent; |
| 11513 | s = expr_end; |
| 11514 | continue; |
| 11515 | |
| 11516 | case 'c': /* 9-bit signed offset in bit 6 */ |
| 11517 | gas_assert (!mips_opts.micromips); |
| 11518 | my_getExpression (&imm_expr, s); |
| 11519 | check_absolute_expr (ip, &imm_expr); |
| 11520 | min_range = -((OP_MASK_OFFSET_C + 1) >> 1); |
| 11521 | max_range = ((OP_MASK_OFFSET_C + 1) >> 1) - 1; |
| 11522 | /* We check the offset range before adjusted. */ |
| 11523 | min_range <<= 4; |
| 11524 | max_range <<= 4; |
| 11525 | if (imm_expr.X_add_number < min_range |
| 11526 | || imm_expr.X_add_number > max_range) |
| 11527 | { |
| 11528 | as_bad (_("Offset not in range %ld..%ld (%ld)"), |
| 11529 | (long) min_range, (long) max_range, |
| 11530 | (long) imm_expr.X_add_number); |
| 11531 | } |
| 11532 | if (imm_expr.X_add_number & 0xf) |
| 11533 | { |
| 11534 | as_bad (_("Offset not 16 bytes alignment (%ld)"), |
| 11535 | (long) imm_expr.X_add_number); |
| 11536 | } |
| 11537 | /* Right shift 4 bits to adjust the offset operand. */ |
| 11538 | INSERT_OPERAND (0, OFFSET_C, *ip, |
| 11539 | imm_expr.X_add_number >> 4); |
| 11540 | imm_expr.X_op = O_absent; |
| 11541 | s = expr_end; |
| 11542 | continue; |
| 11543 | |
| 11544 | case 'z': |
| 11545 | gas_assert (!mips_opts.micromips); |
| 11546 | if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no)) |
| 11547 | break; |
| 11548 | if (regno == AT && mips_opts.at) |
| 11549 | { |
| 11550 | if (mips_opts.at == ATREG) |
| 11551 | as_warn (_("used $at without \".set noat\"")); |
| 11552 | else |
| 11553 | as_warn (_("used $%u with \".set at=$%u\""), |
| 11554 | regno, mips_opts.at); |
| 11555 | } |
| 11556 | INSERT_OPERAND (0, RZ, *ip, regno); |
| 11557 | continue; |
| 11558 | |
| 11559 | case 'Z': |
| 11560 | gas_assert (!mips_opts.micromips); |
| 11561 | if (!reg_lookup (&s, RTYPE_FPU, ®no)) |
| 11562 | break; |
| 11563 | INSERT_OPERAND (0, FZ, *ip, regno); |
| 11564 | continue; |
| 11565 | |
| 11566 | default: |
| 11567 | as_bad (_("Internal error: bad %s opcode " |
| 11568 | "(unknown extension operand type `+%c'): %s %s"), |
| 11569 | mips_opts.micromips ? "microMIPS" : "MIPS", |
| 11570 | *args, insn->name, insn->args); |
| 11571 | /* Further processing is fruitless. */ |
| 11572 | return; |
| 11573 | } |
| 11574 | break; |
| 11575 | |
| 11576 | case '.': /* 10-bit offset. */ |
| 11577 | gas_assert (mips_opts.micromips); |
| 11578 | case '~': /* 12-bit offset. */ |
| 11579 | { |
| 11580 | int shift = *args == '.' ? 9 : 11; |
| 11581 | size_t i; |
| 11582 | |
| 11583 | /* Check whether there is only a single bracketed expression |
| 11584 | left. If so, it must be the base register and the |
| 11585 | constant must be zero. */ |
| 11586 | if (*s == '(' && strchr (s + 1, '(') == 0) |
| 11587 | continue; |
| 11588 | |
| 11589 | /* If this value won't fit into the offset, then go find |
| 11590 | a macro that will generate a 16- or 32-bit offset code |
| 11591 | pattern. */ |
| 11592 | i = my_getSmallExpression (&imm_expr, imm_reloc, s); |
| 11593 | if ((i == 0 && (imm_expr.X_op != O_constant |
| 11594 | || imm_expr.X_add_number >= 1 << shift |
| 11595 | || imm_expr.X_add_number < -1 << shift)) |
| 11596 | || i > 0) |
| 11597 | { |
| 11598 | imm_expr.X_op = O_absent; |
| 11599 | break; |
| 11600 | } |
| 11601 | if (shift == 9) |
| 11602 | INSERT_OPERAND (1, OFFSET10, *ip, imm_expr.X_add_number); |
| 11603 | else |
| 11604 | INSERT_OPERAND (mips_opts.micromips, |
| 11605 | OFFSET12, *ip, imm_expr.X_add_number); |
| 11606 | imm_expr.X_op = O_absent; |
| 11607 | s = expr_end; |
| 11608 | } |
| 11609 | continue; |
| 11610 | |
| 11611 | case '<': /* must be at least one digit */ |
| 11612 | /* |
| 11613 | * According to the manual, if the shift amount is greater |
| 11614 | * than 31 or less than 0, then the shift amount should be |
| 11615 | * mod 32. In reality the mips assembler issues an error. |
| 11616 | * We issue a warning and mask out all but the low 5 bits. |
| 11617 | */ |
| 11618 | my_getExpression (&imm_expr, s); |
| 11619 | check_absolute_expr (ip, &imm_expr); |
| 11620 | if ((unsigned long) imm_expr.X_add_number > 31) |
| 11621 | as_warn (_("Improper shift amount (%lu)"), |
| 11622 | (unsigned long) imm_expr.X_add_number); |
| 11623 | INSERT_OPERAND (mips_opts.micromips, |
| 11624 | SHAMT, *ip, imm_expr.X_add_number); |
| 11625 | imm_expr.X_op = O_absent; |
| 11626 | s = expr_end; |
| 11627 | continue; |
| 11628 | |
| 11629 | case '>': /* shift amount minus 32 */ |
| 11630 | my_getExpression (&imm_expr, s); |
| 11631 | check_absolute_expr (ip, &imm_expr); |
| 11632 | if ((unsigned long) imm_expr.X_add_number < 32 |
| 11633 | || (unsigned long) imm_expr.X_add_number > 63) |
| 11634 | break; |
| 11635 | INSERT_OPERAND (mips_opts.micromips, |
| 11636 | SHAMT, *ip, imm_expr.X_add_number - 32); |
| 11637 | imm_expr.X_op = O_absent; |
| 11638 | s = expr_end; |
| 11639 | continue; |
| 11640 | |
| 11641 | case 'k': /* CACHE code. */ |
| 11642 | case 'h': /* PREFX code. */ |
| 11643 | case '1': /* SYNC type. */ |
| 11644 | my_getExpression (&imm_expr, s); |
| 11645 | check_absolute_expr (ip, &imm_expr); |
| 11646 | if ((unsigned long) imm_expr.X_add_number > 31) |
| 11647 | as_warn (_("Invalid value for `%s' (%lu)"), |
| 11648 | ip->insn_mo->name, |
| 11649 | (unsigned long) imm_expr.X_add_number); |
| 11650 | switch (*args) |
| 11651 | { |
| 11652 | case 'k': |
| 11653 | if (mips_fix_cn63xxp1 |
| 11654 | && !mips_opts.micromips |
| 11655 | && strcmp ("pref", insn->name) == 0) |
| 11656 | switch (imm_expr.X_add_number) |
| 11657 | { |
| 11658 | case 5: |
| 11659 | case 25: |
| 11660 | case 26: |
| 11661 | case 27: |
| 11662 | case 28: |
| 11663 | case 29: |
| 11664 | case 30: |
| 11665 | case 31: /* These are ok. */ |
| 11666 | break; |
| 11667 | |
| 11668 | default: /* The rest must be changed to 28. */ |
| 11669 | imm_expr.X_add_number = 28; |
| 11670 | break; |
| 11671 | } |
| 11672 | INSERT_OPERAND (mips_opts.micromips, |
| 11673 | CACHE, *ip, imm_expr.X_add_number); |
| 11674 | break; |
| 11675 | case 'h': |
| 11676 | INSERT_OPERAND (mips_opts.micromips, |
| 11677 | PREFX, *ip, imm_expr.X_add_number); |
| 11678 | break; |
| 11679 | case '1': |
| 11680 | INSERT_OPERAND (mips_opts.micromips, |
| 11681 | STYPE, *ip, imm_expr.X_add_number); |
| 11682 | break; |
| 11683 | } |
| 11684 | imm_expr.X_op = O_absent; |
| 11685 | s = expr_end; |
| 11686 | continue; |
| 11687 | |
| 11688 | case 'c': /* BREAK code. */ |
| 11689 | { |
| 11690 | unsigned long mask = (mips_opts.micromips |
| 11691 | ? MICROMIPSOP_MASK_CODE |
| 11692 | : OP_MASK_CODE); |
| 11693 | |
| 11694 | my_getExpression (&imm_expr, s); |
| 11695 | check_absolute_expr (ip, &imm_expr); |
| 11696 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 11697 | as_warn (_("Code for %s not in range 0..%lu (%lu)"), |
| 11698 | ip->insn_mo->name, |
| 11699 | mask, (unsigned long) imm_expr.X_add_number); |
| 11700 | INSERT_OPERAND (mips_opts.micromips, |
| 11701 | CODE, *ip, imm_expr.X_add_number); |
| 11702 | imm_expr.X_op = O_absent; |
| 11703 | s = expr_end; |
| 11704 | } |
| 11705 | continue; |
| 11706 | |
| 11707 | case 'q': /* Lower BREAK code. */ |
| 11708 | { |
| 11709 | unsigned long mask = (mips_opts.micromips |
| 11710 | ? MICROMIPSOP_MASK_CODE2 |
| 11711 | : OP_MASK_CODE2); |
| 11712 | |
| 11713 | my_getExpression (&imm_expr, s); |
| 11714 | check_absolute_expr (ip, &imm_expr); |
| 11715 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 11716 | as_warn (_("Lower code for %s not in range 0..%lu (%lu)"), |
| 11717 | ip->insn_mo->name, |
| 11718 | mask, (unsigned long) imm_expr.X_add_number); |
| 11719 | INSERT_OPERAND (mips_opts.micromips, |
| 11720 | CODE2, *ip, imm_expr.X_add_number); |
| 11721 | imm_expr.X_op = O_absent; |
| 11722 | s = expr_end; |
| 11723 | } |
| 11724 | continue; |
| 11725 | |
| 11726 | case 'B': /* 20- or 10-bit syscall/break/wait code. */ |
| 11727 | { |
| 11728 | unsigned long mask = (mips_opts.micromips |
| 11729 | ? MICROMIPSOP_MASK_CODE10 |
| 11730 | : OP_MASK_CODE20); |
| 11731 | |
| 11732 | my_getExpression (&imm_expr, s); |
| 11733 | check_absolute_expr (ip, &imm_expr); |
| 11734 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 11735 | as_warn (_("Code for %s not in range 0..%lu (%lu)"), |
| 11736 | ip->insn_mo->name, |
| 11737 | mask, (unsigned long) imm_expr.X_add_number); |
| 11738 | if (mips_opts.micromips) |
| 11739 | INSERT_OPERAND (1, CODE10, *ip, imm_expr.X_add_number); |
| 11740 | else |
| 11741 | INSERT_OPERAND (0, CODE20, *ip, imm_expr.X_add_number); |
| 11742 | imm_expr.X_op = O_absent; |
| 11743 | s = expr_end; |
| 11744 | } |
| 11745 | continue; |
| 11746 | |
| 11747 | case 'C': /* 25- or 23-bit coprocessor code. */ |
| 11748 | { |
| 11749 | unsigned long mask = (mips_opts.micromips |
| 11750 | ? MICROMIPSOP_MASK_COPZ |
| 11751 | : OP_MASK_COPZ); |
| 11752 | |
| 11753 | my_getExpression (&imm_expr, s); |
| 11754 | check_absolute_expr (ip, &imm_expr); |
| 11755 | if ((unsigned long) imm_expr.X_add_number > mask) |
| 11756 | as_warn (_("Coproccesor code > %u bits (%lu)"), |
| 11757 | mips_opts.micromips ? 23U : 25U, |
| 11758 | (unsigned long) imm_expr.X_add_number); |
| 11759 | INSERT_OPERAND (mips_opts.micromips, |
| 11760 | COPZ, *ip, imm_expr.X_add_number); |
| 11761 | imm_expr.X_op = O_absent; |
| 11762 | s = expr_end; |
| 11763 | } |
| 11764 | continue; |
| 11765 | |
| 11766 | case 'J': /* 19-bit WAIT code. */ |
| 11767 | gas_assert (!mips_opts.micromips); |
| 11768 | my_getExpression (&imm_expr, s); |
| 11769 | check_absolute_expr (ip, &imm_expr); |
| 11770 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19) |
| 11771 | { |
| 11772 | as_warn (_("Illegal 19-bit code (%lu)"), |
| 11773 | (unsigned long) imm_expr.X_add_number); |
| 11774 | imm_expr.X_add_number &= OP_MASK_CODE19; |
| 11775 | } |
| 11776 | INSERT_OPERAND (0, CODE19, *ip, imm_expr.X_add_number); |
| 11777 | imm_expr.X_op = O_absent; |
| 11778 | s = expr_end; |
| 11779 | continue; |
| 11780 | |
| 11781 | case 'P': /* Performance register. */ |
| 11782 | gas_assert (!mips_opts.micromips); |
| 11783 | my_getExpression (&imm_expr, s); |
| 11784 | check_absolute_expr (ip, &imm_expr); |
| 11785 | if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1) |
| 11786 | as_warn (_("Invalid performance register (%lu)"), |
| 11787 | (unsigned long) imm_expr.X_add_number); |
| 11788 | INSERT_OPERAND (0, PERFREG, *ip, imm_expr.X_add_number); |
| 11789 | imm_expr.X_op = O_absent; |
| 11790 | s = expr_end; |
| 11791 | continue; |
| 11792 | |
| 11793 | case 'G': /* Coprocessor destination register. */ |
| 11794 | { |
| 11795 | unsigned long opcode = ip->insn_opcode; |
| 11796 | unsigned long mask; |
| 11797 | unsigned int types; |
| 11798 | int cop0; |
| 11799 | |
| 11800 | if (mips_opts.micromips) |
| 11801 | { |
| 11802 | mask = ~((MICROMIPSOP_MASK_RT << MICROMIPSOP_SH_RT) |
| 11803 | | (MICROMIPSOP_MASK_RS << MICROMIPSOP_SH_RS) |
| 11804 | | (MICROMIPSOP_MASK_SEL << MICROMIPSOP_SH_SEL)); |
| 11805 | opcode &= mask; |
| 11806 | switch (opcode) |
| 11807 | { |
| 11808 | case 0x000000fc: /* mfc0 */ |
| 11809 | case 0x000002fc: /* mtc0 */ |
| 11810 | case 0x580000fc: /* dmfc0 */ |
| 11811 | case 0x580002fc: /* dmtc0 */ |
| 11812 | cop0 = 1; |
| 11813 | break; |
| 11814 | default: |
| 11815 | cop0 = 0; |
| 11816 | break; |
| 11817 | } |
| 11818 | } |
| 11819 | else |
| 11820 | { |
| 11821 | opcode = (opcode >> OP_SH_OP) & OP_MASK_OP; |
| 11822 | cop0 = opcode == OP_OP_COP0; |
| 11823 | } |
| 11824 | types = RTYPE_NUM | (cop0 ? RTYPE_CP0 : RTYPE_GP); |
| 11825 | ok = reg_lookup (&s, types, ®no); |
| 11826 | if (mips_opts.micromips) |
| 11827 | INSERT_OPERAND (1, RS, *ip, regno); |
| 11828 | else |
| 11829 | INSERT_OPERAND (0, RD, *ip, regno); |
| 11830 | if (ok) |
| 11831 | { |
| 11832 | lastregno = regno; |
| 11833 | continue; |
| 11834 | } |
| 11835 | } |
| 11836 | break; |
| 11837 | |
| 11838 | case 'y': /* ALNV.PS source register. */ |
| 11839 | gas_assert (mips_opts.micromips); |
| 11840 | goto do_reg; |
| 11841 | case 'x': /* Ignore register name. */ |
| 11842 | case 'U': /* Destination register (CLO/CLZ). */ |
| 11843 | case 'g': /* Coprocessor destination register. */ |
| 11844 | gas_assert (!mips_opts.micromips); |
| 11845 | case 'b': /* Base register. */ |
| 11846 | case 'd': /* Destination register. */ |
| 11847 | case 's': /* Source register. */ |
| 11848 | case 't': /* Target register. */ |
| 11849 | case 'r': /* Both target and source. */ |
| 11850 | case 'v': /* Both dest and source. */ |
| 11851 | case 'w': /* Both dest and target. */ |
| 11852 | case 'E': /* Coprocessor target register. */ |
| 11853 | case 'K': /* RDHWR destination register. */ |
| 11854 | case 'z': /* Must be zero register. */ |
| 11855 | do_reg: |
| 11856 | s_reset = s; |
| 11857 | if (*args == 'E' || *args == 'K') |
| 11858 | ok = reg_lookup (&s, RTYPE_NUM, ®no); |
| 11859 | else |
| 11860 | { |
| 11861 | ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no); |
| 11862 | if (regno == AT && mips_opts.at) |
| 11863 | { |
| 11864 | if (mips_opts.at == ATREG) |
| 11865 | as_warn (_("Used $at without \".set noat\"")); |
| 11866 | else |
| 11867 | as_warn (_("Used $%u with \".set at=$%u\""), |
| 11868 | regno, mips_opts.at); |
| 11869 | } |
| 11870 | } |
| 11871 | if (ok) |
| 11872 | { |
| 11873 | c = *args; |
| 11874 | if (*s == ' ') |
| 11875 | ++s; |
| 11876 | if (args[1] != *s) |
| 11877 | { |
| 11878 | if (c == 'r' || c == 'v' || c == 'w') |
| 11879 | { |
| 11880 | regno = lastregno; |
| 11881 | s = s_reset; |
| 11882 | ++args; |
| 11883 | } |
| 11884 | } |
| 11885 | /* 'z' only matches $0. */ |
| 11886 | if (c == 'z' && regno != 0) |
| 11887 | break; |
| 11888 | |
| 11889 | if (c == 's' && !strncmp (ip->insn_mo->name, "jalr", 4)) |
| 11890 | { |
| 11891 | if (regno == lastregno) |
| 11892 | { |
| 11893 | insn_error |
| 11894 | = _("Source and destination must be different"); |
| 11895 | continue; |
| 11896 | } |
| 11897 | if (regno == 31 && lastregno == 0xffffffff) |
| 11898 | { |
| 11899 | insn_error |
| 11900 | = _("A destination register must be supplied"); |
| 11901 | continue; |
| 11902 | } |
| 11903 | } |
| 11904 | /* Now that we have assembled one operand, we use the args |
| 11905 | string to figure out where it goes in the instruction. */ |
| 11906 | switch (c) |
| 11907 | { |
| 11908 | case 'r': |
| 11909 | case 's': |
| 11910 | case 'v': |
| 11911 | case 'b': |
| 11912 | INSERT_OPERAND (mips_opts.micromips, RS, *ip, regno); |
| 11913 | break; |
| 11914 | |
| 11915 | case 'K': |
| 11916 | if (mips_opts.micromips) |
| 11917 | INSERT_OPERAND (1, RS, *ip, regno); |
| 11918 | else |
| 11919 | INSERT_OPERAND (0, RD, *ip, regno); |
| 11920 | break; |
| 11921 | |
| 11922 | case 'd': |
| 11923 | case 'g': |
| 11924 | INSERT_OPERAND (mips_opts.micromips, RD, *ip, regno); |
| 11925 | break; |
| 11926 | |
| 11927 | case 'U': |
| 11928 | gas_assert (!mips_opts.micromips); |
| 11929 | INSERT_OPERAND (0, RD, *ip, regno); |
| 11930 | INSERT_OPERAND (0, RT, *ip, regno); |
| 11931 | break; |
| 11932 | |
| 11933 | case 'w': |
| 11934 | case 't': |
| 11935 | case 'E': |
| 11936 | INSERT_OPERAND (mips_opts.micromips, RT, *ip, regno); |
| 11937 | break; |
| 11938 | |
| 11939 | case 'y': |
| 11940 | gas_assert (mips_opts.micromips); |
| 11941 | INSERT_OPERAND (1, RS3, *ip, regno); |
| 11942 | break; |
| 11943 | |
| 11944 | case 'x': |
| 11945 | /* This case exists because on the r3000 trunc |
| 11946 | expands into a macro which requires a gp |
| 11947 | register. On the r6000 or r4000 it is |
| 11948 | assembled into a single instruction which |
| 11949 | ignores the register. Thus the insn version |
| 11950 | is MIPS_ISA2 and uses 'x', and the macro |
| 11951 | version is MIPS_ISA1 and uses 't'. */ |
| 11952 | break; |
| 11953 | |
| 11954 | case 'z': |
| 11955 | /* This case is for the div instruction, which |
| 11956 | acts differently if the destination argument |
| 11957 | is $0. This only matches $0, and is checked |
| 11958 | outside the switch. */ |
| 11959 | break; |
| 11960 | } |
| 11961 | lastregno = regno; |
| 11962 | continue; |
| 11963 | } |
| 11964 | switch (*args++) |
| 11965 | { |
| 11966 | case 'r': |
| 11967 | case 'v': |
| 11968 | INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno); |
| 11969 | continue; |
| 11970 | |
| 11971 | case 'w': |
| 11972 | INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno); |
| 11973 | continue; |
| 11974 | } |
| 11975 | break; |
| 11976 | |
| 11977 | case 'O': /* MDMX alignment immediate constant. */ |
| 11978 | gas_assert (!mips_opts.micromips); |
| 11979 | my_getExpression (&imm_expr, s); |
| 11980 | check_absolute_expr (ip, &imm_expr); |
| 11981 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN) |
| 11982 | as_warn (_("Improper align amount (%ld), using low bits"), |
| 11983 | (long) imm_expr.X_add_number); |
| 11984 | INSERT_OPERAND (0, ALN, *ip, imm_expr.X_add_number); |
| 11985 | imm_expr.X_op = O_absent; |
| 11986 | s = expr_end; |
| 11987 | continue; |
| 11988 | |
| 11989 | case 'Q': /* MDMX vector, element sel, or const. */ |
| 11990 | if (s[0] != '$') |
| 11991 | { |
| 11992 | /* MDMX Immediate. */ |
| 11993 | gas_assert (!mips_opts.micromips); |
| 11994 | my_getExpression (&imm_expr, s); |
| 11995 | check_absolute_expr (ip, &imm_expr); |
| 11996 | if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT) |
| 11997 | as_warn (_("Invalid MDMX Immediate (%ld)"), |
| 11998 | (long) imm_expr.X_add_number); |
| 11999 | INSERT_OPERAND (0, FT, *ip, imm_expr.X_add_number); |
| 12000 | if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL)) |
| 12001 | ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL; |
| 12002 | else |
| 12003 | ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL; |
| 12004 | imm_expr.X_op = O_absent; |
| 12005 | s = expr_end; |
| 12006 | continue; |
| 12007 | } |
| 12008 | /* Not MDMX Immediate. Fall through. */ |
| 12009 | case 'X': /* MDMX destination register. */ |
| 12010 | case 'Y': /* MDMX source register. */ |
| 12011 | case 'Z': /* MDMX target register. */ |
| 12012 | is_mdmx = 1; |
| 12013 | case 'W': |
| 12014 | gas_assert (!mips_opts.micromips); |
| 12015 | case 'D': /* Floating point destination register. */ |
| 12016 | case 'S': /* Floating point source register. */ |
| 12017 | case 'T': /* Floating point target register. */ |
| 12018 | case 'R': /* Floating point source register. */ |
| 12019 | case 'V': |
| 12020 | rtype = RTYPE_FPU; |
| 12021 | if (is_mdmx |
| 12022 | || (mips_opts.ase_mdmx |
| 12023 | && (ip->insn_mo->pinfo & FP_D) |
| 12024 | && (ip->insn_mo->pinfo & (INSN_COPROC_MOVE_DELAY |
| 12025 | | INSN_COPROC_MEMORY_DELAY |
| 12026 | | INSN_LOAD_COPROC_DELAY |
| 12027 | | INSN_LOAD_MEMORY_DELAY |
| 12028 | | INSN_STORE_MEMORY)))) |
| 12029 | rtype |= RTYPE_VEC; |
| 12030 | s_reset = s; |
| 12031 | if (reg_lookup (&s, rtype, ®no)) |
| 12032 | { |
| 12033 | if ((regno & 1) != 0 |
| 12034 | && HAVE_32BIT_FPRS |
| 12035 | && !mips_oddfpreg_ok (ip->insn_mo, argnum)) |
| 12036 | as_warn (_("Float register should be even, was %d"), |
| 12037 | regno); |
| 12038 | |
| 12039 | c = *args; |
| 12040 | if (*s == ' ') |
| 12041 | ++s; |
| 12042 | if (args[1] != *s) |
| 12043 | { |
| 12044 | if (c == 'V' || c == 'W') |
| 12045 | { |
| 12046 | regno = lastregno; |
| 12047 | s = s_reset; |
| 12048 | ++args; |
| 12049 | } |
| 12050 | } |
| 12051 | switch (c) |
| 12052 | { |
| 12053 | case 'D': |
| 12054 | case 'X': |
| 12055 | INSERT_OPERAND (mips_opts.micromips, FD, *ip, regno); |
| 12056 | break; |
| 12057 | |
| 12058 | case 'V': |
| 12059 | case 'S': |
| 12060 | case 'Y': |
| 12061 | INSERT_OPERAND (mips_opts.micromips, FS, *ip, regno); |
| 12062 | break; |
| 12063 | |
| 12064 | case 'Q': |
| 12065 | /* This is like 'Z', but also needs to fix the MDMX |
| 12066 | vector/scalar select bits. Note that the |
| 12067 | scalar immediate case is handled above. */ |
| 12068 | if (*s == '[') |
| 12069 | { |
| 12070 | int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL)); |
| 12071 | int max_el = (is_qh ? 3 : 7); |
| 12072 | s++; |
| 12073 | my_getExpression(&imm_expr, s); |
| 12074 | check_absolute_expr (ip, &imm_expr); |
| 12075 | s = expr_end; |
| 12076 | if (imm_expr.X_add_number > max_el) |
| 12077 | as_bad (_("Bad element selector %ld"), |
| 12078 | (long) imm_expr.X_add_number); |
| 12079 | imm_expr.X_add_number &= max_el; |
| 12080 | ip->insn_opcode |= (imm_expr.X_add_number |
| 12081 | << (OP_SH_VSEL + |
| 12082 | (is_qh ? 2 : 1))); |
| 12083 | imm_expr.X_op = O_absent; |
| 12084 | if (*s != ']') |
| 12085 | as_warn (_("Expecting ']' found '%s'"), s); |
| 12086 | else |
| 12087 | s++; |
| 12088 | } |
| 12089 | else |
| 12090 | { |
| 12091 | if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL)) |
| 12092 | ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH |
| 12093 | << OP_SH_VSEL); |
| 12094 | else |
| 12095 | ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB << |
| 12096 | OP_SH_VSEL); |
| 12097 | } |
| 12098 | /* Fall through. */ |
| 12099 | case 'W': |
| 12100 | case 'T': |
| 12101 | case 'Z': |
| 12102 | INSERT_OPERAND (mips_opts.micromips, FT, *ip, regno); |
| 12103 | break; |
| 12104 | |
| 12105 | case 'R': |
| 12106 | INSERT_OPERAND (mips_opts.micromips, FR, *ip, regno); |
| 12107 | break; |
| 12108 | } |
| 12109 | lastregno = regno; |
| 12110 | continue; |
| 12111 | } |
| 12112 | |
| 12113 | switch (*args++) |
| 12114 | { |
| 12115 | case 'V': |
| 12116 | INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno); |
| 12117 | continue; |
| 12118 | |
| 12119 | case 'W': |
| 12120 | INSERT_OPERAND (mips_opts.micromips, FT, *ip, lastregno); |
| 12121 | continue; |
| 12122 | } |
| 12123 | break; |
| 12124 | |
| 12125 | case 'I': |
| 12126 | my_getExpression (&imm_expr, s); |
| 12127 | if (imm_expr.X_op != O_big |
| 12128 | && imm_expr.X_op != O_constant) |
| 12129 | insn_error = _("absolute expression required"); |
| 12130 | if (HAVE_32BIT_GPRS) |
| 12131 | normalize_constant_expr (&imm_expr); |
| 12132 | s = expr_end; |
| 12133 | continue; |
| 12134 | |
| 12135 | case 'A': |
| 12136 | my_getExpression (&offset_expr, s); |
| 12137 | normalize_address_expr (&offset_expr); |
| 12138 | *imm_reloc = BFD_RELOC_32; |
| 12139 | s = expr_end; |
| 12140 | continue; |
| 12141 | |
| 12142 | case 'F': |
| 12143 | case 'L': |
| 12144 | case 'f': |
| 12145 | case 'l': |
| 12146 | { |
| 12147 | int f64; |
| 12148 | int using_gprs; |
| 12149 | char *save_in; |
| 12150 | char *err; |
| 12151 | unsigned char temp[8]; |
| 12152 | int len; |
| 12153 | unsigned int length; |
| 12154 | segT seg; |
| 12155 | subsegT subseg; |
| 12156 | char *p; |
| 12157 | |
| 12158 | /* These only appear as the last operand in an |
| 12159 | instruction, and every instruction that accepts |
| 12160 | them in any variant accepts them in all variants. |
| 12161 | This means we don't have to worry about backing out |
| 12162 | any changes if the instruction does not match. |
| 12163 | |
| 12164 | The difference between them is the size of the |
| 12165 | floating point constant and where it goes. For 'F' |
| 12166 | and 'L' the constant is 64 bits; for 'f' and 'l' it |
| 12167 | is 32 bits. Where the constant is placed is based |
| 12168 | on how the MIPS assembler does things: |
| 12169 | F -- .rdata |
| 12170 | L -- .lit8 |
| 12171 | f -- immediate value |
| 12172 | l -- .lit4 |
| 12173 | |
| 12174 | The .lit4 and .lit8 sections are only used if |
| 12175 | permitted by the -G argument. |
| 12176 | |
| 12177 | The code below needs to know whether the target register |
| 12178 | is 32 or 64 bits wide. It relies on the fact 'f' and |
| 12179 | 'F' are used with GPR-based instructions and 'l' and |
| 12180 | 'L' are used with FPR-based instructions. */ |
| 12181 | |
| 12182 | f64 = *args == 'F' || *args == 'L'; |
| 12183 | using_gprs = *args == 'F' || *args == 'f'; |
| 12184 | |
| 12185 | save_in = input_line_pointer; |
| 12186 | input_line_pointer = s; |
| 12187 | err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len); |
| 12188 | length = len; |
| 12189 | s = input_line_pointer; |
| 12190 | input_line_pointer = save_in; |
| 12191 | if (err != NULL && *err != '\0') |
| 12192 | { |
| 12193 | as_bad (_("Bad floating point constant: %s"), err); |
| 12194 | memset (temp, '\0', sizeof temp); |
| 12195 | length = f64 ? 8 : 4; |
| 12196 | } |
| 12197 | |
| 12198 | gas_assert (length == (unsigned) (f64 ? 8 : 4)); |
| 12199 | |
| 12200 | if (*args == 'f' |
| 12201 | || (*args == 'l' |
| 12202 | && (g_switch_value < 4 |
| 12203 | || (temp[0] == 0 && temp[1] == 0) |
| 12204 | || (temp[2] == 0 && temp[3] == 0)))) |
| 12205 | { |
| 12206 | imm_expr.X_op = O_constant; |
| 12207 | if (!target_big_endian) |
| 12208 | imm_expr.X_add_number = bfd_getl32 (temp); |
| 12209 | else |
| 12210 | imm_expr.X_add_number = bfd_getb32 (temp); |
| 12211 | } |
| 12212 | else if (length > 4 |
| 12213 | && !mips_disable_float_construction |
| 12214 | /* Constants can only be constructed in GPRs and |
| 12215 | copied to FPRs if the GPRs are at least as wide |
| 12216 | as the FPRs. Force the constant into memory if |
| 12217 | we are using 64-bit FPRs but the GPRs are only |
| 12218 | 32 bits wide. */ |
| 12219 | && (using_gprs |
| 12220 | || !(HAVE_64BIT_FPRS && HAVE_32BIT_GPRS)) |
| 12221 | && ((temp[0] == 0 && temp[1] == 0) |
| 12222 | || (temp[2] == 0 && temp[3] == 0)) |
| 12223 | && ((temp[4] == 0 && temp[5] == 0) |
| 12224 | || (temp[6] == 0 && temp[7] == 0))) |
| 12225 | { |
| 12226 | /* The value is simple enough to load with a couple of |
| 12227 | instructions. If using 32-bit registers, set |
| 12228 | imm_expr to the high order 32 bits and offset_expr to |
| 12229 | the low order 32 bits. Otherwise, set imm_expr to |
| 12230 | the entire 64 bit constant. */ |
| 12231 | if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS) |
| 12232 | { |
| 12233 | imm_expr.X_op = O_constant; |
| 12234 | offset_expr.X_op = O_constant; |
| 12235 | if (!target_big_endian) |
| 12236 | { |
| 12237 | imm_expr.X_add_number = bfd_getl32 (temp + 4); |
| 12238 | offset_expr.X_add_number = bfd_getl32 (temp); |
| 12239 | } |
| 12240 | else |
| 12241 | { |
| 12242 | imm_expr.X_add_number = bfd_getb32 (temp); |
| 12243 | offset_expr.X_add_number = bfd_getb32 (temp + 4); |
| 12244 | } |
| 12245 | if (offset_expr.X_add_number == 0) |
| 12246 | offset_expr.X_op = O_absent; |
| 12247 | } |
| 12248 | else if (sizeof (imm_expr.X_add_number) > 4) |
| 12249 | { |
| 12250 | imm_expr.X_op = O_constant; |
| 12251 | if (!target_big_endian) |
| 12252 | imm_expr.X_add_number = bfd_getl64 (temp); |
| 12253 | else |
| 12254 | imm_expr.X_add_number = bfd_getb64 (temp); |
| 12255 | } |
| 12256 | else |
| 12257 | { |
| 12258 | imm_expr.X_op = O_big; |
| 12259 | imm_expr.X_add_number = 4; |
| 12260 | if (!target_big_endian) |
| 12261 | { |
| 12262 | generic_bignum[0] = bfd_getl16 (temp); |
| 12263 | generic_bignum[1] = bfd_getl16 (temp + 2); |
| 12264 | generic_bignum[2] = bfd_getl16 (temp + 4); |
| 12265 | generic_bignum[3] = bfd_getl16 (temp + 6); |
| 12266 | } |
| 12267 | else |
| 12268 | { |
| 12269 | generic_bignum[0] = bfd_getb16 (temp + 6); |
| 12270 | generic_bignum[1] = bfd_getb16 (temp + 4); |
| 12271 | generic_bignum[2] = bfd_getb16 (temp + 2); |
| 12272 | generic_bignum[3] = bfd_getb16 (temp); |
| 12273 | } |
| 12274 | } |
| 12275 | } |
| 12276 | else |
| 12277 | { |
| 12278 | const char *newname; |
| 12279 | segT new_seg; |
| 12280 | |
| 12281 | /* Switch to the right section. */ |
| 12282 | seg = now_seg; |
| 12283 | subseg = now_subseg; |
| 12284 | switch (*args) |
| 12285 | { |
| 12286 | default: /* unused default case avoids warnings. */ |
| 12287 | case 'L': |
| 12288 | newname = RDATA_SECTION_NAME; |
| 12289 | if (g_switch_value >= 8) |
| 12290 | newname = ".lit8"; |
| 12291 | break; |
| 12292 | case 'F': |
| 12293 | newname = RDATA_SECTION_NAME; |
| 12294 | break; |
| 12295 | case 'l': |
| 12296 | gas_assert (g_switch_value >= 4); |
| 12297 | newname = ".lit4"; |
| 12298 | break; |
| 12299 | } |
| 12300 | new_seg = subseg_new (newname, (subsegT) 0); |
| 12301 | if (IS_ELF) |
| 12302 | bfd_set_section_flags (stdoutput, new_seg, |
| 12303 | (SEC_ALLOC |
| 12304 | | SEC_LOAD |
| 12305 | | SEC_READONLY |
| 12306 | | SEC_DATA)); |
| 12307 | frag_align (*args == 'l' ? 2 : 3, 0, 0); |
| 12308 | if (IS_ELF && strncmp (TARGET_OS, "elf", 3) != 0) |
| 12309 | record_alignment (new_seg, 4); |
| 12310 | else |
| 12311 | record_alignment (new_seg, *args == 'l' ? 2 : 3); |
| 12312 | if (seg == now_seg) |
| 12313 | as_bad (_("Can't use floating point insn in this section")); |
| 12314 | |
| 12315 | /* Set the argument to the current address in the |
| 12316 | section. */ |
| 12317 | offset_expr.X_op = O_symbol; |
| 12318 | offset_expr.X_add_symbol = symbol_temp_new_now (); |
| 12319 | offset_expr.X_add_number = 0; |
| 12320 | |
| 12321 | /* Put the floating point number into the section. */ |
| 12322 | p = frag_more ((int) length); |
| 12323 | memcpy (p, temp, length); |
| 12324 | |
| 12325 | /* Switch back to the original section. */ |
| 12326 | subseg_set (seg, subseg); |
| 12327 | } |
| 12328 | } |
| 12329 | continue; |
| 12330 | |
| 12331 | case 'i': /* 16-bit unsigned immediate. */ |
| 12332 | case 'j': /* 16-bit signed immediate. */ |
| 12333 | *imm_reloc = BFD_RELOC_LO16; |
| 12334 | if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0) |
| 12335 | { |
| 12336 | int more; |
| 12337 | offsetT minval, maxval; |
| 12338 | |
| 12339 | more = (insn + 1 < past |
| 12340 | && strcmp (insn->name, insn[1].name) == 0); |
| 12341 | |
| 12342 | /* If the expression was written as an unsigned number, |
| 12343 | only treat it as signed if there are no more |
| 12344 | alternatives. */ |
| 12345 | if (more |
| 12346 | && *args == 'j' |
| 12347 | && sizeof (imm_expr.X_add_number) <= 4 |
| 12348 | && imm_expr.X_op == O_constant |
| 12349 | && imm_expr.X_add_number < 0 |
| 12350 | && imm_expr.X_unsigned |
| 12351 | && HAVE_64BIT_GPRS) |
| 12352 | break; |
| 12353 | |
| 12354 | /* For compatibility with older assemblers, we accept |
| 12355 | 0x8000-0xffff as signed 16-bit numbers when only |
| 12356 | signed numbers are allowed. */ |
| 12357 | if (*args == 'i') |
| 12358 | minval = 0, maxval = 0xffff; |
| 12359 | else if (more) |
| 12360 | minval = -0x8000, maxval = 0x7fff; |
| 12361 | else |
| 12362 | minval = -0x8000, maxval = 0xffff; |
| 12363 | |
| 12364 | if (imm_expr.X_op != O_constant |
| 12365 | || imm_expr.X_add_number < minval |
| 12366 | || imm_expr.X_add_number > maxval) |
| 12367 | { |
| 12368 | if (more) |
| 12369 | break; |
| 12370 | if (imm_expr.X_op == O_constant |
| 12371 | || imm_expr.X_op == O_big) |
| 12372 | as_bad (_("Expression out of range")); |
| 12373 | } |
| 12374 | } |
| 12375 | s = expr_end; |
| 12376 | continue; |
| 12377 | |
| 12378 | case 'o': /* 16-bit offset. */ |
| 12379 | offset_reloc[0] = BFD_RELOC_LO16; |
| 12380 | offset_reloc[1] = BFD_RELOC_UNUSED; |
| 12381 | offset_reloc[2] = BFD_RELOC_UNUSED; |
| 12382 | |
| 12383 | /* Check whether there is only a single bracketed expression |
| 12384 | left. If so, it must be the base register and the |
| 12385 | constant must be zero. */ |
| 12386 | if (*s == '(' && strchr (s + 1, '(') == 0) |
| 12387 | { |
| 12388 | offset_expr.X_op = O_constant; |
| 12389 | offset_expr.X_add_number = 0; |
| 12390 | continue; |
| 12391 | } |
| 12392 | |
| 12393 | /* If this value won't fit into a 16 bit offset, then go |
| 12394 | find a macro that will generate the 32 bit offset |
| 12395 | code pattern. */ |
| 12396 | if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0 |
| 12397 | && (offset_expr.X_op != O_constant |
| 12398 | || offset_expr.X_add_number >= 0x8000 |
| 12399 | || offset_expr.X_add_number < -0x8000)) |
| 12400 | break; |
| 12401 | |
| 12402 | s = expr_end; |
| 12403 | continue; |
| 12404 | |
| 12405 | case 'p': /* PC-relative offset. */ |
| 12406 | *offset_reloc = BFD_RELOC_16_PCREL_S2; |
| 12407 | my_getExpression (&offset_expr, s); |
| 12408 | s = expr_end; |
| 12409 | continue; |
| 12410 | |
| 12411 | case 'u': /* Upper 16 bits. */ |
| 12412 | if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0 |
| 12413 | && imm_expr.X_op == O_constant |
| 12414 | && (imm_expr.X_add_number < 0 |
| 12415 | || imm_expr.X_add_number >= 0x10000)) |
| 12416 | as_bad (_("lui expression (%lu) not in range 0..65535"), |
| 12417 | (unsigned long) imm_expr.X_add_number); |
| 12418 | s = expr_end; |
| 12419 | continue; |
| 12420 | |
| 12421 | case 'a': /* 26-bit address. */ |
| 12422 | *offset_reloc = BFD_RELOC_MIPS_JMP; |
| 12423 | my_getExpression (&offset_expr, s); |
| 12424 | s = expr_end; |
| 12425 | continue; |
| 12426 | |
| 12427 | case 'N': /* 3-bit branch condition code. */ |
| 12428 | case 'M': /* 3-bit compare condition code. */ |
| 12429 | rtype = RTYPE_CCC; |
| 12430 | if (ip->insn_mo->pinfo & (FP_D | FP_S)) |
| 12431 | rtype |= RTYPE_FCC; |
| 12432 | if (!reg_lookup (&s, rtype, ®no)) |
| 12433 | break; |
| 12434 | if ((strcmp (str + strlen (str) - 3, ".ps") == 0 |
| 12435 | || strcmp (str + strlen (str) - 5, "any2f") == 0 |
| 12436 | || strcmp (str + strlen (str) - 5, "any2t") == 0) |
| 12437 | && (regno & 1) != 0) |
| 12438 | as_warn (_("Condition code register should be even for %s, " |
| 12439 | "was %d"), |
| 12440 | str, regno); |
| 12441 | if ((strcmp (str + strlen (str) - 5, "any4f") == 0 |
| 12442 | || strcmp (str + strlen (str) - 5, "any4t") == 0) |
| 12443 | && (regno & 3) != 0) |
| 12444 | as_warn (_("Condition code register should be 0 or 4 for %s, " |
| 12445 | "was %d"), |
| 12446 | str, regno); |
| 12447 | if (*args == 'N') |
| 12448 | INSERT_OPERAND (mips_opts.micromips, BCC, *ip, regno); |
| 12449 | else |
| 12450 | INSERT_OPERAND (mips_opts.micromips, CCC, *ip, regno); |
| 12451 | continue; |
| 12452 | |
| 12453 | case 'H': |
| 12454 | if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) |
| 12455 | s += 2; |
| 12456 | if (ISDIGIT (*s)) |
| 12457 | { |
| 12458 | c = 0; |
| 12459 | do |
| 12460 | { |
| 12461 | c *= 10; |
| 12462 | c += *s - '0'; |
| 12463 | ++s; |
| 12464 | } |
| 12465 | while (ISDIGIT (*s)); |
| 12466 | } |
| 12467 | else |
| 12468 | c = 8; /* Invalid sel value. */ |
| 12469 | |
| 12470 | if (c > 7) |
| 12471 | as_bad (_("Invalid coprocessor sub-selection value (0-7)")); |
| 12472 | INSERT_OPERAND (mips_opts.micromips, SEL, *ip, c); |
| 12473 | continue; |
| 12474 | |
| 12475 | case 'e': |
| 12476 | gas_assert (!mips_opts.micromips); |
| 12477 | /* Must be at least one digit. */ |
| 12478 | my_getExpression (&imm_expr, s); |
| 12479 | check_absolute_expr (ip, &imm_expr); |
| 12480 | |
| 12481 | if ((unsigned long) imm_expr.X_add_number |
| 12482 | > (unsigned long) OP_MASK_VECBYTE) |
| 12483 | { |
| 12484 | as_bad (_("bad byte vector index (%ld)"), |
| 12485 | (long) imm_expr.X_add_number); |
| 12486 | imm_expr.X_add_number = 0; |
| 12487 | } |
| 12488 | |
| 12489 | INSERT_OPERAND (0, VECBYTE, *ip, imm_expr.X_add_number); |
| 12490 | imm_expr.X_op = O_absent; |
| 12491 | s = expr_end; |
| 12492 | continue; |
| 12493 | |
| 12494 | case '%': |
| 12495 | gas_assert (!mips_opts.micromips); |
| 12496 | my_getExpression (&imm_expr, s); |
| 12497 | check_absolute_expr (ip, &imm_expr); |
| 12498 | |
| 12499 | if ((unsigned long) imm_expr.X_add_number |
| 12500 | > (unsigned long) OP_MASK_VECALIGN) |
| 12501 | { |
| 12502 | as_bad (_("bad byte vector index (%ld)"), |
| 12503 | (long) imm_expr.X_add_number); |
| 12504 | imm_expr.X_add_number = 0; |
| 12505 | } |
| 12506 | |
| 12507 | INSERT_OPERAND (0, VECALIGN, *ip, imm_expr.X_add_number); |
| 12508 | imm_expr.X_op = O_absent; |
| 12509 | s = expr_end; |
| 12510 | continue; |
| 12511 | |
| 12512 | case 'm': /* Opcode extension character. */ |
| 12513 | gas_assert (mips_opts.micromips); |
| 12514 | c = *++args; |
| 12515 | switch (c) |
| 12516 | { |
| 12517 | case 'r': |
| 12518 | if (strncmp (s, "$pc", 3) == 0) |
| 12519 | { |
| 12520 | s += 3; |
| 12521 | continue; |
| 12522 | } |
| 12523 | break; |
| 12524 | |
| 12525 | case 'a': |
| 12526 | case 'b': |
| 12527 | case 'c': |
| 12528 | case 'd': |
| 12529 | case 'e': |
| 12530 | case 'f': |
| 12531 | case 'g': |
| 12532 | case 'h': |
| 12533 | case 'i': |
| 12534 | case 'j': |
| 12535 | case 'l': |
| 12536 | case 'm': |
| 12537 | case 'n': |
| 12538 | case 'p': |
| 12539 | case 'q': |
| 12540 | case 's': |
| 12541 | case 't': |
| 12542 | case 'x': |
| 12543 | case 'y': |
| 12544 | case 'z': |
| 12545 | s_reset = s; |
| 12546 | ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no); |
| 12547 | if (regno == AT && mips_opts.at) |
| 12548 | { |
| 12549 | if (mips_opts.at == ATREG) |
| 12550 | as_warn (_("Used $at without \".set noat\"")); |
| 12551 | else |
| 12552 | as_warn (_("Used $%u with \".set at=$%u\""), |
| 12553 | regno, mips_opts.at); |
| 12554 | } |
| 12555 | if (!ok) |
| 12556 | { |
| 12557 | if (c == 'c') |
| 12558 | { |
| 12559 | gas_assert (args[1] == ','); |
| 12560 | regno = lastregno; |
| 12561 | ++args; |
| 12562 | } |
| 12563 | else if (c == 't') |
| 12564 | { |
| 12565 | gas_assert (args[1] == ','); |
| 12566 | ++args; |
| 12567 | continue; /* Nothing to do. */ |
| 12568 | } |
| 12569 | else |
| 12570 | break; |
| 12571 | } |
| 12572 | |
| 12573 | if (c == 'j' && !strncmp (ip->insn_mo->name, "jalr", 4)) |
| 12574 | { |
| 12575 | if (regno == lastregno) |
| 12576 | { |
| 12577 | insn_error |
| 12578 | = _("Source and destination must be different"); |
| 12579 | continue; |
| 12580 | } |
| 12581 | if (regno == 31 && lastregno == 0xffffffff) |
| 12582 | { |
| 12583 | insn_error |
| 12584 | = _("A destination register must be supplied"); |
| 12585 | continue; |
| 12586 | } |
| 12587 | } |
| 12588 | |
| 12589 | if (*s == ' ') |
| 12590 | ++s; |
| 12591 | if (args[1] != *s) |
| 12592 | { |
| 12593 | if (c == 'e') |
| 12594 | { |
| 12595 | gas_assert (args[1] == ','); |
| 12596 | regno = lastregno; |
| 12597 | s = s_reset; |
| 12598 | ++args; |
| 12599 | } |
| 12600 | else if (c == 't') |
| 12601 | { |
| 12602 | gas_assert (args[1] == ','); |
| 12603 | s = s_reset; |
| 12604 | ++args; |
| 12605 | continue; /* Nothing to do. */ |
| 12606 | } |
| 12607 | } |
| 12608 | |
| 12609 | /* Make sure regno is the same as lastregno. */ |
| 12610 | if (c == 't' && regno != lastregno) |
| 12611 | break; |
| 12612 | |
| 12613 | /* Make sure regno is the same as destregno. */ |
| 12614 | if (c == 'x' && regno != destregno) |
| 12615 | break; |
| 12616 | |
| 12617 | /* We need to save regno, before regno maps to the |
| 12618 | microMIPS register encoding. */ |
| 12619 | lastregno = regno; |
| 12620 | |
| 12621 | if (c == 'f') |
| 12622 | destregno = regno; |
| 12623 | |
| 12624 | switch (c) |
| 12625 | { |
| 12626 | case 'a': |
| 12627 | if (regno != GP) |
| 12628 | regno = ILLEGAL_REG; |
| 12629 | break; |
| 12630 | |
| 12631 | case 'b': |
| 12632 | regno = mips32_to_micromips_reg_b_map[regno]; |
| 12633 | break; |
| 12634 | |
| 12635 | case 'c': |
| 12636 | regno = mips32_to_micromips_reg_c_map[regno]; |
| 12637 | break; |
| 12638 | |
| 12639 | case 'd': |
| 12640 | regno = mips32_to_micromips_reg_d_map[regno]; |
| 12641 | break; |
| 12642 | |
| 12643 | case 'e': |
| 12644 | regno = mips32_to_micromips_reg_e_map[regno]; |
| 12645 | break; |
| 12646 | |
| 12647 | case 'f': |
| 12648 | regno = mips32_to_micromips_reg_f_map[regno]; |
| 12649 | break; |
| 12650 | |
| 12651 | case 'g': |
| 12652 | regno = mips32_to_micromips_reg_g_map[regno]; |
| 12653 | break; |
| 12654 | |
| 12655 | case 'h': |
| 12656 | regno = mips32_to_micromips_reg_h_map[regno]; |
| 12657 | break; |
| 12658 | |
| 12659 | case 'i': |
| 12660 | switch (EXTRACT_OPERAND (1, MI, *ip)) |
| 12661 | { |
| 12662 | case 4: |
| 12663 | if (regno == 21) |
| 12664 | regno = 3; |
| 12665 | else if (regno == 22) |
| 12666 | regno = 4; |
| 12667 | else if (regno == 5) |
| 12668 | regno = 5; |
| 12669 | else if (regno == 6) |
| 12670 | regno = 6; |
| 12671 | else if (regno == 7) |
| 12672 | regno = 7; |
| 12673 | else |
| 12674 | regno = ILLEGAL_REG; |
| 12675 | break; |
| 12676 | |
| 12677 | case 5: |
| 12678 | if (regno == 6) |
| 12679 | regno = 0; |
| 12680 | else if (regno == 7) |
| 12681 | regno = 1; |
| 12682 | else |
| 12683 | regno = ILLEGAL_REG; |
| 12684 | break; |
| 12685 | |
| 12686 | case 6: |
| 12687 | if (regno == 7) |
| 12688 | regno = 2; |
| 12689 | else |
| 12690 | regno = ILLEGAL_REG; |
| 12691 | break; |
| 12692 | |
| 12693 | default: |
| 12694 | regno = ILLEGAL_REG; |
| 12695 | break; |
| 12696 | } |
| 12697 | break; |
| 12698 | |
| 12699 | case 'l': |
| 12700 | regno = mips32_to_micromips_reg_l_map[regno]; |
| 12701 | break; |
| 12702 | |
| 12703 | case 'm': |
| 12704 | regno = mips32_to_micromips_reg_m_map[regno]; |
| 12705 | break; |
| 12706 | |
| 12707 | case 'n': |
| 12708 | regno = mips32_to_micromips_reg_n_map[regno]; |
| 12709 | break; |
| 12710 | |
| 12711 | case 'q': |
| 12712 | regno = mips32_to_micromips_reg_q_map[regno]; |
| 12713 | break; |
| 12714 | |
| 12715 | case 's': |
| 12716 | if (regno != SP) |
| 12717 | regno = ILLEGAL_REG; |
| 12718 | break; |
| 12719 | |
| 12720 | case 'y': |
| 12721 | if (regno != 31) |
| 12722 | regno = ILLEGAL_REG; |
| 12723 | break; |
| 12724 | |
| 12725 | case 'z': |
| 12726 | if (regno != ZERO) |
| 12727 | regno = ILLEGAL_REG; |
| 12728 | break; |
| 12729 | |
| 12730 | case 'j': /* Do nothing. */ |
| 12731 | case 'p': |
| 12732 | case 't': |
| 12733 | case 'x': |
| 12734 | break; |
| 12735 | |
| 12736 | default: |
| 12737 | internalError (); |
| 12738 | } |
| 12739 | |
| 12740 | if (regno == ILLEGAL_REG) |
| 12741 | break; |
| 12742 | |
| 12743 | switch (c) |
| 12744 | { |
| 12745 | case 'b': |
| 12746 | INSERT_OPERAND (1, MB, *ip, regno); |
| 12747 | break; |
| 12748 | |
| 12749 | case 'c': |
| 12750 | INSERT_OPERAND (1, MC, *ip, regno); |
| 12751 | break; |
| 12752 | |
| 12753 | case 'd': |
| 12754 | INSERT_OPERAND (1, MD, *ip, regno); |
| 12755 | break; |
| 12756 | |
| 12757 | case 'e': |
| 12758 | INSERT_OPERAND (1, ME, *ip, regno); |
| 12759 | break; |
| 12760 | |
| 12761 | case 'f': |
| 12762 | INSERT_OPERAND (1, MF, *ip, regno); |
| 12763 | break; |
| 12764 | |
| 12765 | case 'g': |
| 12766 | INSERT_OPERAND (1, MG, *ip, regno); |
| 12767 | break; |
| 12768 | |
| 12769 | case 'h': |
| 12770 | INSERT_OPERAND (1, MH, *ip, regno); |
| 12771 | break; |
| 12772 | |
| 12773 | case 'i': |
| 12774 | INSERT_OPERAND (1, MI, *ip, regno); |
| 12775 | break; |
| 12776 | |
| 12777 | case 'j': |
| 12778 | INSERT_OPERAND (1, MJ, *ip, regno); |
| 12779 | break; |
| 12780 | |
| 12781 | case 'l': |
| 12782 | INSERT_OPERAND (1, ML, *ip, regno); |
| 12783 | break; |
| 12784 | |
| 12785 | case 'm': |
| 12786 | INSERT_OPERAND (1, MM, *ip, regno); |
| 12787 | break; |
| 12788 | |
| 12789 | case 'n': |
| 12790 | INSERT_OPERAND (1, MN, *ip, regno); |
| 12791 | break; |
| 12792 | |
| 12793 | case 'p': |
| 12794 | INSERT_OPERAND (1, MP, *ip, regno); |
| 12795 | break; |
| 12796 | |
| 12797 | case 'q': |
| 12798 | INSERT_OPERAND (1, MQ, *ip, regno); |
| 12799 | break; |
| 12800 | |
| 12801 | case 'a': /* Do nothing. */ |
| 12802 | case 's': /* Do nothing. */ |
| 12803 | case 't': /* Do nothing. */ |
| 12804 | case 'x': /* Do nothing. */ |
| 12805 | case 'y': /* Do nothing. */ |
| 12806 | case 'z': /* Do nothing. */ |
| 12807 | break; |
| 12808 | |
| 12809 | default: |
| 12810 | internalError (); |
| 12811 | } |
| 12812 | continue; |
| 12813 | |
| 12814 | case 'A': |
| 12815 | { |
| 12816 | bfd_reloc_code_real_type r[3]; |
| 12817 | expressionS ep; |
| 12818 | int imm; |
| 12819 | |
| 12820 | /* Check whether there is only a single bracketed |
| 12821 | expression left. If so, it must be the base register |
| 12822 | and the constant must be zero. */ |
| 12823 | if (*s == '(' && strchr (s + 1, '(') == 0) |
| 12824 | { |
| 12825 | INSERT_OPERAND (1, IMMA, *ip, 0); |
| 12826 | continue; |
| 12827 | } |
| 12828 | |
| 12829 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 12830 | || !expr_const_in_range (&ep, -64, 64, 2)) |
| 12831 | break; |
| 12832 | |
| 12833 | imm = ep.X_add_number >> 2; |
| 12834 | INSERT_OPERAND (1, IMMA, *ip, imm); |
| 12835 | } |
| 12836 | s = expr_end; |
| 12837 | continue; |
| 12838 | |
| 12839 | case 'B': |
| 12840 | { |
| 12841 | bfd_reloc_code_real_type r[3]; |
| 12842 | expressionS ep; |
| 12843 | int imm; |
| 12844 | |
| 12845 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 12846 | || ep.X_op != O_constant) |
| 12847 | break; |
| 12848 | |
| 12849 | for (imm = 0; imm < 8; imm++) |
| 12850 | if (micromips_imm_b_map[imm] == ep.X_add_number) |
| 12851 | break; |
| 12852 | if (imm >= 8) |
| 12853 | break; |
| 12854 | |
| 12855 | INSERT_OPERAND (1, IMMB, *ip, imm); |
| 12856 | } |
| 12857 | s = expr_end; |
| 12858 | continue; |
| 12859 | |
| 12860 | case 'C': |
| 12861 | { |
| 12862 | bfd_reloc_code_real_type r[3]; |
| 12863 | expressionS ep; |
| 12864 | int imm; |
| 12865 | |
| 12866 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 12867 | || ep.X_op != O_constant) |
| 12868 | break; |
| 12869 | |
| 12870 | for (imm = 0; imm < 16; imm++) |
| 12871 | if (micromips_imm_c_map[imm] == ep.X_add_number) |
| 12872 | break; |
| 12873 | if (imm >= 16) |
| 12874 | break; |
| 12875 | |
| 12876 | INSERT_OPERAND (1, IMMC, *ip, imm); |
| 12877 | } |
| 12878 | s = expr_end; |
| 12879 | continue; |
| 12880 | |
| 12881 | case 'D': /* pc relative offset */ |
| 12882 | case 'E': /* pc relative offset */ |
| 12883 | my_getExpression (&offset_expr, s); |
| 12884 | if (offset_expr.X_op == O_register) |
| 12885 | break; |
| 12886 | |
| 12887 | if (!forced_insn_length) |
| 12888 | *offset_reloc = (int) BFD_RELOC_UNUSED + c; |
| 12889 | else if (c == 'D') |
| 12890 | *offset_reloc = BFD_RELOC_MICROMIPS_10_PCREL_S1; |
| 12891 | else |
| 12892 | *offset_reloc = BFD_RELOC_MICROMIPS_7_PCREL_S1; |
| 12893 | s = expr_end; |
| 12894 | continue; |
| 12895 | |
| 12896 | case 'F': |
| 12897 | { |
| 12898 | bfd_reloc_code_real_type r[3]; |
| 12899 | expressionS ep; |
| 12900 | int imm; |
| 12901 | |
| 12902 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 12903 | || !expr_const_in_range (&ep, 0, 16, 0)) |
| 12904 | break; |
| 12905 | |
| 12906 | imm = ep.X_add_number; |
| 12907 | INSERT_OPERAND (1, IMMF, *ip, imm); |
| 12908 | } |
| 12909 | s = expr_end; |
| 12910 | continue; |
| 12911 | |
| 12912 | case 'G': |
| 12913 | { |
| 12914 | bfd_reloc_code_real_type r[3]; |
| 12915 | expressionS ep; |
| 12916 | int imm; |
| 12917 | |
| 12918 | /* Check whether there is only a single bracketed |
| 12919 | expression left. If so, it must be the base register |
| 12920 | and the constant must be zero. */ |
| 12921 | if (*s == '(' && strchr (s + 1, '(') == 0) |
| 12922 | { |
| 12923 | INSERT_OPERAND (1, IMMG, *ip, 0); |
| 12924 | continue; |
| 12925 | } |
| 12926 | |
| 12927 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 12928 | || !expr_const_in_range (&ep, -1, 15, 0)) |
| 12929 | break; |
| 12930 | |
| 12931 | imm = ep.X_add_number & 15; |
| 12932 | INSERT_OPERAND (1, IMMG, *ip, imm); |
| 12933 | } |
| 12934 | s = expr_end; |
| 12935 | continue; |
| 12936 | |
| 12937 | case 'H': |
| 12938 | { |
| 12939 | bfd_reloc_code_real_type r[3]; |
| 12940 | expressionS ep; |
| 12941 | int imm; |
| 12942 | |
| 12943 | /* Check whether there is only a single bracketed |
| 12944 | expression left. If so, it must be the base register |
| 12945 | and the constant must be zero. */ |
| 12946 | if (*s == '(' && strchr (s + 1, '(') == 0) |
| 12947 | { |
| 12948 | INSERT_OPERAND (1, IMMH, *ip, 0); |
| 12949 | continue; |
| 12950 | } |
| 12951 | |
| 12952 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 12953 | || !expr_const_in_range (&ep, 0, 16, 1)) |
| 12954 | break; |
| 12955 | |
| 12956 | imm = ep.X_add_number >> 1; |
| 12957 | INSERT_OPERAND (1, IMMH, *ip, imm); |
| 12958 | } |
| 12959 | s = expr_end; |
| 12960 | continue; |
| 12961 | |
| 12962 | case 'I': |
| 12963 | { |
| 12964 | bfd_reloc_code_real_type r[3]; |
| 12965 | expressionS ep; |
| 12966 | int imm; |
| 12967 | |
| 12968 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 12969 | || !expr_const_in_range (&ep, -1, 127, 0)) |
| 12970 | break; |
| 12971 | |
| 12972 | imm = ep.X_add_number & 127; |
| 12973 | INSERT_OPERAND (1, IMMI, *ip, imm); |
| 12974 | } |
| 12975 | s = expr_end; |
| 12976 | continue; |
| 12977 | |
| 12978 | case 'J': |
| 12979 | { |
| 12980 | bfd_reloc_code_real_type r[3]; |
| 12981 | expressionS ep; |
| 12982 | int imm; |
| 12983 | |
| 12984 | /* Check whether there is only a single bracketed |
| 12985 | expression left. If so, it must be the base register |
| 12986 | and the constant must be zero. */ |
| 12987 | if (*s == '(' && strchr (s + 1, '(') == 0) |
| 12988 | { |
| 12989 | INSERT_OPERAND (1, IMMJ, *ip, 0); |
| 12990 | continue; |
| 12991 | } |
| 12992 | |
| 12993 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 12994 | || !expr_const_in_range (&ep, 0, 16, 2)) |
| 12995 | break; |
| 12996 | |
| 12997 | imm = ep.X_add_number >> 2; |
| 12998 | INSERT_OPERAND (1, IMMJ, *ip, imm); |
| 12999 | } |
| 13000 | s = expr_end; |
| 13001 | continue; |
| 13002 | |
| 13003 | case 'L': |
| 13004 | { |
| 13005 | bfd_reloc_code_real_type r[3]; |
| 13006 | expressionS ep; |
| 13007 | int imm; |
| 13008 | |
| 13009 | /* Check whether there is only a single bracketed |
| 13010 | expression left. If so, it must be the base register |
| 13011 | and the constant must be zero. */ |
| 13012 | if (*s == '(' && strchr (s + 1, '(') == 0) |
| 13013 | { |
| 13014 | INSERT_OPERAND (1, IMML, *ip, 0); |
| 13015 | continue; |
| 13016 | } |
| 13017 | |
| 13018 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13019 | || !expr_const_in_range (&ep, 0, 16, 0)) |
| 13020 | break; |
| 13021 | |
| 13022 | imm = ep.X_add_number; |
| 13023 | INSERT_OPERAND (1, IMML, *ip, imm); |
| 13024 | } |
| 13025 | s = expr_end; |
| 13026 | continue; |
| 13027 | |
| 13028 | case 'M': |
| 13029 | { |
| 13030 | bfd_reloc_code_real_type r[3]; |
| 13031 | expressionS ep; |
| 13032 | int imm; |
| 13033 | |
| 13034 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13035 | || !expr_const_in_range (&ep, 1, 9, 0)) |
| 13036 | break; |
| 13037 | |
| 13038 | imm = ep.X_add_number & 7; |
| 13039 | INSERT_OPERAND (1, IMMM, *ip, imm); |
| 13040 | } |
| 13041 | s = expr_end; |
| 13042 | continue; |
| 13043 | |
| 13044 | case 'N': /* Register list for lwm and swm. */ |
| 13045 | { |
| 13046 | /* A comma-separated list of registers and/or |
| 13047 | dash-separated contiguous ranges including |
| 13048 | both ra and a set of one or more registers |
| 13049 | starting at s0 up to s3 which have to be |
| 13050 | consecutive, e.g.: |
| 13051 | |
| 13052 | s0, ra |
| 13053 | s0, s1, ra, s2, s3 |
| 13054 | s0-s2, ra |
| 13055 | |
| 13056 | and any permutations of these. */ |
| 13057 | unsigned int reglist; |
| 13058 | int imm; |
| 13059 | |
| 13060 | if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list)) |
| 13061 | break; |
| 13062 | |
| 13063 | if ((reglist & 0xfff1ffff) != 0x80010000) |
| 13064 | break; |
| 13065 | |
| 13066 | reglist = (reglist >> 17) & 7; |
| 13067 | reglist += 1; |
| 13068 | if ((reglist & -reglist) != reglist) |
| 13069 | break; |
| 13070 | |
| 13071 | imm = ffs (reglist) - 1; |
| 13072 | INSERT_OPERAND (1, IMMN, *ip, imm); |
| 13073 | } |
| 13074 | continue; |
| 13075 | |
| 13076 | case 'O': /* sdbbp 4-bit code. */ |
| 13077 | { |
| 13078 | bfd_reloc_code_real_type r[3]; |
| 13079 | expressionS ep; |
| 13080 | int imm; |
| 13081 | |
| 13082 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13083 | || !expr_const_in_range (&ep, 0, 16, 0)) |
| 13084 | break; |
| 13085 | |
| 13086 | imm = ep.X_add_number; |
| 13087 | INSERT_OPERAND (1, IMMO, *ip, imm); |
| 13088 | } |
| 13089 | s = expr_end; |
| 13090 | continue; |
| 13091 | |
| 13092 | case 'P': |
| 13093 | { |
| 13094 | bfd_reloc_code_real_type r[3]; |
| 13095 | expressionS ep; |
| 13096 | int imm; |
| 13097 | |
| 13098 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13099 | || !expr_const_in_range (&ep, 0, 32, 2)) |
| 13100 | break; |
| 13101 | |
| 13102 | imm = ep.X_add_number >> 2; |
| 13103 | INSERT_OPERAND (1, IMMP, *ip, imm); |
| 13104 | } |
| 13105 | s = expr_end; |
| 13106 | continue; |
| 13107 | |
| 13108 | case 'Q': |
| 13109 | { |
| 13110 | bfd_reloc_code_real_type r[3]; |
| 13111 | expressionS ep; |
| 13112 | int imm; |
| 13113 | |
| 13114 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13115 | || !expr_const_in_range (&ep, -0x400000, 0x400000, 2)) |
| 13116 | break; |
| 13117 | |
| 13118 | imm = ep.X_add_number >> 2; |
| 13119 | INSERT_OPERAND (1, IMMQ, *ip, imm); |
| 13120 | } |
| 13121 | s = expr_end; |
| 13122 | continue; |
| 13123 | |
| 13124 | case 'U': |
| 13125 | { |
| 13126 | bfd_reloc_code_real_type r[3]; |
| 13127 | expressionS ep; |
| 13128 | int imm; |
| 13129 | |
| 13130 | /* Check whether there is only a single bracketed |
| 13131 | expression left. If so, it must be the base register |
| 13132 | and the constant must be zero. */ |
| 13133 | if (*s == '(' && strchr (s + 1, '(') == 0) |
| 13134 | { |
| 13135 | INSERT_OPERAND (1, IMMU, *ip, 0); |
| 13136 | continue; |
| 13137 | } |
| 13138 | |
| 13139 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13140 | || !expr_const_in_range (&ep, 0, 32, 2)) |
| 13141 | break; |
| 13142 | |
| 13143 | imm = ep.X_add_number >> 2; |
| 13144 | INSERT_OPERAND (1, IMMU, *ip, imm); |
| 13145 | } |
| 13146 | s = expr_end; |
| 13147 | continue; |
| 13148 | |
| 13149 | case 'W': |
| 13150 | { |
| 13151 | bfd_reloc_code_real_type r[3]; |
| 13152 | expressionS ep; |
| 13153 | int imm; |
| 13154 | |
| 13155 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13156 | || !expr_const_in_range (&ep, 0, 64, 2)) |
| 13157 | break; |
| 13158 | |
| 13159 | imm = ep.X_add_number >> 2; |
| 13160 | INSERT_OPERAND (1, IMMW, *ip, imm); |
| 13161 | } |
| 13162 | s = expr_end; |
| 13163 | continue; |
| 13164 | |
| 13165 | case 'X': |
| 13166 | { |
| 13167 | bfd_reloc_code_real_type r[3]; |
| 13168 | expressionS ep; |
| 13169 | int imm; |
| 13170 | |
| 13171 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13172 | || !expr_const_in_range (&ep, -8, 8, 0)) |
| 13173 | break; |
| 13174 | |
| 13175 | imm = ep.X_add_number; |
| 13176 | INSERT_OPERAND (1, IMMX, *ip, imm); |
| 13177 | } |
| 13178 | s = expr_end; |
| 13179 | continue; |
| 13180 | |
| 13181 | case 'Y': |
| 13182 | { |
| 13183 | bfd_reloc_code_real_type r[3]; |
| 13184 | expressionS ep; |
| 13185 | int imm; |
| 13186 | |
| 13187 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13188 | || expr_const_in_range (&ep, -2, 2, 2) |
| 13189 | || !expr_const_in_range (&ep, -258, 258, 2)) |
| 13190 | break; |
| 13191 | |
| 13192 | imm = ep.X_add_number >> 2; |
| 13193 | imm = ((imm >> 1) & ~0xff) | (imm & 0xff); |
| 13194 | INSERT_OPERAND (1, IMMY, *ip, imm); |
| 13195 | } |
| 13196 | s = expr_end; |
| 13197 | continue; |
| 13198 | |
| 13199 | case 'Z': |
| 13200 | { |
| 13201 | bfd_reloc_code_real_type r[3]; |
| 13202 | expressionS ep; |
| 13203 | |
| 13204 | if (my_getSmallExpression (&ep, r, s) > 0 |
| 13205 | || !expr_const_in_range (&ep, 0, 1, 0)) |
| 13206 | break; |
| 13207 | } |
| 13208 | s = expr_end; |
| 13209 | continue; |
| 13210 | |
| 13211 | default: |
| 13212 | as_bad (_("Internal error: bad microMIPS opcode " |
| 13213 | "(unknown extension operand type `m%c'): %s %s"), |
| 13214 | *args, insn->name, insn->args); |
| 13215 | /* Further processing is fruitless. */ |
| 13216 | return; |
| 13217 | } |
| 13218 | break; |
| 13219 | |
| 13220 | case 'n': /* Register list for 32-bit lwm and swm. */ |
| 13221 | gas_assert (mips_opts.micromips); |
| 13222 | { |
| 13223 | /* A comma-separated list of registers and/or |
| 13224 | dash-separated contiguous ranges including |
| 13225 | at least one of ra and a set of one or more |
| 13226 | registers starting at s0 up to s7 and then |
| 13227 | s8 which have to be consecutive, e.g.: |
| 13228 | |
| 13229 | ra |
| 13230 | s0 |
| 13231 | ra, s0, s1, s2 |
| 13232 | s0-s8 |
| 13233 | s0-s5, ra |
| 13234 | |
| 13235 | and any permutations of these. */ |
| 13236 | unsigned int reglist; |
| 13237 | int imm; |
| 13238 | int ra; |
| 13239 | |
| 13240 | if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list)) |
| 13241 | break; |
| 13242 | |
| 13243 | if ((reglist & 0x3f00ffff) != 0) |
| 13244 | break; |
| 13245 | |
| 13246 | ra = (reglist >> 27) & 0x10; |
| 13247 | reglist = ((reglist >> 22) & 0x100) | ((reglist >> 16) & 0xff); |
| 13248 | reglist += 1; |
| 13249 | if ((reglist & -reglist) != reglist) |
| 13250 | break; |
| 13251 | |
| 13252 | imm = (ffs (reglist) - 1) | ra; |
| 13253 | INSERT_OPERAND (1, RT, *ip, imm); |
| 13254 | imm_expr.X_op = O_absent; |
| 13255 | } |
| 13256 | continue; |
| 13257 | |
| 13258 | case '|': /* 4-bit trap code. */ |
| 13259 | gas_assert (mips_opts.micromips); |
| 13260 | my_getExpression (&imm_expr, s); |
| 13261 | check_absolute_expr (ip, &imm_expr); |
| 13262 | if ((unsigned long) imm_expr.X_add_number |
| 13263 | > MICROMIPSOP_MASK_TRAP) |
| 13264 | as_bad (_("Trap code (%lu) for %s not in 0..15 range"), |
| 13265 | (unsigned long) imm_expr.X_add_number, |
| 13266 | ip->insn_mo->name); |
| 13267 | INSERT_OPERAND (1, TRAP, *ip, imm_expr.X_add_number); |
| 13268 | imm_expr.X_op = O_absent; |
| 13269 | s = expr_end; |
| 13270 | continue; |
| 13271 | |
| 13272 | default: |
| 13273 | as_bad (_("Bad char = '%c'\n"), *args); |
| 13274 | internalError (); |
| 13275 | } |
| 13276 | break; |
| 13277 | } |
| 13278 | /* Args don't match. */ |
| 13279 | s = argsStart; |
| 13280 | insn_error = _("Illegal operands"); |
| 13281 | if (insn + 1 < past && !strcmp (insn->name, insn[1].name)) |
| 13282 | { |
| 13283 | ++insn; |
| 13284 | continue; |
| 13285 | } |
| 13286 | else if (wrong_delay_slot_insns && need_delay_slot_ok) |
| 13287 | { |
| 13288 | gas_assert (firstinsn); |
| 13289 | need_delay_slot_ok = FALSE; |
| 13290 | past = insn + 1; |
| 13291 | insn = firstinsn; |
| 13292 | continue; |
| 13293 | } |
| 13294 | return; |
| 13295 | } |
| 13296 | } |
| 13297 | |
| 13298 | #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); } |
| 13299 | |
| 13300 | /* This routine assembles an instruction into its binary format when |
| 13301 | assembling for the mips16. As a side effect, it sets one of the |
| 13302 | global variables imm_reloc or offset_reloc to the type of relocation |
| 13303 | to do if one of the operands is an address expression. It also sets |
| 13304 | forced_insn_length to the resulting instruction size in bytes if the |
| 13305 | user explicitly requested a small or extended instruction. */ |
| 13306 | |
| 13307 | static void |
| 13308 | mips16_ip (char *str, struct mips_cl_insn *ip) |
| 13309 | { |
| 13310 | char *s; |
| 13311 | const char *args; |
| 13312 | struct mips_opcode *insn; |
| 13313 | char *argsstart; |
| 13314 | unsigned int regno; |
| 13315 | unsigned int lastregno = 0; |
| 13316 | char *s_reset; |
| 13317 | size_t i; |
| 13318 | |
| 13319 | insn_error = NULL; |
| 13320 | |
| 13321 | forced_insn_length = 0; |
| 13322 | |
| 13323 | for (s = str; ISLOWER (*s); ++s) |
| 13324 | ; |
| 13325 | switch (*s) |
| 13326 | { |
| 13327 | case '\0': |
| 13328 | break; |
| 13329 | |
| 13330 | case ' ': |
| 13331 | *s++ = '\0'; |
| 13332 | break; |
| 13333 | |
| 13334 | case '.': |
| 13335 | if (s[1] == 't' && s[2] == ' ') |
| 13336 | { |
| 13337 | *s = '\0'; |
| 13338 | forced_insn_length = 2; |
| 13339 | s += 3; |
| 13340 | break; |
| 13341 | } |
| 13342 | else if (s[1] == 'e' && s[2] == ' ') |
| 13343 | { |
| 13344 | *s = '\0'; |
| 13345 | forced_insn_length = 4; |
| 13346 | s += 3; |
| 13347 | break; |
| 13348 | } |
| 13349 | /* Fall through. */ |
| 13350 | default: |
| 13351 | insn_error = _("unknown opcode"); |
| 13352 | return; |
| 13353 | } |
| 13354 | |
| 13355 | if (mips_opts.noautoextend && !forced_insn_length) |
| 13356 | forced_insn_length = 2; |
| 13357 | |
| 13358 | if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL) |
| 13359 | { |
| 13360 | insn_error = _("unrecognized opcode"); |
| 13361 | return; |
| 13362 | } |
| 13363 | |
| 13364 | argsstart = s; |
| 13365 | for (;;) |
| 13366 | { |
| 13367 | bfd_boolean ok; |
| 13368 | |
| 13369 | gas_assert (strcmp (insn->name, str) == 0); |
| 13370 | |
| 13371 | ok = is_opcode_valid_16 (insn); |
| 13372 | if (! ok) |
| 13373 | { |
| 13374 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] |
| 13375 | && strcmp (insn->name, insn[1].name) == 0) |
| 13376 | { |
| 13377 | ++insn; |
| 13378 | continue; |
| 13379 | } |
| 13380 | else |
| 13381 | { |
| 13382 | if (!insn_error) |
| 13383 | { |
| 13384 | static char buf[100]; |
| 13385 | sprintf (buf, |
| 13386 | _("Opcode not supported on this processor: %s (%s)"), |
| 13387 | mips_cpu_info_from_arch (mips_opts.arch)->name, |
| 13388 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 13389 | insn_error = buf; |
| 13390 | } |
| 13391 | return; |
| 13392 | } |
| 13393 | } |
| 13394 | |
| 13395 | create_insn (ip, insn); |
| 13396 | imm_expr.X_op = O_absent; |
| 13397 | imm_reloc[0] = BFD_RELOC_UNUSED; |
| 13398 | imm_reloc[1] = BFD_RELOC_UNUSED; |
| 13399 | imm_reloc[2] = BFD_RELOC_UNUSED; |
| 13400 | imm2_expr.X_op = O_absent; |
| 13401 | offset_expr.X_op = O_absent; |
| 13402 | offset_reloc[0] = BFD_RELOC_UNUSED; |
| 13403 | offset_reloc[1] = BFD_RELOC_UNUSED; |
| 13404 | offset_reloc[2] = BFD_RELOC_UNUSED; |
| 13405 | for (args = insn->args; 1; ++args) |
| 13406 | { |
| 13407 | int c; |
| 13408 | |
| 13409 | if (*s == ' ') |
| 13410 | ++s; |
| 13411 | |
| 13412 | /* In this switch statement we call break if we did not find |
| 13413 | a match, continue if we did find a match, or return if we |
| 13414 | are done. */ |
| 13415 | |
| 13416 | c = *args; |
| 13417 | switch (c) |
| 13418 | { |
| 13419 | case '\0': |
| 13420 | if (*s == '\0') |
| 13421 | { |
| 13422 | offsetT value; |
| 13423 | |
| 13424 | /* Stuff the immediate value in now, if we can. */ |
| 13425 | if (imm_expr.X_op == O_constant |
| 13426 | && *imm_reloc > BFD_RELOC_UNUSED |
| 13427 | && insn->pinfo != INSN_MACRO |
| 13428 | && calculate_reloc (*offset_reloc, |
| 13429 | imm_expr.X_add_number, &value)) |
| 13430 | { |
| 13431 | mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED, |
| 13432 | *offset_reloc, value, forced_insn_length, |
| 13433 | &ip->insn_opcode); |
| 13434 | imm_expr.X_op = O_absent; |
| 13435 | *imm_reloc = BFD_RELOC_UNUSED; |
| 13436 | *offset_reloc = BFD_RELOC_UNUSED; |
| 13437 | } |
| 13438 | |
| 13439 | return; |
| 13440 | } |
| 13441 | break; |
| 13442 | |
| 13443 | case ',': |
| 13444 | if (*s++ == c) |
| 13445 | continue; |
| 13446 | s--; |
| 13447 | switch (*++args) |
| 13448 | { |
| 13449 | case 'v': |
| 13450 | MIPS16_INSERT_OPERAND (RX, *ip, lastregno); |
| 13451 | continue; |
| 13452 | case 'w': |
| 13453 | MIPS16_INSERT_OPERAND (RY, *ip, lastregno); |
| 13454 | continue; |
| 13455 | } |
| 13456 | break; |
| 13457 | |
| 13458 | case '(': |
| 13459 | case ')': |
| 13460 | if (*s++ == c) |
| 13461 | continue; |
| 13462 | break; |
| 13463 | |
| 13464 | case 'v': |
| 13465 | case 'w': |
| 13466 | if (s[0] != '$') |
| 13467 | { |
| 13468 | if (c == 'v') |
| 13469 | MIPS16_INSERT_OPERAND (RX, *ip, lastregno); |
| 13470 | else |
| 13471 | MIPS16_INSERT_OPERAND (RY, *ip, lastregno); |
| 13472 | ++args; |
| 13473 | continue; |
| 13474 | } |
| 13475 | /* Fall through. */ |
| 13476 | case 'x': |
| 13477 | case 'y': |
| 13478 | case 'z': |
| 13479 | case 'Z': |
| 13480 | case '0': |
| 13481 | case 'S': |
| 13482 | case 'R': |
| 13483 | case 'X': |
| 13484 | case 'Y': |
| 13485 | s_reset = s; |
| 13486 | if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no)) |
| 13487 | { |
| 13488 | if (c == 'v' || c == 'w') |
| 13489 | { |
| 13490 | if (c == 'v') |
| 13491 | MIPS16_INSERT_OPERAND (RX, *ip, lastregno); |
| 13492 | else |
| 13493 | MIPS16_INSERT_OPERAND (RY, *ip, lastregno); |
| 13494 | ++args; |
| 13495 | continue; |
| 13496 | } |
| 13497 | break; |
| 13498 | } |
| 13499 | |
| 13500 | if (*s == ' ') |
| 13501 | ++s; |
| 13502 | if (args[1] != *s) |
| 13503 | { |
| 13504 | if (c == 'v' || c == 'w') |
| 13505 | { |
| 13506 | regno = mips16_to_32_reg_map[lastregno]; |
| 13507 | s = s_reset; |
| 13508 | ++args; |
| 13509 | } |
| 13510 | } |
| 13511 | |
| 13512 | switch (c) |
| 13513 | { |
| 13514 | case 'x': |
| 13515 | case 'y': |
| 13516 | case 'z': |
| 13517 | case 'v': |
| 13518 | case 'w': |
| 13519 | case 'Z': |
| 13520 | regno = mips32_to_16_reg_map[regno]; |
| 13521 | break; |
| 13522 | |
| 13523 | case '0': |
| 13524 | if (regno != 0) |
| 13525 | regno = ILLEGAL_REG; |
| 13526 | break; |
| 13527 | |
| 13528 | case 'S': |
| 13529 | if (regno != SP) |
| 13530 | regno = ILLEGAL_REG; |
| 13531 | break; |
| 13532 | |
| 13533 | case 'R': |
| 13534 | if (regno != RA) |
| 13535 | regno = ILLEGAL_REG; |
| 13536 | break; |
| 13537 | |
| 13538 | case 'X': |
| 13539 | case 'Y': |
| 13540 | if (regno == AT && mips_opts.at) |
| 13541 | { |
| 13542 | if (mips_opts.at == ATREG) |
| 13543 | as_warn (_("used $at without \".set noat\"")); |
| 13544 | else |
| 13545 | as_warn (_("used $%u with \".set at=$%u\""), |
| 13546 | regno, mips_opts.at); |
| 13547 | } |
| 13548 | break; |
| 13549 | |
| 13550 | default: |
| 13551 | internalError (); |
| 13552 | } |
| 13553 | |
| 13554 | if (regno == ILLEGAL_REG) |
| 13555 | break; |
| 13556 | |
| 13557 | switch (c) |
| 13558 | { |
| 13559 | case 'x': |
| 13560 | case 'v': |
| 13561 | MIPS16_INSERT_OPERAND (RX, *ip, regno); |
| 13562 | break; |
| 13563 | case 'y': |
| 13564 | case 'w': |
| 13565 | MIPS16_INSERT_OPERAND (RY, *ip, regno); |
| 13566 | break; |
| 13567 | case 'z': |
| 13568 | MIPS16_INSERT_OPERAND (RZ, *ip, regno); |
| 13569 | break; |
| 13570 | case 'Z': |
| 13571 | MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno); |
| 13572 | case '0': |
| 13573 | case 'S': |
| 13574 | case 'R': |
| 13575 | break; |
| 13576 | case 'X': |
| 13577 | MIPS16_INSERT_OPERAND (REGR32, *ip, regno); |
| 13578 | break; |
| 13579 | case 'Y': |
| 13580 | regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3); |
| 13581 | MIPS16_INSERT_OPERAND (REG32R, *ip, regno); |
| 13582 | break; |
| 13583 | default: |
| 13584 | internalError (); |
| 13585 | } |
| 13586 | |
| 13587 | lastregno = regno; |
| 13588 | continue; |
| 13589 | |
| 13590 | case 'P': |
| 13591 | if (strncmp (s, "$pc", 3) == 0) |
| 13592 | { |
| 13593 | s += 3; |
| 13594 | continue; |
| 13595 | } |
| 13596 | break; |
| 13597 | |
| 13598 | case '5': |
| 13599 | case 'H': |
| 13600 | case 'W': |
| 13601 | case 'D': |
| 13602 | case 'j': |
| 13603 | case 'V': |
| 13604 | case 'C': |
| 13605 | case 'U': |
| 13606 | case 'k': |
| 13607 | case 'K': |
| 13608 | i = my_getSmallExpression (&imm_expr, imm_reloc, s); |
| 13609 | if (i > 0) |
| 13610 | { |
| 13611 | if (imm_expr.X_op != O_constant) |
| 13612 | { |
| 13613 | forced_insn_length = 4; |
| 13614 | ip->insn_opcode |= MIPS16_EXTEND; |
| 13615 | } |
| 13616 | else |
| 13617 | { |
| 13618 | /* We need to relax this instruction. */ |
| 13619 | *offset_reloc = *imm_reloc; |
| 13620 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
| 13621 | } |
| 13622 | s = expr_end; |
| 13623 | continue; |
| 13624 | } |
| 13625 | *imm_reloc = BFD_RELOC_UNUSED; |
| 13626 | /* Fall through. */ |
| 13627 | case '<': |
| 13628 | case '>': |
| 13629 | case '[': |
| 13630 | case ']': |
| 13631 | case '4': |
| 13632 | case '8': |
| 13633 | my_getExpression (&imm_expr, s); |
| 13634 | if (imm_expr.X_op == O_register) |
| 13635 | { |
| 13636 | /* What we thought was an expression turned out to |
| 13637 | be a register. */ |
| 13638 | |
| 13639 | if (s[0] == '(' && args[1] == '(') |
| 13640 | { |
| 13641 | /* It looks like the expression was omitted |
| 13642 | before a register indirection, which means |
| 13643 | that the expression is implicitly zero. We |
| 13644 | still set up imm_expr, so that we handle |
| 13645 | explicit extensions correctly. */ |
| 13646 | imm_expr.X_op = O_constant; |
| 13647 | imm_expr.X_add_number = 0; |
| 13648 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
| 13649 | continue; |
| 13650 | } |
| 13651 | |
| 13652 | break; |
| 13653 | } |
| 13654 | |
| 13655 | /* We need to relax this instruction. */ |
| 13656 | *imm_reloc = (int) BFD_RELOC_UNUSED + c; |
| 13657 | s = expr_end; |
| 13658 | continue; |
| 13659 | |
| 13660 | case 'p': |
| 13661 | case 'q': |
| 13662 | case 'A': |
| 13663 | case 'B': |
| 13664 | case 'E': |
| 13665 | /* We use offset_reloc rather than imm_reloc for the PC |
| 13666 | relative operands. This lets macros with both |
| 13667 | immediate and address operands work correctly. */ |
| 13668 | my_getExpression (&offset_expr, s); |
| 13669 | |
| 13670 | if (offset_expr.X_op == O_register) |
| 13671 | break; |
| 13672 | |
| 13673 | /* We need to relax this instruction. */ |
| 13674 | *offset_reloc = (int) BFD_RELOC_UNUSED + c; |
| 13675 | s = expr_end; |
| 13676 | continue; |
| 13677 | |
| 13678 | case '6': /* break code */ |
| 13679 | my_getExpression (&imm_expr, s); |
| 13680 | check_absolute_expr (ip, &imm_expr); |
| 13681 | if ((unsigned long) imm_expr.X_add_number > 63) |
| 13682 | as_warn (_("Invalid value for `%s' (%lu)"), |
| 13683 | ip->insn_mo->name, |
| 13684 | (unsigned long) imm_expr.X_add_number); |
| 13685 | MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number); |
| 13686 | imm_expr.X_op = O_absent; |
| 13687 | s = expr_end; |
| 13688 | continue; |
| 13689 | |
| 13690 | case 'a': /* 26 bit address */ |
| 13691 | my_getExpression (&offset_expr, s); |
| 13692 | s = expr_end; |
| 13693 | *offset_reloc = BFD_RELOC_MIPS16_JMP; |
| 13694 | ip->insn_opcode <<= 16; |
| 13695 | continue; |
| 13696 | |
| 13697 | case 'l': /* register list for entry macro */ |
| 13698 | case 'L': /* register list for exit macro */ |
| 13699 | { |
| 13700 | int mask; |
| 13701 | |
| 13702 | if (c == 'l') |
| 13703 | mask = 0; |
| 13704 | else |
| 13705 | mask = 7 << 3; |
| 13706 | while (*s != '\0') |
| 13707 | { |
| 13708 | unsigned int freg, reg1, reg2; |
| 13709 | |
| 13710 | while (*s == ' ' || *s == ',') |
| 13711 | ++s; |
| 13712 | if (reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1)) |
| 13713 | freg = 0; |
| 13714 | else if (reg_lookup (&s, RTYPE_FPU, ®1)) |
| 13715 | freg = 1; |
| 13716 | else |
| 13717 | { |
| 13718 | as_bad (_("can't parse register list")); |
| 13719 | break; |
| 13720 | } |
| 13721 | if (*s == ' ') |
| 13722 | ++s; |
| 13723 | if (*s != '-') |
| 13724 | reg2 = reg1; |
| 13725 | else |
| 13726 | { |
| 13727 | ++s; |
| 13728 | if (!reg_lookup (&s, freg ? RTYPE_FPU |
| 13729 | : (RTYPE_GP | RTYPE_NUM), ®2)) |
| 13730 | { |
| 13731 | as_bad (_("invalid register list")); |
| 13732 | break; |
| 13733 | } |
| 13734 | } |
| 13735 | if (freg && reg1 == 0 && reg2 == 0 && c == 'L') |
| 13736 | { |
| 13737 | mask &= ~ (7 << 3); |
| 13738 | mask |= 5 << 3; |
| 13739 | } |
| 13740 | else if (freg && reg1 == 0 && reg2 == 1 && c == 'L') |
| 13741 | { |
| 13742 | mask &= ~ (7 << 3); |
| 13743 | mask |= 6 << 3; |
| 13744 | } |
| 13745 | else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L') |
| 13746 | mask |= (reg2 - 3) << 3; |
| 13747 | else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17) |
| 13748 | mask |= (reg2 - 15) << 1; |
| 13749 | else if (reg1 == RA && reg2 == RA) |
| 13750 | mask |= 1; |
| 13751 | else |
| 13752 | { |
| 13753 | as_bad (_("invalid register list")); |
| 13754 | break; |
| 13755 | } |
| 13756 | } |
| 13757 | /* The mask is filled in in the opcode table for the |
| 13758 | benefit of the disassembler. We remove it before |
| 13759 | applying the actual mask. */ |
| 13760 | ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6); |
| 13761 | ip->insn_opcode |= mask << MIPS16OP_SH_IMM6; |
| 13762 | } |
| 13763 | continue; |
| 13764 | |
| 13765 | case 'm': /* Register list for save insn. */ |
| 13766 | case 'M': /* Register list for restore insn. */ |
| 13767 | { |
| 13768 | int opcode = ip->insn_opcode; |
| 13769 | int framesz = 0, seen_framesz = 0; |
| 13770 | int nargs = 0, statics = 0, sregs = 0; |
| 13771 | |
| 13772 | while (*s != '\0') |
| 13773 | { |
| 13774 | unsigned int reg1, reg2; |
| 13775 | |
| 13776 | SKIP_SPACE_TABS (s); |
| 13777 | while (*s == ',') |
| 13778 | ++s; |
| 13779 | SKIP_SPACE_TABS (s); |
| 13780 | |
| 13781 | my_getExpression (&imm_expr, s); |
| 13782 | if (imm_expr.X_op == O_constant) |
| 13783 | { |
| 13784 | /* Handle the frame size. */ |
| 13785 | if (seen_framesz) |
| 13786 | { |
| 13787 | as_bad (_("more than one frame size in list")); |
| 13788 | break; |
| 13789 | } |
| 13790 | seen_framesz = 1; |
| 13791 | framesz = imm_expr.X_add_number; |
| 13792 | imm_expr.X_op = O_absent; |
| 13793 | s = expr_end; |
| 13794 | continue; |
| 13795 | } |
| 13796 | |
| 13797 | if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1)) |
| 13798 | { |
| 13799 | as_bad (_("can't parse register list")); |
| 13800 | break; |
| 13801 | } |
| 13802 | |
| 13803 | while (*s == ' ') |
| 13804 | ++s; |
| 13805 | |
| 13806 | if (*s != '-') |
| 13807 | reg2 = reg1; |
| 13808 | else |
| 13809 | { |
| 13810 | ++s; |
| 13811 | if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®2) |
| 13812 | || reg2 < reg1) |
| 13813 | { |
| 13814 | as_bad (_("can't parse register list")); |
| 13815 | break; |
| 13816 | } |
| 13817 | } |
| 13818 | |
| 13819 | while (reg1 <= reg2) |
| 13820 | { |
| 13821 | if (reg1 >= 4 && reg1 <= 7) |
| 13822 | { |
| 13823 | if (!seen_framesz) |
| 13824 | /* args $a0-$a3 */ |
| 13825 | nargs |= 1 << (reg1 - 4); |
| 13826 | else |
| 13827 | /* statics $a0-$a3 */ |
| 13828 | statics |= 1 << (reg1 - 4); |
| 13829 | } |
| 13830 | else if ((reg1 >= 16 && reg1 <= 23) || reg1 == 30) |
| 13831 | { |
| 13832 | /* $s0-$s8 */ |
| 13833 | sregs |= 1 << ((reg1 == 30) ? 8 : (reg1 - 16)); |
| 13834 | } |
| 13835 | else if (reg1 == 31) |
| 13836 | { |
| 13837 | /* Add $ra to insn. */ |
| 13838 | opcode |= 0x40; |
| 13839 | } |
| 13840 | else |
| 13841 | { |
| 13842 | as_bad (_("unexpected register in list")); |
| 13843 | break; |
| 13844 | } |
| 13845 | if (++reg1 == 24) |
| 13846 | reg1 = 30; |
| 13847 | } |
| 13848 | } |
| 13849 | |
| 13850 | /* Encode args/statics combination. */ |
| 13851 | if (nargs & statics) |
| 13852 | as_bad (_("arg/static registers overlap")); |
| 13853 | else if (nargs == 0xf) |
| 13854 | /* All $a0-$a3 are args. */ |
| 13855 | opcode |= MIPS16_ALL_ARGS << 16; |
| 13856 | else if (statics == 0xf) |
| 13857 | /* All $a0-$a3 are statics. */ |
| 13858 | opcode |= MIPS16_ALL_STATICS << 16; |
| 13859 | else |
| 13860 | { |
| 13861 | int narg = 0, nstat = 0; |
| 13862 | |
| 13863 | /* Count arg registers. */ |
| 13864 | while (nargs & 0x1) |
| 13865 | { |
| 13866 | nargs >>= 1; |
| 13867 | narg++; |
| 13868 | } |
| 13869 | if (nargs != 0) |
| 13870 | as_bad (_("invalid arg register list")); |
| 13871 | |
| 13872 | /* Count static registers. */ |
| 13873 | while (statics & 0x8) |
| 13874 | { |
| 13875 | statics = (statics << 1) & 0xf; |
| 13876 | nstat++; |
| 13877 | } |
| 13878 | if (statics != 0) |
| 13879 | as_bad (_("invalid static register list")); |
| 13880 | |
| 13881 | /* Encode args/statics. */ |
| 13882 | opcode |= ((narg << 2) | nstat) << 16; |
| 13883 | } |
| 13884 | |
| 13885 | /* Encode $s0/$s1. */ |
| 13886 | if (sregs & (1 << 0)) /* $s0 */ |
| 13887 | opcode |= 0x20; |
| 13888 | if (sregs & (1 << 1)) /* $s1 */ |
| 13889 | opcode |= 0x10; |
| 13890 | sregs >>= 2; |
| 13891 | |
| 13892 | if (sregs != 0) |
| 13893 | { |
| 13894 | /* Count regs $s2-$s8. */ |
| 13895 | int nsreg = 0; |
| 13896 | while (sregs & 1) |
| 13897 | { |
| 13898 | sregs >>= 1; |
| 13899 | nsreg++; |
| 13900 | } |
| 13901 | if (sregs != 0) |
| 13902 | as_bad (_("invalid static register list")); |
| 13903 | /* Encode $s2-$s8. */ |
| 13904 | opcode |= nsreg << 24; |
| 13905 | } |
| 13906 | |
| 13907 | /* Encode frame size. */ |
| 13908 | if (!seen_framesz) |
| 13909 | as_bad (_("missing frame size")); |
| 13910 | else if ((framesz & 7) != 0 || framesz < 0 |
| 13911 | || framesz > 0xff * 8) |
| 13912 | as_bad (_("invalid frame size")); |
| 13913 | else if (framesz != 128 || (opcode >> 16) != 0) |
| 13914 | { |
| 13915 | framesz /= 8; |
| 13916 | opcode |= (((framesz & 0xf0) << 16) |
| 13917 | | (framesz & 0x0f)); |
| 13918 | } |
| 13919 | |
| 13920 | /* Finally build the instruction. */ |
| 13921 | if ((opcode >> 16) != 0 || framesz == 0) |
| 13922 | opcode |= MIPS16_EXTEND; |
| 13923 | ip->insn_opcode = opcode; |
| 13924 | } |
| 13925 | continue; |
| 13926 | |
| 13927 | case 'e': /* extend code */ |
| 13928 | my_getExpression (&imm_expr, s); |
| 13929 | check_absolute_expr (ip, &imm_expr); |
| 13930 | if ((unsigned long) imm_expr.X_add_number > 0x7ff) |
| 13931 | { |
| 13932 | as_warn (_("Invalid value for `%s' (%lu)"), |
| 13933 | ip->insn_mo->name, |
| 13934 | (unsigned long) imm_expr.X_add_number); |
| 13935 | imm_expr.X_add_number &= 0x7ff; |
| 13936 | } |
| 13937 | ip->insn_opcode |= imm_expr.X_add_number; |
| 13938 | imm_expr.X_op = O_absent; |
| 13939 | s = expr_end; |
| 13940 | continue; |
| 13941 | |
| 13942 | default: |
| 13943 | internalError (); |
| 13944 | } |
| 13945 | break; |
| 13946 | } |
| 13947 | |
| 13948 | /* Args don't match. */ |
| 13949 | if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] && |
| 13950 | strcmp (insn->name, insn[1].name) == 0) |
| 13951 | { |
| 13952 | ++insn; |
| 13953 | s = argsstart; |
| 13954 | continue; |
| 13955 | } |
| 13956 | |
| 13957 | insn_error = _("illegal operands"); |
| 13958 | |
| 13959 | return; |
| 13960 | } |
| 13961 | } |
| 13962 | |
| 13963 | /* This structure holds information we know about a mips16 immediate |
| 13964 | argument type. */ |
| 13965 | |
| 13966 | struct mips16_immed_operand |
| 13967 | { |
| 13968 | /* The type code used in the argument string in the opcode table. */ |
| 13969 | int type; |
| 13970 | /* The number of bits in the short form of the opcode. */ |
| 13971 | int nbits; |
| 13972 | /* The number of bits in the extended form of the opcode. */ |
| 13973 | int extbits; |
| 13974 | /* The amount by which the short form is shifted when it is used; |
| 13975 | for example, the sw instruction has a shift count of 2. */ |
| 13976 | int shift; |
| 13977 | /* The amount by which the short form is shifted when it is stored |
| 13978 | into the instruction code. */ |
| 13979 | int op_shift; |
| 13980 | /* Non-zero if the short form is unsigned. */ |
| 13981 | int unsp; |
| 13982 | /* Non-zero if the extended form is unsigned. */ |
| 13983 | int extu; |
| 13984 | /* Non-zero if the value is PC relative. */ |
| 13985 | int pcrel; |
| 13986 | }; |
| 13987 | |
| 13988 | /* The mips16 immediate operand types. */ |
| 13989 | |
| 13990 | static const struct mips16_immed_operand mips16_immed_operands[] = |
| 13991 | { |
| 13992 | { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, |
| 13993 | { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 }, |
| 13994 | { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 }, |
| 13995 | { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 }, |
| 13996 | { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 }, |
| 13997 | { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 }, |
| 13998 | { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 }, |
| 13999 | { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 }, |
| 14000 | { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 }, |
| 14001 | { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 }, |
| 14002 | { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 }, |
| 14003 | { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 }, |
| 14004 | { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 }, |
| 14005 | { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 }, |
| 14006 | { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 }, |
| 14007 | { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 }, |
| 14008 | { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, |
| 14009 | { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 }, |
| 14010 | { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 }, |
| 14011 | { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 }, |
| 14012 | { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 } |
| 14013 | }; |
| 14014 | |
| 14015 | #define MIPS16_NUM_IMMED \ |
| 14016 | (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0]) |
| 14017 | |
| 14018 | /* Marshal immediate value VAL for an extended MIPS16 instruction. |
| 14019 | NBITS is the number of significant bits in VAL. */ |
| 14020 | |
| 14021 | static unsigned long |
| 14022 | mips16_immed_extend (offsetT val, unsigned int nbits) |
| 14023 | { |
| 14024 | int extval; |
| 14025 | if (nbits == 16) |
| 14026 | { |
| 14027 | extval = ((val >> 11) & 0x1f) | (val & 0x7e0); |
| 14028 | val &= 0x1f; |
| 14029 | } |
| 14030 | else if (nbits == 15) |
| 14031 | { |
| 14032 | extval = ((val >> 11) & 0xf) | (val & 0x7f0); |
| 14033 | val &= 0xf; |
| 14034 | } |
| 14035 | else |
| 14036 | { |
| 14037 | extval = ((val & 0x1f) << 6) | (val & 0x20); |
| 14038 | val = 0; |
| 14039 | } |
| 14040 | return (extval << 16) | val; |
| 14041 | } |
| 14042 | |
| 14043 | /* Install immediate value VAL into MIPS16 instruction *INSN, |
| 14044 | extending it if necessary. The instruction in *INSN may |
| 14045 | already be extended. |
| 14046 | |
| 14047 | RELOC is the relocation that produced VAL, or BFD_RELOC_UNUSED |
| 14048 | if none. In the former case, VAL is a 16-bit number with no |
| 14049 | defined signedness. |
| 14050 | |
| 14051 | TYPE is the type of the immediate field. USER_INSN_LENGTH |
| 14052 | is the length that the user requested, or 0 if none. */ |
| 14053 | |
| 14054 | static void |
| 14055 | mips16_immed (char *file, unsigned int line, int type, |
| 14056 | bfd_reloc_code_real_type reloc, offsetT val, |
| 14057 | unsigned int user_insn_length, unsigned long *insn) |
| 14058 | { |
| 14059 | const struct mips16_immed_operand *op; |
| 14060 | int mintiny, maxtiny; |
| 14061 | |
| 14062 | op = mips16_immed_operands; |
| 14063 | while (op->type != type) |
| 14064 | { |
| 14065 | ++op; |
| 14066 | gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); |
| 14067 | } |
| 14068 | |
| 14069 | if (op->unsp) |
| 14070 | { |
| 14071 | if (type == '<' || type == '>' || type == '[' || type == ']') |
| 14072 | { |
| 14073 | mintiny = 1; |
| 14074 | maxtiny = 1 << op->nbits; |
| 14075 | } |
| 14076 | else |
| 14077 | { |
| 14078 | mintiny = 0; |
| 14079 | maxtiny = (1 << op->nbits) - 1; |
| 14080 | } |
| 14081 | if (reloc != BFD_RELOC_UNUSED) |
| 14082 | val &= 0xffff; |
| 14083 | } |
| 14084 | else |
| 14085 | { |
| 14086 | mintiny = - (1 << (op->nbits - 1)); |
| 14087 | maxtiny = (1 << (op->nbits - 1)) - 1; |
| 14088 | if (reloc != BFD_RELOC_UNUSED) |
| 14089 | val = SEXT_16BIT (val); |
| 14090 | } |
| 14091 | |
| 14092 | /* Branch offsets have an implicit 0 in the lowest bit. */ |
| 14093 | if (type == 'p' || type == 'q') |
| 14094 | val /= 2; |
| 14095 | |
| 14096 | if ((val & ((1 << op->shift) - 1)) != 0 |
| 14097 | || val < (mintiny << op->shift) |
| 14098 | || val > (maxtiny << op->shift)) |
| 14099 | { |
| 14100 | /* We need an extended instruction. */ |
| 14101 | if (user_insn_length == 2) |
| 14102 | as_bad_where (file, line, _("invalid unextended operand value")); |
| 14103 | else |
| 14104 | *insn |= MIPS16_EXTEND; |
| 14105 | } |
| 14106 | else if (user_insn_length == 4) |
| 14107 | { |
| 14108 | /* The operand doesn't force an unextended instruction to be extended. |
| 14109 | Warn if the user wanted an extended instruction anyway. */ |
| 14110 | *insn |= MIPS16_EXTEND; |
| 14111 | as_warn_where (file, line, |
| 14112 | _("extended operand requested but not required")); |
| 14113 | } |
| 14114 | |
| 14115 | if (mips16_opcode_length (*insn) == 2) |
| 14116 | { |
| 14117 | int insnval; |
| 14118 | |
| 14119 | insnval = ((val >> op->shift) & ((1 << op->nbits) - 1)); |
| 14120 | insnval <<= op->op_shift; |
| 14121 | *insn |= insnval; |
| 14122 | } |
| 14123 | else |
| 14124 | { |
| 14125 | long minext, maxext; |
| 14126 | |
| 14127 | if (reloc == BFD_RELOC_UNUSED) |
| 14128 | { |
| 14129 | if (op->extu) |
| 14130 | { |
| 14131 | minext = 0; |
| 14132 | maxext = (1 << op->extbits) - 1; |
| 14133 | } |
| 14134 | else |
| 14135 | { |
| 14136 | minext = - (1 << (op->extbits - 1)); |
| 14137 | maxext = (1 << (op->extbits - 1)) - 1; |
| 14138 | } |
| 14139 | if (val < minext || val > maxext) |
| 14140 | as_bad_where (file, line, |
| 14141 | _("operand value out of range for instruction")); |
| 14142 | } |
| 14143 | |
| 14144 | *insn |= mips16_immed_extend (val, op->extbits); |
| 14145 | } |
| 14146 | } |
| 14147 | \f |
| 14148 | struct percent_op_match |
| 14149 | { |
| 14150 | const char *str; |
| 14151 | bfd_reloc_code_real_type reloc; |
| 14152 | }; |
| 14153 | |
| 14154 | static const struct percent_op_match mips_percent_op[] = |
| 14155 | { |
| 14156 | {"%lo", BFD_RELOC_LO16}, |
| 14157 | #ifdef OBJ_ELF |
| 14158 | {"%call_hi", BFD_RELOC_MIPS_CALL_HI16}, |
| 14159 | {"%call_lo", BFD_RELOC_MIPS_CALL_LO16}, |
| 14160 | {"%call16", BFD_RELOC_MIPS_CALL16}, |
| 14161 | {"%got_disp", BFD_RELOC_MIPS_GOT_DISP}, |
| 14162 | {"%got_page", BFD_RELOC_MIPS_GOT_PAGE}, |
| 14163 | {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST}, |
| 14164 | {"%got_hi", BFD_RELOC_MIPS_GOT_HI16}, |
| 14165 | {"%got_lo", BFD_RELOC_MIPS_GOT_LO16}, |
| 14166 | {"%got", BFD_RELOC_MIPS_GOT16}, |
| 14167 | {"%gp_rel", BFD_RELOC_GPREL16}, |
| 14168 | {"%half", BFD_RELOC_16}, |
| 14169 | {"%highest", BFD_RELOC_MIPS_HIGHEST}, |
| 14170 | {"%higher", BFD_RELOC_MIPS_HIGHER}, |
| 14171 | {"%neg", BFD_RELOC_MIPS_SUB}, |
| 14172 | {"%tlsgd", BFD_RELOC_MIPS_TLS_GD}, |
| 14173 | {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM}, |
| 14174 | {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16}, |
| 14175 | {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16}, |
| 14176 | {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16}, |
| 14177 | {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16}, |
| 14178 | {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL}, |
| 14179 | #endif |
| 14180 | {"%hi", BFD_RELOC_HI16_S} |
| 14181 | }; |
| 14182 | |
| 14183 | static const struct percent_op_match mips16_percent_op[] = |
| 14184 | { |
| 14185 | {"%lo", BFD_RELOC_MIPS16_LO16}, |
| 14186 | {"%gprel", BFD_RELOC_MIPS16_GPREL}, |
| 14187 | {"%got", BFD_RELOC_MIPS16_GOT16}, |
| 14188 | {"%call16", BFD_RELOC_MIPS16_CALL16}, |
| 14189 | {"%hi", BFD_RELOC_MIPS16_HI16_S}, |
| 14190 | {"%tlsgd", BFD_RELOC_MIPS16_TLS_GD}, |
| 14191 | {"%tlsldm", BFD_RELOC_MIPS16_TLS_LDM}, |
| 14192 | {"%dtprel_hi", BFD_RELOC_MIPS16_TLS_DTPREL_HI16}, |
| 14193 | {"%dtprel_lo", BFD_RELOC_MIPS16_TLS_DTPREL_LO16}, |
| 14194 | {"%tprel_hi", BFD_RELOC_MIPS16_TLS_TPREL_HI16}, |
| 14195 | {"%tprel_lo", BFD_RELOC_MIPS16_TLS_TPREL_LO16}, |
| 14196 | {"%gottprel", BFD_RELOC_MIPS16_TLS_GOTTPREL} |
| 14197 | }; |
| 14198 | |
| 14199 | |
| 14200 | /* Return true if *STR points to a relocation operator. When returning true, |
| 14201 | move *STR over the operator and store its relocation code in *RELOC. |
| 14202 | Leave both *STR and *RELOC alone when returning false. */ |
| 14203 | |
| 14204 | static bfd_boolean |
| 14205 | parse_relocation (char **str, bfd_reloc_code_real_type *reloc) |
| 14206 | { |
| 14207 | const struct percent_op_match *percent_op; |
| 14208 | size_t limit, i; |
| 14209 | |
| 14210 | if (mips_opts.mips16) |
| 14211 | { |
| 14212 | percent_op = mips16_percent_op; |
| 14213 | limit = ARRAY_SIZE (mips16_percent_op); |
| 14214 | } |
| 14215 | else |
| 14216 | { |
| 14217 | percent_op = mips_percent_op; |
| 14218 | limit = ARRAY_SIZE (mips_percent_op); |
| 14219 | } |
| 14220 | |
| 14221 | for (i = 0; i < limit; i++) |
| 14222 | if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0) |
| 14223 | { |
| 14224 | int len = strlen (percent_op[i].str); |
| 14225 | |
| 14226 | if (!ISSPACE ((*str)[len]) && (*str)[len] != '(') |
| 14227 | continue; |
| 14228 | |
| 14229 | *str += strlen (percent_op[i].str); |
| 14230 | *reloc = percent_op[i].reloc; |
| 14231 | |
| 14232 | /* Check whether the output BFD supports this relocation. |
| 14233 | If not, issue an error and fall back on something safe. */ |
| 14234 | if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc)) |
| 14235 | { |
| 14236 | as_bad (_("relocation %s isn't supported by the current ABI"), |
| 14237 | percent_op[i].str); |
| 14238 | *reloc = BFD_RELOC_UNUSED; |
| 14239 | } |
| 14240 | return TRUE; |
| 14241 | } |
| 14242 | return FALSE; |
| 14243 | } |
| 14244 | |
| 14245 | |
| 14246 | /* Parse string STR as a 16-bit relocatable operand. Store the |
| 14247 | expression in *EP and the relocations in the array starting |
| 14248 | at RELOC. Return the number of relocation operators used. |
| 14249 | |
| 14250 | On exit, EXPR_END points to the first character after the expression. */ |
| 14251 | |
| 14252 | static size_t |
| 14253 | my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc, |
| 14254 | char *str) |
| 14255 | { |
| 14256 | bfd_reloc_code_real_type reversed_reloc[3]; |
| 14257 | size_t reloc_index, i; |
| 14258 | int crux_depth, str_depth; |
| 14259 | char *crux; |
| 14260 | |
| 14261 | /* Search for the start of the main expression, recoding relocations |
| 14262 | in REVERSED_RELOC. End the loop with CRUX pointing to the start |
| 14263 | of the main expression and with CRUX_DEPTH containing the number |
| 14264 | of open brackets at that point. */ |
| 14265 | reloc_index = -1; |
| 14266 | str_depth = 0; |
| 14267 | do |
| 14268 | { |
| 14269 | reloc_index++; |
| 14270 | crux = str; |
| 14271 | crux_depth = str_depth; |
| 14272 | |
| 14273 | /* Skip over whitespace and brackets, keeping count of the number |
| 14274 | of brackets. */ |
| 14275 | while (*str == ' ' || *str == '\t' || *str == '(') |
| 14276 | if (*str++ == '(') |
| 14277 | str_depth++; |
| 14278 | } |
| 14279 | while (*str == '%' |
| 14280 | && reloc_index < (HAVE_NEWABI ? 3 : 1) |
| 14281 | && parse_relocation (&str, &reversed_reloc[reloc_index])); |
| 14282 | |
| 14283 | my_getExpression (ep, crux); |
| 14284 | str = expr_end; |
| 14285 | |
| 14286 | /* Match every open bracket. */ |
| 14287 | while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t')) |
| 14288 | if (*str++ == ')') |
| 14289 | crux_depth--; |
| 14290 | |
| 14291 | if (crux_depth > 0) |
| 14292 | as_bad (_("unclosed '('")); |
| 14293 | |
| 14294 | expr_end = str; |
| 14295 | |
| 14296 | if (reloc_index != 0) |
| 14297 | { |
| 14298 | prev_reloc_op_frag = frag_now; |
| 14299 | for (i = 0; i < reloc_index; i++) |
| 14300 | reloc[i] = reversed_reloc[reloc_index - 1 - i]; |
| 14301 | } |
| 14302 | |
| 14303 | return reloc_index; |
| 14304 | } |
| 14305 | |
| 14306 | static void |
| 14307 | my_getExpression (expressionS *ep, char *str) |
| 14308 | { |
| 14309 | char *save_in; |
| 14310 | |
| 14311 | save_in = input_line_pointer; |
| 14312 | input_line_pointer = str; |
| 14313 | expression (ep); |
| 14314 | expr_end = input_line_pointer; |
| 14315 | input_line_pointer = save_in; |
| 14316 | } |
| 14317 | |
| 14318 | char * |
| 14319 | md_atof (int type, char *litP, int *sizeP) |
| 14320 | { |
| 14321 | return ieee_md_atof (type, litP, sizeP, target_big_endian); |
| 14322 | } |
| 14323 | |
| 14324 | void |
| 14325 | md_number_to_chars (char *buf, valueT val, int n) |
| 14326 | { |
| 14327 | if (target_big_endian) |
| 14328 | number_to_chars_bigendian (buf, val, n); |
| 14329 | else |
| 14330 | number_to_chars_littleendian (buf, val, n); |
| 14331 | } |
| 14332 | \f |
| 14333 | #ifdef OBJ_ELF |
| 14334 | static int support_64bit_objects(void) |
| 14335 | { |
| 14336 | const char **list, **l; |
| 14337 | int yes; |
| 14338 | |
| 14339 | list = bfd_target_list (); |
| 14340 | for (l = list; *l != NULL; l++) |
| 14341 | if (strcmp (*l, ELF_TARGET ("elf64-", "big")) == 0 |
| 14342 | || strcmp (*l, ELF_TARGET ("elf64-", "little")) == 0) |
| 14343 | break; |
| 14344 | yes = (*l != NULL); |
| 14345 | free (list); |
| 14346 | return yes; |
| 14347 | } |
| 14348 | #endif /* OBJ_ELF */ |
| 14349 | |
| 14350 | const char *md_shortopts = "O::g::G:"; |
| 14351 | |
| 14352 | enum options |
| 14353 | { |
| 14354 | OPTION_MARCH = OPTION_MD_BASE, |
| 14355 | OPTION_MTUNE, |
| 14356 | OPTION_MIPS1, |
| 14357 | OPTION_MIPS2, |
| 14358 | OPTION_MIPS3, |
| 14359 | OPTION_MIPS4, |
| 14360 | OPTION_MIPS5, |
| 14361 | OPTION_MIPS32, |
| 14362 | OPTION_MIPS64, |
| 14363 | OPTION_MIPS32R2, |
| 14364 | OPTION_MIPS64R2, |
| 14365 | OPTION_MIPS16, |
| 14366 | OPTION_NO_MIPS16, |
| 14367 | OPTION_MIPS3D, |
| 14368 | OPTION_NO_MIPS3D, |
| 14369 | OPTION_MDMX, |
| 14370 | OPTION_NO_MDMX, |
| 14371 | OPTION_DSP, |
| 14372 | OPTION_NO_DSP, |
| 14373 | OPTION_MT, |
| 14374 | OPTION_NO_MT, |
| 14375 | OPTION_SMARTMIPS, |
| 14376 | OPTION_NO_SMARTMIPS, |
| 14377 | OPTION_DSPR2, |
| 14378 | OPTION_NO_DSPR2, |
| 14379 | OPTION_MICROMIPS, |
| 14380 | OPTION_NO_MICROMIPS, |
| 14381 | OPTION_MCU, |
| 14382 | OPTION_NO_MCU, |
| 14383 | OPTION_COMPAT_ARCH_BASE, |
| 14384 | OPTION_M4650, |
| 14385 | OPTION_NO_M4650, |
| 14386 | OPTION_M4010, |
| 14387 | OPTION_NO_M4010, |
| 14388 | OPTION_M4100, |
| 14389 | OPTION_NO_M4100, |
| 14390 | OPTION_M3900, |
| 14391 | OPTION_NO_M3900, |
| 14392 | OPTION_M7000_HILO_FIX, |
| 14393 | OPTION_MNO_7000_HILO_FIX, |
| 14394 | OPTION_FIX_24K, |
| 14395 | OPTION_NO_FIX_24K, |
| 14396 | OPTION_FIX_LOONGSON2F_JUMP, |
| 14397 | OPTION_NO_FIX_LOONGSON2F_JUMP, |
| 14398 | OPTION_FIX_LOONGSON2F_NOP, |
| 14399 | OPTION_NO_FIX_LOONGSON2F_NOP, |
| 14400 | OPTION_FIX_VR4120, |
| 14401 | OPTION_NO_FIX_VR4120, |
| 14402 | OPTION_FIX_VR4130, |
| 14403 | OPTION_NO_FIX_VR4130, |
| 14404 | OPTION_FIX_CN63XXP1, |
| 14405 | OPTION_NO_FIX_CN63XXP1, |
| 14406 | OPTION_TRAP, |
| 14407 | OPTION_BREAK, |
| 14408 | OPTION_EB, |
| 14409 | OPTION_EL, |
| 14410 | OPTION_FP32, |
| 14411 | OPTION_GP32, |
| 14412 | OPTION_CONSTRUCT_FLOATS, |
| 14413 | OPTION_NO_CONSTRUCT_FLOATS, |
| 14414 | OPTION_FP64, |
| 14415 | OPTION_GP64, |
| 14416 | OPTION_RELAX_BRANCH, |
| 14417 | OPTION_NO_RELAX_BRANCH, |
| 14418 | OPTION_MSHARED, |
| 14419 | OPTION_MNO_SHARED, |
| 14420 | OPTION_MSYM32, |
| 14421 | OPTION_MNO_SYM32, |
| 14422 | OPTION_SOFT_FLOAT, |
| 14423 | OPTION_HARD_FLOAT, |
| 14424 | OPTION_SINGLE_FLOAT, |
| 14425 | OPTION_DOUBLE_FLOAT, |
| 14426 | OPTION_32, |
| 14427 | #ifdef OBJ_ELF |
| 14428 | OPTION_CALL_SHARED, |
| 14429 | OPTION_CALL_NONPIC, |
| 14430 | OPTION_NON_SHARED, |
| 14431 | OPTION_XGOT, |
| 14432 | OPTION_MABI, |
| 14433 | OPTION_N32, |
| 14434 | OPTION_64, |
| 14435 | OPTION_MDEBUG, |
| 14436 | OPTION_NO_MDEBUG, |
| 14437 | OPTION_PDR, |
| 14438 | OPTION_NO_PDR, |
| 14439 | OPTION_MVXWORKS_PIC, |
| 14440 | #endif /* OBJ_ELF */ |
| 14441 | OPTION_END_OF_ENUM |
| 14442 | }; |
| 14443 | |
| 14444 | struct option md_longopts[] = |
| 14445 | { |
| 14446 | /* Options which specify architecture. */ |
| 14447 | {"march", required_argument, NULL, OPTION_MARCH}, |
| 14448 | {"mtune", required_argument, NULL, OPTION_MTUNE}, |
| 14449 | {"mips0", no_argument, NULL, OPTION_MIPS1}, |
| 14450 | {"mips1", no_argument, NULL, OPTION_MIPS1}, |
| 14451 | {"mips2", no_argument, NULL, OPTION_MIPS2}, |
| 14452 | {"mips3", no_argument, NULL, OPTION_MIPS3}, |
| 14453 | {"mips4", no_argument, NULL, OPTION_MIPS4}, |
| 14454 | {"mips5", no_argument, NULL, OPTION_MIPS5}, |
| 14455 | {"mips32", no_argument, NULL, OPTION_MIPS32}, |
| 14456 | {"mips64", no_argument, NULL, OPTION_MIPS64}, |
| 14457 | {"mips32r2", no_argument, NULL, OPTION_MIPS32R2}, |
| 14458 | {"mips64r2", no_argument, NULL, OPTION_MIPS64R2}, |
| 14459 | |
| 14460 | /* Options which specify Application Specific Extensions (ASEs). */ |
| 14461 | {"mips16", no_argument, NULL, OPTION_MIPS16}, |
| 14462 | {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16}, |
| 14463 | {"mips3d", no_argument, NULL, OPTION_MIPS3D}, |
| 14464 | {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D}, |
| 14465 | {"mdmx", no_argument, NULL, OPTION_MDMX}, |
| 14466 | {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX}, |
| 14467 | {"mdsp", no_argument, NULL, OPTION_DSP}, |
| 14468 | {"mno-dsp", no_argument, NULL, OPTION_NO_DSP}, |
| 14469 | {"mmt", no_argument, NULL, OPTION_MT}, |
| 14470 | {"mno-mt", no_argument, NULL, OPTION_NO_MT}, |
| 14471 | {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS}, |
| 14472 | {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS}, |
| 14473 | {"mdspr2", no_argument, NULL, OPTION_DSPR2}, |
| 14474 | {"mno-dspr2", no_argument, NULL, OPTION_NO_DSPR2}, |
| 14475 | {"mmicromips", no_argument, NULL, OPTION_MICROMIPS}, |
| 14476 | {"mno-micromips", no_argument, NULL, OPTION_NO_MICROMIPS}, |
| 14477 | {"mmcu", no_argument, NULL, OPTION_MCU}, |
| 14478 | {"mno-mcu", no_argument, NULL, OPTION_NO_MCU}, |
| 14479 | |
| 14480 | /* Old-style architecture options. Don't add more of these. */ |
| 14481 | {"m4650", no_argument, NULL, OPTION_M4650}, |
| 14482 | {"no-m4650", no_argument, NULL, OPTION_NO_M4650}, |
| 14483 | {"m4010", no_argument, NULL, OPTION_M4010}, |
| 14484 | {"no-m4010", no_argument, NULL, OPTION_NO_M4010}, |
| 14485 | {"m4100", no_argument, NULL, OPTION_M4100}, |
| 14486 | {"no-m4100", no_argument, NULL, OPTION_NO_M4100}, |
| 14487 | {"m3900", no_argument, NULL, OPTION_M3900}, |
| 14488 | {"no-m3900", no_argument, NULL, OPTION_NO_M3900}, |
| 14489 | |
| 14490 | /* Options which enable bug fixes. */ |
| 14491 | {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX}, |
| 14492 | {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX}, |
| 14493 | {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX}, |
| 14494 | {"mfix-loongson2f-jump", no_argument, NULL, OPTION_FIX_LOONGSON2F_JUMP}, |
| 14495 | {"mno-fix-loongson2f-jump", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_JUMP}, |
| 14496 | {"mfix-loongson2f-nop", no_argument, NULL, OPTION_FIX_LOONGSON2F_NOP}, |
| 14497 | {"mno-fix-loongson2f-nop", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_NOP}, |
| 14498 | {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120}, |
| 14499 | {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120}, |
| 14500 | {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130}, |
| 14501 | {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130}, |
| 14502 | {"mfix-24k", no_argument, NULL, OPTION_FIX_24K}, |
| 14503 | {"mno-fix-24k", no_argument, NULL, OPTION_NO_FIX_24K}, |
| 14504 | {"mfix-cn63xxp1", no_argument, NULL, OPTION_FIX_CN63XXP1}, |
| 14505 | {"mno-fix-cn63xxp1", no_argument, NULL, OPTION_NO_FIX_CN63XXP1}, |
| 14506 | |
| 14507 | /* Miscellaneous options. */ |
| 14508 | {"trap", no_argument, NULL, OPTION_TRAP}, |
| 14509 | {"no-break", no_argument, NULL, OPTION_TRAP}, |
| 14510 | {"break", no_argument, NULL, OPTION_BREAK}, |
| 14511 | {"no-trap", no_argument, NULL, OPTION_BREAK}, |
| 14512 | {"EB", no_argument, NULL, OPTION_EB}, |
| 14513 | {"EL", no_argument, NULL, OPTION_EL}, |
| 14514 | {"mfp32", no_argument, NULL, OPTION_FP32}, |
| 14515 | {"mgp32", no_argument, NULL, OPTION_GP32}, |
| 14516 | {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS}, |
| 14517 | {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS}, |
| 14518 | {"mfp64", no_argument, NULL, OPTION_FP64}, |
| 14519 | {"mgp64", no_argument, NULL, OPTION_GP64}, |
| 14520 | {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH}, |
| 14521 | {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH}, |
| 14522 | {"mshared", no_argument, NULL, OPTION_MSHARED}, |
| 14523 | {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED}, |
| 14524 | {"msym32", no_argument, NULL, OPTION_MSYM32}, |
| 14525 | {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32}, |
| 14526 | {"msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT}, |
| 14527 | {"mhard-float", no_argument, NULL, OPTION_HARD_FLOAT}, |
| 14528 | {"msingle-float", no_argument, NULL, OPTION_SINGLE_FLOAT}, |
| 14529 | {"mdouble-float", no_argument, NULL, OPTION_DOUBLE_FLOAT}, |
| 14530 | |
| 14531 | /* Strictly speaking this next option is ELF specific, |
| 14532 | but we allow it for other ports as well in order to |
| 14533 | make testing easier. */ |
| 14534 | {"32", no_argument, NULL, OPTION_32}, |
| 14535 | |
| 14536 | /* ELF-specific options. */ |
| 14537 | #ifdef OBJ_ELF |
| 14538 | {"KPIC", no_argument, NULL, OPTION_CALL_SHARED}, |
| 14539 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, |
| 14540 | {"call_nonpic", no_argument, NULL, OPTION_CALL_NONPIC}, |
| 14541 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, |
| 14542 | {"xgot", no_argument, NULL, OPTION_XGOT}, |
| 14543 | {"mabi", required_argument, NULL, OPTION_MABI}, |
| 14544 | {"n32", no_argument, NULL, OPTION_N32}, |
| 14545 | {"64", no_argument, NULL, OPTION_64}, |
| 14546 | {"mdebug", no_argument, NULL, OPTION_MDEBUG}, |
| 14547 | {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG}, |
| 14548 | {"mpdr", no_argument, NULL, OPTION_PDR}, |
| 14549 | {"mno-pdr", no_argument, NULL, OPTION_NO_PDR}, |
| 14550 | {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC}, |
| 14551 | #endif /* OBJ_ELF */ |
| 14552 | |
| 14553 | {NULL, no_argument, NULL, 0} |
| 14554 | }; |
| 14555 | size_t md_longopts_size = sizeof (md_longopts); |
| 14556 | |
| 14557 | /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to |
| 14558 | NEW_VALUE. Warn if another value was already specified. Note: |
| 14559 | we have to defer parsing the -march and -mtune arguments in order |
| 14560 | to handle 'from-abi' correctly, since the ABI might be specified |
| 14561 | in a later argument. */ |
| 14562 | |
| 14563 | static void |
| 14564 | mips_set_option_string (const char **string_ptr, const char *new_value) |
| 14565 | { |
| 14566 | if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0) |
| 14567 | as_warn (_("A different %s was already specified, is now %s"), |
| 14568 | string_ptr == &mips_arch_string ? "-march" : "-mtune", |
| 14569 | new_value); |
| 14570 | |
| 14571 | *string_ptr = new_value; |
| 14572 | } |
| 14573 | |
| 14574 | int |
| 14575 | md_parse_option (int c, char *arg) |
| 14576 | { |
| 14577 | switch (c) |
| 14578 | { |
| 14579 | case OPTION_CONSTRUCT_FLOATS: |
| 14580 | mips_disable_float_construction = 0; |
| 14581 | break; |
| 14582 | |
| 14583 | case OPTION_NO_CONSTRUCT_FLOATS: |
| 14584 | mips_disable_float_construction = 1; |
| 14585 | break; |
| 14586 | |
| 14587 | case OPTION_TRAP: |
| 14588 | mips_trap = 1; |
| 14589 | break; |
| 14590 | |
| 14591 | case OPTION_BREAK: |
| 14592 | mips_trap = 0; |
| 14593 | break; |
| 14594 | |
| 14595 | case OPTION_EB: |
| 14596 | target_big_endian = 1; |
| 14597 | break; |
| 14598 | |
| 14599 | case OPTION_EL: |
| 14600 | target_big_endian = 0; |
| 14601 | break; |
| 14602 | |
| 14603 | case 'O': |
| 14604 | if (arg == NULL) |
| 14605 | mips_optimize = 1; |
| 14606 | else if (arg[0] == '0') |
| 14607 | mips_optimize = 0; |
| 14608 | else if (arg[0] == '1') |
| 14609 | mips_optimize = 1; |
| 14610 | else |
| 14611 | mips_optimize = 2; |
| 14612 | break; |
| 14613 | |
| 14614 | case 'g': |
| 14615 | if (arg == NULL) |
| 14616 | mips_debug = 2; |
| 14617 | else |
| 14618 | mips_debug = atoi (arg); |
| 14619 | break; |
| 14620 | |
| 14621 | case OPTION_MIPS1: |
| 14622 | file_mips_isa = ISA_MIPS1; |
| 14623 | break; |
| 14624 | |
| 14625 | case OPTION_MIPS2: |
| 14626 | file_mips_isa = ISA_MIPS2; |
| 14627 | break; |
| 14628 | |
| 14629 | case OPTION_MIPS3: |
| 14630 | file_mips_isa = ISA_MIPS3; |
| 14631 | break; |
| 14632 | |
| 14633 | case OPTION_MIPS4: |
| 14634 | file_mips_isa = ISA_MIPS4; |
| 14635 | break; |
| 14636 | |
| 14637 | case OPTION_MIPS5: |
| 14638 | file_mips_isa = ISA_MIPS5; |
| 14639 | break; |
| 14640 | |
| 14641 | case OPTION_MIPS32: |
| 14642 | file_mips_isa = ISA_MIPS32; |
| 14643 | break; |
| 14644 | |
| 14645 | case OPTION_MIPS32R2: |
| 14646 | file_mips_isa = ISA_MIPS32R2; |
| 14647 | break; |
| 14648 | |
| 14649 | case OPTION_MIPS64R2: |
| 14650 | file_mips_isa = ISA_MIPS64R2; |
| 14651 | break; |
| 14652 | |
| 14653 | case OPTION_MIPS64: |
| 14654 | file_mips_isa = ISA_MIPS64; |
| 14655 | break; |
| 14656 | |
| 14657 | case OPTION_MTUNE: |
| 14658 | mips_set_option_string (&mips_tune_string, arg); |
| 14659 | break; |
| 14660 | |
| 14661 | case OPTION_MARCH: |
| 14662 | mips_set_option_string (&mips_arch_string, arg); |
| 14663 | break; |
| 14664 | |
| 14665 | case OPTION_M4650: |
| 14666 | mips_set_option_string (&mips_arch_string, "4650"); |
| 14667 | mips_set_option_string (&mips_tune_string, "4650"); |
| 14668 | break; |
| 14669 | |
| 14670 | case OPTION_NO_M4650: |
| 14671 | break; |
| 14672 | |
| 14673 | case OPTION_M4010: |
| 14674 | mips_set_option_string (&mips_arch_string, "4010"); |
| 14675 | mips_set_option_string (&mips_tune_string, "4010"); |
| 14676 | break; |
| 14677 | |
| 14678 | case OPTION_NO_M4010: |
| 14679 | break; |
| 14680 | |
| 14681 | case OPTION_M4100: |
| 14682 | mips_set_option_string (&mips_arch_string, "4100"); |
| 14683 | mips_set_option_string (&mips_tune_string, "4100"); |
| 14684 | break; |
| 14685 | |
| 14686 | case OPTION_NO_M4100: |
| 14687 | break; |
| 14688 | |
| 14689 | case OPTION_M3900: |
| 14690 | mips_set_option_string (&mips_arch_string, "3900"); |
| 14691 | mips_set_option_string (&mips_tune_string, "3900"); |
| 14692 | break; |
| 14693 | |
| 14694 | case OPTION_NO_M3900: |
| 14695 | break; |
| 14696 | |
| 14697 | case OPTION_MDMX: |
| 14698 | mips_opts.ase_mdmx = 1; |
| 14699 | break; |
| 14700 | |
| 14701 | case OPTION_NO_MDMX: |
| 14702 | mips_opts.ase_mdmx = 0; |
| 14703 | break; |
| 14704 | |
| 14705 | case OPTION_DSP: |
| 14706 | mips_opts.ase_dsp = 1; |
| 14707 | mips_opts.ase_dspr2 = 0; |
| 14708 | break; |
| 14709 | |
| 14710 | case OPTION_NO_DSP: |
| 14711 | mips_opts.ase_dsp = 0; |
| 14712 | mips_opts.ase_dspr2 = 0; |
| 14713 | break; |
| 14714 | |
| 14715 | case OPTION_DSPR2: |
| 14716 | mips_opts.ase_dspr2 = 1; |
| 14717 | mips_opts.ase_dsp = 1; |
| 14718 | break; |
| 14719 | |
| 14720 | case OPTION_NO_DSPR2: |
| 14721 | mips_opts.ase_dspr2 = 0; |
| 14722 | mips_opts.ase_dsp = 0; |
| 14723 | break; |
| 14724 | |
| 14725 | case OPTION_MT: |
| 14726 | mips_opts.ase_mt = 1; |
| 14727 | break; |
| 14728 | |
| 14729 | case OPTION_NO_MT: |
| 14730 | mips_opts.ase_mt = 0; |
| 14731 | break; |
| 14732 | |
| 14733 | case OPTION_MCU: |
| 14734 | mips_opts.ase_mcu = 1; |
| 14735 | break; |
| 14736 | |
| 14737 | case OPTION_NO_MCU: |
| 14738 | mips_opts.ase_mcu = 0; |
| 14739 | break; |
| 14740 | |
| 14741 | case OPTION_MICROMIPS: |
| 14742 | if (mips_opts.mips16 == 1) |
| 14743 | { |
| 14744 | as_bad (_("-mmicromips cannot be used with -mips16")); |
| 14745 | return 0; |
| 14746 | } |
| 14747 | mips_opts.micromips = 1; |
| 14748 | mips_no_prev_insn (); |
| 14749 | break; |
| 14750 | |
| 14751 | case OPTION_NO_MICROMIPS: |
| 14752 | mips_opts.micromips = 0; |
| 14753 | mips_no_prev_insn (); |
| 14754 | break; |
| 14755 | |
| 14756 | case OPTION_MIPS16: |
| 14757 | if (mips_opts.micromips == 1) |
| 14758 | { |
| 14759 | as_bad (_("-mips16 cannot be used with -micromips")); |
| 14760 | return 0; |
| 14761 | } |
| 14762 | mips_opts.mips16 = 1; |
| 14763 | mips_no_prev_insn (); |
| 14764 | break; |
| 14765 | |
| 14766 | case OPTION_NO_MIPS16: |
| 14767 | mips_opts.mips16 = 0; |
| 14768 | mips_no_prev_insn (); |
| 14769 | break; |
| 14770 | |
| 14771 | case OPTION_MIPS3D: |
| 14772 | mips_opts.ase_mips3d = 1; |
| 14773 | break; |
| 14774 | |
| 14775 | case OPTION_NO_MIPS3D: |
| 14776 | mips_opts.ase_mips3d = 0; |
| 14777 | break; |
| 14778 | |
| 14779 | case OPTION_SMARTMIPS: |
| 14780 | mips_opts.ase_smartmips = 1; |
| 14781 | break; |
| 14782 | |
| 14783 | case OPTION_NO_SMARTMIPS: |
| 14784 | mips_opts.ase_smartmips = 0; |
| 14785 | break; |
| 14786 | |
| 14787 | case OPTION_FIX_24K: |
| 14788 | mips_fix_24k = 1; |
| 14789 | break; |
| 14790 | |
| 14791 | case OPTION_NO_FIX_24K: |
| 14792 | mips_fix_24k = 0; |
| 14793 | break; |
| 14794 | |
| 14795 | case OPTION_FIX_LOONGSON2F_JUMP: |
| 14796 | mips_fix_loongson2f_jump = TRUE; |
| 14797 | break; |
| 14798 | |
| 14799 | case OPTION_NO_FIX_LOONGSON2F_JUMP: |
| 14800 | mips_fix_loongson2f_jump = FALSE; |
| 14801 | break; |
| 14802 | |
| 14803 | case OPTION_FIX_LOONGSON2F_NOP: |
| 14804 | mips_fix_loongson2f_nop = TRUE; |
| 14805 | break; |
| 14806 | |
| 14807 | case OPTION_NO_FIX_LOONGSON2F_NOP: |
| 14808 | mips_fix_loongson2f_nop = FALSE; |
| 14809 | break; |
| 14810 | |
| 14811 | case OPTION_FIX_VR4120: |
| 14812 | mips_fix_vr4120 = 1; |
| 14813 | break; |
| 14814 | |
| 14815 | case OPTION_NO_FIX_VR4120: |
| 14816 | mips_fix_vr4120 = 0; |
| 14817 | break; |
| 14818 | |
| 14819 | case OPTION_FIX_VR4130: |
| 14820 | mips_fix_vr4130 = 1; |
| 14821 | break; |
| 14822 | |
| 14823 | case OPTION_NO_FIX_VR4130: |
| 14824 | mips_fix_vr4130 = 0; |
| 14825 | break; |
| 14826 | |
| 14827 | case OPTION_FIX_CN63XXP1: |
| 14828 | mips_fix_cn63xxp1 = TRUE; |
| 14829 | break; |
| 14830 | |
| 14831 | case OPTION_NO_FIX_CN63XXP1: |
| 14832 | mips_fix_cn63xxp1 = FALSE; |
| 14833 | break; |
| 14834 | |
| 14835 | case OPTION_RELAX_BRANCH: |
| 14836 | mips_relax_branch = 1; |
| 14837 | break; |
| 14838 | |
| 14839 | case OPTION_NO_RELAX_BRANCH: |
| 14840 | mips_relax_branch = 0; |
| 14841 | break; |
| 14842 | |
| 14843 | case OPTION_MSHARED: |
| 14844 | mips_in_shared = TRUE; |
| 14845 | break; |
| 14846 | |
| 14847 | case OPTION_MNO_SHARED: |
| 14848 | mips_in_shared = FALSE; |
| 14849 | break; |
| 14850 | |
| 14851 | case OPTION_MSYM32: |
| 14852 | mips_opts.sym32 = TRUE; |
| 14853 | break; |
| 14854 | |
| 14855 | case OPTION_MNO_SYM32: |
| 14856 | mips_opts.sym32 = FALSE; |
| 14857 | break; |
| 14858 | |
| 14859 | #ifdef OBJ_ELF |
| 14860 | /* When generating ELF code, we permit -KPIC and -call_shared to |
| 14861 | select SVR4_PIC, and -non_shared to select no PIC. This is |
| 14862 | intended to be compatible with Irix 5. */ |
| 14863 | case OPTION_CALL_SHARED: |
| 14864 | if (!IS_ELF) |
| 14865 | { |
| 14866 | as_bad (_("-call_shared is supported only for ELF format")); |
| 14867 | return 0; |
| 14868 | } |
| 14869 | mips_pic = SVR4_PIC; |
| 14870 | mips_abicalls = TRUE; |
| 14871 | break; |
| 14872 | |
| 14873 | case OPTION_CALL_NONPIC: |
| 14874 | if (!IS_ELF) |
| 14875 | { |
| 14876 | as_bad (_("-call_nonpic is supported only for ELF format")); |
| 14877 | return 0; |
| 14878 | } |
| 14879 | mips_pic = NO_PIC; |
| 14880 | mips_abicalls = TRUE; |
| 14881 | break; |
| 14882 | |
| 14883 | case OPTION_NON_SHARED: |
| 14884 | if (!IS_ELF) |
| 14885 | { |
| 14886 | as_bad (_("-non_shared is supported only for ELF format")); |
| 14887 | return 0; |
| 14888 | } |
| 14889 | mips_pic = NO_PIC; |
| 14890 | mips_abicalls = FALSE; |
| 14891 | break; |
| 14892 | |
| 14893 | /* The -xgot option tells the assembler to use 32 bit offsets |
| 14894 | when accessing the got in SVR4_PIC mode. It is for Irix |
| 14895 | compatibility. */ |
| 14896 | case OPTION_XGOT: |
| 14897 | mips_big_got = 1; |
| 14898 | break; |
| 14899 | #endif /* OBJ_ELF */ |
| 14900 | |
| 14901 | case 'G': |
| 14902 | g_switch_value = atoi (arg); |
| 14903 | g_switch_seen = 1; |
| 14904 | break; |
| 14905 | |
| 14906 | /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32 |
| 14907 | and -mabi=64. */ |
| 14908 | case OPTION_32: |
| 14909 | if (IS_ELF) |
| 14910 | mips_abi = O32_ABI; |
| 14911 | /* We silently ignore -32 for non-ELF targets. This greatly |
| 14912 | simplifies the construction of the MIPS GAS test cases. */ |
| 14913 | break; |
| 14914 | |
| 14915 | #ifdef OBJ_ELF |
| 14916 | case OPTION_N32: |
| 14917 | if (!IS_ELF) |
| 14918 | { |
| 14919 | as_bad (_("-n32 is supported for ELF format only")); |
| 14920 | return 0; |
| 14921 | } |
| 14922 | mips_abi = N32_ABI; |
| 14923 | break; |
| 14924 | |
| 14925 | case OPTION_64: |
| 14926 | if (!IS_ELF) |
| 14927 | { |
| 14928 | as_bad (_("-64 is supported for ELF format only")); |
| 14929 | return 0; |
| 14930 | } |
| 14931 | mips_abi = N64_ABI; |
| 14932 | if (!support_64bit_objects()) |
| 14933 | as_fatal (_("No compiled in support for 64 bit object file format")); |
| 14934 | break; |
| 14935 | #endif /* OBJ_ELF */ |
| 14936 | |
| 14937 | case OPTION_GP32: |
| 14938 | file_mips_gp32 = 1; |
| 14939 | break; |
| 14940 | |
| 14941 | case OPTION_GP64: |
| 14942 | file_mips_gp32 = 0; |
| 14943 | break; |
| 14944 | |
| 14945 | case OPTION_FP32: |
| 14946 | file_mips_fp32 = 1; |
| 14947 | break; |
| 14948 | |
| 14949 | case OPTION_FP64: |
| 14950 | file_mips_fp32 = 0; |
| 14951 | break; |
| 14952 | |
| 14953 | case OPTION_SINGLE_FLOAT: |
| 14954 | file_mips_single_float = 1; |
| 14955 | break; |
| 14956 | |
| 14957 | case OPTION_DOUBLE_FLOAT: |
| 14958 | file_mips_single_float = 0; |
| 14959 | break; |
| 14960 | |
| 14961 | case OPTION_SOFT_FLOAT: |
| 14962 | file_mips_soft_float = 1; |
| 14963 | break; |
| 14964 | |
| 14965 | case OPTION_HARD_FLOAT: |
| 14966 | file_mips_soft_float = 0; |
| 14967 | break; |
| 14968 | |
| 14969 | #ifdef OBJ_ELF |
| 14970 | case OPTION_MABI: |
| 14971 | if (!IS_ELF) |
| 14972 | { |
| 14973 | as_bad (_("-mabi is supported for ELF format only")); |
| 14974 | return 0; |
| 14975 | } |
| 14976 | if (strcmp (arg, "32") == 0) |
| 14977 | mips_abi = O32_ABI; |
| 14978 | else if (strcmp (arg, "o64") == 0) |
| 14979 | mips_abi = O64_ABI; |
| 14980 | else if (strcmp (arg, "n32") == 0) |
| 14981 | mips_abi = N32_ABI; |
| 14982 | else if (strcmp (arg, "64") == 0) |
| 14983 | { |
| 14984 | mips_abi = N64_ABI; |
| 14985 | if (! support_64bit_objects()) |
| 14986 | as_fatal (_("No compiled in support for 64 bit object file " |
| 14987 | "format")); |
| 14988 | } |
| 14989 | else if (strcmp (arg, "eabi") == 0) |
| 14990 | mips_abi = EABI_ABI; |
| 14991 | else |
| 14992 | { |
| 14993 | as_fatal (_("invalid abi -mabi=%s"), arg); |
| 14994 | return 0; |
| 14995 | } |
| 14996 | break; |
| 14997 | #endif /* OBJ_ELF */ |
| 14998 | |
| 14999 | case OPTION_M7000_HILO_FIX: |
| 15000 | mips_7000_hilo_fix = TRUE; |
| 15001 | break; |
| 15002 | |
| 15003 | case OPTION_MNO_7000_HILO_FIX: |
| 15004 | mips_7000_hilo_fix = FALSE; |
| 15005 | break; |
| 15006 | |
| 15007 | #ifdef OBJ_ELF |
| 15008 | case OPTION_MDEBUG: |
| 15009 | mips_flag_mdebug = TRUE; |
| 15010 | break; |
| 15011 | |
| 15012 | case OPTION_NO_MDEBUG: |
| 15013 | mips_flag_mdebug = FALSE; |
| 15014 | break; |
| 15015 | |
| 15016 | case OPTION_PDR: |
| 15017 | mips_flag_pdr = TRUE; |
| 15018 | break; |
| 15019 | |
| 15020 | case OPTION_NO_PDR: |
| 15021 | mips_flag_pdr = FALSE; |
| 15022 | break; |
| 15023 | |
| 15024 | case OPTION_MVXWORKS_PIC: |
| 15025 | mips_pic = VXWORKS_PIC; |
| 15026 | break; |
| 15027 | #endif /* OBJ_ELF */ |
| 15028 | |
| 15029 | default: |
| 15030 | return 0; |
| 15031 | } |
| 15032 | |
| 15033 | mips_fix_loongson2f = mips_fix_loongson2f_nop || mips_fix_loongson2f_jump; |
| 15034 | |
| 15035 | return 1; |
| 15036 | } |
| 15037 | \f |
| 15038 | /* Set up globals to generate code for the ISA or processor |
| 15039 | described by INFO. */ |
| 15040 | |
| 15041 | static void |
| 15042 | mips_set_architecture (const struct mips_cpu_info *info) |
| 15043 | { |
| 15044 | if (info != 0) |
| 15045 | { |
| 15046 | file_mips_arch = info->cpu; |
| 15047 | mips_opts.arch = info->cpu; |
| 15048 | mips_opts.isa = info->isa; |
| 15049 | } |
| 15050 | } |
| 15051 | |
| 15052 | |
| 15053 | /* Likewise for tuning. */ |
| 15054 | |
| 15055 | static void |
| 15056 | mips_set_tune (const struct mips_cpu_info *info) |
| 15057 | { |
| 15058 | if (info != 0) |
| 15059 | mips_tune = info->cpu; |
| 15060 | } |
| 15061 | |
| 15062 | |
| 15063 | void |
| 15064 | mips_after_parse_args (void) |
| 15065 | { |
| 15066 | const struct mips_cpu_info *arch_info = 0; |
| 15067 | const struct mips_cpu_info *tune_info = 0; |
| 15068 | |
| 15069 | /* GP relative stuff not working for PE */ |
| 15070 | if (strncmp (TARGET_OS, "pe", 2) == 0) |
| 15071 | { |
| 15072 | if (g_switch_seen && g_switch_value != 0) |
| 15073 | as_bad (_("-G not supported in this configuration.")); |
| 15074 | g_switch_value = 0; |
| 15075 | } |
| 15076 | |
| 15077 | if (mips_abi == NO_ABI) |
| 15078 | mips_abi = MIPS_DEFAULT_ABI; |
| 15079 | |
| 15080 | /* The following code determines the architecture and register size. |
| 15081 | Similar code was added to GCC 3.3 (see override_options() in |
| 15082 | config/mips/mips.c). The GAS and GCC code should be kept in sync |
| 15083 | as much as possible. */ |
| 15084 | |
| 15085 | if (mips_arch_string != 0) |
| 15086 | arch_info = mips_parse_cpu ("-march", mips_arch_string); |
| 15087 | |
| 15088 | if (file_mips_isa != ISA_UNKNOWN) |
| 15089 | { |
| 15090 | /* Handle -mipsN. At this point, file_mips_isa contains the |
| 15091 | ISA level specified by -mipsN, while arch_info->isa contains |
| 15092 | the -march selection (if any). */ |
| 15093 | if (arch_info != 0) |
| 15094 | { |
| 15095 | /* -march takes precedence over -mipsN, since it is more descriptive. |
| 15096 | There's no harm in specifying both as long as the ISA levels |
| 15097 | are the same. */ |
| 15098 | if (file_mips_isa != arch_info->isa) |
| 15099 | as_bad (_("-%s conflicts with the other architecture options, which imply -%s"), |
| 15100 | mips_cpu_info_from_isa (file_mips_isa)->name, |
| 15101 | mips_cpu_info_from_isa (arch_info->isa)->name); |
| 15102 | } |
| 15103 | else |
| 15104 | arch_info = mips_cpu_info_from_isa (file_mips_isa); |
| 15105 | } |
| 15106 | |
| 15107 | if (arch_info == 0) |
| 15108 | { |
| 15109 | arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT); |
| 15110 | gas_assert (arch_info); |
| 15111 | } |
| 15112 | |
| 15113 | if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa)) |
| 15114 | as_bad (_("-march=%s is not compatible with the selected ABI"), |
| 15115 | arch_info->name); |
| 15116 | |
| 15117 | mips_set_architecture (arch_info); |
| 15118 | |
| 15119 | /* Optimize for file_mips_arch, unless -mtune selects a different processor. */ |
| 15120 | if (mips_tune_string != 0) |
| 15121 | tune_info = mips_parse_cpu ("-mtune", mips_tune_string); |
| 15122 | |
| 15123 | if (tune_info == 0) |
| 15124 | mips_set_tune (arch_info); |
| 15125 | else |
| 15126 | mips_set_tune (tune_info); |
| 15127 | |
| 15128 | if (file_mips_gp32 >= 0) |
| 15129 | { |
| 15130 | /* The user specified the size of the integer registers. Make sure |
| 15131 | it agrees with the ABI and ISA. */ |
| 15132 | if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa)) |
| 15133 | as_bad (_("-mgp64 used with a 32-bit processor")); |
| 15134 | else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi)) |
| 15135 | as_bad (_("-mgp32 used with a 64-bit ABI")); |
| 15136 | else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi)) |
| 15137 | as_bad (_("-mgp64 used with a 32-bit ABI")); |
| 15138 | } |
| 15139 | else |
| 15140 | { |
| 15141 | /* Infer the integer register size from the ABI and processor. |
| 15142 | Restrict ourselves to 32-bit registers if that's all the |
| 15143 | processor has, or if the ABI cannot handle 64-bit registers. */ |
| 15144 | file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi) |
| 15145 | || !ISA_HAS_64BIT_REGS (mips_opts.isa)); |
| 15146 | } |
| 15147 | |
| 15148 | switch (file_mips_fp32) |
| 15149 | { |
| 15150 | default: |
| 15151 | case -1: |
| 15152 | /* No user specified float register size. |
| 15153 | ??? GAS treats single-float processors as though they had 64-bit |
| 15154 | float registers (although it complains when double-precision |
| 15155 | instructions are used). As things stand, saying they have 32-bit |
| 15156 | registers would lead to spurious "register must be even" messages. |
| 15157 | So here we assume float registers are never smaller than the |
| 15158 | integer ones. */ |
| 15159 | if (file_mips_gp32 == 0) |
| 15160 | /* 64-bit integer registers implies 64-bit float registers. */ |
| 15161 | file_mips_fp32 = 0; |
| 15162 | else if ((mips_opts.ase_mips3d > 0 || mips_opts.ase_mdmx > 0) |
| 15163 | && ISA_HAS_64BIT_FPRS (mips_opts.isa)) |
| 15164 | /* -mips3d and -mdmx imply 64-bit float registers, if possible. */ |
| 15165 | file_mips_fp32 = 0; |
| 15166 | else |
| 15167 | /* 32-bit float registers. */ |
| 15168 | file_mips_fp32 = 1; |
| 15169 | break; |
| 15170 | |
| 15171 | /* The user specified the size of the float registers. Check if it |
| 15172 | agrees with the ABI and ISA. */ |
| 15173 | case 0: |
| 15174 | if (!ISA_HAS_64BIT_FPRS (mips_opts.isa)) |
| 15175 | as_bad (_("-mfp64 used with a 32-bit fpu")); |
| 15176 | else if (ABI_NEEDS_32BIT_REGS (mips_abi) |
| 15177 | && !ISA_HAS_MXHC1 (mips_opts.isa)) |
| 15178 | as_warn (_("-mfp64 used with a 32-bit ABI")); |
| 15179 | break; |
| 15180 | case 1: |
| 15181 | if (ABI_NEEDS_64BIT_REGS (mips_abi)) |
| 15182 | as_warn (_("-mfp32 used with a 64-bit ABI")); |
| 15183 | break; |
| 15184 | } |
| 15185 | |
| 15186 | /* End of GCC-shared inference code. */ |
| 15187 | |
| 15188 | /* This flag is set when we have a 64-bit capable CPU but use only |
| 15189 | 32-bit wide registers. Note that EABI does not use it. */ |
| 15190 | if (ISA_HAS_64BIT_REGS (mips_opts.isa) |
| 15191 | && ((mips_abi == NO_ABI && file_mips_gp32 == 1) |
| 15192 | || mips_abi == O32_ABI)) |
| 15193 | mips_32bitmode = 1; |
| 15194 | |
| 15195 | if (mips_opts.isa == ISA_MIPS1 && mips_trap) |
| 15196 | as_bad (_("trap exception not supported at ISA 1")); |
| 15197 | |
| 15198 | /* If the selected architecture includes support for ASEs, enable |
| 15199 | generation of code for them. */ |
| 15200 | if (mips_opts.mips16 == -1) |
| 15201 | mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0; |
| 15202 | if (mips_opts.micromips == -1) |
| 15203 | mips_opts.micromips = (CPU_HAS_MICROMIPS (file_mips_arch)) ? 1 : 0; |
| 15204 | if (mips_opts.ase_mips3d == -1) |
| 15205 | mips_opts.ase_mips3d = ((arch_info->flags & MIPS_CPU_ASE_MIPS3D) |
| 15206 | && file_mips_fp32 == 0) ? 1 : 0; |
| 15207 | if (mips_opts.ase_mips3d && file_mips_fp32 == 1) |
| 15208 | as_bad (_("-mfp32 used with -mips3d")); |
| 15209 | |
| 15210 | if (mips_opts.ase_mdmx == -1) |
| 15211 | mips_opts.ase_mdmx = ((arch_info->flags & MIPS_CPU_ASE_MDMX) |
| 15212 | && file_mips_fp32 == 0) ? 1 : 0; |
| 15213 | if (mips_opts.ase_mdmx && file_mips_fp32 == 1) |
| 15214 | as_bad (_("-mfp32 used with -mdmx")); |
| 15215 | |
| 15216 | if (mips_opts.ase_smartmips == -1) |
| 15217 | mips_opts.ase_smartmips = (arch_info->flags & MIPS_CPU_ASE_SMARTMIPS) ? 1 : 0; |
| 15218 | if (mips_opts.ase_smartmips && !ISA_SUPPORTS_SMARTMIPS) |
| 15219 | as_warn (_("%s ISA does not support SmartMIPS"), |
| 15220 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 15221 | |
| 15222 | if (mips_opts.ase_dsp == -1) |
| 15223 | mips_opts.ase_dsp = (arch_info->flags & MIPS_CPU_ASE_DSP) ? 1 : 0; |
| 15224 | if (mips_opts.ase_dsp && !ISA_SUPPORTS_DSP_ASE) |
| 15225 | as_warn (_("%s ISA does not support DSP ASE"), |
| 15226 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 15227 | |
| 15228 | if (mips_opts.ase_dspr2 == -1) |
| 15229 | { |
| 15230 | mips_opts.ase_dspr2 = (arch_info->flags & MIPS_CPU_ASE_DSPR2) ? 1 : 0; |
| 15231 | mips_opts.ase_dsp = (arch_info->flags & MIPS_CPU_ASE_DSP) ? 1 : 0; |
| 15232 | } |
| 15233 | if (mips_opts.ase_dspr2 && !ISA_SUPPORTS_DSPR2_ASE) |
| 15234 | as_warn (_("%s ISA does not support DSP R2 ASE"), |
| 15235 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 15236 | |
| 15237 | if (mips_opts.ase_mt == -1) |
| 15238 | mips_opts.ase_mt = (arch_info->flags & MIPS_CPU_ASE_MT) ? 1 : 0; |
| 15239 | if (mips_opts.ase_mt && !ISA_SUPPORTS_MT_ASE) |
| 15240 | as_warn (_("%s ISA does not support MT ASE"), |
| 15241 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 15242 | |
| 15243 | if (mips_opts.ase_mcu == -1) |
| 15244 | mips_opts.ase_mcu = (arch_info->flags & MIPS_CPU_ASE_MCU) ? 1 : 0; |
| 15245 | if (mips_opts.ase_mcu && !ISA_SUPPORTS_MCU_ASE) |
| 15246 | as_warn (_("%s ISA does not support MCU ASE"), |
| 15247 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 15248 | |
| 15249 | file_mips_isa = mips_opts.isa; |
| 15250 | file_ase_mips3d = mips_opts.ase_mips3d; |
| 15251 | file_ase_mdmx = mips_opts.ase_mdmx; |
| 15252 | file_ase_smartmips = mips_opts.ase_smartmips; |
| 15253 | file_ase_dsp = mips_opts.ase_dsp; |
| 15254 | file_ase_dspr2 = mips_opts.ase_dspr2; |
| 15255 | file_ase_mt = mips_opts.ase_mt; |
| 15256 | mips_opts.gp32 = file_mips_gp32; |
| 15257 | mips_opts.fp32 = file_mips_fp32; |
| 15258 | mips_opts.soft_float = file_mips_soft_float; |
| 15259 | mips_opts.single_float = file_mips_single_float; |
| 15260 | |
| 15261 | if (mips_flag_mdebug < 0) |
| 15262 | { |
| 15263 | #ifdef OBJ_MAYBE_ECOFF |
| 15264 | if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour) |
| 15265 | mips_flag_mdebug = 1; |
| 15266 | else |
| 15267 | #endif /* OBJ_MAYBE_ECOFF */ |
| 15268 | mips_flag_mdebug = 0; |
| 15269 | } |
| 15270 | } |
| 15271 | \f |
| 15272 | void |
| 15273 | mips_init_after_args (void) |
| 15274 | { |
| 15275 | /* initialize opcodes */ |
| 15276 | bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes; |
| 15277 | mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes; |
| 15278 | } |
| 15279 | |
| 15280 | long |
| 15281 | md_pcrel_from (fixS *fixP) |
| 15282 | { |
| 15283 | valueT addr = fixP->fx_where + fixP->fx_frag->fr_address; |
| 15284 | switch (fixP->fx_r_type) |
| 15285 | { |
| 15286 | case BFD_RELOC_MICROMIPS_7_PCREL_S1: |
| 15287 | case BFD_RELOC_MICROMIPS_10_PCREL_S1: |
| 15288 | /* Return the address of the delay slot. */ |
| 15289 | return addr + 2; |
| 15290 | |
| 15291 | case BFD_RELOC_MICROMIPS_16_PCREL_S1: |
| 15292 | case BFD_RELOC_MICROMIPS_JMP: |
| 15293 | case BFD_RELOC_16_PCREL_S2: |
| 15294 | case BFD_RELOC_MIPS_JMP: |
| 15295 | /* Return the address of the delay slot. */ |
| 15296 | return addr + 4; |
| 15297 | |
| 15298 | default: |
| 15299 | /* We have no relocation type for PC relative MIPS16 instructions. */ |
| 15300 | if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != now_seg) |
| 15301 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 15302 | _("PC relative MIPS16 instruction references a different section")); |
| 15303 | return addr; |
| 15304 | } |
| 15305 | } |
| 15306 | |
| 15307 | /* This is called before the symbol table is processed. In order to |
| 15308 | work with gcc when using mips-tfile, we must keep all local labels. |
| 15309 | However, in other cases, we want to discard them. If we were |
| 15310 | called with -g, but we didn't see any debugging information, it may |
| 15311 | mean that gcc is smuggling debugging information through to |
| 15312 | mips-tfile, in which case we must generate all local labels. */ |
| 15313 | |
| 15314 | void |
| 15315 | mips_frob_file_before_adjust (void) |
| 15316 | { |
| 15317 | #ifndef NO_ECOFF_DEBUGGING |
| 15318 | if (ECOFF_DEBUGGING |
| 15319 | && mips_debug != 0 |
| 15320 | && ! ecoff_debugging_seen) |
| 15321 | flag_keep_locals = 1; |
| 15322 | #endif |
| 15323 | } |
| 15324 | |
| 15325 | /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede |
| 15326 | the corresponding LO16 reloc. This is called before md_apply_fix and |
| 15327 | tc_gen_reloc. Unmatched relocs can only be generated by use of explicit |
| 15328 | relocation operators. |
| 15329 | |
| 15330 | For our purposes, a %lo() expression matches a %got() or %hi() |
| 15331 | expression if: |
| 15332 | |
| 15333 | (a) it refers to the same symbol; and |
| 15334 | (b) the offset applied in the %lo() expression is no lower than |
| 15335 | the offset applied in the %got() or %hi(). |
| 15336 | |
| 15337 | (b) allows us to cope with code like: |
| 15338 | |
| 15339 | lui $4,%hi(foo) |
| 15340 | lh $4,%lo(foo+2)($4) |
| 15341 | |
| 15342 | ...which is legal on RELA targets, and has a well-defined behaviour |
| 15343 | if the user knows that adding 2 to "foo" will not induce a carry to |
| 15344 | the high 16 bits. |
| 15345 | |
| 15346 | When several %lo()s match a particular %got() or %hi(), we use the |
| 15347 | following rules to distinguish them: |
| 15348 | |
| 15349 | (1) %lo()s with smaller offsets are a better match than %lo()s with |
| 15350 | higher offsets. |
| 15351 | |
| 15352 | (2) %lo()s with no matching %got() or %hi() are better than those |
| 15353 | that already have a matching %got() or %hi(). |
| 15354 | |
| 15355 | (3) later %lo()s are better than earlier %lo()s. |
| 15356 | |
| 15357 | These rules are applied in order. |
| 15358 | |
| 15359 | (1) means, among other things, that %lo()s with identical offsets are |
| 15360 | chosen if they exist. |
| 15361 | |
| 15362 | (2) means that we won't associate several high-part relocations with |
| 15363 | the same low-part relocation unless there's no alternative. Having |
| 15364 | several high parts for the same low part is a GNU extension; this rule |
| 15365 | allows careful users to avoid it. |
| 15366 | |
| 15367 | (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order, |
| 15368 | with the last high-part relocation being at the front of the list. |
| 15369 | It therefore makes sense to choose the last matching low-part |
| 15370 | relocation, all other things being equal. It's also easier |
| 15371 | to code that way. */ |
| 15372 | |
| 15373 | void |
| 15374 | mips_frob_file (void) |
| 15375 | { |
| 15376 | struct mips_hi_fixup *l; |
| 15377 | bfd_reloc_code_real_type looking_for_rtype = BFD_RELOC_UNUSED; |
| 15378 | |
| 15379 | for (l = mips_hi_fixup_list; l != NULL; l = l->next) |
| 15380 | { |
| 15381 | segment_info_type *seginfo; |
| 15382 | bfd_boolean matched_lo_p; |
| 15383 | fixS **hi_pos, **lo_pos, **pos; |
| 15384 | |
| 15385 | gas_assert (reloc_needs_lo_p (l->fixp->fx_r_type)); |
| 15386 | |
| 15387 | /* If a GOT16 relocation turns out to be against a global symbol, |
| 15388 | there isn't supposed to be a matching LO. Ignore %gots against |
| 15389 | constants; we'll report an error for those later. */ |
| 15390 | if (got16_reloc_p (l->fixp->fx_r_type) |
| 15391 | && !(l->fixp->fx_addsy |
| 15392 | && pic_need_relax (l->fixp->fx_addsy, l->seg))) |
| 15393 | continue; |
| 15394 | |
| 15395 | /* Check quickly whether the next fixup happens to be a matching %lo. */ |
| 15396 | if (fixup_has_matching_lo_p (l->fixp)) |
| 15397 | continue; |
| 15398 | |
| 15399 | seginfo = seg_info (l->seg); |
| 15400 | |
| 15401 | /* Set HI_POS to the position of this relocation in the chain. |
| 15402 | Set LO_POS to the position of the chosen low-part relocation. |
| 15403 | MATCHED_LO_P is true on entry to the loop if *POS is a low-part |
| 15404 | relocation that matches an immediately-preceding high-part |
| 15405 | relocation. */ |
| 15406 | hi_pos = NULL; |
| 15407 | lo_pos = NULL; |
| 15408 | matched_lo_p = FALSE; |
| 15409 | looking_for_rtype = matching_lo_reloc (l->fixp->fx_r_type); |
| 15410 | |
| 15411 | for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next) |
| 15412 | { |
| 15413 | if (*pos == l->fixp) |
| 15414 | hi_pos = pos; |
| 15415 | |
| 15416 | if ((*pos)->fx_r_type == looking_for_rtype |
| 15417 | && symbol_same_p ((*pos)->fx_addsy, l->fixp->fx_addsy) |
| 15418 | && (*pos)->fx_offset >= l->fixp->fx_offset |
| 15419 | && (lo_pos == NULL |
| 15420 | || (*pos)->fx_offset < (*lo_pos)->fx_offset |
| 15421 | || (!matched_lo_p |
| 15422 | && (*pos)->fx_offset == (*lo_pos)->fx_offset))) |
| 15423 | lo_pos = pos; |
| 15424 | |
| 15425 | matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type) |
| 15426 | && fixup_has_matching_lo_p (*pos)); |
| 15427 | } |
| 15428 | |
| 15429 | /* If we found a match, remove the high-part relocation from its |
| 15430 | current position and insert it before the low-part relocation. |
| 15431 | Make the offsets match so that fixup_has_matching_lo_p() |
| 15432 | will return true. |
| 15433 | |
| 15434 | We don't warn about unmatched high-part relocations since some |
| 15435 | versions of gcc have been known to emit dead "lui ...%hi(...)" |
| 15436 | instructions. */ |
| 15437 | if (lo_pos != NULL) |
| 15438 | { |
| 15439 | l->fixp->fx_offset = (*lo_pos)->fx_offset; |
| 15440 | if (l->fixp->fx_next != *lo_pos) |
| 15441 | { |
| 15442 | *hi_pos = l->fixp->fx_next; |
| 15443 | l->fixp->fx_next = *lo_pos; |
| 15444 | *lo_pos = l->fixp; |
| 15445 | } |
| 15446 | } |
| 15447 | } |
| 15448 | } |
| 15449 | |
| 15450 | int |
| 15451 | mips_force_relocation (fixS *fixp) |
| 15452 | { |
| 15453 | if (generic_force_reloc (fixp)) |
| 15454 | return 1; |
| 15455 | |
| 15456 | /* We want to keep BFD_RELOC_MICROMIPS_*_PCREL_S1 relocation, |
| 15457 | so that the linker relaxation can update targets. */ |
| 15458 | if (fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1 |
| 15459 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1 |
| 15460 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1) |
| 15461 | return 1; |
| 15462 | |
| 15463 | return 0; |
| 15464 | } |
| 15465 | |
| 15466 | /* Read the instruction associated with RELOC from BUF. */ |
| 15467 | |
| 15468 | static unsigned int |
| 15469 | read_reloc_insn (char *buf, bfd_reloc_code_real_type reloc) |
| 15470 | { |
| 15471 | if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc)) |
| 15472 | return read_compressed_insn (buf, 4); |
| 15473 | else |
| 15474 | return read_insn (buf); |
| 15475 | } |
| 15476 | |
| 15477 | /* Write instruction INSN to BUF, given that it has been relocated |
| 15478 | by RELOC. */ |
| 15479 | |
| 15480 | static void |
| 15481 | write_reloc_insn (char *buf, bfd_reloc_code_real_type reloc, |
| 15482 | unsigned long insn) |
| 15483 | { |
| 15484 | if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc)) |
| 15485 | write_compressed_insn (buf, insn, 4); |
| 15486 | else |
| 15487 | write_insn (buf, insn); |
| 15488 | } |
| 15489 | |
| 15490 | /* Apply a fixup to the object file. */ |
| 15491 | |
| 15492 | void |
| 15493 | md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) |
| 15494 | { |
| 15495 | char *buf; |
| 15496 | unsigned long insn; |
| 15497 | reloc_howto_type *howto; |
| 15498 | |
| 15499 | /* We ignore generic BFD relocations we don't know about. */ |
| 15500 | howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type); |
| 15501 | if (! howto) |
| 15502 | return; |
| 15503 | |
| 15504 | gas_assert (fixP->fx_size == 2 |
| 15505 | || fixP->fx_size == 4 |
| 15506 | || fixP->fx_r_type == BFD_RELOC_16 |
| 15507 | || fixP->fx_r_type == BFD_RELOC_64 |
| 15508 | || fixP->fx_r_type == BFD_RELOC_CTOR |
| 15509 | || fixP->fx_r_type == BFD_RELOC_MIPS_SUB |
| 15510 | || fixP->fx_r_type == BFD_RELOC_MICROMIPS_SUB |
| 15511 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
| 15512 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY |
| 15513 | || fixP->fx_r_type == BFD_RELOC_MIPS_TLS_DTPREL64); |
| 15514 | |
| 15515 | buf = fixP->fx_frag->fr_literal + fixP->fx_where; |
| 15516 | |
| 15517 | gas_assert (!fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2 |
| 15518 | || fixP->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1 |
| 15519 | || fixP->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1 |
| 15520 | || fixP->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1); |
| 15521 | |
| 15522 | /* Don't treat parts of a composite relocation as done. There are two |
| 15523 | reasons for this: |
| 15524 | |
| 15525 | (1) The second and third parts will be against 0 (RSS_UNDEF) but |
| 15526 | should nevertheless be emitted if the first part is. |
| 15527 | |
| 15528 | (2) In normal usage, composite relocations are never assembly-time |
| 15529 | constants. The easiest way of dealing with the pathological |
| 15530 | exceptions is to generate a relocation against STN_UNDEF and |
| 15531 | leave everything up to the linker. */ |
| 15532 | if (fixP->fx_addsy == NULL && !fixP->fx_pcrel && fixP->fx_tcbit == 0) |
| 15533 | fixP->fx_done = 1; |
| 15534 | |
| 15535 | switch (fixP->fx_r_type) |
| 15536 | { |
| 15537 | case BFD_RELOC_MIPS_TLS_GD: |
| 15538 | case BFD_RELOC_MIPS_TLS_LDM: |
| 15539 | case BFD_RELOC_MIPS_TLS_DTPREL32: |
| 15540 | case BFD_RELOC_MIPS_TLS_DTPREL64: |
| 15541 | case BFD_RELOC_MIPS_TLS_DTPREL_HI16: |
| 15542 | case BFD_RELOC_MIPS_TLS_DTPREL_LO16: |
| 15543 | case BFD_RELOC_MIPS_TLS_GOTTPREL: |
| 15544 | case BFD_RELOC_MIPS_TLS_TPREL32: |
| 15545 | case BFD_RELOC_MIPS_TLS_TPREL64: |
| 15546 | case BFD_RELOC_MIPS_TLS_TPREL_HI16: |
| 15547 | case BFD_RELOC_MIPS_TLS_TPREL_LO16: |
| 15548 | case BFD_RELOC_MICROMIPS_TLS_GD: |
| 15549 | case BFD_RELOC_MICROMIPS_TLS_LDM: |
| 15550 | case BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16: |
| 15551 | case BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16: |
| 15552 | case BFD_RELOC_MICROMIPS_TLS_GOTTPREL: |
| 15553 | case BFD_RELOC_MICROMIPS_TLS_TPREL_HI16: |
| 15554 | case BFD_RELOC_MICROMIPS_TLS_TPREL_LO16: |
| 15555 | case BFD_RELOC_MIPS16_TLS_GD: |
| 15556 | case BFD_RELOC_MIPS16_TLS_LDM: |
| 15557 | case BFD_RELOC_MIPS16_TLS_DTPREL_HI16: |
| 15558 | case BFD_RELOC_MIPS16_TLS_DTPREL_LO16: |
| 15559 | case BFD_RELOC_MIPS16_TLS_GOTTPREL: |
| 15560 | case BFD_RELOC_MIPS16_TLS_TPREL_HI16: |
| 15561 | case BFD_RELOC_MIPS16_TLS_TPREL_LO16: |
| 15562 | if (!fixP->fx_addsy) |
| 15563 | { |
| 15564 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 15565 | _("TLS relocation against a constant")); |
| 15566 | break; |
| 15567 | } |
| 15568 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
| 15569 | /* fall through */ |
| 15570 | |
| 15571 | case BFD_RELOC_MIPS_JMP: |
| 15572 | case BFD_RELOC_MIPS_SHIFT5: |
| 15573 | case BFD_RELOC_MIPS_SHIFT6: |
| 15574 | case BFD_RELOC_MIPS_GOT_DISP: |
| 15575 | case BFD_RELOC_MIPS_GOT_PAGE: |
| 15576 | case BFD_RELOC_MIPS_GOT_OFST: |
| 15577 | case BFD_RELOC_MIPS_SUB: |
| 15578 | case BFD_RELOC_MIPS_INSERT_A: |
| 15579 | case BFD_RELOC_MIPS_INSERT_B: |
| 15580 | case BFD_RELOC_MIPS_DELETE: |
| 15581 | case BFD_RELOC_MIPS_HIGHEST: |
| 15582 | case BFD_RELOC_MIPS_HIGHER: |
| 15583 | case BFD_RELOC_MIPS_SCN_DISP: |
| 15584 | case BFD_RELOC_MIPS_REL16: |
| 15585 | case BFD_RELOC_MIPS_RELGOT: |
| 15586 | case BFD_RELOC_MIPS_JALR: |
| 15587 | case BFD_RELOC_HI16: |
| 15588 | case BFD_RELOC_HI16_S: |
| 15589 | case BFD_RELOC_LO16: |
| 15590 | case BFD_RELOC_GPREL16: |
| 15591 | case BFD_RELOC_MIPS_LITERAL: |
| 15592 | case BFD_RELOC_MIPS_CALL16: |
| 15593 | case BFD_RELOC_MIPS_GOT16: |
| 15594 | case BFD_RELOC_GPREL32: |
| 15595 | case BFD_RELOC_MIPS_GOT_HI16: |
| 15596 | case BFD_RELOC_MIPS_GOT_LO16: |
| 15597 | case BFD_RELOC_MIPS_CALL_HI16: |
| 15598 | case BFD_RELOC_MIPS_CALL_LO16: |
| 15599 | case BFD_RELOC_MIPS16_GPREL: |
| 15600 | case BFD_RELOC_MIPS16_GOT16: |
| 15601 | case BFD_RELOC_MIPS16_CALL16: |
| 15602 | case BFD_RELOC_MIPS16_HI16: |
| 15603 | case BFD_RELOC_MIPS16_HI16_S: |
| 15604 | case BFD_RELOC_MIPS16_LO16: |
| 15605 | case BFD_RELOC_MIPS16_JMP: |
| 15606 | case BFD_RELOC_MICROMIPS_JMP: |
| 15607 | case BFD_RELOC_MICROMIPS_GOT_DISP: |
| 15608 | case BFD_RELOC_MICROMIPS_GOT_PAGE: |
| 15609 | case BFD_RELOC_MICROMIPS_GOT_OFST: |
| 15610 | case BFD_RELOC_MICROMIPS_SUB: |
| 15611 | case BFD_RELOC_MICROMIPS_HIGHEST: |
| 15612 | case BFD_RELOC_MICROMIPS_HIGHER: |
| 15613 | case BFD_RELOC_MICROMIPS_SCN_DISP: |
| 15614 | case BFD_RELOC_MICROMIPS_JALR: |
| 15615 | case BFD_RELOC_MICROMIPS_HI16: |
| 15616 | case BFD_RELOC_MICROMIPS_HI16_S: |
| 15617 | case BFD_RELOC_MICROMIPS_LO16: |
| 15618 | case BFD_RELOC_MICROMIPS_GPREL16: |
| 15619 | case BFD_RELOC_MICROMIPS_LITERAL: |
| 15620 | case BFD_RELOC_MICROMIPS_CALL16: |
| 15621 | case BFD_RELOC_MICROMIPS_GOT16: |
| 15622 | case BFD_RELOC_MICROMIPS_GOT_HI16: |
| 15623 | case BFD_RELOC_MICROMIPS_GOT_LO16: |
| 15624 | case BFD_RELOC_MICROMIPS_CALL_HI16: |
| 15625 | case BFD_RELOC_MICROMIPS_CALL_LO16: |
| 15626 | if (fixP->fx_done) |
| 15627 | { |
| 15628 | offsetT value; |
| 15629 | |
| 15630 | if (calculate_reloc (fixP->fx_r_type, *valP, &value)) |
| 15631 | { |
| 15632 | insn = read_reloc_insn (buf, fixP->fx_r_type); |
| 15633 | if (mips16_reloc_p (fixP->fx_r_type)) |
| 15634 | insn |= mips16_immed_extend (value, 16); |
| 15635 | else |
| 15636 | insn |= (value & 0xffff); |
| 15637 | write_reloc_insn (buf, fixP->fx_r_type, insn); |
| 15638 | } |
| 15639 | else |
| 15640 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 15641 | _("Unsupported constant in relocation")); |
| 15642 | } |
| 15643 | break; |
| 15644 | |
| 15645 | case BFD_RELOC_64: |
| 15646 | /* This is handled like BFD_RELOC_32, but we output a sign |
| 15647 | extended value if we are only 32 bits. */ |
| 15648 | if (fixP->fx_done) |
| 15649 | { |
| 15650 | if (8 <= sizeof (valueT)) |
| 15651 | md_number_to_chars (buf, *valP, 8); |
| 15652 | else |
| 15653 | { |
| 15654 | valueT hiv; |
| 15655 | |
| 15656 | if ((*valP & 0x80000000) != 0) |
| 15657 | hiv = 0xffffffff; |
| 15658 | else |
| 15659 | hiv = 0; |
| 15660 | md_number_to_chars (buf + (target_big_endian ? 4 : 0), *valP, 4); |
| 15661 | md_number_to_chars (buf + (target_big_endian ? 0 : 4), hiv, 4); |
| 15662 | } |
| 15663 | } |
| 15664 | break; |
| 15665 | |
| 15666 | case BFD_RELOC_RVA: |
| 15667 | case BFD_RELOC_32: |
| 15668 | case BFD_RELOC_16: |
| 15669 | /* If we are deleting this reloc entry, we must fill in the |
| 15670 | value now. This can happen if we have a .word which is not |
| 15671 | resolved when it appears but is later defined. */ |
| 15672 | if (fixP->fx_done) |
| 15673 | md_number_to_chars (buf, *valP, fixP->fx_size); |
| 15674 | break; |
| 15675 | |
| 15676 | case BFD_RELOC_16_PCREL_S2: |
| 15677 | if ((*valP & 0x3) != 0) |
| 15678 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 15679 | _("Branch to misaligned address (%lx)"), (long) *valP); |
| 15680 | |
| 15681 | /* We need to save the bits in the instruction since fixup_segment() |
| 15682 | might be deleting the relocation entry (i.e., a branch within |
| 15683 | the current segment). */ |
| 15684 | if (! fixP->fx_done) |
| 15685 | break; |
| 15686 | |
| 15687 | /* Update old instruction data. */ |
| 15688 | insn = read_insn (buf); |
| 15689 | |
| 15690 | if (*valP + 0x20000 <= 0x3ffff) |
| 15691 | { |
| 15692 | insn |= (*valP >> 2) & 0xffff; |
| 15693 | write_insn (buf, insn); |
| 15694 | } |
| 15695 | else if (mips_pic == NO_PIC |
| 15696 | && fixP->fx_done |
| 15697 | && fixP->fx_frag->fr_address >= text_section->vma |
| 15698 | && (fixP->fx_frag->fr_address |
| 15699 | < text_section->vma + bfd_get_section_size (text_section)) |
| 15700 | && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */ |
| 15701 | || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */ |
| 15702 | || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */ |
| 15703 | { |
| 15704 | /* The branch offset is too large. If this is an |
| 15705 | unconditional branch, and we are not generating PIC code, |
| 15706 | we can convert it to an absolute jump instruction. */ |
| 15707 | if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */ |
| 15708 | insn = 0x0c000000; /* jal */ |
| 15709 | else |
| 15710 | insn = 0x08000000; /* j */ |
| 15711 | fixP->fx_r_type = BFD_RELOC_MIPS_JMP; |
| 15712 | fixP->fx_done = 0; |
| 15713 | fixP->fx_addsy = section_symbol (text_section); |
| 15714 | *valP += md_pcrel_from (fixP); |
| 15715 | write_insn (buf, insn); |
| 15716 | } |
| 15717 | else |
| 15718 | { |
| 15719 | /* If we got here, we have branch-relaxation disabled, |
| 15720 | and there's nothing we can do to fix this instruction |
| 15721 | without turning it into a longer sequence. */ |
| 15722 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 15723 | _("Branch out of range")); |
| 15724 | } |
| 15725 | break; |
| 15726 | |
| 15727 | case BFD_RELOC_MICROMIPS_7_PCREL_S1: |
| 15728 | case BFD_RELOC_MICROMIPS_10_PCREL_S1: |
| 15729 | case BFD_RELOC_MICROMIPS_16_PCREL_S1: |
| 15730 | /* We adjust the offset back to even. */ |
| 15731 | if ((*valP & 0x1) != 0) |
| 15732 | --(*valP); |
| 15733 | |
| 15734 | if (! fixP->fx_done) |
| 15735 | break; |
| 15736 | |
| 15737 | /* Should never visit here, because we keep the relocation. */ |
| 15738 | abort (); |
| 15739 | break; |
| 15740 | |
| 15741 | case BFD_RELOC_VTABLE_INHERIT: |
| 15742 | fixP->fx_done = 0; |
| 15743 | if (fixP->fx_addsy |
| 15744 | && !S_IS_DEFINED (fixP->fx_addsy) |
| 15745 | && !S_IS_WEAK (fixP->fx_addsy)) |
| 15746 | S_SET_WEAK (fixP->fx_addsy); |
| 15747 | break; |
| 15748 | |
| 15749 | case BFD_RELOC_VTABLE_ENTRY: |
| 15750 | fixP->fx_done = 0; |
| 15751 | break; |
| 15752 | |
| 15753 | default: |
| 15754 | internalError (); |
| 15755 | } |
| 15756 | |
| 15757 | /* Remember value for tc_gen_reloc. */ |
| 15758 | fixP->fx_addnumber = *valP; |
| 15759 | } |
| 15760 | |
| 15761 | static symbolS * |
| 15762 | get_symbol (void) |
| 15763 | { |
| 15764 | int c; |
| 15765 | char *name; |
| 15766 | symbolS *p; |
| 15767 | |
| 15768 | name = input_line_pointer; |
| 15769 | c = get_symbol_end (); |
| 15770 | p = (symbolS *) symbol_find_or_make (name); |
| 15771 | *input_line_pointer = c; |
| 15772 | return p; |
| 15773 | } |
| 15774 | |
| 15775 | /* Align the current frag to a given power of two. If a particular |
| 15776 | fill byte should be used, FILL points to an integer that contains |
| 15777 | that byte, otherwise FILL is null. |
| 15778 | |
| 15779 | This function used to have the comment: |
| 15780 | |
| 15781 | The MIPS assembler also automatically adjusts any preceding label. |
| 15782 | |
| 15783 | The implementation therefore applied the adjustment to a maximum of |
| 15784 | one label. However, other label adjustments are applied to batches |
| 15785 | of labels, and adjusting just one caused problems when new labels |
| 15786 | were added for the sake of debugging or unwind information. |
| 15787 | We therefore adjust all preceding labels (given as LABELS) instead. */ |
| 15788 | |
| 15789 | static void |
| 15790 | mips_align (int to, int *fill, struct insn_label_list *labels) |
| 15791 | { |
| 15792 | mips_emit_delays (); |
| 15793 | mips_record_compressed_mode (); |
| 15794 | if (fill == NULL && subseg_text_p (now_seg)) |
| 15795 | frag_align_code (to, 0); |
| 15796 | else |
| 15797 | frag_align (to, fill ? *fill : 0, 0); |
| 15798 | record_alignment (now_seg, to); |
| 15799 | mips_move_labels (labels, FALSE); |
| 15800 | } |
| 15801 | |
| 15802 | /* Align to a given power of two. .align 0 turns off the automatic |
| 15803 | alignment used by the data creating pseudo-ops. */ |
| 15804 | |
| 15805 | static void |
| 15806 | s_align (int x ATTRIBUTE_UNUSED) |
| 15807 | { |
| 15808 | int temp, fill_value, *fill_ptr; |
| 15809 | long max_alignment = 28; |
| 15810 | |
| 15811 | /* o Note that the assembler pulls down any immediately preceding label |
| 15812 | to the aligned address. |
| 15813 | o It's not documented but auto alignment is reinstated by |
| 15814 | a .align pseudo instruction. |
| 15815 | o Note also that after auto alignment is turned off the mips assembler |
| 15816 | issues an error on attempt to assemble an improperly aligned data item. |
| 15817 | We don't. */ |
| 15818 | |
| 15819 | temp = get_absolute_expression (); |
| 15820 | if (temp > max_alignment) |
| 15821 | as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment); |
| 15822 | else if (temp < 0) |
| 15823 | { |
| 15824 | as_warn (_("Alignment negative: 0 assumed.")); |
| 15825 | temp = 0; |
| 15826 | } |
| 15827 | if (*input_line_pointer == ',') |
| 15828 | { |
| 15829 | ++input_line_pointer; |
| 15830 | fill_value = get_absolute_expression (); |
| 15831 | fill_ptr = &fill_value; |
| 15832 | } |
| 15833 | else |
| 15834 | fill_ptr = 0; |
| 15835 | if (temp) |
| 15836 | { |
| 15837 | segment_info_type *si = seg_info (now_seg); |
| 15838 | struct insn_label_list *l = si->label_list; |
| 15839 | /* Auto alignment should be switched on by next section change. */ |
| 15840 | auto_align = 1; |
| 15841 | mips_align (temp, fill_ptr, l); |
| 15842 | } |
| 15843 | else |
| 15844 | { |
| 15845 | auto_align = 0; |
| 15846 | } |
| 15847 | |
| 15848 | demand_empty_rest_of_line (); |
| 15849 | } |
| 15850 | |
| 15851 | static void |
| 15852 | s_change_sec (int sec) |
| 15853 | { |
| 15854 | segT seg; |
| 15855 | |
| 15856 | #ifdef OBJ_ELF |
| 15857 | /* The ELF backend needs to know that we are changing sections, so |
| 15858 | that .previous works correctly. We could do something like check |
| 15859 | for an obj_section_change_hook macro, but that might be confusing |
| 15860 | as it would not be appropriate to use it in the section changing |
| 15861 | functions in read.c, since obj-elf.c intercepts those. FIXME: |
| 15862 | This should be cleaner, somehow. */ |
| 15863 | if (IS_ELF) |
| 15864 | obj_elf_section_change_hook (); |
| 15865 | #endif |
| 15866 | |
| 15867 | mips_emit_delays (); |
| 15868 | |
| 15869 | switch (sec) |
| 15870 | { |
| 15871 | case 't': |
| 15872 | s_text (0); |
| 15873 | break; |
| 15874 | case 'd': |
| 15875 | s_data (0); |
| 15876 | break; |
| 15877 | case 'b': |
| 15878 | subseg_set (bss_section, (subsegT) get_absolute_expression ()); |
| 15879 | demand_empty_rest_of_line (); |
| 15880 | break; |
| 15881 | |
| 15882 | case 'r': |
| 15883 | seg = subseg_new (RDATA_SECTION_NAME, |
| 15884 | (subsegT) get_absolute_expression ()); |
| 15885 | if (IS_ELF) |
| 15886 | { |
| 15887 | bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD |
| 15888 | | SEC_READONLY | SEC_RELOC |
| 15889 | | SEC_DATA)); |
| 15890 | if (strncmp (TARGET_OS, "elf", 3) != 0) |
| 15891 | record_alignment (seg, 4); |
| 15892 | } |
| 15893 | demand_empty_rest_of_line (); |
| 15894 | break; |
| 15895 | |
| 15896 | case 's': |
| 15897 | seg = subseg_new (".sdata", (subsegT) get_absolute_expression ()); |
| 15898 | if (IS_ELF) |
| 15899 | { |
| 15900 | bfd_set_section_flags (stdoutput, seg, |
| 15901 | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA); |
| 15902 | if (strncmp (TARGET_OS, "elf", 3) != 0) |
| 15903 | record_alignment (seg, 4); |
| 15904 | } |
| 15905 | demand_empty_rest_of_line (); |
| 15906 | break; |
| 15907 | |
| 15908 | case 'B': |
| 15909 | seg = subseg_new (".sbss", (subsegT) get_absolute_expression ()); |
| 15910 | if (IS_ELF) |
| 15911 | { |
| 15912 | bfd_set_section_flags (stdoutput, seg, SEC_ALLOC); |
| 15913 | if (strncmp (TARGET_OS, "elf", 3) != 0) |
| 15914 | record_alignment (seg, 4); |
| 15915 | } |
| 15916 | demand_empty_rest_of_line (); |
| 15917 | break; |
| 15918 | } |
| 15919 | |
| 15920 | auto_align = 1; |
| 15921 | } |
| 15922 | |
| 15923 | void |
| 15924 | s_change_section (int ignore ATTRIBUTE_UNUSED) |
| 15925 | { |
| 15926 | #ifdef OBJ_ELF |
| 15927 | char *section_name; |
| 15928 | char c; |
| 15929 | char next_c = 0; |
| 15930 | int section_type; |
| 15931 | int section_flag; |
| 15932 | int section_entry_size; |
| 15933 | int section_alignment; |
| 15934 | |
| 15935 | if (!IS_ELF) |
| 15936 | return; |
| 15937 | |
| 15938 | section_name = input_line_pointer; |
| 15939 | c = get_symbol_end (); |
| 15940 | if (c) |
| 15941 | next_c = *(input_line_pointer + 1); |
| 15942 | |
| 15943 | /* Do we have .section Name<,"flags">? */ |
| 15944 | if (c != ',' || (c == ',' && next_c == '"')) |
| 15945 | { |
| 15946 | /* just after name is now '\0'. */ |
| 15947 | *input_line_pointer = c; |
| 15948 | input_line_pointer = section_name; |
| 15949 | obj_elf_section (ignore); |
| 15950 | return; |
| 15951 | } |
| 15952 | input_line_pointer++; |
| 15953 | |
| 15954 | /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */ |
| 15955 | if (c == ',') |
| 15956 | section_type = get_absolute_expression (); |
| 15957 | else |
| 15958 | section_type = 0; |
| 15959 | if (*input_line_pointer++ == ',') |
| 15960 | section_flag = get_absolute_expression (); |
| 15961 | else |
| 15962 | section_flag = 0; |
| 15963 | if (*input_line_pointer++ == ',') |
| 15964 | section_entry_size = get_absolute_expression (); |
| 15965 | else |
| 15966 | section_entry_size = 0; |
| 15967 | if (*input_line_pointer++ == ',') |
| 15968 | section_alignment = get_absolute_expression (); |
| 15969 | else |
| 15970 | section_alignment = 0; |
| 15971 | /* FIXME: really ignore? */ |
| 15972 | (void) section_alignment; |
| 15973 | |
| 15974 | section_name = xstrdup (section_name); |
| 15975 | |
| 15976 | /* When using the generic form of .section (as implemented by obj-elf.c), |
| 15977 | there's no way to set the section type to SHT_MIPS_DWARF. Users have |
| 15978 | traditionally had to fall back on the more common @progbits instead. |
| 15979 | |
| 15980 | There's nothing really harmful in this, since bfd will correct |
| 15981 | SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it |
| 15982 | means that, for backwards compatibility, the special_section entries |
| 15983 | for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF. |
| 15984 | |
| 15985 | Even so, we shouldn't force users of the MIPS .section syntax to |
| 15986 | incorrectly label the sections as SHT_PROGBITS. The best compromise |
| 15987 | seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the |
| 15988 | generic type-checking code. */ |
| 15989 | if (section_type == SHT_MIPS_DWARF) |
| 15990 | section_type = SHT_PROGBITS; |
| 15991 | |
| 15992 | obj_elf_change_section (section_name, section_type, section_flag, |
| 15993 | section_entry_size, 0, 0, 0); |
| 15994 | |
| 15995 | if (now_seg->name != section_name) |
| 15996 | free (section_name); |
| 15997 | #endif /* OBJ_ELF */ |
| 15998 | } |
| 15999 | |
| 16000 | void |
| 16001 | mips_enable_auto_align (void) |
| 16002 | { |
| 16003 | auto_align = 1; |
| 16004 | } |
| 16005 | |
| 16006 | static void |
| 16007 | s_cons (int log_size) |
| 16008 | { |
| 16009 | segment_info_type *si = seg_info (now_seg); |
| 16010 | struct insn_label_list *l = si->label_list; |
| 16011 | |
| 16012 | mips_emit_delays (); |
| 16013 | if (log_size > 0 && auto_align) |
| 16014 | mips_align (log_size, 0, l); |
| 16015 | cons (1 << log_size); |
| 16016 | mips_clear_insn_labels (); |
| 16017 | } |
| 16018 | |
| 16019 | static void |
| 16020 | s_float_cons (int type) |
| 16021 | { |
| 16022 | segment_info_type *si = seg_info (now_seg); |
| 16023 | struct insn_label_list *l = si->label_list; |
| 16024 | |
| 16025 | mips_emit_delays (); |
| 16026 | |
| 16027 | if (auto_align) |
| 16028 | { |
| 16029 | if (type == 'd') |
| 16030 | mips_align (3, 0, l); |
| 16031 | else |
| 16032 | mips_align (2, 0, l); |
| 16033 | } |
| 16034 | |
| 16035 | float_cons (type); |
| 16036 | mips_clear_insn_labels (); |
| 16037 | } |
| 16038 | |
| 16039 | /* Handle .globl. We need to override it because on Irix 5 you are |
| 16040 | permitted to say |
| 16041 | .globl foo .text |
| 16042 | where foo is an undefined symbol, to mean that foo should be |
| 16043 | considered to be the address of a function. */ |
| 16044 | |
| 16045 | static void |
| 16046 | s_mips_globl (int x ATTRIBUTE_UNUSED) |
| 16047 | { |
| 16048 | char *name; |
| 16049 | int c; |
| 16050 | symbolS *symbolP; |
| 16051 | flagword flag; |
| 16052 | |
| 16053 | do |
| 16054 | { |
| 16055 | name = input_line_pointer; |
| 16056 | c = get_symbol_end (); |
| 16057 | symbolP = symbol_find_or_make (name); |
| 16058 | S_SET_EXTERNAL (symbolP); |
| 16059 | |
| 16060 | *input_line_pointer = c; |
| 16061 | SKIP_WHITESPACE (); |
| 16062 | |
| 16063 | /* On Irix 5, every global symbol that is not explicitly labelled as |
| 16064 | being a function is apparently labelled as being an object. */ |
| 16065 | flag = BSF_OBJECT; |
| 16066 | |
| 16067 | if (!is_end_of_line[(unsigned char) *input_line_pointer] |
| 16068 | && (*input_line_pointer != ',')) |
| 16069 | { |
| 16070 | char *secname; |
| 16071 | asection *sec; |
| 16072 | |
| 16073 | secname = input_line_pointer; |
| 16074 | c = get_symbol_end (); |
| 16075 | sec = bfd_get_section_by_name (stdoutput, secname); |
| 16076 | if (sec == NULL) |
| 16077 | as_bad (_("%s: no such section"), secname); |
| 16078 | *input_line_pointer = c; |
| 16079 | |
| 16080 | if (sec != NULL && (sec->flags & SEC_CODE) != 0) |
| 16081 | flag = BSF_FUNCTION; |
| 16082 | } |
| 16083 | |
| 16084 | symbol_get_bfdsym (symbolP)->flags |= flag; |
| 16085 | |
| 16086 | c = *input_line_pointer; |
| 16087 | if (c == ',') |
| 16088 | { |
| 16089 | input_line_pointer++; |
| 16090 | SKIP_WHITESPACE (); |
| 16091 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
| 16092 | c = '\n'; |
| 16093 | } |
| 16094 | } |
| 16095 | while (c == ','); |
| 16096 | |
| 16097 | demand_empty_rest_of_line (); |
| 16098 | } |
| 16099 | |
| 16100 | static void |
| 16101 | s_option (int x ATTRIBUTE_UNUSED) |
| 16102 | { |
| 16103 | char *opt; |
| 16104 | char c; |
| 16105 | |
| 16106 | opt = input_line_pointer; |
| 16107 | c = get_symbol_end (); |
| 16108 | |
| 16109 | if (*opt == 'O') |
| 16110 | { |
| 16111 | /* FIXME: What does this mean? */ |
| 16112 | } |
| 16113 | else if (strncmp (opt, "pic", 3) == 0) |
| 16114 | { |
| 16115 | int i; |
| 16116 | |
| 16117 | i = atoi (opt + 3); |
| 16118 | if (i == 0) |
| 16119 | mips_pic = NO_PIC; |
| 16120 | else if (i == 2) |
| 16121 | { |
| 16122 | mips_pic = SVR4_PIC; |
| 16123 | mips_abicalls = TRUE; |
| 16124 | } |
| 16125 | else |
| 16126 | as_bad (_(".option pic%d not supported"), i); |
| 16127 | |
| 16128 | if (mips_pic == SVR4_PIC) |
| 16129 | { |
| 16130 | if (g_switch_seen && g_switch_value != 0) |
| 16131 | as_warn (_("-G may not be used with SVR4 PIC code")); |
| 16132 | g_switch_value = 0; |
| 16133 | bfd_set_gp_size (stdoutput, 0); |
| 16134 | } |
| 16135 | } |
| 16136 | else |
| 16137 | as_warn (_("Unrecognized option \"%s\""), opt); |
| 16138 | |
| 16139 | *input_line_pointer = c; |
| 16140 | demand_empty_rest_of_line (); |
| 16141 | } |
| 16142 | |
| 16143 | /* This structure is used to hold a stack of .set values. */ |
| 16144 | |
| 16145 | struct mips_option_stack |
| 16146 | { |
| 16147 | struct mips_option_stack *next; |
| 16148 | struct mips_set_options options; |
| 16149 | }; |
| 16150 | |
| 16151 | static struct mips_option_stack *mips_opts_stack; |
| 16152 | |
| 16153 | /* Handle the .set pseudo-op. */ |
| 16154 | |
| 16155 | static void |
| 16156 | s_mipsset (int x ATTRIBUTE_UNUSED) |
| 16157 | { |
| 16158 | char *name = input_line_pointer, ch; |
| 16159 | |
| 16160 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) |
| 16161 | ++input_line_pointer; |
| 16162 | ch = *input_line_pointer; |
| 16163 | *input_line_pointer = '\0'; |
| 16164 | |
| 16165 | if (strcmp (name, "reorder") == 0) |
| 16166 | { |
| 16167 | if (mips_opts.noreorder) |
| 16168 | end_noreorder (); |
| 16169 | } |
| 16170 | else if (strcmp (name, "noreorder") == 0) |
| 16171 | { |
| 16172 | if (!mips_opts.noreorder) |
| 16173 | start_noreorder (); |
| 16174 | } |
| 16175 | else if (strncmp (name, "at=", 3) == 0) |
| 16176 | { |
| 16177 | char *s = name + 3; |
| 16178 | |
| 16179 | if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, &mips_opts.at)) |
| 16180 | as_bad (_("Unrecognized register name `%s'"), s); |
| 16181 | } |
| 16182 | else if (strcmp (name, "at") == 0) |
| 16183 | { |
| 16184 | mips_opts.at = ATREG; |
| 16185 | } |
| 16186 | else if (strcmp (name, "noat") == 0) |
| 16187 | { |
| 16188 | mips_opts.at = ZERO; |
| 16189 | } |
| 16190 | else if (strcmp (name, "macro") == 0) |
| 16191 | { |
| 16192 | mips_opts.warn_about_macros = 0; |
| 16193 | } |
| 16194 | else if (strcmp (name, "nomacro") == 0) |
| 16195 | { |
| 16196 | if (mips_opts.noreorder == 0) |
| 16197 | as_bad (_("`noreorder' must be set before `nomacro'")); |
| 16198 | mips_opts.warn_about_macros = 1; |
| 16199 | } |
| 16200 | else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0) |
| 16201 | { |
| 16202 | mips_opts.nomove = 0; |
| 16203 | } |
| 16204 | else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0) |
| 16205 | { |
| 16206 | mips_opts.nomove = 1; |
| 16207 | } |
| 16208 | else if (strcmp (name, "bopt") == 0) |
| 16209 | { |
| 16210 | mips_opts.nobopt = 0; |
| 16211 | } |
| 16212 | else if (strcmp (name, "nobopt") == 0) |
| 16213 | { |
| 16214 | mips_opts.nobopt = 1; |
| 16215 | } |
| 16216 | else if (strcmp (name, "gp=default") == 0) |
| 16217 | mips_opts.gp32 = file_mips_gp32; |
| 16218 | else if (strcmp (name, "gp=32") == 0) |
| 16219 | mips_opts.gp32 = 1; |
| 16220 | else if (strcmp (name, "gp=64") == 0) |
| 16221 | { |
| 16222 | if (!ISA_HAS_64BIT_REGS (mips_opts.isa)) |
| 16223 | as_warn (_("%s isa does not support 64-bit registers"), |
| 16224 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 16225 | mips_opts.gp32 = 0; |
| 16226 | } |
| 16227 | else if (strcmp (name, "fp=default") == 0) |
| 16228 | mips_opts.fp32 = file_mips_fp32; |
| 16229 | else if (strcmp (name, "fp=32") == 0) |
| 16230 | mips_opts.fp32 = 1; |
| 16231 | else if (strcmp (name, "fp=64") == 0) |
| 16232 | { |
| 16233 | if (!ISA_HAS_64BIT_FPRS (mips_opts.isa)) |
| 16234 | as_warn (_("%s isa does not support 64-bit floating point registers"), |
| 16235 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 16236 | mips_opts.fp32 = 0; |
| 16237 | } |
| 16238 | else if (strcmp (name, "softfloat") == 0) |
| 16239 | mips_opts.soft_float = 1; |
| 16240 | else if (strcmp (name, "hardfloat") == 0) |
| 16241 | mips_opts.soft_float = 0; |
| 16242 | else if (strcmp (name, "singlefloat") == 0) |
| 16243 | mips_opts.single_float = 1; |
| 16244 | else if (strcmp (name, "doublefloat") == 0) |
| 16245 | mips_opts.single_float = 0; |
| 16246 | else if (strcmp (name, "mips16") == 0 |
| 16247 | || strcmp (name, "MIPS-16") == 0) |
| 16248 | { |
| 16249 | if (mips_opts.micromips == 1) |
| 16250 | as_fatal (_("`mips16' cannot be used with `micromips'")); |
| 16251 | mips_opts.mips16 = 1; |
| 16252 | } |
| 16253 | else if (strcmp (name, "nomips16") == 0 |
| 16254 | || strcmp (name, "noMIPS-16") == 0) |
| 16255 | mips_opts.mips16 = 0; |
| 16256 | else if (strcmp (name, "micromips") == 0) |
| 16257 | { |
| 16258 | if (mips_opts.mips16 == 1) |
| 16259 | as_fatal (_("`micromips' cannot be used with `mips16'")); |
| 16260 | mips_opts.micromips = 1; |
| 16261 | } |
| 16262 | else if (strcmp (name, "nomicromips") == 0) |
| 16263 | mips_opts.micromips = 0; |
| 16264 | else if (strcmp (name, "smartmips") == 0) |
| 16265 | { |
| 16266 | if (!ISA_SUPPORTS_SMARTMIPS) |
| 16267 | as_warn (_("%s ISA does not support SmartMIPS ASE"), |
| 16268 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 16269 | mips_opts.ase_smartmips = 1; |
| 16270 | } |
| 16271 | else if (strcmp (name, "nosmartmips") == 0) |
| 16272 | mips_opts.ase_smartmips = 0; |
| 16273 | else if (strcmp (name, "mips3d") == 0) |
| 16274 | mips_opts.ase_mips3d = 1; |
| 16275 | else if (strcmp (name, "nomips3d") == 0) |
| 16276 | mips_opts.ase_mips3d = 0; |
| 16277 | else if (strcmp (name, "mdmx") == 0) |
| 16278 | mips_opts.ase_mdmx = 1; |
| 16279 | else if (strcmp (name, "nomdmx") == 0) |
| 16280 | mips_opts.ase_mdmx = 0; |
| 16281 | else if (strcmp (name, "dsp") == 0) |
| 16282 | { |
| 16283 | if (!ISA_SUPPORTS_DSP_ASE) |
| 16284 | as_warn (_("%s ISA does not support DSP ASE"), |
| 16285 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 16286 | mips_opts.ase_dsp = 1; |
| 16287 | mips_opts.ase_dspr2 = 0; |
| 16288 | } |
| 16289 | else if (strcmp (name, "nodsp") == 0) |
| 16290 | { |
| 16291 | mips_opts.ase_dsp = 0; |
| 16292 | mips_opts.ase_dspr2 = 0; |
| 16293 | } |
| 16294 | else if (strcmp (name, "dspr2") == 0) |
| 16295 | { |
| 16296 | if (!ISA_SUPPORTS_DSPR2_ASE) |
| 16297 | as_warn (_("%s ISA does not support DSP R2 ASE"), |
| 16298 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 16299 | mips_opts.ase_dspr2 = 1; |
| 16300 | mips_opts.ase_dsp = 1; |
| 16301 | } |
| 16302 | else if (strcmp (name, "nodspr2") == 0) |
| 16303 | { |
| 16304 | mips_opts.ase_dspr2 = 0; |
| 16305 | mips_opts.ase_dsp = 0; |
| 16306 | } |
| 16307 | else if (strcmp (name, "mt") == 0) |
| 16308 | { |
| 16309 | if (!ISA_SUPPORTS_MT_ASE) |
| 16310 | as_warn (_("%s ISA does not support MT ASE"), |
| 16311 | mips_cpu_info_from_isa (mips_opts.isa)->name); |
| 16312 | mips_opts.ase_mt = 1; |
| 16313 | } |
| 16314 | else if (strcmp (name, "nomt") == 0) |
| 16315 | mips_opts.ase_mt = 0; |
| 16316 | else if (strcmp (name, "mcu") == 0) |
| 16317 | mips_opts.ase_mcu = 1; |
| 16318 | else if (strcmp (name, "nomcu") == 0) |
| 16319 | mips_opts.ase_mcu = 0; |
| 16320 | else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0) |
| 16321 | { |
| 16322 | int reset = 0; |
| 16323 | |
| 16324 | /* Permit the user to change the ISA and architecture on the fly. |
| 16325 | Needless to say, misuse can cause serious problems. */ |
| 16326 | if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0) |
| 16327 | { |
| 16328 | reset = 1; |
| 16329 | mips_opts.isa = file_mips_isa; |
| 16330 | mips_opts.arch = file_mips_arch; |
| 16331 | } |
| 16332 | else if (strncmp (name, "arch=", 5) == 0) |
| 16333 | { |
| 16334 | const struct mips_cpu_info *p; |
| 16335 | |
| 16336 | p = mips_parse_cpu("internal use", name + 5); |
| 16337 | if (!p) |
| 16338 | as_bad (_("unknown architecture %s"), name + 5); |
| 16339 | else |
| 16340 | { |
| 16341 | mips_opts.arch = p->cpu; |
| 16342 | mips_opts.isa = p->isa; |
| 16343 | } |
| 16344 | } |
| 16345 | else if (strncmp (name, "mips", 4) == 0) |
| 16346 | { |
| 16347 | const struct mips_cpu_info *p; |
| 16348 | |
| 16349 | p = mips_parse_cpu("internal use", name); |
| 16350 | if (!p) |
| 16351 | as_bad (_("unknown ISA level %s"), name + 4); |
| 16352 | else |
| 16353 | { |
| 16354 | mips_opts.arch = p->cpu; |
| 16355 | mips_opts.isa = p->isa; |
| 16356 | } |
| 16357 | } |
| 16358 | else |
| 16359 | as_bad (_("unknown ISA or architecture %s"), name); |
| 16360 | |
| 16361 | switch (mips_opts.isa) |
| 16362 | { |
| 16363 | case 0: |
| 16364 | break; |
| 16365 | case ISA_MIPS1: |
| 16366 | case ISA_MIPS2: |
| 16367 | case ISA_MIPS32: |
| 16368 | case ISA_MIPS32R2: |
| 16369 | mips_opts.gp32 = 1; |
| 16370 | mips_opts.fp32 = 1; |
| 16371 | break; |
| 16372 | case ISA_MIPS3: |
| 16373 | case ISA_MIPS4: |
| 16374 | case ISA_MIPS5: |
| 16375 | case ISA_MIPS64: |
| 16376 | case ISA_MIPS64R2: |
| 16377 | mips_opts.gp32 = 0; |
| 16378 | mips_opts.fp32 = 0; |
| 16379 | break; |
| 16380 | default: |
| 16381 | as_bad (_("unknown ISA level %s"), name + 4); |
| 16382 | break; |
| 16383 | } |
| 16384 | if (reset) |
| 16385 | { |
| 16386 | mips_opts.gp32 = file_mips_gp32; |
| 16387 | mips_opts.fp32 = file_mips_fp32; |
| 16388 | } |
| 16389 | } |
| 16390 | else if (strcmp (name, "autoextend") == 0) |
| 16391 | mips_opts.noautoextend = 0; |
| 16392 | else if (strcmp (name, "noautoextend") == 0) |
| 16393 | mips_opts.noautoextend = 1; |
| 16394 | else if (strcmp (name, "push") == 0) |
| 16395 | { |
| 16396 | struct mips_option_stack *s; |
| 16397 | |
| 16398 | s = (struct mips_option_stack *) xmalloc (sizeof *s); |
| 16399 | s->next = mips_opts_stack; |
| 16400 | s->options = mips_opts; |
| 16401 | mips_opts_stack = s; |
| 16402 | } |
| 16403 | else if (strcmp (name, "pop") == 0) |
| 16404 | { |
| 16405 | struct mips_option_stack *s; |
| 16406 | |
| 16407 | s = mips_opts_stack; |
| 16408 | if (s == NULL) |
| 16409 | as_bad (_(".set pop with no .set push")); |
| 16410 | else |
| 16411 | { |
| 16412 | /* If we're changing the reorder mode we need to handle |
| 16413 | delay slots correctly. */ |
| 16414 | if (s->options.noreorder && ! mips_opts.noreorder) |
| 16415 | start_noreorder (); |
| 16416 | else if (! s->options.noreorder && mips_opts.noreorder) |
| 16417 | end_noreorder (); |
| 16418 | |
| 16419 | mips_opts = s->options; |
| 16420 | mips_opts_stack = s->next; |
| 16421 | free (s); |
| 16422 | } |
| 16423 | } |
| 16424 | else if (strcmp (name, "sym32") == 0) |
| 16425 | mips_opts.sym32 = TRUE; |
| 16426 | else if (strcmp (name, "nosym32") == 0) |
| 16427 | mips_opts.sym32 = FALSE; |
| 16428 | else if (strchr (name, ',')) |
| 16429 | { |
| 16430 | /* Generic ".set" directive; use the generic handler. */ |
| 16431 | *input_line_pointer = ch; |
| 16432 | input_line_pointer = name; |
| 16433 | s_set (0); |
| 16434 | return; |
| 16435 | } |
| 16436 | else |
| 16437 | { |
| 16438 | as_warn (_("Tried to set unrecognized symbol: %s\n"), name); |
| 16439 | } |
| 16440 | *input_line_pointer = ch; |
| 16441 | demand_empty_rest_of_line (); |
| 16442 | } |
| 16443 | |
| 16444 | /* Handle the .abicalls pseudo-op. I believe this is equivalent to |
| 16445 | .option pic2. It means to generate SVR4 PIC calls. */ |
| 16446 | |
| 16447 | static void |
| 16448 | s_abicalls (int ignore ATTRIBUTE_UNUSED) |
| 16449 | { |
| 16450 | mips_pic = SVR4_PIC; |
| 16451 | mips_abicalls = TRUE; |
| 16452 | |
| 16453 | if (g_switch_seen && g_switch_value != 0) |
| 16454 | as_warn (_("-G may not be used with SVR4 PIC code")); |
| 16455 | g_switch_value = 0; |
| 16456 | |
| 16457 | bfd_set_gp_size (stdoutput, 0); |
| 16458 | demand_empty_rest_of_line (); |
| 16459 | } |
| 16460 | |
| 16461 | /* Handle the .cpload pseudo-op. This is used when generating SVR4 |
| 16462 | PIC code. It sets the $gp register for the function based on the |
| 16463 | function address, which is in the register named in the argument. |
| 16464 | This uses a relocation against _gp_disp, which is handled specially |
| 16465 | by the linker. The result is: |
| 16466 | lui $gp,%hi(_gp_disp) |
| 16467 | addiu $gp,$gp,%lo(_gp_disp) |
| 16468 | addu $gp,$gp,.cpload argument |
| 16469 | The .cpload argument is normally $25 == $t9. |
| 16470 | |
| 16471 | The -mno-shared option changes this to: |
| 16472 | lui $gp,%hi(__gnu_local_gp) |
| 16473 | addiu $gp,$gp,%lo(__gnu_local_gp) |
| 16474 | and the argument is ignored. This saves an instruction, but the |
| 16475 | resulting code is not position independent; it uses an absolute |
| 16476 | address for __gnu_local_gp. Thus code assembled with -mno-shared |
| 16477 | can go into an ordinary executable, but not into a shared library. */ |
| 16478 | |
| 16479 | static void |
| 16480 | s_cpload (int ignore ATTRIBUTE_UNUSED) |
| 16481 | { |
| 16482 | expressionS ex; |
| 16483 | int reg; |
| 16484 | int in_shared; |
| 16485 | |
| 16486 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
| 16487 | .cpload is ignored. */ |
| 16488 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) |
| 16489 | { |
| 16490 | s_ignore (0); |
| 16491 | return; |
| 16492 | } |
| 16493 | |
| 16494 | if (mips_opts.mips16) |
| 16495 | { |
| 16496 | as_bad (_("%s not supported in MIPS16 mode"), ".cpload"); |
| 16497 | ignore_rest_of_line (); |
| 16498 | return; |
| 16499 | } |
| 16500 | |
| 16501 | /* .cpload should be in a .set noreorder section. */ |
| 16502 | if (mips_opts.noreorder == 0) |
| 16503 | as_warn (_(".cpload not in noreorder section")); |
| 16504 | |
| 16505 | reg = tc_get_register (0); |
| 16506 | |
| 16507 | /* If we need to produce a 64-bit address, we are better off using |
| 16508 | the default instruction sequence. */ |
| 16509 | in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS; |
| 16510 | |
| 16511 | ex.X_op = O_symbol; |
| 16512 | ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" : |
| 16513 | "__gnu_local_gp"); |
| 16514 | ex.X_op_symbol = NULL; |
| 16515 | ex.X_add_number = 0; |
| 16516 | |
| 16517 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ |
| 16518 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
| 16519 | |
| 16520 | macro_start (); |
| 16521 | macro_build_lui (&ex, mips_gp_register); |
| 16522 | macro_build (&ex, "addiu", "t,r,j", mips_gp_register, |
| 16523 | mips_gp_register, BFD_RELOC_LO16); |
| 16524 | if (in_shared) |
| 16525 | macro_build (NULL, "addu", "d,v,t", mips_gp_register, |
| 16526 | mips_gp_register, reg); |
| 16527 | macro_end (); |
| 16528 | |
| 16529 | demand_empty_rest_of_line (); |
| 16530 | } |
| 16531 | |
| 16532 | /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is: |
| 16533 | .cpsetup $reg1, offset|$reg2, label |
| 16534 | |
| 16535 | If offset is given, this results in: |
| 16536 | sd $gp, offset($sp) |
| 16537 | lui $gp, %hi(%neg(%gp_rel(label))) |
| 16538 | addiu $gp, $gp, %lo(%neg(%gp_rel(label))) |
| 16539 | daddu $gp, $gp, $reg1 |
| 16540 | |
| 16541 | If $reg2 is given, this results in: |
| 16542 | daddu $reg2, $gp, $0 |
| 16543 | lui $gp, %hi(%neg(%gp_rel(label))) |
| 16544 | addiu $gp, $gp, %lo(%neg(%gp_rel(label))) |
| 16545 | daddu $gp, $gp, $reg1 |
| 16546 | $reg1 is normally $25 == $t9. |
| 16547 | |
| 16548 | The -mno-shared option replaces the last three instructions with |
| 16549 | lui $gp,%hi(_gp) |
| 16550 | addiu $gp,$gp,%lo(_gp) */ |
| 16551 | |
| 16552 | static void |
| 16553 | s_cpsetup (int ignore ATTRIBUTE_UNUSED) |
| 16554 | { |
| 16555 | expressionS ex_off; |
| 16556 | expressionS ex_sym; |
| 16557 | int reg1; |
| 16558 | |
| 16559 | /* If we are not generating SVR4 PIC code, .cpsetup is ignored. |
| 16560 | We also need NewABI support. */ |
| 16561 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) |
| 16562 | { |
| 16563 | s_ignore (0); |
| 16564 | return; |
| 16565 | } |
| 16566 | |
| 16567 | if (mips_opts.mips16) |
| 16568 | { |
| 16569 | as_bad (_("%s not supported in MIPS16 mode"), ".cpsetup"); |
| 16570 | ignore_rest_of_line (); |
| 16571 | return; |
| 16572 | } |
| 16573 | |
| 16574 | reg1 = tc_get_register (0); |
| 16575 | SKIP_WHITESPACE (); |
| 16576 | if (*input_line_pointer != ',') |
| 16577 | { |
| 16578 | as_bad (_("missing argument separator ',' for .cpsetup")); |
| 16579 | return; |
| 16580 | } |
| 16581 | else |
| 16582 | ++input_line_pointer; |
| 16583 | SKIP_WHITESPACE (); |
| 16584 | if (*input_line_pointer == '$') |
| 16585 | { |
| 16586 | mips_cpreturn_register = tc_get_register (0); |
| 16587 | mips_cpreturn_offset = -1; |
| 16588 | } |
| 16589 | else |
| 16590 | { |
| 16591 | mips_cpreturn_offset = get_absolute_expression (); |
| 16592 | mips_cpreturn_register = -1; |
| 16593 | } |
| 16594 | SKIP_WHITESPACE (); |
| 16595 | if (*input_line_pointer != ',') |
| 16596 | { |
| 16597 | as_bad (_("missing argument separator ',' for .cpsetup")); |
| 16598 | return; |
| 16599 | } |
| 16600 | else |
| 16601 | ++input_line_pointer; |
| 16602 | SKIP_WHITESPACE (); |
| 16603 | expression (&ex_sym); |
| 16604 | |
| 16605 | macro_start (); |
| 16606 | if (mips_cpreturn_register == -1) |
| 16607 | { |
| 16608 | ex_off.X_op = O_constant; |
| 16609 | ex_off.X_add_symbol = NULL; |
| 16610 | ex_off.X_op_symbol = NULL; |
| 16611 | ex_off.X_add_number = mips_cpreturn_offset; |
| 16612 | |
| 16613 | macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register, |
| 16614 | BFD_RELOC_LO16, SP); |
| 16615 | } |
| 16616 | else |
| 16617 | macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register, |
| 16618 | mips_gp_register, 0); |
| 16619 | |
| 16620 | if (mips_in_shared || HAVE_64BIT_SYMBOLS) |
| 16621 | { |
| 16622 | macro_build (&ex_sym, "lui", LUI_FMT, mips_gp_register, |
| 16623 | -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB, |
| 16624 | BFD_RELOC_HI16_S); |
| 16625 | |
| 16626 | macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register, |
| 16627 | mips_gp_register, -1, BFD_RELOC_GPREL16, |
| 16628 | BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16); |
| 16629 | |
| 16630 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register, |
| 16631 | mips_gp_register, reg1); |
| 16632 | } |
| 16633 | else |
| 16634 | { |
| 16635 | expressionS ex; |
| 16636 | |
| 16637 | ex.X_op = O_symbol; |
| 16638 | ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp"); |
| 16639 | ex.X_op_symbol = NULL; |
| 16640 | ex.X_add_number = 0; |
| 16641 | |
| 16642 | /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */ |
| 16643 | symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT; |
| 16644 | |
| 16645 | macro_build_lui (&ex, mips_gp_register); |
| 16646 | macro_build (&ex, "addiu", "t,r,j", mips_gp_register, |
| 16647 | mips_gp_register, BFD_RELOC_LO16); |
| 16648 | } |
| 16649 | |
| 16650 | macro_end (); |
| 16651 | |
| 16652 | demand_empty_rest_of_line (); |
| 16653 | } |
| 16654 | |
| 16655 | static void |
| 16656 | s_cplocal (int ignore ATTRIBUTE_UNUSED) |
| 16657 | { |
| 16658 | /* If we are not generating SVR4 PIC code, or if this is not NewABI code, |
| 16659 | .cplocal is ignored. */ |
| 16660 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) |
| 16661 | { |
| 16662 | s_ignore (0); |
| 16663 | return; |
| 16664 | } |
| 16665 | |
| 16666 | if (mips_opts.mips16) |
| 16667 | { |
| 16668 | as_bad (_("%s not supported in MIPS16 mode"), ".cplocal"); |
| 16669 | ignore_rest_of_line (); |
| 16670 | return; |
| 16671 | } |
| 16672 | |
| 16673 | mips_gp_register = tc_get_register (0); |
| 16674 | demand_empty_rest_of_line (); |
| 16675 | } |
| 16676 | |
| 16677 | /* Handle the .cprestore pseudo-op. This stores $gp into a given |
| 16678 | offset from $sp. The offset is remembered, and after making a PIC |
| 16679 | call $gp is restored from that location. */ |
| 16680 | |
| 16681 | static void |
| 16682 | s_cprestore (int ignore ATTRIBUTE_UNUSED) |
| 16683 | { |
| 16684 | expressionS ex; |
| 16685 | |
| 16686 | /* If we are not generating SVR4 PIC code, or if this is NewABI code, |
| 16687 | .cprestore is ignored. */ |
| 16688 | if (mips_pic != SVR4_PIC || HAVE_NEWABI) |
| 16689 | { |
| 16690 | s_ignore (0); |
| 16691 | return; |
| 16692 | } |
| 16693 | |
| 16694 | if (mips_opts.mips16) |
| 16695 | { |
| 16696 | as_bad (_("%s not supported in MIPS16 mode"), ".cprestore"); |
| 16697 | ignore_rest_of_line (); |
| 16698 | return; |
| 16699 | } |
| 16700 | |
| 16701 | mips_cprestore_offset = get_absolute_expression (); |
| 16702 | mips_cprestore_valid = 1; |
| 16703 | |
| 16704 | ex.X_op = O_constant; |
| 16705 | ex.X_add_symbol = NULL; |
| 16706 | ex.X_op_symbol = NULL; |
| 16707 | ex.X_add_number = mips_cprestore_offset; |
| 16708 | |
| 16709 | macro_start (); |
| 16710 | macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register, |
| 16711 | SP, HAVE_64BIT_ADDRESSES); |
| 16712 | macro_end (); |
| 16713 | |
| 16714 | demand_empty_rest_of_line (); |
| 16715 | } |
| 16716 | |
| 16717 | /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset |
| 16718 | was given in the preceding .cpsetup, it results in: |
| 16719 | ld $gp, offset($sp) |
| 16720 | |
| 16721 | If a register $reg2 was given there, it results in: |
| 16722 | daddu $gp, $reg2, $0 */ |
| 16723 | |
| 16724 | static void |
| 16725 | s_cpreturn (int ignore ATTRIBUTE_UNUSED) |
| 16726 | { |
| 16727 | expressionS ex; |
| 16728 | |
| 16729 | /* If we are not generating SVR4 PIC code, .cpreturn is ignored. |
| 16730 | We also need NewABI support. */ |
| 16731 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) |
| 16732 | { |
| 16733 | s_ignore (0); |
| 16734 | return; |
| 16735 | } |
| 16736 | |
| 16737 | if (mips_opts.mips16) |
| 16738 | { |
| 16739 | as_bad (_("%s not supported in MIPS16 mode"), ".cpreturn"); |
| 16740 | ignore_rest_of_line (); |
| 16741 | return; |
| 16742 | } |
| 16743 | |
| 16744 | macro_start (); |
| 16745 | if (mips_cpreturn_register == -1) |
| 16746 | { |
| 16747 | ex.X_op = O_constant; |
| 16748 | ex.X_add_symbol = NULL; |
| 16749 | ex.X_op_symbol = NULL; |
| 16750 | ex.X_add_number = mips_cpreturn_offset; |
| 16751 | |
| 16752 | macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP); |
| 16753 | } |
| 16754 | else |
| 16755 | macro_build (NULL, "daddu", "d,v,t", mips_gp_register, |
| 16756 | mips_cpreturn_register, 0); |
| 16757 | macro_end (); |
| 16758 | |
| 16759 | demand_empty_rest_of_line (); |
| 16760 | } |
| 16761 | |
| 16762 | /* Handle a .dtprelword, .dtpreldword, .tprelword, or .tpreldword |
| 16763 | pseudo-op; DIRSTR says which. The pseudo-op generates a BYTES-size |
| 16764 | DTP- or TP-relative relocation of type RTYPE, for use in either DWARF |
| 16765 | debug information or MIPS16 TLS. */ |
| 16766 | |
| 16767 | static void |
| 16768 | s_tls_rel_directive (const size_t bytes, const char *dirstr, |
| 16769 | bfd_reloc_code_real_type rtype) |
| 16770 | { |
| 16771 | expressionS ex; |
| 16772 | char *p; |
| 16773 | |
| 16774 | expression (&ex); |
| 16775 | |
| 16776 | if (ex.X_op != O_symbol) |
| 16777 | { |
| 16778 | as_bad (_("Unsupported use of %s"), dirstr); |
| 16779 | ignore_rest_of_line (); |
| 16780 | } |
| 16781 | |
| 16782 | p = frag_more (bytes); |
| 16783 | md_number_to_chars (p, 0, bytes); |
| 16784 | fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE, rtype); |
| 16785 | demand_empty_rest_of_line (); |
| 16786 | mips_clear_insn_labels (); |
| 16787 | } |
| 16788 | |
| 16789 | /* Handle .dtprelword. */ |
| 16790 | |
| 16791 | static void |
| 16792 | s_dtprelword (int ignore ATTRIBUTE_UNUSED) |
| 16793 | { |
| 16794 | s_tls_rel_directive (4, ".dtprelword", BFD_RELOC_MIPS_TLS_DTPREL32); |
| 16795 | } |
| 16796 | |
| 16797 | /* Handle .dtpreldword. */ |
| 16798 | |
| 16799 | static void |
| 16800 | s_dtpreldword (int ignore ATTRIBUTE_UNUSED) |
| 16801 | { |
| 16802 | s_tls_rel_directive (8, ".dtpreldword", BFD_RELOC_MIPS_TLS_DTPREL64); |
| 16803 | } |
| 16804 | |
| 16805 | /* Handle .tprelword. */ |
| 16806 | |
| 16807 | static void |
| 16808 | s_tprelword (int ignore ATTRIBUTE_UNUSED) |
| 16809 | { |
| 16810 | s_tls_rel_directive (4, ".tprelword", BFD_RELOC_MIPS_TLS_TPREL32); |
| 16811 | } |
| 16812 | |
| 16813 | /* Handle .tpreldword. */ |
| 16814 | |
| 16815 | static void |
| 16816 | s_tpreldword (int ignore ATTRIBUTE_UNUSED) |
| 16817 | { |
| 16818 | s_tls_rel_directive (8, ".tpreldword", BFD_RELOC_MIPS_TLS_TPREL64); |
| 16819 | } |
| 16820 | |
| 16821 | /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC |
| 16822 | code. It sets the offset to use in gp_rel relocations. */ |
| 16823 | |
| 16824 | static void |
| 16825 | s_gpvalue (int ignore ATTRIBUTE_UNUSED) |
| 16826 | { |
| 16827 | /* If we are not generating SVR4 PIC code, .gpvalue is ignored. |
| 16828 | We also need NewABI support. */ |
| 16829 | if (mips_pic != SVR4_PIC || ! HAVE_NEWABI) |
| 16830 | { |
| 16831 | s_ignore (0); |
| 16832 | return; |
| 16833 | } |
| 16834 | |
| 16835 | mips_gprel_offset = get_absolute_expression (); |
| 16836 | |
| 16837 | demand_empty_rest_of_line (); |
| 16838 | } |
| 16839 | |
| 16840 | /* Handle the .gpword pseudo-op. This is used when generating PIC |
| 16841 | code. It generates a 32 bit GP relative reloc. */ |
| 16842 | |
| 16843 | static void |
| 16844 | s_gpword (int ignore ATTRIBUTE_UNUSED) |
| 16845 | { |
| 16846 | segment_info_type *si; |
| 16847 | struct insn_label_list *l; |
| 16848 | expressionS ex; |
| 16849 | char *p; |
| 16850 | |
| 16851 | /* When not generating PIC code, this is treated as .word. */ |
| 16852 | if (mips_pic != SVR4_PIC) |
| 16853 | { |
| 16854 | s_cons (2); |
| 16855 | return; |
| 16856 | } |
| 16857 | |
| 16858 | si = seg_info (now_seg); |
| 16859 | l = si->label_list; |
| 16860 | mips_emit_delays (); |
| 16861 | if (auto_align) |
| 16862 | mips_align (2, 0, l); |
| 16863 | |
| 16864 | expression (&ex); |
| 16865 | mips_clear_insn_labels (); |
| 16866 | |
| 16867 | if (ex.X_op != O_symbol || ex.X_add_number != 0) |
| 16868 | { |
| 16869 | as_bad (_("Unsupported use of .gpword")); |
| 16870 | ignore_rest_of_line (); |
| 16871 | } |
| 16872 | |
| 16873 | p = frag_more (4); |
| 16874 | md_number_to_chars (p, 0, 4); |
| 16875 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE, |
| 16876 | BFD_RELOC_GPREL32); |
| 16877 | |
| 16878 | demand_empty_rest_of_line (); |
| 16879 | } |
| 16880 | |
| 16881 | static void |
| 16882 | s_gpdword (int ignore ATTRIBUTE_UNUSED) |
| 16883 | { |
| 16884 | segment_info_type *si; |
| 16885 | struct insn_label_list *l; |
| 16886 | expressionS ex; |
| 16887 | char *p; |
| 16888 | |
| 16889 | /* When not generating PIC code, this is treated as .dword. */ |
| 16890 | if (mips_pic != SVR4_PIC) |
| 16891 | { |
| 16892 | s_cons (3); |
| 16893 | return; |
| 16894 | } |
| 16895 | |
| 16896 | si = seg_info (now_seg); |
| 16897 | l = si->label_list; |
| 16898 | mips_emit_delays (); |
| 16899 | if (auto_align) |
| 16900 | mips_align (3, 0, l); |
| 16901 | |
| 16902 | expression (&ex); |
| 16903 | mips_clear_insn_labels (); |
| 16904 | |
| 16905 | if (ex.X_op != O_symbol || ex.X_add_number != 0) |
| 16906 | { |
| 16907 | as_bad (_("Unsupported use of .gpdword")); |
| 16908 | ignore_rest_of_line (); |
| 16909 | } |
| 16910 | |
| 16911 | p = frag_more (8); |
| 16912 | md_number_to_chars (p, 0, 8); |
| 16913 | fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE, |
| 16914 | BFD_RELOC_GPREL32)->fx_tcbit = 1; |
| 16915 | |
| 16916 | /* GPREL32 composed with 64 gives a 64-bit GP offset. */ |
| 16917 | fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0, |
| 16918 | FALSE, BFD_RELOC_64)->fx_tcbit = 1; |
| 16919 | |
| 16920 | demand_empty_rest_of_line (); |
| 16921 | } |
| 16922 | |
| 16923 | /* Handle the .cpadd pseudo-op. This is used when dealing with switch |
| 16924 | tables in SVR4 PIC code. */ |
| 16925 | |
| 16926 | static void |
| 16927 | s_cpadd (int ignore ATTRIBUTE_UNUSED) |
| 16928 | { |
| 16929 | int reg; |
| 16930 | |
| 16931 | /* This is ignored when not generating SVR4 PIC code. */ |
| 16932 | if (mips_pic != SVR4_PIC) |
| 16933 | { |
| 16934 | s_ignore (0); |
| 16935 | return; |
| 16936 | } |
| 16937 | |
| 16938 | /* Add $gp to the register named as an argument. */ |
| 16939 | macro_start (); |
| 16940 | reg = tc_get_register (0); |
| 16941 | macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register); |
| 16942 | macro_end (); |
| 16943 | |
| 16944 | demand_empty_rest_of_line (); |
| 16945 | } |
| 16946 | |
| 16947 | /* Handle the .insn pseudo-op. This marks instruction labels in |
| 16948 | mips16/micromips mode. This permits the linker to handle them specially, |
| 16949 | such as generating jalx instructions when needed. We also make |
| 16950 | them odd for the duration of the assembly, in order to generate the |
| 16951 | right sort of code. We will make them even in the adjust_symtab |
| 16952 | routine, while leaving them marked. This is convenient for the |
| 16953 | debugger and the disassembler. The linker knows to make them odd |
| 16954 | again. */ |
| 16955 | |
| 16956 | static void |
| 16957 | s_insn (int ignore ATTRIBUTE_UNUSED) |
| 16958 | { |
| 16959 | mips_mark_labels (); |
| 16960 | |
| 16961 | demand_empty_rest_of_line (); |
| 16962 | } |
| 16963 | |
| 16964 | /* Handle a .stabn directive. We need these in order to mark a label |
| 16965 | as being a mips16 text label correctly. Sometimes the compiler |
| 16966 | will emit a label, followed by a .stabn, and then switch sections. |
| 16967 | If the label and .stabn are in mips16 mode, then the label is |
| 16968 | really a mips16 text label. */ |
| 16969 | |
| 16970 | static void |
| 16971 | s_mips_stab (int type) |
| 16972 | { |
| 16973 | if (type == 'n') |
| 16974 | mips_mark_labels (); |
| 16975 | |
| 16976 | s_stab (type); |
| 16977 | } |
| 16978 | |
| 16979 | /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */ |
| 16980 | |
| 16981 | static void |
| 16982 | s_mips_weakext (int ignore ATTRIBUTE_UNUSED) |
| 16983 | { |
| 16984 | char *name; |
| 16985 | int c; |
| 16986 | symbolS *symbolP; |
| 16987 | expressionS exp; |
| 16988 | |
| 16989 | name = input_line_pointer; |
| 16990 | c = get_symbol_end (); |
| 16991 | symbolP = symbol_find_or_make (name); |
| 16992 | S_SET_WEAK (symbolP); |
| 16993 | *input_line_pointer = c; |
| 16994 | |
| 16995 | SKIP_WHITESPACE (); |
| 16996 | |
| 16997 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) |
| 16998 | { |
| 16999 | if (S_IS_DEFINED (symbolP)) |
| 17000 | { |
| 17001 | as_bad (_("ignoring attempt to redefine symbol %s"), |
| 17002 | S_GET_NAME (symbolP)); |
| 17003 | ignore_rest_of_line (); |
| 17004 | return; |
| 17005 | } |
| 17006 | |
| 17007 | if (*input_line_pointer == ',') |
| 17008 | { |
| 17009 | ++input_line_pointer; |
| 17010 | SKIP_WHITESPACE (); |
| 17011 | } |
| 17012 | |
| 17013 | expression (&exp); |
| 17014 | if (exp.X_op != O_symbol) |
| 17015 | { |
| 17016 | as_bad (_("bad .weakext directive")); |
| 17017 | ignore_rest_of_line (); |
| 17018 | return; |
| 17019 | } |
| 17020 | symbol_set_value_expression (symbolP, &exp); |
| 17021 | } |
| 17022 | |
| 17023 | demand_empty_rest_of_line (); |
| 17024 | } |
| 17025 | |
| 17026 | /* Parse a register string into a number. Called from the ECOFF code |
| 17027 | to parse .frame. The argument is non-zero if this is the frame |
| 17028 | register, so that we can record it in mips_frame_reg. */ |
| 17029 | |
| 17030 | int |
| 17031 | tc_get_register (int frame) |
| 17032 | { |
| 17033 | unsigned int reg; |
| 17034 | |
| 17035 | SKIP_WHITESPACE (); |
| 17036 | if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®)) |
| 17037 | reg = 0; |
| 17038 | if (frame) |
| 17039 | { |
| 17040 | mips_frame_reg = reg != 0 ? reg : SP; |
| 17041 | mips_frame_reg_valid = 1; |
| 17042 | mips_cprestore_valid = 0; |
| 17043 | } |
| 17044 | return reg; |
| 17045 | } |
| 17046 | |
| 17047 | valueT |
| 17048 | md_section_align (asection *seg, valueT addr) |
| 17049 | { |
| 17050 | int align = bfd_get_section_alignment (stdoutput, seg); |
| 17051 | |
| 17052 | if (IS_ELF) |
| 17053 | { |
| 17054 | /* We don't need to align ELF sections to the full alignment. |
| 17055 | However, Irix 5 may prefer that we align them at least to a 16 |
| 17056 | byte boundary. We don't bother to align the sections if we |
| 17057 | are targeted for an embedded system. */ |
| 17058 | if (strncmp (TARGET_OS, "elf", 3) == 0) |
| 17059 | return addr; |
| 17060 | if (align > 4) |
| 17061 | align = 4; |
| 17062 | } |
| 17063 | |
| 17064 | return ((addr + (1 << align) - 1) & (-1 << align)); |
| 17065 | } |
| 17066 | |
| 17067 | /* Utility routine, called from above as well. If called while the |
| 17068 | input file is still being read, it's only an approximation. (For |
| 17069 | example, a symbol may later become defined which appeared to be |
| 17070 | undefined earlier.) */ |
| 17071 | |
| 17072 | static int |
| 17073 | nopic_need_relax (symbolS *sym, int before_relaxing) |
| 17074 | { |
| 17075 | if (sym == 0) |
| 17076 | return 0; |
| 17077 | |
| 17078 | if (g_switch_value > 0) |
| 17079 | { |
| 17080 | const char *symname; |
| 17081 | int change; |
| 17082 | |
| 17083 | /* Find out whether this symbol can be referenced off the $gp |
| 17084 | register. It can be if it is smaller than the -G size or if |
| 17085 | it is in the .sdata or .sbss section. Certain symbols can |
| 17086 | not be referenced off the $gp, although it appears as though |
| 17087 | they can. */ |
| 17088 | symname = S_GET_NAME (sym); |
| 17089 | if (symname != (const char *) NULL |
| 17090 | && (strcmp (symname, "eprol") == 0 |
| 17091 | || strcmp (symname, "etext") == 0 |
| 17092 | || strcmp (symname, "_gp") == 0 |
| 17093 | || strcmp (symname, "edata") == 0 |
| 17094 | || strcmp (symname, "_fbss") == 0 |
| 17095 | || strcmp (symname, "_fdata") == 0 |
| 17096 | || strcmp (symname, "_ftext") == 0 |
| 17097 | || strcmp (symname, "end") == 0 |
| 17098 | || strcmp (symname, "_gp_disp") == 0)) |
| 17099 | change = 1; |
| 17100 | else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym)) |
| 17101 | && (0 |
| 17102 | #ifndef NO_ECOFF_DEBUGGING |
| 17103 | || (symbol_get_obj (sym)->ecoff_extern_size != 0 |
| 17104 | && (symbol_get_obj (sym)->ecoff_extern_size |
| 17105 | <= g_switch_value)) |
| 17106 | #endif |
| 17107 | /* We must defer this decision until after the whole |
| 17108 | file has been read, since there might be a .extern |
| 17109 | after the first use of this symbol. */ |
| 17110 | || (before_relaxing |
| 17111 | #ifndef NO_ECOFF_DEBUGGING |
| 17112 | && symbol_get_obj (sym)->ecoff_extern_size == 0 |
| 17113 | #endif |
| 17114 | && S_GET_VALUE (sym) == 0) |
| 17115 | || (S_GET_VALUE (sym) != 0 |
| 17116 | && S_GET_VALUE (sym) <= g_switch_value))) |
| 17117 | change = 0; |
| 17118 | else |
| 17119 | { |
| 17120 | const char *segname; |
| 17121 | |
| 17122 | segname = segment_name (S_GET_SEGMENT (sym)); |
| 17123 | gas_assert (strcmp (segname, ".lit8") != 0 |
| 17124 | && strcmp (segname, ".lit4") != 0); |
| 17125 | change = (strcmp (segname, ".sdata") != 0 |
| 17126 | && strcmp (segname, ".sbss") != 0 |
| 17127 | && strncmp (segname, ".sdata.", 7) != 0 |
| 17128 | && strncmp (segname, ".sbss.", 6) != 0 |
| 17129 | && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0 |
| 17130 | && strncmp (segname, ".gnu.linkonce.s.", 16) != 0); |
| 17131 | } |
| 17132 | return change; |
| 17133 | } |
| 17134 | else |
| 17135 | /* We are not optimizing for the $gp register. */ |
| 17136 | return 1; |
| 17137 | } |
| 17138 | |
| 17139 | |
| 17140 | /* Return true if the given symbol should be considered local for SVR4 PIC. */ |
| 17141 | |
| 17142 | static bfd_boolean |
| 17143 | pic_need_relax (symbolS *sym, asection *segtype) |
| 17144 | { |
| 17145 | asection *symsec; |
| 17146 | |
| 17147 | /* Handle the case of a symbol equated to another symbol. */ |
| 17148 | while (symbol_equated_reloc_p (sym)) |
| 17149 | { |
| 17150 | symbolS *n; |
| 17151 | |
| 17152 | /* It's possible to get a loop here in a badly written program. */ |
| 17153 | n = symbol_get_value_expression (sym)->X_add_symbol; |
| 17154 | if (n == sym) |
| 17155 | break; |
| 17156 | sym = n; |
| 17157 | } |
| 17158 | |
| 17159 | if (symbol_section_p (sym)) |
| 17160 | return TRUE; |
| 17161 | |
| 17162 | symsec = S_GET_SEGMENT (sym); |
| 17163 | |
| 17164 | /* This must duplicate the test in adjust_reloc_syms. */ |
| 17165 | return (!bfd_is_und_section (symsec) |
| 17166 | && !bfd_is_abs_section (symsec) |
| 17167 | && !bfd_is_com_section (symsec) |
| 17168 | && !s_is_linkonce (sym, segtype) |
| 17169 | #ifdef OBJ_ELF |
| 17170 | /* A global or weak symbol is treated as external. */ |
| 17171 | && (!IS_ELF || (! S_IS_WEAK (sym) && ! S_IS_EXTERNAL (sym))) |
| 17172 | #endif |
| 17173 | ); |
| 17174 | } |
| 17175 | |
| 17176 | |
| 17177 | /* Given a mips16 variant frag FRAGP, return non-zero if it needs an |
| 17178 | extended opcode. SEC is the section the frag is in. */ |
| 17179 | |
| 17180 | static int |
| 17181 | mips16_extended_frag (fragS *fragp, asection *sec, long stretch) |
| 17182 | { |
| 17183 | int type; |
| 17184 | const struct mips16_immed_operand *op; |
| 17185 | offsetT val; |
| 17186 | int mintiny, maxtiny; |
| 17187 | segT symsec; |
| 17188 | fragS *sym_frag; |
| 17189 | |
| 17190 | if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) |
| 17191 | return 0; |
| 17192 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) |
| 17193 | return 1; |
| 17194 | |
| 17195 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); |
| 17196 | op = mips16_immed_operands; |
| 17197 | while (op->type != type) |
| 17198 | { |
| 17199 | ++op; |
| 17200 | gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED); |
| 17201 | } |
| 17202 | |
| 17203 | if (op->unsp) |
| 17204 | { |
| 17205 | if (type == '<' || type == '>' || type == '[' || type == ']') |
| 17206 | { |
| 17207 | mintiny = 1; |
| 17208 | maxtiny = 1 << op->nbits; |
| 17209 | } |
| 17210 | else |
| 17211 | { |
| 17212 | mintiny = 0; |
| 17213 | maxtiny = (1 << op->nbits) - 1; |
| 17214 | } |
| 17215 | } |
| 17216 | else |
| 17217 | { |
| 17218 | mintiny = - (1 << (op->nbits - 1)); |
| 17219 | maxtiny = (1 << (op->nbits - 1)) - 1; |
| 17220 | } |
| 17221 | |
| 17222 | sym_frag = symbol_get_frag (fragp->fr_symbol); |
| 17223 | val = S_GET_VALUE (fragp->fr_symbol); |
| 17224 | symsec = S_GET_SEGMENT (fragp->fr_symbol); |
| 17225 | |
| 17226 | if (op->pcrel) |
| 17227 | { |
| 17228 | addressT addr; |
| 17229 | |
| 17230 | /* We won't have the section when we are called from |
| 17231 | mips_relax_frag. However, we will always have been called |
| 17232 | from md_estimate_size_before_relax first. If this is a |
| 17233 | branch to a different section, we mark it as such. If SEC is |
| 17234 | NULL, and the frag is not marked, then it must be a branch to |
| 17235 | the same section. */ |
| 17236 | if (sec == NULL) |
| 17237 | { |
| 17238 | if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype)) |
| 17239 | return 1; |
| 17240 | } |
| 17241 | else |
| 17242 | { |
| 17243 | /* Must have been called from md_estimate_size_before_relax. */ |
| 17244 | if (symsec != sec) |
| 17245 | { |
| 17246 | fragp->fr_subtype = |
| 17247 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); |
| 17248 | |
| 17249 | /* FIXME: We should support this, and let the linker |
| 17250 | catch branches and loads that are out of range. */ |
| 17251 | as_bad_where (fragp->fr_file, fragp->fr_line, |
| 17252 | _("unsupported PC relative reference to different section")); |
| 17253 | |
| 17254 | return 1; |
| 17255 | } |
| 17256 | if (fragp != sym_frag && sym_frag->fr_address == 0) |
| 17257 | /* Assume non-extended on the first relaxation pass. |
| 17258 | The address we have calculated will be bogus if this is |
| 17259 | a forward branch to another frag, as the forward frag |
| 17260 | will have fr_address == 0. */ |
| 17261 | return 0; |
| 17262 | } |
| 17263 | |
| 17264 | /* In this case, we know for sure that the symbol fragment is in |
| 17265 | the same section. If the relax_marker of the symbol fragment |
| 17266 | differs from the relax_marker of this fragment, we have not |
| 17267 | yet adjusted the symbol fragment fr_address. We want to add |
| 17268 | in STRETCH in order to get a better estimate of the address. |
| 17269 | This particularly matters because of the shift bits. */ |
| 17270 | if (stretch != 0 |
| 17271 | && sym_frag->relax_marker != fragp->relax_marker) |
| 17272 | { |
| 17273 | fragS *f; |
| 17274 | |
| 17275 | /* Adjust stretch for any alignment frag. Note that if have |
| 17276 | been expanding the earlier code, the symbol may be |
| 17277 | defined in what appears to be an earlier frag. FIXME: |
| 17278 | This doesn't handle the fr_subtype field, which specifies |
| 17279 | a maximum number of bytes to skip when doing an |
| 17280 | alignment. */ |
| 17281 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) |
| 17282 | { |
| 17283 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) |
| 17284 | { |
| 17285 | if (stretch < 0) |
| 17286 | stretch = - ((- stretch) |
| 17287 | & ~ ((1 << (int) f->fr_offset) - 1)); |
| 17288 | else |
| 17289 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); |
| 17290 | if (stretch == 0) |
| 17291 | break; |
| 17292 | } |
| 17293 | } |
| 17294 | if (f != NULL) |
| 17295 | val += stretch; |
| 17296 | } |
| 17297 | |
| 17298 | addr = fragp->fr_address + fragp->fr_fix; |
| 17299 | |
| 17300 | /* The base address rules are complicated. The base address of |
| 17301 | a branch is the following instruction. The base address of a |
| 17302 | PC relative load or add is the instruction itself, but if it |
| 17303 | is in a delay slot (in which case it can not be extended) use |
| 17304 | the address of the instruction whose delay slot it is in. */ |
| 17305 | if (type == 'p' || type == 'q') |
| 17306 | { |
| 17307 | addr += 2; |
| 17308 | |
| 17309 | /* If we are currently assuming that this frag should be |
| 17310 | extended, then, the current address is two bytes |
| 17311 | higher. */ |
| 17312 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
| 17313 | addr += 2; |
| 17314 | |
| 17315 | /* Ignore the low bit in the target, since it will be set |
| 17316 | for a text label. */ |
| 17317 | if ((val & 1) != 0) |
| 17318 | --val; |
| 17319 | } |
| 17320 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) |
| 17321 | addr -= 4; |
| 17322 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) |
| 17323 | addr -= 2; |
| 17324 | |
| 17325 | val -= addr & ~ ((1 << op->shift) - 1); |
| 17326 | |
| 17327 | /* Branch offsets have an implicit 0 in the lowest bit. */ |
| 17328 | if (type == 'p' || type == 'q') |
| 17329 | val /= 2; |
| 17330 | |
| 17331 | /* If any of the shifted bits are set, we must use an extended |
| 17332 | opcode. If the address depends on the size of this |
| 17333 | instruction, this can lead to a loop, so we arrange to always |
| 17334 | use an extended opcode. We only check this when we are in |
| 17335 | the main relaxation loop, when SEC is NULL. */ |
| 17336 | if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL) |
| 17337 | { |
| 17338 | fragp->fr_subtype = |
| 17339 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); |
| 17340 | return 1; |
| 17341 | } |
| 17342 | |
| 17343 | /* If we are about to mark a frag as extended because the value |
| 17344 | is precisely maxtiny + 1, then there is a chance of an |
| 17345 | infinite loop as in the following code: |
| 17346 | la $4,foo |
| 17347 | .skip 1020 |
| 17348 | .align 2 |
| 17349 | foo: |
| 17350 | In this case when the la is extended, foo is 0x3fc bytes |
| 17351 | away, so the la can be shrunk, but then foo is 0x400 away, so |
| 17352 | the la must be extended. To avoid this loop, we mark the |
| 17353 | frag as extended if it was small, and is about to become |
| 17354 | extended with a value of maxtiny + 1. */ |
| 17355 | if (val == ((maxtiny + 1) << op->shift) |
| 17356 | && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype) |
| 17357 | && sec == NULL) |
| 17358 | { |
| 17359 | fragp->fr_subtype = |
| 17360 | RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype); |
| 17361 | return 1; |
| 17362 | } |
| 17363 | } |
| 17364 | else if (symsec != absolute_section && sec != NULL) |
| 17365 | as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation")); |
| 17366 | |
| 17367 | if ((val & ((1 << op->shift) - 1)) != 0 |
| 17368 | || val < (mintiny << op->shift) |
| 17369 | || val > (maxtiny << op->shift)) |
| 17370 | return 1; |
| 17371 | else |
| 17372 | return 0; |
| 17373 | } |
| 17374 | |
| 17375 | /* Compute the length of a branch sequence, and adjust the |
| 17376 | RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the |
| 17377 | worst-case length is computed, with UPDATE being used to indicate |
| 17378 | whether an unconditional (-1), branch-likely (+1) or regular (0) |
| 17379 | branch is to be computed. */ |
| 17380 | static int |
| 17381 | relaxed_branch_length (fragS *fragp, asection *sec, int update) |
| 17382 | { |
| 17383 | bfd_boolean toofar; |
| 17384 | int length; |
| 17385 | |
| 17386 | if (fragp |
| 17387 | && S_IS_DEFINED (fragp->fr_symbol) |
| 17388 | && sec == S_GET_SEGMENT (fragp->fr_symbol)) |
| 17389 | { |
| 17390 | addressT addr; |
| 17391 | offsetT val; |
| 17392 | |
| 17393 | val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; |
| 17394 | |
| 17395 | addr = fragp->fr_address + fragp->fr_fix + 4; |
| 17396 | |
| 17397 | val -= addr; |
| 17398 | |
| 17399 | toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2); |
| 17400 | } |
| 17401 | else if (fragp) |
| 17402 | /* If the symbol is not defined or it's in a different segment, |
| 17403 | assume the user knows what's going on and emit a short |
| 17404 | branch. */ |
| 17405 | toofar = FALSE; |
| 17406 | else |
| 17407 | toofar = TRUE; |
| 17408 | |
| 17409 | if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype)) |
| 17410 | fragp->fr_subtype |
| 17411 | = RELAX_BRANCH_ENCODE (RELAX_BRANCH_AT (fragp->fr_subtype), |
| 17412 | RELAX_BRANCH_UNCOND (fragp->fr_subtype), |
| 17413 | RELAX_BRANCH_LIKELY (fragp->fr_subtype), |
| 17414 | RELAX_BRANCH_LINK (fragp->fr_subtype), |
| 17415 | toofar); |
| 17416 | |
| 17417 | length = 4; |
| 17418 | if (toofar) |
| 17419 | { |
| 17420 | if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0)) |
| 17421 | length += 8; |
| 17422 | |
| 17423 | if (mips_pic != NO_PIC) |
| 17424 | { |
| 17425 | /* Additional space for PIC loading of target address. */ |
| 17426 | length += 8; |
| 17427 | if (mips_opts.isa == ISA_MIPS1) |
| 17428 | /* Additional space for $at-stabilizing nop. */ |
| 17429 | length += 4; |
| 17430 | } |
| 17431 | |
| 17432 | /* If branch is conditional. */ |
| 17433 | if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0)) |
| 17434 | length += 8; |
| 17435 | } |
| 17436 | |
| 17437 | return length; |
| 17438 | } |
| 17439 | |
| 17440 | /* Compute the length of a branch sequence, and adjust the |
| 17441 | RELAX_MICROMIPS_TOOFAR32 bit accordingly. If FRAGP is NULL, the |
| 17442 | worst-case length is computed, with UPDATE being used to indicate |
| 17443 | whether an unconditional (-1), or regular (0) branch is to be |
| 17444 | computed. */ |
| 17445 | |
| 17446 | static int |
| 17447 | relaxed_micromips_32bit_branch_length (fragS *fragp, asection *sec, int update) |
| 17448 | { |
| 17449 | bfd_boolean toofar; |
| 17450 | int length; |
| 17451 | |
| 17452 | if (fragp |
| 17453 | && S_IS_DEFINED (fragp->fr_symbol) |
| 17454 | && sec == S_GET_SEGMENT (fragp->fr_symbol)) |
| 17455 | { |
| 17456 | addressT addr; |
| 17457 | offsetT val; |
| 17458 | |
| 17459 | val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; |
| 17460 | /* Ignore the low bit in the target, since it will be set |
| 17461 | for a text label. */ |
| 17462 | if ((val & 1) != 0) |
| 17463 | --val; |
| 17464 | |
| 17465 | addr = fragp->fr_address + fragp->fr_fix + 4; |
| 17466 | |
| 17467 | val -= addr; |
| 17468 | |
| 17469 | toofar = val < - (0x8000 << 1) || val >= (0x8000 << 1); |
| 17470 | } |
| 17471 | else if (fragp) |
| 17472 | /* If the symbol is not defined or it's in a different segment, |
| 17473 | assume the user knows what's going on and emit a short |
| 17474 | branch. */ |
| 17475 | toofar = FALSE; |
| 17476 | else |
| 17477 | toofar = TRUE; |
| 17478 | |
| 17479 | if (fragp && update |
| 17480 | && toofar != RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype)) |
| 17481 | fragp->fr_subtype = (toofar |
| 17482 | ? RELAX_MICROMIPS_MARK_TOOFAR32 (fragp->fr_subtype) |
| 17483 | : RELAX_MICROMIPS_CLEAR_TOOFAR32 (fragp->fr_subtype)); |
| 17484 | |
| 17485 | length = 4; |
| 17486 | if (toofar) |
| 17487 | { |
| 17488 | bfd_boolean compact_known = fragp != NULL; |
| 17489 | bfd_boolean compact = FALSE; |
| 17490 | bfd_boolean uncond; |
| 17491 | |
| 17492 | if (compact_known) |
| 17493 | compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype); |
| 17494 | if (fragp) |
| 17495 | uncond = RELAX_MICROMIPS_UNCOND (fragp->fr_subtype); |
| 17496 | else |
| 17497 | uncond = update < 0; |
| 17498 | |
| 17499 | /* If label is out of range, we turn branch <br>: |
| 17500 | |
| 17501 | <br> label # 4 bytes |
| 17502 | 0: |
| 17503 | |
| 17504 | into: |
| 17505 | |
| 17506 | j label # 4 bytes |
| 17507 | nop # 2 bytes if compact && !PIC |
| 17508 | 0: |
| 17509 | */ |
| 17510 | if (mips_pic == NO_PIC && (!compact_known || compact)) |
| 17511 | length += 2; |
| 17512 | |
| 17513 | /* If assembling PIC code, we further turn: |
| 17514 | |
| 17515 | j label # 4 bytes |
| 17516 | |
| 17517 | into: |
| 17518 | |
| 17519 | lw/ld at, %got(label)(gp) # 4 bytes |
| 17520 | d/addiu at, %lo(label) # 4 bytes |
| 17521 | jr/c at # 2 bytes |
| 17522 | */ |
| 17523 | if (mips_pic != NO_PIC) |
| 17524 | length += 6; |
| 17525 | |
| 17526 | /* If branch <br> is conditional, we prepend negated branch <brneg>: |
| 17527 | |
| 17528 | <brneg> 0f # 4 bytes |
| 17529 | nop # 2 bytes if !compact |
| 17530 | */ |
| 17531 | if (!uncond) |
| 17532 | length += (compact_known && compact) ? 4 : 6; |
| 17533 | } |
| 17534 | |
| 17535 | return length; |
| 17536 | } |
| 17537 | |
| 17538 | /* Compute the length of a branch, and adjust the RELAX_MICROMIPS_TOOFAR16 |
| 17539 | bit accordingly. */ |
| 17540 | |
| 17541 | static int |
| 17542 | relaxed_micromips_16bit_branch_length (fragS *fragp, asection *sec, int update) |
| 17543 | { |
| 17544 | bfd_boolean toofar; |
| 17545 | |
| 17546 | if (fragp |
| 17547 | && S_IS_DEFINED (fragp->fr_symbol) |
| 17548 | && sec == S_GET_SEGMENT (fragp->fr_symbol)) |
| 17549 | { |
| 17550 | addressT addr; |
| 17551 | offsetT val; |
| 17552 | int type; |
| 17553 | |
| 17554 | val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; |
| 17555 | /* Ignore the low bit in the target, since it will be set |
| 17556 | for a text label. */ |
| 17557 | if ((val & 1) != 0) |
| 17558 | --val; |
| 17559 | |
| 17560 | /* Assume this is a 2-byte branch. */ |
| 17561 | addr = fragp->fr_address + fragp->fr_fix + 2; |
| 17562 | |
| 17563 | /* We try to avoid the infinite loop by not adding 2 more bytes for |
| 17564 | long branches. */ |
| 17565 | |
| 17566 | val -= addr; |
| 17567 | |
| 17568 | type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype); |
| 17569 | if (type == 'D') |
| 17570 | toofar = val < - (0x200 << 1) || val >= (0x200 << 1); |
| 17571 | else if (type == 'E') |
| 17572 | toofar = val < - (0x40 << 1) || val >= (0x40 << 1); |
| 17573 | else |
| 17574 | abort (); |
| 17575 | } |
| 17576 | else |
| 17577 | /* If the symbol is not defined or it's in a different segment, |
| 17578 | we emit a normal 32-bit branch. */ |
| 17579 | toofar = TRUE; |
| 17580 | |
| 17581 | if (fragp && update |
| 17582 | && toofar != RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype)) |
| 17583 | fragp->fr_subtype |
| 17584 | = toofar ? RELAX_MICROMIPS_MARK_TOOFAR16 (fragp->fr_subtype) |
| 17585 | : RELAX_MICROMIPS_CLEAR_TOOFAR16 (fragp->fr_subtype); |
| 17586 | |
| 17587 | if (toofar) |
| 17588 | return 4; |
| 17589 | |
| 17590 | return 2; |
| 17591 | } |
| 17592 | |
| 17593 | /* Estimate the size of a frag before relaxing. Unless this is the |
| 17594 | mips16, we are not really relaxing here, and the final size is |
| 17595 | encoded in the subtype information. For the mips16, we have to |
| 17596 | decide whether we are using an extended opcode or not. */ |
| 17597 | |
| 17598 | int |
| 17599 | md_estimate_size_before_relax (fragS *fragp, asection *segtype) |
| 17600 | { |
| 17601 | int change; |
| 17602 | |
| 17603 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
| 17604 | { |
| 17605 | |
| 17606 | fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE); |
| 17607 | |
| 17608 | return fragp->fr_var; |
| 17609 | } |
| 17610 | |
| 17611 | if (RELAX_MIPS16_P (fragp->fr_subtype)) |
| 17612 | /* We don't want to modify the EXTENDED bit here; it might get us |
| 17613 | into infinite loops. We change it only in mips_relax_frag(). */ |
| 17614 | return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2); |
| 17615 | |
| 17616 | if (RELAX_MICROMIPS_P (fragp->fr_subtype)) |
| 17617 | { |
| 17618 | int length = 4; |
| 17619 | |
| 17620 | if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0) |
| 17621 | length = relaxed_micromips_16bit_branch_length (fragp, segtype, FALSE); |
| 17622 | if (length == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)) |
| 17623 | length = relaxed_micromips_32bit_branch_length (fragp, segtype, FALSE); |
| 17624 | fragp->fr_var = length; |
| 17625 | |
| 17626 | return length; |
| 17627 | } |
| 17628 | |
| 17629 | if (mips_pic == NO_PIC) |
| 17630 | change = nopic_need_relax (fragp->fr_symbol, 0); |
| 17631 | else if (mips_pic == SVR4_PIC) |
| 17632 | change = pic_need_relax (fragp->fr_symbol, segtype); |
| 17633 | else if (mips_pic == VXWORKS_PIC) |
| 17634 | /* For vxworks, GOT16 relocations never have a corresponding LO16. */ |
| 17635 | change = 0; |
| 17636 | else |
| 17637 | abort (); |
| 17638 | |
| 17639 | if (change) |
| 17640 | { |
| 17641 | fragp->fr_subtype |= RELAX_USE_SECOND; |
| 17642 | return -RELAX_FIRST (fragp->fr_subtype); |
| 17643 | } |
| 17644 | else |
| 17645 | return -RELAX_SECOND (fragp->fr_subtype); |
| 17646 | } |
| 17647 | |
| 17648 | /* This is called to see whether a reloc against a defined symbol |
| 17649 | should be converted into a reloc against a section. */ |
| 17650 | |
| 17651 | int |
| 17652 | mips_fix_adjustable (fixS *fixp) |
| 17653 | { |
| 17654 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
| 17655 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
| 17656 | return 0; |
| 17657 | |
| 17658 | if (fixp->fx_addsy == NULL) |
| 17659 | return 1; |
| 17660 | |
| 17661 | /* If symbol SYM is in a mergeable section, relocations of the form |
| 17662 | SYM + 0 can usually be made section-relative. The mergeable data |
| 17663 | is then identified by the section offset rather than by the symbol. |
| 17664 | |
| 17665 | However, if we're generating REL LO16 relocations, the offset is split |
| 17666 | between the LO16 and parterning high part relocation. The linker will |
| 17667 | need to recalculate the complete offset in order to correctly identify |
| 17668 | the merge data. |
| 17669 | |
| 17670 | The linker has traditionally not looked for the parterning high part |
| 17671 | relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be |
| 17672 | placed anywhere. Rather than break backwards compatibility by changing |
| 17673 | this, it seems better not to force the issue, and instead keep the |
| 17674 | original symbol. This will work with either linker behavior. */ |
| 17675 | if ((lo16_reloc_p (fixp->fx_r_type) |
| 17676 | || reloc_needs_lo_p (fixp->fx_r_type)) |
| 17677 | && HAVE_IN_PLACE_ADDENDS |
| 17678 | && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0) |
| 17679 | return 0; |
| 17680 | |
| 17681 | /* There is no place to store an in-place offset for JALR relocations. |
| 17682 | Likewise an in-range offset of PC-relative relocations may overflow |
| 17683 | the in-place relocatable field if recalculated against the start |
| 17684 | address of the symbol's containing section. */ |
| 17685 | if (HAVE_IN_PLACE_ADDENDS |
| 17686 | && (fixp->fx_pcrel || jalr_reloc_p (fixp->fx_r_type))) |
| 17687 | return 0; |
| 17688 | |
| 17689 | #ifdef OBJ_ELF |
| 17690 | /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve |
| 17691 | to a floating-point stub. The same is true for non-R_MIPS16_26 |
| 17692 | relocations against MIPS16 functions; in this case, the stub becomes |
| 17693 | the function's canonical address. |
| 17694 | |
| 17695 | Floating-point stubs are stored in unique .mips16.call.* or |
| 17696 | .mips16.fn.* sections. If a stub T for function F is in section S, |
| 17697 | the first relocation in section S must be against F; this is how the |
| 17698 | linker determines the target function. All relocations that might |
| 17699 | resolve to T must also be against F. We therefore have the following |
| 17700 | restrictions, which are given in an intentionally-redundant way: |
| 17701 | |
| 17702 | 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16 |
| 17703 | symbols. |
| 17704 | |
| 17705 | 2. We cannot reduce a stub's relocations against non-MIPS16 symbols |
| 17706 | if that stub might be used. |
| 17707 | |
| 17708 | 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16 |
| 17709 | symbols. |
| 17710 | |
| 17711 | 4. We cannot reduce a stub's relocations against MIPS16 symbols if |
| 17712 | that stub might be used. |
| 17713 | |
| 17714 | There is a further restriction: |
| 17715 | |
| 17716 | 5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or |
| 17717 | R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols on |
| 17718 | targets with in-place addends; the relocation field cannot |
| 17719 | encode the low bit. |
| 17720 | |
| 17721 | For simplicity, we deal with (3)-(4) by not reducing _any_ relocation |
| 17722 | against a MIPS16 symbol. We deal with (5) by by not reducing any |
| 17723 | such relocations on REL targets. |
| 17724 | |
| 17725 | We deal with (1)-(2) by saying that, if there's a R_MIPS16_26 |
| 17726 | relocation against some symbol R, no relocation against R may be |
| 17727 | reduced. (Note that this deals with (2) as well as (1) because |
| 17728 | relocations against global symbols will never be reduced on ELF |
| 17729 | targets.) This approach is a little simpler than trying to detect |
| 17730 | stub sections, and gives the "all or nothing" per-symbol consistency |
| 17731 | that we have for MIPS16 symbols. */ |
| 17732 | if (IS_ELF |
| 17733 | && fixp->fx_subsy == NULL |
| 17734 | && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy)) |
| 17735 | || *symbol_get_tc (fixp->fx_addsy) |
| 17736 | || (HAVE_IN_PLACE_ADDENDS |
| 17737 | && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy)) |
| 17738 | && jmp_reloc_p (fixp->fx_r_type)))) |
| 17739 | return 0; |
| 17740 | #endif |
| 17741 | |
| 17742 | return 1; |
| 17743 | } |
| 17744 | |
| 17745 | /* Translate internal representation of relocation info to BFD target |
| 17746 | format. */ |
| 17747 | |
| 17748 | arelent ** |
| 17749 | tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp) |
| 17750 | { |
| 17751 | static arelent *retval[4]; |
| 17752 | arelent *reloc; |
| 17753 | bfd_reloc_code_real_type code; |
| 17754 | |
| 17755 | memset (retval, 0, sizeof(retval)); |
| 17756 | reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent)); |
| 17757 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
| 17758 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
| 17759 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
| 17760 | |
| 17761 | if (fixp->fx_pcrel) |
| 17762 | { |
| 17763 | gas_assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2 |
| 17764 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1 |
| 17765 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1 |
| 17766 | || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1); |
| 17767 | |
| 17768 | /* At this point, fx_addnumber is "symbol offset - pcrel address". |
| 17769 | Relocations want only the symbol offset. */ |
| 17770 | reloc->addend = fixp->fx_addnumber + reloc->address; |
| 17771 | if (!IS_ELF) |
| 17772 | { |
| 17773 | /* A gruesome hack which is a result of the gruesome gas |
| 17774 | reloc handling. What's worse, for COFF (as opposed to |
| 17775 | ECOFF), we might need yet another copy of reloc->address. |
| 17776 | See bfd_install_relocation. */ |
| 17777 | reloc->addend += reloc->address; |
| 17778 | } |
| 17779 | } |
| 17780 | else |
| 17781 | reloc->addend = fixp->fx_addnumber; |
| 17782 | |
| 17783 | /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable |
| 17784 | entry to be used in the relocation's section offset. */ |
| 17785 | if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
| 17786 | { |
| 17787 | reloc->address = reloc->addend; |
| 17788 | reloc->addend = 0; |
| 17789 | } |
| 17790 | |
| 17791 | code = fixp->fx_r_type; |
| 17792 | |
| 17793 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
| 17794 | if (reloc->howto == NULL) |
| 17795 | { |
| 17796 | as_bad_where (fixp->fx_file, fixp->fx_line, |
| 17797 | _("Can not represent %s relocation in this object file format"), |
| 17798 | bfd_get_reloc_code_name (code)); |
| 17799 | retval[0] = NULL; |
| 17800 | } |
| 17801 | |
| 17802 | return retval; |
| 17803 | } |
| 17804 | |
| 17805 | /* Relax a machine dependent frag. This returns the amount by which |
| 17806 | the current size of the frag should change. */ |
| 17807 | |
| 17808 | int |
| 17809 | mips_relax_frag (asection *sec, fragS *fragp, long stretch) |
| 17810 | { |
| 17811 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
| 17812 | { |
| 17813 | offsetT old_var = fragp->fr_var; |
| 17814 | |
| 17815 | fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE); |
| 17816 | |
| 17817 | return fragp->fr_var - old_var; |
| 17818 | } |
| 17819 | |
| 17820 | if (RELAX_MICROMIPS_P (fragp->fr_subtype)) |
| 17821 | { |
| 17822 | offsetT old_var = fragp->fr_var; |
| 17823 | offsetT new_var = 4; |
| 17824 | |
| 17825 | if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0) |
| 17826 | new_var = relaxed_micromips_16bit_branch_length (fragp, sec, TRUE); |
| 17827 | if (new_var == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)) |
| 17828 | new_var = relaxed_micromips_32bit_branch_length (fragp, sec, TRUE); |
| 17829 | fragp->fr_var = new_var; |
| 17830 | |
| 17831 | return new_var - old_var; |
| 17832 | } |
| 17833 | |
| 17834 | if (! RELAX_MIPS16_P (fragp->fr_subtype)) |
| 17835 | return 0; |
| 17836 | |
| 17837 | if (mips16_extended_frag (fragp, NULL, stretch)) |
| 17838 | { |
| 17839 | if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
| 17840 | return 0; |
| 17841 | fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype); |
| 17842 | return 2; |
| 17843 | } |
| 17844 | else |
| 17845 | { |
| 17846 | if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)) |
| 17847 | return 0; |
| 17848 | fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype); |
| 17849 | return -2; |
| 17850 | } |
| 17851 | |
| 17852 | return 0; |
| 17853 | } |
| 17854 | |
| 17855 | /* Convert a machine dependent frag. */ |
| 17856 | |
| 17857 | void |
| 17858 | md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp) |
| 17859 | { |
| 17860 | if (RELAX_BRANCH_P (fragp->fr_subtype)) |
| 17861 | { |
| 17862 | char *buf; |
| 17863 | unsigned long insn; |
| 17864 | expressionS exp; |
| 17865 | fixS *fixp; |
| 17866 | |
| 17867 | buf = fragp->fr_literal + fragp->fr_fix; |
| 17868 | insn = read_insn (buf); |
| 17869 | |
| 17870 | if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype)) |
| 17871 | { |
| 17872 | /* We generate a fixup instead of applying it right now |
| 17873 | because, if there are linker relaxations, we're going to |
| 17874 | need the relocations. */ |
| 17875 | exp.X_op = O_symbol; |
| 17876 | exp.X_add_symbol = fragp->fr_symbol; |
| 17877 | exp.X_add_number = fragp->fr_offset; |
| 17878 | |
| 17879 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE, |
| 17880 | BFD_RELOC_16_PCREL_S2); |
| 17881 | fixp->fx_file = fragp->fr_file; |
| 17882 | fixp->fx_line = fragp->fr_line; |
| 17883 | |
| 17884 | buf = write_insn (buf, insn); |
| 17885 | } |
| 17886 | else |
| 17887 | { |
| 17888 | int i; |
| 17889 | |
| 17890 | as_warn_where (fragp->fr_file, fragp->fr_line, |
| 17891 | _("Relaxed out-of-range branch into a jump")); |
| 17892 | |
| 17893 | if (RELAX_BRANCH_UNCOND (fragp->fr_subtype)) |
| 17894 | goto uncond; |
| 17895 | |
| 17896 | if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype)) |
| 17897 | { |
| 17898 | /* Reverse the branch. */ |
| 17899 | switch ((insn >> 28) & 0xf) |
| 17900 | { |
| 17901 | case 4: |
| 17902 | /* bc[0-3][tf]l? and bc1any[24][ft] instructions can |
| 17903 | have the condition reversed by tweaking a single |
| 17904 | bit, and their opcodes all have 0x4???????. */ |
| 17905 | gas_assert ((insn & 0xf1000000) == 0x41000000); |
| 17906 | insn ^= 0x00010000; |
| 17907 | break; |
| 17908 | |
| 17909 | case 0: |
| 17910 | /* bltz 0x04000000 bgez 0x04010000 |
| 17911 | bltzal 0x04100000 bgezal 0x04110000 */ |
| 17912 | gas_assert ((insn & 0xfc0e0000) == 0x04000000); |
| 17913 | insn ^= 0x00010000; |
| 17914 | break; |
| 17915 | |
| 17916 | case 1: |
| 17917 | /* beq 0x10000000 bne 0x14000000 |
| 17918 | blez 0x18000000 bgtz 0x1c000000 */ |
| 17919 | insn ^= 0x04000000; |
| 17920 | break; |
| 17921 | |
| 17922 | default: |
| 17923 | abort (); |
| 17924 | } |
| 17925 | } |
| 17926 | |
| 17927 | if (RELAX_BRANCH_LINK (fragp->fr_subtype)) |
| 17928 | { |
| 17929 | /* Clear the and-link bit. */ |
| 17930 | gas_assert ((insn & 0xfc1c0000) == 0x04100000); |
| 17931 | |
| 17932 | /* bltzal 0x04100000 bgezal 0x04110000 |
| 17933 | bltzall 0x04120000 bgezall 0x04130000 */ |
| 17934 | insn &= ~0x00100000; |
| 17935 | } |
| 17936 | |
| 17937 | /* Branch over the branch (if the branch was likely) or the |
| 17938 | full jump (not likely case). Compute the offset from the |
| 17939 | current instruction to branch to. */ |
| 17940 | if (RELAX_BRANCH_LIKELY (fragp->fr_subtype)) |
| 17941 | i = 16; |
| 17942 | else |
| 17943 | { |
| 17944 | /* How many bytes in instructions we've already emitted? */ |
| 17945 | i = buf - fragp->fr_literal - fragp->fr_fix; |
| 17946 | /* How many bytes in instructions from here to the end? */ |
| 17947 | i = fragp->fr_var - i; |
| 17948 | } |
| 17949 | /* Convert to instruction count. */ |
| 17950 | i >>= 2; |
| 17951 | /* Branch counts from the next instruction. */ |
| 17952 | i--; |
| 17953 | insn |= i; |
| 17954 | /* Branch over the jump. */ |
| 17955 | buf = write_insn (buf, insn); |
| 17956 | |
| 17957 | /* nop */ |
| 17958 | buf = write_insn (buf, 0); |
| 17959 | |
| 17960 | if (RELAX_BRANCH_LIKELY (fragp->fr_subtype)) |
| 17961 | { |
| 17962 | /* beql $0, $0, 2f */ |
| 17963 | insn = 0x50000000; |
| 17964 | /* Compute the PC offset from the current instruction to |
| 17965 | the end of the variable frag. */ |
| 17966 | /* How many bytes in instructions we've already emitted? */ |
| 17967 | i = buf - fragp->fr_literal - fragp->fr_fix; |
| 17968 | /* How many bytes in instructions from here to the end? */ |
| 17969 | i = fragp->fr_var - i; |
| 17970 | /* Convert to instruction count. */ |
| 17971 | i >>= 2; |
| 17972 | /* Don't decrement i, because we want to branch over the |
| 17973 | delay slot. */ |
| 17974 | insn |= i; |
| 17975 | |
| 17976 | buf = write_insn (buf, insn); |
| 17977 | buf = write_insn (buf, 0); |
| 17978 | } |
| 17979 | |
| 17980 | uncond: |
| 17981 | if (mips_pic == NO_PIC) |
| 17982 | { |
| 17983 | /* j or jal. */ |
| 17984 | insn = (RELAX_BRANCH_LINK (fragp->fr_subtype) |
| 17985 | ? 0x0c000000 : 0x08000000); |
| 17986 | exp.X_op = O_symbol; |
| 17987 | exp.X_add_symbol = fragp->fr_symbol; |
| 17988 | exp.X_add_number = fragp->fr_offset; |
| 17989 | |
| 17990 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, |
| 17991 | FALSE, BFD_RELOC_MIPS_JMP); |
| 17992 | fixp->fx_file = fragp->fr_file; |
| 17993 | fixp->fx_line = fragp->fr_line; |
| 17994 | |
| 17995 | buf = write_insn (buf, insn); |
| 17996 | } |
| 17997 | else |
| 17998 | { |
| 17999 | unsigned long at = RELAX_BRANCH_AT (fragp->fr_subtype); |
| 18000 | |
| 18001 | /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */ |
| 18002 | insn = HAVE_64BIT_ADDRESSES ? 0xdf800000 : 0x8f800000; |
| 18003 | insn |= at << OP_SH_RT; |
| 18004 | exp.X_op = O_symbol; |
| 18005 | exp.X_add_symbol = fragp->fr_symbol; |
| 18006 | exp.X_add_number = fragp->fr_offset; |
| 18007 | |
| 18008 | if (fragp->fr_offset) |
| 18009 | { |
| 18010 | exp.X_add_symbol = make_expr_symbol (&exp); |
| 18011 | exp.X_add_number = 0; |
| 18012 | } |
| 18013 | |
| 18014 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, |
| 18015 | FALSE, BFD_RELOC_MIPS_GOT16); |
| 18016 | fixp->fx_file = fragp->fr_file; |
| 18017 | fixp->fx_line = fragp->fr_line; |
| 18018 | |
| 18019 | buf = write_insn (buf, insn); |
| 18020 | |
| 18021 | if (mips_opts.isa == ISA_MIPS1) |
| 18022 | /* nop */ |
| 18023 | buf = write_insn (buf, 0); |
| 18024 | |
| 18025 | /* d/addiu $at, $at, <sym> R_MIPS_LO16 */ |
| 18026 | insn = HAVE_64BIT_ADDRESSES ? 0x64000000 : 0x24000000; |
| 18027 | insn |= at << OP_SH_RS | at << OP_SH_RT; |
| 18028 | |
| 18029 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, |
| 18030 | FALSE, BFD_RELOC_LO16); |
| 18031 | fixp->fx_file = fragp->fr_file; |
| 18032 | fixp->fx_line = fragp->fr_line; |
| 18033 | |
| 18034 | buf = write_insn (buf, insn); |
| 18035 | |
| 18036 | /* j(al)r $at. */ |
| 18037 | if (RELAX_BRANCH_LINK (fragp->fr_subtype)) |
| 18038 | insn = 0x0000f809; |
| 18039 | else |
| 18040 | insn = 0x00000008; |
| 18041 | insn |= at << OP_SH_RS; |
| 18042 | |
| 18043 | buf = write_insn (buf, insn); |
| 18044 | } |
| 18045 | } |
| 18046 | |
| 18047 | fragp->fr_fix += fragp->fr_var; |
| 18048 | gas_assert (buf == fragp->fr_literal + fragp->fr_fix); |
| 18049 | return; |
| 18050 | } |
| 18051 | |
| 18052 | /* Relax microMIPS branches. */ |
| 18053 | if (RELAX_MICROMIPS_P (fragp->fr_subtype)) |
| 18054 | { |
| 18055 | char *buf = fragp->fr_literal + fragp->fr_fix; |
| 18056 | bfd_boolean compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype); |
| 18057 | bfd_boolean al = RELAX_MICROMIPS_LINK (fragp->fr_subtype); |
| 18058 | int type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype); |
| 18059 | bfd_boolean short_ds; |
| 18060 | unsigned long insn; |
| 18061 | expressionS exp; |
| 18062 | fixS *fixp; |
| 18063 | |
| 18064 | exp.X_op = O_symbol; |
| 18065 | exp.X_add_symbol = fragp->fr_symbol; |
| 18066 | exp.X_add_number = fragp->fr_offset; |
| 18067 | |
| 18068 | fragp->fr_fix += fragp->fr_var; |
| 18069 | |
| 18070 | /* Handle 16-bit branches that fit or are forced to fit. */ |
| 18071 | if (type != 0 && !RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype)) |
| 18072 | { |
| 18073 | /* We generate a fixup instead of applying it right now, |
| 18074 | because if there is linker relaxation, we're going to |
| 18075 | need the relocations. */ |
| 18076 | if (type == 'D') |
| 18077 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE, |
| 18078 | BFD_RELOC_MICROMIPS_10_PCREL_S1); |
| 18079 | else if (type == 'E') |
| 18080 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE, |
| 18081 | BFD_RELOC_MICROMIPS_7_PCREL_S1); |
| 18082 | else |
| 18083 | abort (); |
| 18084 | |
| 18085 | fixp->fx_file = fragp->fr_file; |
| 18086 | fixp->fx_line = fragp->fr_line; |
| 18087 | |
| 18088 | /* These relocations can have an addend that won't fit in |
| 18089 | 2 octets. */ |
| 18090 | fixp->fx_no_overflow = 1; |
| 18091 | |
| 18092 | return; |
| 18093 | } |
| 18094 | |
| 18095 | /* Handle 32-bit branches that fit or are forced to fit. */ |
| 18096 | if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype) |
| 18097 | || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype)) |
| 18098 | { |
| 18099 | /* We generate a fixup instead of applying it right now, |
| 18100 | because if there is linker relaxation, we're going to |
| 18101 | need the relocations. */ |
| 18102 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE, |
| 18103 | BFD_RELOC_MICROMIPS_16_PCREL_S1); |
| 18104 | fixp->fx_file = fragp->fr_file; |
| 18105 | fixp->fx_line = fragp->fr_line; |
| 18106 | |
| 18107 | if (type == 0) |
| 18108 | return; |
| 18109 | } |
| 18110 | |
| 18111 | /* Relax 16-bit branches to 32-bit branches. */ |
| 18112 | if (type != 0) |
| 18113 | { |
| 18114 | insn = read_compressed_insn (buf, 2); |
| 18115 | |
| 18116 | if ((insn & 0xfc00) == 0xcc00) /* b16 */ |
| 18117 | insn = 0x94000000; /* beq */ |
| 18118 | else if ((insn & 0xdc00) == 0x8c00) /* beqz16/bnez16 */ |
| 18119 | { |
| 18120 | unsigned long regno; |
| 18121 | |
| 18122 | regno = (insn >> MICROMIPSOP_SH_MD) & MICROMIPSOP_MASK_MD; |
| 18123 | regno = micromips_to_32_reg_d_map [regno]; |
| 18124 | insn = ((insn & 0x2000) << 16) | 0x94000000; /* beq/bne */ |
| 18125 | insn |= regno << MICROMIPSOP_SH_RS; |
| 18126 | } |
| 18127 | else |
| 18128 | abort (); |
| 18129 | |
| 18130 | /* Nothing else to do, just write it out. */ |
| 18131 | if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype) |
| 18132 | || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype)) |
| 18133 | { |
| 18134 | buf = write_compressed_insn (buf, insn, 4); |
| 18135 | gas_assert (buf == fragp->fr_literal + fragp->fr_fix); |
| 18136 | return; |
| 18137 | } |
| 18138 | } |
| 18139 | else |
| 18140 | insn = read_compressed_insn (buf, 4); |
| 18141 | |
| 18142 | /* Relax 32-bit branches to a sequence of instructions. */ |
| 18143 | as_warn_where (fragp->fr_file, fragp->fr_line, |
| 18144 | _("Relaxed out-of-range branch into a jump")); |
| 18145 | |
| 18146 | /* Set the short-delay-slot bit. */ |
| 18147 | short_ds = al && (insn & 0x02000000) != 0; |
| 18148 | |
| 18149 | if (!RELAX_MICROMIPS_UNCOND (fragp->fr_subtype)) |
| 18150 | { |
| 18151 | symbolS *l; |
| 18152 | |
| 18153 | /* Reverse the branch. */ |
| 18154 | if ((insn & 0xfc000000) == 0x94000000 /* beq */ |
| 18155 | || (insn & 0xfc000000) == 0xb4000000) /* bne */ |
| 18156 | insn ^= 0x20000000; |
| 18157 | else if ((insn & 0xffe00000) == 0x40000000 /* bltz */ |
| 18158 | || (insn & 0xffe00000) == 0x40400000 /* bgez */ |
| 18159 | || (insn & 0xffe00000) == 0x40800000 /* blez */ |
| 18160 | || (insn & 0xffe00000) == 0x40c00000 /* bgtz */ |
| 18161 | || (insn & 0xffe00000) == 0x40a00000 /* bnezc */ |
| 18162 | || (insn & 0xffe00000) == 0x40e00000 /* beqzc */ |
| 18163 | || (insn & 0xffe00000) == 0x40200000 /* bltzal */ |
| 18164 | || (insn & 0xffe00000) == 0x40600000 /* bgezal */ |
| 18165 | || (insn & 0xffe00000) == 0x42200000 /* bltzals */ |
| 18166 | || (insn & 0xffe00000) == 0x42600000) /* bgezals */ |
| 18167 | insn ^= 0x00400000; |
| 18168 | else if ((insn & 0xffe30000) == 0x43800000 /* bc1f */ |
| 18169 | || (insn & 0xffe30000) == 0x43a00000 /* bc1t */ |
| 18170 | || (insn & 0xffe30000) == 0x42800000 /* bc2f */ |
| 18171 | || (insn & 0xffe30000) == 0x42a00000) /* bc2t */ |
| 18172 | insn ^= 0x00200000; |
| 18173 | else |
| 18174 | abort (); |
| 18175 | |
| 18176 | if (al) |
| 18177 | { |
| 18178 | /* Clear the and-link and short-delay-slot bits. */ |
| 18179 | gas_assert ((insn & 0xfda00000) == 0x40200000); |
| 18180 | |
| 18181 | /* bltzal 0x40200000 bgezal 0x40600000 */ |
| 18182 | /* bltzals 0x42200000 bgezals 0x42600000 */ |
| 18183 | insn &= ~0x02200000; |
| 18184 | } |
| 18185 | |
| 18186 | /* Make a label at the end for use with the branch. */ |
| 18187 | l = symbol_new (micromips_label_name (), asec, fragp->fr_fix, fragp); |
| 18188 | micromips_label_inc (); |
| 18189 | #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF) |
| 18190 | if (IS_ELF) |
| 18191 | S_SET_OTHER (l, ELF_ST_SET_MICROMIPS (S_GET_OTHER (l))); |
| 18192 | #endif |
| 18193 | |
| 18194 | /* Refer to it. */ |
| 18195 | fixp = fix_new (fragp, buf - fragp->fr_literal, 4, l, 0, TRUE, |
| 18196 | BFD_RELOC_MICROMIPS_16_PCREL_S1); |
| 18197 | fixp->fx_file = fragp->fr_file; |
| 18198 | fixp->fx_line = fragp->fr_line; |
| 18199 | |
| 18200 | /* Branch over the jump. */ |
| 18201 | buf = write_compressed_insn (buf, insn, 4); |
| 18202 | if (!compact) |
| 18203 | /* nop */ |
| 18204 | buf = write_compressed_insn (buf, 0x0c00, 2); |
| 18205 | } |
| 18206 | |
| 18207 | if (mips_pic == NO_PIC) |
| 18208 | { |
| 18209 | unsigned long jal = short_ds ? 0x74000000 : 0xf4000000; /* jal/s */ |
| 18210 | |
| 18211 | /* j/jal/jals <sym> R_MICROMIPS_26_S1 */ |
| 18212 | insn = al ? jal : 0xd4000000; |
| 18213 | |
| 18214 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE, |
| 18215 | BFD_RELOC_MICROMIPS_JMP); |
| 18216 | fixp->fx_file = fragp->fr_file; |
| 18217 | fixp->fx_line = fragp->fr_line; |
| 18218 | |
| 18219 | buf = write_compressed_insn (buf, insn, 4); |
| 18220 | if (compact) |
| 18221 | /* nop */ |
| 18222 | buf = write_compressed_insn (buf, 0x0c00, 2); |
| 18223 | } |
| 18224 | else |
| 18225 | { |
| 18226 | unsigned long at = RELAX_MICROMIPS_AT (fragp->fr_subtype); |
| 18227 | unsigned long jalr = short_ds ? 0x45e0 : 0x45c0; /* jalr/s */ |
| 18228 | unsigned long jr = compact ? 0x45a0 : 0x4580; /* jr/c */ |
| 18229 | |
| 18230 | /* lw/ld $at, <sym>($gp) R_MICROMIPS_GOT16 */ |
| 18231 | insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000; |
| 18232 | insn |= at << MICROMIPSOP_SH_RT; |
| 18233 | |
| 18234 | if (exp.X_add_number) |
| 18235 | { |
| 18236 | exp.X_add_symbol = make_expr_symbol (&exp); |
| 18237 | exp.X_add_number = 0; |
| 18238 | } |
| 18239 | |
| 18240 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE, |
| 18241 | BFD_RELOC_MICROMIPS_GOT16); |
| 18242 | fixp->fx_file = fragp->fr_file; |
| 18243 | fixp->fx_line = fragp->fr_line; |
| 18244 | |
| 18245 | buf = write_compressed_insn (buf, insn, 4); |
| 18246 | |
| 18247 | /* d/addiu $at, $at, <sym> R_MICROMIPS_LO16 */ |
| 18248 | insn = HAVE_64BIT_ADDRESSES ? 0x5c000000 : 0x30000000; |
| 18249 | insn |= at << MICROMIPSOP_SH_RT | at << MICROMIPSOP_SH_RS; |
| 18250 | |
| 18251 | fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE, |
| 18252 | BFD_RELOC_MICROMIPS_LO16); |
| 18253 | fixp->fx_file = fragp->fr_file; |
| 18254 | fixp->fx_line = fragp->fr_line; |
| 18255 | |
| 18256 | buf = write_compressed_insn (buf, insn, 4); |
| 18257 | |
| 18258 | /* jr/jrc/jalr/jalrs $at */ |
| 18259 | insn = al ? jalr : jr; |
| 18260 | insn |= at << MICROMIPSOP_SH_MJ; |
| 18261 | |
| 18262 | buf = write_compressed_insn (buf, insn, 2); |
| 18263 | } |
| 18264 | |
| 18265 | gas_assert (buf == fragp->fr_literal + fragp->fr_fix); |
| 18266 | return; |
| 18267 | } |
| 18268 | |
| 18269 | if (RELAX_MIPS16_P (fragp->fr_subtype)) |
| 18270 | { |
| 18271 | int type; |
| 18272 | const struct mips16_immed_operand *op; |
| 18273 | offsetT val; |
| 18274 | char *buf; |
| 18275 | unsigned int user_length, length; |
| 18276 | unsigned long insn; |
| 18277 | bfd_boolean ext; |
| 18278 | |
| 18279 | type = RELAX_MIPS16_TYPE (fragp->fr_subtype); |
| 18280 | op = mips16_immed_operands; |
| 18281 | while (op->type != type) |
| 18282 | ++op; |
| 18283 | |
| 18284 | ext = RELAX_MIPS16_EXTENDED (fragp->fr_subtype); |
| 18285 | val = resolve_symbol_value (fragp->fr_symbol); |
| 18286 | if (op->pcrel) |
| 18287 | { |
| 18288 | addressT addr; |
| 18289 | |
| 18290 | addr = fragp->fr_address + fragp->fr_fix; |
| 18291 | |
| 18292 | /* The rules for the base address of a PC relative reloc are |
| 18293 | complicated; see mips16_extended_frag. */ |
| 18294 | if (type == 'p' || type == 'q') |
| 18295 | { |
| 18296 | addr += 2; |
| 18297 | if (ext) |
| 18298 | addr += 2; |
| 18299 | /* Ignore the low bit in the target, since it will be |
| 18300 | set for a text label. */ |
| 18301 | if ((val & 1) != 0) |
| 18302 | --val; |
| 18303 | } |
| 18304 | else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)) |
| 18305 | addr -= 4; |
| 18306 | else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype)) |
| 18307 | addr -= 2; |
| 18308 | |
| 18309 | addr &= ~ (addressT) ((1 << op->shift) - 1); |
| 18310 | val -= addr; |
| 18311 | |
| 18312 | /* Make sure the section winds up with the alignment we have |
| 18313 | assumed. */ |
| 18314 | if (op->shift > 0) |
| 18315 | record_alignment (asec, op->shift); |
| 18316 | } |
| 18317 | |
| 18318 | if (ext |
| 18319 | && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype) |
| 18320 | || RELAX_MIPS16_DSLOT (fragp->fr_subtype))) |
| 18321 | as_warn_where (fragp->fr_file, fragp->fr_line, |
| 18322 | _("extended instruction in delay slot")); |
| 18323 | |
| 18324 | buf = fragp->fr_literal + fragp->fr_fix; |
| 18325 | |
| 18326 | insn = read_compressed_insn (buf, 2); |
| 18327 | if (ext) |
| 18328 | insn |= MIPS16_EXTEND; |
| 18329 | |
| 18330 | if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype)) |
| 18331 | user_length = 4; |
| 18332 | else if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype)) |
| 18333 | user_length = 2; |
| 18334 | else |
| 18335 | user_length = 0; |
| 18336 | |
| 18337 | mips16_immed (fragp->fr_file, fragp->fr_line, type, |
| 18338 | BFD_RELOC_UNUSED, val, user_length, &insn); |
| 18339 | |
| 18340 | length = (ext ? 4 : 2); |
| 18341 | gas_assert (mips16_opcode_length (insn) == length); |
| 18342 | write_compressed_insn (buf, insn, length); |
| 18343 | fragp->fr_fix += length; |
| 18344 | } |
| 18345 | else |
| 18346 | { |
| 18347 | relax_substateT subtype = fragp->fr_subtype; |
| 18348 | bfd_boolean second_longer = (subtype & RELAX_SECOND_LONGER) != 0; |
| 18349 | bfd_boolean use_second = (subtype & RELAX_USE_SECOND) != 0; |
| 18350 | int first, second; |
| 18351 | fixS *fixp; |
| 18352 | |
| 18353 | first = RELAX_FIRST (subtype); |
| 18354 | second = RELAX_SECOND (subtype); |
| 18355 | fixp = (fixS *) fragp->fr_opcode; |
| 18356 | |
| 18357 | /* If the delay slot chosen does not match the size of the instruction, |
| 18358 | then emit a warning. */ |
| 18359 | if ((!use_second && (subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0) |
| 18360 | || (use_second && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0)) |
| 18361 | { |
| 18362 | relax_substateT s; |
| 18363 | const char *msg; |
| 18364 | |
| 18365 | s = subtype & (RELAX_DELAY_SLOT_16BIT |
| 18366 | | RELAX_DELAY_SLOT_SIZE_FIRST |
| 18367 | | RELAX_DELAY_SLOT_SIZE_SECOND); |
| 18368 | msg = macro_warning (s); |
| 18369 | if (msg != NULL) |
| 18370 | as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg); |
| 18371 | subtype &= ~s; |
| 18372 | } |
| 18373 | |
| 18374 | /* Possibly emit a warning if we've chosen the longer option. */ |
| 18375 | if (use_second == second_longer) |
| 18376 | { |
| 18377 | relax_substateT s; |
| 18378 | const char *msg; |
| 18379 | |
| 18380 | s = (subtype |
| 18381 | & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT)); |
| 18382 | msg = macro_warning (s); |
| 18383 | if (msg != NULL) |
| 18384 | as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg); |
| 18385 | subtype &= ~s; |
| 18386 | } |
| 18387 | |
| 18388 | /* Go through all the fixups for the first sequence. Disable them |
| 18389 | (by marking them as done) if we're going to use the second |
| 18390 | sequence instead. */ |
| 18391 | while (fixp |
| 18392 | && fixp->fx_frag == fragp |
| 18393 | && fixp->fx_where < fragp->fr_fix - second) |
| 18394 | { |
| 18395 | if (subtype & RELAX_USE_SECOND) |
| 18396 | fixp->fx_done = 1; |
| 18397 | fixp = fixp->fx_next; |
| 18398 | } |
| 18399 | |
| 18400 | /* Go through the fixups for the second sequence. Disable them if |
| 18401 | we're going to use the first sequence, otherwise adjust their |
| 18402 | addresses to account for the relaxation. */ |
| 18403 | while (fixp && fixp->fx_frag == fragp) |
| 18404 | { |
| 18405 | if (subtype & RELAX_USE_SECOND) |
| 18406 | fixp->fx_where -= first; |
| 18407 | else |
| 18408 | fixp->fx_done = 1; |
| 18409 | fixp = fixp->fx_next; |
| 18410 | } |
| 18411 | |
| 18412 | /* Now modify the frag contents. */ |
| 18413 | if (subtype & RELAX_USE_SECOND) |
| 18414 | { |
| 18415 | char *start; |
| 18416 | |
| 18417 | start = fragp->fr_literal + fragp->fr_fix - first - second; |
| 18418 | memmove (start, start + first, second); |
| 18419 | fragp->fr_fix -= first; |
| 18420 | } |
| 18421 | else |
| 18422 | fragp->fr_fix -= second; |
| 18423 | } |
| 18424 | } |
| 18425 | |
| 18426 | #ifdef OBJ_ELF |
| 18427 | |
| 18428 | /* This function is called after the relocs have been generated. |
| 18429 | We've been storing mips16 text labels as odd. Here we convert them |
| 18430 | back to even for the convenience of the debugger. */ |
| 18431 | |
| 18432 | void |
| 18433 | mips_frob_file_after_relocs (void) |
| 18434 | { |
| 18435 | asymbol **syms; |
| 18436 | unsigned int count, i; |
| 18437 | |
| 18438 | if (!IS_ELF) |
| 18439 | return; |
| 18440 | |
| 18441 | syms = bfd_get_outsymbols (stdoutput); |
| 18442 | count = bfd_get_symcount (stdoutput); |
| 18443 | for (i = 0; i < count; i++, syms++) |
| 18444 | if (ELF_ST_IS_COMPRESSED (elf_symbol (*syms)->internal_elf_sym.st_other) |
| 18445 | && ((*syms)->value & 1) != 0) |
| 18446 | { |
| 18447 | (*syms)->value &= ~1; |
| 18448 | /* If the symbol has an odd size, it was probably computed |
| 18449 | incorrectly, so adjust that as well. */ |
| 18450 | if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0) |
| 18451 | ++elf_symbol (*syms)->internal_elf_sym.st_size; |
| 18452 | } |
| 18453 | } |
| 18454 | |
| 18455 | #endif |
| 18456 | |
| 18457 | /* This function is called whenever a label is defined, including fake |
| 18458 | labels instantiated off the dot special symbol. It is used when |
| 18459 | handling branch delays; if a branch has a label, we assume we cannot |
| 18460 | move it. This also bumps the value of the symbol by 1 in compressed |
| 18461 | code. */ |
| 18462 | |
| 18463 | static void |
| 18464 | mips_record_label (symbolS *sym) |
| 18465 | { |
| 18466 | segment_info_type *si = seg_info (now_seg); |
| 18467 | struct insn_label_list *l; |
| 18468 | |
| 18469 | if (free_insn_labels == NULL) |
| 18470 | l = (struct insn_label_list *) xmalloc (sizeof *l); |
| 18471 | else |
| 18472 | { |
| 18473 | l = free_insn_labels; |
| 18474 | free_insn_labels = l->next; |
| 18475 | } |
| 18476 | |
| 18477 | l->label = sym; |
| 18478 | l->next = si->label_list; |
| 18479 | si->label_list = l; |
| 18480 | } |
| 18481 | |
| 18482 | /* This function is called as tc_frob_label() whenever a label is defined |
| 18483 | and adds a DWARF-2 record we only want for true labels. */ |
| 18484 | |
| 18485 | void |
| 18486 | mips_define_label (symbolS *sym) |
| 18487 | { |
| 18488 | mips_record_label (sym); |
| 18489 | #ifdef OBJ_ELF |
| 18490 | dwarf2_emit_label (sym); |
| 18491 | #endif |
| 18492 | } |
| 18493 | |
| 18494 | /* This function is called by tc_new_dot_label whenever a new dot symbol |
| 18495 | is defined. */ |
| 18496 | |
| 18497 | void |
| 18498 | mips_add_dot_label (symbolS *sym) |
| 18499 | { |
| 18500 | mips_record_label (sym); |
| 18501 | if (mips_assembling_insn && HAVE_CODE_COMPRESSION) |
| 18502 | mips_compressed_mark_label (sym); |
| 18503 | } |
| 18504 | \f |
| 18505 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
| 18506 | |
| 18507 | /* Some special processing for a MIPS ELF file. */ |
| 18508 | |
| 18509 | void |
| 18510 | mips_elf_final_processing (void) |
| 18511 | { |
| 18512 | /* Write out the register information. */ |
| 18513 | if (mips_abi != N64_ABI) |
| 18514 | { |
| 18515 | Elf32_RegInfo s; |
| 18516 | |
| 18517 | s.ri_gprmask = mips_gprmask; |
| 18518 | s.ri_cprmask[0] = mips_cprmask[0]; |
| 18519 | s.ri_cprmask[1] = mips_cprmask[1]; |
| 18520 | s.ri_cprmask[2] = mips_cprmask[2]; |
| 18521 | s.ri_cprmask[3] = mips_cprmask[3]; |
| 18522 | /* The gp_value field is set by the MIPS ELF backend. */ |
| 18523 | |
| 18524 | bfd_mips_elf32_swap_reginfo_out (stdoutput, &s, |
| 18525 | ((Elf32_External_RegInfo *) |
| 18526 | mips_regmask_frag)); |
| 18527 | } |
| 18528 | else |
| 18529 | { |
| 18530 | Elf64_Internal_RegInfo s; |
| 18531 | |
| 18532 | s.ri_gprmask = mips_gprmask; |
| 18533 | s.ri_pad = 0; |
| 18534 | s.ri_cprmask[0] = mips_cprmask[0]; |
| 18535 | s.ri_cprmask[1] = mips_cprmask[1]; |
| 18536 | s.ri_cprmask[2] = mips_cprmask[2]; |
| 18537 | s.ri_cprmask[3] = mips_cprmask[3]; |
| 18538 | /* The gp_value field is set by the MIPS ELF backend. */ |
| 18539 | |
| 18540 | bfd_mips_elf64_swap_reginfo_out (stdoutput, &s, |
| 18541 | ((Elf64_External_RegInfo *) |
| 18542 | mips_regmask_frag)); |
| 18543 | } |
| 18544 | |
| 18545 | /* Set the MIPS ELF flag bits. FIXME: There should probably be some |
| 18546 | sort of BFD interface for this. */ |
| 18547 | if (mips_any_noreorder) |
| 18548 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER; |
| 18549 | if (mips_pic != NO_PIC) |
| 18550 | { |
| 18551 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC; |
| 18552 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC; |
| 18553 | } |
| 18554 | if (mips_abicalls) |
| 18555 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC; |
| 18556 | |
| 18557 | /* Set MIPS ELF flags for ASEs. */ |
| 18558 | /* We may need to define a new flag for DSP ASE, and set this flag when |
| 18559 | file_ase_dsp is true. */ |
| 18560 | /* Same for DSP R2. */ |
| 18561 | /* We may need to define a new flag for MT ASE, and set this flag when |
| 18562 | file_ase_mt is true. */ |
| 18563 | if (file_ase_mips16) |
| 18564 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16; |
| 18565 | if (file_ase_micromips) |
| 18566 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MICROMIPS; |
| 18567 | #if 0 /* XXX FIXME */ |
| 18568 | if (file_ase_mips3d) |
| 18569 | elf_elfheader (stdoutput)->e_flags |= ???; |
| 18570 | #endif |
| 18571 | if (file_ase_mdmx) |
| 18572 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX; |
| 18573 | |
| 18574 | /* Set the MIPS ELF ABI flags. */ |
| 18575 | if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32) |
| 18576 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32; |
| 18577 | else if (mips_abi == O64_ABI) |
| 18578 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64; |
| 18579 | else if (mips_abi == EABI_ABI) |
| 18580 | { |
| 18581 | if (!file_mips_gp32) |
| 18582 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64; |
| 18583 | else |
| 18584 | elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32; |
| 18585 | } |
| 18586 | else if (mips_abi == N32_ABI) |
| 18587 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2; |
| 18588 | |
| 18589 | /* Nothing to do for N64_ABI. */ |
| 18590 | |
| 18591 | if (mips_32bitmode) |
| 18592 | elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE; |
| 18593 | |
| 18594 | #if 0 /* XXX FIXME */ |
| 18595 | /* 32 bit code with 64 bit FP registers. */ |
| 18596 | if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi)) |
| 18597 | elf_elfheader (stdoutput)->e_flags |= ???; |
| 18598 | #endif |
| 18599 | } |
| 18600 | |
| 18601 | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ |
| 18602 | \f |
| 18603 | typedef struct proc { |
| 18604 | symbolS *func_sym; |
| 18605 | symbolS *func_end_sym; |
| 18606 | unsigned long reg_mask; |
| 18607 | unsigned long reg_offset; |
| 18608 | unsigned long fpreg_mask; |
| 18609 | unsigned long fpreg_offset; |
| 18610 | unsigned long frame_offset; |
| 18611 | unsigned long frame_reg; |
| 18612 | unsigned long pc_reg; |
| 18613 | } procS; |
| 18614 | |
| 18615 | static procS cur_proc; |
| 18616 | static procS *cur_proc_ptr; |
| 18617 | static int numprocs; |
| 18618 | |
| 18619 | /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1", a microMIPS nop |
| 18620 | as "2", and a normal nop as "0". */ |
| 18621 | |
| 18622 | #define NOP_OPCODE_MIPS 0 |
| 18623 | #define NOP_OPCODE_MIPS16 1 |
| 18624 | #define NOP_OPCODE_MICROMIPS 2 |
| 18625 | |
| 18626 | char |
| 18627 | mips_nop_opcode (void) |
| 18628 | { |
| 18629 | if (seg_info (now_seg)->tc_segment_info_data.micromips) |
| 18630 | return NOP_OPCODE_MICROMIPS; |
| 18631 | else if (seg_info (now_seg)->tc_segment_info_data.mips16) |
| 18632 | return NOP_OPCODE_MIPS16; |
| 18633 | else |
| 18634 | return NOP_OPCODE_MIPS; |
| 18635 | } |
| 18636 | |
| 18637 | /* Fill in an rs_align_code fragment. Unlike elsewhere we want to use |
| 18638 | 32-bit microMIPS NOPs here (if applicable). */ |
| 18639 | |
| 18640 | void |
| 18641 | mips_handle_align (fragS *fragp) |
| 18642 | { |
| 18643 | char nop_opcode; |
| 18644 | char *p; |
| 18645 | int bytes, size, excess; |
| 18646 | valueT opcode; |
| 18647 | |
| 18648 | if (fragp->fr_type != rs_align_code) |
| 18649 | return; |
| 18650 | |
| 18651 | p = fragp->fr_literal + fragp->fr_fix; |
| 18652 | nop_opcode = *p; |
| 18653 | switch (nop_opcode) |
| 18654 | { |
| 18655 | case NOP_OPCODE_MICROMIPS: |
| 18656 | opcode = micromips_nop32_insn.insn_opcode; |
| 18657 | size = 4; |
| 18658 | break; |
| 18659 | case NOP_OPCODE_MIPS16: |
| 18660 | opcode = mips16_nop_insn.insn_opcode; |
| 18661 | size = 2; |
| 18662 | break; |
| 18663 | case NOP_OPCODE_MIPS: |
| 18664 | default: |
| 18665 | opcode = nop_insn.insn_opcode; |
| 18666 | size = 4; |
| 18667 | break; |
| 18668 | } |
| 18669 | |
| 18670 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
| 18671 | excess = bytes % size; |
| 18672 | |
| 18673 | /* Handle the leading part if we're not inserting a whole number of |
| 18674 | instructions, and make it the end of the fixed part of the frag. |
| 18675 | Try to fit in a short microMIPS NOP if applicable and possible, |
| 18676 | and use zeroes otherwise. */ |
| 18677 | gas_assert (excess < 4); |
| 18678 | fragp->fr_fix += excess; |
| 18679 | switch (excess) |
| 18680 | { |
| 18681 | case 3: |
| 18682 | *p++ = '\0'; |
| 18683 | /* Fall through. */ |
| 18684 | case 2: |
| 18685 | if (nop_opcode == NOP_OPCODE_MICROMIPS) |
| 18686 | { |
| 18687 | p = write_compressed_insn (p, micromips_nop16_insn.insn_opcode, 2); |
| 18688 | break; |
| 18689 | } |
| 18690 | *p++ = '\0'; |
| 18691 | /* Fall through. */ |
| 18692 | case 1: |
| 18693 | *p++ = '\0'; |
| 18694 | /* Fall through. */ |
| 18695 | case 0: |
| 18696 | break; |
| 18697 | } |
| 18698 | |
| 18699 | md_number_to_chars (p, opcode, size); |
| 18700 | fragp->fr_var = size; |
| 18701 | } |
| 18702 | |
| 18703 | static void |
| 18704 | md_obj_begin (void) |
| 18705 | { |
| 18706 | } |
| 18707 | |
| 18708 | static void |
| 18709 | md_obj_end (void) |
| 18710 | { |
| 18711 | /* Check for premature end, nesting errors, etc. */ |
| 18712 | if (cur_proc_ptr) |
| 18713 | as_warn (_("missing .end at end of assembly")); |
| 18714 | } |
| 18715 | |
| 18716 | static long |
| 18717 | get_number (void) |
| 18718 | { |
| 18719 | int negative = 0; |
| 18720 | long val = 0; |
| 18721 | |
| 18722 | if (*input_line_pointer == '-') |
| 18723 | { |
| 18724 | ++input_line_pointer; |
| 18725 | negative = 1; |
| 18726 | } |
| 18727 | if (!ISDIGIT (*input_line_pointer)) |
| 18728 | as_bad (_("expected simple number")); |
| 18729 | if (input_line_pointer[0] == '0') |
| 18730 | { |
| 18731 | if (input_line_pointer[1] == 'x') |
| 18732 | { |
| 18733 | input_line_pointer += 2; |
| 18734 | while (ISXDIGIT (*input_line_pointer)) |
| 18735 | { |
| 18736 | val <<= 4; |
| 18737 | val |= hex_value (*input_line_pointer++); |
| 18738 | } |
| 18739 | return negative ? -val : val; |
| 18740 | } |
| 18741 | else |
| 18742 | { |
| 18743 | ++input_line_pointer; |
| 18744 | while (ISDIGIT (*input_line_pointer)) |
| 18745 | { |
| 18746 | val <<= 3; |
| 18747 | val |= *input_line_pointer++ - '0'; |
| 18748 | } |
| 18749 | return negative ? -val : val; |
| 18750 | } |
| 18751 | } |
| 18752 | if (!ISDIGIT (*input_line_pointer)) |
| 18753 | { |
| 18754 | printf (_(" *input_line_pointer == '%c' 0x%02x\n"), |
| 18755 | *input_line_pointer, *input_line_pointer); |
| 18756 | as_warn (_("invalid number")); |
| 18757 | return -1; |
| 18758 | } |
| 18759 | while (ISDIGIT (*input_line_pointer)) |
| 18760 | { |
| 18761 | val *= 10; |
| 18762 | val += *input_line_pointer++ - '0'; |
| 18763 | } |
| 18764 | return negative ? -val : val; |
| 18765 | } |
| 18766 | |
| 18767 | /* The .file directive; just like the usual .file directive, but there |
| 18768 | is an initial number which is the ECOFF file index. In the non-ECOFF |
| 18769 | case .file implies DWARF-2. */ |
| 18770 | |
| 18771 | static void |
| 18772 | s_mips_file (int x ATTRIBUTE_UNUSED) |
| 18773 | { |
| 18774 | static int first_file_directive = 0; |
| 18775 | |
| 18776 | if (ECOFF_DEBUGGING) |
| 18777 | { |
| 18778 | get_number (); |
| 18779 | s_app_file (0); |
| 18780 | } |
| 18781 | else |
| 18782 | { |
| 18783 | char *filename; |
| 18784 | |
| 18785 | filename = dwarf2_directive_file (0); |
| 18786 | |
| 18787 | /* Versions of GCC up to 3.1 start files with a ".file" |
| 18788 | directive even for stabs output. Make sure that this |
| 18789 | ".file" is handled. Note that you need a version of GCC |
| 18790 | after 3.1 in order to support DWARF-2 on MIPS. */ |
| 18791 | if (filename != NULL && ! first_file_directive) |
| 18792 | { |
| 18793 | (void) new_logical_line (filename, -1); |
| 18794 | s_app_file_string (filename, 0); |
| 18795 | } |
| 18796 | first_file_directive = 1; |
| 18797 | } |
| 18798 | } |
| 18799 | |
| 18800 | /* The .loc directive, implying DWARF-2. */ |
| 18801 | |
| 18802 | static void |
| 18803 | s_mips_loc (int x ATTRIBUTE_UNUSED) |
| 18804 | { |
| 18805 | if (!ECOFF_DEBUGGING) |
| 18806 | dwarf2_directive_loc (0); |
| 18807 | } |
| 18808 | |
| 18809 | /* The .end directive. */ |
| 18810 | |
| 18811 | static void |
| 18812 | s_mips_end (int x ATTRIBUTE_UNUSED) |
| 18813 | { |
| 18814 | symbolS *p; |
| 18815 | |
| 18816 | /* Following functions need their own .frame and .cprestore directives. */ |
| 18817 | mips_frame_reg_valid = 0; |
| 18818 | mips_cprestore_valid = 0; |
| 18819 | |
| 18820 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
| 18821 | { |
| 18822 | p = get_symbol (); |
| 18823 | demand_empty_rest_of_line (); |
| 18824 | } |
| 18825 | else |
| 18826 | p = NULL; |
| 18827 | |
| 18828 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0) |
| 18829 | as_warn (_(".end not in text section")); |
| 18830 | |
| 18831 | if (!cur_proc_ptr) |
| 18832 | { |
| 18833 | as_warn (_(".end directive without a preceding .ent directive.")); |
| 18834 | demand_empty_rest_of_line (); |
| 18835 | return; |
| 18836 | } |
| 18837 | |
| 18838 | if (p != NULL) |
| 18839 | { |
| 18840 | gas_assert (S_GET_NAME (p)); |
| 18841 | if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym))) |
| 18842 | as_warn (_(".end symbol does not match .ent symbol.")); |
| 18843 | |
| 18844 | if (debug_type == DEBUG_STABS) |
| 18845 | stabs_generate_asm_endfunc (S_GET_NAME (p), |
| 18846 | S_GET_NAME (p)); |
| 18847 | } |
| 18848 | else |
| 18849 | as_warn (_(".end directive missing or unknown symbol")); |
| 18850 | |
| 18851 | #ifdef OBJ_ELF |
| 18852 | /* Create an expression to calculate the size of the function. */ |
| 18853 | if (p && cur_proc_ptr) |
| 18854 | { |
| 18855 | OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p); |
| 18856 | expressionS *exp = xmalloc (sizeof (expressionS)); |
| 18857 | |
| 18858 | obj->size = exp; |
| 18859 | exp->X_op = O_subtract; |
| 18860 | exp->X_add_symbol = symbol_temp_new_now (); |
| 18861 | exp->X_op_symbol = p; |
| 18862 | exp->X_add_number = 0; |
| 18863 | |
| 18864 | cur_proc_ptr->func_end_sym = exp->X_add_symbol; |
| 18865 | } |
| 18866 | |
| 18867 | /* Generate a .pdr section. */ |
| 18868 | if (IS_ELF && !ECOFF_DEBUGGING && mips_flag_pdr) |
| 18869 | { |
| 18870 | segT saved_seg = now_seg; |
| 18871 | subsegT saved_subseg = now_subseg; |
| 18872 | expressionS exp; |
| 18873 | char *fragp; |
| 18874 | |
| 18875 | #ifdef md_flush_pending_output |
| 18876 | md_flush_pending_output (); |
| 18877 | #endif |
| 18878 | |
| 18879 | gas_assert (pdr_seg); |
| 18880 | subseg_set (pdr_seg, 0); |
| 18881 | |
| 18882 | /* Write the symbol. */ |
| 18883 | exp.X_op = O_symbol; |
| 18884 | exp.X_add_symbol = p; |
| 18885 | exp.X_add_number = 0; |
| 18886 | emit_expr (&exp, 4); |
| 18887 | |
| 18888 | fragp = frag_more (7 * 4); |
| 18889 | |
| 18890 | md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4); |
| 18891 | md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4); |
| 18892 | md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4); |
| 18893 | md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4); |
| 18894 | md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4); |
| 18895 | md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4); |
| 18896 | md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4); |
| 18897 | |
| 18898 | subseg_set (saved_seg, saved_subseg); |
| 18899 | } |
| 18900 | #endif /* OBJ_ELF */ |
| 18901 | |
| 18902 | cur_proc_ptr = NULL; |
| 18903 | } |
| 18904 | |
| 18905 | /* The .aent and .ent directives. */ |
| 18906 | |
| 18907 | static void |
| 18908 | s_mips_ent (int aent) |
| 18909 | { |
| 18910 | symbolS *symbolP; |
| 18911 | |
| 18912 | symbolP = get_symbol (); |
| 18913 | if (*input_line_pointer == ',') |
| 18914 | ++input_line_pointer; |
| 18915 | SKIP_WHITESPACE (); |
| 18916 | if (ISDIGIT (*input_line_pointer) |
| 18917 | || *input_line_pointer == '-') |
| 18918 | get_number (); |
| 18919 | |
| 18920 | if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0) |
| 18921 | as_warn (_(".ent or .aent not in text section.")); |
| 18922 | |
| 18923 | if (!aent && cur_proc_ptr) |
| 18924 | as_warn (_("missing .end")); |
| 18925 | |
| 18926 | if (!aent) |
| 18927 | { |
| 18928 | /* This function needs its own .frame and .cprestore directives. */ |
| 18929 | mips_frame_reg_valid = 0; |
| 18930 | mips_cprestore_valid = 0; |
| 18931 | |
| 18932 | cur_proc_ptr = &cur_proc; |
| 18933 | memset (cur_proc_ptr, '\0', sizeof (procS)); |
| 18934 | |
| 18935 | cur_proc_ptr->func_sym = symbolP; |
| 18936 | |
| 18937 | ++numprocs; |
| 18938 | |
| 18939 | if (debug_type == DEBUG_STABS) |
| 18940 | stabs_generate_asm_func (S_GET_NAME (symbolP), |
| 18941 | S_GET_NAME (symbolP)); |
| 18942 | } |
| 18943 | |
| 18944 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
| 18945 | |
| 18946 | demand_empty_rest_of_line (); |
| 18947 | } |
| 18948 | |
| 18949 | /* The .frame directive. If the mdebug section is present (IRIX 5 native) |
| 18950 | then ecoff.c (ecoff_directive_frame) is used. For embedded targets, |
| 18951 | s_mips_frame is used so that we can set the PDR information correctly. |
| 18952 | We can't use the ecoff routines because they make reference to the ecoff |
| 18953 | symbol table (in the mdebug section). */ |
| 18954 | |
| 18955 | static void |
| 18956 | s_mips_frame (int ignore ATTRIBUTE_UNUSED) |
| 18957 | { |
| 18958 | #ifdef OBJ_ELF |
| 18959 | if (IS_ELF && !ECOFF_DEBUGGING) |
| 18960 | { |
| 18961 | long val; |
| 18962 | |
| 18963 | if (cur_proc_ptr == (procS *) NULL) |
| 18964 | { |
| 18965 | as_warn (_(".frame outside of .ent")); |
| 18966 | demand_empty_rest_of_line (); |
| 18967 | return; |
| 18968 | } |
| 18969 | |
| 18970 | cur_proc_ptr->frame_reg = tc_get_register (1); |
| 18971 | |
| 18972 | SKIP_WHITESPACE (); |
| 18973 | if (*input_line_pointer++ != ',' |
| 18974 | || get_absolute_expression_and_terminator (&val) != ',') |
| 18975 | { |
| 18976 | as_warn (_("Bad .frame directive")); |
| 18977 | --input_line_pointer; |
| 18978 | demand_empty_rest_of_line (); |
| 18979 | return; |
| 18980 | } |
| 18981 | |
| 18982 | cur_proc_ptr->frame_offset = val; |
| 18983 | cur_proc_ptr->pc_reg = tc_get_register (0); |
| 18984 | |
| 18985 | demand_empty_rest_of_line (); |
| 18986 | } |
| 18987 | else |
| 18988 | #endif /* OBJ_ELF */ |
| 18989 | s_ignore (ignore); |
| 18990 | } |
| 18991 | |
| 18992 | /* The .fmask and .mask directives. If the mdebug section is present |
| 18993 | (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For |
| 18994 | embedded targets, s_mips_mask is used so that we can set the PDR |
| 18995 | information correctly. We can't use the ecoff routines because they |
| 18996 | make reference to the ecoff symbol table (in the mdebug section). */ |
| 18997 | |
| 18998 | static void |
| 18999 | s_mips_mask (int reg_type) |
| 19000 | { |
| 19001 | #ifdef OBJ_ELF |
| 19002 | if (IS_ELF && !ECOFF_DEBUGGING) |
| 19003 | { |
| 19004 | long mask, off; |
| 19005 | |
| 19006 | if (cur_proc_ptr == (procS *) NULL) |
| 19007 | { |
| 19008 | as_warn (_(".mask/.fmask outside of .ent")); |
| 19009 | demand_empty_rest_of_line (); |
| 19010 | return; |
| 19011 | } |
| 19012 | |
| 19013 | if (get_absolute_expression_and_terminator (&mask) != ',') |
| 19014 | { |
| 19015 | as_warn (_("Bad .mask/.fmask directive")); |
| 19016 | --input_line_pointer; |
| 19017 | demand_empty_rest_of_line (); |
| 19018 | return; |
| 19019 | } |
| 19020 | |
| 19021 | off = get_absolute_expression (); |
| 19022 | |
| 19023 | if (reg_type == 'F') |
| 19024 | { |
| 19025 | cur_proc_ptr->fpreg_mask = mask; |
| 19026 | cur_proc_ptr->fpreg_offset = off; |
| 19027 | } |
| 19028 | else |
| 19029 | { |
| 19030 | cur_proc_ptr->reg_mask = mask; |
| 19031 | cur_proc_ptr->reg_offset = off; |
| 19032 | } |
| 19033 | |
| 19034 | demand_empty_rest_of_line (); |
| 19035 | } |
| 19036 | else |
| 19037 | #endif /* OBJ_ELF */ |
| 19038 | s_ignore (reg_type); |
| 19039 | } |
| 19040 | |
| 19041 | /* A table describing all the processors gas knows about. Names are |
| 19042 | matched in the order listed. |
| 19043 | |
| 19044 | To ease comparison, please keep this table in the same order as |
| 19045 | gcc's mips_cpu_info_table[]. */ |
| 19046 | static const struct mips_cpu_info mips_cpu_info_table[] = |
| 19047 | { |
| 19048 | /* Entries for generic ISAs */ |
| 19049 | { "mips1", MIPS_CPU_IS_ISA, ISA_MIPS1, CPU_R3000 }, |
| 19050 | { "mips2", MIPS_CPU_IS_ISA, ISA_MIPS2, CPU_R6000 }, |
| 19051 | { "mips3", MIPS_CPU_IS_ISA, ISA_MIPS3, CPU_R4000 }, |
| 19052 | { "mips4", MIPS_CPU_IS_ISA, ISA_MIPS4, CPU_R8000 }, |
| 19053 | { "mips5", MIPS_CPU_IS_ISA, ISA_MIPS5, CPU_MIPS5 }, |
| 19054 | { "mips32", MIPS_CPU_IS_ISA, ISA_MIPS32, CPU_MIPS32 }, |
| 19055 | { "mips32r2", MIPS_CPU_IS_ISA, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19056 | { "mips64", MIPS_CPU_IS_ISA, ISA_MIPS64, CPU_MIPS64 }, |
| 19057 | { "mips64r2", MIPS_CPU_IS_ISA, ISA_MIPS64R2, CPU_MIPS64R2 }, |
| 19058 | |
| 19059 | /* MIPS I */ |
| 19060 | { "r3000", 0, ISA_MIPS1, CPU_R3000 }, |
| 19061 | { "r2000", 0, ISA_MIPS1, CPU_R3000 }, |
| 19062 | { "r3900", 0, ISA_MIPS1, CPU_R3900 }, |
| 19063 | |
| 19064 | /* MIPS II */ |
| 19065 | { "r6000", 0, ISA_MIPS2, CPU_R6000 }, |
| 19066 | |
| 19067 | /* MIPS III */ |
| 19068 | { "r4000", 0, ISA_MIPS3, CPU_R4000 }, |
| 19069 | { "r4010", 0, ISA_MIPS2, CPU_R4010 }, |
| 19070 | { "vr4100", 0, ISA_MIPS3, CPU_VR4100 }, |
| 19071 | { "vr4111", 0, ISA_MIPS3, CPU_R4111 }, |
| 19072 | { "vr4120", 0, ISA_MIPS3, CPU_VR4120 }, |
| 19073 | { "vr4130", 0, ISA_MIPS3, CPU_VR4120 }, |
| 19074 | { "vr4181", 0, ISA_MIPS3, CPU_R4111 }, |
| 19075 | { "vr4300", 0, ISA_MIPS3, CPU_R4300 }, |
| 19076 | { "r4400", 0, ISA_MIPS3, CPU_R4400 }, |
| 19077 | { "r4600", 0, ISA_MIPS3, CPU_R4600 }, |
| 19078 | { "orion", 0, ISA_MIPS3, CPU_R4600 }, |
| 19079 | { "r4650", 0, ISA_MIPS3, CPU_R4650 }, |
| 19080 | /* ST Microelectronics Loongson 2E and 2F cores */ |
| 19081 | { "loongson2e", 0, ISA_MIPS3, CPU_LOONGSON_2E }, |
| 19082 | { "loongson2f", 0, ISA_MIPS3, CPU_LOONGSON_2F }, |
| 19083 | |
| 19084 | /* MIPS IV */ |
| 19085 | { "r8000", 0, ISA_MIPS4, CPU_R8000 }, |
| 19086 | { "r10000", 0, ISA_MIPS4, CPU_R10000 }, |
| 19087 | { "r12000", 0, ISA_MIPS4, CPU_R12000 }, |
| 19088 | { "r14000", 0, ISA_MIPS4, CPU_R14000 }, |
| 19089 | { "r16000", 0, ISA_MIPS4, CPU_R16000 }, |
| 19090 | { "vr5000", 0, ISA_MIPS4, CPU_R5000 }, |
| 19091 | { "vr5400", 0, ISA_MIPS4, CPU_VR5400 }, |
| 19092 | { "vr5500", 0, ISA_MIPS4, CPU_VR5500 }, |
| 19093 | { "rm5200", 0, ISA_MIPS4, CPU_R5000 }, |
| 19094 | { "rm5230", 0, ISA_MIPS4, CPU_R5000 }, |
| 19095 | { "rm5231", 0, ISA_MIPS4, CPU_R5000 }, |
| 19096 | { "rm5261", 0, ISA_MIPS4, CPU_R5000 }, |
| 19097 | { "rm5721", 0, ISA_MIPS4, CPU_R5000 }, |
| 19098 | { "rm7000", 0, ISA_MIPS4, CPU_RM7000 }, |
| 19099 | { "rm9000", 0, ISA_MIPS4, CPU_RM9000 }, |
| 19100 | |
| 19101 | /* MIPS 32 */ |
| 19102 | { "4kc", 0, ISA_MIPS32, CPU_MIPS32 }, |
| 19103 | { "4km", 0, ISA_MIPS32, CPU_MIPS32 }, |
| 19104 | { "4kp", 0, ISA_MIPS32, CPU_MIPS32 }, |
| 19105 | { "4ksc", MIPS_CPU_ASE_SMARTMIPS, ISA_MIPS32, CPU_MIPS32 }, |
| 19106 | |
| 19107 | /* MIPS 32 Release 2 */ |
| 19108 | { "4kec", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19109 | { "4kem", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19110 | { "4kep", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19111 | { "4ksd", MIPS_CPU_ASE_SMARTMIPS, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19112 | { "m4k", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19113 | { "m4kp", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19114 | { "m14k", MIPS_CPU_ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19115 | { "m14kc", MIPS_CPU_ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19116 | { "m14ke", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2 | MIPS_CPU_ASE_MCU, |
| 19117 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19118 | { "m14kec", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2 | MIPS_CPU_ASE_MCU, |
| 19119 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19120 | { "24kc", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19121 | { "24kf2_1", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19122 | { "24kf", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19123 | { "24kf1_1", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19124 | /* Deprecated forms of the above. */ |
| 19125 | { "24kfx", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19126 | { "24kx", 0, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19127 | /* 24KE is a 24K with DSP ASE, other ASEs are optional. */ |
| 19128 | { "24kec", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19129 | { "24kef2_1", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19130 | { "24kef", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19131 | { "24kef1_1", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19132 | /* Deprecated forms of the above. */ |
| 19133 | { "24kefx", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19134 | { "24kex", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19135 | /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */ |
| 19136 | { "34kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19137 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19138 | { "34kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19139 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19140 | { "34kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19141 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19142 | { "34kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19143 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19144 | /* Deprecated forms of the above. */ |
| 19145 | { "34kfx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19146 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19147 | { "34kx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19148 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19149 | /* 34Kn is a 34kc without DSP. */ |
| 19150 | { "34kn", MIPS_CPU_ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19151 | /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */ |
| 19152 | { "74kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
| 19153 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19154 | { "74kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
| 19155 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19156 | { "74kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
| 19157 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19158 | { "74kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
| 19159 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19160 | { "74kf3_2", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
| 19161 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19162 | /* Deprecated forms of the above. */ |
| 19163 | { "74kfx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
| 19164 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19165 | { "74kx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2, |
| 19166 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19167 | /* 1004K cores are multiprocessor versions of the 34K. */ |
| 19168 | { "1004kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19169 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19170 | { "1004kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19171 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19172 | { "1004kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19173 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19174 | { "1004kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT, |
| 19175 | ISA_MIPS32R2, CPU_MIPS32R2 }, |
| 19176 | |
| 19177 | /* MIPS 64 */ |
| 19178 | { "5kc", 0, ISA_MIPS64, CPU_MIPS64 }, |
| 19179 | { "5kf", 0, ISA_MIPS64, CPU_MIPS64 }, |
| 19180 | { "20kc", MIPS_CPU_ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 }, |
| 19181 | { "25kf", MIPS_CPU_ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 }, |
| 19182 | |
| 19183 | /* Broadcom SB-1 CPU core */ |
| 19184 | { "sb1", MIPS_CPU_ASE_MIPS3D | MIPS_CPU_ASE_MDMX, |
| 19185 | ISA_MIPS64, CPU_SB1 }, |
| 19186 | /* Broadcom SB-1A CPU core */ |
| 19187 | { "sb1a", MIPS_CPU_ASE_MIPS3D | MIPS_CPU_ASE_MDMX, |
| 19188 | ISA_MIPS64, CPU_SB1 }, |
| 19189 | |
| 19190 | { "loongson3a", 0, ISA_MIPS64, CPU_LOONGSON_3A }, |
| 19191 | |
| 19192 | /* MIPS 64 Release 2 */ |
| 19193 | |
| 19194 | /* Cavium Networks Octeon CPU core */ |
| 19195 | { "octeon", 0, ISA_MIPS64R2, CPU_OCTEON }, |
| 19196 | { "octeon+", 0, ISA_MIPS64R2, CPU_OCTEONP }, |
| 19197 | { "octeon2", 0, ISA_MIPS64R2, CPU_OCTEON2 }, |
| 19198 | |
| 19199 | /* RMI Xlr */ |
| 19200 | { "xlr", 0, ISA_MIPS64, CPU_XLR }, |
| 19201 | |
| 19202 | /* Broadcom XLP. |
| 19203 | XLP is mostly like XLR, with the prominent exception that it is |
| 19204 | MIPS64R2 rather than MIPS64. */ |
| 19205 | { "xlp", 0, ISA_MIPS64R2, CPU_XLR }, |
| 19206 | |
| 19207 | /* End marker */ |
| 19208 | { NULL, 0, 0, 0 } |
| 19209 | }; |
| 19210 | |
| 19211 | |
| 19212 | /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL |
| 19213 | with a final "000" replaced by "k". Ignore case. |
| 19214 | |
| 19215 | Note: this function is shared between GCC and GAS. */ |
| 19216 | |
| 19217 | static bfd_boolean |
| 19218 | mips_strict_matching_cpu_name_p (const char *canonical, const char *given) |
| 19219 | { |
| 19220 | while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical)) |
| 19221 | given++, canonical++; |
| 19222 | |
| 19223 | return ((*given == 0 && *canonical == 0) |
| 19224 | || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0)); |
| 19225 | } |
| 19226 | |
| 19227 | |
| 19228 | /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied |
| 19229 | CPU name. We've traditionally allowed a lot of variation here. |
| 19230 | |
| 19231 | Note: this function is shared between GCC and GAS. */ |
| 19232 | |
| 19233 | static bfd_boolean |
| 19234 | mips_matching_cpu_name_p (const char *canonical, const char *given) |
| 19235 | { |
| 19236 | /* First see if the name matches exactly, or with a final "000" |
| 19237 | turned into "k". */ |
| 19238 | if (mips_strict_matching_cpu_name_p (canonical, given)) |
| 19239 | return TRUE; |
| 19240 | |
| 19241 | /* If not, try comparing based on numerical designation alone. |
| 19242 | See if GIVEN is an unadorned number, or 'r' followed by a number. */ |
| 19243 | if (TOLOWER (*given) == 'r') |
| 19244 | given++; |
| 19245 | if (!ISDIGIT (*given)) |
| 19246 | return FALSE; |
| 19247 | |
| 19248 | /* Skip over some well-known prefixes in the canonical name, |
| 19249 | hoping to find a number there too. */ |
| 19250 | if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r') |
| 19251 | canonical += 2; |
| 19252 | else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm') |
| 19253 | canonical += 2; |
| 19254 | else if (TOLOWER (canonical[0]) == 'r') |
| 19255 | canonical += 1; |
| 19256 | |
| 19257 | return mips_strict_matching_cpu_name_p (canonical, given); |
| 19258 | } |
| 19259 | |
| 19260 | |
| 19261 | /* Parse an option that takes the name of a processor as its argument. |
| 19262 | OPTION is the name of the option and CPU_STRING is the argument. |
| 19263 | Return the corresponding processor enumeration if the CPU_STRING is |
| 19264 | recognized, otherwise report an error and return null. |
| 19265 | |
| 19266 | A similar function exists in GCC. */ |
| 19267 | |
| 19268 | static const struct mips_cpu_info * |
| 19269 | mips_parse_cpu (const char *option, const char *cpu_string) |
| 19270 | { |
| 19271 | const struct mips_cpu_info *p; |
| 19272 | |
| 19273 | /* 'from-abi' selects the most compatible architecture for the given |
| 19274 | ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the |
| 19275 | EABIs, we have to decide whether we're using the 32-bit or 64-bit |
| 19276 | version. Look first at the -mgp options, if given, otherwise base |
| 19277 | the choice on MIPS_DEFAULT_64BIT. |
| 19278 | |
| 19279 | Treat NO_ABI like the EABIs. One reason to do this is that the |
| 19280 | plain 'mips' and 'mips64' configs have 'from-abi' as their default |
| 19281 | architecture. This code picks MIPS I for 'mips' and MIPS III for |
| 19282 | 'mips64', just as we did in the days before 'from-abi'. */ |
| 19283 | if (strcasecmp (cpu_string, "from-abi") == 0) |
| 19284 | { |
| 19285 | if (ABI_NEEDS_32BIT_REGS (mips_abi)) |
| 19286 | return mips_cpu_info_from_isa (ISA_MIPS1); |
| 19287 | |
| 19288 | if (ABI_NEEDS_64BIT_REGS (mips_abi)) |
| 19289 | return mips_cpu_info_from_isa (ISA_MIPS3); |
| 19290 | |
| 19291 | if (file_mips_gp32 >= 0) |
| 19292 | return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3); |
| 19293 | |
| 19294 | return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT |
| 19295 | ? ISA_MIPS3 |
| 19296 | : ISA_MIPS1); |
| 19297 | } |
| 19298 | |
| 19299 | /* 'default' has traditionally been a no-op. Probably not very useful. */ |
| 19300 | if (strcasecmp (cpu_string, "default") == 0) |
| 19301 | return 0; |
| 19302 | |
| 19303 | for (p = mips_cpu_info_table; p->name != 0; p++) |
| 19304 | if (mips_matching_cpu_name_p (p->name, cpu_string)) |
| 19305 | return p; |
| 19306 | |
| 19307 | as_bad (_("Bad value (%s) for %s"), cpu_string, option); |
| 19308 | return 0; |
| 19309 | } |
| 19310 | |
| 19311 | /* Return the canonical processor information for ISA (a member of the |
| 19312 | ISA_MIPS* enumeration). */ |
| 19313 | |
| 19314 | static const struct mips_cpu_info * |
| 19315 | mips_cpu_info_from_isa (int isa) |
| 19316 | { |
| 19317 | int i; |
| 19318 | |
| 19319 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) |
| 19320 | if ((mips_cpu_info_table[i].flags & MIPS_CPU_IS_ISA) |
| 19321 | && isa == mips_cpu_info_table[i].isa) |
| 19322 | return (&mips_cpu_info_table[i]); |
| 19323 | |
| 19324 | return NULL; |
| 19325 | } |
| 19326 | |
| 19327 | static const struct mips_cpu_info * |
| 19328 | mips_cpu_info_from_arch (int arch) |
| 19329 | { |
| 19330 | int i; |
| 19331 | |
| 19332 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) |
| 19333 | if (arch == mips_cpu_info_table[i].cpu) |
| 19334 | return (&mips_cpu_info_table[i]); |
| 19335 | |
| 19336 | return NULL; |
| 19337 | } |
| 19338 | \f |
| 19339 | static void |
| 19340 | show (FILE *stream, const char *string, int *col_p, int *first_p) |
| 19341 | { |
| 19342 | if (*first_p) |
| 19343 | { |
| 19344 | fprintf (stream, "%24s", ""); |
| 19345 | *col_p = 24; |
| 19346 | } |
| 19347 | else |
| 19348 | { |
| 19349 | fprintf (stream, ", "); |
| 19350 | *col_p += 2; |
| 19351 | } |
| 19352 | |
| 19353 | if (*col_p + strlen (string) > 72) |
| 19354 | { |
| 19355 | fprintf (stream, "\n%24s", ""); |
| 19356 | *col_p = 24; |
| 19357 | } |
| 19358 | |
| 19359 | fprintf (stream, "%s", string); |
| 19360 | *col_p += strlen (string); |
| 19361 | |
| 19362 | *first_p = 0; |
| 19363 | } |
| 19364 | |
| 19365 | void |
| 19366 | md_show_usage (FILE *stream) |
| 19367 | { |
| 19368 | int column, first; |
| 19369 | size_t i; |
| 19370 | |
| 19371 | fprintf (stream, _("\ |
| 19372 | MIPS options:\n\ |
| 19373 | -EB generate big endian output\n\ |
| 19374 | -EL generate little endian output\n\ |
| 19375 | -g, -g2 do not remove unneeded NOPs or swap branches\n\ |
| 19376 | -G NUM allow referencing objects up to NUM bytes\n\ |
| 19377 | implicitly with the gp register [default 8]\n")); |
| 19378 | fprintf (stream, _("\ |
| 19379 | -mips1 generate MIPS ISA I instructions\n\ |
| 19380 | -mips2 generate MIPS ISA II instructions\n\ |
| 19381 | -mips3 generate MIPS ISA III instructions\n\ |
| 19382 | -mips4 generate MIPS ISA IV instructions\n\ |
| 19383 | -mips5 generate MIPS ISA V instructions\n\ |
| 19384 | -mips32 generate MIPS32 ISA instructions\n\ |
| 19385 | -mips32r2 generate MIPS32 release 2 ISA instructions\n\ |
| 19386 | -mips64 generate MIPS64 ISA instructions\n\ |
| 19387 | -mips64r2 generate MIPS64 release 2 ISA instructions\n\ |
| 19388 | -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n")); |
| 19389 | |
| 19390 | first = 1; |
| 19391 | |
| 19392 | for (i = 0; mips_cpu_info_table[i].name != NULL; i++) |
| 19393 | show (stream, mips_cpu_info_table[i].name, &column, &first); |
| 19394 | show (stream, "from-abi", &column, &first); |
| 19395 | fputc ('\n', stream); |
| 19396 | |
| 19397 | fprintf (stream, _("\ |
| 19398 | -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\ |
| 19399 | -no-mCPU don't generate code specific to CPU.\n\ |
| 19400 | For -mCPU and -no-mCPU, CPU must be one of:\n")); |
| 19401 | |
| 19402 | first = 1; |
| 19403 | |
| 19404 | show (stream, "3900", &column, &first); |
| 19405 | show (stream, "4010", &column, &first); |
| 19406 | show (stream, "4100", &column, &first); |
| 19407 | show (stream, "4650", &column, &first); |
| 19408 | fputc ('\n', stream); |
| 19409 | |
| 19410 | fprintf (stream, _("\ |
| 19411 | -mips16 generate mips16 instructions\n\ |
| 19412 | -no-mips16 do not generate mips16 instructions\n")); |
| 19413 | fprintf (stream, _("\ |
| 19414 | -mmicromips generate microMIPS instructions\n\ |
| 19415 | -mno-micromips do not generate microMIPS instructions\n")); |
| 19416 | fprintf (stream, _("\ |
| 19417 | -msmartmips generate smartmips instructions\n\ |
| 19418 | -mno-smartmips do not generate smartmips instructions\n")); |
| 19419 | fprintf (stream, _("\ |
| 19420 | -mdsp generate DSP instructions\n\ |
| 19421 | -mno-dsp do not generate DSP instructions\n")); |
| 19422 | fprintf (stream, _("\ |
| 19423 | -mdspr2 generate DSP R2 instructions\n\ |
| 19424 | -mno-dspr2 do not generate DSP R2 instructions\n")); |
| 19425 | fprintf (stream, _("\ |
| 19426 | -mmt generate MT instructions\n\ |
| 19427 | -mno-mt do not generate MT instructions\n")); |
| 19428 | fprintf (stream, _("\ |
| 19429 | -mmcu generate MCU instructions\n\ |
| 19430 | -mno-mcu do not generate MCU instructions\n")); |
| 19431 | fprintf (stream, _("\ |
| 19432 | -mfix-loongson2f-jump work around Loongson2F JUMP instructions\n\ |
| 19433 | -mfix-loongson2f-nop work around Loongson2F NOP errata\n\ |
| 19434 | -mfix-vr4120 work around certain VR4120 errata\n\ |
| 19435 | -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\ |
| 19436 | -mfix-24k insert a nop after ERET and DERET instructions\n\ |
| 19437 | -mfix-cn63xxp1 work around CN63XXP1 PREF errata\n\ |
| 19438 | -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\ |
| 19439 | -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\ |
| 19440 | -msym32 assume all symbols have 32-bit values\n\ |
| 19441 | -O0 remove unneeded NOPs, do not swap branches\n\ |
| 19442 | -O remove unneeded NOPs and swap branches\n\ |
| 19443 | --trap, --no-break trap exception on div by 0 and mult overflow\n\ |
| 19444 | --break, --no-trap break exception on div by 0 and mult overflow\n")); |
| 19445 | fprintf (stream, _("\ |
| 19446 | -mhard-float allow floating-point instructions\n\ |
| 19447 | -msoft-float do not allow floating-point instructions\n\ |
| 19448 | -msingle-float only allow 32-bit floating-point operations\n\ |
| 19449 | -mdouble-float allow 32-bit and 64-bit floating-point operations\n\ |
| 19450 | --[no-]construct-floats [dis]allow floating point values to be constructed\n" |
| 19451 | )); |
| 19452 | #ifdef OBJ_ELF |
| 19453 | fprintf (stream, _("\ |
| 19454 | -KPIC, -call_shared generate SVR4 position independent code\n\ |
| 19455 | -call_nonpic generate non-PIC code that can operate with DSOs\n\ |
| 19456 | -mvxworks-pic generate VxWorks position independent code\n\ |
| 19457 | -non_shared do not generate code that can operate with DSOs\n\ |
| 19458 | -xgot assume a 32 bit GOT\n\ |
| 19459 | -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\ |
| 19460 | -mshared, -mno-shared disable/enable .cpload optimization for\n\ |
| 19461 | position dependent (non shared) code\n\ |
| 19462 | -mabi=ABI create ABI conformant object file for:\n")); |
| 19463 | |
| 19464 | first = 1; |
| 19465 | |
| 19466 | show (stream, "32", &column, &first); |
| 19467 | show (stream, "o64", &column, &first); |
| 19468 | show (stream, "n32", &column, &first); |
| 19469 | show (stream, "64", &column, &first); |
| 19470 | show (stream, "eabi", &column, &first); |
| 19471 | |
| 19472 | fputc ('\n', stream); |
| 19473 | |
| 19474 | fprintf (stream, _("\ |
| 19475 | -32 create o32 ABI object file (default)\n\ |
| 19476 | -n32 create n32 ABI object file\n\ |
| 19477 | -64 create 64 ABI object file\n")); |
| 19478 | #endif |
| 19479 | } |
| 19480 | |
| 19481 | #ifdef TE_IRIX |
| 19482 | enum dwarf2_format |
| 19483 | mips_dwarf2_format (asection *sec ATTRIBUTE_UNUSED) |
| 19484 | { |
| 19485 | if (HAVE_64BIT_SYMBOLS) |
| 19486 | return dwarf2_format_64bit_irix; |
| 19487 | else |
| 19488 | return dwarf2_format_32bit; |
| 19489 | } |
| 19490 | #endif |
| 19491 | |
| 19492 | int |
| 19493 | mips_dwarf2_addr_size (void) |
| 19494 | { |
| 19495 | if (HAVE_64BIT_OBJECTS) |
| 19496 | return 8; |
| 19497 | else |
| 19498 | return 4; |
| 19499 | } |
| 19500 | |
| 19501 | /* Standard calling conventions leave the CFA at SP on entry. */ |
| 19502 | void |
| 19503 | mips_cfi_frame_initial_instructions (void) |
| 19504 | { |
| 19505 | cfi_add_CFA_def_cfa_register (SP); |
| 19506 | } |
| 19507 | |
| 19508 | int |
| 19509 | tc_mips_regname_to_dw2regnum (char *regname) |
| 19510 | { |
| 19511 | unsigned int regnum = -1; |
| 19512 | unsigned int reg; |
| 19513 | |
| 19514 | if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®)) |
| 19515 | regnum = reg; |
| 19516 | |
| 19517 | return regnum; |
| 19518 | } |