1 1.1 christos /* tc-cris.c -- Assembler code for the CRIS CPU core. 2 1.10 christos Copyright (C) 2000-2025 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos Contributed by Axis Communications AB, Lund, Sweden. 5 1.1 christos Originally written for GAS 1.38.1 by Mikael Asker. 6 1.1 christos Updates, BFDizing, GNUifying and ELF support by Hans-Peter Nilsson. 7 1.1 christos 8 1.1 christos This file is part of GAS, the GNU Assembler. 9 1.1 christos 10 1.1 christos GAS is free software; you can redistribute it and/or modify 11 1.1 christos it under the terms of the GNU General Public License as published by 12 1.1 christos the Free Software Foundation; either version 3, or (at your option) 13 1.1 christos any later version. 14 1.1 christos 15 1.1 christos GAS is distributed in the hope that it will be useful, 16 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 17 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 1.1 christos GNU General Public License for more details. 19 1.1 christos 20 1.1 christos You should have received a copy of the GNU General Public License 21 1.1 christos along with GAS; see the file COPYING. If not, write to the 22 1.1 christos Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, 23 1.1 christos MA 02110-1301, USA. */ 24 1.1 christos 25 1.1 christos #include "as.h" 26 1.1 christos #include "safe-ctype.h" 27 1.1 christos #include "subsegs.h" 28 1.1 christos #include "opcode/cris.h" 29 1.1 christos #include "dwarf2dbg.h" 30 1.1 christos 31 1.1 christos /* Conventions used here: 32 1.1 christos Generally speaking, pointers to binutils types such as "fragS" and 33 1.1 christos "expressionS" get parameter and variable names ending in "P", such as 34 1.1 christos "fragP", to harmonize with the rest of the binutils code. Other 35 1.1 christos pointers get a "p" suffix, such as "bufp". Any function or type-name 36 1.1 christos that could clash with a current or future binutils or GAS function get 37 1.1 christos a "cris_" prefix. */ 38 1.1 christos 39 1.1 christos #define SYNTAX_RELAX_REG_PREFIX "no_register_prefix" 40 1.1 christos #define SYNTAX_ENFORCE_REG_PREFIX "register_prefix" 41 1.1 christos #define SYNTAX_USER_SYM_LEADING_UNDERSCORE "leading_underscore" 42 1.1 christos #define SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE "no_leading_underscore" 43 1.1 christos #define REGISTER_PREFIX_CHAR '$' 44 1.1 christos 45 1.1 christos /* True for expressions where getting X_add_symbol and X_add_number is 46 1.1 christos enough to get the "base" and "offset"; no need to make_expr_symbol. 47 1.1 christos It's not enough to check if X_op_symbol is NULL; that misses unary 48 1.1 christos operations like O_uminus. */ 49 1.1 christos #define SIMPLE_EXPR(EXP) \ 50 1.1 christos ((EXP)->X_op == O_constant || (EXP)->X_op == O_symbol) 51 1.1 christos 52 1.1 christos /* Like in ":GOT", ":GOTOFF" etc. Other ports use '@', but that's in 53 1.1 christos line_separator_chars for CRIS, so we avoid it. */ 54 1.1 christos #define RELOC_SUFFIX_CHAR ':' 55 1.1 christos 56 1.1 christos /* This might be CRIS_INSN_NONE if we're assembling a prefix-insn only. 57 1.1 christos Note that some prefix-insns might be assembled as CRIS_INSN_NORMAL. */ 58 1.1 christos enum cris_insn_kind 59 1.1 christos { 60 1.1 christos CRIS_INSN_NORMAL, CRIS_INSN_NONE, CRIS_INSN_BRANCH, CRIS_INSN_MUL 61 1.1 christos }; 62 1.1 christos 63 1.1 christos /* An instruction will have one of these prefixes. 64 1.1 christos Although the same bit-pattern, we handle BDAP with an immediate 65 1.1 christos expression (eventually quick or [pc+]) different from when we only have 66 1.1 christos register expressions. */ 67 1.1 christos enum prefix_kind 68 1.1 christos { 69 1.1 christos PREFIX_NONE, PREFIX_BDAP_IMM, PREFIX_BDAP, PREFIX_BIAP, PREFIX_DIP, 70 1.1 christos PREFIX_PUSH 71 1.1 christos }; 72 1.1 christos 73 1.1 christos /* The prefix for an instruction. */ 74 1.1 christos struct cris_prefix 75 1.1 christos { 76 1.1 christos enum prefix_kind kind; 77 1.1 christos int base_reg_number; 78 1.1 christos unsigned int opcode; 79 1.1 christos 80 1.1 christos /* There might be an expression to be evaluated, like I in [rN+I]. */ 81 1.1 christos expressionS expr; 82 1.1 christos 83 1.1 christos /* If there's an expression, we might need a relocation. Here's the 84 1.6 christos type of what relocation to start relaxation with. 85 1.1 christos The relocation is assumed to start immediately after the prefix insn, 86 1.1 christos so we don't provide an offset. */ 87 1.1 christos enum bfd_reloc_code_real reloc; 88 1.1 christos }; 89 1.1 christos 90 1.1 christos /* The description of the instruction being assembled. */ 91 1.1 christos struct cris_instruction 92 1.1 christos { 93 1.1 christos /* If CRIS_INSN_NONE, then this insn is of zero length. */ 94 1.1 christos enum cris_insn_kind insn_type; 95 1.1 christos 96 1.1 christos /* If a special register was mentioned, this is its description, else 97 1.1 christos it is NULL. */ 98 1.1 christos const struct cris_spec_reg *spec_reg; 99 1.1 christos 100 1.1 christos unsigned int opcode; 101 1.1 christos 102 1.1 christos /* An insn may have at most one expression; theoretically there could be 103 1.1 christos another in its prefix (but I don't see how that could happen). */ 104 1.1 christos expressionS expr; 105 1.1 christos 106 1.1 christos /* The expression might need a relocation. Here's one to start 107 1.1 christos relaxation with. */ 108 1.1 christos enum bfd_reloc_code_real reloc; 109 1.1 christos 110 1.1 christos /* The size in bytes of an immediate expression, or zero if 111 1.1 christos nonapplicable. */ 112 1.1 christos int imm_oprnd_size; 113 1.1 christos }; 114 1.1 christos 115 1.1 christos enum cris_archs 116 1.1 christos { 117 1.1 christos arch_cris_unknown, 118 1.1 christos arch_crisv0, arch_crisv3, arch_crisv8, arch_crisv10, 119 1.1 christos arch_cris_any_v0_v10, arch_crisv32, arch_cris_common_v10_v32 120 1.1 christos }; 121 1.1 christos 122 1.5 christos static enum cris_archs cris_arch_from_string (const char **); 123 1.1 christos static int cris_insn_ver_valid_for_arch (enum cris_insn_version_usage, 124 1.1 christos enum cris_archs); 125 1.1 christos 126 1.1 christos static void cris_process_instruction (char *, struct cris_instruction *, 127 1.1 christos struct cris_prefix *); 128 1.1 christos static int get_bwd_size_modifier (char **, int *); 129 1.1 christos static int get_bw_size_modifier (char **, int *); 130 1.1 christos static int get_gen_reg (char **, int *); 131 1.1 christos static int get_spec_reg (char **, const struct cris_spec_reg **); 132 1.1 christos static int get_sup_reg (char **, int *); 133 1.1 christos static int get_autoinc_prefix_or_indir_op (char **, struct cris_prefix *, 134 1.1 christos int *, int *, int *, 135 1.1 christos expressionS *); 136 1.1 christos static int get_3op_or_dip_prefix_op (char **, struct cris_prefix *); 137 1.1 christos static int cris_get_expression (char **, expressionS *); 138 1.1 christos static int get_flags (char **, int *); 139 1.1 christos static void gen_bdap (int, expressionS *); 140 1.1 christos static int branch_disp (int); 141 1.1 christos static void gen_cond_branch_32 (char *, char *, fragS *, symbolS *, symbolS *, 142 1.1 christos long int); 143 1.1 christos static void cris_number_to_imm (char *, long, int, fixS *, segT); 144 1.1 christos static void s_syntax (int); 145 1.1 christos static void s_cris_file (int); 146 1.1 christos static void s_cris_loc (int); 147 1.1 christos static void s_cris_arch (int); 148 1.1 christos static void s_cris_dtpoff (int); 149 1.1 christos 150 1.1 christos /* Get ":GOT", ":GOTOFF", ":PLT" etc. suffixes. */ 151 1.1 christos static void cris_get_reloc_suffix (char **, bfd_reloc_code_real_type *, 152 1.1 christos expressionS *); 153 1.1 christos static unsigned int cris_get_specified_reloc_size (bfd_reloc_code_real_type); 154 1.1 christos 155 1.1 christos /* All the .syntax functions. */ 156 1.1 christos static void cris_force_reg_prefix (void); 157 1.1 christos static void cris_relax_reg_prefix (void); 158 1.1 christos static void cris_sym_leading_underscore (void); 159 1.1 christos static void cris_sym_no_leading_underscore (void); 160 1.1 christos static char *cris_insn_first_word_frag (void); 161 1.1 christos 162 1.1 christos /* Handle to the opcode hash table. */ 163 1.8 christos static htab_t op_hash = NULL; 164 1.1 christos 165 1.1 christos /* If we target cris-axis-linux-gnu (as opposed to generic cris-axis-elf), 166 1.1 christos we default to no underscore and required register-prefixes. The 167 1.1 christos difference is in the default values. */ 168 1.1 christos #ifdef TE_LINUX 169 1.8 christos #define DEFAULT_CRIS_AXIS_LINUX_GNU true 170 1.1 christos #else 171 1.8 christos #define DEFAULT_CRIS_AXIS_LINUX_GNU false 172 1.1 christos #endif 173 1.1 christos 174 1.1 christos /* Whether we demand that registers have a `$' prefix. Default here. */ 175 1.8 christos static bool demand_register_prefix = DEFAULT_CRIS_AXIS_LINUX_GNU; 176 1.1 christos 177 1.1 christos /* Whether global user symbols have a leading underscore. Default here. */ 178 1.8 christos static bool symbols_have_leading_underscore 179 1.1 christos = !DEFAULT_CRIS_AXIS_LINUX_GNU; 180 1.1 christos 181 1.1 christos /* Whether or not we allow PIC, and expand to PIC-friendly constructs. */ 182 1.8 christos static bool pic = false; 183 1.1 christos 184 1.1 christos /* Whether or not we allow TLS suffixes. For the moment, we always do. */ 185 1.8 christos static const bool tls = true; 186 1.1 christos 187 1.1 christos /* If we're configured for "cris", default to allow all v0..v10 188 1.1 christos instructions and register names. */ 189 1.1 christos #ifndef DEFAULT_CRIS_ARCH 190 1.1 christos #define DEFAULT_CRIS_ARCH cris_any_v0_v10 191 1.1 christos #endif 192 1.1 christos 193 1.1 christos /* No whitespace in the CONCAT2 parameter list. */ 194 1.1 christos static enum cris_archs cris_arch = XCONCAT2 (arch_,DEFAULT_CRIS_ARCH); 195 1.1 christos 196 1.1 christos const pseudo_typeS md_pseudo_table[] = 197 1.1 christos { 198 1.1 christos {"dword", cons, 4}, 199 1.1 christos {"dtpoffd", s_cris_dtpoff, 4}, 200 1.1 christos {"syntax", s_syntax, 0}, 201 1.1 christos {"file", s_cris_file, 0}, 202 1.1 christos {"loc", s_cris_loc, 0}, 203 1.1 christos {"arch", s_cris_arch, 0}, 204 1.1 christos {NULL, 0, 0} 205 1.1 christos }; 206 1.1 christos 207 1.1 christos static int warn_for_branch_expansion = 0; 208 1.1 christos 209 1.1 christos /* Whether to emit error when a MULS/MULU could be located last on a 210 1.1 christos cache-line. */ 211 1.1 christos static int err_for_dangerous_mul_placement 212 1.1 christos = (XCONCAT2 (arch_,DEFAULT_CRIS_ARCH) != arch_crisv32); 213 1.1 christos 214 1.10 christos const char comment_chars[] = ";"; 215 1.1 christos 216 1.1 christos /* This array holds the chars that only start a comment at the beginning of 217 1.1 christos a line. If the line seems to have the form '# 123 filename' 218 1.1 christos .line and .file directives will appear in the pre-processed output. */ 219 1.1 christos /* Note that input_file.c hand-checks for '#' at the beginning of the 220 1.1 christos first line of the input file. This is because the compiler outputs 221 1.1 christos #NO_APP at the beginning of its output. */ 222 1.1 christos /* Also note that slash-star will always start a comment. */ 223 1.1 christos const char line_comment_chars[] = "#"; 224 1.1 christos const char line_separator_chars[] = "@"; 225 1.1 christos 226 1.1 christos /* Now all floating point support is shut off. See md_atof. */ 227 1.1 christos const char EXP_CHARS[] = ""; 228 1.1 christos const char FLT_CHARS[] = ""; 229 1.1 christos 230 1.1 christos /* For CRIS, we encode the relax_substateTs (in e.g. fr_substate) as: 231 1.1 christos 2 1 0 232 1.1 christos ---/ /--+-----------------+-----------------+-----------------+ 233 1.1 christos | what state ? | how long ? | 234 1.1 christos ---/ /--+-----------------+-----------------+-----------------+ 235 1.1 christos 236 1.1 christos The "how long" bits are 00 = byte, 01 = word, 10 = dword (long). 237 1.1 christos Not all lengths are legit for a given value of (what state). 238 1.1 christos 239 1.1 christos Groups for CRIS address relaxing: 240 1.1 christos 241 1.1 christos 1. Bcc (pre-V32) 242 1.1 christos length: byte, word, 10-byte expansion 243 1.1 christos 244 1.1 christos 2. BDAP 245 1.1 christos length: byte, word, dword 246 1.1 christos 247 1.1 christos 3. MULS/MULU 248 1.1 christos Not really a relaxation (no infrastructure to get delay-slots 249 1.1 christos right), just an alignment and placement checker for the v10 250 1.1 christos multiply/cache-bug. 251 1.1 christos 252 1.1 christos 4. Bcc (V32 and later) 253 1.1 christos length: byte, word, 14-byte expansion 254 1.1 christos 255 1.1 christos 5. Bcc (V10+V32) 256 1.1 christos length: byte, word, error 257 1.1 christos 258 1.1 christos 6. BA (V32) 259 1.1 christos length: byte, word, dword 260 1.1 christos 261 1.1 christos 7. LAPC (V32) 262 1.1 christos length: byte, dword 263 1.1 christos */ 264 1.1 christos 265 1.1 christos #define STATE_COND_BRANCH (1) 266 1.1 christos #define STATE_BASE_PLUS_DISP_PREFIX (2) 267 1.1 christos #define STATE_MUL (3) 268 1.1 christos #define STATE_COND_BRANCH_V32 (4) 269 1.1 christos #define STATE_COND_BRANCH_COMMON (5) 270 1.1 christos #define STATE_ABS_BRANCH_V32 (6) 271 1.1 christos #define STATE_LAPC (7) 272 1.1 christos #define STATE_COND_BRANCH_PIC (8) 273 1.1 christos 274 1.1 christos #define STATE_LENGTH_MASK (3) 275 1.1 christos #define STATE_BYTE (0) 276 1.1 christos #define STATE_WORD (1) 277 1.1 christos #define STATE_DWORD (2) 278 1.1 christos /* Symbol undefined. */ 279 1.1 christos #define STATE_UNDF (3) 280 1.1 christos #define STATE_MAX_LENGTH (3) 281 1.1 christos 282 1.1 christos /* These displacements are relative to the address following the opcode 283 1.1 christos word of the instruction. The first letter is Byte, Word. The 2nd 284 1.1 christos letter is Forward, Backward. */ 285 1.1 christos 286 1.1 christos #define BRANCH_BF ( 254) 287 1.1 christos #define BRANCH_BB (-256) 288 1.1 christos #define BRANCH_BF_V32 ( 252) 289 1.1 christos #define BRANCH_BB_V32 (-258) 290 1.1 christos #define BRANCH_WF (2 + 32767) 291 1.1 christos #define BRANCH_WB (2 + -32768) 292 1.1 christos #define BRANCH_WF_V32 (-2 + 32767) 293 1.1 christos #define BRANCH_WB_V32 (-2 + -32768) 294 1.1 christos 295 1.1 christos #define BDAP_BF ( 127) 296 1.1 christos #define BDAP_BB (-128) 297 1.1 christos #define BDAP_WF ( 32767) 298 1.1 christos #define BDAP_WB (-32768) 299 1.1 christos 300 1.1 christos #define ENCODE_RELAX(what, length) (((what) << 2) + (length)) 301 1.1 christos 302 1.1 christos const relax_typeS md_cris_relax_table[] = 303 1.1 christos { 304 1.1 christos /* Error sentinel (0, 0). */ 305 1.1 christos {1, 1, 0, 0}, 306 1.1 christos 307 1.1 christos /* Unused (0, 1). */ 308 1.1 christos {1, 1, 0, 0}, 309 1.1 christos 310 1.1 christos /* Unused (0, 2). */ 311 1.1 christos {1, 1, 0, 0}, 312 1.1 christos 313 1.1 christos /* Unused (0, 3). */ 314 1.1 christos {1, 1, 0, 0}, 315 1.1 christos 316 1.1 christos /* Bcc o (1, 0). */ 317 1.1 christos {BRANCH_BF, BRANCH_BB, 0, ENCODE_RELAX (1, 1)}, 318 1.1 christos 319 1.1 christos /* Bcc [PC+] (1, 1). */ 320 1.1 christos {BRANCH_WF, BRANCH_WB, 2, ENCODE_RELAX (1, 2)}, 321 1.1 christos 322 1.1 christos /* BEXT/BWF, BA, JUMP (external), JUMP (always), Bnot_cc, JUMP (default) 323 1.1 christos (1, 2). */ 324 1.1 christos {0, 0, 10, 0}, 325 1.1 christos 326 1.1 christos /* Unused (1, 3). */ 327 1.1 christos {1, 1, 0, 0}, 328 1.1 christos 329 1.1 christos /* BDAP o (2, 0). */ 330 1.1 christos {BDAP_BF, BDAP_BB, 0, ENCODE_RELAX (2, 1)}, 331 1.1 christos 332 1.1 christos /* BDAP.[bw] [PC+] (2, 1). */ 333 1.1 christos {BDAP_WF, BDAP_WB, 2, ENCODE_RELAX (2, 2)}, 334 1.1 christos 335 1.1 christos /* BDAP.d [PC+] (2, 2). */ 336 1.1 christos {0, 0, 4, 0}, 337 1.1 christos 338 1.1 christos /* Unused (2, 3). */ 339 1.1 christos {1, 1, 0, 0}, 340 1.1 christos 341 1.1 christos /* MULS/MULU (3, 0). Positions (3, 1..3) are unused. */ 342 1.1 christos {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, 343 1.1 christos 344 1.1 christos /* V32: Bcc o (4, 0). */ 345 1.1 christos {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (4, 1)}, 346 1.1 christos 347 1.1 christos /* V32: Bcc [PC+] (4, 1). */ 348 1.1 christos {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (4, 2)}, 349 1.1 christos 350 1.1 christos /* V32: BA .+12; NOP; BA32 target; NOP; Bcc .-6 (4, 2). */ 351 1.1 christos {0, 0, 12, 0}, 352 1.1 christos 353 1.1 christos /* Unused (4, 3). */ 354 1.1 christos {1, 1, 0, 0}, 355 1.1 christos 356 1.1 christos /* COMMON: Bcc o (5, 0). The offsets are calculated as for v32. Code 357 1.1 christos should contain two nop insns (or four if offset size is large or 358 1.1 christos unknown) after every label. */ 359 1.1 christos {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (5, 1)}, 360 1.1 christos 361 1.1 christos /* COMMON: Bcc [PC+] (5, 1). */ 362 1.1 christos {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (5, 2)}, 363 1.1 christos 364 1.1 christos /* COMMON: FIXME: ???. Treat as error currently. */ 365 1.1 christos {0, 0, 12, 0}, 366 1.1 christos 367 1.1 christos /* Unused (5, 3). */ 368 1.1 christos {1, 1, 0, 0}, 369 1.1 christos 370 1.1 christos /* V32: BA o (6, 0). */ 371 1.1 christos {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (6, 1)}, 372 1.1 christos 373 1.1 christos /* V32: BA.W (6, 1). */ 374 1.1 christos {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (6, 2)}, 375 1.1 christos 376 1.1 christos /* V32: BA.D (6, 2). */ 377 1.1 christos {0, 0, 4, 0}, 378 1.1 christos 379 1.1 christos /* Unused (6, 3). */ 380 1.1 christos {1, 1, 0, 0}, 381 1.1 christos 382 1.1 christos /* LAPC: LAPCQ .+0..15*2,Rn (7, 0). */ 383 1.1 christos {14*2, -1*2, 0, ENCODE_RELAX (7, 2)}, 384 1.1 christos 385 1.1 christos /* Unused (7, 1). 386 1.1 christos While there's a shorter sequence, e.g. LAPCQ + an ADDQ or SUBQ, 387 1.1 christos that would affect flags, so we can't do that as it wouldn't be a 388 1.1 christos proper insn expansion of LAPCQ. This row is associated with a 389 1.1 christos 2-byte expansion, so it's unused rather than the next. */ 390 1.1 christos {1, 1, 0, 0}, 391 1.1 christos 392 1.1 christos /* LAPC: LAPC.D (7, 2). */ 393 1.1 christos {0, 0, 4, 0}, 394 1.1 christos 395 1.1 christos /* Unused (7, 3). */ 396 1.1 christos {1, 1, 0, 0}, 397 1.1 christos 398 1.1 christos /* PIC for pre-v32: Bcc o (8, 0). */ 399 1.1 christos {BRANCH_BF, BRANCH_BB, 0, ENCODE_RELAX (STATE_COND_BRANCH_PIC, 1)}, 400 1.1 christos 401 1.1 christos /* Bcc [PC+] (8, 1). */ 402 1.1 christos {BRANCH_WF, BRANCH_WB, 2, ENCODE_RELAX (STATE_COND_BRANCH_PIC, 2)}, 403 1.1 christos 404 1.1 christos /* 32-bit expansion, PIC (8, 2). */ 405 1.1 christos {0, 0, 12, 0}, 406 1.1 christos 407 1.1 christos /* Unused (8, 3). */ 408 1.1 christos {1, 1, 0, 0} 409 1.1 christos }; 410 1.1 christos 411 1.1 christos #undef BDAP_BF 412 1.1 christos #undef BDAP_BB 413 1.1 christos #undef BDAP_WF 414 1.1 christos #undef BDAP_WB 415 1.1 christos 416 1.1 christos /* Target-specific multicharacter options, not const-declared. */ 417 1.10 christos const struct option md_longopts[] = 418 1.1 christos { 419 1.1 christos #define OPTION_NO_US (OPTION_MD_BASE + 0) 420 1.1 christos {"no-underscore", no_argument, NULL, OPTION_NO_US}, 421 1.1 christos #define OPTION_US (OPTION_MD_BASE + 1) 422 1.1 christos {"underscore", no_argument, NULL, OPTION_US}, 423 1.1 christos #define OPTION_PIC (OPTION_US + 1) 424 1.1 christos {"pic", no_argument, NULL, OPTION_PIC}, 425 1.1 christos #define OPTION_MULBUG_ABORT_ON (OPTION_PIC + 1) 426 1.1 christos {"mul-bug-abort", no_argument, NULL, OPTION_MULBUG_ABORT_ON}, 427 1.1 christos #define OPTION_MULBUG_ABORT_OFF (OPTION_MULBUG_ABORT_ON + 1) 428 1.1 christos {"no-mul-bug-abort", no_argument, NULL, OPTION_MULBUG_ABORT_OFF}, 429 1.1 christos #define OPTION_ARCH (OPTION_MULBUG_ABORT_OFF + 1) 430 1.1 christos {"march", required_argument, NULL, OPTION_ARCH}, 431 1.1 christos {NULL, no_argument, NULL, 0} 432 1.1 christos }; 433 1.1 christos 434 1.1 christos /* Not const-declared. */ 435 1.10 christos const size_t md_longopts_size = sizeof (md_longopts); 436 1.10 christos const char md_shortopts[] = "hHN"; 437 1.1 christos 438 1.1 christos /* At first glance, this may seems wrong and should be 4 (ba + nop); but 439 1.1 christos since a short_jump must skip a *number* of long jumps, it must also be 440 1.1 christos a long jump. Here, we hope to make it a "ba [16bit_offs]" and a "nop" 441 1.1 christos for the delay slot and hope that the jump table at most needs 442 1.1 christos 32767/4=8191 long-jumps. A branch is better than a jump, since it is 443 1.1 christos relative; we will not have a reloc to fix up somewhere. 444 1.1 christos 445 1.1 christos Note that we can't add relocs, because relaxation uses these fixed 446 1.1 christos numbers, and md_create_short_jump is called after relaxation. */ 447 1.1 christos 448 1.1 christos int md_short_jump_size = 6; 449 1.1 christos 450 1.1 christos /* The v32 version has a delay-slot, hence two bytes longer. 451 1.1 christos The pre-v32 PIC version uses a prefixed insn. */ 452 1.1 christos #define cris_any_v0_v10_long_jump_size 6 453 1.1 christos #define cris_any_v0_v10_long_jump_size_pic 8 454 1.1 christos #define crisv32_long_jump_size 8 455 1.1 christos 456 1.1 christos int md_long_jump_size = XCONCAT2 (DEFAULT_CRIS_ARCH,_long_jump_size); 457 1.1 christos 458 1.1 christos /* Report output format. Small changes in output format (like elf 459 1.1 christos variants below) can happen until all options are parsed, but after 460 1.1 christos that, the output format must remain fixed. */ 461 1.1 christos 462 1.1 christos const char * 463 1.1 christos cris_target_format (void) 464 1.1 christos { 465 1.1 christos switch (OUTPUT_FLAVOR) 466 1.1 christos { 467 1.1 christos case bfd_target_aout_flavour: 468 1.1 christos return "a.out-cris"; 469 1.1 christos 470 1.1 christos case bfd_target_elf_flavour: 471 1.1 christos if (symbols_have_leading_underscore) 472 1.1 christos return "elf32-us-cris"; 473 1.1 christos return "elf32-cris"; 474 1.1 christos 475 1.1 christos default: 476 1.1 christos abort (); 477 1.1 christos return NULL; 478 1.1 christos } 479 1.1 christos } 480 1.1 christos 481 1.1 christos /* Return a bfd_mach_cris... value corresponding to the value of 482 1.1 christos cris_arch. */ 483 1.1 christos 484 1.1 christos unsigned int 485 1.1 christos cris_mach (void) 486 1.1 christos { 487 1.1 christos unsigned int retval = 0; 488 1.1 christos 489 1.1 christos switch (cris_arch) 490 1.1 christos { 491 1.1 christos case arch_cris_common_v10_v32: 492 1.1 christos retval = bfd_mach_cris_v10_v32; 493 1.1 christos break; 494 1.1 christos 495 1.1 christos case arch_crisv32: 496 1.1 christos retval = bfd_mach_cris_v32; 497 1.1 christos break; 498 1.1 christos 499 1.1 christos case arch_crisv10: 500 1.1 christos case arch_cris_any_v0_v10: 501 1.1 christos retval = bfd_mach_cris_v0_v10; 502 1.1 christos break; 503 1.1 christos 504 1.1 christos default: 505 1.1 christos BAD_CASE (cris_arch); 506 1.1 christos } 507 1.1 christos 508 1.1 christos return retval; 509 1.1 christos } 510 1.1 christos 511 1.1 christos /* We need a port-specific relaxation function to cope with sym2 - sym1 512 1.1 christos relative expressions with both symbols in the same segment (but not 513 1.1 christos necessarily in the same frag as this insn), for example: 514 1.1 christos move.d [pc+sym2-(sym1-2)],r10 515 1.1 christos sym1: 516 1.1 christos The offset can be 8, 16 or 32 bits long. */ 517 1.1 christos 518 1.1 christos long 519 1.1 christos cris_relax_frag (segT seg ATTRIBUTE_UNUSED, fragS *fragP, 520 1.1 christos long stretch ATTRIBUTE_UNUSED) 521 1.1 christos { 522 1.1 christos long growth; 523 1.1 christos offsetT aim = 0; 524 1.1 christos symbolS *symbolP; 525 1.1 christos const relax_typeS *this_type; 526 1.1 christos const relax_typeS *start_type; 527 1.1 christos relax_substateT next_state; 528 1.1 christos relax_substateT this_state; 529 1.1 christos const relax_typeS *table = TC_GENERIC_RELAX_TABLE; 530 1.1 christos 531 1.1 christos /* We only have to cope with frags as prepared by 532 1.1 christos md_estimate_size_before_relax. The dword cases may get here 533 1.1 christos because of the different reasons that they aren't relaxable. */ 534 1.1 christos switch (fragP->fr_subtype) 535 1.1 christos { 536 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_DWORD): 537 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD): 538 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD): 539 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD): 540 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD): 541 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_DWORD): 542 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD): 543 1.1 christos /* When we get to these states, the frag won't grow any more. */ 544 1.1 christos return 0; 545 1.1 christos 546 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD): 547 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE): 548 1.1 christos if (fragP->fr_symbol == NULL 549 1.1 christos || S_GET_SEGMENT (fragP->fr_symbol) != absolute_section) 550 1.1 christos as_fatal (_("internal inconsistency problem in %s: fr_symbol %lx"), 551 1.9 christos __func__, (long) fragP->fr_symbol); 552 1.1 christos symbolP = fragP->fr_symbol; 553 1.1 christos if (symbol_resolved_p (symbolP)) 554 1.1 christos as_fatal (_("internal inconsistency problem in %s: resolved symbol"), 555 1.9 christos __func__); 556 1.1 christos aim = S_GET_VALUE (symbolP); 557 1.1 christos break; 558 1.1 christos 559 1.1 christos case ENCODE_RELAX (STATE_MUL, STATE_BYTE): 560 1.1 christos /* Nothing to do here. */ 561 1.1 christos return 0; 562 1.1 christos 563 1.1 christos default: 564 1.1 christos as_fatal (_("internal inconsistency problem in %s: fr_subtype %d"), 565 1.9 christos __func__, fragP->fr_subtype); 566 1.1 christos } 567 1.1 christos 568 1.1 christos /* The rest is stolen from relax_frag. There's no obvious way to 569 1.1 christos share the code, but fortunately no requirement to keep in sync as 570 1.1 christos long as fragP->fr_symbol does not have its segment changed. */ 571 1.1 christos 572 1.1 christos this_state = fragP->fr_subtype; 573 1.1 christos start_type = this_type = table + this_state; 574 1.1 christos 575 1.1 christos if (aim < 0) 576 1.1 christos { 577 1.1 christos /* Look backwards. */ 578 1.1 christos for (next_state = this_type->rlx_more; next_state;) 579 1.1 christos if (aim >= this_type->rlx_backward) 580 1.1 christos next_state = 0; 581 1.1 christos else 582 1.1 christos { 583 1.1 christos /* Grow to next state. */ 584 1.1 christos this_state = next_state; 585 1.1 christos this_type = table + this_state; 586 1.1 christos next_state = this_type->rlx_more; 587 1.1 christos } 588 1.1 christos } 589 1.1 christos else 590 1.1 christos { 591 1.1 christos /* Look forwards. */ 592 1.1 christos for (next_state = this_type->rlx_more; next_state;) 593 1.1 christos if (aim <= this_type->rlx_forward) 594 1.1 christos next_state = 0; 595 1.1 christos else 596 1.1 christos { 597 1.1 christos /* Grow to next state. */ 598 1.1 christos this_state = next_state; 599 1.1 christos this_type = table + this_state; 600 1.1 christos next_state = this_type->rlx_more; 601 1.1 christos } 602 1.1 christos } 603 1.1 christos 604 1.1 christos growth = this_type->rlx_length - start_type->rlx_length; 605 1.1 christos if (growth != 0) 606 1.1 christos fragP->fr_subtype = this_state; 607 1.1 christos return growth; 608 1.1 christos } 609 1.1 christos 610 1.1 christos /* Prepare machine-dependent frags for relaxation. 611 1.1 christos 612 1.1 christos Called just before relaxation starts. Any symbol that is now undefined 613 1.1 christos will not become defined. 614 1.1 christos 615 1.1 christos Return the correct fr_subtype in the frag. 616 1.1 christos 617 1.1 christos Return the initial "guess for fr_var" to caller. The guess for fr_var 618 1.1 christos is *actually* the growth beyond fr_fix. Whatever we do to grow fr_fix 619 1.1 christos or fr_var contributes to our returned value. 620 1.1 christos 621 1.1 christos Although it may not be explicit in the frag, pretend 622 1.1 christos fr_var starts with a value. */ 623 1.1 christos 624 1.1 christos int 625 1.1 christos md_estimate_size_before_relax (fragS *fragP, segT segment_type) 626 1.1 christos { 627 1.1 christos int old_fr_fix; 628 1.1 christos symbolS *symbolP = fragP->fr_symbol; 629 1.1 christos 630 1.1 christos #define HANDLE_RELAXABLE(state) \ 631 1.1 christos case ENCODE_RELAX (state, STATE_UNDF): \ 632 1.1 christos if (symbolP != NULL \ 633 1.1 christos && S_GET_SEGMENT (symbolP) == segment_type \ 634 1.1 christos && !S_IS_WEAK (symbolP)) \ 635 1.1 christos /* The symbol lies in the same segment - a relaxable \ 636 1.1 christos case. */ \ 637 1.1 christos fragP->fr_subtype \ 638 1.1 christos = ENCODE_RELAX (state, STATE_BYTE); \ 639 1.1 christos else \ 640 1.1 christos /* Unknown or not the same segment, so not relaxable. */ \ 641 1.1 christos fragP->fr_subtype \ 642 1.1 christos = ENCODE_RELAX (state, STATE_DWORD); \ 643 1.1 christos fragP->fr_var \ 644 1.1 christos = md_cris_relax_table[fragP->fr_subtype].rlx_length; \ 645 1.1 christos break 646 1.1 christos 647 1.1 christos old_fr_fix = fragP->fr_fix; 648 1.1 christos 649 1.1 christos switch (fragP->fr_subtype) 650 1.1 christos { 651 1.1 christos HANDLE_RELAXABLE (STATE_COND_BRANCH); 652 1.1 christos HANDLE_RELAXABLE (STATE_COND_BRANCH_V32); 653 1.1 christos HANDLE_RELAXABLE (STATE_COND_BRANCH_COMMON); 654 1.1 christos HANDLE_RELAXABLE (STATE_COND_BRANCH_PIC); 655 1.1 christos HANDLE_RELAXABLE (STATE_ABS_BRANCH_V32); 656 1.1 christos 657 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_UNDF): 658 1.1 christos if (symbolP != NULL 659 1.1 christos && S_GET_SEGMENT (symbolP) == segment_type 660 1.1 christos && !S_IS_WEAK (symbolP)) 661 1.1 christos { 662 1.1 christos /* The symbol lies in the same segment - a relaxable case. 663 1.1 christos Check if we currently have an odd offset; we can't code 664 1.1 christos that into the instruction. Relaxing presumably only cause 665 1.1 christos multiple-of-two changes, so we should only need to adjust 666 1.1 christos for that here. */ 667 1.1 christos bfd_vma target_address 668 1.1 christos = (symbolP 669 1.1 christos ? S_GET_VALUE (symbolP) 670 1.1 christos : 0) + fragP->fr_offset; 671 1.1 christos bfd_vma var_part_offset = fragP->fr_fix; 672 1.1 christos bfd_vma address_of_var_part = fragP->fr_address + var_part_offset; 673 1.1 christos long offset = target_address - (address_of_var_part - 2); 674 1.1 christos 675 1.1 christos fragP->fr_subtype 676 1.1 christos = (offset & 1) 677 1.1 christos ? ENCODE_RELAX (STATE_LAPC, STATE_DWORD) 678 1.1 christos : ENCODE_RELAX (STATE_LAPC, STATE_BYTE); 679 1.1 christos } 680 1.1 christos else 681 1.1 christos /* Unknown or not the same segment, so not relaxable. */ 682 1.1 christos fragP->fr_subtype 683 1.1 christos = ENCODE_RELAX (STATE_LAPC, STATE_DWORD); 684 1.1 christos fragP->fr_var 685 1.1 christos = md_cris_relax_table[fragP->fr_subtype].rlx_length; 686 1.1 christos break; 687 1.1 christos 688 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF): 689 1.1 christos /* Note that we can not do anything sane with relaxing 690 1.1 christos [rX + a_known_symbol_in_text], it will have to be a 32-bit 691 1.1 christos value. 692 1.1 christos 693 1.1 christos We could play tricks with managing a constant pool and make 694 1.1 christos a_known_symbol_in_text a "bdap [pc + offset]" pointing there 695 1.1 christos (like the GOT for ELF shared libraries), but that's no use, it 696 1.1 christos would in general be no shorter or faster code, only more 697 1.1 christos complicated. */ 698 1.1 christos 699 1.1 christos if (S_GET_SEGMENT (symbolP) != absolute_section) 700 1.1 christos { 701 1.1 christos /* Go for dword if not absolute or same segment. */ 702 1.1 christos fragP->fr_subtype 703 1.1 christos = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD); 704 1.1 christos fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length; 705 1.1 christos } 706 1.1 christos else if (!symbol_resolved_p (fragP->fr_symbol)) 707 1.1 christos { 708 1.1 christos /* The symbol will eventually be completely resolved as an 709 1.1 christos absolute expression, but right now it depends on the result 710 1.1 christos of relaxation and we don't know anything else about the 711 1.1 christos value. We start relaxation with the assumption that it'll 712 1.1 christos fit in a byte. */ 713 1.1 christos fragP->fr_subtype 714 1.1 christos = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE); 715 1.1 christos fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length; 716 1.1 christos } 717 1.1 christos else 718 1.1 christos { 719 1.1 christos /* Absolute expression. */ 720 1.1 christos long int value; 721 1.1 christos value = (symbolP != NULL 722 1.1 christos ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset; 723 1.1 christos 724 1.1 christos if (value >= -128 && value <= 127) 725 1.1 christos { 726 1.1 christos /* Byte displacement. */ 727 1.1 christos (fragP->fr_opcode)[0] = value; 728 1.1 christos } 729 1.1 christos else 730 1.1 christos { 731 1.1 christos /* Word or dword displacement. */ 732 1.1 christos int pow2_of_size = 1; 733 1.1 christos char *writep; 734 1.1 christos 735 1.1 christos if (value < -32768 || value > 32767) 736 1.1 christos { 737 1.1 christos /* Outside word range, make it a dword. */ 738 1.1 christos pow2_of_size = 2; 739 1.1 christos } 740 1.1 christos 741 1.1 christos /* Modify the byte-offset BDAP into a word or dword offset 742 1.1 christos BDAP. Or really, a BDAP rX,8bit into a 743 1.1 christos BDAP.[wd] rX,[PC+] followed by a word or dword. */ 744 1.1 christos (fragP->fr_opcode)[0] = BDAP_PC_LOW + pow2_of_size * 16; 745 1.1 christos 746 1.1 christos /* Keep the register number in the highest four bits. */ 747 1.1 christos (fragP->fr_opcode)[1] &= 0xF0; 748 1.1 christos (fragP->fr_opcode)[1] |= BDAP_INCR_HIGH; 749 1.1 christos 750 1.1 christos /* It grew by two or four bytes. */ 751 1.1 christos fragP->fr_fix += 1 << pow2_of_size; 752 1.1 christos writep = fragP->fr_literal + old_fr_fix; 753 1.1 christos md_number_to_chars (writep, value, 1 << pow2_of_size); 754 1.1 christos } 755 1.1 christos frag_wane (fragP); 756 1.1 christos } 757 1.1 christos break; 758 1.1 christos 759 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_BYTE): 760 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_WORD): 761 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD): 762 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_BYTE): 763 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_WORD): 764 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_DWORD): 765 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_BYTE): 766 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_WORD): 767 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD): 768 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_BYTE): 769 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_WORD): 770 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD): 771 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_BYTE): 772 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_WORD): 773 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD): 774 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_BYTE): 775 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_DWORD): 776 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE): 777 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD): 778 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD): 779 1.1 christos /* When relaxing a section for the second time, we don't need to 780 1.1 christos do anything except making sure that fr_var is set right. */ 781 1.1 christos fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length; 782 1.1 christos break; 783 1.1 christos 784 1.1 christos case ENCODE_RELAX (STATE_MUL, STATE_BYTE): 785 1.1 christos /* Nothing to do here. */ 786 1.1 christos break; 787 1.1 christos 788 1.1 christos default: 789 1.1 christos BAD_CASE (fragP->fr_subtype); 790 1.1 christos } 791 1.1 christos 792 1.1 christos return fragP->fr_var + (fragP->fr_fix - old_fr_fix); 793 1.1 christos } 794 1.1 christos 795 1.1 christos /* Perform post-processing of machine-dependent frags after relaxation. 796 1.1 christos Called after relaxation is finished. 797 1.1 christos In: Address of frag. 798 1.1 christos fr_type == rs_machine_dependent. 799 1.1 christos fr_subtype is what the address relaxed to. 800 1.1 christos 801 1.1 christos Out: Any fixS:s and constants are set up. 802 1.1 christos 803 1.1 christos The caller will turn the frag into a ".space 0". */ 804 1.1 christos 805 1.1 christos void 806 1.1 christos md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED, 807 1.1 christos fragS *fragP) 808 1.1 christos { 809 1.1 christos /* Pointer to first byte in variable-sized part of the frag. */ 810 1.1 christos char *var_partp; 811 1.1 christos 812 1.1 christos /* Pointer to first opcode byte in frag. */ 813 1.1 christos char *opcodep; 814 1.1 christos 815 1.1 christos /* Used to check integrity of the relaxation. 816 1.1 christos One of 2 = long, 1 = word, or 0 = byte. */ 817 1.1 christos int length_code ATTRIBUTE_UNUSED; 818 1.1 christos 819 1.1 christos /* Size in bytes of variable-sized part of frag. */ 820 1.1 christos int var_part_size = 0; 821 1.1 christos 822 1.1 christos /* This is part of *fragP. It contains all information about addresses 823 1.1 christos and offsets to varying parts. */ 824 1.1 christos symbolS *symbolP; 825 1.1 christos unsigned long var_part_offset; 826 1.1 christos 827 1.1 christos /* Where, in file space, is _var of *fragP? */ 828 1.1 christos unsigned long address_of_var_part = 0; 829 1.1 christos 830 1.1 christos /* Where, in file space, does addr point? */ 831 1.1 christos unsigned long target_address; 832 1.1 christos 833 1.1 christos know (fragP->fr_type == rs_machine_dependent); 834 1.1 christos 835 1.1 christos length_code = fragP->fr_subtype & STATE_LENGTH_MASK; 836 1.1 christos know (length_code >= 0 && length_code < STATE_MAX_LENGTH); 837 1.1 christos 838 1.1 christos var_part_offset = fragP->fr_fix; 839 1.1 christos var_partp = fragP->fr_literal + var_part_offset; 840 1.1 christos opcodep = fragP->fr_opcode; 841 1.1 christos 842 1.1 christos symbolP = fragP->fr_symbol; 843 1.1 christos target_address = (symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset; 844 1.1 christos address_of_var_part = fragP->fr_address + var_part_offset; 845 1.1 christos 846 1.1 christos switch (fragP->fr_subtype) 847 1.1 christos { 848 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_BYTE): 849 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_BYTE): 850 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_BYTE): 851 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_BYTE): 852 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_BYTE): 853 1.1 christos opcodep[0] = branch_disp ((target_address - address_of_var_part)); 854 1.1 christos var_part_size = 0; 855 1.1 christos break; 856 1.1 christos 857 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_WORD): 858 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_WORD): 859 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_WORD): 860 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_WORD): 861 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_WORD): 862 1.1 christos /* We had a quick immediate branch, now turn it into a word one i.e. a 863 1.1 christos PC autoincrement. */ 864 1.1 christos opcodep[0] = BRANCH_PC_LOW; 865 1.1 christos opcodep[1] &= 0xF0; 866 1.1 christos opcodep[1] |= BRANCH_INCR_HIGH; 867 1.1 christos md_number_to_chars (var_partp, 868 1.1 christos (long) 869 1.1 christos (target_address 870 1.1 christos - (address_of_var_part 871 1.1 christos + (cris_arch == arch_crisv32 872 1.1 christos || cris_arch == arch_cris_common_v10_v32 873 1.1 christos ? -2 : 2))), 874 1.1 christos 2); 875 1.1 christos var_part_size = 2; 876 1.1 christos break; 877 1.1 christos 878 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD): 879 1.1 christos gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP, 880 1.10 christos fragP->fr_symbol, NULL, 881 1.1 christos fragP->fr_offset); 882 1.1 christos /* Ten bytes added: a branch, nop and a jump. */ 883 1.1 christos var_part_size = 2 + 2 + 4 + 2; 884 1.1 christos break; 885 1.1 christos 886 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_DWORD): 887 1.1 christos gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP, 888 1.10 christos fragP->fr_symbol, NULL, 889 1.1 christos fragP->fr_offset); 890 1.1 christos /* Twelve bytes added: a branch, nop and a pic-branch-32. */ 891 1.1 christos var_part_size = 2 + 2 + 4 + 2 + 2; 892 1.1 christos break; 893 1.1 christos 894 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD): 895 1.1 christos gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP, 896 1.10 christos fragP->fr_symbol, NULL, 897 1.1 christos fragP->fr_offset); 898 1.1 christos /* Twelve bytes added: a branch, nop and another branch and nop. */ 899 1.1 christos var_part_size = 2 + 2 + 2 + 4 + 2; 900 1.1 christos break; 901 1.1 christos 902 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD): 903 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line, 904 1.1 christos _("Relaxation to long branches for .arch common_v10_v32\ 905 1.1 christos not implemented")); 906 1.1 christos /* Pretend we have twelve bytes for sake of quelling further 907 1.1 christos errors. */ 908 1.1 christos var_part_size = 2 + 2 + 2 + 4 + 2; 909 1.1 christos break; 910 1.1 christos 911 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD): 912 1.1 christos /* We had a quick immediate branch or a word immediate ba. Now 913 1.1 christos turn it into a dword one. */ 914 1.1 christos opcodep[0] = BA_DWORD_OPCODE & 255; 915 1.1 christos opcodep[1] = (BA_DWORD_OPCODE >> 8) & 255; 916 1.1 christos fix_new (fragP, var_partp - fragP->fr_literal, 4, symbolP, 917 1.1 christos fragP->fr_offset + 6, 1, BFD_RELOC_32_PCREL); 918 1.1 christos var_part_size = 4; 919 1.1 christos break; 920 1.1 christos 921 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_BYTE): 922 1.1 christos { 923 1.1 christos long offset = target_address - (address_of_var_part - 2); 924 1.1 christos 925 1.1 christos /* This is mostly a sanity check; useful occurrences (if there 926 1.1 christos really are any) should have been caught in 927 1.1 christos md_estimate_size_before_relax. We can (at least 928 1.1 christos theoretically) stumble over invalid code with odd sizes and 929 1.1 christos .p2aligns within the code, so emit an error if that happens. 930 1.1 christos (The generic relaxation machinery is not fit to check this.) */ 931 1.1 christos 932 1.1 christos if (offset & 1) 933 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line, 934 1.1 christos _("Complicated LAPC target operand is not\ 935 1.1 christos a multiple of two. Use LAPC.D")); 936 1.1 christos 937 1.1 christos /* FIXME: This *is* a sanity check. Remove when done with. */ 938 1.1 christos if (offset > 15*2 || offset < 0) 939 1.1 christos as_fatal (_("Internal error found in md_convert_frag: offset %ld.\ 940 1.1 christos Please report this."), 941 1.1 christos offset); 942 1.1 christos 943 1.1 christos opcodep[0] |= (offset / 2) & 0xf; 944 1.1 christos var_part_size = 0; 945 1.1 christos } 946 1.1 christos break; 947 1.1 christos 948 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_DWORD): 949 1.1 christos { 950 1.1 christos md_number_to_chars (opcodep, 951 1.1 christos LAPC_DWORD_OPCODE + (opcodep[1] & 0xf0) * 256, 952 1.1 christos 2); 953 1.1 christos /* Remember that the reloc is against the position *after* the 954 1.1 christos relocated contents, so we need to adjust to the start of 955 1.1 christos the insn. */ 956 1.1 christos fix_new (fragP, var_partp - fragP->fr_literal, 4, fragP->fr_symbol, 957 1.1 christos fragP->fr_offset + 6, 1, BFD_RELOC_32_PCREL); 958 1.1 christos var_part_size = 4; 959 1.1 christos } 960 1.1 christos break; 961 1.1 christos 962 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE): 963 1.1 christos if (symbolP == NULL) 964 1.1 christos as_fatal (_("internal inconsistency in %s: bdapq no symbol"), 965 1.9 christos __func__); 966 1.1 christos opcodep[0] = S_GET_VALUE (symbolP); 967 1.1 christos var_part_size = 0; 968 1.1 christos break; 969 1.1 christos 970 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD): 971 1.1 christos /* We had a BDAP 8-bit "quick immediate", now turn it into a 16-bit 972 1.1 christos one that uses PC autoincrement. */ 973 1.1 christos opcodep[0] = BDAP_PC_LOW + (1 << 4); 974 1.1 christos opcodep[1] &= 0xF0; 975 1.1 christos opcodep[1] |= BDAP_INCR_HIGH; 976 1.1 christos if (symbolP == NULL) 977 1.1 christos as_fatal (_("internal inconsistency in %s: bdap.w with no symbol"), 978 1.9 christos __func__); 979 1.1 christos md_number_to_chars (var_partp, S_GET_VALUE (symbolP), 2); 980 1.1 christos var_part_size = 2; 981 1.1 christos break; 982 1.1 christos 983 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD): 984 1.1 christos /* We had a BDAP 16-bit "word", change the offset to a dword. */ 985 1.1 christos opcodep[0] = BDAP_PC_LOW + (2 << 4); 986 1.1 christos opcodep[1] &= 0xF0; 987 1.1 christos opcodep[1] |= BDAP_INCR_HIGH; 988 1.1 christos if (fragP->fr_symbol == NULL) 989 1.1 christos md_number_to_chars (var_partp, fragP->fr_offset, 4); 990 1.1 christos else 991 1.1 christos fix_new (fragP, var_partp - fragP->fr_literal, 4, fragP->fr_symbol, 992 1.1 christos fragP->fr_offset, 0, BFD_RELOC_32); 993 1.1 christos var_part_size = 4; 994 1.1 christos break; 995 1.1 christos 996 1.1 christos case ENCODE_RELAX (STATE_MUL, STATE_BYTE): 997 1.1 christos /* This is the only time we check position and alignment of the 998 1.1 christos placement-tracking frag. */ 999 1.1 christos if (sec->alignment_power < 2) 1000 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line, 1001 1.1 christos _("section alignment must be >= 4 bytes to check MULS/MULU safeness")); 1002 1.1 christos else 1003 1.1 christos { 1004 1.1 christos /* If the address after the MULS/MULU has alignment which is 1005 1.1 christos that of the section and may be that of a cache-size of the 1006 1.1 christos buggy versions, then the MULS/MULU can be placed badly. */ 1007 1.1 christos if ((address_of_var_part 1008 1.1 christos & ((1 << sec->alignment_power) - 1) & 31) == 0) 1009 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line, 1010 1.1 christos _("dangerous MULS/MULU location; give it higher alignment")); 1011 1.1 christos } 1012 1.1 christos break; 1013 1.1 christos 1014 1.1 christos default: 1015 1.1 christos BAD_CASE (fragP->fr_subtype); 1016 1.1 christos break; 1017 1.1 christos } 1018 1.1 christos 1019 1.1 christos fragP->fr_fix += var_part_size; 1020 1.1 christos } 1021 1.1 christos 1022 1.1 christos /* Generate a short jump around a secondary jump table. 1023 1.1 christos Also called from md_create_long_jump, when sufficient. */ 1024 1.1 christos 1025 1.1 christos void 1026 1.1 christos md_create_short_jump (char *storep, addressT from_addr, addressT to_addr, 1027 1.1 christos fragS *fragP ATTRIBUTE_UNUSED, 1028 1.1 christos symbolS *to_symbol ATTRIBUTE_UNUSED) 1029 1.1 christos { 1030 1.1 christos long int distance; 1031 1.1 christos 1032 1.1 christos /* See md_create_long_jump about the comment on the "+ 2". */ 1033 1.1 christos long int max_minimal_minus_distance; 1034 1.1 christos long int max_minimal_plus_distance; 1035 1.1 christos long int max_minus_distance; 1036 1.1 christos long int max_plus_distance; 1037 1.1 christos int nop_opcode; 1038 1.1 christos 1039 1.1 christos if (cris_arch == arch_crisv32) 1040 1.1 christos { 1041 1.1 christos max_minimal_minus_distance = BRANCH_BB_V32 + 2; 1042 1.1 christos max_minimal_plus_distance = BRANCH_BF_V32 + 2; 1043 1.1 christos max_minus_distance = BRANCH_WB_V32 + 2; 1044 1.1 christos max_plus_distance = BRANCH_WF_V32 + 2; 1045 1.1 christos nop_opcode = NOP_OPCODE_V32; 1046 1.1 christos } 1047 1.1 christos else if (cris_arch == arch_cris_common_v10_v32) 1048 1.1 christos /* Bail out for compatibility mode. (It seems it can be implemented, 1049 1.1 christos perhaps with a 10-byte sequence: "move.d NNNN,$pc/$acr", "jump 1050 1.1 christos $acr", "nop"; but doesn't seem worth it at the moment.) */ 1051 1.1 christos as_fatal (_("Out-of-range .word offset handling\ 1052 1.1 christos is not implemented for .arch common_v10_v32")); 1053 1.1 christos else 1054 1.1 christos { 1055 1.1 christos max_minimal_minus_distance = BRANCH_BB + 2; 1056 1.1 christos max_minimal_plus_distance = BRANCH_BF + 2; 1057 1.1 christos max_minus_distance = BRANCH_WB + 2; 1058 1.1 christos max_plus_distance = BRANCH_WF + 2; 1059 1.1 christos nop_opcode = NOP_OPCODE; 1060 1.1 christos } 1061 1.1 christos 1062 1.1 christos distance = to_addr - from_addr; 1063 1.1 christos 1064 1.1 christos if (max_minimal_minus_distance <= distance 1065 1.1 christos && distance <= max_minimal_plus_distance) 1066 1.1 christos { 1067 1.1 christos /* Create a "short" short jump: "BA distance - 2". */ 1068 1.1 christos storep[0] = branch_disp (distance - 2); 1069 1.1 christos storep[1] = BA_QUICK_HIGH; 1070 1.1 christos 1071 1.1 christos /* A nop for the delay slot. */ 1072 1.1 christos md_number_to_chars (storep + 2, nop_opcode, 2); 1073 1.1 christos 1074 1.1 christos /* The extra word should be filled with something sane too. Make it 1075 1.1 christos a nop to keep disassembly sane. */ 1076 1.1 christos md_number_to_chars (storep + 4, nop_opcode, 2); 1077 1.1 christos } 1078 1.1 christos else if (max_minus_distance <= distance 1079 1.1 christos && distance <= max_plus_distance) 1080 1.1 christos { 1081 1.1 christos /* Make it a "long" short jump: "BA (PC+)". */ 1082 1.1 christos md_number_to_chars (storep, BA_PC_INCR_OPCODE, 2); 1083 1.1 christos 1084 1.1 christos /* ".WORD distance - 4". */ 1085 1.1 christos md_number_to_chars (storep + 2, 1086 1.1 christos (long) (distance - 4 1087 1.1 christos - (cris_arch == arch_crisv32 1088 1.1 christos ? -4 : 0)), 1089 1.1 christos 2); 1090 1.1 christos 1091 1.1 christos /* A nop for the delay slot. */ 1092 1.1 christos md_number_to_chars (storep + 4, nop_opcode, 2); 1093 1.1 christos } 1094 1.1 christos else 1095 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line, 1096 1.1 christos _(".word case-table handling failed: table too large")); 1097 1.1 christos } 1098 1.1 christos 1099 1.1 christos /* Generate a long jump in a secondary jump table. 1100 1.1 christos 1101 1.1 christos storep Where to store the jump instruction. 1102 1.1 christos from_addr Address of the jump instruction. 1103 1.1 christos to_addr Destination address of the jump. 1104 1.1 christos fragP Which frag the destination address operand 1105 1.1 christos lies in. 1106 1.1 christos to_symbol Destination symbol. */ 1107 1.1 christos 1108 1.1 christos void 1109 1.1 christos md_create_long_jump (char *storep, addressT from_addr, addressT to_addr, 1110 1.1 christos fragS *fragP, symbolS *to_symbol) 1111 1.1 christos { 1112 1.1 christos long int distance; 1113 1.1 christos 1114 1.1 christos /* FIXME: What's that "+ 3"? It comes from the magic numbers that 1115 1.1 christos used to be here, it's just translated to the limit macros used in 1116 1.1 christos the relax table. But why + 3? */ 1117 1.1 christos long int max_short_minus_distance 1118 1.1 christos = cris_arch != arch_crisv32 ? BRANCH_WB + 3 : BRANCH_WB_V32 + 3; 1119 1.1 christos 1120 1.1 christos long int max_short_plus_distance 1121 1.1 christos = cris_arch != arch_crisv32 ? BRANCH_WF + 3 : BRANCH_WF_V32 + 3; 1122 1.1 christos 1123 1.1 christos distance = to_addr - from_addr; 1124 1.1 christos 1125 1.1 christos if (max_short_minus_distance <= distance 1126 1.1 christos && distance <= max_short_plus_distance) 1127 1.3 christos { 1128 1.3 christos /* Then make it a "short" long jump. */ 1129 1.3 christos md_create_short_jump (storep, from_addr, to_addr, fragP, 1130 1.1 christos to_symbol); 1131 1.3 christos if (cris_arch == arch_crisv32) 1132 1.3 christos md_number_to_chars (storep + 6, NOP_OPCODE_V32, 2); 1133 1.3 christos else 1134 1.3 christos md_number_to_chars (storep + 6, NOP_OPCODE, 2); 1135 1.3 christos } 1136 1.1 christos else 1137 1.1 christos { 1138 1.1 christos /* We have a "long" long jump: "JUMP [PC+]". If CRISv32, always 1139 1.1 christos make it a BA. Else make it an "MOVE [PC=PC+N],P0" if we're supposed 1140 1.1 christos to emit PIC code. */ 1141 1.1 christos md_number_to_chars (storep, 1142 1.1 christos cris_arch == arch_crisv32 1143 1.1 christos ? BA_DWORD_OPCODE 1144 1.1 christos : (pic ? MOVE_PC_INCR_OPCODE_PREFIX 1145 1.1 christos : JUMP_PC_INCR_OPCODE), 1146 1.1 christos 2); 1147 1.1 christos 1148 1.1 christos /* Follow with a ".DWORD to_addr", PC-relative for PIC. */ 1149 1.1 christos fix_new (fragP, storep + 2 - fragP->fr_literal, 4, to_symbol, 1150 1.1 christos cris_arch == arch_crisv32 ? 6 : 0, 1151 1.1 christos cris_arch == arch_crisv32 || pic ? 1 : 0, 1152 1.1 christos cris_arch == arch_crisv32 || pic 1153 1.1 christos ? BFD_RELOC_32_PCREL : BFD_RELOC_32); 1154 1.1 christos 1155 1.1 christos /* Follow it with a "NOP" for CRISv32. */ 1156 1.1 christos if (cris_arch == arch_crisv32) 1157 1.1 christos md_number_to_chars (storep + 6, NOP_OPCODE_V32, 2); 1158 1.1 christos else if (pic) 1159 1.1 christos /* ...and the rest of the move-opcode for pre-v32 PIC. */ 1160 1.1 christos md_number_to_chars (storep + 6, MOVE_PC_INCR_OPCODE_SUFFIX, 2); 1161 1.1 christos } 1162 1.1 christos } 1163 1.1 christos 1164 1.1 christos /* Allocate space for the first piece of an insn, and mark it as the 1165 1.1 christos start of the insn for debug-format use. */ 1166 1.1 christos 1167 1.1 christos static char * 1168 1.1 christos cris_insn_first_word_frag (void) 1169 1.1 christos { 1170 1.1 christos char *insnp = frag_more (2); 1171 1.1 christos 1172 1.1 christos /* We need to mark the start of the insn by passing dwarf2_emit_insn 1173 1.1 christos the offset from the current fragment position. This must be done 1174 1.1 christos after the first fragment is created but before any other fragments 1175 1.1 christos (fixed or varying) are created. Note that the offset only 1176 1.1 christos corresponds to the "size" of the insn for a fixed-size, 1177 1.1 christos non-expanded insn. */ 1178 1.1 christos if (OUTPUT_FLAVOR == bfd_target_elf_flavour) 1179 1.1 christos dwarf2_emit_insn (2); 1180 1.1 christos 1181 1.1 christos return insnp; 1182 1.1 christos } 1183 1.1 christos 1184 1.1 christos /* Port-specific assembler initialization. */ 1185 1.1 christos 1186 1.1 christos void 1187 1.1 christos md_begin (void) 1188 1.1 christos { 1189 1.1 christos int i = 0; 1190 1.1 christos 1191 1.1 christos /* Set up a hash table for the instructions. */ 1192 1.8 christos op_hash = str_htab_create (); 1193 1.1 christos 1194 1.1 christos /* Enable use of ".if ..asm.arch.cris.v32" 1195 1.1 christos and ".if ..asm.arch.cris.common_v10_v32" and a few others. */ 1196 1.1 christos symbol_table_insert (symbol_new ("..asm.arch.cris.v32", absolute_section, 1197 1.8 christos &zero_address_frag, 1198 1.8 christos cris_arch == arch_crisv32)); 1199 1.1 christos symbol_table_insert (symbol_new ("..asm.arch.cris.v10", absolute_section, 1200 1.8 christos &zero_address_frag, 1201 1.8 christos cris_arch == arch_crisv10)); 1202 1.1 christos symbol_table_insert (symbol_new ("..asm.arch.cris.common_v10_v32", 1203 1.1 christos absolute_section, 1204 1.8 christos &zero_address_frag, 1205 1.8 christos cris_arch == arch_cris_common_v10_v32)); 1206 1.1 christos symbol_table_insert (symbol_new ("..asm.arch.cris.any_v0_v10", 1207 1.1 christos absolute_section, 1208 1.8 christos &zero_address_frag, 1209 1.8 christos cris_arch == arch_cris_any_v0_v10)); 1210 1.1 christos 1211 1.1 christos while (cris_opcodes[i].name != NULL) 1212 1.1 christos { 1213 1.1 christos const char *name = cris_opcodes[i].name; 1214 1.1 christos 1215 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_opcodes[i].applicable_version, 1216 1.1 christos cris_arch)) 1217 1.1 christos { 1218 1.1 christos i++; 1219 1.1 christos continue; 1220 1.1 christos } 1221 1.1 christos 1222 1.8 christos if (str_hash_insert (op_hash, name, &cris_opcodes[i], 0) != NULL) 1223 1.8 christos as_fatal (_("duplicate %s"), name); 1224 1.1 christos 1225 1.1 christos do 1226 1.1 christos { 1227 1.1 christos if (cris_opcodes[i].match & cris_opcodes[i].lose) 1228 1.1 christos as_fatal (_("Buggy opcode: `%s' \"%s\"\n"), cris_opcodes[i].name, 1229 1.1 christos cris_opcodes[i].args); 1230 1.1 christos 1231 1.1 christos ++i; 1232 1.1 christos } 1233 1.1 christos while (cris_opcodes[i].name != NULL 1234 1.1 christos && strcmp (cris_opcodes[i].name, name) == 0); 1235 1.1 christos } 1236 1.1 christos } 1237 1.1 christos 1238 1.1 christos /* Assemble a source line. */ 1239 1.1 christos 1240 1.1 christos void 1241 1.1 christos md_assemble (char *str) 1242 1.1 christos { 1243 1.1 christos struct cris_instruction output_instruction; 1244 1.1 christos struct cris_prefix prefix; 1245 1.1 christos char *opcodep; 1246 1.1 christos char *p; 1247 1.1 christos 1248 1.1 christos know (str); 1249 1.1 christos 1250 1.1 christos /* Do the low-level grunt - assemble to bits and split up into a prefix 1251 1.1 christos and ordinary insn. */ 1252 1.1 christos cris_process_instruction (str, &output_instruction, &prefix); 1253 1.1 christos 1254 1.1 christos /* Handle any prefixes to the instruction. */ 1255 1.1 christos switch (prefix.kind) 1256 1.1 christos { 1257 1.1 christos case PREFIX_NONE: 1258 1.1 christos break; 1259 1.1 christos 1260 1.1 christos /* When the expression is unknown for a BDAP, it can need 0, 2 or 4 1261 1.1 christos extra bytes, so we handle it separately. */ 1262 1.1 christos case PREFIX_BDAP_IMM: 1263 1.1 christos /* We only do it if the relocation is unspecified, i.e. not a PIC or TLS 1264 1.1 christos relocation. */ 1265 1.1 christos if (prefix.reloc == BFD_RELOC_NONE) 1266 1.1 christos { 1267 1.1 christos gen_bdap (prefix.base_reg_number, &prefix.expr); 1268 1.1 christos break; 1269 1.1 christos } 1270 1.1 christos /* Fall through. */ 1271 1.1 christos case PREFIX_BDAP: 1272 1.1 christos case PREFIX_BIAP: 1273 1.1 christos case PREFIX_DIP: 1274 1.1 christos opcodep = cris_insn_first_word_frag (); 1275 1.1 christos 1276 1.1 christos /* Output the prefix opcode. */ 1277 1.10 christos md_number_to_chars (opcodep, prefix.opcode, 2); 1278 1.1 christos 1279 1.1 christos /* Having a specified reloc only happens for DIP and for BDAP with 1280 1.1 christos PIC or TLS operands, but it is ok to drop through here for the other 1281 1.1 christos prefixes as they can have no relocs specified. */ 1282 1.1 christos if (prefix.reloc != BFD_RELOC_NONE) 1283 1.1 christos { 1284 1.1 christos unsigned int relocsize 1285 1.1 christos = (prefix.kind == PREFIX_DIP 1286 1.1 christos ? 4 : cris_get_specified_reloc_size (prefix.reloc)); 1287 1.1 christos 1288 1.1 christos p = frag_more (relocsize); 1289 1.1 christos fix_new_exp (frag_now, (p - frag_now->fr_literal), relocsize, 1290 1.1 christos &prefix.expr, 0, prefix.reloc); 1291 1.1 christos } 1292 1.1 christos break; 1293 1.1 christos 1294 1.1 christos case PREFIX_PUSH: 1295 1.1 christos opcodep = cris_insn_first_word_frag (); 1296 1.1 christos 1297 1.1 christos /* Output the prefix opcode. Being a "push", we add the negative 1298 1.1 christos size of the register to "sp". */ 1299 1.1 christos if (output_instruction.spec_reg != NULL) 1300 1.1 christos { 1301 1.1 christos /* Special register. */ 1302 1.1 christos opcodep[0] = -output_instruction.spec_reg->reg_size; 1303 1.1 christos } 1304 1.1 christos else 1305 1.1 christos { 1306 1.1 christos /* General register. */ 1307 1.1 christos opcodep[0] = -4; 1308 1.1 christos } 1309 1.1 christos opcodep[1] = (REG_SP << 4) + (BDAP_QUICK_OPCODE >> 8); 1310 1.1 christos break; 1311 1.1 christos 1312 1.1 christos default: 1313 1.1 christos BAD_CASE (prefix.kind); 1314 1.1 christos } 1315 1.1 christos 1316 1.1 christos /* If we only had a prefix insn, we're done. */ 1317 1.1 christos if (output_instruction.insn_type == CRIS_INSN_NONE) 1318 1.1 christos return; 1319 1.1 christos 1320 1.1 christos /* Done with the prefix. Continue with the main instruction. */ 1321 1.1 christos if (prefix.kind == PREFIX_NONE) 1322 1.1 christos opcodep = cris_insn_first_word_frag (); 1323 1.1 christos else 1324 1.1 christos opcodep = frag_more (2); 1325 1.1 christos 1326 1.1 christos /* Output the instruction opcode. */ 1327 1.10 christos md_number_to_chars (opcodep, output_instruction.opcode, 2); 1328 1.1 christos 1329 1.1 christos /* Output the symbol-dependent instruction stuff. */ 1330 1.1 christos if (output_instruction.insn_type == CRIS_INSN_BRANCH) 1331 1.1 christos { 1332 1.1 christos segT to_seg = absolute_section; 1333 1.1 christos int is_undefined = 0; 1334 1.1 christos int length_code; 1335 1.1 christos 1336 1.1 christos if (output_instruction.expr.X_op != O_constant) 1337 1.1 christos { 1338 1.1 christos to_seg = S_GET_SEGMENT (output_instruction.expr.X_add_symbol); 1339 1.1 christos 1340 1.1 christos if (to_seg == undefined_section) 1341 1.1 christos is_undefined = 1; 1342 1.1 christos } 1343 1.1 christos 1344 1.1 christos if (to_seg == now_seg || is_undefined 1345 1.1 christos /* In CRISv32, there *is* a 32-bit absolute branch, so don't 1346 1.1 christos emit the 12-byte sequence for known symbols in other 1347 1.1 christos segments. */ 1348 1.1 christos || (cris_arch == arch_crisv32 1349 1.1 christos && output_instruction.opcode == BA_QUICK_OPCODE)) 1350 1.1 christos { 1351 1.1 christos /* Handle complex expressions. */ 1352 1.1 christos valueT addvalue 1353 1.1 christos = (SIMPLE_EXPR (&output_instruction.expr) 1354 1.1 christos ? output_instruction.expr.X_add_number 1355 1.1 christos : 0); 1356 1.1 christos symbolS *sym 1357 1.1 christos = (SIMPLE_EXPR (&output_instruction.expr) 1358 1.1 christos ? output_instruction.expr.X_add_symbol 1359 1.1 christos : make_expr_symbol (&output_instruction.expr)); 1360 1.1 christos 1361 1.1 christos /* If is_undefined, the expression may still become now_seg. 1362 1.1 christos That case is handled by md_estimate_size_before_relax. */ 1363 1.1 christos length_code = to_seg == now_seg ? STATE_BYTE : STATE_UNDF; 1364 1.1 christos 1365 1.1 christos /* Make room for max twelve bytes of variable length for v32 mode 1366 1.1 christos or PIC, ten for v10 and older. */ 1367 1.1 christos frag_var (rs_machine_dependent, 1368 1.1 christos (cris_arch == arch_crisv32 1369 1.1 christos || cris_arch == arch_cris_common_v10_v32 1370 1.1 christos || pic) ? 12 : 10, 0, 1371 1.1 christos ENCODE_RELAX (cris_arch == arch_crisv32 1372 1.1 christos ? (output_instruction.opcode 1373 1.1 christos == BA_QUICK_OPCODE 1374 1.1 christos ? STATE_ABS_BRANCH_V32 1375 1.1 christos : STATE_COND_BRANCH_V32) 1376 1.1 christos : (cris_arch == arch_cris_common_v10_v32 1377 1.1 christos ? STATE_COND_BRANCH_COMMON 1378 1.1 christos : (pic ? STATE_COND_BRANCH_PIC 1379 1.1 christos : STATE_COND_BRANCH)), 1380 1.1 christos length_code), 1381 1.1 christos sym, addvalue, opcodep); 1382 1.1 christos } 1383 1.1 christos else 1384 1.1 christos { 1385 1.1 christos /* We have: to_seg != now_seg && to_seg != undefined_section. 1386 1.1 christos This means it is a branch to a known symbol in another 1387 1.1 christos section, perhaps an absolute address. Emit a 32-bit branch. */ 1388 1.1 christos char *cond_jump 1389 1.1 christos = frag_more ((cris_arch == arch_crisv32 1390 1.1 christos || cris_arch == arch_cris_common_v10_v32 1391 1.1 christos || pic) 1392 1.1 christos ? 12 : 10); 1393 1.1 christos 1394 1.1 christos gen_cond_branch_32 (opcodep, cond_jump, frag_now, 1395 1.10 christos output_instruction.expr.X_add_symbol, NULL, 1396 1.1 christos output_instruction.expr.X_add_number); 1397 1.1 christos } 1398 1.1 christos } 1399 1.1 christos else if (output_instruction.insn_type == CRIS_INSN_MUL 1400 1.1 christos && err_for_dangerous_mul_placement) 1401 1.1 christos /* Create a frag which which we track the location of the mul insn 1402 1.1 christos (in the last two bytes before the mul-frag). */ 1403 1.1 christos frag_variant (rs_machine_dependent, 0, 0, 1404 1.1 christos ENCODE_RELAX (STATE_MUL, STATE_BYTE), 1405 1.1 christos NULL, 0, opcodep); 1406 1.1 christos else 1407 1.1 christos { 1408 1.1 christos if (output_instruction.imm_oprnd_size > 0) 1409 1.1 christos { 1410 1.1 christos /* The instruction has an immediate operand. */ 1411 1.1 christos enum bfd_reloc_code_real reloc = BFD_RELOC_NONE; 1412 1.1 christos 1413 1.1 christos switch (output_instruction.imm_oprnd_size) 1414 1.1 christos { 1415 1.1 christos /* Any byte-size immediate constants are treated as 1416 1.1 christos word-size. FIXME: Thus overflow check does not work 1417 1.1 christos correctly. */ 1418 1.1 christos 1419 1.1 christos case 2: 1420 1.1 christos /* Note that size-check for the explicit reloc has already 1421 1.1 christos been done when we get here. */ 1422 1.1 christos if (output_instruction.reloc != BFD_RELOC_NONE) 1423 1.1 christos reloc = output_instruction.reloc; 1424 1.1 christos else 1425 1.1 christos reloc = BFD_RELOC_16; 1426 1.1 christos break; 1427 1.1 christos 1428 1.1 christos case 4: 1429 1.1 christos /* Allow a relocation specified in the operand. */ 1430 1.1 christos if (output_instruction.reloc != BFD_RELOC_NONE) 1431 1.1 christos reloc = output_instruction.reloc; 1432 1.1 christos else 1433 1.1 christos reloc = BFD_RELOC_32; 1434 1.1 christos break; 1435 1.1 christos 1436 1.1 christos default: 1437 1.1 christos BAD_CASE (output_instruction.imm_oprnd_size); 1438 1.1 christos } 1439 1.1 christos 1440 1.1 christos p = frag_more (output_instruction.imm_oprnd_size); 1441 1.1 christos fix_new_exp (frag_now, (p - frag_now->fr_literal), 1442 1.1 christos output_instruction.imm_oprnd_size, 1443 1.1 christos &output_instruction.expr, 1444 1.1 christos reloc == BFD_RELOC_32_PCREL 1445 1.1 christos || reloc == BFD_RELOC_16_PCREL 1446 1.1 christos || reloc == BFD_RELOC_8_PCREL, reloc); 1447 1.1 christos } 1448 1.1 christos else if (output_instruction.reloc == BFD_RELOC_CRIS_LAPCQ_OFFSET 1449 1.1 christos && output_instruction.expr.X_md != 0) 1450 1.1 christos { 1451 1.1 christos /* Handle complex expressions. */ 1452 1.1 christos valueT addvalue 1453 1.1 christos = (output_instruction.expr.X_op_symbol != NULL 1454 1.1 christos ? 0 : output_instruction.expr.X_add_number); 1455 1.1 christos symbolS *sym 1456 1.1 christos = (output_instruction.expr.X_op_symbol != NULL 1457 1.1 christos ? make_expr_symbol (&output_instruction.expr) 1458 1.1 christos : output_instruction.expr.X_add_symbol); 1459 1.1 christos 1460 1.1 christos /* This is a relaxing construct, so we need a frag_var rather 1461 1.1 christos than the fix_new_exp call below. */ 1462 1.1 christos frag_var (rs_machine_dependent, 1463 1.1 christos 4, 0, 1464 1.1 christos ENCODE_RELAX (STATE_LAPC, STATE_UNDF), 1465 1.1 christos sym, addvalue, opcodep); 1466 1.1 christos } 1467 1.1 christos else if (output_instruction.reloc != BFD_RELOC_NONE) 1468 1.1 christos { 1469 1.1 christos /* An immediate operand that has a relocation and needs to be 1470 1.1 christos processed further. */ 1471 1.1 christos 1472 1.1 christos /* It is important to use fix_new_exp here and everywhere else 1473 1.1 christos (and not fix_new), as fix_new_exp can handle "difference 1474 1.1 christos expressions" - where the expression contains a difference of 1475 1.1 christos two symbols in the same segment. */ 1476 1.1 christos fix_new_exp (frag_now, (opcodep - frag_now->fr_literal), 2, 1477 1.1 christos &output_instruction.expr, 1478 1.1 christos output_instruction.reloc == BFD_RELOC_32_PCREL 1479 1.1 christos || output_instruction.reloc == BFD_RELOC_16_PCREL 1480 1.1 christos || output_instruction.reloc == BFD_RELOC_8_PCREL 1481 1.1 christos || (output_instruction.reloc 1482 1.1 christos == BFD_RELOC_CRIS_LAPCQ_OFFSET), 1483 1.1 christos output_instruction.reloc); 1484 1.1 christos } 1485 1.1 christos } 1486 1.1 christos } 1487 1.1 christos 1488 1.3 christos /* Helper error-reporting function: calls as_bad for a format string 1489 1.3 christos for a single value and zeroes the offending value (zero assumed 1490 1.3 christos being a valid value) to avoid repeated error reports in later value 1491 1.3 christos checking. */ 1492 1.3 christos 1493 1.3 christos static void 1494 1.3 christos cris_bad (const char *format, offsetT *valp) 1495 1.3 christos { 1496 1.3 christos /* We cast to long so the format string can assume that format. */ 1497 1.3 christos as_bad (format, (long) *valp); 1498 1.3 christos *valp = 0; 1499 1.3 christos } 1500 1.3 christos 1501 1.1 christos /* Low level text-to-bits assembly. */ 1502 1.1 christos 1503 1.1 christos static void 1504 1.1 christos cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp, 1505 1.1 christos struct cris_prefix *prefixp) 1506 1.1 christos { 1507 1.1 christos char *s; 1508 1.1 christos char modified_char = 0; 1509 1.1 christos const char *args; 1510 1.1 christos struct cris_opcode *instruction; 1511 1.1 christos char *operands; 1512 1.1 christos int match = 0; 1513 1.1 christos int mode; 1514 1.1 christos int regno; 1515 1.1 christos int size_bits; 1516 1.1 christos 1517 1.1 christos /* Reset these fields to a harmless state in case we need to return in 1518 1.1 christos error. */ 1519 1.1 christos prefixp->kind = PREFIX_NONE; 1520 1.1 christos prefixp->reloc = BFD_RELOC_NONE; 1521 1.1 christos out_insnp->insn_type = CRIS_INSN_NONE; 1522 1.1 christos out_insnp->imm_oprnd_size = 0; 1523 1.1 christos 1524 1.1 christos /* Find the end of the opcode mnemonic. We assume (true in 2.9.1) 1525 1.1 christos that the caller has translated the opcode to lower-case, up to the 1526 1.1 christos first non-letter. */ 1527 1.1 christos for (operands = insn_text; ISLOWER (*operands); ++operands) 1528 1.1 christos ; 1529 1.1 christos 1530 1.1 christos /* Terminate the opcode after letters, but save the character there if 1531 1.1 christos it was of significance. */ 1532 1.1 christos switch (*operands) 1533 1.1 christos { 1534 1.1 christos case '\0': 1535 1.1 christos break; 1536 1.1 christos 1537 1.1 christos case '.': 1538 1.1 christos /* Put back the modified character later. */ 1539 1.1 christos modified_char = *operands; 1540 1.1 christos /* Fall through. */ 1541 1.1 christos 1542 1.1 christos case ' ': 1543 1.1 christos /* Consume the character after the mnemonic 1544 1.1 christos and replace it with '\0'. */ 1545 1.1 christos *operands++ = '\0'; 1546 1.1 christos break; 1547 1.1 christos 1548 1.1 christos default: 1549 1.1 christos as_bad (_("Unknown opcode: `%s'"), insn_text); 1550 1.1 christos return; 1551 1.1 christos } 1552 1.1 christos 1553 1.1 christos /* Find the instruction. */ 1554 1.10 christos instruction = str_hash_find (op_hash, insn_text); 1555 1.1 christos if (instruction == NULL) 1556 1.1 christos { 1557 1.1 christos as_bad (_("Unknown opcode: `%s'"), insn_text); 1558 1.1 christos return; 1559 1.1 christos } 1560 1.1 christos 1561 1.1 christos /* Put back the modified character. */ 1562 1.1 christos switch (modified_char) 1563 1.1 christos { 1564 1.1 christos case 0: 1565 1.1 christos break; 1566 1.1 christos 1567 1.1 christos default: 1568 1.1 christos *--operands = modified_char; 1569 1.1 christos } 1570 1.1 christos 1571 1.1 christos /* Try to match an opcode table slot. */ 1572 1.1 christos for (s = operands;;) 1573 1.1 christos { 1574 1.1 christos int imm_expr_found; 1575 1.1 christos 1576 1.1 christos /* Initialize *prefixp, perhaps after being modified for a 1577 1.1 christos "near match". */ 1578 1.1 christos prefixp->kind = PREFIX_NONE; 1579 1.1 christos prefixp->reloc = BFD_RELOC_NONE; 1580 1.1 christos 1581 1.1 christos /* Initialize *out_insnp. */ 1582 1.1 christos memset (out_insnp, 0, sizeof (*out_insnp)); 1583 1.1 christos out_insnp->opcode = instruction->match; 1584 1.1 christos out_insnp->reloc = BFD_RELOC_NONE; 1585 1.1 christos out_insnp->insn_type = CRIS_INSN_NORMAL; 1586 1.1 christos out_insnp->imm_oprnd_size = 0; 1587 1.1 christos 1588 1.1 christos imm_expr_found = 0; 1589 1.1 christos 1590 1.1 christos /* Build the opcode, checking as we go to make sure that the 1591 1.1 christos operands match. */ 1592 1.1 christos for (args = instruction->args;; ++args) 1593 1.1 christos { 1594 1.1 christos switch (*args) 1595 1.1 christos { 1596 1.1 christos case '\0': 1597 1.1 christos /* If we've come to the end of arguments, we're done. */ 1598 1.1 christos if (*s == '\0') 1599 1.1 christos match = 1; 1600 1.1 christos break; 1601 1.1 christos 1602 1.1 christos case '!': 1603 1.1 christos /* Non-matcher character for disassembly. 1604 1.1 christos Ignore it here. */ 1605 1.1 christos continue; 1606 1.1 christos 1607 1.1 christos case '[': 1608 1.1 christos case ']': 1609 1.1 christos case ',': 1610 1.1 christos case ' ': 1611 1.1 christos /* These must match exactly. */ 1612 1.1 christos if (*s++ == *args) 1613 1.1 christos continue; 1614 1.1 christos break; 1615 1.1 christos 1616 1.1 christos case 'A': 1617 1.1 christos /* "ACR", case-insensitive. 1618 1.1 christos Handle a sometimes-mandatory dollar sign as register 1619 1.1 christos prefix. */ 1620 1.1 christos if (*s == REGISTER_PREFIX_CHAR) 1621 1.1 christos s++; 1622 1.1 christos else if (demand_register_prefix) 1623 1.1 christos break; 1624 1.1 christos 1625 1.1 christos if ((*s++ != 'a' && s[-1] != 'A') 1626 1.1 christos || (*s++ != 'c' && s[-1] != 'C') 1627 1.1 christos || (*s++ != 'r' && s[-1] != 'R')) 1628 1.1 christos break; 1629 1.1 christos continue; 1630 1.1 christos 1631 1.1 christos case 'B': 1632 1.1 christos /* This is not really an operand, but causes a "BDAP 1633 1.1 christos -size,SP" prefix to be output, for PUSH instructions. */ 1634 1.1 christos prefixp->kind = PREFIX_PUSH; 1635 1.1 christos continue; 1636 1.1 christos 1637 1.1 christos case 'b': 1638 1.1 christos /* This letter marks an operand that should not be matched 1639 1.1 christos in the assembler. It is a branch with 16-bit 1640 1.1 christos displacement. The assembler will create them from the 1641 1.1 christos 8-bit flavor when necessary. The assembler does not 1642 1.1 christos support the [rN+] operand, as the [r15+] that is 1643 1.1 christos generated for 16-bit displacements. */ 1644 1.1 christos break; 1645 1.1 christos 1646 1.1 christos case 'c': 1647 1.1 christos /* A 5-bit unsigned immediate in bits <4:0>. */ 1648 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr)) 1649 1.1 christos break; 1650 1.1 christos else 1651 1.1 christos { 1652 1.1 christos if (out_insnp->expr.X_op == O_constant 1653 1.1 christos && (out_insnp->expr.X_add_number < 0 1654 1.1 christos || out_insnp->expr.X_add_number > 31)) 1655 1.3 christos cris_bad (_("Immediate value not in 5 bit unsigned range: %ld"), 1656 1.3 christos &out_insnp->expr.X_add_number); 1657 1.1 christos 1658 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_5; 1659 1.1 christos continue; 1660 1.1 christos } 1661 1.1 christos 1662 1.1 christos case 'C': 1663 1.1 christos /* A 4-bit unsigned immediate in bits <3:0>. */ 1664 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr)) 1665 1.1 christos break; 1666 1.1 christos else 1667 1.1 christos { 1668 1.1 christos if (out_insnp->expr.X_op == O_constant 1669 1.1 christos && (out_insnp->expr.X_add_number < 0 1670 1.1 christos || out_insnp->expr.X_add_number > 15)) 1671 1.3 christos cris_bad (_("Immediate value not in 4 bit unsigned range: %ld"), 1672 1.3 christos &out_insnp->expr.X_add_number); 1673 1.1 christos 1674 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_4; 1675 1.1 christos continue; 1676 1.1 christos } 1677 1.1 christos 1678 1.1 christos /* For 'd', check for an optional ".d" or ".D" at the 1679 1.1 christos start of the operands, followed by a space character. */ 1680 1.1 christos case 'd': 1681 1.1 christos if (modified_char == '.' && *s == '.') 1682 1.1 christos { 1683 1.1 christos if ((s[1] != 'd' && s[1] == 'D') 1684 1.10 christos || ! is_whitespace (s[2])) 1685 1.1 christos break; 1686 1.1 christos s += 2; 1687 1.1 christos continue; 1688 1.1 christos } 1689 1.1 christos continue; 1690 1.1 christos 1691 1.1 christos case 'D': 1692 1.1 christos /* General register in bits <15:12> and <3:0>. */ 1693 1.1 christos if (! get_gen_reg (&s, ®no)) 1694 1.1 christos break; 1695 1.1 christos else 1696 1.1 christos { 1697 1.1 christos out_insnp->opcode |= regno /* << 0 */; 1698 1.1 christos out_insnp->opcode |= regno << 12; 1699 1.1 christos continue; 1700 1.1 christos } 1701 1.1 christos 1702 1.1 christos case 'f': 1703 1.1 christos /* Flags from the condition code register. */ 1704 1.1 christos { 1705 1.1 christos int flags = 0; 1706 1.1 christos 1707 1.1 christos if (! get_flags (&s, &flags)) 1708 1.1 christos break; 1709 1.1 christos 1710 1.1 christos out_insnp->opcode |= ((flags & 0xf0) << 8) | (flags & 0xf); 1711 1.1 christos continue; 1712 1.1 christos } 1713 1.1 christos 1714 1.1 christos case 'i': 1715 1.1 christos /* A 6-bit signed immediate in bits <5:0>. */ 1716 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr)) 1717 1.1 christos break; 1718 1.1 christos else 1719 1.1 christos { 1720 1.1 christos if (out_insnp->expr.X_op == O_constant 1721 1.1 christos && (out_insnp->expr.X_add_number < -32 1722 1.1 christos || out_insnp->expr.X_add_number > 31)) 1723 1.3 christos cris_bad (_("Immediate value not in 6 bit range: %ld"), 1724 1.3 christos &out_insnp->expr.X_add_number); 1725 1.3 christos 1726 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_6; 1727 1.1 christos continue; 1728 1.1 christos } 1729 1.1 christos 1730 1.1 christos case 'I': 1731 1.1 christos /* A 6-bit unsigned immediate in bits <5:0>. */ 1732 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr)) 1733 1.1 christos break; 1734 1.1 christos else 1735 1.1 christos { 1736 1.1 christos if (out_insnp->expr.X_op == O_constant 1737 1.1 christos && (out_insnp->expr.X_add_number < 0 1738 1.1 christos || out_insnp->expr.X_add_number > 63)) 1739 1.3 christos cris_bad (_("Immediate value not in 6 bit unsigned range: %ld"), 1740 1.3 christos &out_insnp->expr.X_add_number); 1741 1.3 christos 1742 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_6; 1743 1.1 christos continue; 1744 1.1 christos } 1745 1.1 christos 1746 1.1 christos case 'M': 1747 1.1 christos /* A size modifier, B, W or D, to be put in a bit position 1748 1.1 christos suitable for CLEAR instructions (i.e. reflecting a zero 1749 1.1 christos register). */ 1750 1.1 christos if (! get_bwd_size_modifier (&s, &size_bits)) 1751 1.1 christos break; 1752 1.1 christos else 1753 1.1 christos { 1754 1.1 christos switch (size_bits) 1755 1.1 christos { 1756 1.1 christos case 0: 1757 1.1 christos out_insnp->opcode |= 0 << 12; 1758 1.1 christos break; 1759 1.1 christos 1760 1.1 christos case 1: 1761 1.1 christos out_insnp->opcode |= 4 << 12; 1762 1.1 christos break; 1763 1.1 christos 1764 1.1 christos case 2: 1765 1.1 christos out_insnp->opcode |= 8 << 12; 1766 1.1 christos break; 1767 1.1 christos } 1768 1.1 christos continue; 1769 1.1 christos } 1770 1.1 christos 1771 1.1 christos case 'm': 1772 1.1 christos /* A size modifier, B, W or D, to be put in bits <5:4>. */ 1773 1.1 christos if (modified_char != '.' 1774 1.1 christos || ! get_bwd_size_modifier (&s, &size_bits)) 1775 1.1 christos break; 1776 1.1 christos else 1777 1.1 christos { 1778 1.1 christos out_insnp->opcode |= size_bits << 4; 1779 1.1 christos continue; 1780 1.1 christos } 1781 1.1 christos 1782 1.1 christos case 'o': 1783 1.1 christos /* A branch expression. */ 1784 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr)) 1785 1.1 christos break; 1786 1.1 christos else 1787 1.1 christos { 1788 1.1 christos out_insnp->insn_type = CRIS_INSN_BRANCH; 1789 1.1 christos continue; 1790 1.1 christos } 1791 1.1 christos 1792 1.1 christos case 'Q': 1793 1.1 christos /* A 8-bit quick BDAP expression, "expr,R". */ 1794 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr)) 1795 1.1 christos break; 1796 1.1 christos 1797 1.1 christos if (*s != ',') 1798 1.1 christos break; 1799 1.1 christos 1800 1.1 christos s++; 1801 1.1 christos 1802 1.1 christos if (!get_gen_reg (&s, ®no)) 1803 1.1 christos break; 1804 1.1 christos 1805 1.1 christos out_insnp->opcode |= regno << 12; 1806 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_8; 1807 1.1 christos continue; 1808 1.3 christos 1809 1.1 christos case 'O': 1810 1.1 christos /* A BDAP expression for any size, "expr,R". */ 1811 1.1 christos if (! cris_get_expression (&s, &prefixp->expr)) 1812 1.1 christos break; 1813 1.1 christos else 1814 1.1 christos { 1815 1.1 christos if (*s != ',') 1816 1.1 christos break; 1817 1.1 christos 1818 1.1 christos s++; 1819 1.1 christos 1820 1.1 christos if (!get_gen_reg (&s, &prefixp->base_reg_number)) 1821 1.1 christos break; 1822 1.1 christos 1823 1.1 christos /* Since 'O' is used with an explicit bdap, we have no 1824 1.1 christos "real" instruction. */ 1825 1.1 christos prefixp->kind = PREFIX_BDAP_IMM; 1826 1.1 christos prefixp->opcode 1827 1.1 christos = BDAP_QUICK_OPCODE | (prefixp->base_reg_number << 12); 1828 1.1 christos 1829 1.1 christos out_insnp->insn_type = CRIS_INSN_NONE; 1830 1.1 christos continue; 1831 1.1 christos } 1832 1.1 christos 1833 1.1 christos case 'P': 1834 1.1 christos /* Special register in bits <15:12>. */ 1835 1.1 christos if (! get_spec_reg (&s, &out_insnp->spec_reg)) 1836 1.1 christos break; 1837 1.1 christos else 1838 1.1 christos { 1839 1.1 christos /* Use of some special register names come with a 1840 1.1 christos specific warning. Note that we have no ".cpu type" 1841 1.1 christos pseudo yet, so some of this is just unused 1842 1.1 christos framework. */ 1843 1.1 christos if (out_insnp->spec_reg->warning) 1844 1.1 christos as_warn ("%s", out_insnp->spec_reg->warning); 1845 1.1 christos else if (out_insnp->spec_reg->applicable_version 1846 1.1 christos == cris_ver_warning) 1847 1.1 christos /* Others have a generic warning. */ 1848 1.1 christos as_warn (_("Unimplemented register `%s' specified"), 1849 1.1 christos out_insnp->spec_reg->name); 1850 1.1 christos 1851 1.1 christos out_insnp->opcode 1852 1.1 christos |= out_insnp->spec_reg->number << 12; 1853 1.1 christos continue; 1854 1.1 christos } 1855 1.1 christos 1856 1.1 christos case 'p': 1857 1.1 christos /* This character is used in the disassembler to 1858 1.1 christos recognize a prefix instruction to fold into the 1859 1.1 christos addressing mode for the next instruction. It is 1860 1.1 christos ignored here. */ 1861 1.1 christos continue; 1862 1.1 christos 1863 1.1 christos case 'R': 1864 1.1 christos /* General register in bits <15:12>. */ 1865 1.1 christos if (! get_gen_reg (&s, ®no)) 1866 1.1 christos break; 1867 1.1 christos else 1868 1.1 christos { 1869 1.1 christos out_insnp->opcode |= regno << 12; 1870 1.1 christos continue; 1871 1.1 christos } 1872 1.1 christos 1873 1.1 christos case 'r': 1874 1.1 christos /* General register in bits <3:0>. */ 1875 1.1 christos if (! get_gen_reg (&s, ®no)) 1876 1.1 christos break; 1877 1.1 christos else 1878 1.1 christos { 1879 1.1 christos out_insnp->opcode |= regno /* << 0 */; 1880 1.1 christos continue; 1881 1.1 christos } 1882 1.1 christos 1883 1.1 christos case 'S': 1884 1.1 christos /* Source operand in bit <10> and a prefix; a 3-operand 1885 1.1 christos prefix. */ 1886 1.1 christos if (! get_3op_or_dip_prefix_op (&s, prefixp)) 1887 1.1 christos break; 1888 1.1 christos else 1889 1.1 christos continue; 1890 1.1 christos 1891 1.1 christos case 's': 1892 1.1 christos /* Source operand in bits <10>, <3:0> and optionally a 1893 1.1 christos prefix; i.e. an indirect operand or an side-effect 1894 1.1 christos prefix (where valid). */ 1895 1.1 christos if (! get_autoinc_prefix_or_indir_op (&s, prefixp, &mode, 1896 1.1 christos ®no, 1897 1.1 christos &imm_expr_found, 1898 1.1 christos &out_insnp->expr)) 1899 1.1 christos break; 1900 1.1 christos else 1901 1.1 christos { 1902 1.1 christos if (prefixp->kind != PREFIX_NONE) 1903 1.1 christos { 1904 1.1 christos /* A prefix, so it has the autoincrement bit 1905 1.1 christos set. */ 1906 1.1 christos out_insnp->opcode |= (AUTOINCR_BIT << 8); 1907 1.1 christos } 1908 1.1 christos else 1909 1.1 christos { 1910 1.1 christos /* No prefix. The "mode" variable contains bits like 1911 1.1 christos whether or not this is autoincrement mode. */ 1912 1.1 christos out_insnp->opcode |= (mode << 10); 1913 1.1 christos 1914 1.1 christos /* If there was a reloc specifier, then it was 1915 1.1 christos attached to the prefix. Note that we can't check 1916 1.1 christos that the reloc size matches, since we don't have 1917 1.1 christos all the operands yet in all cases. */ 1918 1.1 christos if (prefixp->reloc != BFD_RELOC_NONE) 1919 1.1 christos out_insnp->reloc = prefixp->reloc; 1920 1.1 christos } 1921 1.1 christos 1922 1.1 christos out_insnp->opcode |= regno /* << 0 */ ; 1923 1.1 christos continue; 1924 1.1 christos } 1925 1.1 christos 1926 1.1 christos case 'N': 1927 1.1 christos case 'Y': 1928 1.1 christos /* Like 's', but immediate operand only. Also do not 1929 1.1 christos modify insn. There are no insns where an explicit reloc 1930 1.1 christos specifier makes sense. */ 1931 1.1 christos if (cris_get_expression (&s, &out_insnp->expr)) 1932 1.1 christos { 1933 1.1 christos imm_expr_found = 1; 1934 1.1 christos continue; 1935 1.1 christos } 1936 1.1 christos break; 1937 1.1 christos 1938 1.1 christos case 'n': 1939 1.1 christos /* Like 'N', but PC-relative to the start of the insn. 1940 1.1 christos There might be a :PLT to request a PLT entry. */ 1941 1.1 christos if (cris_get_expression (&s, &out_insnp->expr)) 1942 1.1 christos { 1943 1.1 christos imm_expr_found = 1; 1944 1.1 christos out_insnp->reloc = BFD_RELOC_32_PCREL; 1945 1.1 christos 1946 1.1 christos /* We have to adjust the expression, because that 1947 1.1 christos relocation is to the location *after* the 1948 1.1 christos relocation. So add 2 for the insn and 4 for the 1949 1.1 christos relocation. */ 1950 1.1 christos out_insnp->expr.X_add_number += 6; 1951 1.1 christos 1952 1.1 christos /* TLS specifiers do not make sense here. */ 1953 1.1 christos if (pic && *s == RELOC_SUFFIX_CHAR) 1954 1.1 christos cris_get_reloc_suffix (&s, &out_insnp->reloc, 1955 1.1 christos &out_insnp->expr); 1956 1.1 christos 1957 1.1 christos continue; 1958 1.1 christos } 1959 1.1 christos break; 1960 1.1 christos 1961 1.1 christos case 'U': 1962 1.1 christos /* Maybe 'u', maybe 'n'. Only for LAPC/LAPCQ. */ 1963 1.1 christos if (cris_get_expression (&s, &out_insnp->expr)) 1964 1.1 christos { 1965 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_LAPCQ_OFFSET; 1966 1.1 christos 1967 1.1 christos /* Define 1 as relaxing. */ 1968 1.1 christos out_insnp->expr.X_md = 1; 1969 1.1 christos continue; 1970 1.1 christos } 1971 1.1 christos break; 1972 1.1 christos 1973 1.1 christos case 'u': 1974 1.1 christos /* Four PC-relative bits in <3:0> representing <4:1>:0 of 1975 1.1 christos an offset relative to the beginning of the current 1976 1.1 christos insn. */ 1977 1.1 christos if (cris_get_expression (&s, &out_insnp->expr)) 1978 1.1 christos { 1979 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_LAPCQ_OFFSET; 1980 1.1 christos 1981 1.1 christos /* Define 0 as non-relaxing. */ 1982 1.1 christos out_insnp->expr.X_md = 0; 1983 1.1 christos 1984 1.1 christos /* We have to adjust the expression, because that 1985 1.1 christos relocation is to the location *after* the 1986 1.1 christos insn. So add 2 for the insn. */ 1987 1.1 christos out_insnp->expr.X_add_number += 2; 1988 1.1 christos continue; 1989 1.1 christos } 1990 1.1 christos break; 1991 1.1 christos 1992 1.1 christos case 'x': 1993 1.1 christos /* Rs.m in bits <15:12> and <5:4>. */ 1994 1.1 christos if (! get_gen_reg (&s, ®no) 1995 1.1 christos || ! get_bwd_size_modifier (&s, &size_bits)) 1996 1.1 christos break; 1997 1.1 christos else 1998 1.1 christos { 1999 1.1 christos out_insnp->opcode |= (regno << 12) | (size_bits << 4); 2000 1.1 christos continue; 2001 1.1 christos } 2002 1.1 christos 2003 1.1 christos case 'y': 2004 1.1 christos /* Source operand in bits <10>, <3:0> and optionally a 2005 1.1 christos prefix; i.e. an indirect operand or an side-effect 2006 1.1 christos prefix. 2007 1.1 christos 2008 1.1 christos The difference to 's' is that this does not allow an 2009 1.1 christos "immediate" expression. */ 2010 1.1 christos if (! get_autoinc_prefix_or_indir_op (&s, prefixp, 2011 1.1 christos &mode, ®no, 2012 1.1 christos &imm_expr_found, 2013 1.1 christos &out_insnp->expr) 2014 1.1 christos || imm_expr_found) 2015 1.1 christos break; 2016 1.1 christos else 2017 1.1 christos { 2018 1.1 christos if (prefixp->kind != PREFIX_NONE) 2019 1.1 christos { 2020 1.1 christos /* A prefix, and those matched here always have 2021 1.1 christos side-effects (see 's' case). */ 2022 1.1 christos out_insnp->opcode |= (AUTOINCR_BIT << 8); 2023 1.1 christos } 2024 1.1 christos else 2025 1.1 christos { 2026 1.1 christos /* No prefix. The "mode" variable contains bits 2027 1.1 christos like whether or not this is autoincrement 2028 1.1 christos mode. */ 2029 1.1 christos out_insnp->opcode |= (mode << 10); 2030 1.1 christos } 2031 1.1 christos 2032 1.1 christos out_insnp->opcode |= regno /* << 0 */; 2033 1.1 christos continue; 2034 1.1 christos } 2035 1.1 christos 2036 1.1 christos case 'z': 2037 1.1 christos /* Size modifier (B or W) in bit <4>. */ 2038 1.1 christos if (! get_bw_size_modifier (&s, &size_bits)) 2039 1.1 christos break; 2040 1.1 christos else 2041 1.1 christos { 2042 1.1 christos out_insnp->opcode |= size_bits << 4; 2043 1.1 christos continue; 2044 1.1 christos } 2045 1.1 christos 2046 1.1 christos case 'T': 2047 1.1 christos if (cris_arch == arch_crisv32 2048 1.1 christos && get_sup_reg (&s, ®no)) 2049 1.1 christos { 2050 1.1 christos out_insnp->opcode |= regno << 12; 2051 1.1 christos continue; 2052 1.1 christos } 2053 1.1 christos break; 2054 1.1 christos 2055 1.1 christos default: 2056 1.1 christos BAD_CASE (*args); 2057 1.1 christos } 2058 1.1 christos 2059 1.1 christos /* We get here when we fail a match above or we found a 2060 1.1 christos complete match. Break out of this loop. */ 2061 1.1 christos break; 2062 1.1 christos } 2063 1.1 christos 2064 1.1 christos /* Was it a match or a miss? */ 2065 1.1 christos if (match == 0) 2066 1.1 christos { 2067 1.1 christos /* If it's just that the args don't match, maybe the next 2068 1.1 christos item in the table is the same opcode but with 2069 1.1 christos matching operands. First skip any invalid ones. */ 2070 1.1 christos while (instruction[1].name != NULL 2071 1.1 christos && strcmp (instruction->name, instruction[1].name) == 0 2072 1.1 christos && ! cris_insn_ver_valid_for_arch (instruction[1] 2073 1.1 christos .applicable_version, 2074 1.1 christos cris_arch)) 2075 1.1 christos ++instruction; 2076 1.1 christos 2077 1.1 christos if (instruction[1].name != NULL 2078 1.1 christos && strcmp (instruction->name, instruction[1].name) == 0 2079 1.1 christos && cris_insn_ver_valid_for_arch (instruction[1] 2080 1.1 christos .applicable_version, 2081 1.1 christos cris_arch)) 2082 1.1 christos { 2083 1.1 christos /* Yep. Restart and try that one instead. */ 2084 1.1 christos ++instruction; 2085 1.1 christos s = operands; 2086 1.1 christos continue; 2087 1.1 christos } 2088 1.1 christos else 2089 1.1 christos { 2090 1.1 christos /* We've come to the end of instructions with this 2091 1.1 christos opcode, so it must be an error. */ 2092 1.1 christos as_bad (_("Illegal operands")); 2093 1.1 christos 2094 1.1 christos /* As discard_rest_of_line, but without continuing to the 2095 1.1 christos next line. */ 2096 1.10 christos while (!is_end_of_stmt (*input_line_pointer)) 2097 1.1 christos input_line_pointer++; 2098 1.1 christos return; 2099 1.1 christos } 2100 1.1 christos } 2101 1.1 christos else 2102 1.1 christos { 2103 1.1 christos /* We have a match. Check if there's anything more to do. */ 2104 1.1 christos if (imm_expr_found) 2105 1.1 christos { 2106 1.1 christos /* There was an immediate mode operand, so we must check 2107 1.1 christos that it has an appropriate size. */ 2108 1.1 christos switch (instruction->imm_oprnd_size) 2109 1.1 christos { 2110 1.1 christos default: 2111 1.1 christos case SIZE_NONE: 2112 1.1 christos /* Shouldn't happen; this one does not have immediate 2113 1.1 christos operands with different sizes. */ 2114 1.1 christos BAD_CASE (instruction->imm_oprnd_size); 2115 1.1 christos break; 2116 1.1 christos 2117 1.1 christos case SIZE_FIX_32: 2118 1.1 christos out_insnp->imm_oprnd_size = 4; 2119 1.1 christos break; 2120 1.1 christos 2121 1.1 christos case SIZE_SPEC_REG: 2122 1.1 christos if (cris_arch == arch_crisv32) 2123 1.1 christos /* All immediate loads of special registers are 2124 1.1 christos 32-bit on CRISv32. */ 2125 1.1 christos out_insnp->imm_oprnd_size = 4; 2126 1.1 christos else 2127 1.1 christos switch (out_insnp->spec_reg->reg_size) 2128 1.1 christos { 2129 1.1 christos case 1: 2130 1.1 christos if (out_insnp->expr.X_op == O_constant 2131 1.1 christos && (out_insnp->expr.X_add_number < -128 2132 1.1 christos || out_insnp->expr.X_add_number > 255)) 2133 1.3 christos cris_bad (_("Immediate value not in 8 bit range: %ld"), 2134 1.3 christos &out_insnp->expr.X_add_number); 2135 1.1 christos /* Fall through. */ 2136 1.1 christos case 2: 2137 1.1 christos /* FIXME: We need an indicator in the instruction 2138 1.1 christos table to pass on, to indicate if we need to check 2139 1.1 christos overflow for a signed or unsigned number. */ 2140 1.1 christos if (out_insnp->expr.X_op == O_constant 2141 1.1 christos && (out_insnp->expr.X_add_number < -32768 2142 1.1 christos || out_insnp->expr.X_add_number > 65535)) 2143 1.3 christos cris_bad (_("Immediate value not in 16 bit range: %ld"), 2144 1.3 christos &out_insnp->expr.X_add_number); 2145 1.1 christos out_insnp->imm_oprnd_size = 2; 2146 1.1 christos break; 2147 1.1 christos 2148 1.1 christos case 4: 2149 1.1 christos out_insnp->imm_oprnd_size = 4; 2150 1.1 christos break; 2151 1.1 christos 2152 1.1 christos default: 2153 1.1 christos BAD_CASE (out_insnp->spec_reg->reg_size); 2154 1.1 christos } 2155 1.1 christos break; 2156 1.1 christos 2157 1.1 christos case SIZE_FIELD: 2158 1.1 christos case SIZE_FIELD_SIGNED: 2159 1.1 christos case SIZE_FIELD_UNSIGNED: 2160 1.1 christos switch (size_bits) 2161 1.1 christos { 2162 1.1 christos /* FIXME: Find way to pass un/signedness to 2163 1.1 christos caller, and set reloc type instead, postponing 2164 1.1 christos this check until cris_number_to_imm. That 2165 1.1 christos necessarily corrects the reloc type for the 2166 1.1 christos byte case, maybe requiring further changes. */ 2167 1.1 christos case 0: 2168 1.1 christos if (out_insnp->expr.X_op == O_constant) 2169 1.1 christos { 2170 1.1 christos if (instruction->imm_oprnd_size == SIZE_FIELD 2171 1.1 christos && (out_insnp->expr.X_add_number < -128 2172 1.1 christos || out_insnp->expr.X_add_number > 255)) 2173 1.3 christos cris_bad (_("Immediate value not in 8 bit range: %ld"), 2174 1.3 christos &out_insnp->expr.X_add_number); 2175 1.1 christos else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED 2176 1.1 christos && (out_insnp->expr.X_add_number < -128 2177 1.1 christos || out_insnp->expr.X_add_number > 127)) 2178 1.3 christos cris_bad (_("Immediate value not in 8 bit signed range: %ld"), 2179 1.3 christos &out_insnp->expr.X_add_number); 2180 1.1 christos else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED 2181 1.1 christos && (out_insnp->expr.X_add_number < 0 2182 1.1 christos || out_insnp->expr.X_add_number > 255)) 2183 1.3 christos cris_bad (_("Immediate value not in 8 bit unsigned range: %ld"), 2184 1.3 christos &out_insnp->expr.X_add_number); 2185 1.1 christos } 2186 1.1 christos 2187 1.1 christos /* Fall through. */ 2188 1.1 christos case 1: 2189 1.1 christos if (out_insnp->expr.X_op == O_constant) 2190 1.1 christos { 2191 1.1 christos if (instruction->imm_oprnd_size == SIZE_FIELD 2192 1.1 christos && (out_insnp->expr.X_add_number < -32768 2193 1.1 christos || out_insnp->expr.X_add_number > 65535)) 2194 1.3 christos cris_bad (_("Immediate value not in 16 bit range: %ld"), 2195 1.3 christos &out_insnp->expr.X_add_number); 2196 1.1 christos else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED 2197 1.1 christos && (out_insnp->expr.X_add_number < -32768 2198 1.1 christos || out_insnp->expr.X_add_number > 32767)) 2199 1.3 christos cris_bad (_("Immediate value not in 16 bit signed range: %ld"), 2200 1.3 christos &out_insnp->expr.X_add_number); 2201 1.1 christos else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED 2202 1.1 christos && (out_insnp->expr.X_add_number < 0 2203 1.1 christos || out_insnp->expr.X_add_number > 65535)) 2204 1.3 christos cris_bad (_("Immediate value not in 16 bit unsigned range: %ld"), 2205 1.3 christos &out_insnp->expr.X_add_number); 2206 1.1 christos } 2207 1.1 christos out_insnp->imm_oprnd_size = 2; 2208 1.1 christos break; 2209 1.1 christos 2210 1.1 christos case 2: 2211 1.1 christos out_insnp->imm_oprnd_size = 4; 2212 1.1 christos break; 2213 1.1 christos 2214 1.1 christos default: 2215 1.1 christos BAD_CASE (out_insnp->spec_reg->reg_size); 2216 1.1 christos } 2217 1.1 christos } 2218 1.1 christos 2219 1.1 christos /* If there was a relocation specified for the immediate 2220 1.1 christos expression (i.e. it had a PIC or TLS modifier) check that the 2221 1.1 christos size of the relocation matches the size specified by 2222 1.1 christos the opcode. */ 2223 1.1 christos if (out_insnp->reloc != BFD_RELOC_NONE 2224 1.1 christos && (cris_get_specified_reloc_size (out_insnp->reloc) 2225 1.1 christos != (unsigned int) out_insnp->imm_oprnd_size)) 2226 1.1 christos as_bad (out_insnp->reloc == BFD_RELOC_CRIS_32_GD 2227 1.1 christos || out_insnp->reloc == BFD_RELOC_CRIS_32_TPREL 2228 1.1 christos || out_insnp->reloc == BFD_RELOC_CRIS_16_TPREL 2229 1.1 christos || out_insnp->reloc == BFD_RELOC_CRIS_32_IE 2230 1.1 christos ? _("TLS relocation size does not match operand size") 2231 1.1 christos : _("PIC relocation size does not match operand size")); 2232 1.1 christos } 2233 1.1 christos else if (instruction->op == cris_muls_op 2234 1.1 christos || instruction->op == cris_mulu_op) 2235 1.1 christos out_insnp->insn_type = CRIS_INSN_MUL; 2236 1.1 christos } 2237 1.1 christos break; 2238 1.1 christos } 2239 1.1 christos } 2240 1.1 christos 2241 1.1 christos /* Get a B, W, or D size modifier from the string pointed out by *cPP, 2242 1.1 christos which must point to a '.' in front of the modifier. On successful 2243 1.1 christos return, *cPP is advanced to the character following the size 2244 1.1 christos modifier, and is undefined otherwise. 2245 1.1 christos 2246 1.1 christos cPP Pointer to pointer to string starting 2247 1.1 christos with the size modifier. 2248 1.1 christos 2249 1.1 christos size_bitsp Pointer to variable to contain the size bits on 2250 1.1 christos successful return. 2251 1.1 christos 2252 1.1 christos Return 1 iff a correct size modifier is found, else 0. */ 2253 1.1 christos 2254 1.1 christos static int 2255 1.1 christos get_bwd_size_modifier (char **cPP, int *size_bitsp) 2256 1.1 christos { 2257 1.1 christos if (**cPP != '.') 2258 1.1 christos return 0; 2259 1.1 christos else 2260 1.1 christos { 2261 1.1 christos /* Consume the '.'. */ 2262 1.1 christos (*cPP)++; 2263 1.1 christos 2264 1.1 christos switch (**cPP) 2265 1.1 christos { 2266 1.1 christos case 'B': 2267 1.1 christos case 'b': 2268 1.1 christos *size_bitsp = 0; 2269 1.1 christos break; 2270 1.1 christos 2271 1.1 christos case 'W': 2272 1.1 christos case 'w': 2273 1.1 christos *size_bitsp = 1; 2274 1.1 christos break; 2275 1.1 christos 2276 1.1 christos case 'D': 2277 1.1 christos case 'd': 2278 1.1 christos *size_bitsp = 2; 2279 1.1 christos break; 2280 1.1 christos 2281 1.1 christos default: 2282 1.1 christos return 0; 2283 1.1 christos } 2284 1.1 christos 2285 1.1 christos /* Consume the size letter. */ 2286 1.1 christos (*cPP)++; 2287 1.1 christos return 1; 2288 1.1 christos } 2289 1.1 christos } 2290 1.1 christos 2291 1.1 christos /* Get a B or W size modifier from the string pointed out by *cPP, 2292 1.1 christos which must point to a '.' in front of the modifier. On successful 2293 1.1 christos return, *cPP is advanced to the character following the size 2294 1.1 christos modifier, and is undefined otherwise. 2295 1.1 christos 2296 1.1 christos cPP Pointer to pointer to string starting 2297 1.1 christos with the size modifier. 2298 1.1 christos 2299 1.1 christos size_bitsp Pointer to variable to contain the size bits on 2300 1.1 christos successful return. 2301 1.1 christos 2302 1.1 christos Return 1 iff a correct size modifier is found, else 0. */ 2303 1.1 christos 2304 1.1 christos static int 2305 1.1 christos get_bw_size_modifier (char **cPP, int *size_bitsp) 2306 1.1 christos { 2307 1.1 christos if (**cPP != '.') 2308 1.1 christos return 0; 2309 1.1 christos else 2310 1.1 christos { 2311 1.1 christos /* Consume the '.'. */ 2312 1.1 christos (*cPP)++; 2313 1.1 christos 2314 1.1 christos switch (**cPP) 2315 1.1 christos { 2316 1.1 christos case 'B': 2317 1.1 christos case 'b': 2318 1.1 christos *size_bitsp = 0; 2319 1.1 christos break; 2320 1.1 christos 2321 1.1 christos case 'W': 2322 1.1 christos case 'w': 2323 1.1 christos *size_bitsp = 1; 2324 1.1 christos break; 2325 1.1 christos 2326 1.1 christos default: 2327 1.1 christos return 0; 2328 1.1 christos } 2329 1.1 christos 2330 1.1 christos /* Consume the size letter. */ 2331 1.1 christos (*cPP)++; 2332 1.1 christos return 1; 2333 1.1 christos } 2334 1.1 christos } 2335 1.1 christos 2336 1.1 christos /* Get a general register from the string pointed out by *cPP. The 2337 1.1 christos variable *cPP is advanced to the character following the general 2338 1.1 christos register name on a successful return, and has its initial position 2339 1.1 christos otherwise. 2340 1.1 christos 2341 1.1 christos cPP Pointer to pointer to string, beginning with a general 2342 1.1 christos register name. 2343 1.1 christos 2344 1.1 christos regnop Pointer to int containing the register number. 2345 1.1 christos 2346 1.1 christos Return 1 iff a correct general register designator is found, 2347 1.1 christos else 0. */ 2348 1.1 christos 2349 1.1 christos static int 2350 1.1 christos get_gen_reg (char **cPP, int *regnop) 2351 1.1 christos { 2352 1.1 christos char *oldp; 2353 1.1 christos oldp = *cPP; 2354 1.1 christos 2355 1.1 christos /* Handle a sometimes-mandatory dollar sign as register prefix. */ 2356 1.1 christos if (**cPP == REGISTER_PREFIX_CHAR) 2357 1.1 christos (*cPP)++; 2358 1.1 christos else if (demand_register_prefix) 2359 1.1 christos return 0; 2360 1.1 christos 2361 1.1 christos switch (**cPP) 2362 1.1 christos { 2363 1.1 christos case 'P': 2364 1.1 christos case 'p': 2365 1.1 christos /* "P" as in "PC"? Consume the "P". */ 2366 1.1 christos (*cPP)++; 2367 1.1 christos 2368 1.1 christos if ((**cPP == 'C' || **cPP == 'c') 2369 1.1 christos && ! ISALNUM ((*cPP)[1]) 2370 1.1 christos /* Here's a little twist: For v32 and the compatibility mode, 2371 1.1 christos we only recognize PC as a register number if there's '+]' 2372 1.1 christos after. We don't consume that, but the presence can only be 2373 1.1 christos valid after a register in a post-increment context, which 2374 1.1 christos is also the only valid context for PC as a register for 2375 1.1 christos v32. Not that it's used very often, but saying "MOVE.D 2376 1.1 christos [PC+],R5" should remain valid. It's not supported for 2377 1.1 christos jump-type insns or other insns with no [Rn+] mode, though. */ 2378 1.1 christos && ((cris_arch != arch_crisv32 2379 1.1 christos && cris_arch != arch_cris_common_v10_v32) 2380 1.1 christos || ((*cPP)[1] == '+' && (*cPP)[2] == ']'))) 2381 1.1 christos { 2382 1.1 christos /* It's "PC": consume the "c" and we're done. */ 2383 1.1 christos (*cPP)++; 2384 1.1 christos *regnop = REG_PC; 2385 1.1 christos return 1; 2386 1.1 christos } 2387 1.1 christos break; 2388 1.1 christos 2389 1.1 christos /* Like with PC, we recognize ACR, but only if it's *not* followed 2390 1.1 christos by '+', and only for v32. */ 2391 1.1 christos case 'A': 2392 1.1 christos case 'a': 2393 1.1 christos if (cris_arch != arch_crisv32 2394 1.1 christos || ((*cPP)[1] != 'c' && (*cPP)[1] != 'C') 2395 1.1 christos || ((*cPP)[2] != 'r' && (*cPP)[2] != 'R') 2396 1.1 christos || ISALNUM ((*cPP)[3]) 2397 1.1 christos || (*cPP)[3] == '+') 2398 1.1 christos break; 2399 1.1 christos (*cPP) += 3; 2400 1.1 christos *regnop = 15; 2401 1.1 christos return 1; 2402 1.1 christos 2403 1.1 christos case 'R': 2404 1.1 christos case 'r': 2405 1.1 christos /* Hopefully r[0-9] or r1[0-5]. Consume 'R' or 'r'. */ 2406 1.1 christos (*cPP)++; 2407 1.1 christos 2408 1.1 christos if (ISDIGIT (**cPP)) 2409 1.1 christos { 2410 1.1 christos /* It's r[0-9]. Consume and check the next digit. */ 2411 1.1 christos *regnop = **cPP - '0'; 2412 1.1 christos (*cPP)++; 2413 1.1 christos 2414 1.1 christos if (! ISALNUM (**cPP)) 2415 1.1 christos { 2416 1.1 christos /* No more digits, we're done. */ 2417 1.1 christos return 1; 2418 1.1 christos } 2419 1.1 christos else 2420 1.1 christos { 2421 1.1 christos /* One more digit. Consume and add. */ 2422 1.1 christos *regnop = *regnop * 10 + (**cPP - '0'); 2423 1.1 christos 2424 1.1 christos /* We need to check for a valid register number; Rn, 2425 1.1 christos 0 <= n <= MAX_REG. */ 2426 1.1 christos if (*regnop <= MAX_REG) 2427 1.1 christos { 2428 1.1 christos /* Consume second digit. */ 2429 1.1 christos (*cPP)++; 2430 1.1 christos return 1; 2431 1.1 christos } 2432 1.1 christos } 2433 1.1 christos } 2434 1.1 christos break; 2435 1.1 christos 2436 1.1 christos case 'S': 2437 1.1 christos case 's': 2438 1.1 christos /* "S" as in "SP"? Consume the "S". */ 2439 1.1 christos (*cPP)++; 2440 1.1 christos if (**cPP == 'P' || **cPP == 'p') 2441 1.1 christos { 2442 1.1 christos /* It's "SP": consume the "p" and we're done. */ 2443 1.1 christos (*cPP)++; 2444 1.1 christos *regnop = REG_SP; 2445 1.1 christos return 1; 2446 1.1 christos } 2447 1.1 christos break; 2448 1.1 christos 2449 1.1 christos default: 2450 1.1 christos /* Just here to silence compilation warnings. */ 2451 1.1 christos ; 2452 1.1 christos } 2453 1.1 christos 2454 1.1 christos /* We get here if we fail. Restore the pointer. */ 2455 1.1 christos *cPP = oldp; 2456 1.1 christos return 0; 2457 1.1 christos } 2458 1.1 christos 2459 1.1 christos /* Get a special register from the string pointed out by *cPP. The 2460 1.1 christos variable *cPP is advanced to the character following the special 2461 1.1 christos register name if one is found, and retains its original position 2462 1.1 christos otherwise. 2463 1.1 christos 2464 1.1 christos cPP Pointer to pointer to string starting with a special register 2465 1.1 christos name. 2466 1.1 christos 2467 1.1 christos sregpp Pointer to Pointer to struct spec_reg, where a pointer to the 2468 1.1 christos register description will be stored. 2469 1.1 christos 2470 1.1 christos Return 1 iff a correct special register name is found. */ 2471 1.1 christos 2472 1.1 christos static int 2473 1.1 christos get_spec_reg (char **cPP, const struct cris_spec_reg **sregpp) 2474 1.1 christos { 2475 1.1 christos char *s1; 2476 1.1 christos const char *s2; 2477 1.1 christos char *name_begin = *cPP; 2478 1.1 christos 2479 1.1 christos const struct cris_spec_reg *sregp; 2480 1.1 christos 2481 1.1 christos /* Handle a sometimes-mandatory dollar sign as register prefix. */ 2482 1.1 christos if (*name_begin == REGISTER_PREFIX_CHAR) 2483 1.1 christos name_begin++; 2484 1.1 christos else if (demand_register_prefix) 2485 1.1 christos return 0; 2486 1.1 christos 2487 1.1 christos /* Loop over all special registers. */ 2488 1.1 christos for (sregp = cris_spec_regs; sregp->name != NULL; sregp++) 2489 1.1 christos { 2490 1.1 christos /* Start over from beginning of the supposed name. */ 2491 1.1 christos s1 = name_begin; 2492 1.1 christos s2 = sregp->name; 2493 1.1 christos 2494 1.1 christos while (*s2 != '\0' && TOLOWER (*s1) == *s2) 2495 1.1 christos { 2496 1.1 christos s1++; 2497 1.1 christos s2++; 2498 1.1 christos } 2499 1.1 christos 2500 1.1 christos /* For a match, we must have consumed the name in the table, and we 2501 1.1 christos must be outside what could be part of a name. Assume here that a 2502 1.1 christos test for alphanumerics is sufficient for a name test. */ 2503 1.1 christos if (*s2 == 0 && ! ISALNUM (*s1) 2504 1.1 christos && cris_insn_ver_valid_for_arch (sregp->applicable_version, 2505 1.1 christos cris_arch)) 2506 1.1 christos { 2507 1.1 christos /* We have a match. Update the pointer and be done. */ 2508 1.1 christos *cPP = s1; 2509 1.1 christos *sregpp = sregp; 2510 1.1 christos return 1; 2511 1.1 christos } 2512 1.1 christos } 2513 1.1 christos 2514 1.1 christos /* If we got here, we did not find any name. */ 2515 1.1 christos return 0; 2516 1.1 christos } 2517 1.1 christos 2518 1.1 christos /* Get a support register from the string pointed out by *cPP. The 2519 1.1 christos variable *cPP is advanced to the character following the support- 2520 1.1 christos register name if one is found, and retains its original position 2521 1.1 christos otherwise. 2522 1.1 christos 2523 1.1 christos cPP Pointer to pointer to string starting with a support-register 2524 1.1 christos name. 2525 1.1 christos 2526 1.1 christos sregpp Pointer to int containing the register number. 2527 1.1 christos 2528 1.1 christos Return 1 iff a correct support-register name is found. */ 2529 1.1 christos 2530 1.1 christos static int 2531 1.1 christos get_sup_reg (char **cPP, int *regnop) 2532 1.1 christos { 2533 1.1 christos char *s1; 2534 1.1 christos const char *s2; 2535 1.1 christos char *name_begin = *cPP; 2536 1.1 christos 2537 1.1 christos const struct cris_support_reg *sregp; 2538 1.1 christos 2539 1.1 christos /* Handle a sometimes-mandatory dollar sign as register prefix. */ 2540 1.1 christos if (*name_begin == REGISTER_PREFIX_CHAR) 2541 1.1 christos name_begin++; 2542 1.1 christos else if (demand_register_prefix) 2543 1.1 christos return 0; 2544 1.1 christos 2545 1.1 christos /* Loop over all support-registers. */ 2546 1.1 christos for (sregp = cris_support_regs; sregp->name != NULL; sregp++) 2547 1.1 christos { 2548 1.1 christos /* Start over from beginning of the supposed name. */ 2549 1.1 christos s1 = name_begin; 2550 1.1 christos s2 = sregp->name; 2551 1.1 christos 2552 1.1 christos while (*s2 != '\0' && TOLOWER (*s1) == *s2) 2553 1.1 christos { 2554 1.1 christos s1++; 2555 1.1 christos s2++; 2556 1.1 christos } 2557 1.1 christos 2558 1.1 christos /* For a match, we must have consumed the name in the table, and we 2559 1.1 christos must be outside what could be part of a name. Assume here that a 2560 1.1 christos test for alphanumerics is sufficient for a name test. */ 2561 1.1 christos if (*s2 == 0 && ! ISALNUM (*s1)) 2562 1.1 christos { 2563 1.1 christos /* We have a match. Update the pointer and be done. */ 2564 1.1 christos *cPP = s1; 2565 1.1 christos *regnop = sregp->number; 2566 1.1 christos return 1; 2567 1.1 christos } 2568 1.1 christos } 2569 1.1 christos 2570 1.1 christos /* If we got here, we did not find any name. */ 2571 1.1 christos return 0; 2572 1.1 christos } 2573 1.1 christos 2574 1.1 christos /* Get an unprefixed or side-effect-prefix operand from the string pointed 2575 1.1 christos out by *cPP. The pointer *cPP is advanced to the character following 2576 1.1 christos the indirect operand if we have success, else it contains an undefined 2577 1.1 christos value. 2578 1.1 christos 2579 1.1 christos cPP Pointer to pointer to string beginning with the first 2580 1.1 christos character of the supposed operand. 2581 1.1 christos 2582 1.1 christos prefixp Pointer to structure containing an optional instruction 2583 1.1 christos prefix. 2584 1.1 christos 2585 1.1 christos is_autoincp Pointer to int indicating the indirect or autoincrement 2586 1.1 christos bits. 2587 1.1 christos 2588 1.1 christos src_regnop Pointer to int containing the source register number in 2589 1.1 christos the instruction. 2590 1.1 christos 2591 1.1 christos imm_foundp Pointer to an int indicating if an immediate expression 2592 1.1 christos is found. 2593 1.1 christos 2594 1.1 christos imm_exprP Pointer to a structure containing an immediate 2595 1.1 christos expression, if success and if *imm_foundp is nonzero. 2596 1.1 christos 2597 1.1 christos Return 1 iff a correct indirect operand is found. */ 2598 1.1 christos 2599 1.1 christos static int 2600 1.1 christos get_autoinc_prefix_or_indir_op (char **cPP, struct cris_prefix *prefixp, 2601 1.1 christos int *is_autoincp, int *src_regnop, 2602 1.1 christos int *imm_foundp, expressionS *imm_exprP) 2603 1.1 christos { 2604 1.1 christos /* Assume there was no immediate mode expression. */ 2605 1.1 christos *imm_foundp = 0; 2606 1.1 christos 2607 1.1 christos if (**cPP == '[') 2608 1.1 christos { 2609 1.1 christos /* So this operand is one of: 2610 1.1 christos Indirect: [rN] 2611 1.1 christos Autoincrement: [rN+] 2612 1.1 christos Indexed with assign: [rN=rM+rO.S] 2613 1.1 christos Offset with assign: [rN=rM+I], [rN=rM+[rO].s], [rN=rM+[rO+].s] 2614 1.1 christos 2615 1.1 christos Either way, consume the '['. */ 2616 1.1 christos (*cPP)++; 2617 1.1 christos 2618 1.1 christos /* Get the rN register. */ 2619 1.1 christos if (! get_gen_reg (cPP, src_regnop)) 2620 1.1 christos /* If there was no register, then this cannot match. */ 2621 1.1 christos return 0; 2622 1.1 christos else 2623 1.1 christos { 2624 1.1 christos /* We got the register, now check the next character. */ 2625 1.1 christos switch (**cPP) 2626 1.1 christos { 2627 1.1 christos case ']': 2628 1.1 christos /* Indirect mode. We're done here. */ 2629 1.1 christos prefixp->kind = PREFIX_NONE; 2630 1.1 christos *is_autoincp = 0; 2631 1.1 christos break; 2632 1.1 christos 2633 1.1 christos case '+': 2634 1.1 christos /* This must be an auto-increment mode, if there's a 2635 1.1 christos match. */ 2636 1.1 christos prefixp->kind = PREFIX_NONE; 2637 1.1 christos *is_autoincp = 1; 2638 1.1 christos 2639 1.1 christos /* We consume this character and break out to check the 2640 1.1 christos closing ']'. */ 2641 1.1 christos (*cPP)++; 2642 1.1 christos break; 2643 1.1 christos 2644 1.1 christos case '=': 2645 1.1 christos /* This must be indexed with assign, or offset with assign 2646 1.1 christos to match. Not supported for crisv32 or in 2647 1.1 christos compatibility mode. */ 2648 1.1 christos if (cris_arch == arch_crisv32 2649 1.1 christos || cris_arch == arch_cris_common_v10_v32) 2650 1.1 christos return 0; 2651 1.1 christos 2652 1.1 christos (*cPP)++; 2653 1.1 christos 2654 1.1 christos /* Either way, the next thing must be a register. */ 2655 1.1 christos if (! get_gen_reg (cPP, &prefixp->base_reg_number)) 2656 1.1 christos /* No register, no match. */ 2657 1.1 christos return 0; 2658 1.1 christos else 2659 1.1 christos { 2660 1.1 christos /* We've consumed "[rN=rM", so we must be looking at 2661 1.1 christos "+rO.s]" or "+I]", or "-I]", or "+[rO].s]" or 2662 1.1 christos "+[rO+].s]". */ 2663 1.1 christos if (**cPP == '+') 2664 1.1 christos { 2665 1.1 christos int index_reg_number; 2666 1.1 christos (*cPP)++; 2667 1.1 christos 2668 1.1 christos if (**cPP == '[') 2669 1.1 christos { 2670 1.1 christos int size_bits; 2671 1.1 christos /* This must be [rx=ry+[rz].s] or 2672 1.1 christos [rx=ry+[rz+].s] or no match. We must be 2673 1.1 christos looking at rz after consuming the '['. */ 2674 1.1 christos (*cPP)++; 2675 1.1 christos 2676 1.1 christos if (!get_gen_reg (cPP, &index_reg_number)) 2677 1.1 christos return 0; 2678 1.1 christos 2679 1.1 christos prefixp->kind = PREFIX_BDAP; 2680 1.1 christos prefixp->opcode 2681 1.1 christos = (BDAP_INDIR_OPCODE 2682 1.1 christos + (prefixp->base_reg_number << 12) 2683 1.1 christos + index_reg_number); 2684 1.1 christos 2685 1.1 christos if (**cPP == '+') 2686 1.1 christos { 2687 1.1 christos /* We've seen "[rx=ry+[rz+" here, so now we 2688 1.1 christos know that there must be "].s]" left to 2689 1.1 christos check. */ 2690 1.1 christos (*cPP)++; 2691 1.1 christos prefixp->opcode |= AUTOINCR_BIT << 8; 2692 1.1 christos } 2693 1.1 christos 2694 1.1 christos /* If it wasn't autoincrement, we don't need to 2695 1.1 christos add anything. */ 2696 1.1 christos 2697 1.1 christos /* Check the next-to-last ']'. */ 2698 1.1 christos if (**cPP != ']') 2699 1.1 christos return 0; 2700 1.1 christos 2701 1.1 christos (*cPP)++; 2702 1.1 christos 2703 1.1 christos /* Check the ".s" modifier. */ 2704 1.1 christos if (! get_bwd_size_modifier (cPP, &size_bits)) 2705 1.1 christos return 0; 2706 1.1 christos 2707 1.1 christos prefixp->opcode |= size_bits << 4; 2708 1.1 christos 2709 1.1 christos /* Now we got [rx=ry+[rz+].s or [rx=ry+[rz].s. 2710 1.1 christos We break out to check the final ']'. */ 2711 1.1 christos break; 2712 1.1 christos } 2713 1.1 christos /* It wasn't an indirection. Check if it's a 2714 1.1 christos register. */ 2715 1.1 christos else if (get_gen_reg (cPP, &index_reg_number)) 2716 1.1 christos { 2717 1.1 christos int size_bits; 2718 1.1 christos 2719 1.1 christos /* Indexed with assign mode: "[rN+rM.S]". */ 2720 1.1 christos prefixp->kind = PREFIX_BIAP; 2721 1.1 christos prefixp->opcode 2722 1.1 christos = (BIAP_OPCODE + (index_reg_number << 12) 2723 1.1 christos + prefixp->base_reg_number /* << 0 */); 2724 1.1 christos 2725 1.1 christos if (! get_bwd_size_modifier (cPP, &size_bits)) 2726 1.1 christos /* Size missing, this isn't a match. */ 2727 1.1 christos return 0; 2728 1.1 christos else 2729 1.1 christos { 2730 1.1 christos /* Size found, break out to check the 2731 1.1 christos final ']'. */ 2732 1.1 christos prefixp->opcode |= size_bits << 4; 2733 1.1 christos break; 2734 1.1 christos } 2735 1.1 christos } 2736 1.1 christos /* Not a register. Then this must be "[rN+I]". */ 2737 1.1 christos else if (cris_get_expression (cPP, &prefixp->expr)) 2738 1.1 christos { 2739 1.1 christos /* We've got offset with assign mode. Fill 2740 1.1 christos in the blanks and break out to match the 2741 1.1 christos final ']'. */ 2742 1.1 christos prefixp->kind = PREFIX_BDAP_IMM; 2743 1.1 christos 2744 1.1 christos /* We tentatively put an opcode corresponding to 2745 1.1 christos a 32-bit operand here, although it may be 2746 1.1 christos relaxed when there's no relocation 2747 1.1 christos specifier for the operand. */ 2748 1.1 christos prefixp->opcode 2749 1.1 christos = (BDAP_INDIR_OPCODE 2750 1.1 christos | (prefixp->base_reg_number << 12) 2751 1.1 christos | (AUTOINCR_BIT << 8) 2752 1.1 christos | (2 << 4) 2753 1.1 christos | REG_PC /* << 0 */); 2754 1.1 christos 2755 1.1 christos /* This can have a PIC suffix, specifying reloc 2756 1.1 christos type to use. */ 2757 1.1 christos if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR) 2758 1.1 christos { 2759 1.1 christos unsigned int relocsize; 2760 1.1 christos 2761 1.1 christos cris_get_reloc_suffix (cPP, &prefixp->reloc, 2762 1.1 christos &prefixp->expr); 2763 1.1 christos 2764 1.1 christos /* Tweak the size of the immediate operand 2765 1.1 christos in the prefix opcode if it isn't what we 2766 1.1 christos set. */ 2767 1.1 christos relocsize 2768 1.1 christos = cris_get_specified_reloc_size (prefixp->reloc); 2769 1.1 christos if (relocsize != 4) 2770 1.1 christos prefixp->opcode 2771 1.1 christos = ((prefixp->opcode & ~(3 << 4)) 2772 1.1 christos | ((relocsize >> 1) << 4)); 2773 1.1 christos } 2774 1.1 christos break; 2775 1.1 christos } 2776 1.1 christos else 2777 1.1 christos /* Neither register nor expression found, so 2778 1.1 christos this can't be a match. */ 2779 1.1 christos return 0; 2780 1.1 christos } 2781 1.1 christos /* Not "[rN+" but perhaps "[rN-"? */ 2782 1.1 christos else if (**cPP == '-') 2783 1.1 christos { 2784 1.1 christos /* We must have an offset with assign mode. */ 2785 1.1 christos if (! cris_get_expression (cPP, &prefixp->expr)) 2786 1.1 christos /* No expression, no match. */ 2787 1.1 christos return 0; 2788 1.1 christos else 2789 1.1 christos { 2790 1.1 christos /* We've got offset with assign mode. Fill 2791 1.1 christos in the blanks and break out to match the 2792 1.1 christos final ']'. 2793 1.1 christos 2794 1.1 christos Note that we don't allow a relocation 2795 1.1 christos suffix for an operand with a minus 2796 1.1 christos sign. */ 2797 1.1 christos prefixp->kind = PREFIX_BDAP_IMM; 2798 1.1 christos break; 2799 1.1 christos } 2800 1.1 christos } 2801 1.1 christos else 2802 1.1 christos /* Neither '+' nor '-' after "[rN=rM". Lose. */ 2803 1.1 christos return 0; 2804 1.1 christos } 2805 1.1 christos default: 2806 1.1 christos /* Neither ']' nor '+' nor '=' after "[rN". Lose. */ 2807 1.1 christos return 0; 2808 1.1 christos } 2809 1.1 christos } 2810 1.1 christos 2811 1.1 christos /* When we get here, we have a match and will just check the closing 2812 1.1 christos ']'. We can still fail though. */ 2813 1.1 christos if (**cPP != ']') 2814 1.1 christos return 0; 2815 1.1 christos else 2816 1.1 christos { 2817 1.1 christos /* Don't forget to consume the final ']'. 2818 1.1 christos Then return in glory. */ 2819 1.1 christos (*cPP)++; 2820 1.1 christos return 1; 2821 1.1 christos } 2822 1.1 christos } 2823 1.1 christos /* No indirection. Perhaps a constant? */ 2824 1.1 christos else if (cris_get_expression (cPP, imm_exprP)) 2825 1.1 christos { 2826 1.1 christos /* Expression found, this is immediate mode. */ 2827 1.1 christos prefixp->kind = PREFIX_NONE; 2828 1.1 christos *is_autoincp = 1; 2829 1.1 christos *src_regnop = REG_PC; 2830 1.1 christos *imm_foundp = 1; 2831 1.1 christos 2832 1.1 christos /* This can have a PIC suffix, specifying reloc type to use. The 2833 1.1 christos caller must check that the reloc size matches the operand size. */ 2834 1.1 christos if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR) 2835 1.1 christos cris_get_reloc_suffix (cPP, &prefixp->reloc, imm_exprP); 2836 1.1 christos 2837 1.1 christos return 1; 2838 1.1 christos } 2839 1.1 christos 2840 1.1 christos /* No luck today. */ 2841 1.1 christos return 0; 2842 1.1 christos } 2843 1.1 christos 2844 1.1 christos /* This function gets an indirect operand in a three-address operand 2845 1.1 christos combination from the string pointed out by *cPP. The pointer *cPP is 2846 1.1 christos advanced to the character following the indirect operand on success, or 2847 1.1 christos has an unspecified value on failure. 2848 1.1 christos 2849 1.1 christos cPP Pointer to pointer to string beginning 2850 1.1 christos with the operand 2851 1.1 christos 2852 1.1 christos prefixp Pointer to structure containing an 2853 1.1 christos instruction prefix 2854 1.1 christos 2855 1.1 christos Returns 1 iff a correct indirect operand is found. */ 2856 1.1 christos 2857 1.1 christos static int 2858 1.1 christos get_3op_or_dip_prefix_op (char **cPP, struct cris_prefix *prefixp) 2859 1.1 christos { 2860 1.1 christos int reg_number; 2861 1.1 christos 2862 1.1 christos if (**cPP != '[') 2863 1.1 christos /* We must have a '[' or it's a clean failure. */ 2864 1.1 christos return 0; 2865 1.1 christos 2866 1.1 christos /* Eat the first '['. */ 2867 1.1 christos (*cPP)++; 2868 1.1 christos 2869 1.1 christos if (**cPP == '[') 2870 1.1 christos { 2871 1.1 christos /* A second '[', so this must be double-indirect mode. */ 2872 1.1 christos (*cPP)++; 2873 1.1 christos prefixp->kind = PREFIX_DIP; 2874 1.1 christos prefixp->opcode = DIP_OPCODE; 2875 1.1 christos 2876 1.1 christos /* Get the register or fail entirely. */ 2877 1.1 christos if (! get_gen_reg (cPP, ®_number)) 2878 1.1 christos return 0; 2879 1.1 christos else 2880 1.1 christos { 2881 1.1 christos prefixp->opcode |= reg_number /* << 0 */ ; 2882 1.1 christos if (**cPP == '+') 2883 1.1 christos { 2884 1.1 christos /* Since we found a '+', this must be double-indirect 2885 1.1 christos autoincrement mode. */ 2886 1.1 christos (*cPP)++; 2887 1.1 christos prefixp->opcode |= AUTOINCR_BIT << 8; 2888 1.1 christos } 2889 1.1 christos 2890 1.1 christos /* There's nothing particular to do, if this was a 2891 1.1 christos double-indirect *without* autoincrement. */ 2892 1.1 christos } 2893 1.1 christos 2894 1.1 christos /* Check the first ']'. The second one is checked at the end. */ 2895 1.1 christos if (**cPP != ']') 2896 1.1 christos return 0; 2897 1.1 christos 2898 1.1 christos /* Eat the first ']', so we'll be looking at a second ']'. */ 2899 1.1 christos (*cPP)++; 2900 1.1 christos } 2901 1.1 christos /* No second '['. Then we should have a register here, making 2902 1.1 christos it "[rN". */ 2903 1.1 christos else if (get_gen_reg (cPP, &prefixp->base_reg_number)) 2904 1.1 christos { 2905 1.1 christos /* This must be indexed or offset mode: "[rN+I]" or 2906 1.1 christos "[rN+rM.S]" or "[rN+[rM].S]" or "[rN+[rM+].S]". */ 2907 1.1 christos if (**cPP == '+') 2908 1.1 christos { 2909 1.1 christos int index_reg_number; 2910 1.1 christos 2911 1.1 christos (*cPP)++; 2912 1.1 christos 2913 1.1 christos if (**cPP == '[') 2914 1.1 christos { 2915 1.1 christos /* This is "[rx+["... Expect a register next. */ 2916 1.1 christos int size_bits; 2917 1.1 christos (*cPP)++; 2918 1.1 christos 2919 1.1 christos if (!get_gen_reg (cPP, &index_reg_number)) 2920 1.1 christos return 0; 2921 1.1 christos 2922 1.1 christos prefixp->kind = PREFIX_BDAP; 2923 1.1 christos prefixp->opcode 2924 1.1 christos = (BDAP_INDIR_OPCODE 2925 1.1 christos + (prefixp->base_reg_number << 12) 2926 1.1 christos + index_reg_number); 2927 1.1 christos 2928 1.1 christos /* We've seen "[rx+[ry", so check if this is 2929 1.1 christos autoincrement. */ 2930 1.1 christos if (**cPP == '+') 2931 1.1 christos { 2932 1.1 christos /* Yep, now at "[rx+[ry+". */ 2933 1.1 christos (*cPP)++; 2934 1.1 christos prefixp->opcode |= AUTOINCR_BIT << 8; 2935 1.1 christos } 2936 1.1 christos /* If it wasn't autoincrement, we don't need to 2937 1.1 christos add anything. */ 2938 1.1 christos 2939 1.1 christos /* Check a first closing ']': "[rx+[ry]" or 2940 1.1 christos "[rx+[ry+]". */ 2941 1.1 christos if (**cPP != ']') 2942 1.1 christos return 0; 2943 1.1 christos (*cPP)++; 2944 1.1 christos 2945 1.1 christos /* Now expect a size modifier ".S". */ 2946 1.1 christos if (! get_bwd_size_modifier (cPP, &size_bits)) 2947 1.1 christos return 0; 2948 1.1 christos 2949 1.1 christos prefixp->opcode |= size_bits << 4; 2950 1.1 christos 2951 1.1 christos /* Ok, all interesting stuff has been seen: 2952 1.1 christos "[rx+[ry+].S" or "[rx+[ry].S". We only need to 2953 1.1 christos expect a final ']', which we'll do in a common 2954 1.1 christos closing session. */ 2955 1.1 christos } 2956 1.1 christos /* Seen "[rN+", but not a '[', so check if we have a 2957 1.1 christos register. */ 2958 1.1 christos else if (get_gen_reg (cPP, &index_reg_number)) 2959 1.1 christos { 2960 1.1 christos /* This is indexed mode: "[rN+rM.S]" or 2961 1.1 christos "[rN+rM.S+]". */ 2962 1.1 christos int size_bits; 2963 1.1 christos prefixp->kind = PREFIX_BIAP; 2964 1.1 christos prefixp->opcode 2965 1.1 christos = (BIAP_OPCODE 2966 1.1 christos | prefixp->base_reg_number /* << 0 */ 2967 1.1 christos | (index_reg_number << 12)); 2968 1.1 christos 2969 1.1 christos /* Consume the ".S". */ 2970 1.1 christos if (! get_bwd_size_modifier (cPP, &size_bits)) 2971 1.1 christos /* Missing size, so fail. */ 2972 1.1 christos return 0; 2973 1.1 christos else 2974 1.1 christos /* Size found. Add that piece and drop down to 2975 1.1 christos the common checking of the closing ']'. */ 2976 1.1 christos prefixp->opcode |= size_bits << 4; 2977 1.1 christos } 2978 1.1 christos /* Seen "[rN+", but not a '[' or a register, so then 2979 1.1 christos it must be a constant "I". 2980 1.1 christos 2981 1.1 christos As a quality of implementation improvement, we check for a 2982 1.1 christos closing ']', like in an erroneous "[rN+]". If we don't, 2983 1.1 christos the expression parser will emit a confusing "bad 2984 1.1 christos expression" when it sees the ']', probably because it 2985 1.1 christos doesn't like seeing no expression. */ 2986 1.1 christos else if (**cPP != ']' && cris_get_expression (cPP, &prefixp->expr)) 2987 1.1 christos { 2988 1.1 christos /* Expression found, so fill in the bits of offset 2989 1.1 christos mode and drop down to check the closing ']'. */ 2990 1.1 christos prefixp->kind = PREFIX_BDAP_IMM; 2991 1.1 christos 2992 1.1 christos /* We tentatively put an opcode corresponding to a 32-bit 2993 1.1 christos operand here, although it may be relaxed when there's no 2994 1.1 christos PIC specifier for the operand. */ 2995 1.1 christos prefixp->opcode 2996 1.1 christos = (BDAP_INDIR_OPCODE 2997 1.1 christos | (prefixp->base_reg_number << 12) 2998 1.1 christos | (AUTOINCR_BIT << 8) 2999 1.1 christos | (2 << 4) 3000 1.1 christos | REG_PC /* << 0 */); 3001 1.1 christos 3002 1.1 christos /* This can have a PIC suffix, specifying reloc type to use. */ 3003 1.1 christos if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR) 3004 1.1 christos { 3005 1.1 christos unsigned int relocsize; 3006 1.1 christos 3007 1.1 christos cris_get_reloc_suffix (cPP, &prefixp->reloc, &prefixp->expr); 3008 1.1 christos 3009 1.1 christos /* Tweak the size of the immediate operand in the prefix 3010 1.1 christos opcode if it isn't what we set. */ 3011 1.1 christos relocsize = cris_get_specified_reloc_size (prefixp->reloc); 3012 1.1 christos if (relocsize != 4) 3013 1.1 christos prefixp->opcode 3014 1.1 christos = ((prefixp->opcode & ~(3 << 4)) 3015 1.1 christos | ((relocsize >> 1) << 4)); 3016 1.1 christos } 3017 1.1 christos } 3018 1.1 christos else 3019 1.1 christos /* Nothing valid here: lose. */ 3020 1.1 christos return 0; 3021 1.1 christos } 3022 1.1 christos /* Seen "[rN" but no '+', so check if it's a '-'. */ 3023 1.1 christos else if (**cPP == '-') 3024 1.1 christos { 3025 1.1 christos /* Yep, we must have offset mode. */ 3026 1.1 christos if (! cris_get_expression (cPP, &prefixp->expr)) 3027 1.1 christos /* No expression, so we lose. */ 3028 1.1 christos return 0; 3029 1.1 christos else 3030 1.1 christos { 3031 1.1 christos /* Expression found to make this offset mode, so 3032 1.1 christos fill those bits and drop down to check the 3033 1.1 christos closing ']'. 3034 1.1 christos 3035 1.1 christos Note that we don't allow a PIC suffix for 3036 1.1 christos an operand with a minus sign like this. */ 3037 1.1 christos prefixp->kind = PREFIX_BDAP_IMM; 3038 1.1 christos } 3039 1.1 christos } 3040 1.1 christos else 3041 1.1 christos { 3042 1.1 christos /* We've seen "[rN", but not '+' or '-'; rather a ']'. 3043 1.1 christos Hmm. Normally this is a simple indirect mode that we 3044 1.1 christos shouldn't match, but if we expect ']', then we have a 3045 1.1 christos zero offset, so it can be a three-address-operand, 3046 1.1 christos like "[rN],rO,rP", thus offset mode. 3047 1.1 christos 3048 1.1 christos Don't eat the ']', that will be done in the closing 3049 1.1 christos ceremony. */ 3050 1.1 christos prefixp->expr.X_op = O_constant; 3051 1.1 christos prefixp->expr.X_add_number = 0; 3052 1.1 christos prefixp->expr.X_add_symbol = NULL; 3053 1.1 christos prefixp->expr.X_op_symbol = NULL; 3054 1.1 christos prefixp->kind = PREFIX_BDAP_IMM; 3055 1.1 christos } 3056 1.1 christos } 3057 1.1 christos /* A '[', but no second '[', and no register. Check if we 3058 1.1 christos have an expression, making this "[I]" for a double-indirect 3059 1.1 christos prefix. */ 3060 1.1 christos else if (cris_get_expression (cPP, &prefixp->expr)) 3061 1.1 christos { 3062 1.1 christos /* Expression found, the so called absolute mode for a 3063 1.1 christos double-indirect prefix on PC. */ 3064 1.1 christos prefixp->kind = PREFIX_DIP; 3065 1.1 christos prefixp->opcode = DIP_OPCODE | (AUTOINCR_BIT << 8) | REG_PC; 3066 1.1 christos prefixp->reloc = BFD_RELOC_32; 3067 1.1 christos 3068 1.1 christos /* For :GD and :IE, it makes sense to have TLS specifiers here. */ 3069 1.1 christos if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR) 3070 1.1 christos cris_get_reloc_suffix (cPP, &prefixp->reloc, &prefixp->expr); 3071 1.1 christos } 3072 1.1 christos else 3073 1.1 christos /* Neither '[' nor register nor expression. We lose. */ 3074 1.1 christos return 0; 3075 1.1 christos 3076 1.1 christos /* We get here as a closing ceremony to a successful match. We just 3077 1.1 christos need to check the closing ']'. */ 3078 1.1 christos if (**cPP != ']') 3079 1.1 christos /* Oops. Close but no air-polluter. */ 3080 1.1 christos return 0; 3081 1.1 christos 3082 1.1 christos /* Don't forget to consume that ']', before returning in glory. */ 3083 1.1 christos (*cPP)++; 3084 1.1 christos return 1; 3085 1.1 christos } 3086 1.1 christos 3087 1.1 christos /* Get an expression from the string pointed out by *cPP. 3088 1.1 christos The pointer *cPP is advanced to the character following the expression 3089 1.1 christos on a success, or retains its original value otherwise. 3090 1.1 christos 3091 1.1 christos cPP Pointer to pointer to string beginning with the expression. 3092 1.1 christos 3093 1.1 christos exprP Pointer to structure containing the expression. 3094 1.1 christos 3095 1.1 christos Return 1 iff a correct expression is found. */ 3096 1.1 christos 3097 1.1 christos static int 3098 1.1 christos cris_get_expression (char **cPP, expressionS *exprP) 3099 1.1 christos { 3100 1.1 christos char *saved_input_line_pointer; 3101 1.1 christos 3102 1.1 christos /* The "expression" function expects to find an expression at the 3103 1.1 christos global variable input_line_pointer, so we have to save it to give 3104 1.1 christos the impression that we don't fiddle with global variables. */ 3105 1.1 christos saved_input_line_pointer = input_line_pointer; 3106 1.1 christos input_line_pointer = *cPP; 3107 1.1 christos 3108 1.1 christos /* Avoid a common error, confusing addressing modes. Beware that the 3109 1.1 christos call to expression below does not signal that error; it treats [] 3110 1.1 christos as parentheses, unless #define NEED_INDEX_OPERATOR in which case it 3111 1.1 christos gives them other confusing semantics rather than plain outlawing 3112 1.1 christos them, which is what we want. */ 3113 1.1 christos if (*input_line_pointer == '[') 3114 1.1 christos { 3115 1.1 christos input_line_pointer = saved_input_line_pointer; 3116 1.1 christos return 0; 3117 1.1 christos } 3118 1.1 christos 3119 1.1 christos expression (exprP); 3120 1.1 christos if (exprP->X_op == O_illegal || exprP->X_op == O_absent) 3121 1.1 christos { 3122 1.1 christos input_line_pointer = saved_input_line_pointer; 3123 1.1 christos return 0; 3124 1.1 christos } 3125 1.1 christos 3126 1.1 christos /* Everything seems to be fine, just restore the global 3127 1.1 christos input_line_pointer and say we're successful. */ 3128 1.1 christos *cPP = input_line_pointer; 3129 1.1 christos input_line_pointer = saved_input_line_pointer; 3130 1.1 christos return 1; 3131 1.1 christos } 3132 1.1 christos 3133 1.1 christos /* Get a sequence of flag characters from *spp. The pointer *cPP is 3134 1.1 christos advanced to the character following the expression. The flag 3135 1.1 christos characters are consecutive, no commas or spaces. 3136 1.1 christos 3137 1.1 christos cPP Pointer to pointer to string beginning with the expression. 3138 1.1 christos 3139 1.1 christos flagp Pointer to int to return the flags expression. 3140 1.1 christos 3141 1.1 christos Return 1 iff a correct flags expression is found. */ 3142 1.1 christos 3143 1.1 christos static int 3144 1.1 christos get_flags (char **cPP, int *flagsp) 3145 1.1 christos { 3146 1.1 christos for (;;) 3147 1.1 christos { 3148 1.1 christos switch (**cPP) 3149 1.1 christos { 3150 1.1 christos case 'd': 3151 1.1 christos case 'D': 3152 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v0_3, 3153 1.1 christos cris_arch)) 3154 1.1 christos return 0; 3155 1.1 christos *flagsp |= 0x80; 3156 1.1 christos break; 3157 1.1 christos 3158 1.1 christos case 'm': 3159 1.1 christos case 'M': 3160 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v8_10, 3161 1.1 christos cris_arch)) 3162 1.1 christos return 0; 3163 1.1 christos *flagsp |= 0x80; 3164 1.1 christos break; 3165 1.1 christos 3166 1.1 christos case 'e': 3167 1.1 christos case 'E': 3168 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v0_3, 3169 1.1 christos cris_arch)) 3170 1.1 christos return 0; 3171 1.1 christos *flagsp |= 0x40; 3172 1.1 christos break; 3173 1.1 christos 3174 1.1 christos case 'b': 3175 1.1 christos case 'B': 3176 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v8_10, 3177 1.1 christos cris_arch)) 3178 1.1 christos return 0; 3179 1.1 christos *flagsp |= 0x40; 3180 1.1 christos break; 3181 1.1 christos 3182 1.1 christos case 'p': 3183 1.1 christos case 'P': 3184 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v32p, 3185 1.1 christos cris_arch)) 3186 1.1 christos return 0; 3187 1.1 christos *flagsp |= 0x80; 3188 1.1 christos break; 3189 1.1 christos 3190 1.1 christos case 'u': 3191 1.1 christos case 'U': 3192 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v32p, 3193 1.1 christos cris_arch)) 3194 1.1 christos return 0; 3195 1.1 christos *flagsp |= 0x40; 3196 1.1 christos break; 3197 1.1 christos 3198 1.1 christos case 'i': 3199 1.1 christos case 'I': 3200 1.1 christos *flagsp |= 0x20; 3201 1.1 christos break; 3202 1.1 christos 3203 1.1 christos case 'x': 3204 1.1 christos case 'X': 3205 1.1 christos *flagsp |= 0x10; 3206 1.1 christos break; 3207 1.1 christos 3208 1.1 christos case 'n': 3209 1.1 christos case 'N': 3210 1.1 christos *flagsp |= 0x8; 3211 1.1 christos break; 3212 1.1 christos 3213 1.1 christos case 'z': 3214 1.1 christos case 'Z': 3215 1.1 christos *flagsp |= 0x4; 3216 1.1 christos break; 3217 1.1 christos 3218 1.1 christos case 'v': 3219 1.1 christos case 'V': 3220 1.1 christos *flagsp |= 0x2; 3221 1.1 christos break; 3222 1.1 christos 3223 1.1 christos case 'c': 3224 1.1 christos case 'C': 3225 1.1 christos *flagsp |= 1; 3226 1.1 christos break; 3227 1.1 christos 3228 1.1 christos default: 3229 1.1 christos /* We consider this successful if we stop at a comma or 3230 1.1 christos whitespace. Anything else, and we consider it a failure. */ 3231 1.1 christos if (**cPP != ',' 3232 1.1 christos && **cPP != 0 3233 1.10 christos && ! is_whitespace (**cPP)) 3234 1.1 christos return 0; 3235 1.1 christos else 3236 1.1 christos return 1; 3237 1.1 christos } 3238 1.1 christos 3239 1.1 christos /* Don't forget to consume each flag character. */ 3240 1.1 christos (*cPP)++; 3241 1.1 christos } 3242 1.1 christos } 3243 1.1 christos 3244 1.1 christos /* Generate code and fixes for a BDAP prefix. 3245 1.1 christos For v32, this handles ADDOQ because thankfully the opcodes are the 3246 1.1 christos same. 3247 1.1 christos 3248 1.1 christos base_regno Int containing the base register number. 3249 1.1 christos 3250 1.1 christos exprP Pointer to structure containing the offset expression. */ 3251 1.1 christos 3252 1.1 christos static void 3253 1.1 christos gen_bdap (int base_regno, expressionS *exprP) 3254 1.1 christos { 3255 1.1 christos unsigned int opcode; 3256 1.1 christos char *opcodep; 3257 1.1 christos 3258 1.1 christos /* Put out the prefix opcode; assume quick immediate mode at first. */ 3259 1.1 christos opcode = BDAP_QUICK_OPCODE | (base_regno << 12); 3260 1.1 christos opcodep = cris_insn_first_word_frag (); 3261 1.1 christos md_number_to_chars (opcodep, opcode, 2); 3262 1.1 christos 3263 1.1 christos if (exprP->X_op == O_constant) 3264 1.1 christos { 3265 1.1 christos /* We have an absolute expression that we know the size of right 3266 1.1 christos now. */ 3267 1.1 christos long int value; 3268 1.1 christos int size; 3269 1.1 christos 3270 1.1 christos value = exprP->X_add_number; 3271 1.1 christos if (value < -32768 || value > 32767) 3272 1.1 christos /* Outside range for a "word", make it a dword. */ 3273 1.1 christos size = 2; 3274 1.1 christos else 3275 1.1 christos /* Assume "word" size. */ 3276 1.1 christos size = 1; 3277 1.1 christos 3278 1.1 christos /* If this is a signed-byte value, we can fit it into the prefix 3279 1.1 christos insn itself. */ 3280 1.1 christos if (value >= -128 && value <= 127) 3281 1.1 christos opcodep[0] = value; 3282 1.1 christos else 3283 1.1 christos { 3284 1.1 christos /* This is a word or dword displacement, which will be put in a 3285 1.1 christos word or dword after the prefix. */ 3286 1.1 christos char *p; 3287 1.1 christos 3288 1.1 christos opcodep[0] = BDAP_PC_LOW + (size << 4); 3289 1.1 christos opcodep[1] &= 0xF0; 3290 1.1 christos opcodep[1] |= BDAP_INCR_HIGH; 3291 1.1 christos p = frag_more (1 << size); 3292 1.1 christos md_number_to_chars (p, value, 1 << size); 3293 1.1 christos } 3294 1.1 christos } 3295 1.1 christos else 3296 1.1 christos { 3297 1.1 christos /* Handle complex expressions. */ 3298 1.1 christos valueT addvalue 3299 1.1 christos = SIMPLE_EXPR (exprP) ? exprP->X_add_number : 0; 3300 1.1 christos symbolS *sym 3301 1.1 christos = (SIMPLE_EXPR (exprP) 3302 1.1 christos ? exprP->X_add_symbol : make_expr_symbol (exprP)); 3303 1.1 christos 3304 1.1 christos /* The expression is not defined yet but may become absolute. We 3305 1.1 christos make it a relocation to be relaxed. */ 3306 1.1 christos frag_var (rs_machine_dependent, 4, 0, 3307 1.1 christos ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF), 3308 1.1 christos sym, addvalue, opcodep); 3309 1.1 christos } 3310 1.1 christos } 3311 1.1 christos 3312 1.1 christos /* Encode a branch displacement in the range -256..254 into the form used 3313 1.1 christos by CRIS conditional branch instructions. 3314 1.1 christos 3315 1.1 christos offset The displacement value in bytes. */ 3316 1.1 christos 3317 1.1 christos static int 3318 1.1 christos branch_disp (int offset) 3319 1.1 christos { 3320 1.1 christos int disp; 3321 1.1 christos 3322 1.1 christos /* Adjust all short branch offsets here. */ 3323 1.1 christos if (cris_arch == arch_crisv32 || cris_arch == arch_cris_common_v10_v32) 3324 1.1 christos offset += 2; 3325 1.1 christos 3326 1.1 christos disp = offset & 0xFE; 3327 1.1 christos 3328 1.1 christos if (offset < 0) 3329 1.1 christos disp |= 1; 3330 1.1 christos 3331 1.1 christos return disp; 3332 1.1 christos } 3333 1.1 christos 3334 1.1 christos /* Generate code and fixes for a 32-bit conditional branch instruction 3335 1.1 christos created by "extending" an existing 8-bit branch instruction. 3336 1.1 christos 3337 1.1 christos opcodep Pointer to the word containing the original 8-bit branch 3338 1.1 christos instruction. 3339 1.1 christos 3340 1.1 christos writep Pointer to "extension area" following the first instruction 3341 1.1 christos word. 3342 1.1 christos 3343 1.1 christos fragP Pointer to the frag containing the instruction. 3344 1.1 christos 3345 1.1 christos add_symP, Parts of the destination address expression. 3346 1.1 christos sub_symP, 3347 1.1 christos add_num. */ 3348 1.1 christos 3349 1.1 christos static void 3350 1.1 christos gen_cond_branch_32 (char *opcodep, char *writep, fragS *fragP, 3351 1.1 christos symbolS *add_symP, symbolS *sub_symP, long int add_num) 3352 1.1 christos { 3353 1.1 christos int nop_opcode; 3354 1.1 christos int opc_offset; 3355 1.1 christos int branch_offset; 3356 1.1 christos 3357 1.1 christos if (cris_arch == arch_crisv32) 3358 1.1 christos { 3359 1.1 christos nop_opcode = NOP_OPCODE_V32; 3360 1.1 christos opc_offset = 10; 3361 1.1 christos branch_offset = -2 - 8; 3362 1.1 christos } 3363 1.1 christos else if (pic) 3364 1.1 christos { 3365 1.1 christos nop_opcode = NOP_OPCODE; 3366 1.1 christos opc_offset = 10; 3367 1.1 christos branch_offset = -2 - 8; 3368 1.1 christos } 3369 1.1 christos else 3370 1.1 christos { 3371 1.1 christos nop_opcode = NOP_OPCODE; 3372 1.1 christos opc_offset = 8; 3373 1.1 christos branch_offset = -2 - 6; 3374 1.1 christos } 3375 1.1 christos 3376 1.1 christos /* We should never get here for compatibility mode. */ 3377 1.1 christos if (cris_arch == arch_cris_common_v10_v32) 3378 1.1 christos as_fatal (_("Calling gen_cond_branch_32 for .arch common_v10_v32\n")); 3379 1.1 christos 3380 1.1 christos if (warn_for_branch_expansion) 3381 1.1 christos as_warn_where (fragP->fr_file, fragP->fr_line, 3382 1.1 christos _("32-bit conditional branch generated")); 3383 1.1 christos 3384 1.1 christos /* Here, writep points to what will be opcodep + 2. First, we change 3385 1.1 christos the actual branch in opcodep[0] and opcodep[1], so that in the 3386 1.1 christos final insn, it will look like: 3387 1.1 christos opcodep+10: Bcc .-6 3388 1.1 christos 3389 1.1 christos This means we don't have to worry about changing the opcode or 3390 1.1 christos messing with the delay-slot instruction. So, we move it to last in 3391 1.1 christos the "extended" branch, and just change the displacement. Admittedly, 3392 1.1 christos it's not the optimal extended construct, but we should get this 3393 1.1 christos rarely enough that it shouldn't matter. */ 3394 1.1 christos 3395 1.1 christos writep[opc_offset] = branch_disp (branch_offset); 3396 1.1 christos writep[opc_offset + 1] = opcodep[1]; 3397 1.1 christos 3398 1.1 christos /* Then, we change the branch to an unconditional branch over the 3399 1.1 christos extended part, to the new location of the Bcc: 3400 1.1 christos opcodep: BA .+10 3401 1.1 christos opcodep+2: NOP 3402 1.1 christos 3403 1.1 christos Note that these two writes are to currently different locations, 3404 1.1 christos merged later. */ 3405 1.1 christos 3406 1.1 christos md_number_to_chars (opcodep, BA_QUICK_OPCODE 3407 1.1 christos + (cris_arch == arch_crisv32 ? 12 : (pic ? 10 : 8)), 3408 1.1 christos 2); 3409 1.1 christos md_number_to_chars (writep, nop_opcode, 2); 3410 1.1 christos 3411 1.1 christos /* Then the extended thing, the 32-bit jump insn. 3412 1.1 christos opcodep+4: JUMP [PC+] 3413 1.1 christos or, in the PIC case, 3414 1.1 christos opcodep+4: MOVE [PC=PC+N],P0. */ 3415 1.1 christos 3416 1.1 christos md_number_to_chars (writep + 2, 3417 1.1 christos cris_arch == arch_crisv32 3418 1.1 christos ? BA_DWORD_OPCODE 3419 1.1 christos : (pic ? MOVE_PC_INCR_OPCODE_PREFIX 3420 1.1 christos : JUMP_PC_INCR_OPCODE), 2); 3421 1.1 christos 3422 1.1 christos /* We have to fill in the actual value too. 3423 1.1 christos opcodep+6: .DWORD 3424 1.1 christos This is most probably an expression, but we can cope with an absolute 3425 1.1 christos value too. FIXME: Testcase needed with and without pic. */ 3426 1.1 christos 3427 1.1 christos if (add_symP == NULL && sub_symP == NULL) 3428 1.1 christos { 3429 1.1 christos /* An absolute address. */ 3430 1.1 christos if (pic || cris_arch == arch_crisv32) 3431 1.1 christos fix_new (fragP, writep + 4 - fragP->fr_literal, 4, 3432 1.1 christos section_symbol (absolute_section), 3433 1.1 christos add_num 3434 1.1 christos + (cris_arch == arch_crisv32 ? 6 : 0), 3435 1.1 christos 1, BFD_RELOC_32_PCREL); 3436 1.1 christos else 3437 1.1 christos md_number_to_chars (writep + 4, add_num, 4); 3438 1.1 christos } 3439 1.1 christos else 3440 1.1 christos { 3441 1.1 christos if (sub_symP != NULL) 3442 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line, 3443 1.1 christos _("Complex expression not supported")); 3444 1.1 christos 3445 1.1 christos /* Not absolute, we have to make it a frag for later evaluation. */ 3446 1.1 christos fix_new (fragP, writep + 4 - fragP->fr_literal, 4, add_symP, 3447 1.1 christos add_num + (cris_arch == arch_crisv32 ? 6 : 0), 3448 1.1 christos pic || cris_arch == arch_crisv32 ? 1 : 0, 3449 1.1 christos pic || cris_arch == arch_crisv32 3450 1.1 christos ? BFD_RELOC_32_PCREL : BFD_RELOC_32); 3451 1.1 christos } 3452 1.1 christos 3453 1.1 christos if (cris_arch == arch_crisv32) 3454 1.1 christos /* Follow it with a "NOP" for CRISv32. */ 3455 1.1 christos md_number_to_chars (writep + 8, NOP_OPCODE_V32, 2); 3456 1.1 christos else if (pic) 3457 1.1 christos /* ...and the rest of the move-opcode for pre-v32 PIC. */ 3458 1.1 christos md_number_to_chars (writep + 8, MOVE_PC_INCR_OPCODE_SUFFIX, 2); 3459 1.1 christos } 3460 1.1 christos 3461 1.1 christos /* Get the size of an immediate-reloc in bytes. Only valid for 3462 1.1 christos specified relocs (TLS, PIC). */ 3463 1.1 christos 3464 1.1 christos static unsigned int 3465 1.1 christos cris_get_specified_reloc_size (bfd_reloc_code_real_type reloc) 3466 1.1 christos { 3467 1.1 christos return 3468 1.1 christos reloc == BFD_RELOC_CRIS_16_GOTPLT 3469 1.1 christos || reloc == BFD_RELOC_CRIS_16_GOT 3470 1.1 christos || reloc == BFD_RELOC_CRIS_16_GOT_GD 3471 1.1 christos || reloc == BFD_RELOC_CRIS_16_DTPREL 3472 1.1 christos || reloc == BFD_RELOC_CRIS_16_GOT_TPREL 3473 1.1 christos || reloc == BFD_RELOC_CRIS_16_TPREL 3474 1.1 christos ? 2 : 4; 3475 1.1 christos } 3476 1.1 christos 3477 1.1 christos /* Store a reloc type at *RELOCP corresponding to the PIC suffix at *CPP. 3478 1.1 christos Adjust *EXPRP with any addend found after the PIC suffix. */ 3479 1.1 christos 3480 1.1 christos static void 3481 1.1 christos cris_get_reloc_suffix (char **cPP, bfd_reloc_code_real_type *relocp, 3482 1.1 christos expressionS *exprP) 3483 1.1 christos { 3484 1.1 christos char *s = *cPP; 3485 1.1 christos unsigned int i; 3486 1.1 christos expressionS const_expr; 3487 1.1 christos 3488 1.1 christos const struct pic_suffixes_struct 3489 1.1 christos { 3490 1.1 christos const char *const suffix; 3491 1.1 christos unsigned int len; 3492 1.1 christos bfd_reloc_code_real_type reloc; 3493 1.8 christos bool pic_p; 3494 1.8 christos bool tls_p; 3495 1.1 christos } pic_suffixes[] = 3496 1.1 christos { 3497 1.1 christos #undef PICMAP 3498 1.8 christos #define PICMAP(s, r) {s, sizeof (s) - 1, r, true, false} 3499 1.8 christos #define PICTLSMAP(s, r) {s, sizeof (s) - 1, r, true, true} 3500 1.8 christos #define TLSMAP(s, r) {s, sizeof (s) - 1, r, false, true} 3501 1.1 christos /* Keep this in order with longest unambiguous prefix first. */ 3502 1.1 christos PICMAP ("GOTPLT16", BFD_RELOC_CRIS_16_GOTPLT), 3503 1.1 christos PICMAP ("GOTPLT", BFD_RELOC_CRIS_32_GOTPLT), 3504 1.1 christos PICMAP ("PLTG", BFD_RELOC_CRIS_32_PLT_GOTREL), 3505 1.1 christos PICMAP ("PLT", BFD_RELOC_CRIS_32_PLT_PCREL), 3506 1.1 christos PICMAP ("GOTOFF", BFD_RELOC_CRIS_32_GOTREL), 3507 1.1 christos PICMAP ("GOT16", BFD_RELOC_CRIS_16_GOT), 3508 1.1 christos PICMAP ("GOT", BFD_RELOC_CRIS_32_GOT), 3509 1.1 christos PICTLSMAP ("GDGOTREL16", BFD_RELOC_CRIS_16_GOT_GD), 3510 1.1 christos PICTLSMAP ("GDGOTREL", BFD_RELOC_CRIS_32_GOT_GD), 3511 1.1 christos TLSMAP ("GD", BFD_RELOC_CRIS_32_GD), 3512 1.1 christos PICTLSMAP ("DTPREL16", BFD_RELOC_CRIS_16_DTPREL), 3513 1.1 christos PICTLSMAP ("DTPREL", BFD_RELOC_CRIS_32_DTPREL), 3514 1.1 christos TLSMAP ("IE", BFD_RELOC_CRIS_32_IE), 3515 1.1 christos PICTLSMAP ("TPOFFGOT16", BFD_RELOC_CRIS_16_GOT_TPREL), 3516 1.1 christos PICTLSMAP ("TPOFFGOT", BFD_RELOC_CRIS_32_GOT_TPREL), 3517 1.1 christos TLSMAP ("TPOFF16", BFD_RELOC_CRIS_16_TPREL), 3518 1.1 christos TLSMAP ("TPOFF", BFD_RELOC_CRIS_32_TPREL) 3519 1.1 christos }; 3520 1.1 christos 3521 1.1 christos /* We've already seen the ':', so consume it. */ 3522 1.1 christos s++; 3523 1.1 christos 3524 1.1 christos for (i = 0; i < sizeof (pic_suffixes)/sizeof (pic_suffixes[0]); i++) 3525 1.1 christos { 3526 1.1 christos if (strncmp (s, pic_suffixes[i].suffix, pic_suffixes[i].len) == 0 3527 1.1 christos && ! is_part_of_name (s[pic_suffixes[i].len]) 3528 1.1 christos /* PIC and non-PIC relocations are exclusive. */ 3529 1.1 christos && (pic != 0) == (pic_suffixes[i].pic_p != 0) 3530 1.1 christos /* But TLS can be active for non-TLS relocations too. */ 3531 1.1 christos && (pic_suffixes[i].tls_p == 0 || tls)) 3532 1.1 christos { 3533 1.1 christos /* We have a match. Consume the suffix and set the relocation 3534 1.1 christos type. */ 3535 1.1 christos s += pic_suffixes[i].len; 3536 1.1 christos 3537 1.1 christos /* There can be a constant term appended. If so, we will add it 3538 1.1 christos to *EXPRP. */ 3539 1.1 christos if (*s == '+' || *s == '-') 3540 1.1 christos { 3541 1.1 christos if (! cris_get_expression (&s, &const_expr)) 3542 1.1 christos /* There was some kind of syntax error. Bail out. */ 3543 1.1 christos break; 3544 1.1 christos 3545 1.1 christos /* Allow complex expressions as the constant part. It still 3546 1.1 christos has to be an assembly-time constant or there will be an 3547 1.1 christos error emitting the reloc. This makes the PIC qualifiers 3548 1.1 christos idempotent; foo:GOTOFF+32 == foo+32:GOTOFF. The former we 3549 1.1 christos recognize here; the latter is parsed in the incoming 3550 1.1 christos expression. */ 3551 1.1 christos exprP->X_add_symbol = make_expr_symbol (exprP); 3552 1.1 christos exprP->X_op = O_add; 3553 1.1 christos exprP->X_add_number = 0; 3554 1.1 christos exprP->X_op_symbol = make_expr_symbol (&const_expr); 3555 1.1 christos } 3556 1.1 christos 3557 1.1 christos *relocp = pic_suffixes[i].reloc; 3558 1.1 christos *cPP = s; 3559 1.1 christos return; 3560 1.1 christos } 3561 1.1 christos } 3562 1.1 christos 3563 1.1 christos /* No match. Don't consume anything; fall back and there will be a 3564 1.1 christos syntax error. */ 3565 1.1 christos } 3566 1.1 christos 3567 1.1 christos /* This *could* have been: 3568 1.1 christos 3569 1.1 christos Turn a string in input_line_pointer into a floating point constant 3570 1.1 christos of type TYPE, and store the appropriate bytes in *LITP. The number 3571 1.1 christos of LITTLENUMS emitted is stored in *SIZEP. 3572 1.1 christos 3573 1.1 christos type A character from FLTCHARS that describes what kind of 3574 1.1 christos floating-point number is wanted. 3575 1.1 christos 3576 1.1 christos litp A pointer to an array that the result should be stored in. 3577 1.1 christos 3578 1.1 christos sizep A pointer to an integer where the size of the result is stored. 3579 1.1 christos 3580 1.1 christos But we don't support floating point constants in assembly code *at all*, 3581 1.1 christos since it's suboptimal and just opens up bug opportunities. GCC emits 3582 1.1 christos the bit patterns as hex. All we could do here is to emit what GCC 3583 1.1 christos would have done in the first place. *Nobody* writes floating-point 3584 1.1 christos code as assembly code, but if they do, they should be able enough to 3585 1.1 christos find out the correct bit patterns and use them. */ 3586 1.1 christos 3587 1.5 christos const char * 3588 1.1 christos md_atof (int type ATTRIBUTE_UNUSED, char *litp ATTRIBUTE_UNUSED, 3589 1.1 christos int *sizep ATTRIBUTE_UNUSED) 3590 1.1 christos { 3591 1.1 christos /* FIXME: Is this function mentioned in the internals.texi manual? If 3592 1.1 christos not, add it. */ 3593 1.1 christos return _("Bad call to md_atof () - floating point formats are not supported"); 3594 1.1 christos } 3595 1.1 christos 3596 1.1 christos /* Turn a number as a fixS * into a series of bytes that represents the 3597 1.1 christos number on the target machine. The purpose of this procedure is the 3598 1.1 christos same as that of md_number_to_chars but this procedure is supposed to 3599 1.1 christos handle general bit field fixes and machine-dependent fixups. 3600 1.1 christos 3601 1.1 christos bufp Pointer to an array where the result should be stored. 3602 1.1 christos 3603 1.1 christos val The value to store. 3604 1.1 christos 3605 1.1 christos n The number of bytes in "val" that should be stored. 3606 1.1 christos 3607 1.1 christos fixP The fix to be applied to the bit field starting at bufp. 3608 1.1 christos 3609 1.1 christos seg The segment containing this number. */ 3610 1.1 christos 3611 1.1 christos static void 3612 1.1 christos cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg) 3613 1.1 christos { 3614 1.1 christos segT sym_seg; 3615 1.1 christos 3616 1.1 christos know (n <= 4); 3617 1.1 christos know (fixP); 3618 1.1 christos 3619 1.1 christos /* We put the relative "vma" for the other segment for inter-segment 3620 1.1 christos relocations in the object data to stay binary "compatible" (with an 3621 1.1 christos uninteresting old version) for the relocation. 3622 1.1 christos Maybe delete some day. */ 3623 1.1 christos if (fixP->fx_addsy 3624 1.1 christos && (sym_seg = S_GET_SEGMENT (fixP->fx_addsy)) != seg) 3625 1.1 christos val += sym_seg->vma; 3626 1.1 christos 3627 1.1 christos if (fixP->fx_addsy != NULL || fixP->fx_pcrel) 3628 1.1 christos switch (fixP->fx_r_type) 3629 1.1 christos { 3630 1.1 christos /* These must be fully resolved when getting here. */ 3631 1.1 christos case BFD_RELOC_16_PCREL: 3632 1.1 christos case BFD_RELOC_8_PCREL: 3633 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3634 1.1 christos _("PC-relative relocation must be trivially resolved")); 3635 1.1 christos default: 3636 1.1 christos ; 3637 1.1 christos } 3638 1.1 christos 3639 1.1 christos /* Only use the computed value for old-arch binaries. For all 3640 1.1 christos others, where we're going to output a relocation, put 0 in the 3641 1.1 christos code. */ 3642 1.1 christos if (cris_arch != arch_cris_any_v0_v10 3643 1.1 christos && (fixP->fx_addsy != NULL || fixP->fx_pcrel)) 3644 1.1 christos val = 0; 3645 1.1 christos 3646 1.1 christos switch (fixP->fx_r_type) 3647 1.1 christos { 3648 1.1 christos /* Ditto here, we put the addend into the object code as 3649 1.1 christos well as the reloc addend. Keep it that way for now, to simplify 3650 1.1 christos regression tests on the object file contents. FIXME: Seems 3651 1.1 christos uninteresting now that we have a test suite. */ 3652 1.1 christos 3653 1.1 christos case BFD_RELOC_CRIS_32_GOT_GD: 3654 1.1 christos case BFD_RELOC_CRIS_16_GOT_GD: 3655 1.1 christos case BFD_RELOC_CRIS_32_GD: 3656 1.1 christos case BFD_RELOC_CRIS_32_IE: 3657 1.1 christos case BFD_RELOC_CRIS_32_DTPREL: 3658 1.1 christos case BFD_RELOC_CRIS_16_DTPREL: 3659 1.1 christos case BFD_RELOC_CRIS_32_GOT_TPREL: 3660 1.1 christos case BFD_RELOC_CRIS_16_GOT_TPREL: 3661 1.1 christos case BFD_RELOC_CRIS_32_TPREL: 3662 1.1 christos case BFD_RELOC_CRIS_16_TPREL: 3663 1.1 christos #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) 3664 1.1 christos if (IS_ELF && fixP->fx_addsy != NULL) 3665 1.1 christos S_SET_THREAD_LOCAL (fixP->fx_addsy); 3666 1.1 christos #endif 3667 1.1 christos /* Fall through. */ 3668 1.1 christos 3669 1.1 christos case BFD_RELOC_CRIS_16_GOT: 3670 1.1 christos case BFD_RELOC_CRIS_32_GOT: 3671 1.1 christos case BFD_RELOC_CRIS_32_GOTREL: 3672 1.1 christos case BFD_RELOC_CRIS_16_GOTPLT: 3673 1.1 christos case BFD_RELOC_CRIS_32_GOTPLT: 3674 1.1 christos case BFD_RELOC_CRIS_32_PLT_GOTREL: 3675 1.1 christos case BFD_RELOC_CRIS_32_PLT_PCREL: 3676 1.1 christos /* We don't want to put in any kind of non-zero bits in the data 3677 1.1 christos being relocated for these. */ 3678 1.1 christos md_number_to_chars (bufp, 0, n); 3679 1.1 christos break; 3680 1.1 christos 3681 1.1 christos case BFD_RELOC_32_PCREL: 3682 1.1 christos /* If this one isn't fully resolved, we don't want to put non-zero 3683 1.1 christos in the object. */ 3684 1.1 christos if (fixP->fx_addsy != NULL || fixP->fx_pcrel) 3685 1.1 christos val = 0; 3686 1.1 christos 3687 1.1 christos /* Fall through. */ 3688 1.1 christos case BFD_RELOC_32: 3689 1.1 christos /* No use having warnings here, since most hosts have a 32-bit type 3690 1.1 christos for "long" (which will probably change soon, now that I wrote 3691 1.1 christos this). */ 3692 1.1 christos bufp[3] = (val >> 24) & 0xFF; 3693 1.1 christos bufp[2] = (val >> 16) & 0xFF; 3694 1.1 christos bufp[1] = (val >> 8) & 0xFF; 3695 1.1 christos bufp[0] = val & 0xFF; 3696 1.1 christos break; 3697 1.1 christos 3698 1.1 christos /* FIXME: The 16 and 8-bit cases should have a way to check 3699 1.1 christos whether a signed or unsigned (or any signedness) number is 3700 1.1 christos accepted. */ 3701 1.1 christos 3702 1.1 christos case BFD_RELOC_16: 3703 1.1 christos case BFD_RELOC_16_PCREL: 3704 1.1 christos if (val > 0xffff || val < -32768) 3705 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3706 1.1 christos _("Value not in 16 bit range: %ld"), val); 3707 1.1 christos bufp[1] = (val >> 8) & 0xFF; 3708 1.1 christos bufp[0] = val & 0xFF; 3709 1.1 christos break; 3710 1.1 christos 3711 1.1 christos case BFD_RELOC_CRIS_SIGNED_16: 3712 1.1 christos if (val > 32767 || val < -32768) 3713 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3714 1.1 christos _("Value not in 16 bit signed range: %ld"), val); 3715 1.1 christos bufp[1] = (val >> 8) & 0xFF; 3716 1.1 christos bufp[0] = val & 0xFF; 3717 1.1 christos break; 3718 1.1 christos 3719 1.1 christos case BFD_RELOC_8: 3720 1.1 christos case BFD_RELOC_8_PCREL: 3721 1.1 christos if (val > 255 || val < -128) 3722 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, _("Value not in 8 bit range: %ld"), val); 3723 1.1 christos bufp[0] = val & 0xFF; 3724 1.1 christos break; 3725 1.1 christos 3726 1.1 christos case BFD_RELOC_CRIS_SIGNED_8: 3727 1.1 christos if (val > 127 || val < -128) 3728 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3729 1.1 christos _("Value not in 8 bit signed range: %ld"), val); 3730 1.1 christos bufp[0] = val & 0xFF; 3731 1.1 christos break; 3732 1.1 christos 3733 1.1 christos case BFD_RELOC_CRIS_LAPCQ_OFFSET: 3734 1.1 christos /* FIXME: Test-cases for out-of-range values. Probably also need 3735 1.1 christos to use as_bad_where. */ 3736 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_4: 3737 1.1 christos if (val > 15 || val < 0) 3738 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3739 1.1 christos _("Value not in 4 bit unsigned range: %ld"), val); 3740 1.1 christos bufp[0] |= val & 0x0F; 3741 1.1 christos break; 3742 1.1 christos 3743 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_5: 3744 1.1 christos if (val > 31 || val < 0) 3745 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3746 1.1 christos _("Value not in 5 bit unsigned range: %ld"), val); 3747 1.1 christos bufp[0] |= val & 0x1F; 3748 1.1 christos break; 3749 1.1 christos 3750 1.1 christos case BFD_RELOC_CRIS_SIGNED_6: 3751 1.1 christos if (val > 31 || val < -32) 3752 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3753 1.1 christos _("Value not in 6 bit range: %ld"), val); 3754 1.1 christos bufp[0] |= val & 0x3F; 3755 1.1 christos break; 3756 1.1 christos 3757 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_6: 3758 1.1 christos if (val > 63 || val < 0) 3759 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3760 1.1 christos _("Value not in 6 bit unsigned range: %ld"), val); 3761 1.1 christos bufp[0] |= val & 0x3F; 3762 1.1 christos break; 3763 1.1 christos 3764 1.1 christos case BFD_RELOC_CRIS_BDISP8: 3765 1.1 christos bufp[0] = branch_disp (val); 3766 1.1 christos break; 3767 1.1 christos 3768 1.1 christos case BFD_RELOC_NONE: 3769 1.1 christos /* May actually happen automatically. For example at broken 3770 1.1 christos words, if the word turns out not to be broken. 3771 1.1 christos FIXME: When? Which testcase? */ 3772 1.1 christos if (! fixP->fx_addsy) 3773 1.1 christos md_number_to_chars (bufp, val, n); 3774 1.1 christos break; 3775 1.1 christos 3776 1.1 christos case BFD_RELOC_VTABLE_INHERIT: 3777 1.1 christos /* This borrowed from tc-ppc.c on a whim. */ 3778 1.1 christos if (fixP->fx_addsy 3779 1.1 christos && !S_IS_DEFINED (fixP->fx_addsy) 3780 1.1 christos && !S_IS_WEAK (fixP->fx_addsy)) 3781 1.1 christos S_SET_WEAK (fixP->fx_addsy); 3782 1.1 christos /* Fall through. */ 3783 1.1 christos 3784 1.1 christos case BFD_RELOC_VTABLE_ENTRY: 3785 1.1 christos fixP->fx_done = 0; 3786 1.1 christos break; 3787 1.1 christos 3788 1.1 christos default: 3789 1.1 christos BAD_CASE (fixP->fx_r_type); 3790 1.1 christos } 3791 1.1 christos } 3792 1.1 christos 3793 1.1 christos /* Processes machine-dependent command line options. Called once for 3794 1.1 christos each option on the command line that the machine-independent part of 3795 1.1 christos GAS does not understand. */ 3796 1.1 christos 3797 1.1 christos int 3798 1.5 christos md_parse_option (int arg, const char *argp ATTRIBUTE_UNUSED) 3799 1.1 christos { 3800 1.1 christos switch (arg) 3801 1.1 christos { 3802 1.1 christos case 'H': 3803 1.1 christos case 'h': 3804 1.1 christos printf (_("Please use --help to see usage and options for this assembler.\n")); 3805 1.1 christos md_show_usage (stdout); 3806 1.1 christos exit (EXIT_SUCCESS); 3807 1.1 christos 3808 1.1 christos case 'N': 3809 1.1 christos warn_for_branch_expansion = 1; 3810 1.1 christos break; 3811 1.1 christos 3812 1.1 christos case OPTION_NO_US: 3813 1.8 christos demand_register_prefix = true; 3814 1.1 christos 3815 1.1 christos if (OUTPUT_FLAVOR == bfd_target_aout_flavour) 3816 1.1 christos as_bad (_("--no-underscore is invalid with a.out format")); 3817 1.1 christos else 3818 1.8 christos symbols_have_leading_underscore = false; 3819 1.1 christos break; 3820 1.1 christos 3821 1.1 christos case OPTION_US: 3822 1.8 christos demand_register_prefix = false; 3823 1.8 christos symbols_have_leading_underscore = true; 3824 1.1 christos break; 3825 1.1 christos 3826 1.1 christos case OPTION_PIC: 3827 1.1 christos if (OUTPUT_FLAVOR != bfd_target_elf_flavour) 3828 1.1 christos as_bad (_("--pic is invalid for this object format")); 3829 1.8 christos pic = true; 3830 1.1 christos if (cris_arch != arch_crisv32) 3831 1.1 christos md_long_jump_size = cris_any_v0_v10_long_jump_size_pic; 3832 1.1 christos else 3833 1.1 christos md_long_jump_size = crisv32_long_jump_size; 3834 1.1 christos break; 3835 1.1 christos 3836 1.1 christos case OPTION_ARCH: 3837 1.1 christos { 3838 1.5 christos const char *str = argp; 3839 1.1 christos enum cris_archs argarch = cris_arch_from_string (&str); 3840 1.1 christos 3841 1.1 christos if (argarch == arch_cris_unknown) 3842 1.1 christos as_bad (_("invalid <arch> in --march=<arch>: %s"), argp); 3843 1.1 christos else 3844 1.1 christos cris_arch = argarch; 3845 1.1 christos 3846 1.1 christos if (argarch == arch_crisv32) 3847 1.1 christos { 3848 1.1 christos err_for_dangerous_mul_placement = 0; 3849 1.1 christos md_long_jump_size = crisv32_long_jump_size; 3850 1.1 christos } 3851 1.1 christos else 3852 1.1 christos { 3853 1.1 christos if (pic) 3854 1.1 christos md_long_jump_size = cris_any_v0_v10_long_jump_size_pic; 3855 1.1 christos else 3856 1.1 christos md_long_jump_size = cris_any_v0_v10_long_jump_size; 3857 1.1 christos } 3858 1.1 christos } 3859 1.1 christos break; 3860 1.1 christos 3861 1.1 christos case OPTION_MULBUG_ABORT_OFF: 3862 1.1 christos err_for_dangerous_mul_placement = 0; 3863 1.1 christos break; 3864 1.1 christos 3865 1.1 christos case OPTION_MULBUG_ABORT_ON: 3866 1.1 christos err_for_dangerous_mul_placement = 1; 3867 1.1 christos break; 3868 1.1 christos 3869 1.1 christos default: 3870 1.1 christos return 0; 3871 1.1 christos } 3872 1.1 christos 3873 1.1 christos return 1; 3874 1.1 christos } 3875 1.1 christos 3876 1.1 christos /* Round up a section size to the appropriate boundary. */ 3877 1.1 christos valueT 3878 1.1 christos md_section_align (segT segment, valueT size) 3879 1.1 christos { 3880 1.1 christos /* Round all sects to multiple of 4, except the bss section, which 3881 1.1 christos we'll round to word-size. 3882 1.1 christos 3883 1.1 christos FIXME: Check if this really matters. All sections should be 3884 1.1 christos rounded up, and all sections should (optionally) be assumed to be 3885 1.1 christos dword-aligned, it's just that there is actual usage of linking to a 3886 1.1 christos multiple of two. */ 3887 1.1 christos if (OUTPUT_FLAVOR == bfd_target_aout_flavour) 3888 1.1 christos { 3889 1.1 christos if (segment == bss_section) 3890 1.1 christos return (size + 1) & ~1; 3891 1.1 christos return (size + 3) & ~3; 3892 1.1 christos } 3893 1.1 christos else 3894 1.1 christos { 3895 1.1 christos /* FIXME: Is this wanted? It matches the testsuite, but that's not 3896 1.1 christos really a valid reason. */ 3897 1.1 christos if (segment == text_section) 3898 1.1 christos return (size + 3) & ~3; 3899 1.1 christos } 3900 1.1 christos 3901 1.1 christos return size; 3902 1.1 christos } 3903 1.1 christos 3904 1.1 christos /* Generate a machine-dependent relocation. */ 3905 1.1 christos arelent * 3906 1.1 christos tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP) 3907 1.1 christos { 3908 1.1 christos arelent *relP; 3909 1.1 christos bfd_reloc_code_real_type code; 3910 1.1 christos 3911 1.1 christos switch (fixP->fx_r_type) 3912 1.1 christos { 3913 1.1 christos case BFD_RELOC_CRIS_SIGNED_8: 3914 1.1 christos code = BFD_RELOC_8; 3915 1.1 christos break; 3916 1.1 christos 3917 1.1 christos case BFD_RELOC_CRIS_SIGNED_16: 3918 1.1 christos code = BFD_RELOC_16; 3919 1.1 christos break; 3920 1.1 christos 3921 1.1 christos case BFD_RELOC_CRIS_16_GOT: 3922 1.1 christos case BFD_RELOC_CRIS_32_GOT: 3923 1.1 christos case BFD_RELOC_CRIS_16_GOTPLT: 3924 1.1 christos case BFD_RELOC_CRIS_32_GOTPLT: 3925 1.1 christos case BFD_RELOC_CRIS_32_GOTREL: 3926 1.1 christos case BFD_RELOC_CRIS_32_PLT_GOTREL: 3927 1.1 christos case BFD_RELOC_CRIS_32_PLT_PCREL: 3928 1.1 christos case BFD_RELOC_32: 3929 1.1 christos case BFD_RELOC_32_PCREL: 3930 1.1 christos case BFD_RELOC_16: 3931 1.1 christos case BFD_RELOC_8: 3932 1.1 christos case BFD_RELOC_VTABLE_INHERIT: 3933 1.1 christos case BFD_RELOC_VTABLE_ENTRY: 3934 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_8: 3935 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_16: 3936 1.1 christos case BFD_RELOC_CRIS_LAPCQ_OFFSET: 3937 1.1 christos case BFD_RELOC_CRIS_32_GOT_GD: 3938 1.1 christos case BFD_RELOC_CRIS_16_GOT_GD: 3939 1.1 christos case BFD_RELOC_CRIS_32_GD: 3940 1.1 christos case BFD_RELOC_CRIS_32_IE: 3941 1.1 christos case BFD_RELOC_CRIS_32_DTPREL: 3942 1.1 christos case BFD_RELOC_CRIS_16_DTPREL: 3943 1.1 christos case BFD_RELOC_CRIS_32_GOT_TPREL: 3944 1.1 christos case BFD_RELOC_CRIS_16_GOT_TPREL: 3945 1.1 christos case BFD_RELOC_CRIS_32_TPREL: 3946 1.1 christos case BFD_RELOC_CRIS_16_TPREL: 3947 1.1 christos code = fixP->fx_r_type; 3948 1.1 christos break; 3949 1.1 christos default: 3950 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 3951 1.1 christos _("Semantics error. This type of operand can not be relocated, it must be an assembly-time constant")); 3952 1.1 christos return 0; 3953 1.1 christos } 3954 1.1 christos 3955 1.10 christos relP = notes_alloc (sizeof (arelent)); 3956 1.10 christos relP->sym_ptr_ptr = notes_alloc (sizeof (asymbol *)); 3957 1.1 christos *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy); 3958 1.1 christos relP->address = fixP->fx_frag->fr_address + fixP->fx_where; 3959 1.1 christos 3960 1.1 christos relP->addend = fixP->fx_offset; 3961 1.1 christos 3962 1.1 christos /* This is the standard place for KLUDGEs to work around bugs in 3963 1.1 christos bfd_install_relocation (first such note in the documentation 3964 1.1 christos appears with binutils-2.8). 3965 1.1 christos 3966 1.1 christos That function bfd_install_relocation does the wrong thing with 3967 1.1 christos putting stuff into the addend of a reloc (it should stay out) for a 3968 1.1 christos weak symbol. The really bad thing is that it adds the 3969 1.1 christos "segment-relative offset" of the symbol into the reloc. In this 3970 1.1 christos case, the reloc should instead be relative to the symbol with no 3971 1.1 christos other offset than the assembly code shows; and since the symbol is 3972 1.1 christos weak, any local definition should be ignored until link time (or 3973 1.1 christos thereafter). 3974 1.1 christos To wit: weaksym+42 should be weaksym+42 in the reloc, 3975 1.1 christos not weaksym+(offset_from_segment_of_local_weaksym_definition) 3976 1.1 christos 3977 1.1 christos To "work around" this, we subtract the segment-relative offset of 3978 1.1 christos "known" weak symbols. This evens out the extra offset. 3979 1.1 christos 3980 1.1 christos That happens for a.out but not for ELF, since for ELF, 3981 1.1 christos bfd_install_relocation uses the "special function" field of the 3982 1.1 christos howto, and does not execute the code that needs to be undone. */ 3983 1.1 christos 3984 1.1 christos if (OUTPUT_FLAVOR == bfd_target_aout_flavour 3985 1.1 christos && fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy) 3986 1.1 christos && ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy))) 3987 1.1 christos { 3988 1.1 christos relP->addend -= S_GET_VALUE (fixP->fx_addsy); 3989 1.1 christos } 3990 1.1 christos 3991 1.1 christos relP->howto = bfd_reloc_type_lookup (stdoutput, code); 3992 1.1 christos if (! relP->howto) 3993 1.1 christos { 3994 1.1 christos const char *name; 3995 1.1 christos 3996 1.1 christos name = S_GET_NAME (fixP->fx_addsy); 3997 1.1 christos if (name == NULL) 3998 1.1 christos name = _("<unknown>"); 3999 1.1 christos as_fatal (_("Cannot generate relocation type for symbol %s, code %s"), 4000 1.1 christos name, bfd_get_reloc_code_name (code)); 4001 1.1 christos } 4002 1.1 christos 4003 1.1 christos return relP; 4004 1.1 christos } 4005 1.1 christos 4006 1.1 christos /* Machine-dependent usage-output. */ 4007 1.1 christos 4008 1.1 christos void 4009 1.1 christos md_show_usage (FILE *stream) 4010 1.1 christos { 4011 1.1 christos /* The messages are formatted to line up with the generic options. */ 4012 1.1 christos fprintf (stream, _("CRIS-specific options:\n")); 4013 1.1 christos fprintf (stream, "%s", 4014 1.1 christos _(" -h, -H Don't execute, print this help text. Deprecated.\n")); 4015 1.1 christos fprintf (stream, "%s", 4016 1.1 christos _(" -N Warn when branches are expanded to jumps.\n")); 4017 1.1 christos fprintf (stream, "%s", 4018 1.1 christos _(" --underscore User symbols are normally prepended with underscore.\n")); 4019 1.1 christos fprintf (stream, "%s", 4020 1.1 christos _(" Registers will not need any prefix.\n")); 4021 1.1 christos fprintf (stream, "%s", 4022 1.1 christos _(" --no-underscore User symbols do not have any prefix.\n")); 4023 1.1 christos fprintf (stream, "%s", 4024 1.1 christos _(" Registers will require a `$'-prefix.\n")); 4025 1.1 christos #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) 4026 1.1 christos fprintf (stream, "%s", 4027 1.1 christos _(" --pic Enable generation of position-independent code.\n")); 4028 1.1 christos #endif 4029 1.1 christos fprintf (stream, "%s", 4030 1.1 christos _(" --march=<arch> Generate code for <arch>. Valid choices for <arch>\n\ 4031 1.1 christos are v0_v10, v10, v32 and common_v10_v32.\n")); 4032 1.1 christos } 4033 1.1 christos 4034 1.1 christos /* Apply a fixS (fixup of an instruction or data that we didn't have 4035 1.1 christos enough info to complete immediately) to the data in a frag. */ 4036 1.1 christos 4037 1.1 christos void 4038 1.1 christos md_apply_fix (fixS *fixP, valueT *valP, segT seg) 4039 1.1 christos { 4040 1.1 christos /* This assignment truncates upper bits if valueT is 64 bits (as with 4041 1.10 christos --enable-64-bit-bfd), which is fine here. */ 4042 1.10 christos long val = *valP; 4043 1.1 christos char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; 4044 1.1 christos 4045 1.1 christos if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) 4046 1.1 christos fixP->fx_done = 1; 4047 1.1 christos 4048 1.7 christos /* We can't actually support subtracting a symbol. */ 4049 1.10 christos if (fixP->fx_subsy != NULL) 4050 1.8 christos as_bad_subtract (fixP); 4051 1.1 christos 4052 1.7 christos /* This operand-type is scaled. */ 4053 1.7 christos if (fixP->fx_r_type == BFD_RELOC_CRIS_LAPCQ_OFFSET) 4054 1.7 christos val /= 2; 4055 1.7 christos cris_number_to_imm (buf, val, fixP->fx_size, fixP, seg); 4056 1.1 christos } 4057 1.1 christos 4058 1.1 christos /* All relocations are relative to the location just after the fixup; 4059 1.1 christos the address of the fixup plus its size. */ 4060 1.1 christos 4061 1.1 christos long 4062 1.1 christos md_pcrel_from (fixS *fixP) 4063 1.1 christos { 4064 1.1 christos valueT addr = fixP->fx_where + fixP->fx_frag->fr_address; 4065 1.1 christos 4066 1.1 christos /* FIXME: We get here only at the end of assembly, when X in ".-X" is 4067 1.1 christos still unknown. Since we don't have pc-relative relocations in a.out, 4068 1.1 christos this is invalid. What to do if anything for a.out, is to add 4069 1.1 christos pc-relative relocations everywhere including the elinux program 4070 1.1 christos loader. For ELF, allow straight-forward PC-relative relocations, 4071 1.1 christos which are always relative to the location after the relocation. */ 4072 1.1 christos if (OUTPUT_FLAVOR != bfd_target_elf_flavour 4073 1.1 christos || (fixP->fx_r_type != BFD_RELOC_8_PCREL 4074 1.1 christos && fixP->fx_r_type != BFD_RELOC_16_PCREL 4075 1.1 christos && fixP->fx_r_type != BFD_RELOC_32_PCREL 4076 1.1 christos && fixP->fx_r_type != BFD_RELOC_CRIS_LAPCQ_OFFSET)) 4077 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 4078 1.1 christos _("Invalid pc-relative relocation")); 4079 1.1 christos return fixP->fx_size + addr; 4080 1.1 christos } 4081 1.1 christos 4082 1.1 christos /* We have no need to give defaults for symbol-values. */ 4083 1.1 christos symbolS * 4084 1.1 christos md_undefined_symbol (char *name ATTRIBUTE_UNUSED) 4085 1.1 christos { 4086 1.1 christos return 0; 4087 1.1 christos } 4088 1.1 christos 4089 1.1 christos /* If this function returns non-zero, it prevents the relocation 4090 1.1 christos against symbol(s) in the FIXP from being replaced with relocations 4091 1.1 christos against section symbols, and guarantees that a relocation will be 4092 1.1 christos emitted even when the value can be resolved locally. */ 4093 1.1 christos int 4094 1.1 christos md_cris_force_relocation (struct fix *fixp) 4095 1.1 christos { 4096 1.1 christos switch (fixp->fx_r_type) 4097 1.1 christos { 4098 1.1 christos case BFD_RELOC_CRIS_16_GOT: 4099 1.1 christos case BFD_RELOC_CRIS_32_GOT: 4100 1.1 christos case BFD_RELOC_CRIS_16_GOTPLT: 4101 1.1 christos case BFD_RELOC_CRIS_32_GOTPLT: 4102 1.1 christos case BFD_RELOC_CRIS_32_GOTREL: 4103 1.1 christos case BFD_RELOC_CRIS_32_PLT_GOTREL: 4104 1.1 christos case BFD_RELOC_CRIS_32_PLT_PCREL: 4105 1.1 christos return 1; 4106 1.1 christos default: 4107 1.1 christos ; 4108 1.1 christos } 4109 1.1 christos 4110 1.1 christos return generic_force_reloc (fixp); 4111 1.1 christos } 4112 1.1 christos 4113 1.1 christos /* Check and emit error if broken-word handling has failed to fix up a 4114 1.1 christos case-table. This is called from write.c, after doing everything it 4115 1.1 christos knows about how to handle broken words. */ 4116 1.1 christos 4117 1.1 christos void 4118 1.1 christos tc_cris_check_adjusted_broken_word (offsetT new_offset, struct broken_word *brokwP) 4119 1.1 christos { 4120 1.1 christos if (new_offset > 32767 || new_offset < -32768) 4121 1.1 christos /* We really want a genuine error, not a warning, so make it one. */ 4122 1.1 christos as_bad_where (brokwP->frag->fr_file, brokwP->frag->fr_line, 4123 1.1 christos _("Adjusted signed .word (%ld) overflows: `switch'-statement too large."), 4124 1.1 christos (long) new_offset); 4125 1.1 christos } 4126 1.1 christos 4127 1.1 christos /* Make a leading REGISTER_PREFIX_CHAR mandatory for all registers. */ 4128 1.1 christos 4129 1.1 christos static void 4130 1.1 christos cris_force_reg_prefix (void) 4131 1.1 christos { 4132 1.8 christos demand_register_prefix = true; 4133 1.1 christos } 4134 1.1 christos 4135 1.1 christos /* Do not demand a leading REGISTER_PREFIX_CHAR for all registers. */ 4136 1.1 christos 4137 1.1 christos static void 4138 1.1 christos cris_relax_reg_prefix (void) 4139 1.1 christos { 4140 1.8 christos demand_register_prefix = false; 4141 1.1 christos } 4142 1.1 christos 4143 1.1 christos /* Adjust for having a leading '_' on all user symbols. */ 4144 1.1 christos 4145 1.1 christos static void 4146 1.1 christos cris_sym_leading_underscore (void) 4147 1.1 christos { 4148 1.1 christos /* We can't really do anything more than assert that what the program 4149 1.1 christos thinks symbol starts with agrees with the command-line options, since 4150 1.1 christos the bfd is already created. */ 4151 1.1 christos 4152 1.1 christos if (!symbols_have_leading_underscore) 4153 1.1 christos as_bad (_(".syntax %s requires command-line option `--underscore'"), 4154 1.1 christos SYNTAX_USER_SYM_LEADING_UNDERSCORE); 4155 1.1 christos } 4156 1.1 christos 4157 1.1 christos /* Adjust for not having any particular prefix on user symbols. */ 4158 1.1 christos 4159 1.1 christos static void cris_sym_no_leading_underscore (void) 4160 1.1 christos { 4161 1.1 christos if (symbols_have_leading_underscore) 4162 1.1 christos as_bad (_(".syntax %s requires command-line option `--no-underscore'"), 4163 1.1 christos SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE); 4164 1.1 christos } 4165 1.1 christos 4166 1.1 christos /* Handle the .syntax pseudo, which takes an argument that decides what 4167 1.1 christos syntax the assembly code has. */ 4168 1.1 christos 4169 1.1 christos static void 4170 1.1 christos s_syntax (int ignore ATTRIBUTE_UNUSED) 4171 1.1 christos { 4172 1.1 christos static const struct syntaxes 4173 1.1 christos { 4174 1.1 christos const char *const operand; 4175 1.1 christos void (*fn) (void); 4176 1.1 christos } syntax_table[] = 4177 1.1 christos {{SYNTAX_ENFORCE_REG_PREFIX, cris_force_reg_prefix}, 4178 1.1 christos {SYNTAX_RELAX_REG_PREFIX, cris_relax_reg_prefix}, 4179 1.1 christos {SYNTAX_USER_SYM_LEADING_UNDERSCORE, cris_sym_leading_underscore}, 4180 1.1 christos {SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE, cris_sym_no_leading_underscore}}; 4181 1.1 christos 4182 1.1 christos const struct syntaxes *sp; 4183 1.1 christos 4184 1.1 christos for (sp = syntax_table; 4185 1.1 christos sp < syntax_table + sizeof (syntax_table) / sizeof (syntax_table[0]); 4186 1.1 christos sp++) 4187 1.1 christos { 4188 1.1 christos if (strncmp (input_line_pointer, sp->operand, 4189 1.1 christos strlen (sp->operand)) == 0) 4190 1.1 christos { 4191 1.1 christos (sp->fn) (); 4192 1.1 christos 4193 1.1 christos input_line_pointer += strlen (sp->operand); 4194 1.1 christos demand_empty_rest_of_line (); 4195 1.1 christos return; 4196 1.1 christos } 4197 1.1 christos } 4198 1.1 christos 4199 1.1 christos as_bad (_("Unknown .syntax operand")); 4200 1.1 christos } 4201 1.1 christos 4202 1.1 christos /* Wrapper for dwarf2_directive_file to emit error if this is seen when 4203 1.1 christos not emitting ELF. */ 4204 1.1 christos 4205 1.1 christos static void 4206 1.1 christos s_cris_file (int dummy) 4207 1.1 christos { 4208 1.1 christos if (OUTPUT_FLAVOR != bfd_target_elf_flavour) 4209 1.1 christos as_bad (_("Pseudodirective .file is only valid when generating ELF")); 4210 1.1 christos else 4211 1.1 christos dwarf2_directive_file (dummy); 4212 1.1 christos } 4213 1.1 christos 4214 1.1 christos /* Wrapper for dwarf2_directive_loc to emit error if this is seen when not 4215 1.1 christos emitting ELF. */ 4216 1.1 christos 4217 1.1 christos static void 4218 1.1 christos s_cris_loc (int dummy) 4219 1.1 christos { 4220 1.1 christos if (OUTPUT_FLAVOR != bfd_target_elf_flavour) 4221 1.1 christos as_bad (_("Pseudodirective .loc is only valid when generating ELF")); 4222 1.1 christos else 4223 1.1 christos dwarf2_directive_loc (dummy); 4224 1.1 christos } 4225 1.1 christos 4226 1.1 christos /* Worker for .dtpoffd: generate a R_CRIS_32_DTPREL reloc, as for 4227 1.1 christos expr:DTPREL but for use in debug info. */ 4228 1.1 christos 4229 1.1 christos static void 4230 1.1 christos s_cris_dtpoff (int bytes) 4231 1.1 christos { 4232 1.1 christos expressionS ex; 4233 1.1 christos char *p; 4234 1.1 christos 4235 1.1 christos if (bytes != 4) 4236 1.1 christos as_fatal (_("internal inconsistency problem: %s called for %d bytes"), 4237 1.9 christos __func__, bytes); 4238 1.1 christos 4239 1.1 christos expression (&ex); 4240 1.1 christos 4241 1.1 christos p = frag_more (bytes); 4242 1.1 christos md_number_to_chars (p, 0, bytes); 4243 1.8 christos fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, false, 4244 1.1 christos BFD_RELOC_CRIS_32_DTPREL); 4245 1.1 christos 4246 1.1 christos demand_empty_rest_of_line (); 4247 1.1 christos } 4248 1.1 christos 4249 1.1 christos 4250 1.1 christos /* Translate a <arch> string (as common to --march=<arch> and .arch <arch>) 4251 1.1 christos into an enum. If the string *STR is recognized, *STR is updated to point 4252 1.1 christos to the end of the string. If the string is not recognized, 4253 1.1 christos arch_cris_unknown is returned. */ 4254 1.1 christos 4255 1.1 christos static enum cris_archs 4256 1.5 christos cris_arch_from_string (const char **str) 4257 1.1 christos { 4258 1.1 christos static const struct cris_arch_struct 4259 1.1 christos { 4260 1.1 christos const char *const name; 4261 1.1 christos enum cris_archs arch; 4262 1.1 christos } arch_table[] = 4263 1.1 christos /* Keep in order longest-first for choices where one is a prefix 4264 1.1 christos of another. */ 4265 1.1 christos {{"v0_v10", arch_cris_any_v0_v10}, 4266 1.1 christos {"v10", arch_crisv10}, 4267 1.1 christos {"v32", arch_crisv32}, 4268 1.1 christos {"common_v10_v32", arch_cris_common_v10_v32}}; 4269 1.1 christos 4270 1.1 christos const struct cris_arch_struct *ap; 4271 1.1 christos 4272 1.1 christos for (ap = arch_table; 4273 1.1 christos ap < arch_table + sizeof (arch_table) / sizeof (arch_table[0]); 4274 1.1 christos ap++) 4275 1.1 christos { 4276 1.1 christos int len = strlen (ap->name); 4277 1.1 christos 4278 1.1 christos if (strncmp (*str, ap->name, len) == 0 4279 1.10 christos && (is_end_of_stmt (str[0][len]) || is_whitespace (str[0][len]))) 4280 1.1 christos { 4281 1.1 christos *str += strlen (ap->name); 4282 1.1 christos return ap->arch; 4283 1.1 christos } 4284 1.1 christos } 4285 1.1 christos 4286 1.1 christos return arch_cris_unknown; 4287 1.1 christos } 4288 1.1 christos 4289 1.1 christos /* Return nonzero if architecture version ARCH matches version range in 4290 1.1 christos IVER. */ 4291 1.1 christos 4292 1.1 christos static int 4293 1.1 christos cris_insn_ver_valid_for_arch (enum cris_insn_version_usage iver, 4294 1.1 christos enum cris_archs arch) 4295 1.1 christos { 4296 1.1 christos switch (arch) 4297 1.1 christos { 4298 1.1 christos case arch_cris_any_v0_v10: 4299 1.1 christos return 4300 1.1 christos (iver == cris_ver_version_all 4301 1.1 christos || iver == cris_ver_warning 4302 1.1 christos || iver == cris_ver_v0_3 4303 1.1 christos || iver == cris_ver_v3p 4304 1.1 christos || iver == cris_ver_v0_10 4305 1.1 christos || iver == cris_ver_sim_v0_10 4306 1.1 christos || iver == cris_ver_v3_10 4307 1.1 christos || iver == cris_ver_v8 4308 1.1 christos || iver == cris_ver_v8p 4309 1.1 christos || iver == cris_ver_v8_10 4310 1.1 christos || iver == cris_ver_v10 4311 1.1 christos || iver == cris_ver_v10p); 4312 1.3 christos 4313 1.1 christos case arch_crisv32: 4314 1.1 christos return 4315 1.1 christos (iver == cris_ver_version_all 4316 1.1 christos || iver == cris_ver_v3p 4317 1.1 christos || iver == cris_ver_v8p 4318 1.1 christos || iver == cris_ver_v10p 4319 1.1 christos || iver == cris_ver_v32p); 4320 1.1 christos 4321 1.1 christos case arch_cris_common_v10_v32: 4322 1.1 christos return 4323 1.1 christos (iver == cris_ver_version_all 4324 1.1 christos || iver == cris_ver_v3p 4325 1.1 christos || iver == cris_ver_v8p 4326 1.1 christos || iver == cris_ver_v10p); 4327 1.1 christos 4328 1.1 christos case arch_crisv0: 4329 1.1 christos return 4330 1.1 christos (iver == cris_ver_version_all 4331 1.1 christos || iver == cris_ver_v0_3 4332 1.1 christos || iver == cris_ver_v0_10 4333 1.1 christos || iver == cris_ver_sim_v0_10); 4334 1.1 christos 4335 1.1 christos case arch_crisv3: 4336 1.1 christos return 4337 1.1 christos (iver == cris_ver_version_all 4338 1.1 christos || iver == cris_ver_v0_3 4339 1.1 christos || iver == cris_ver_v3p 4340 1.1 christos || iver == cris_ver_v0_10 4341 1.1 christos || iver == cris_ver_sim_v0_10 4342 1.1 christos || iver == cris_ver_v3_10); 4343 1.1 christos 4344 1.1 christos case arch_crisv8: 4345 1.1 christos return 4346 1.1 christos (iver == cris_ver_version_all 4347 1.1 christos || iver == cris_ver_v3p 4348 1.1 christos || iver == cris_ver_v0_10 4349 1.1 christos || iver == cris_ver_sim_v0_10 4350 1.1 christos || iver == cris_ver_v3_10 4351 1.1 christos || iver == cris_ver_v8 4352 1.1 christos || iver == cris_ver_v8p 4353 1.1 christos || iver == cris_ver_v8_10); 4354 1.1 christos 4355 1.1 christos case arch_crisv10: 4356 1.1 christos return 4357 1.1 christos (iver == cris_ver_version_all 4358 1.1 christos || iver == cris_ver_v3p 4359 1.1 christos || iver == cris_ver_v0_10 4360 1.1 christos || iver == cris_ver_sim_v0_10 4361 1.1 christos || iver == cris_ver_v3_10 4362 1.1 christos || iver == cris_ver_v8p 4363 1.1 christos || iver == cris_ver_v8_10 4364 1.1 christos || iver == cris_ver_v10 4365 1.1 christos || iver == cris_ver_v10p); 4366 1.1 christos 4367 1.1 christos default: 4368 1.1 christos BAD_CASE (arch); 4369 1.1 christos } 4370 1.1 christos } 4371 1.1 christos 4372 1.1 christos /* Assert that the .arch ARCHCHOICE1 is compatible with the specified or 4373 1.1 christos default --march=<ARCHCHOICE2> option. */ 4374 1.1 christos 4375 1.1 christos static void 4376 1.1 christos s_cris_arch (int dummy ATTRIBUTE_UNUSED) 4377 1.1 christos { 4378 1.1 christos /* Right now we take the easy route and check for sameness. It's not 4379 1.1 christos obvious that allowing e.g. --march=v32 and .arch common_v0_v32 4380 1.1 christos would be more useful than confusing, implementation-wise and 4381 1.1 christos user-wise. */ 4382 1.1 christos 4383 1.5 christos const char *str = input_line_pointer; 4384 1.1 christos enum cris_archs arch = cris_arch_from_string (&str); 4385 1.1 christos 4386 1.1 christos if (arch == arch_cris_unknown) 4387 1.1 christos { 4388 1.1 christos as_bad (_("unknown operand to .arch")); 4389 1.1 christos 4390 1.1 christos /* For this one, str does not reflect the end of the operand, 4391 1.1 christos since there was no matching arch. Skip it manually; skip 4392 1.1 christos things that can be part of a word (a name). */ 4393 1.1 christos while (is_part_of_name (*str)) 4394 1.1 christos str++; 4395 1.1 christos } 4396 1.1 christos else if (arch != cris_arch) 4397 1.1 christos as_bad (_(".arch <arch> requires a matching --march=... option")); 4398 1.1 christos 4399 1.5 christos input_line_pointer = (char *) str; 4400 1.1 christos demand_empty_rest_of_line (); 4401 1.1 christos return; 4402 1.1 christos } 4403 1.1 christos 4404 1.1 christos /* 4405 1.1 christos * Local variables: 4406 1.1 christos * eval: (c-set-style "gnu") 4407 1.1 christos * indent-tabs-mode: t 4408 1.1 christos * End: 4409 1.1 christos */ 4410