1 1.6 christos /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */ 2 1.1 christos /* Assembler interface for targets using CGEN. -*- C -*- 3 1.1 christos CGEN: Cpu tools GENerator 4 1.1 christos 5 1.1 christos THIS FILE IS MACHINE GENERATED WITH CGEN. 6 1.1 christos - the resultant file is machine generated, cgen-asm.in isn't 7 1.1 christos 8 1.9 christos Copyright (C) 1996-2024 Free Software Foundation, Inc. 9 1.1 christos 10 1.1 christos This file is part of libopcodes. 11 1.1 christos 12 1.1 christos This library is free software; you can redistribute it and/or modify 13 1.1 christos it under the terms of the GNU General Public License as published by 14 1.1 christos the Free Software Foundation; either version 3, or (at your option) 15 1.1 christos any later version. 16 1.1 christos 17 1.1 christos It is distributed in the hope that it will be useful, but WITHOUT 18 1.1 christos ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 1.1 christos or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 20 1.1 christos License for more details. 21 1.1 christos 22 1.1 christos You should have received a copy of the GNU General Public License 23 1.1 christos along with this program; if not, write to the Free Software Foundation, Inc., 24 1.1 christos 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 25 1.1 christos 26 1.1 christos 27 1.1 christos /* ??? Eventually more and more of this stuff can go to cpu-independent files. 28 1.1 christos Keep that in mind. */ 29 1.1 christos 30 1.1 christos #include "sysdep.h" 31 1.1 christos #include <stdio.h> 32 1.1 christos #include "ansidecl.h" 33 1.1 christos #include "bfd.h" 34 1.1 christos #include "symcat.h" 35 1.1 christos #include "or1k-desc.h" 36 1.1 christos #include "or1k-opc.h" 37 1.1 christos #include "opintl.h" 38 1.1 christos #include "xregex.h" 39 1.1 christos #include "libiberty.h" 40 1.1 christos #include "safe-ctype.h" 41 1.1 christos 42 1.1 christos #undef min 43 1.1 christos #define min(a,b) ((a) < (b) ? (a) : (b)) 44 1.1 christos #undef max 45 1.1 christos #define max(a,b) ((a) > (b) ? (a) : (b)) 46 1.1 christos 47 1.1 christos static const char * parse_insn_normal 48 1.1 christos (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *); 49 1.1 christos 50 1.1 christos /* -- assembler routines inserted here. */ 52 1.1 christos 53 1.1 christos /* -- asm.c */ 54 1.1 christos 55 1.6 christos static const char * MISSING_CLOSING_PARENTHESIS = N_("missing `)'"); 56 1.6 christos static const char * INVALID_STORE_RELOC = N_("relocation invalid for store"); 57 1.1 christos static const char * INVALID_RELOC_TYPE = N_("internal relocation type invalid"); 58 1.1 christos 59 1.1 christos #define CGEN_VERBOSE_ASSEMBLER_ERRORS 60 1.1 christos 61 1.1 christos static const char * 62 1.1 christos parse_disp26 (CGEN_CPU_DESC cd, 63 1.1 christos const char ** strp, 64 1.6 christos int opindex, 65 1.1 christos int opinfo ATTRIBUTE_UNUSED, 66 1.1 christos enum cgen_parse_operand_result * resultp, 67 1.1 christos bfd_vma * valuep) 68 1.6 christos { 69 1.1 christos const char *str = *strp; 70 1.6 christos const char *errmsg = NULL; 71 1.1 christos bfd_reloc_code_real_type reloc = BFD_RELOC_OR1K_REL_26; 72 1.6 christos 73 1.6 christos if (strncasecmp (str, "plta(", 5) == 0) 74 1.6 christos { 75 1.6 christos *strp = str + 5; 76 1.6 christos reloc = BFD_RELOC_OR1K_PLTA26; 77 1.6 christos } 78 1.1 christos else if (strncasecmp (str, "plt(", 4) == 0) 79 1.6 christos { 80 1.6 christos *strp = str + 4; 81 1.1 christos reloc = BFD_RELOC_OR1K_PLT26; 82 1.1 christos } 83 1.6 christos 84 1.1 christos errmsg = cgen_parse_address (cd, strp, opindex, reloc, resultp, valuep); 85 1.6 christos 86 1.1 christos if (reloc != BFD_RELOC_OR1K_REL_26) 87 1.1 christos { 88 1.1 christos if (**strp != ')') 89 1.6 christos errmsg = MISSING_CLOSING_PARENTHESIS; 90 1.6 christos else 91 1.1 christos ++*strp; 92 1.1 christos } 93 1.6 christos 94 1.6 christos return errmsg; 95 1.1 christos } 96 1.6 christos 97 1.6 christos static const char * 98 1.6 christos parse_disp21 (CGEN_CPU_DESC cd, 99 1.6 christos const char ** strp, 100 1.6 christos int opindex, 101 1.6 christos int opinfo ATTRIBUTE_UNUSED, 102 1.6 christos enum cgen_parse_operand_result * resultp, 103 1.6 christos bfd_vma * valuep) 104 1.6 christos { 105 1.6 christos const char *str = *strp; 106 1.6 christos const char *errmsg = NULL; 107 1.1 christos bfd_reloc_code_real_type reloc = BFD_RELOC_OR1K_PCREL_PG21; 108 1.6 christos 109 1.6 christos if (strncasecmp (str, "got(", 4) == 0) 110 1.6 christos { 111 1.6 christos *strp = str + 4; 112 1.1 christos reloc = BFD_RELOC_OR1K_GOT_PG21; 113 1.6 christos } 114 1.1 christos else if (strncasecmp (str, "tlsgd(", 6) == 0) 115 1.6 christos { 116 1.6 christos *strp = str + 6; 117 1.1 christos reloc = BFD_RELOC_OR1K_TLS_GD_PG21; 118 1.6 christos } 119 1.1 christos else if (strncasecmp (str, "tlsldm(", 7) == 0) 120 1.6 christos { 121 1.6 christos *strp = str + 7; 122 1.1 christos reloc = BFD_RELOC_OR1K_TLS_LDM_PG21; 123 1.6 christos } 124 1.1 christos else if (strncasecmp (str, "gottp(", 6) == 0) 125 1.6 christos { 126 1.6 christos *strp = str + 6; 127 1.1 christos reloc = BFD_RELOC_OR1K_TLS_IE_PG21; 128 1.1 christos } 129 1.6 christos 130 1.1 christos errmsg = cgen_parse_address (cd, strp, opindex, reloc, resultp, valuep); 131 1.6 christos 132 1.6 christos if (reloc != BFD_RELOC_OR1K_PCREL_PG21) 133 1.1 christos { 134 1.6 christos if (**strp != ')') 135 1.6 christos errmsg = MISSING_CLOSING_PARENTHESIS; 136 1.6 christos else 137 1.1 christos ++*strp; 138 1.1 christos } 139 1.6 christos 140 1.6 christos return errmsg; 141 1.6 christos } 142 1.6 christos 143 1.6 christos enum or1k_rclass 144 1.6 christos { 145 1.6 christos RCLASS_DIRECT = 0, 146 1.6 christos RCLASS_GOT = 1, 147 1.6 christos RCLASS_GOTPC = 2, 148 1.6 christos RCLASS_GOTOFF = 3, 149 1.6 christos RCLASS_TLSGD = 4, 150 1.6 christos RCLASS_TLSLDM = 5, 151 1.6 christos RCLASS_DTPOFF = 6, 152 1.6 christos RCLASS_GOTTPOFF = 7, 153 1.6 christos RCLASS_TPOFF = 8, 154 1.1 christos }; 155 1.6 christos 156 1.6 christos enum or1k_rtype 157 1.6 christos { 158 1.6 christos RTYPE_LO = 0, 159 1.6 christos RTYPE_SLO = 1, 160 1.6 christos RTYPE_PO = 2, 161 1.6 christos RTYPE_SPO = 3, 162 1.6 christos RTYPE_HI = 4, 163 1.6 christos RTYPE_AHI = 5, 164 1.1 christos }; 165 1.6 christos 166 1.6 christos #define RCLASS_SHIFT 3 167 1.1 christos #define RTYPE_MASK 7 168 1.6 christos 169 1.6 christos static const bfd_reloc_code_real_type or1k_imm16_relocs[][6] = { 170 1.6 christos { BFD_RELOC_LO16, 171 1.6 christos BFD_RELOC_OR1K_SLO16, 172 1.6 christos BFD_RELOC_OR1K_LO13, 173 1.6 christos BFD_RELOC_OR1K_SLO13, 174 1.6 christos BFD_RELOC_HI16, 175 1.6 christos BFD_RELOC_HI16_S, }, 176 1.6 christos { BFD_RELOC_OR1K_GOT16, 177 1.6 christos BFD_RELOC_UNUSED, 178 1.6 christos BFD_RELOC_OR1K_GOT_LO13, 179 1.6 christos BFD_RELOC_UNUSED, 180 1.8 christos BFD_RELOC_UNUSED, 181 1.6 christos BFD_RELOC_OR1K_GOT_AHI16 }, 182 1.6 christos { BFD_RELOC_OR1K_GOTPC_LO16, 183 1.6 christos BFD_RELOC_UNUSED, 184 1.6 christos BFD_RELOC_UNUSED, 185 1.6 christos BFD_RELOC_UNUSED, 186 1.6 christos BFD_RELOC_OR1K_GOTPC_HI16, 187 1.6 christos BFD_RELOC_UNUSED }, 188 1.6 christos { BFD_RELOC_LO16_GOTOFF, 189 1.6 christos BFD_RELOC_OR1K_GOTOFF_SLO16, 190 1.6 christos BFD_RELOC_UNUSED, 191 1.6 christos BFD_RELOC_UNUSED, 192 1.6 christos BFD_RELOC_HI16_GOTOFF, 193 1.6 christos BFD_RELOC_HI16_S_GOTOFF }, 194 1.6 christos { BFD_RELOC_OR1K_TLS_GD_LO16, 195 1.6 christos BFD_RELOC_UNUSED, 196 1.6 christos BFD_RELOC_OR1K_TLS_GD_LO13, 197 1.6 christos BFD_RELOC_UNUSED, 198 1.6 christos BFD_RELOC_OR1K_TLS_GD_HI16, 199 1.6 christos BFD_RELOC_UNUSED }, 200 1.6 christos { BFD_RELOC_OR1K_TLS_LDM_LO16, 201 1.6 christos BFD_RELOC_UNUSED, 202 1.6 christos BFD_RELOC_OR1K_TLS_LDM_LO13, 203 1.6 christos BFD_RELOC_UNUSED, 204 1.6 christos BFD_RELOC_OR1K_TLS_LDM_HI16, 205 1.6 christos BFD_RELOC_UNUSED }, 206 1.6 christos { BFD_RELOC_OR1K_TLS_LDO_LO16, 207 1.6 christos BFD_RELOC_UNUSED, 208 1.6 christos BFD_RELOC_UNUSED, 209 1.6 christos BFD_RELOC_UNUSED, 210 1.6 christos BFD_RELOC_OR1K_TLS_LDO_HI16, 211 1.6 christos BFD_RELOC_UNUSED }, 212 1.6 christos { BFD_RELOC_OR1K_TLS_IE_LO16, 213 1.6 christos BFD_RELOC_UNUSED, 214 1.6 christos BFD_RELOC_OR1K_TLS_IE_LO13, 215 1.6 christos BFD_RELOC_UNUSED, 216 1.6 christos BFD_RELOC_OR1K_TLS_IE_HI16, 217 1.6 christos BFD_RELOC_OR1K_TLS_IE_AHI16 }, 218 1.6 christos { BFD_RELOC_OR1K_TLS_LE_LO16, 219 1.6 christos BFD_RELOC_OR1K_TLS_LE_SLO16, 220 1.6 christos BFD_RELOC_UNUSED, 221 1.6 christos BFD_RELOC_UNUSED, 222 1.6 christos BFD_RELOC_OR1K_TLS_LE_HI16, 223 1.6 christos BFD_RELOC_OR1K_TLS_LE_AHI16 }, 224 1.1 christos }; 225 1.6 christos 226 1.6 christos static int 227 1.6 christos parse_reloc (const char **strp) 228 1.6 christos { 229 1.6 christos const char *str = *strp; 230 1.6 christos enum or1k_rclass cls = RCLASS_DIRECT; 231 1.1 christos enum or1k_rtype typ; 232 1.6 christos 233 1.6 christos if (strncasecmp (str, "got(", 4) == 0) 234 1.6 christos { 235 1.6 christos *strp = str + 4; 236 1.6 christos return (RCLASS_GOT << RCLASS_SHIFT) | RTYPE_LO; 237 1.6 christos } 238 1.6 christos if (strncasecmp (str, "gotpo(", 6) == 0) 239 1.6 christos { 240 1.6 christos *strp = str + 6; 241 1.6 christos return (RCLASS_GOT << RCLASS_SHIFT) | RTYPE_PO; 242 1.6 christos } 243 1.6 christos if (strncasecmp (str, "gottppo(", 8) == 0) 244 1.6 christos { 245 1.6 christos *strp = str + 8; 246 1.6 christos return (RCLASS_GOTTPOFF << RCLASS_SHIFT) | RTYPE_PO; 247 1.1 christos } 248 1.6 christos 249 1.6 christos if (strncasecmp (str, "gotpc", 5) == 0) 250 1.6 christos { 251 1.6 christos str += 5; 252 1.6 christos cls = RCLASS_GOTPC; 253 1.6 christos } 254 1.6 christos else if (strncasecmp (str, "gotoff", 6) == 0) 255 1.6 christos { 256 1.6 christos str += 6; 257 1.6 christos cls = RCLASS_GOTOFF; 258 1.6 christos } 259 1.6 christos else if (strncasecmp (str, "tlsgd", 5) == 0) 260 1.6 christos { 261 1.6 christos str += 5; 262 1.6 christos cls = RCLASS_TLSGD; 263 1.6 christos } 264 1.6 christos else if (strncasecmp (str, "tlsldm", 6) == 0) 265 1.6 christos { 266 1.6 christos str += 6; 267 1.6 christos cls = RCLASS_TLSLDM; 268 1.6 christos } 269 1.6 christos else if (strncasecmp (str, "dtpoff", 6) == 0) 270 1.6 christos { 271 1.6 christos str += 6; 272 1.6 christos cls = RCLASS_DTPOFF; 273 1.6 christos } 274 1.6 christos else if (strncasecmp (str, "gottpoff", 8) == 0) 275 1.6 christos { 276 1.6 christos str += 8; 277 1.6 christos cls = RCLASS_GOTTPOFF; 278 1.6 christos } 279 1.6 christos else if (strncasecmp (str, "tpoff", 5) == 0) 280 1.6 christos { 281 1.6 christos str += 5; 282 1.6 christos cls = RCLASS_TPOFF; 283 1.8 christos } 284 1.8 christos else if (strncasecmp (str, "got", 3) == 0) 285 1.8 christos { 286 1.8 christos str += 3; 287 1.8 christos cls = RCLASS_GOT; 288 1.1 christos } 289 1.6 christos 290 1.6 christos if (strncasecmp (str, "hi(", 3) == 0) 291 1.6 christos { 292 1.6 christos str += 3; 293 1.6 christos typ = RTYPE_HI; 294 1.6 christos } 295 1.6 christos else if (strncasecmp (str, "lo(", 3) == 0) 296 1.6 christos { 297 1.6 christos str += 3; 298 1.6 christos typ = RTYPE_LO; 299 1.6 christos } 300 1.6 christos else if (strncasecmp (str, "ha(", 3) == 0) 301 1.6 christos { 302 1.6 christos str += 3; 303 1.6 christos typ = RTYPE_AHI; 304 1.6 christos } 305 1.6 christos else if (strncasecmp (str, "po(", 3) == 0 && cls != RCLASS_GOTTPOFF) 306 1.6 christos { 307 1.6 christos str += 3; 308 1.6 christos typ = RTYPE_PO; 309 1.6 christos } 310 1.6 christos else 311 1.1 christos return -1; 312 1.6 christos 313 1.6 christos *strp = str; 314 1.6 christos return (cls << RCLASS_SHIFT) | typ; 315 1.1 christos } 316 1.6 christos 317 1.6 christos static const char * 318 1.6 christos parse_imm16 (CGEN_CPU_DESC cd, const char **strp, int opindex, 319 1.6 christos long *valuep, int splitp) 320 1.6 christos { 321 1.6 christos const char *errmsg; 322 1.6 christos enum cgen_parse_operand_result result_type; 323 1.6 christos bfd_reloc_code_real_type reloc = BFD_RELOC_UNUSED; 324 1.6 christos enum or1k_rtype reloc_type; 325 1.6 christos int reloc_code; 326 1.1 christos bfd_vma ret; 327 1.6 christos 328 1.6 christos if (**strp == '#') 329 1.1 christos ++*strp; 330 1.6 christos 331 1.6 christos reloc_code = parse_reloc (strp); 332 1.6 christos reloc_type = reloc_code & RTYPE_MASK; 333 1.6 christos if (reloc_code >= 0) 334 1.6 christos { 335 1.6 christos enum or1k_rclass reloc_class = reloc_code >> RCLASS_SHIFT; 336 1.6 christos if (splitp) 337 1.6 christos { 338 1.6 christos if ((reloc_type == RTYPE_LO || reloc_type == RTYPE_PO) 339 1.6 christos && reloc_class != RCLASS_GOT) 340 1.6 christos /* If split we or up the type to RTYPE_SLO or RTYPE_SPO. */ 341 1.6 christos reloc_type |= 1; 342 1.6 christos else 343 1.6 christos return INVALID_STORE_RELOC; 344 1.6 christos } 345 1.1 christos reloc = or1k_imm16_relocs[reloc_class][reloc_type]; 346 1.6 christos } 347 1.6 christos 348 1.1 christos if (reloc != BFD_RELOC_UNUSED) 349 1.1 christos { 350 1.1 christos bfd_vma value; 351 1.6 christos 352 1.1 christos errmsg = cgen_parse_address (cd, strp, opindex, reloc, 353 1.1 christos &result_type, &value); 354 1.6 christos if (**strp != ')') 355 1.1 christos errmsg = MISSING_CLOSING_PARENTHESIS; 356 1.1 christos ++*strp; 357 1.6 christos 358 1.1 christos ret = value; 359 1.6 christos 360 1.6 christos if (errmsg == NULL && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER) 361 1.6 christos switch (reloc_type) 362 1.6 christos { 363 1.6 christos case RTYPE_AHI: 364 1.6 christos ret += 0x8000; 365 1.6 christos /* FALLTHRU */ 366 1.6 christos case RTYPE_HI: 367 1.6 christos ret >>= 16; 368 1.6 christos /* FALLTHRU */ 369 1.6 christos case RTYPE_LO: 370 1.6 christos case RTYPE_SLO: 371 1.6 christos ret &= 0xffff; 372 1.6 christos ret = (ret ^ 0x8000) - 0x8000; 373 1.6 christos break; 374 1.6 christos case RTYPE_PO: 375 1.6 christos case RTYPE_SPO: 376 1.6 christos ret &= 0x1fff; 377 1.6 christos break; 378 1.6 christos default: 379 1.6 christos errmsg = INVALID_RELOC_TYPE; 380 1.1 christos } 381 1.1 christos } 382 1.1 christos else 383 1.1 christos { 384 1.1 christos long value; 385 1.1 christos errmsg = cgen_parse_signed_integer (cd, strp, opindex, &value); 386 1.1 christos ret = value; 387 1.1 christos } 388 1.1 christos 389 1.1 christos if (errmsg == NULL) 390 1.1 christos *valuep = ret; 391 1.1 christos 392 1.1 christos return errmsg; 393 1.1 christos } 394 1.1 christos 395 1.6 christos static const char * 396 1.6 christos parse_simm16 (CGEN_CPU_DESC cd, const char **strp, int opindex, long *valuep) 397 1.6 christos { 398 1.6 christos return parse_imm16(cd, strp, opindex, (long *) valuep, 0); 399 1.6 christos } 400 1.6 christos 401 1.6 christos static const char * 402 1.6 christos parse_simm16_split (CGEN_CPU_DESC cd, const char **strp, int opindex, 403 1.1 christos long *valuep) 404 1.6 christos { 405 1.6 christos return parse_imm16(cd, strp, opindex, (long *) valuep, 1); 406 1.1 christos } 407 1.6 christos 408 1.6 christos static const char * 409 1.6 christos parse_uimm16 (CGEN_CPU_DESC cd, const char **strp, int opindex, 410 1.6 christos unsigned long *valuep) 411 1.6 christos { 412 1.6 christos const char *errmsg = parse_imm16(cd, strp, opindex, (long *) valuep, 0); 413 1.6 christos if (errmsg == NULL) 414 1.6 christos *valuep &= 0xffff; 415 1.6 christos return errmsg; 416 1.6 christos } 417 1.6 christos 418 1.6 christos static const char * 419 1.6 christos parse_uimm16_split (CGEN_CPU_DESC cd, const char **strp, int opindex, 420 1.6 christos unsigned long *valuep) 421 1.6 christos { 422 1.1 christos const char *errmsg = parse_imm16(cd, strp, opindex, (long *) valuep, 1); 423 1.1 christos if (errmsg == NULL) 424 1.1 christos *valuep &= 0xffff; 425 1.1 christos return errmsg; 426 1.1 christos } 427 1.7 christos 428 1.7 christos /* Parse register pairs with syntax rA,rB to a flag + rA value. */ 429 1.7 christos 430 1.7 christos static const char * 431 1.7 christos parse_regpair (CGEN_CPU_DESC cd, const char **strp, 432 1.7 christos int opindex ATTRIBUTE_UNUSED, unsigned long *valuep) 433 1.7 christos { 434 1.7 christos long reg1_index; 435 1.7 christos long reg2_index; 436 1.7 christos const char *errmsg; 437 1.7 christos 438 1.7 christos /* The first part should just be a register. */ 439 1.7 christos errmsg = cgen_parse_keyword (cd, strp, &or1k_cgen_opval_h_gpr, 440 1.7 christos ®1_index); 441 1.7 christos 442 1.7 christos /* If that worked skip the comma separator. */ 443 1.7 christos if (errmsg == NULL) 444 1.7 christos { 445 1.7 christos if (**strp == ',') 446 1.7 christos ++*strp; 447 1.7 christos else 448 1.7 christos errmsg = "Unexpected character, expected ','"; 449 1.7 christos } 450 1.7 christos 451 1.7 christos /* If that worked the next part is just another register. */ 452 1.7 christos if (errmsg == NULL) 453 1.7 christos errmsg = cgen_parse_keyword (cd, strp, &or1k_cgen_opval_h_gpr, 454 1.7 christos ®2_index); 455 1.7 christos 456 1.7 christos /* Validate the register pair is valid and create the output value. */ 457 1.7 christos if (errmsg == NULL) 458 1.7 christos { 459 1.7 christos int regoffset = reg2_index - reg1_index; 460 1.7 christos 461 1.7 christos if (regoffset == 1 || regoffset == 2) 462 1.7 christos { 463 1.7 christos unsigned short offsetmask; 464 1.7 christos unsigned short value; 465 1.7 christos 466 1.7 christos offsetmask = ((regoffset == 2 ? 1 : 0) << 5); 467 1.7 christos value = offsetmask | reg1_index; 468 1.7 christos 469 1.7 christos *valuep = value; 470 1.7 christos } 471 1.7 christos else 472 1.7 christos errmsg = "Invalid register pair, offset not 1 or 2."; 473 1.7 christos } 474 1.7 christos 475 1.7 christos return errmsg; 476 1.7 christos } 477 1.1 christos 478 1.1 christos /* -- */ 479 1.1 christos 480 1.1 christos const char * or1k_cgen_parse_operand 481 1.1 christos (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *); 482 1.1 christos 483 1.1 christos /* Main entry point for operand parsing. 484 1.1 christos 485 1.1 christos This function is basically just a big switch statement. Earlier versions 486 1.1 christos used tables to look up the function to use, but 487 1.1 christos - if the table contains both assembler and disassembler functions then 488 1.1 christos the disassembler contains much of the assembler and vice-versa, 489 1.1 christos - there's a lot of inlining possibilities as things grow, 490 1.1 christos - using a switch statement avoids the function call overhead. 491 1.1 christos 492 1.1 christos This function could be moved into `parse_insn_normal', but keeping it 493 1.1 christos separate makes clear the interface between `parse_insn_normal' and each of 494 1.1 christos the handlers. */ 495 1.1 christos 496 1.1 christos const char * 497 1.1 christos or1k_cgen_parse_operand (CGEN_CPU_DESC cd, 498 1.1 christos int opindex, 499 1.1 christos const char ** strp, 500 1.1 christos CGEN_FIELDS * fields) 501 1.1 christos { 502 1.1 christos const char * errmsg = NULL; 503 1.1 christos /* Used by scalar operands that still need to be parsed. */ 504 1.1 christos long junk ATTRIBUTE_UNUSED; 505 1.1 christos 506 1.1 christos switch (opindex) 507 1.6 christos { 508 1.6 christos case OR1K_OPERAND_DISP21 : 509 1.6 christos { 510 1.6 christos bfd_vma value = 0; 511 1.6 christos errmsg = parse_disp21 (cd, strp, OR1K_OPERAND_DISP21, 0, NULL, & value); 512 1.6 christos fields->f_disp21 = value; 513 1.6 christos } 514 1.1 christos break; 515 1.1 christos case OR1K_OPERAND_DISP26 : 516 1.1 christos { 517 1.1 christos bfd_vma value = 0; 518 1.1 christos errmsg = parse_disp26 (cd, strp, OR1K_OPERAND_DISP26, 0, NULL, & value); 519 1.1 christos fields->f_disp26 = value; 520 1.1 christos } 521 1.1 christos break; 522 1.1 christos case OR1K_OPERAND_RA : 523 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r2); 524 1.7 christos break; 525 1.7 christos case OR1K_OPERAND_RAD32F : 526 1.7 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RAD32F, (unsigned long *) (& fields->f_rad32)); 527 1.7 christos break; 528 1.7 christos case OR1K_OPERAND_RADI : 529 1.1 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RADI, (unsigned long *) (& fields->f_rad32)); 530 1.1 christos break; 531 1.1 christos case OR1K_OPERAND_RASF : 532 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r2); 533 1.1 christos break; 534 1.1 christos case OR1K_OPERAND_RB : 535 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r3); 536 1.7 christos break; 537 1.7 christos case OR1K_OPERAND_RBD32F : 538 1.7 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RBD32F, (unsigned long *) (& fields->f_rbd32)); 539 1.7 christos break; 540 1.7 christos case OR1K_OPERAND_RBDI : 541 1.1 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RBDI, (unsigned long *) (& fields->f_rbd32)); 542 1.1 christos break; 543 1.1 christos case OR1K_OPERAND_RBSF : 544 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r3); 545 1.1 christos break; 546 1.1 christos case OR1K_OPERAND_RD : 547 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r1); 548 1.7 christos break; 549 1.7 christos case OR1K_OPERAND_RDD32F : 550 1.7 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RDD32F, (unsigned long *) (& fields->f_rdd32)); 551 1.7 christos break; 552 1.7 christos case OR1K_OPERAND_RDDI : 553 1.1 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RDDI, (unsigned long *) (& fields->f_rdd32)); 554 1.1 christos break; 555 1.1 christos case OR1K_OPERAND_RDSF : 556 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r1); 557 1.1 christos break; 558 1.1 christos case OR1K_OPERAND_SIMM16 : 559 1.1 christos errmsg = parse_simm16 (cd, strp, OR1K_OPERAND_SIMM16, (long *) (& fields->f_simm16)); 560 1.1 christos break; 561 1.6 christos case OR1K_OPERAND_SIMM16_SPLIT : 562 1.1 christos errmsg = parse_simm16_split (cd, strp, OR1K_OPERAND_SIMM16_SPLIT, (long *) (& fields->f_simm16_split)); 563 1.1 christos break; 564 1.1 christos case OR1K_OPERAND_UIMM16 : 565 1.1 christos errmsg = parse_uimm16 (cd, strp, OR1K_OPERAND_UIMM16, (unsigned long *) (& fields->f_uimm16)); 566 1.1 christos break; 567 1.6 christos case OR1K_OPERAND_UIMM16_SPLIT : 568 1.1 christos errmsg = parse_uimm16_split (cd, strp, OR1K_OPERAND_UIMM16_SPLIT, (unsigned long *) (& fields->f_uimm16_split)); 569 1.1 christos break; 570 1.1 christos case OR1K_OPERAND_UIMM6 : 571 1.1 christos errmsg = cgen_parse_unsigned_integer (cd, strp, OR1K_OPERAND_UIMM6, (unsigned long *) (& fields->f_uimm6)); 572 1.1 christos break; 573 1.1 christos 574 1.1 christos default : 575 1.6 christos /* xgettext:c-format */ 576 1.6 christos opcodes_error_handler 577 1.6 christos (_("internal error: unrecognized field %d while parsing"), 578 1.1 christos opindex); 579 1.1 christos abort (); 580 1.1 christos } 581 1.1 christos 582 1.1 christos return errmsg; 583 1.1 christos } 584 1.4 christos 585 1.1 christos cgen_parse_fn * const or1k_cgen_parse_handlers[] = 586 1.1 christos { 587 1.1 christos parse_insn_normal, 588 1.1 christos }; 589 1.1 christos 590 1.1 christos void 591 1.1 christos or1k_cgen_init_asm (CGEN_CPU_DESC cd) 592 1.1 christos { 593 1.1 christos or1k_cgen_init_opcode_table (cd); 594 1.1 christos or1k_cgen_init_ibld_table (cd); 595 1.1 christos cd->parse_handlers = & or1k_cgen_parse_handlers[0]; 596 1.1 christos cd->parse_operand = or1k_cgen_parse_operand; 597 1.1 christos #ifdef CGEN_ASM_INIT_HOOK 598 1.1 christos CGEN_ASM_INIT_HOOK 599 1.1 christos #endif 600 1.1 christos } 601 1.1 christos 602 1.1 christos 603 1.1 christos 605 1.1 christos /* Regex construction routine. 606 1.1 christos 607 1.1 christos This translates an opcode syntax string into a regex string, 608 1.1 christos by replacing any non-character syntax element (such as an 609 1.1 christos opcode) with the pattern '.*' 610 1.1 christos 611 1.1 christos It then compiles the regex and stores it in the opcode, for 612 1.1 christos later use by or1k_cgen_assemble_insn 613 1.1 christos 614 1.4 christos Returns NULL for success, an error message for failure. */ 615 1.1 christos 616 1.4 christos char * 617 1.1 christos or1k_cgen_build_insn_regex (CGEN_INSN *insn) 618 1.1 christos { 619 1.1 christos CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn); 620 1.1 christos const char *mnem = CGEN_INSN_MNEMONIC (insn); 621 1.1 christos char rxbuf[CGEN_MAX_RX_ELEMENTS]; 622 1.1 christos char *rx = rxbuf; 623 1.1 christos const CGEN_SYNTAX_CHAR_TYPE *syn; 624 1.1 christos int reg_err; 625 1.1 christos 626 1.1 christos syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc)); 627 1.1 christos 628 1.1 christos /* Mnemonics come first in the syntax string. */ 629 1.1 christos if (! CGEN_SYNTAX_MNEMONIC_P (* syn)) 630 1.1 christos return _("missing mnemonic in syntax string"); 631 1.1 christos ++syn; 632 1.1 christos 633 1.1 christos /* Generate a case sensitive regular expression that emulates case 634 1.1 christos insensitive matching in the "C" locale. We cannot generate a case 635 1.1 christos insensitive regular expression because in Turkish locales, 'i' and 'I' 636 1.1 christos are not equal modulo case conversion. */ 637 1.1 christos 638 1.1 christos /* Copy the literal mnemonic out of the insn. */ 639 1.1 christos for (; *mnem; mnem++) 640 1.1 christos { 641 1.1 christos char c = *mnem; 642 1.1 christos 643 1.1 christos if (ISALPHA (c)) 644 1.1 christos { 645 1.1 christos *rx++ = '['; 646 1.1 christos *rx++ = TOLOWER (c); 647 1.1 christos *rx++ = TOUPPER (c); 648 1.1 christos *rx++ = ']'; 649 1.1 christos } 650 1.1 christos else 651 1.1 christos *rx++ = c; 652 1.1 christos } 653 1.1 christos 654 1.1 christos /* Copy any remaining literals from the syntax string into the rx. */ 655 1.4 christos for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn) 656 1.1 christos { 657 1.1 christos if (CGEN_SYNTAX_CHAR_P (* syn)) 658 1.1 christos { 659 1.4 christos char c = CGEN_SYNTAX_CHAR (* syn); 660 1.1 christos 661 1.1 christos switch (c) 662 1.4 christos { 663 1.4 christos /* Escape any regex metacharacters in the syntax. */ 664 1.1 christos case '.': case '[': case '\\': 665 1.1 christos case '*': case '^': case '$': 666 1.4 christos 667 1.1 christos #ifdef CGEN_ESCAPE_EXTENDED_REGEX 668 1.1 christos case '?': case '{': case '}': 669 1.1 christos case '(': case ')': case '*': 670 1.1 christos case '|': case '+': case ']': 671 1.1 christos #endif 672 1.1 christos *rx++ = '\\'; 673 1.1 christos *rx++ = c; 674 1.1 christos break; 675 1.1 christos 676 1.1 christos default: 677 1.1 christos if (ISALPHA (c)) 678 1.1 christos { 679 1.1 christos *rx++ = '['; 680 1.1 christos *rx++ = TOLOWER (c); 681 1.1 christos *rx++ = TOUPPER (c); 682 1.1 christos *rx++ = ']'; 683 1.1 christos } 684 1.1 christos else 685 1.1 christos *rx++ = c; 686 1.1 christos break; 687 1.1 christos } 688 1.1 christos } 689 1.1 christos else 690 1.1 christos { 691 1.1 christos /* Replace non-syntax fields with globs. */ 692 1.1 christos *rx++ = '.'; 693 1.1 christos *rx++ = '*'; 694 1.1 christos } 695 1.1 christos } 696 1.4 christos 697 1.4 christos /* Trailing whitespace ok. */ 698 1.4 christos * rx++ = '['; 699 1.4 christos * rx++ = ' '; 700 1.4 christos * rx++ = '\t'; 701 1.1 christos * rx++ = ']'; 702 1.1 christos * rx++ = '*'; 703 1.4 christos 704 1.1 christos /* But anchor it after that. */ 705 1.1 christos * rx++ = '$'; 706 1.1 christos * rx = '\0'; 707 1.1 christos 708 1.1 christos CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t)); 709 1.4 christos reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB); 710 1.1 christos 711 1.1 christos if (reg_err == 0) 712 1.1 christos return NULL; 713 1.1 christos else 714 1.1 christos { 715 1.1 christos static char msg[80]; 716 1.1 christos 717 1.1 christos regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80); 718 1.1 christos regfree ((regex_t *) CGEN_INSN_RX (insn)); 719 1.1 christos free (CGEN_INSN_RX (insn)); 720 1.1 christos (CGEN_INSN_RX (insn)) = NULL; 721 1.1 christos return msg; 722 1.1 christos } 723 1.1 christos } 724 1.1 christos 725 1.1 christos 726 1.1 christos /* Default insn parser. 728 1.1 christos 729 1.1 christos The syntax string is scanned and operands are parsed and stored in FIELDS. 730 1.1 christos Relocs are queued as we go via other callbacks. 731 1.1 christos 732 1.1 christos ??? Note that this is currently an all-or-nothing parser. If we fail to 733 1.1 christos parse the instruction, we return 0 and the caller will start over from 734 1.1 christos the beginning. Backtracking will be necessary in parsing subexpressions, 735 1.1 christos but that can be handled there. Not handling backtracking here may get 736 1.1 christos expensive in the case of the m68k. Deal with later. 737 1.1 christos 738 1.1 christos Returns NULL for success, an error message for failure. */ 739 1.1 christos 740 1.1 christos static const char * 741 1.1 christos parse_insn_normal (CGEN_CPU_DESC cd, 742 1.1 christos const CGEN_INSN *insn, 743 1.1 christos const char **strp, 744 1.1 christos CGEN_FIELDS *fields) 745 1.1 christos { 746 1.1 christos /* ??? Runtime added insns not handled yet. */ 747 1.1 christos const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); 748 1.1 christos const char *str = *strp; 749 1.1 christos const char *errmsg; 750 1.1 christos const char *p; 751 1.1 christos const CGEN_SYNTAX_CHAR_TYPE * syn; 752 1.1 christos #ifdef CGEN_MNEMONIC_OPERANDS 753 1.1 christos /* FIXME: wip */ 754 1.1 christos int past_opcode_p; 755 1.1 christos #endif 756 1.1 christos 757 1.1 christos /* For now we assume the mnemonic is first (there are no leading operands). 758 1.1 christos We can parse it without needing to set up operand parsing. 759 1.1 christos GAS's input scrubber will ensure mnemonics are lowercase, but we may 760 1.1 christos not be called from GAS. */ 761 1.1 christos p = CGEN_INSN_MNEMONIC (insn); 762 1.1 christos while (*p && TOLOWER (*p) == TOLOWER (*str)) 763 1.1 christos ++p, ++str; 764 1.1 christos 765 1.1 christos if (* p) 766 1.1 christos return _("unrecognized instruction"); 767 1.1 christos 768 1.1 christos #ifndef CGEN_MNEMONIC_OPERANDS 769 1.1 christos if (* str && ! ISSPACE (* str)) 770 1.1 christos return _("unrecognized instruction"); 771 1.1 christos #endif 772 1.1 christos 773 1.1 christos CGEN_INIT_PARSE (cd); 774 1.1 christos cgen_init_parse_operand (cd); 775 1.1 christos #ifdef CGEN_MNEMONIC_OPERANDS 776 1.1 christos past_opcode_p = 0; 777 1.1 christos #endif 778 1.1 christos 779 1.1 christos /* We don't check for (*str != '\0') here because we want to parse 780 1.1 christos any trailing fake arguments in the syntax string. */ 781 1.1 christos syn = CGEN_SYNTAX_STRING (syntax); 782 1.1 christos 783 1.1 christos /* Mnemonics come first for now, ensure valid string. */ 784 1.1 christos if (! CGEN_SYNTAX_MNEMONIC_P (* syn)) 785 1.1 christos abort (); 786 1.1 christos 787 1.1 christos ++syn; 788 1.1 christos 789 1.1 christos while (* syn != 0) 790 1.1 christos { 791 1.1 christos /* Non operand chars must match exactly. */ 792 1.1 christos if (CGEN_SYNTAX_CHAR_P (* syn)) 793 1.1 christos { 794 1.1 christos /* FIXME: While we allow for non-GAS callers above, we assume the 795 1.1 christos first char after the mnemonic part is a space. */ 796 1.1 christos /* FIXME: We also take inappropriate advantage of the fact that 797 1.1 christos GAS's input scrubber will remove extraneous blanks. */ 798 1.1 christos if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn))) 799 1.1 christos { 800 1.1 christos #ifdef CGEN_MNEMONIC_OPERANDS 801 1.1 christos if (CGEN_SYNTAX_CHAR(* syn) == ' ') 802 1.1 christos past_opcode_p = 1; 803 1.1 christos #endif 804 1.1 christos ++ syn; 805 1.1 christos ++ str; 806 1.1 christos } 807 1.1 christos else if (*str) 808 1.1 christos { 809 1.1 christos /* Syntax char didn't match. Can't be this insn. */ 810 1.1 christos static char msg [80]; 811 1.1 christos 812 1.1 christos /* xgettext:c-format */ 813 1.1 christos sprintf (msg, _("syntax error (expected char `%c', found `%c')"), 814 1.1 christos CGEN_SYNTAX_CHAR(*syn), *str); 815 1.1 christos return msg; 816 1.1 christos } 817 1.1 christos else 818 1.1 christos { 819 1.1 christos /* Ran out of input. */ 820 1.1 christos static char msg [80]; 821 1.1 christos 822 1.1 christos /* xgettext:c-format */ 823 1.1 christos sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"), 824 1.1 christos CGEN_SYNTAX_CHAR(*syn)); 825 1.1 christos return msg; 826 1.1 christos } 827 1.1 christos continue; 828 1.1 christos } 829 1.1 christos 830 1.1 christos #ifdef CGEN_MNEMONIC_OPERANDS 831 1.1 christos (void) past_opcode_p; 832 1.1 christos #endif 833 1.1 christos /* We have an operand of some sort. */ 834 1.1 christos errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields); 835 1.1 christos if (errmsg) 836 1.1 christos return errmsg; 837 1.1 christos 838 1.1 christos /* Done with this operand, continue with next one. */ 839 1.1 christos ++ syn; 840 1.1 christos } 841 1.1 christos 842 1.1 christos /* If we're at the end of the syntax string, we're done. */ 843 1.1 christos if (* syn == 0) 844 1.1 christos { 845 1.1 christos /* FIXME: For the moment we assume a valid `str' can only contain 846 1.1 christos blanks now. IE: We needn't try again with a longer version of 847 1.1 christos the insn and it is assumed that longer versions of insns appear 848 1.1 christos before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */ 849 1.1 christos while (ISSPACE (* str)) 850 1.1 christos ++ str; 851 1.1 christos 852 1.1 christos if (* str != '\0') 853 1.1 christos return _("junk at end of line"); /* FIXME: would like to include `str' */ 854 1.1 christos 855 1.1 christos return NULL; 856 1.1 christos } 857 1.1 christos 858 1.1 christos /* We couldn't parse it. */ 859 1.1 christos return _("unrecognized instruction"); 860 1.1 christos } 861 1.1 christos 862 1.1 christos /* Main entry point. 864 1.1 christos This routine is called for each instruction to be assembled. 865 1.1 christos STR points to the insn to be assembled. 866 1.1 christos We assume all necessary tables have been initialized. 867 1.1 christos The assembled instruction, less any fixups, is stored in BUF. 868 1.1 christos Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value 869 1.1 christos still needs to be converted to target byte order, otherwise BUF is an array 870 1.1 christos of bytes in target byte order. 871 1.1 christos The result is a pointer to the insn's entry in the opcode table, 872 1.1 christos or NULL if an error occured (an error message will have already been 873 1.1 christos printed). 874 1.1 christos 875 1.1 christos Note that when processing (non-alias) macro-insns, 876 1.1 christos this function recurses. 877 1.1 christos 878 1.1 christos ??? It's possible to make this cpu-independent. 879 1.1 christos One would have to deal with a few minor things. 880 1.1 christos At this point in time doing so would be more of a curiosity than useful 881 1.1 christos [for example this file isn't _that_ big], but keeping the possibility in 882 1.1 christos mind helps keep the design clean. */ 883 1.1 christos 884 1.1 christos const CGEN_INSN * 885 1.1 christos or1k_cgen_assemble_insn (CGEN_CPU_DESC cd, 886 1.1 christos const char *str, 887 1.1 christos CGEN_FIELDS *fields, 888 1.1 christos CGEN_INSN_BYTES_PTR buf, 889 1.1 christos char **errmsg) 890 1.1 christos { 891 1.1 christos const char *start; 892 1.1 christos CGEN_INSN_LIST *ilist; 893 1.1 christos const char *parse_errmsg = NULL; 894 1.1 christos const char *insert_errmsg = NULL; 895 1.1 christos int recognized_mnemonic = 0; 896 1.1 christos 897 1.1 christos /* Skip leading white space. */ 898 1.1 christos while (ISSPACE (* str)) 899 1.1 christos ++ str; 900 1.1 christos 901 1.1 christos /* The instructions are stored in hashed lists. 902 1.1 christos Get the first in the list. */ 903 1.1 christos ilist = CGEN_ASM_LOOKUP_INSN (cd, str); 904 1.1 christos 905 1.1 christos /* Keep looking until we find a match. */ 906 1.1 christos start = str; 907 1.1 christos for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist)) 908 1.4 christos { 909 1.1 christos const CGEN_INSN *insn = ilist->insn; 910 1.1 christos recognized_mnemonic = 1; 911 1.1 christos 912 1.1 christos #ifdef CGEN_VALIDATE_INSN_SUPPORTED 913 1.1 christos /* Not usually needed as unsupported opcodes 914 1.1 christos shouldn't be in the hash lists. */ 915 1.1 christos /* Is this insn supported by the selected cpu? */ 916 1.1 christos if (! or1k_cgen_insn_supported (cd, insn)) 917 1.1 christos continue; 918 1.1 christos #endif 919 1.1 christos /* If the RELAXED attribute is set, this is an insn that shouldn't be 920 1.1 christos chosen immediately. Instead, it is used during assembler/linker 921 1.1 christos relaxation if possible. */ 922 1.1 christos if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0) 923 1.1 christos continue; 924 1.1 christos 925 1.1 christos str = start; 926 1.1 christos 927 1.1 christos /* Skip this insn if str doesn't look right lexically. */ 928 1.1 christos if (CGEN_INSN_RX (insn) != NULL && 929 1.1 christos regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH) 930 1.1 christos continue; 931 1.1 christos 932 1.1 christos /* Allow parse/insert handlers to obtain length of insn. */ 933 1.1 christos CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn); 934 1.1 christos 935 1.1 christos parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields); 936 1.1 christos if (parse_errmsg != NULL) 937 1.1 christos continue; 938 1.1 christos 939 1.1 christos /* ??? 0 is passed for `pc'. */ 940 1.1 christos insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf, 941 1.1 christos (bfd_vma) 0); 942 1.1 christos if (insert_errmsg != NULL) 943 1.1 christos continue; 944 1.1 christos 945 1.1 christos /* It is up to the caller to actually output the insn and any 946 1.1 christos queued relocs. */ 947 1.1 christos return insn; 948 1.1 christos } 949 1.1 christos 950 1.1 christos { 951 1.1 christos static char errbuf[150]; 952 1.1 christos const char *tmp_errmsg; 953 1.1 christos #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS 954 1.1 christos #define be_verbose 1 955 1.1 christos #else 956 1.1 christos #define be_verbose 0 957 1.1 christos #endif 958 1.1 christos 959 1.1 christos if (be_verbose) 960 1.1 christos { 961 1.1 christos /* If requesting verbose error messages, use insert_errmsg. 962 1.1 christos Failing that, use parse_errmsg. */ 963 1.1 christos tmp_errmsg = (insert_errmsg ? insert_errmsg : 964 1.1 christos parse_errmsg ? parse_errmsg : 965 1.1 christos recognized_mnemonic ? 966 1.1 christos _("unrecognized form of instruction") : 967 1.1 christos _("unrecognized instruction")); 968 1.4 christos 969 1.1 christos if (strlen (start) > 50) 970 1.1 christos /* xgettext:c-format */ 971 1.1 christos sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start); 972 1.1 christos else 973 1.1 christos /* xgettext:c-format */ 974 1.1 christos sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start); 975 1.1 christos } 976 1.1 christos else 977 1.4 christos { 978 1.1 christos if (strlen (start) > 50) 979 1.1 christos /* xgettext:c-format */ 980 1.1 christos sprintf (errbuf, _("bad instruction `%.50s...'"), start); 981 1.4 christos else 982 1.1 christos /* xgettext:c-format */ 983 1.1 christos sprintf (errbuf, _("bad instruction `%.50s'"), start); 984 1.1 christos } 985 1.1 christos 986 *errmsg = errbuf; 987 return NULL; 988 } 989 } 990