| 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 "fr30-desc.h"
|
|---|
| 34 | #include "fr30-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 | /* Handle register lists for LDMx and STMx. */
|
|---|
| 53 |
|
|---|
| 54 | static int parse_register_number
|
|---|
| 55 | PARAMS ((const char **));
|
|---|
| 56 | static const char * parse_register_list
|
|---|
| 57 | PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *, int, int));
|
|---|
| 58 | static const char * parse_low_register_list_ld
|
|---|
| 59 | PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
|
|---|
| 60 | static const char * parse_hi_register_list_ld
|
|---|
| 61 | PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
|
|---|
| 62 | static const char * parse_low_register_list_st
|
|---|
| 63 | PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
|
|---|
| 64 | static const char * parse_hi_register_list_st
|
|---|
| 65 | PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
|
|---|
| 66 |
|
|---|
| 67 | static int
|
|---|
| 68 | parse_register_number (strp)
|
|---|
| 69 | const char **strp;
|
|---|
| 70 | {
|
|---|
| 71 | int regno;
|
|---|
| 72 | if (**strp < '0' || **strp > '9')
|
|---|
| 73 | return -1; /* error. */
|
|---|
| 74 | regno = **strp - '0';
|
|---|
| 75 | ++*strp;
|
|---|
| 76 |
|
|---|
| 77 | if (**strp >= '0' && **strp <= '9')
|
|---|
| 78 | {
|
|---|
| 79 | regno = regno * 10 + (**strp - '0');
|
|---|
| 80 | ++*strp;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | return regno;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | static const char *
|
|---|
| 87 | parse_register_list (cd, strp, opindex, valuep, high_low, load_store)
|
|---|
| 88 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
|---|
| 89 | const char **strp;
|
|---|
| 90 | int opindex ATTRIBUTE_UNUSED;
|
|---|
| 91 | unsigned long *valuep;
|
|---|
| 92 | int high_low; /* 0 == high, 1 == low */
|
|---|
| 93 | int load_store; /* 0 == load, 1 == store */
|
|---|
| 94 | {
|
|---|
| 95 | int regno;
|
|---|
| 96 |
|
|---|
| 97 | *valuep = 0;
|
|---|
| 98 | while (**strp && **strp != ')')
|
|---|
| 99 | {
|
|---|
| 100 | if (**strp != 'R' && **strp != 'r')
|
|---|
| 101 | break;
|
|---|
| 102 | ++*strp;
|
|---|
| 103 |
|
|---|
| 104 | regno = parse_register_number (strp);
|
|---|
| 105 | if (regno == -1)
|
|---|
| 106 | return "Register number is not valid";
|
|---|
| 107 | if (regno > 7 && !high_low)
|
|---|
| 108 | return "Register must be between r0 and r7";
|
|---|
| 109 | if (regno < 8 && high_low)
|
|---|
| 110 | return "Register must be between r8 and r15";
|
|---|
| 111 |
|
|---|
| 112 | if (high_low)
|
|---|
| 113 | regno -= 8;
|
|---|
| 114 |
|
|---|
| 115 | if (load_store) /* Mask is reversed for store. */
|
|---|
| 116 | *valuep |= 0x80 >> regno;
|
|---|
| 117 | else
|
|---|
| 118 | *valuep |= 1 << regno;
|
|---|
| 119 |
|
|---|
| 120 | if (**strp == ',')
|
|---|
| 121 | {
|
|---|
| 122 | if (*(*strp + 1) == ')')
|
|---|
| 123 | break;
|
|---|
| 124 | ++*strp;
|
|---|
| 125 | }
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | if (!*strp || **strp != ')')
|
|---|
| 129 | return "Register list is not valid";
|
|---|
| 130 |
|
|---|
| 131 | return NULL;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | static const char *
|
|---|
| 135 | parse_low_register_list_ld (cd, strp, opindex, valuep)
|
|---|
| 136 | CGEN_CPU_DESC cd;
|
|---|
| 137 | const char **strp;
|
|---|
| 138 | int opindex;
|
|---|
| 139 | unsigned long *valuep;
|
|---|
| 140 | {
|
|---|
| 141 | return parse_register_list (cd, strp, opindex, valuep, 0/*low*/, 0/*load*/);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | static const char *
|
|---|
| 145 | parse_hi_register_list_ld (cd, strp, opindex, valuep)
|
|---|
| 146 | CGEN_CPU_DESC cd;
|
|---|
| 147 | const char **strp;
|
|---|
| 148 | int opindex;
|
|---|
| 149 | unsigned long *valuep;
|
|---|
| 150 | {
|
|---|
| 151 | return parse_register_list (cd, strp, opindex, valuep, 1/*high*/, 0/*load*/);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | static const char *
|
|---|
| 155 | parse_low_register_list_st (cd, strp, opindex, valuep)
|
|---|
| 156 | CGEN_CPU_DESC cd;
|
|---|
| 157 | const char **strp;
|
|---|
| 158 | int opindex;
|
|---|
| 159 | unsigned long *valuep;
|
|---|
| 160 | {
|
|---|
| 161 | return parse_register_list (cd, strp, opindex, valuep, 0/*low*/, 1/*store*/);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | static const char *
|
|---|
| 165 | parse_hi_register_list_st (cd, strp, opindex, valuep)
|
|---|
| 166 | CGEN_CPU_DESC cd;
|
|---|
| 167 | const char **strp;
|
|---|
| 168 | int opindex;
|
|---|
| 169 | unsigned long *valuep;
|
|---|
| 170 | {
|
|---|
| 171 | return parse_register_list (cd, strp, opindex, valuep, 1/*high*/, 1/*store*/);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | /* -- */
|
|---|
| 175 |
|
|---|
| 176 | const char * fr30_cgen_parse_operand
|
|---|
| 177 | PARAMS ((CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *));
|
|---|
| 178 |
|
|---|
| 179 | /* Main entry point for operand parsing.
|
|---|
| 180 |
|
|---|
| 181 | This function is basically just a big switch statement. Earlier versions
|
|---|
| 182 | used tables to look up the function to use, but
|
|---|
| 183 | - if the table contains both assembler and disassembler functions then
|
|---|
| 184 | the disassembler contains much of the assembler and vice-versa,
|
|---|
| 185 | - there's a lot of inlining possibilities as things grow,
|
|---|
| 186 | - using a switch statement avoids the function call overhead.
|
|---|
| 187 |
|
|---|
| 188 | This function could be moved into `parse_insn_normal', but keeping it
|
|---|
| 189 | separate makes clear the interface between `parse_insn_normal' and each of
|
|---|
| 190 | the handlers. */
|
|---|
| 191 |
|
|---|
| 192 | const char *
|
|---|
| 193 | fr30_cgen_parse_operand (cd, opindex, strp, fields)
|
|---|
| 194 | CGEN_CPU_DESC cd;
|
|---|
| 195 | int opindex;
|
|---|
| 196 | const char ** strp;
|
|---|
| 197 | CGEN_FIELDS * fields;
|
|---|
| 198 | {
|
|---|
| 199 | const char * errmsg = NULL;
|
|---|
| 200 | /* Used by scalar operands that still need to be parsed. */
|
|---|
| 201 | long junk ATTRIBUTE_UNUSED;
|
|---|
| 202 |
|
|---|
| 203 | switch (opindex)
|
|---|
| 204 | {
|
|---|
| 205 | case FR30_OPERAND_CRI :
|
|---|
| 206 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_cr_names, & fields->f_CRi);
|
|---|
| 207 | break;
|
|---|
| 208 | case FR30_OPERAND_CRJ :
|
|---|
| 209 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_cr_names, & fields->f_CRj);
|
|---|
| 210 | break;
|
|---|
| 211 | case FR30_OPERAND_R13 :
|
|---|
| 212 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r13, & junk);
|
|---|
| 213 | break;
|
|---|
| 214 | case FR30_OPERAND_R14 :
|
|---|
| 215 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r14, & junk);
|
|---|
| 216 | break;
|
|---|
| 217 | case FR30_OPERAND_R15 :
|
|---|
| 218 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r15, & junk);
|
|---|
| 219 | break;
|
|---|
| 220 | case FR30_OPERAND_RI :
|
|---|
| 221 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Ri);
|
|---|
| 222 | break;
|
|---|
| 223 | case FR30_OPERAND_RIC :
|
|---|
| 224 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Ric);
|
|---|
| 225 | break;
|
|---|
| 226 | case FR30_OPERAND_RJ :
|
|---|
| 227 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Rj);
|
|---|
| 228 | break;
|
|---|
| 229 | case FR30_OPERAND_RJC :
|
|---|
| 230 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Rjc);
|
|---|
| 231 | break;
|
|---|
| 232 | case FR30_OPERAND_RS1 :
|
|---|
| 233 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_dr_names, & fields->f_Rs1);
|
|---|
| 234 | break;
|
|---|
| 235 | case FR30_OPERAND_RS2 :
|
|---|
| 236 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_dr_names, & fields->f_Rs2);
|
|---|
| 237 | break;
|
|---|
| 238 | case FR30_OPERAND_CC :
|
|---|
| 239 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_CC, &fields->f_cc);
|
|---|
| 240 | break;
|
|---|
| 241 | case FR30_OPERAND_CCC :
|
|---|
| 242 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_CCC, &fields->f_ccc);
|
|---|
| 243 | break;
|
|---|
| 244 | case FR30_OPERAND_DIR10 :
|
|---|
| 245 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR10, &fields->f_dir10);
|
|---|
| 246 | break;
|
|---|
| 247 | case FR30_OPERAND_DIR8 :
|
|---|
| 248 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR8, &fields->f_dir8);
|
|---|
| 249 | break;
|
|---|
| 250 | case FR30_OPERAND_DIR9 :
|
|---|
| 251 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR9, &fields->f_dir9);
|
|---|
| 252 | break;
|
|---|
| 253 | case FR30_OPERAND_DISP10 :
|
|---|
| 254 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP10, &fields->f_disp10);
|
|---|
| 255 | break;
|
|---|
| 256 | case FR30_OPERAND_DISP8 :
|
|---|
| 257 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP8, &fields->f_disp8);
|
|---|
| 258 | break;
|
|---|
| 259 | case FR30_OPERAND_DISP9 :
|
|---|
| 260 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP9, &fields->f_disp9);
|
|---|
| 261 | break;
|
|---|
| 262 | case FR30_OPERAND_I20 :
|
|---|
| 263 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I20, &fields->f_i20);
|
|---|
| 264 | break;
|
|---|
| 265 | case FR30_OPERAND_I32 :
|
|---|
| 266 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I32, &fields->f_i32);
|
|---|
| 267 | break;
|
|---|
| 268 | case FR30_OPERAND_I8 :
|
|---|
| 269 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I8, &fields->f_i8);
|
|---|
| 270 | break;
|
|---|
| 271 | case FR30_OPERAND_LABEL12 :
|
|---|
| 272 | {
|
|---|
| 273 | bfd_vma value;
|
|---|
| 274 | errmsg = cgen_parse_address (cd, strp, FR30_OPERAND_LABEL12, 0, NULL, & value);
|
|---|
| 275 | fields->f_rel12 = value;
|
|---|
| 276 | }
|
|---|
| 277 | break;
|
|---|
| 278 | case FR30_OPERAND_LABEL9 :
|
|---|
| 279 | {
|
|---|
| 280 | bfd_vma value;
|
|---|
| 281 | errmsg = cgen_parse_address (cd, strp, FR30_OPERAND_LABEL9, 0, NULL, & value);
|
|---|
| 282 | fields->f_rel9 = value;
|
|---|
| 283 | }
|
|---|
| 284 | break;
|
|---|
| 285 | case FR30_OPERAND_M4 :
|
|---|
| 286 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_M4, &fields->f_m4);
|
|---|
| 287 | break;
|
|---|
| 288 | case FR30_OPERAND_PS :
|
|---|
| 289 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_ps, & junk);
|
|---|
| 290 | break;
|
|---|
| 291 | case FR30_OPERAND_REGLIST_HI_LD :
|
|---|
| 292 | errmsg = parse_hi_register_list_ld (cd, strp, FR30_OPERAND_REGLIST_HI_LD, &fields->f_reglist_hi_ld);
|
|---|
| 293 | break;
|
|---|
| 294 | case FR30_OPERAND_REGLIST_HI_ST :
|
|---|
| 295 | errmsg = parse_hi_register_list_st (cd, strp, FR30_OPERAND_REGLIST_HI_ST, &fields->f_reglist_hi_st);
|
|---|
| 296 | break;
|
|---|
| 297 | case FR30_OPERAND_REGLIST_LOW_LD :
|
|---|
| 298 | errmsg = parse_low_register_list_ld (cd, strp, FR30_OPERAND_REGLIST_LOW_LD, &fields->f_reglist_low_ld);
|
|---|
| 299 | break;
|
|---|
| 300 | case FR30_OPERAND_REGLIST_LOW_ST :
|
|---|
| 301 | errmsg = parse_low_register_list_st (cd, strp, FR30_OPERAND_REGLIST_LOW_ST, &fields->f_reglist_low_st);
|
|---|
| 302 | break;
|
|---|
| 303 | case FR30_OPERAND_S10 :
|
|---|
| 304 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_S10, &fields->f_s10);
|
|---|
| 305 | break;
|
|---|
| 306 | case FR30_OPERAND_U10 :
|
|---|
| 307 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U10, &fields->f_u10);
|
|---|
| 308 | break;
|
|---|
| 309 | case FR30_OPERAND_U4 :
|
|---|
| 310 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U4, &fields->f_u4);
|
|---|
| 311 | break;
|
|---|
| 312 | case FR30_OPERAND_U4C :
|
|---|
| 313 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U4C, &fields->f_u4c);
|
|---|
| 314 | break;
|
|---|
| 315 | case FR30_OPERAND_U8 :
|
|---|
| 316 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U8, &fields->f_u8);
|
|---|
| 317 | break;
|
|---|
| 318 | case FR30_OPERAND_UDISP6 :
|
|---|
| 319 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_UDISP6, &fields->f_udisp6);
|
|---|
| 320 | break;
|
|---|
| 321 |
|
|---|
| 322 | default :
|
|---|
| 323 | /* xgettext:c-format */
|
|---|
| 324 | fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
|
|---|
| 325 | abort ();
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | return errmsg;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | cgen_parse_fn * const fr30_cgen_parse_handlers[] =
|
|---|
| 332 | {
|
|---|
| 333 | parse_insn_normal,
|
|---|
| 334 | };
|
|---|
| 335 |
|
|---|
| 336 | void
|
|---|
| 337 | fr30_cgen_init_asm (cd)
|
|---|
| 338 | CGEN_CPU_DESC cd;
|
|---|
| 339 | {
|
|---|
| 340 | fr30_cgen_init_opcode_table (cd);
|
|---|
| 341 | fr30_cgen_init_ibld_table (cd);
|
|---|
| 342 | cd->parse_handlers = & fr30_cgen_parse_handlers[0];
|
|---|
| 343 | cd->parse_operand = fr30_cgen_parse_operand;
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 | /* Regex construction routine.
|
|---|
| 350 |
|
|---|
| 351 | This translates an opcode syntax string into a regex string,
|
|---|
| 352 | by replacing any non-character syntax element (such as an
|
|---|
| 353 | opcode) with the pattern '.*'
|
|---|
| 354 |
|
|---|
| 355 | It then compiles the regex and stores it in the opcode, for
|
|---|
| 356 | later use by fr30_cgen_assemble_insn
|
|---|
| 357 |
|
|---|
| 358 | Returns NULL for success, an error message for failure. */
|
|---|
| 359 |
|
|---|
| 360 | char *
|
|---|
| 361 | fr30_cgen_build_insn_regex (insn)
|
|---|
| 362 | CGEN_INSN *insn;
|
|---|
| 363 | {
|
|---|
| 364 | CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
|
|---|
| 365 | const char *mnem = CGEN_INSN_MNEMONIC (insn);
|
|---|
| 366 | char rxbuf[CGEN_MAX_RX_ELEMENTS];
|
|---|
| 367 | char *rx = rxbuf;
|
|---|
| 368 | const CGEN_SYNTAX_CHAR_TYPE *syn;
|
|---|
| 369 | int reg_err;
|
|---|
| 370 |
|
|---|
| 371 | syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
|
|---|
| 372 |
|
|---|
| 373 | /* Mnemonics come first in the syntax string. */
|
|---|
| 374 | if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
|
|---|
| 375 | return _("missing mnemonic in syntax string");
|
|---|
| 376 | ++syn;
|
|---|
| 377 |
|
|---|
| 378 | /* Generate a case sensitive regular expression that emulates case
|
|---|
| 379 | insensitive matching in the "C" locale. We cannot generate a case
|
|---|
| 380 | insensitive regular expression because in Turkish locales, 'i' and 'I'
|
|---|
| 381 | are not equal modulo case conversion. */
|
|---|
| 382 |
|
|---|
| 383 | /* Copy the literal mnemonic out of the insn. */
|
|---|
| 384 | for (; *mnem; mnem++)
|
|---|
| 385 | {
|
|---|
| 386 | char c = *mnem;
|
|---|
| 387 |
|
|---|
| 388 | if (ISALPHA (c))
|
|---|
| 389 | {
|
|---|
| 390 | *rx++ = '[';
|
|---|
| 391 | *rx++ = TOLOWER (c);
|
|---|
| 392 | *rx++ = TOUPPER (c);
|
|---|
| 393 | *rx++ = ']';
|
|---|
| 394 | }
|
|---|
| 395 | else
|
|---|
| 396 | *rx++ = c;
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | /* Copy any remaining literals from the syntax string into the rx. */
|
|---|
| 400 | for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
|
|---|
| 401 | {
|
|---|
| 402 | if (CGEN_SYNTAX_CHAR_P (* syn))
|
|---|
| 403 | {
|
|---|
| 404 | char c = CGEN_SYNTAX_CHAR (* syn);
|
|---|
| 405 |
|
|---|
| 406 | switch (c)
|
|---|
| 407 | {
|
|---|
| 408 | /* Escape any regex metacharacters in the syntax. */
|
|---|
| 409 | case '.': case '[': case '\\':
|
|---|
| 410 | case '*': case '^': case '$':
|
|---|
| 411 |
|
|---|
| 412 | #ifdef CGEN_ESCAPE_EXTENDED_REGEX
|
|---|
| 413 | case '?': case '{': case '}':
|
|---|
| 414 | case '(': case ')': case '*':
|
|---|
| 415 | case '|': case '+': case ']':
|
|---|
| 416 | #endif
|
|---|
| 417 | *rx++ = '\\';
|
|---|
| 418 | *rx++ = c;
|
|---|
| 419 | break;
|
|---|
| 420 |
|
|---|
| 421 | default:
|
|---|
| 422 | if (ISALPHA (c))
|
|---|
| 423 | {
|
|---|
| 424 | *rx++ = '[';
|
|---|
| 425 | *rx++ = TOLOWER (c);
|
|---|
| 426 | *rx++ = TOUPPER (c);
|
|---|
| 427 | *rx++ = ']';
|
|---|
| 428 | }
|
|---|
| 429 | else
|
|---|
| 430 | *rx++ = c;
|
|---|
| 431 | break;
|
|---|
| 432 | }
|
|---|
| 433 | }
|
|---|
| 434 | else
|
|---|
| 435 | {
|
|---|
| 436 | /* Replace non-syntax fields with globs. */
|
|---|
| 437 | *rx++ = '.';
|
|---|
| 438 | *rx++ = '*';
|
|---|
| 439 | }
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | /* Trailing whitespace ok. */
|
|---|
| 443 | * rx++ = '[';
|
|---|
| 444 | * rx++ = ' ';
|
|---|
| 445 | * rx++ = '\t';
|
|---|
| 446 | * rx++ = ']';
|
|---|
| 447 | * rx++ = '*';
|
|---|
| 448 |
|
|---|
| 449 | /* But anchor it after that. */
|
|---|
| 450 | * rx++ = '$';
|
|---|
| 451 | * rx = '\0';
|
|---|
| 452 |
|
|---|
| 453 | CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
|
|---|
| 454 | reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
|
|---|
| 455 |
|
|---|
| 456 | if (reg_err == 0)
|
|---|
| 457 | return NULL;
|
|---|
| 458 | else
|
|---|
| 459 | {
|
|---|
| 460 | static char msg[80];
|
|---|
| 461 |
|
|---|
| 462 | regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
|
|---|
| 463 | regfree ((regex_t *) CGEN_INSN_RX (insn));
|
|---|
| 464 | free (CGEN_INSN_RX (insn));
|
|---|
| 465 | (CGEN_INSN_RX (insn)) = NULL;
|
|---|
| 466 | return msg;
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | |
|---|
| 471 |
|
|---|
| 472 | /* Default insn parser.
|
|---|
| 473 |
|
|---|
| 474 | The syntax string is scanned and operands are parsed and stored in FIELDS.
|
|---|
| 475 | Relocs are queued as we go via other callbacks.
|
|---|
| 476 |
|
|---|
| 477 | ??? Note that this is currently an all-or-nothing parser. If we fail to
|
|---|
| 478 | parse the instruction, we return 0 and the caller will start over from
|
|---|
| 479 | the beginning. Backtracking will be necessary in parsing subexpressions,
|
|---|
| 480 | but that can be handled there. Not handling backtracking here may get
|
|---|
| 481 | expensive in the case of the m68k. Deal with later.
|
|---|
| 482 |
|
|---|
| 483 | Returns NULL for success, an error message for failure. */
|
|---|
| 484 |
|
|---|
| 485 | static const char *
|
|---|
| 486 | parse_insn_normal (cd, insn, strp, fields)
|
|---|
| 487 | CGEN_CPU_DESC cd;
|
|---|
| 488 | const CGEN_INSN *insn;
|
|---|
| 489 | const char **strp;
|
|---|
| 490 | CGEN_FIELDS *fields;
|
|---|
| 491 | {
|
|---|
| 492 | /* ??? Runtime added insns not handled yet. */
|
|---|
| 493 | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
|
|---|
| 494 | const char *str = *strp;
|
|---|
| 495 | const char *errmsg;
|
|---|
| 496 | const char *p;
|
|---|
| 497 | const CGEN_SYNTAX_CHAR_TYPE * syn;
|
|---|
| 498 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 499 | /* FIXME: wip */
|
|---|
| 500 | int past_opcode_p;
|
|---|
| 501 | #endif
|
|---|
| 502 |
|
|---|
| 503 | /* For now we assume the mnemonic is first (there are no leading operands).
|
|---|
| 504 | We can parse it without needing to set up operand parsing.
|
|---|
| 505 | GAS's input scrubber will ensure mnemonics are lowercase, but we may
|
|---|
| 506 | not be called from GAS. */
|
|---|
| 507 | p = CGEN_INSN_MNEMONIC (insn);
|
|---|
| 508 | while (*p && TOLOWER (*p) == TOLOWER (*str))
|
|---|
| 509 | ++p, ++str;
|
|---|
| 510 |
|
|---|
| 511 | if (* p)
|
|---|
| 512 | return _("unrecognized instruction");
|
|---|
| 513 |
|
|---|
| 514 | #ifndef CGEN_MNEMONIC_OPERANDS
|
|---|
| 515 | if (* str && ! ISSPACE (* str))
|
|---|
| 516 | return _("unrecognized instruction");
|
|---|
| 517 | #endif
|
|---|
| 518 |
|
|---|
| 519 | CGEN_INIT_PARSE (cd);
|
|---|
| 520 | cgen_init_parse_operand (cd);
|
|---|
| 521 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 522 | past_opcode_p = 0;
|
|---|
| 523 | #endif
|
|---|
| 524 |
|
|---|
| 525 | /* We don't check for (*str != '\0') here because we want to parse
|
|---|
| 526 | any trailing fake arguments in the syntax string. */
|
|---|
| 527 | syn = CGEN_SYNTAX_STRING (syntax);
|
|---|
| 528 |
|
|---|
| 529 | /* Mnemonics come first for now, ensure valid string. */
|
|---|
| 530 | if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
|
|---|
| 531 | abort ();
|
|---|
| 532 |
|
|---|
| 533 | ++syn;
|
|---|
| 534 |
|
|---|
| 535 | while (* syn != 0)
|
|---|
| 536 | {
|
|---|
| 537 | /* Non operand chars must match exactly. */
|
|---|
| 538 | if (CGEN_SYNTAX_CHAR_P (* syn))
|
|---|
| 539 | {
|
|---|
| 540 | /* FIXME: While we allow for non-GAS callers above, we assume the
|
|---|
| 541 | first char after the mnemonic part is a space. */
|
|---|
| 542 | /* FIXME: We also take inappropriate advantage of the fact that
|
|---|
| 543 | GAS's input scrubber will remove extraneous blanks. */
|
|---|
| 544 | if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
|
|---|
| 545 | {
|
|---|
| 546 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 547 | if (CGEN_SYNTAX_CHAR(* syn) == ' ')
|
|---|
| 548 | past_opcode_p = 1;
|
|---|
| 549 | #endif
|
|---|
| 550 | ++ syn;
|
|---|
| 551 | ++ str;
|
|---|
| 552 | }
|
|---|
| 553 | else if (*str)
|
|---|
| 554 | {
|
|---|
| 555 | /* Syntax char didn't match. Can't be this insn. */
|
|---|
| 556 | static char msg [80];
|
|---|
| 557 |
|
|---|
| 558 | /* xgettext:c-format */
|
|---|
| 559 | sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
|
|---|
| 560 | CGEN_SYNTAX_CHAR(*syn), *str);
|
|---|
| 561 | return msg;
|
|---|
| 562 | }
|
|---|
| 563 | else
|
|---|
| 564 | {
|
|---|
| 565 | /* Ran out of input. */
|
|---|
| 566 | static char msg [80];
|
|---|
| 567 |
|
|---|
| 568 | /* xgettext:c-format */
|
|---|
| 569 | sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
|
|---|
| 570 | CGEN_SYNTAX_CHAR(*syn));
|
|---|
| 571 | return msg;
|
|---|
| 572 | }
|
|---|
| 573 | continue;
|
|---|
| 574 | }
|
|---|
| 575 |
|
|---|
| 576 | /* We have an operand of some sort. */
|
|---|
| 577 | errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
|
|---|
| 578 | &str, fields);
|
|---|
| 579 | if (errmsg)
|
|---|
| 580 | return errmsg;
|
|---|
| 581 |
|
|---|
| 582 | /* Done with this operand, continue with next one. */
|
|---|
| 583 | ++ syn;
|
|---|
| 584 | }
|
|---|
| 585 |
|
|---|
| 586 | /* If we're at the end of the syntax string, we're done. */
|
|---|
| 587 | if (* syn == 0)
|
|---|
| 588 | {
|
|---|
| 589 | /* FIXME: For the moment we assume a valid `str' can only contain
|
|---|
| 590 | blanks now. IE: We needn't try again with a longer version of
|
|---|
| 591 | the insn and it is assumed that longer versions of insns appear
|
|---|
| 592 | before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
|
|---|
| 593 | while (ISSPACE (* str))
|
|---|
| 594 | ++ str;
|
|---|
| 595 |
|
|---|
| 596 | if (* str != '\0')
|
|---|
| 597 | return _("junk at end of line"); /* FIXME: would like to include `str' */
|
|---|
| 598 |
|
|---|
| 599 | return NULL;
|
|---|
| 600 | }
|
|---|
| 601 |
|
|---|
| 602 | /* We couldn't parse it. */
|
|---|
| 603 | return _("unrecognized instruction");
|
|---|
| 604 | }
|
|---|
| 605 | |
|---|
| 606 |
|
|---|
| 607 | /* Main entry point.
|
|---|
| 608 | This routine is called for each instruction to be assembled.
|
|---|
| 609 | STR points to the insn to be assembled.
|
|---|
| 610 | We assume all necessary tables have been initialized.
|
|---|
| 611 | The assembled instruction, less any fixups, is stored in BUF.
|
|---|
| 612 | Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
|
|---|
| 613 | still needs to be converted to target byte order, otherwise BUF is an array
|
|---|
| 614 | of bytes in target byte order.
|
|---|
| 615 | The result is a pointer to the insn's entry in the opcode table,
|
|---|
| 616 | or NULL if an error occured (an error message will have already been
|
|---|
| 617 | printed).
|
|---|
| 618 |
|
|---|
| 619 | Note that when processing (non-alias) macro-insns,
|
|---|
| 620 | this function recurses.
|
|---|
| 621 |
|
|---|
| 622 | ??? It's possible to make this cpu-independent.
|
|---|
| 623 | One would have to deal with a few minor things.
|
|---|
| 624 | At this point in time doing so would be more of a curiosity than useful
|
|---|
| 625 | [for example this file isn't _that_ big], but keeping the possibility in
|
|---|
| 626 | mind helps keep the design clean. */
|
|---|
| 627 |
|
|---|
| 628 | const CGEN_INSN *
|
|---|
| 629 | fr30_cgen_assemble_insn (cd, str, fields, buf, errmsg)
|
|---|
| 630 | CGEN_CPU_DESC cd;
|
|---|
| 631 | const char *str;
|
|---|
| 632 | CGEN_FIELDS *fields;
|
|---|
| 633 | CGEN_INSN_BYTES_PTR buf;
|
|---|
| 634 | char **errmsg;
|
|---|
| 635 | {
|
|---|
| 636 | const char *start;
|
|---|
| 637 | CGEN_INSN_LIST *ilist;
|
|---|
| 638 | const char *parse_errmsg = NULL;
|
|---|
| 639 | const char *insert_errmsg = NULL;
|
|---|
| 640 | int recognized_mnemonic = 0;
|
|---|
| 641 |
|
|---|
| 642 | /* Skip leading white space. */
|
|---|
| 643 | while (ISSPACE (* str))
|
|---|
| 644 | ++ str;
|
|---|
| 645 |
|
|---|
| 646 | /* The instructions are stored in hashed lists.
|
|---|
| 647 | Get the first in the list. */
|
|---|
| 648 | ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
|
|---|
| 649 |
|
|---|
| 650 | /* Keep looking until we find a match. */
|
|---|
| 651 | start = str;
|
|---|
| 652 | for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
|
|---|
| 653 | {
|
|---|
| 654 | const CGEN_INSN *insn = ilist->insn;
|
|---|
| 655 | recognized_mnemonic = 1;
|
|---|
| 656 |
|
|---|
| 657 | #ifdef CGEN_VALIDATE_INSN_SUPPORTED
|
|---|
| 658 | /* Not usually needed as unsupported opcodes
|
|---|
| 659 | shouldn't be in the hash lists. */
|
|---|
| 660 | /* Is this insn supported by the selected cpu? */
|
|---|
| 661 | if (! fr30_cgen_insn_supported (cd, insn))
|
|---|
| 662 | continue;
|
|---|
| 663 | #endif
|
|---|
| 664 | /* If the RELAX attribute is set, this is an insn that shouldn't be
|
|---|
| 665 | chosen immediately. Instead, it is used during assembler/linker
|
|---|
| 666 | relaxation if possible. */
|
|---|
| 667 | if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAX) != 0)
|
|---|
| 668 | continue;
|
|---|
| 669 |
|
|---|
| 670 | str = start;
|
|---|
| 671 |
|
|---|
| 672 | /* Skip this insn if str doesn't look right lexically. */
|
|---|
| 673 | if (CGEN_INSN_RX (insn) != NULL &&
|
|---|
| 674 | regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
|
|---|
| 675 | continue;
|
|---|
| 676 |
|
|---|
| 677 | /* Allow parse/insert handlers to obtain length of insn. */
|
|---|
| 678 | CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
|
|---|
| 679 |
|
|---|
| 680 | parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
|
|---|
| 681 | if (parse_errmsg != NULL)
|
|---|
| 682 | continue;
|
|---|
| 683 |
|
|---|
| 684 | /* ??? 0 is passed for `pc'. */
|
|---|
| 685 | insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
|
|---|
| 686 | (bfd_vma) 0);
|
|---|
| 687 | if (insert_errmsg != NULL)
|
|---|
| 688 | continue;
|
|---|
| 689 |
|
|---|
| 690 | /* It is up to the caller to actually output the insn and any
|
|---|
| 691 | queued relocs. */
|
|---|
| 692 | return insn;
|
|---|
| 693 | }
|
|---|
| 694 |
|
|---|
| 695 | {
|
|---|
| 696 | static char errbuf[150];
|
|---|
| 697 | #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
|
|---|
| 698 | const char *tmp_errmsg;
|
|---|
| 699 |
|
|---|
| 700 | /* If requesting verbose error messages, use insert_errmsg.
|
|---|
| 701 | Failing that, use parse_errmsg. */
|
|---|
| 702 | tmp_errmsg = (insert_errmsg ? insert_errmsg :
|
|---|
| 703 | parse_errmsg ? parse_errmsg :
|
|---|
| 704 | recognized_mnemonic ?
|
|---|
| 705 | _("unrecognized form of instruction") :
|
|---|
| 706 | _("unrecognized instruction"));
|
|---|
| 707 |
|
|---|
| 708 | if (strlen (start) > 50)
|
|---|
| 709 | /* xgettext:c-format */
|
|---|
| 710 | sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
|
|---|
| 711 | else
|
|---|
| 712 | /* xgettext:c-format */
|
|---|
| 713 | sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
|
|---|
| 714 | #else
|
|---|
| 715 | if (strlen (start) > 50)
|
|---|
| 716 | /* xgettext:c-format */
|
|---|
| 717 | sprintf (errbuf, _("bad instruction `%.50s...'"), start);
|
|---|
| 718 | else
|
|---|
| 719 | /* xgettext:c-format */
|
|---|
| 720 | sprintf (errbuf, _("bad instruction `%.50s'"), start);
|
|---|
| 721 | #endif
|
|---|
| 722 |
|
|---|
| 723 | *errmsg = errbuf;
|
|---|
| 724 | return NULL;
|
|---|
| 725 | }
|
|---|
| 726 | }
|
|---|
| 727 | |
|---|
| 728 |
|
|---|
| 729 | #if 0 /* This calls back to GAS which we can't do without care. */
|
|---|
| 730 |
|
|---|
| 731 | /* Record each member of OPVALS in the assembler's symbol table.
|
|---|
| 732 | This lets GAS parse registers for us.
|
|---|
| 733 | ??? Interesting idea but not currently used. */
|
|---|
| 734 |
|
|---|
| 735 | /* Record each member of OPVALS in the assembler's symbol table.
|
|---|
| 736 | FIXME: Not currently used. */
|
|---|
| 737 |
|
|---|
| 738 | void
|
|---|
| 739 | fr30_cgen_asm_hash_keywords (cd, opvals)
|
|---|
| 740 | CGEN_CPU_DESC cd;
|
|---|
| 741 | CGEN_KEYWORD *opvals;
|
|---|
| 742 | {
|
|---|
| 743 | CGEN_KEYWORD_SEARCH search = cgen_keyword_search_init (opvals, NULL);
|
|---|
| 744 | const CGEN_KEYWORD_ENTRY * ke;
|
|---|
| 745 |
|
|---|
| 746 | while ((ke = cgen_keyword_search_next (& search)) != NULL)
|
|---|
| 747 | {
|
|---|
| 748 | #if 0 /* Unnecessary, should be done in the search routine. */
|
|---|
| 749 | if (! fr30_cgen_opval_supported (ke))
|
|---|
| 750 | continue;
|
|---|
| 751 | #endif
|
|---|
| 752 | cgen_asm_record_register (cd, ke->name, ke->value);
|
|---|
| 753 | }
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | #endif /* 0 */
|
|---|