| 1 | /* Assembler interface for targets using CGEN. -*- C -*-
|
|---|
| 2 | CGEN: Cpu tools GENerator
|
|---|
| 3 |
|
|---|
| 4 | THIS FILE IS MACHINE GENERATED WITH CGEN.
|
|---|
| 5 | - the resultant file is machine generated, cgen-asm.in isn't
|
|---|
| 6 |
|
|---|
| 7 | Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
|---|
| 8 |
|
|---|
| 9 | This file is part of the GNU Binutils and GDB, the GNU debugger.
|
|---|
| 10 |
|
|---|
| 11 | This program is free software; you can redistribute it and/or modify
|
|---|
| 12 | it under the terms of the GNU General Public License as published by
|
|---|
| 13 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 14 | any later version.
|
|---|
| 15 |
|
|---|
| 16 | This program is distributed in the hope that it will be useful,
|
|---|
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | GNU General Public License for more details.
|
|---|
| 20 |
|
|---|
| 21 | You should have received a copy of the GNU General Public License
|
|---|
| 22 | along with this program; if not, write to the Free Software Foundation, Inc.,
|
|---|
| 23 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 24 |
|
|---|
| 25 | /* ??? Eventually more and more of this stuff can go to cpu-independent files.
|
|---|
| 26 | Keep that in mind. */
|
|---|
| 27 |
|
|---|
| 28 | #include "sysdep.h"
|
|---|
| 29 | #include <stdio.h>
|
|---|
| 30 | #include "ansidecl.h"
|
|---|
| 31 | #include "bfd.h"
|
|---|
| 32 | #include "symcat.h"
|
|---|
| 33 | #include "ip2k-desc.h"
|
|---|
| 34 | #include "ip2k-opc.h"
|
|---|
| 35 | #include "opintl.h"
|
|---|
| 36 | #include "xregex.h"
|
|---|
| 37 | #include "libiberty.h"
|
|---|
| 38 | #include "safe-ctype.h"
|
|---|
| 39 |
|
|---|
| 40 | #undef min
|
|---|
| 41 | #define min(a,b) ((a) < (b) ? (a) : (b))
|
|---|
| 42 | #undef max
|
|---|
| 43 | #define max(a,b) ((a) > (b) ? (a) : (b))
|
|---|
| 44 |
|
|---|
| 45 | static const char * parse_insn_normal
|
|---|
| 46 | PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *));
|
|---|
| 47 | |
|---|
| 48 |
|
|---|
| 49 | /* -- assembler routines inserted here. */
|
|---|
| 50 |
|
|---|
| 51 | /* -- asm.c */
|
|---|
| 52 |
|
|---|
| 53 | #define PARSE_FUNC_DECL(name) \
|
|---|
| 54 | static const char *name PARAMS ((CGEN_CPU_DESC, const char **, int, long *))
|
|---|
| 55 |
|
|---|
| 56 | PARSE_FUNC_DECL (parse_fr);
|
|---|
| 57 | PARSE_FUNC_DECL (parse_addr16);
|
|---|
| 58 | PARSE_FUNC_DECL (parse_addr16_p);
|
|---|
| 59 | PARSE_FUNC_DECL (parse_addr16_cjp);
|
|---|
| 60 | PARSE_FUNC_DECL (parse_lit8);
|
|---|
| 61 | PARSE_FUNC_DECL (parse_bit3);
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | static const char *
|
|---|
| 65 | parse_fr (cd, strp, opindex, valuep)
|
|---|
| 66 | CGEN_CPU_DESC cd;
|
|---|
| 67 | const char **strp;
|
|---|
| 68 | int opindex;
|
|---|
| 69 | long *valuep;
|
|---|
| 70 | {
|
|---|
| 71 | const char *errmsg;
|
|---|
| 72 | const char *old_strp;
|
|---|
| 73 | char *afteroffset;
|
|---|
| 74 | enum cgen_parse_operand_result result_type;
|
|---|
| 75 | bfd_vma value;
|
|---|
| 76 | extern CGEN_KEYWORD ip2k_cgen_opval_register_names;
|
|---|
| 77 | bfd_vma tempvalue;
|
|---|
| 78 |
|
|---|
| 79 | old_strp = *strp;
|
|---|
| 80 | afteroffset = NULL;
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | /* Check here to see if you're about to try parsing a w as the first arg */
|
|---|
| 84 | /* and return an error if you are. */
|
|---|
| 85 | if ( (strncmp(*strp,"w",1)==0) || (strncmp(*strp,"W",1)==0) )
|
|---|
| 86 | {
|
|---|
| 87 | (*strp)++;
|
|---|
| 88 |
|
|---|
| 89 | if ( (strncmp(*strp,",",1)==0) || ISSPACE(**strp) )
|
|---|
| 90 | {
|
|---|
| 91 | /* We've been passed a w. Return with an error message so that */
|
|---|
| 92 | /* cgen will try the next parsing option. */
|
|---|
| 93 | errmsg = _("W keyword invalid in FR operand slot.");
|
|---|
| 94 | return errmsg;
|
|---|
| 95 | }
|
|---|
| 96 | *strp = old_strp;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | /* Attempt parse as register keyword. */
|
|---|
| 101 | /* old_strp = *strp; */
|
|---|
| 102 |
|
|---|
| 103 | errmsg = cgen_parse_keyword (cd, strp, & ip2k_cgen_opval_register_names,
|
|---|
| 104 | valuep);
|
|---|
| 105 | if ( *strp != NULL )
|
|---|
| 106 | if (errmsg == NULL)
|
|---|
| 107 | return errmsg;
|
|---|
| 108 |
|
|---|
| 109 | /* Attempt to parse for "(IP)" */
|
|---|
| 110 | afteroffset = strstr(*strp,"(IP)");
|
|---|
| 111 |
|
|---|
| 112 | if ( afteroffset == NULL)
|
|---|
| 113 | {
|
|---|
| 114 | /* Make sure it's not in lower case */
|
|---|
| 115 | afteroffset = strstr(*strp,"(ip)");
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | if ( afteroffset != NULL )
|
|---|
| 119 | {
|
|---|
| 120 | if ( afteroffset != *strp )
|
|---|
| 121 | {
|
|---|
| 122 | /* Invalid offset present.*/
|
|---|
| 123 | errmsg = _("offset(IP) is not a valid form");
|
|---|
| 124 | return errmsg;
|
|---|
| 125 | }
|
|---|
| 126 | else
|
|---|
| 127 | {
|
|---|
| 128 | *strp += 4;
|
|---|
| 129 | *valuep = 0;
|
|---|
| 130 | errmsg = NULL;
|
|---|
| 131 | return errmsg;
|
|---|
| 132 | }
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | /* Attempt to parse for DP. ex: mov w, offset(DP) */
|
|---|
| 136 | /* mov offset(DP),w */
|
|---|
| 137 |
|
|---|
| 138 | /* Try parsing it as an address and see what comes back */
|
|---|
| 139 |
|
|---|
| 140 | afteroffset = strstr(*strp,"(DP)");
|
|---|
| 141 |
|
|---|
| 142 | if ( afteroffset == NULL)
|
|---|
| 143 | {
|
|---|
| 144 | /* Maybe it's in lower case */
|
|---|
| 145 | afteroffset = strstr(*strp,"(dp)");
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | if ( afteroffset != NULL )
|
|---|
| 149 | {
|
|---|
| 150 | if ( afteroffset == *strp )
|
|---|
| 151 | {
|
|---|
| 152 | /* No offset present. Use 0 by default. */
|
|---|
| 153 | tempvalue = 0;
|
|---|
| 154 | errmsg = NULL;
|
|---|
| 155 | }
|
|---|
| 156 | else
|
|---|
| 157 | {
|
|---|
| 158 | errmsg = cgen_parse_address (cd, strp, opindex,
|
|---|
| 159 | BFD_RELOC_IP2K_FR_OFFSET,
|
|---|
| 160 | & result_type, & tempvalue);
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | if (errmsg == NULL)
|
|---|
| 164 | {
|
|---|
| 165 | if (tempvalue <= 127)
|
|---|
| 166 | {
|
|---|
| 167 | /* Value is ok. Fix up the first 2 bits and return */
|
|---|
| 168 | *valuep = 0x0100 | tempvalue;
|
|---|
| 169 | *strp += 4; /* skip over the (DP) in *strp */
|
|---|
| 170 | return errmsg;
|
|---|
| 171 | }
|
|---|
| 172 | else
|
|---|
| 173 | {
|
|---|
| 174 | /* Found something there in front of (DP) but it's out
|
|---|
| 175 | of range. */
|
|---|
| 176 | errmsg = _("(DP) offset out of range.");
|
|---|
| 177 | return errmsg;
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 | /* Attempt to parse for SP. ex: mov w, offset(SP) */
|
|---|
| 184 | /* mov offset(SP), w */
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 | afteroffset = strstr(*strp,"(SP)");
|
|---|
| 188 |
|
|---|
| 189 | if (afteroffset == NULL)
|
|---|
| 190 | {
|
|---|
| 191 | /* Maybe it's in lower case. */
|
|---|
| 192 | afteroffset = strstr(*strp, "(sp)");
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | if ( afteroffset != NULL )
|
|---|
| 196 | {
|
|---|
| 197 | if ( afteroffset == *strp )
|
|---|
| 198 | {
|
|---|
| 199 | /* No offset present. Use 0 by default. */
|
|---|
| 200 | tempvalue = 0;
|
|---|
| 201 | errmsg = NULL;
|
|---|
| 202 | }
|
|---|
| 203 | else
|
|---|
| 204 | {
|
|---|
| 205 | errmsg = cgen_parse_address (cd, strp, opindex,
|
|---|
| 206 | BFD_RELOC_IP2K_FR_OFFSET,
|
|---|
| 207 | & result_type, & tempvalue);
|
|---|
| 208 | }
|
|---|
| 209 | if (errmsg == NULL)
|
|---|
| 210 | {
|
|---|
| 211 | if (tempvalue <= 127)
|
|---|
| 212 | {
|
|---|
| 213 | /* Value is ok. Fix up the first 2 bits and return */
|
|---|
| 214 | *valuep = 0x0180 | tempvalue;
|
|---|
| 215 | *strp += 4; /* skip over the (SP) in *strp */
|
|---|
| 216 | return errmsg;
|
|---|
| 217 | }
|
|---|
| 218 | else
|
|---|
| 219 | {
|
|---|
| 220 | /* Found something there in front of (SP) but it's out
|
|---|
| 221 | of range. */
|
|---|
| 222 | errmsg = _("(SP) offset out of range.");
|
|---|
| 223 | return errmsg;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | }
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 | /* Attempt to parse as an address. */
|
|---|
| 231 | *strp = old_strp;
|
|---|
| 232 | errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_IP2K_FR9,
|
|---|
| 233 | & result_type, & value);
|
|---|
| 234 | if (errmsg == NULL)
|
|---|
| 235 | {
|
|---|
| 236 | *valuep = value;
|
|---|
| 237 |
|
|---|
| 238 | /* if a parenthesis is found, warn about invalid form */
|
|---|
| 239 |
|
|---|
| 240 | if (**strp == '(')
|
|---|
| 241 | {
|
|---|
| 242 | errmsg = _("illegal use of parentheses");
|
|---|
| 243 | }
|
|---|
| 244 | /* if a numeric value is specified, ensure that it is between
|
|---|
| 245 | 1 and 255 */
|
|---|
| 246 | else if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
|
|---|
| 247 | {
|
|---|
| 248 | if (value < 0x1 || value > 0xff)
|
|---|
| 249 | errmsg = _("operand out of range (not between 1 and 255)");
|
|---|
| 250 | }
|
|---|
| 251 | }
|
|---|
| 252 | return errmsg;
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | static const char *
|
|---|
| 256 | parse_addr16 (cd, strp, opindex, valuep)
|
|---|
| 257 | CGEN_CPU_DESC cd;
|
|---|
| 258 | const char **strp;
|
|---|
| 259 | int opindex;
|
|---|
| 260 | long *valuep;
|
|---|
| 261 | {
|
|---|
| 262 | const char *errmsg;
|
|---|
| 263 | enum cgen_parse_operand_result result_type;
|
|---|
| 264 | bfd_reloc_code_real_type code = BFD_RELOC_NONE;
|
|---|
| 265 | bfd_vma value;
|
|---|
| 266 |
|
|---|
| 267 | if ( opindex == (CGEN_OPERAND_TYPE)IP2K_OPERAND_ADDR16H )
|
|---|
| 268 | code = BFD_RELOC_IP2K_HI8DATA;
|
|---|
| 269 | else if ( opindex == (CGEN_OPERAND_TYPE)IP2K_OPERAND_ADDR16L )
|
|---|
| 270 | code = BFD_RELOC_IP2K_LO8DATA;
|
|---|
| 271 | else
|
|---|
| 272 | {
|
|---|
| 273 | /* Something is very wrong. opindex has to be one of the above. */
|
|---|
| 274 | errmsg = _("parse_addr16: invalid opindex.");
|
|---|
| 275 | return errmsg;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | errmsg = cgen_parse_address (cd, strp, opindex, code,
|
|---|
| 279 | & result_type, & value);
|
|---|
| 280 | if (errmsg == NULL)
|
|---|
| 281 | {
|
|---|
| 282 | /* We either have a relocation or a number now. */
|
|---|
| 283 | if ( result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER )
|
|---|
| 284 | {
|
|---|
| 285 | /* We got a number back. */
|
|---|
| 286 | if ( code == BFD_RELOC_IP2K_HI8DATA )
|
|---|
| 287 | value >>= 8;
|
|---|
| 288 | else /* code = BFD_RELOC_IP2K_LOW8DATA */
|
|---|
| 289 | value &= 0x00FF;
|
|---|
| 290 | }
|
|---|
| 291 | *valuep = value;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | return errmsg;
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 | static const char *
|
|---|
| 299 | parse_addr16_p (cd, strp, opindex, valuep)
|
|---|
| 300 | CGEN_CPU_DESC cd;
|
|---|
| 301 | const char **strp;
|
|---|
| 302 | int opindex;
|
|---|
| 303 | long *valuep;
|
|---|
| 304 | {
|
|---|
| 305 | const char *errmsg;
|
|---|
| 306 | enum cgen_parse_operand_result result_type;
|
|---|
| 307 | bfd_reloc_code_real_type code = BFD_RELOC_IP2K_PAGE3;
|
|---|
| 308 | bfd_vma value;
|
|---|
| 309 |
|
|---|
| 310 | errmsg = cgen_parse_address (cd, strp, opindex, code,
|
|---|
| 311 | & result_type, & value);
|
|---|
| 312 | if (errmsg == NULL)
|
|---|
| 313 | {
|
|---|
| 314 | if ( result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER )
|
|---|
| 315 | *valuep = (value >> 13) & 0x7;
|
|---|
| 316 | else if ( result_type == CGEN_PARSE_OPERAND_RESULT_QUEUED )
|
|---|
| 317 | *valuep = value;
|
|---|
| 318 | }
|
|---|
| 319 | return errmsg;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 | static const char *
|
|---|
| 324 | parse_addr16_cjp (cd, strp, opindex, valuep)
|
|---|
| 325 | CGEN_CPU_DESC cd;
|
|---|
| 326 | const char **strp;
|
|---|
| 327 | int opindex;
|
|---|
| 328 | long *valuep;
|
|---|
| 329 | {
|
|---|
| 330 | const char *errmsg;
|
|---|
| 331 | enum cgen_parse_operand_result result_type;
|
|---|
| 332 | bfd_reloc_code_real_type code = BFD_RELOC_NONE;
|
|---|
| 333 | bfd_vma value;
|
|---|
| 334 |
|
|---|
| 335 | if ( opindex == (CGEN_OPERAND_TYPE)IP2K_OPERAND_ADDR16CJP )
|
|---|
| 336 | code = BFD_RELOC_IP2K_ADDR16CJP;
|
|---|
| 337 | else if ( opindex == (CGEN_OPERAND_TYPE)IP2K_OPERAND_ADDR16P )
|
|---|
| 338 | code = BFD_RELOC_IP2K_PAGE3;
|
|---|
| 339 |
|
|---|
| 340 | errmsg = cgen_parse_address (cd, strp, opindex, code,
|
|---|
| 341 | & result_type, & value);
|
|---|
| 342 | if (errmsg == NULL)
|
|---|
| 343 | {
|
|---|
| 344 | if ( result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER )
|
|---|
| 345 | {
|
|---|
| 346 | if ( (value & 0x1) == 0) /* If the address is even .... */
|
|---|
| 347 | {
|
|---|
| 348 | if ( opindex == (CGEN_OPERAND_TYPE)IP2K_OPERAND_ADDR16CJP )
|
|---|
| 349 | *valuep = (value >> 1) & 0x1FFF; /* Should mask be 1FFF? */
|
|---|
| 350 | else if ( opindex == (CGEN_OPERAND_TYPE)IP2K_OPERAND_ADDR16P )
|
|---|
| 351 | *valuep = (value >> 14) & 0x7;
|
|---|
| 352 | }
|
|---|
| 353 | else
|
|---|
| 354 | errmsg = _("Byte address required. - must be even.");
|
|---|
| 355 | }
|
|---|
| 356 | else if ( result_type == CGEN_PARSE_OPERAND_RESULT_QUEUED )
|
|---|
| 357 | {
|
|---|
| 358 | /* This will happen for things like (s2-s1) where s2 and s1
|
|---|
| 359 | are labels. */
|
|---|
| 360 | *valuep = value;
|
|---|
| 361 | }
|
|---|
| 362 | else
|
|---|
| 363 | errmsg = _("cgen_parse_address returned a symbol. Literal required.");
|
|---|
| 364 | }
|
|---|
| 365 | return errmsg;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 | static const char *
|
|---|
| 370 | parse_lit8 (cd, strp, opindex, valuep)
|
|---|
| 371 | CGEN_CPU_DESC cd;
|
|---|
| 372 | const char **strp;
|
|---|
| 373 | int opindex;
|
|---|
| 374 | long *valuep;
|
|---|
| 375 | {
|
|---|
| 376 | const char *errmsg;
|
|---|
| 377 | enum cgen_parse_operand_result result_type;
|
|---|
| 378 | bfd_reloc_code_real_type code = BFD_RELOC_NONE;
|
|---|
| 379 | bfd_vma value;
|
|---|
| 380 |
|
|---|
| 381 | /* Parse %OP relocating operators. */
|
|---|
| 382 | if (strncmp (*strp, "%bank", 5) == 0)
|
|---|
| 383 | {
|
|---|
| 384 | *strp += 5;
|
|---|
| 385 | code = BFD_RELOC_IP2K_BANK;
|
|---|
| 386 | }
|
|---|
| 387 | else if (strncmp (*strp, "%lo8data", 8) == 0)
|
|---|
| 388 | {
|
|---|
| 389 | *strp += 8;
|
|---|
| 390 | code = BFD_RELOC_IP2K_LO8DATA;
|
|---|
| 391 | }
|
|---|
| 392 | else if (strncmp (*strp, "%hi8data", 8) == 0)
|
|---|
| 393 | {
|
|---|
| 394 | *strp += 8;
|
|---|
| 395 | code = BFD_RELOC_IP2K_HI8DATA;
|
|---|
| 396 | }
|
|---|
| 397 | else if (strncmp (*strp, "%ex8data", 8) == 0)
|
|---|
| 398 | {
|
|---|
| 399 | *strp += 8;
|
|---|
| 400 | code = BFD_RELOC_IP2K_EX8DATA;
|
|---|
| 401 | }
|
|---|
| 402 | else if (strncmp (*strp, "%lo8insn", 8) == 0)
|
|---|
| 403 | {
|
|---|
| 404 | *strp += 8;
|
|---|
| 405 | code = BFD_RELOC_IP2K_LO8INSN;
|
|---|
| 406 | }
|
|---|
| 407 | else if (strncmp (*strp, "%hi8insn", 8) == 0)
|
|---|
| 408 | {
|
|---|
| 409 | *strp += 8;
|
|---|
| 410 | code = BFD_RELOC_IP2K_HI8INSN;
|
|---|
| 411 | }
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 | /* Parse %op operand. */
|
|---|
| 415 | if (code != BFD_RELOC_NONE)
|
|---|
| 416 | {
|
|---|
| 417 | errmsg = cgen_parse_address (cd, strp, opindex, code,
|
|---|
| 418 | & result_type, & value);
|
|---|
| 419 | if ((errmsg == NULL) &&
|
|---|
| 420 | (result_type != CGEN_PARSE_OPERAND_RESULT_QUEUED))
|
|---|
| 421 | errmsg = _("%operator operand is not a symbol");
|
|---|
| 422 |
|
|---|
| 423 | *valuep = value;
|
|---|
| 424 | }
|
|---|
| 425 | /* Parse as a number. */
|
|---|
| 426 | else
|
|---|
| 427 | {
|
|---|
| 428 | errmsg = cgen_parse_signed_integer (cd, strp, opindex, valuep);
|
|---|
| 429 |
|
|---|
| 430 | /* Truncate to eight bits to accept both signed and unsigned input. */
|
|---|
| 431 | if (errmsg == NULL)
|
|---|
| 432 | *valuep &= 0xFF;
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | return errmsg;
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | static const char *
|
|---|
| 439 | parse_bit3 (cd, strp, opindex, valuep)
|
|---|
| 440 | CGEN_CPU_DESC cd;
|
|---|
| 441 | const char **strp;
|
|---|
| 442 | int opindex;
|
|---|
| 443 | long *valuep;
|
|---|
| 444 | {
|
|---|
| 445 | const char *errmsg;
|
|---|
| 446 | char mode = 0;
|
|---|
| 447 | long count = 0;
|
|---|
| 448 | unsigned long value;
|
|---|
| 449 |
|
|---|
| 450 | if (strncmp (*strp, "%bit", 4) == 0)
|
|---|
| 451 | {
|
|---|
| 452 | *strp += 4;
|
|---|
| 453 | mode = 1;
|
|---|
| 454 | }
|
|---|
| 455 | else if (strncmp (*strp, "%msbbit", 7) == 0)
|
|---|
| 456 | {
|
|---|
| 457 | *strp += 7;
|
|---|
| 458 | mode = 1;
|
|---|
| 459 | }
|
|---|
| 460 | else if (strncmp (*strp, "%lsbbit", 7) == 0)
|
|---|
| 461 | {
|
|---|
| 462 | *strp += 7;
|
|---|
| 463 | mode = 2;
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | errmsg = cgen_parse_signed_integer (cd, strp, opindex, valuep);
|
|---|
| 467 | if (errmsg)
|
|---|
| 468 | return errmsg;
|
|---|
| 469 |
|
|---|
| 470 | if (mode)
|
|---|
| 471 | {
|
|---|
| 472 | value = (unsigned long) *valuep;
|
|---|
| 473 | if (value == 0)
|
|---|
| 474 | {
|
|---|
| 475 | errmsg = _("Attempt to find bit index of 0");
|
|---|
| 476 | return errmsg;
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | if (mode == 1)
|
|---|
| 480 | {
|
|---|
| 481 | count = 31;
|
|---|
| 482 | while ((value & 0x80000000) == 0)
|
|---|
| 483 | {
|
|---|
| 484 | count--;
|
|---|
| 485 | value <<= 1;
|
|---|
| 486 | }
|
|---|
| 487 | }
|
|---|
| 488 | else if (mode == 2)
|
|---|
| 489 | {
|
|---|
| 490 | count = 0;
|
|---|
| 491 | while ((value & 0x00000001) == 0)
|
|---|
| 492 | {
|
|---|
| 493 | count++;
|
|---|
| 494 | value >>= 1;
|
|---|
| 495 | }
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | *valuep = count;
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | return errmsg;
|
|---|
| 502 | }
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 | /* -- dis.c */
|
|---|
| 506 |
|
|---|
| 507 | const char * ip2k_cgen_parse_operand
|
|---|
| 508 | PARAMS ((CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *));
|
|---|
| 509 |
|
|---|
| 510 | /* Main entry point for operand parsing.
|
|---|
| 511 |
|
|---|
| 512 | This function is basically just a big switch statement. Earlier versions
|
|---|
| 513 | used tables to look up the function to use, but
|
|---|
| 514 | - if the table contains both assembler and disassembler functions then
|
|---|
| 515 | the disassembler contains much of the assembler and vice-versa,
|
|---|
| 516 | - there's a lot of inlining possibilities as things grow,
|
|---|
| 517 | - using a switch statement avoids the function call overhead.
|
|---|
| 518 |
|
|---|
| 519 | This function could be moved into `parse_insn_normal', but keeping it
|
|---|
| 520 | separate makes clear the interface between `parse_insn_normal' and each of
|
|---|
| 521 | the handlers. */
|
|---|
| 522 |
|
|---|
| 523 | const char *
|
|---|
| 524 | ip2k_cgen_parse_operand (cd, opindex, strp, fields)
|
|---|
| 525 | CGEN_CPU_DESC cd;
|
|---|
| 526 | int opindex;
|
|---|
| 527 | const char ** strp;
|
|---|
| 528 | CGEN_FIELDS * fields;
|
|---|
| 529 | {
|
|---|
| 530 | const char * errmsg = NULL;
|
|---|
| 531 | /* Used by scalar operands that still need to be parsed. */
|
|---|
| 532 | long junk ATTRIBUTE_UNUSED;
|
|---|
| 533 |
|
|---|
| 534 | switch (opindex)
|
|---|
| 535 | {
|
|---|
| 536 | case IP2K_OPERAND_ADDR16CJP :
|
|---|
| 537 | errmsg = parse_addr16_cjp (cd, strp, IP2K_OPERAND_ADDR16CJP, &fields->f_addr16cjp);
|
|---|
| 538 | break;
|
|---|
| 539 | case IP2K_OPERAND_ADDR16H :
|
|---|
| 540 | errmsg = parse_addr16 (cd, strp, IP2K_OPERAND_ADDR16H, &fields->f_imm8);
|
|---|
| 541 | break;
|
|---|
| 542 | case IP2K_OPERAND_ADDR16L :
|
|---|
| 543 | errmsg = parse_addr16 (cd, strp, IP2K_OPERAND_ADDR16L, &fields->f_imm8);
|
|---|
| 544 | break;
|
|---|
| 545 | case IP2K_OPERAND_ADDR16P :
|
|---|
| 546 | errmsg = parse_addr16_cjp (cd, strp, IP2K_OPERAND_ADDR16P, &fields->f_page3);
|
|---|
| 547 | break;
|
|---|
| 548 | case IP2K_OPERAND_BITNO :
|
|---|
| 549 | errmsg = parse_bit3 (cd, strp, IP2K_OPERAND_BITNO, &fields->f_bitno);
|
|---|
| 550 | break;
|
|---|
| 551 | case IP2K_OPERAND_CBIT :
|
|---|
| 552 | errmsg = cgen_parse_unsigned_integer (cd, strp, IP2K_OPERAND_CBIT, &junk);
|
|---|
| 553 | break;
|
|---|
| 554 | case IP2K_OPERAND_DCBIT :
|
|---|
| 555 | errmsg = cgen_parse_unsigned_integer (cd, strp, IP2K_OPERAND_DCBIT, &junk);
|
|---|
| 556 | break;
|
|---|
| 557 | case IP2K_OPERAND_FR :
|
|---|
| 558 | errmsg = parse_fr (cd, strp, IP2K_OPERAND_FR, &fields->f_reg);
|
|---|
| 559 | break;
|
|---|
| 560 | case IP2K_OPERAND_LIT8 :
|
|---|
| 561 | errmsg = parse_lit8 (cd, strp, IP2K_OPERAND_LIT8, &fields->f_imm8);
|
|---|
| 562 | break;
|
|---|
| 563 | case IP2K_OPERAND_PABITS :
|
|---|
| 564 | errmsg = cgen_parse_unsigned_integer (cd, strp, IP2K_OPERAND_PABITS, &junk);
|
|---|
| 565 | break;
|
|---|
| 566 | case IP2K_OPERAND_RETI3 :
|
|---|
| 567 | errmsg = cgen_parse_unsigned_integer (cd, strp, IP2K_OPERAND_RETI3, &fields->f_reti3);
|
|---|
| 568 | break;
|
|---|
| 569 | case IP2K_OPERAND_ZBIT :
|
|---|
| 570 | errmsg = cgen_parse_unsigned_integer (cd, strp, IP2K_OPERAND_ZBIT, &junk);
|
|---|
| 571 | break;
|
|---|
| 572 |
|
|---|
| 573 | default :
|
|---|
| 574 | /* xgettext:c-format */
|
|---|
| 575 | fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
|
|---|
| 576 | abort ();
|
|---|
| 577 | }
|
|---|
| 578 |
|
|---|
| 579 | return errmsg;
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | cgen_parse_fn * const ip2k_cgen_parse_handlers[] =
|
|---|
| 583 | {
|
|---|
| 584 | parse_insn_normal,
|
|---|
| 585 | };
|
|---|
| 586 |
|
|---|
| 587 | void
|
|---|
| 588 | ip2k_cgen_init_asm (cd)
|
|---|
| 589 | CGEN_CPU_DESC cd;
|
|---|
| 590 | {
|
|---|
| 591 | ip2k_cgen_init_opcode_table (cd);
|
|---|
| 592 | ip2k_cgen_init_ibld_table (cd);
|
|---|
| 593 | cd->parse_handlers = & ip2k_cgen_parse_handlers[0];
|
|---|
| 594 | cd->parse_operand = ip2k_cgen_parse_operand;
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 | |
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 | /* Regex construction routine.
|
|---|
| 601 |
|
|---|
| 602 | This translates an opcode syntax string into a regex string,
|
|---|
| 603 | by replacing any non-character syntax element (such as an
|
|---|
| 604 | opcode) with the pattern '.*'
|
|---|
| 605 |
|
|---|
| 606 | It then compiles the regex and stores it in the opcode, for
|
|---|
| 607 | later use by ip2k_cgen_assemble_insn
|
|---|
| 608 |
|
|---|
| 609 | Returns NULL for success, an error message for failure. */
|
|---|
| 610 |
|
|---|
| 611 | char *
|
|---|
| 612 | ip2k_cgen_build_insn_regex (insn)
|
|---|
| 613 | CGEN_INSN *insn;
|
|---|
| 614 | {
|
|---|
| 615 | CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
|
|---|
| 616 | const char *mnem = CGEN_INSN_MNEMONIC (insn);
|
|---|
| 617 | char rxbuf[CGEN_MAX_RX_ELEMENTS];
|
|---|
| 618 | char *rx = rxbuf;
|
|---|
| 619 | const CGEN_SYNTAX_CHAR_TYPE *syn;
|
|---|
| 620 | int reg_err;
|
|---|
| 621 |
|
|---|
| 622 | syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
|
|---|
| 623 |
|
|---|
| 624 | /* Mnemonics come first in the syntax string. */
|
|---|
| 625 | if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
|
|---|
| 626 | return _("missing mnemonic in syntax string");
|
|---|
| 627 | ++syn;
|
|---|
| 628 |
|
|---|
| 629 | /* Generate a case sensitive regular expression that emulates case
|
|---|
| 630 | insensitive matching in the "C" locale. We cannot generate a case
|
|---|
| 631 | insensitive regular expression because in Turkish locales, 'i' and 'I'
|
|---|
| 632 | are not equal modulo case conversion. */
|
|---|
| 633 |
|
|---|
| 634 | /* Copy the literal mnemonic out of the insn. */
|
|---|
| 635 | for (; *mnem; mnem++)
|
|---|
| 636 | {
|
|---|
| 637 | char c = *mnem;
|
|---|
| 638 |
|
|---|
| 639 | if (ISALPHA (c))
|
|---|
| 640 | {
|
|---|
| 641 | *rx++ = '[';
|
|---|
| 642 | *rx++ = TOLOWER (c);
|
|---|
| 643 | *rx++ = TOUPPER (c);
|
|---|
| 644 | *rx++ = ']';
|
|---|
| 645 | }
|
|---|
| 646 | else
|
|---|
| 647 | *rx++ = c;
|
|---|
| 648 | }
|
|---|
| 649 |
|
|---|
| 650 | /* Copy any remaining literals from the syntax string into the rx. */
|
|---|
| 651 | for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
|
|---|
| 652 | {
|
|---|
| 653 | if (CGEN_SYNTAX_CHAR_P (* syn))
|
|---|
| 654 | {
|
|---|
| 655 | char c = CGEN_SYNTAX_CHAR (* syn);
|
|---|
| 656 |
|
|---|
| 657 | switch (c)
|
|---|
| 658 | {
|
|---|
| 659 | /* Escape any regex metacharacters in the syntax. */
|
|---|
| 660 | case '.': case '[': case '\\':
|
|---|
| 661 | case '*': case '^': case '$':
|
|---|
| 662 |
|
|---|
| 663 | #ifdef CGEN_ESCAPE_EXTENDED_REGEX
|
|---|
| 664 | case '?': case '{': case '}':
|
|---|
| 665 | case '(': case ')': case '*':
|
|---|
| 666 | case '|': case '+': case ']':
|
|---|
| 667 | #endif
|
|---|
| 668 | *rx++ = '\\';
|
|---|
| 669 | *rx++ = c;
|
|---|
| 670 | break;
|
|---|
| 671 |
|
|---|
| 672 | default:
|
|---|
| 673 | if (ISALPHA (c))
|
|---|
| 674 | {
|
|---|
| 675 | *rx++ = '[';
|
|---|
| 676 | *rx++ = TOLOWER (c);
|
|---|
| 677 | *rx++ = TOUPPER (c);
|
|---|
| 678 | *rx++ = ']';
|
|---|
| 679 | }
|
|---|
| 680 | else
|
|---|
| 681 | *rx++ = c;
|
|---|
| 682 | break;
|
|---|
| 683 | }
|
|---|
| 684 | }
|
|---|
| 685 | else
|
|---|
| 686 | {
|
|---|
| 687 | /* Replace non-syntax fields with globs. */
|
|---|
| 688 | *rx++ = '.';
|
|---|
| 689 | *rx++ = '*';
|
|---|
| 690 | }
|
|---|
| 691 | }
|
|---|
| 692 |
|
|---|
| 693 | /* Trailing whitespace ok. */
|
|---|
| 694 | * rx++ = '[';
|
|---|
| 695 | * rx++ = ' ';
|
|---|
| 696 | * rx++ = '\t';
|
|---|
| 697 | * rx++ = ']';
|
|---|
| 698 | * rx++ = '*';
|
|---|
| 699 |
|
|---|
| 700 | /* But anchor it after that. */
|
|---|
| 701 | * rx++ = '$';
|
|---|
| 702 | * rx = '\0';
|
|---|
| 703 |
|
|---|
| 704 | CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
|
|---|
| 705 | reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
|
|---|
| 706 |
|
|---|
| 707 | if (reg_err == 0)
|
|---|
| 708 | return NULL;
|
|---|
| 709 | else
|
|---|
| 710 | {
|
|---|
| 711 | static char msg[80];
|
|---|
| 712 |
|
|---|
| 713 | regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
|
|---|
| 714 | regfree ((regex_t *) CGEN_INSN_RX (insn));
|
|---|
| 715 | free (CGEN_INSN_RX (insn));
|
|---|
| 716 | (CGEN_INSN_RX (insn)) = NULL;
|
|---|
| 717 | return msg;
|
|---|
| 718 | }
|
|---|
| 719 | }
|
|---|
| 720 |
|
|---|
| 721 | |
|---|
| 722 |
|
|---|
| 723 | /* Default insn parser.
|
|---|
| 724 |
|
|---|
| 725 | The syntax string is scanned and operands are parsed and stored in FIELDS.
|
|---|
| 726 | Relocs are queued as we go via other callbacks.
|
|---|
| 727 |
|
|---|
| 728 | ??? Note that this is currently an all-or-nothing parser. If we fail to
|
|---|
| 729 | parse the instruction, we return 0 and the caller will start over from
|
|---|
| 730 | the beginning. Backtracking will be necessary in parsing subexpressions,
|
|---|
| 731 | but that can be handled there. Not handling backtracking here may get
|
|---|
| 732 | expensive in the case of the m68k. Deal with later.
|
|---|
| 733 |
|
|---|
| 734 | Returns NULL for success, an error message for failure. */
|
|---|
| 735 |
|
|---|
| 736 | static const char *
|
|---|
| 737 | parse_insn_normal (cd, insn, strp, fields)
|
|---|
| 738 | CGEN_CPU_DESC cd;
|
|---|
| 739 | const CGEN_INSN *insn;
|
|---|
| 740 | const char **strp;
|
|---|
| 741 | CGEN_FIELDS *fields;
|
|---|
| 742 | {
|
|---|
| 743 | /* ??? Runtime added insns not handled yet. */
|
|---|
| 744 | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
|
|---|
| 745 | const char *str = *strp;
|
|---|
| 746 | const char *errmsg;
|
|---|
| 747 | const char *p;
|
|---|
| 748 | const CGEN_SYNTAX_CHAR_TYPE * syn;
|
|---|
| 749 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 750 | /* FIXME: wip */
|
|---|
| 751 | int past_opcode_p;
|
|---|
| 752 | #endif
|
|---|
| 753 |
|
|---|
| 754 | /* For now we assume the mnemonic is first (there are no leading operands).
|
|---|
| 755 | We can parse it without needing to set up operand parsing.
|
|---|
| 756 | GAS's input scrubber will ensure mnemonics are lowercase, but we may
|
|---|
| 757 | not be called from GAS. */
|
|---|
| 758 | p = CGEN_INSN_MNEMONIC (insn);
|
|---|
| 759 | while (*p && TOLOWER (*p) == TOLOWER (*str))
|
|---|
| 760 | ++p, ++str;
|
|---|
| 761 |
|
|---|
| 762 | if (* p)
|
|---|
| 763 | return _("unrecognized instruction");
|
|---|
| 764 |
|
|---|
| 765 | #ifndef CGEN_MNEMONIC_OPERANDS
|
|---|
| 766 | if (* str && ! ISSPACE (* str))
|
|---|
| 767 | return _("unrecognized instruction");
|
|---|
| 768 | #endif
|
|---|
| 769 |
|
|---|
| 770 | CGEN_INIT_PARSE (cd);
|
|---|
| 771 | cgen_init_parse_operand (cd);
|
|---|
| 772 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 773 | past_opcode_p = 0;
|
|---|
| 774 | #endif
|
|---|
| 775 |
|
|---|
| 776 | /* We don't check for (*str != '\0') here because we want to parse
|
|---|
| 777 | any trailing fake arguments in the syntax string. */
|
|---|
| 778 | syn = CGEN_SYNTAX_STRING (syntax);
|
|---|
| 779 |
|
|---|
| 780 | /* Mnemonics come first for now, ensure valid string. */
|
|---|
| 781 | if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
|
|---|
| 782 | abort ();
|
|---|
| 783 |
|
|---|
| 784 | ++syn;
|
|---|
| 785 |
|
|---|
| 786 | while (* syn != 0)
|
|---|
| 787 | {
|
|---|
| 788 | /* Non operand chars must match exactly. */
|
|---|
| 789 | if (CGEN_SYNTAX_CHAR_P (* syn))
|
|---|
| 790 | {
|
|---|
| 791 | /* FIXME: While we allow for non-GAS callers above, we assume the
|
|---|
| 792 | first char after the mnemonic part is a space. */
|
|---|
| 793 | /* FIXME: We also take inappropriate advantage of the fact that
|
|---|
| 794 | GAS's input scrubber will remove extraneous blanks. */
|
|---|
| 795 | if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
|
|---|
| 796 | {
|
|---|
| 797 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 798 | if (CGEN_SYNTAX_CHAR(* syn) == ' ')
|
|---|
| 799 | past_opcode_p = 1;
|
|---|
| 800 | #endif
|
|---|
| 801 | ++ syn;
|
|---|
| 802 | ++ str;
|
|---|
| 803 | }
|
|---|
| 804 | else if (*str)
|
|---|
| 805 | {
|
|---|
| 806 | /* Syntax char didn't match. Can't be this insn. */
|
|---|
| 807 | static char msg [80];
|
|---|
| 808 |
|
|---|
| 809 | /* xgettext:c-format */
|
|---|
| 810 | sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
|
|---|
| 811 | CGEN_SYNTAX_CHAR(*syn), *str);
|
|---|
| 812 | return msg;
|
|---|
| 813 | }
|
|---|
| 814 | else
|
|---|
| 815 | {
|
|---|
| 816 | /* Ran out of input. */
|
|---|
| 817 | static char msg [80];
|
|---|
| 818 |
|
|---|
| 819 | /* xgettext:c-format */
|
|---|
| 820 | sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
|
|---|
| 821 | CGEN_SYNTAX_CHAR(*syn));
|
|---|
| 822 | return msg;
|
|---|
| 823 | }
|
|---|
| 824 | continue;
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | /* We have an operand of some sort. */
|
|---|
| 828 | errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
|
|---|
| 829 | &str, fields);
|
|---|
| 830 | if (errmsg)
|
|---|
| 831 | return errmsg;
|
|---|
| 832 |
|
|---|
| 833 | /* Done with this operand, continue with next one. */
|
|---|
| 834 | ++ syn;
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 | /* If we're at the end of the syntax string, we're done. */
|
|---|
| 838 | if (* syn == 0)
|
|---|
| 839 | {
|
|---|
| 840 | /* FIXME: For the moment we assume a valid `str' can only contain
|
|---|
| 841 | blanks now. IE: We needn't try again with a longer version of
|
|---|
| 842 | the insn and it is assumed that longer versions of insns appear
|
|---|
| 843 | before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
|
|---|
| 844 | while (ISSPACE (* str))
|
|---|
| 845 | ++ str;
|
|---|
| 846 |
|
|---|
| 847 | if (* str != '\0')
|
|---|
| 848 | return _("junk at end of line"); /* FIXME: would like to include `str' */
|
|---|
| 849 |
|
|---|
| 850 | return NULL;
|
|---|
| 851 | }
|
|---|
| 852 |
|
|---|
| 853 | /* We couldn't parse it. */
|
|---|
| 854 | return _("unrecognized instruction");
|
|---|
| 855 | }
|
|---|
| 856 | |
|---|
| 857 |
|
|---|
| 858 | /* Main entry point.
|
|---|
| 859 | This routine is called for each instruction to be assembled.
|
|---|
| 860 | STR points to the insn to be assembled.
|
|---|
| 861 | We assume all necessary tables have been initialized.
|
|---|
| 862 | The assembled instruction, less any fixups, is stored in BUF.
|
|---|
| 863 | Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
|
|---|
| 864 | still needs to be converted to target byte order, otherwise BUF is an array
|
|---|
| 865 | of bytes in target byte order.
|
|---|
| 866 | The result is a pointer to the insn's entry in the opcode table,
|
|---|
| 867 | or NULL if an error occured (an error message will have already been
|
|---|
| 868 | printed).
|
|---|
| 869 |
|
|---|
| 870 | Note that when processing (non-alias) macro-insns,
|
|---|
| 871 | this function recurses.
|
|---|
| 872 |
|
|---|
| 873 | ??? It's possible to make this cpu-independent.
|
|---|
| 874 | One would have to deal with a few minor things.
|
|---|
| 875 | At this point in time doing so would be more of a curiosity than useful
|
|---|
| 876 | [for example this file isn't _that_ big], but keeping the possibility in
|
|---|
| 877 | mind helps keep the design clean. */
|
|---|
| 878 |
|
|---|
| 879 | const CGEN_INSN *
|
|---|
| 880 | ip2k_cgen_assemble_insn (cd, str, fields, buf, errmsg)
|
|---|
| 881 | CGEN_CPU_DESC cd;
|
|---|
| 882 | const char *str;
|
|---|
| 883 | CGEN_FIELDS *fields;
|
|---|
| 884 | CGEN_INSN_BYTES_PTR buf;
|
|---|
| 885 | char **errmsg;
|
|---|
| 886 | {
|
|---|
| 887 | const char *start;
|
|---|
| 888 | CGEN_INSN_LIST *ilist;
|
|---|
| 889 | const char *parse_errmsg = NULL;
|
|---|
| 890 | const char *insert_errmsg = NULL;
|
|---|
| 891 | int recognized_mnemonic = 0;
|
|---|
| 892 |
|
|---|
| 893 | /* Skip leading white space. */
|
|---|
| 894 | while (ISSPACE (* str))
|
|---|
| 895 | ++ str;
|
|---|
| 896 |
|
|---|
| 897 | /* The instructions are stored in hashed lists.
|
|---|
| 898 | Get the first in the list. */
|
|---|
| 899 | ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
|
|---|
| 900 |
|
|---|
| 901 | /* Keep looking until we find a match. */
|
|---|
| 902 | start = str;
|
|---|
| 903 | for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
|
|---|
| 904 | {
|
|---|
| 905 | const CGEN_INSN *insn = ilist->insn;
|
|---|
| 906 | recognized_mnemonic = 1;
|
|---|
| 907 |
|
|---|
| 908 | #ifdef CGEN_VALIDATE_INSN_SUPPORTED
|
|---|
| 909 | /* Not usually needed as unsupported opcodes
|
|---|
| 910 | shouldn't be in the hash lists. */
|
|---|
| 911 | /* Is this insn supported by the selected cpu? */
|
|---|
| 912 | if (! ip2k_cgen_insn_supported (cd, insn))
|
|---|
| 913 | continue;
|
|---|
| 914 | #endif
|
|---|
| 915 | /* If the RELAX attribute is set, this is an insn that shouldn't be
|
|---|
| 916 | chosen immediately. Instead, it is used during assembler/linker
|
|---|
| 917 | relaxation if possible. */
|
|---|
| 918 | if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAX) != 0)
|
|---|
| 919 | continue;
|
|---|
| 920 |
|
|---|
| 921 | str = start;
|
|---|
| 922 |
|
|---|
| 923 | /* Skip this insn if str doesn't look right lexically. */
|
|---|
| 924 | if (CGEN_INSN_RX (insn) != NULL &&
|
|---|
| 925 | regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
|
|---|
| 926 | continue;
|
|---|
| 927 |
|
|---|
| 928 | /* Allow parse/insert handlers to obtain length of insn. */
|
|---|
| 929 | CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
|
|---|
| 930 |
|
|---|
| 931 | parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
|
|---|
| 932 | if (parse_errmsg != NULL)
|
|---|
| 933 | continue;
|
|---|
| 934 |
|
|---|
| 935 | /* ??? 0 is passed for `pc'. */
|
|---|
| 936 | insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
|
|---|
| 937 | (bfd_vma) 0);
|
|---|
| 938 | if (insert_errmsg != NULL)
|
|---|
| 939 | continue;
|
|---|
| 940 |
|
|---|
| 941 | /* It is up to the caller to actually output the insn and any
|
|---|
| 942 | queued relocs. */
|
|---|
| 943 | return insn;
|
|---|
| 944 | }
|
|---|
| 945 |
|
|---|
| 946 | {
|
|---|
| 947 | static char errbuf[150];
|
|---|
| 948 | #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
|
|---|
| 949 | const char *tmp_errmsg;
|
|---|
| 950 |
|
|---|
| 951 | /* If requesting verbose error messages, use insert_errmsg.
|
|---|
| 952 | Failing that, use parse_errmsg. */
|
|---|
| 953 | tmp_errmsg = (insert_errmsg ? insert_errmsg :
|
|---|
| 954 | parse_errmsg ? parse_errmsg :
|
|---|
| 955 | recognized_mnemonic ?
|
|---|
| 956 | _("unrecognized form of instruction") :
|
|---|
| 957 | _("unrecognized instruction"));
|
|---|
| 958 |
|
|---|
| 959 | if (strlen (start) > 50)
|
|---|
| 960 | /* xgettext:c-format */
|
|---|
| 961 | sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
|
|---|
| 962 | else
|
|---|
| 963 | /* xgettext:c-format */
|
|---|
| 964 | sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
|
|---|
| 965 | #else
|
|---|
| 966 | if (strlen (start) > 50)
|
|---|
| 967 | /* xgettext:c-format */
|
|---|
| 968 | sprintf (errbuf, _("bad instruction `%.50s...'"), start);
|
|---|
| 969 | else
|
|---|
| 970 | /* xgettext:c-format */
|
|---|
| 971 | sprintf (errbuf, _("bad instruction `%.50s'"), start);
|
|---|
| 972 | #endif
|
|---|
| 973 |
|
|---|
| 974 | *errmsg = errbuf;
|
|---|
| 975 | return NULL;
|
|---|
| 976 | }
|
|---|
| 977 | }
|
|---|
| 978 | |
|---|
| 979 |
|
|---|
| 980 | #if 0 /* This calls back to GAS which we can't do without care. */
|
|---|
| 981 |
|
|---|
| 982 | /* Record each member of OPVALS in the assembler's symbol table.
|
|---|
| 983 | This lets GAS parse registers for us.
|
|---|
| 984 | ??? Interesting idea but not currently used. */
|
|---|
| 985 |
|
|---|
| 986 | /* Record each member of OPVALS in the assembler's symbol table.
|
|---|
| 987 | FIXME: Not currently used. */
|
|---|
| 988 |
|
|---|
| 989 | void
|
|---|
| 990 | ip2k_cgen_asm_hash_keywords (cd, opvals)
|
|---|
| 991 | CGEN_CPU_DESC cd;
|
|---|
| 992 | CGEN_KEYWORD *opvals;
|
|---|
| 993 | {
|
|---|
| 994 | CGEN_KEYWORD_SEARCH search = cgen_keyword_search_init (opvals, NULL);
|
|---|
| 995 | const CGEN_KEYWORD_ENTRY * ke;
|
|---|
| 996 |
|
|---|
| 997 | while ((ke = cgen_keyword_search_next (& search)) != NULL)
|
|---|
| 998 | {
|
|---|
| 999 | #if 0 /* Unnecessary, should be done in the search routine. */
|
|---|
| 1000 | if (! ip2k_cgen_opval_supported (ke))
|
|---|
| 1001 | continue;
|
|---|
| 1002 | #endif
|
|---|
| 1003 | cgen_asm_record_register (cd, ke->name, ke->value);
|
|---|
| 1004 | }
|
|---|
| 1005 | }
|
|---|
| 1006 |
|
|---|
| 1007 | #endif /* 0 */
|
|---|