| 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 <ctype.h>
|
|---|
| 30 | #include <stdio.h>
|
|---|
| 31 | #include "ansidecl.h"
|
|---|
| 32 | #include "bfd.h"
|
|---|
| 33 | #include "symcat.h"
|
|---|
| 34 | #include "fr30-desc.h"
|
|---|
| 35 | #include "fr30-opc.h"
|
|---|
| 36 | #include "opintl.h"
|
|---|
| 37 |
|
|---|
| 38 | #undef min
|
|---|
| 39 | #define min(a,b) ((a) < (b) ? (a) : (b))
|
|---|
| 40 | #undef max
|
|---|
| 41 | #define max(a,b) ((a) > (b) ? (a) : (b))
|
|---|
| 42 |
|
|---|
| 43 | static const char * parse_insn_normal
|
|---|
| 44 | PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *));
|
|---|
| 45 | |
|---|
| 46 |
|
|---|
| 47 | /* -- assembler routines inserted here */
|
|---|
| 48 |
|
|---|
| 49 | /* -- asm.c */
|
|---|
| 50 | /* Handle register lists for LDMx and STMx */
|
|---|
| 51 |
|
|---|
| 52 | static int
|
|---|
| 53 | parse_register_number (strp)
|
|---|
| 54 | const char **strp;
|
|---|
| 55 | {
|
|---|
| 56 | int regno;
|
|---|
| 57 | if (**strp < '0' || **strp > '9')
|
|---|
| 58 | return -1; /* error */
|
|---|
| 59 | regno = **strp - '0';
|
|---|
| 60 | ++*strp;
|
|---|
| 61 |
|
|---|
| 62 | if (**strp >= '0' && **strp <= '9')
|
|---|
| 63 | {
|
|---|
| 64 | regno = regno * 10 + (**strp - '0');
|
|---|
| 65 | ++*strp;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | return regno;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | static const char *
|
|---|
| 72 | parse_register_list (cd, strp, opindex, valuep, high_low, load_store)
|
|---|
| 73 | CGEN_CPU_DESC cd;
|
|---|
| 74 | const char **strp;
|
|---|
| 75 | int opindex;
|
|---|
| 76 | unsigned long *valuep;
|
|---|
| 77 | int high_low; /* 0 == high, 1 == low */
|
|---|
| 78 | int load_store; /* 0 == load, 1 == store */
|
|---|
| 79 | {
|
|---|
| 80 | int regno;
|
|---|
| 81 | *valuep = 0;
|
|---|
| 82 | while (**strp && **strp != ')')
|
|---|
| 83 | {
|
|---|
| 84 | if (**strp != 'R' && **strp != 'r')
|
|---|
| 85 | break;
|
|---|
| 86 | ++*strp;
|
|---|
| 87 |
|
|---|
| 88 | regno = parse_register_number (strp);
|
|---|
| 89 | if (regno == -1)
|
|---|
| 90 | return "Register number is not valid";
|
|---|
| 91 | if (regno > 7 && !high_low)
|
|---|
| 92 | return "Register must be between r0 and r7";
|
|---|
| 93 | if (regno < 8 && high_low)
|
|---|
| 94 | return "Register must be between r8 and r15";
|
|---|
| 95 |
|
|---|
| 96 | if (high_low)
|
|---|
| 97 | regno -= 8;
|
|---|
| 98 |
|
|---|
| 99 | if (load_store) /* mask is reversed for store */
|
|---|
| 100 | *valuep |= 0x80 >> regno;
|
|---|
| 101 | else
|
|---|
| 102 | *valuep |= 1 << regno;
|
|---|
| 103 |
|
|---|
| 104 | if (**strp == ',')
|
|---|
| 105 | {
|
|---|
| 106 | if (*(*strp + 1) == ')')
|
|---|
| 107 | break;
|
|---|
| 108 | ++*strp;
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | if (!*strp || **strp != ')')
|
|---|
| 113 | return "Register list is not valid";
|
|---|
| 114 |
|
|---|
| 115 | return NULL;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | static const char *
|
|---|
| 119 | parse_low_register_list_ld (cd, strp, opindex, valuep)
|
|---|
| 120 | CGEN_CPU_DESC cd;
|
|---|
| 121 | const char **strp;
|
|---|
| 122 | int opindex;
|
|---|
| 123 | unsigned long *valuep;
|
|---|
| 124 | {
|
|---|
| 125 | return parse_register_list (cd, strp, opindex, valuep, 0/*low*/, 0/*load*/);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | static const char *
|
|---|
| 129 | parse_hi_register_list_ld (cd, strp, opindex, valuep)
|
|---|
| 130 | CGEN_CPU_DESC cd;
|
|---|
| 131 | const char **strp;
|
|---|
| 132 | int opindex;
|
|---|
| 133 | unsigned long *valuep;
|
|---|
| 134 | {
|
|---|
| 135 | return parse_register_list (cd, strp, opindex, valuep, 1/*high*/, 0/*load*/);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | static const char *
|
|---|
| 139 | parse_low_register_list_st (cd, strp, opindex, valuep)
|
|---|
| 140 | CGEN_CPU_DESC cd;
|
|---|
| 141 | const char **strp;
|
|---|
| 142 | int opindex;
|
|---|
| 143 | unsigned long *valuep;
|
|---|
| 144 | {
|
|---|
| 145 | return parse_register_list (cd, strp, opindex, valuep, 0/*low*/, 1/*store*/);
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | static const char *
|
|---|
| 149 | parse_hi_register_list_st (cd, strp, opindex, valuep)
|
|---|
| 150 | CGEN_CPU_DESC cd;
|
|---|
| 151 | const char **strp;
|
|---|
| 152 | int opindex;
|
|---|
| 153 | unsigned long *valuep;
|
|---|
| 154 | {
|
|---|
| 155 | return parse_register_list (cd, strp, opindex, valuep, 1/*high*/, 1/*store*/);
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /* -- */
|
|---|
| 159 |
|
|---|
| 160 | /* Main entry point for operand parsing.
|
|---|
| 161 |
|
|---|
| 162 | This function is basically just a big switch statement. Earlier versions
|
|---|
| 163 | used tables to look up the function to use, but
|
|---|
| 164 | - if the table contains both assembler and disassembler functions then
|
|---|
| 165 | the disassembler contains much of the assembler and vice-versa,
|
|---|
| 166 | - there's a lot of inlining possibilities as things grow,
|
|---|
| 167 | - using a switch statement avoids the function call overhead.
|
|---|
| 168 |
|
|---|
| 169 | This function could be moved into `parse_insn_normal', but keeping it
|
|---|
| 170 | separate makes clear the interface between `parse_insn_normal' and each of
|
|---|
| 171 | the handlers.
|
|---|
| 172 | */
|
|---|
| 173 |
|
|---|
| 174 | const char *
|
|---|
| 175 | fr30_cgen_parse_operand (cd, opindex, strp, fields)
|
|---|
| 176 | CGEN_CPU_DESC cd;
|
|---|
| 177 | int opindex;
|
|---|
| 178 | const char ** strp;
|
|---|
| 179 | CGEN_FIELDS * fields;
|
|---|
| 180 | {
|
|---|
| 181 | const char * errmsg = NULL;
|
|---|
| 182 | /* Used by scalar operands that still need to be parsed. */
|
|---|
| 183 | long junk;
|
|---|
| 184 |
|
|---|
| 185 | switch (opindex)
|
|---|
| 186 | {
|
|---|
| 187 | case FR30_OPERAND_CRI :
|
|---|
| 188 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_cr_names, & fields->f_CRi);
|
|---|
| 189 | break;
|
|---|
| 190 | case FR30_OPERAND_CRJ :
|
|---|
| 191 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_cr_names, & fields->f_CRj);
|
|---|
| 192 | break;
|
|---|
| 193 | case FR30_OPERAND_R13 :
|
|---|
| 194 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r13, & junk);
|
|---|
| 195 | break;
|
|---|
| 196 | case FR30_OPERAND_R14 :
|
|---|
| 197 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r14, & junk);
|
|---|
| 198 | break;
|
|---|
| 199 | case FR30_OPERAND_R15 :
|
|---|
| 200 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r15, & junk);
|
|---|
| 201 | break;
|
|---|
| 202 | case FR30_OPERAND_RI :
|
|---|
| 203 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Ri);
|
|---|
| 204 | break;
|
|---|
| 205 | case FR30_OPERAND_RIC :
|
|---|
| 206 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Ric);
|
|---|
| 207 | break;
|
|---|
| 208 | case FR30_OPERAND_RJ :
|
|---|
| 209 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Rj);
|
|---|
| 210 | break;
|
|---|
| 211 | case FR30_OPERAND_RJC :
|
|---|
| 212 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Rjc);
|
|---|
| 213 | break;
|
|---|
| 214 | case FR30_OPERAND_RS1 :
|
|---|
| 215 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_dr_names, & fields->f_Rs1);
|
|---|
| 216 | break;
|
|---|
| 217 | case FR30_OPERAND_RS2 :
|
|---|
| 218 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_dr_names, & fields->f_Rs2);
|
|---|
| 219 | break;
|
|---|
| 220 | case FR30_OPERAND_CC :
|
|---|
| 221 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_CC, &fields->f_cc);
|
|---|
| 222 | break;
|
|---|
| 223 | case FR30_OPERAND_CCC :
|
|---|
| 224 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_CCC, &fields->f_ccc);
|
|---|
| 225 | break;
|
|---|
| 226 | case FR30_OPERAND_DIR10 :
|
|---|
| 227 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR10, &fields->f_dir10);
|
|---|
| 228 | break;
|
|---|
| 229 | case FR30_OPERAND_DIR8 :
|
|---|
| 230 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR8, &fields->f_dir8);
|
|---|
| 231 | break;
|
|---|
| 232 | case FR30_OPERAND_DIR9 :
|
|---|
| 233 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR9, &fields->f_dir9);
|
|---|
| 234 | break;
|
|---|
| 235 | case FR30_OPERAND_DISP10 :
|
|---|
| 236 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP10, &fields->f_disp10);
|
|---|
| 237 | break;
|
|---|
| 238 | case FR30_OPERAND_DISP8 :
|
|---|
| 239 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP8, &fields->f_disp8);
|
|---|
| 240 | break;
|
|---|
| 241 | case FR30_OPERAND_DISP9 :
|
|---|
| 242 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP9, &fields->f_disp9);
|
|---|
| 243 | break;
|
|---|
| 244 | case FR30_OPERAND_I20 :
|
|---|
| 245 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I20, &fields->f_i20);
|
|---|
| 246 | break;
|
|---|
| 247 | case FR30_OPERAND_I32 :
|
|---|
| 248 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I32, &fields->f_i32);
|
|---|
| 249 | break;
|
|---|
| 250 | case FR30_OPERAND_I8 :
|
|---|
| 251 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I8, &fields->f_i8);
|
|---|
| 252 | break;
|
|---|
| 253 | case FR30_OPERAND_LABEL12 :
|
|---|
| 254 | {
|
|---|
| 255 | bfd_vma value;
|
|---|
| 256 | errmsg = cgen_parse_address (cd, strp, FR30_OPERAND_LABEL12, 0, NULL, & value);
|
|---|
| 257 | fields->f_rel12 = value;
|
|---|
| 258 | }
|
|---|
| 259 | break;
|
|---|
| 260 | case FR30_OPERAND_LABEL9 :
|
|---|
| 261 | {
|
|---|
| 262 | bfd_vma value;
|
|---|
| 263 | errmsg = cgen_parse_address (cd, strp, FR30_OPERAND_LABEL9, 0, NULL, & value);
|
|---|
| 264 | fields->f_rel9 = value;
|
|---|
| 265 | }
|
|---|
| 266 | break;
|
|---|
| 267 | case FR30_OPERAND_M4 :
|
|---|
| 268 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_M4, &fields->f_m4);
|
|---|
| 269 | break;
|
|---|
| 270 | case FR30_OPERAND_PS :
|
|---|
| 271 | errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_ps, & junk);
|
|---|
| 272 | break;
|
|---|
| 273 | case FR30_OPERAND_REGLIST_HI_LD :
|
|---|
| 274 | errmsg = parse_hi_register_list_ld (cd, strp, FR30_OPERAND_REGLIST_HI_LD, &fields->f_reglist_hi_ld);
|
|---|
| 275 | break;
|
|---|
| 276 | case FR30_OPERAND_REGLIST_HI_ST :
|
|---|
| 277 | errmsg = parse_hi_register_list_st (cd, strp, FR30_OPERAND_REGLIST_HI_ST, &fields->f_reglist_hi_st);
|
|---|
| 278 | break;
|
|---|
| 279 | case FR30_OPERAND_REGLIST_LOW_LD :
|
|---|
| 280 | errmsg = parse_low_register_list_ld (cd, strp, FR30_OPERAND_REGLIST_LOW_LD, &fields->f_reglist_low_ld);
|
|---|
| 281 | break;
|
|---|
| 282 | case FR30_OPERAND_REGLIST_LOW_ST :
|
|---|
| 283 | errmsg = parse_low_register_list_st (cd, strp, FR30_OPERAND_REGLIST_LOW_ST, &fields->f_reglist_low_st);
|
|---|
| 284 | break;
|
|---|
| 285 | case FR30_OPERAND_S10 :
|
|---|
| 286 | errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_S10, &fields->f_s10);
|
|---|
| 287 | break;
|
|---|
| 288 | case FR30_OPERAND_U10 :
|
|---|
| 289 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U10, &fields->f_u10);
|
|---|
| 290 | break;
|
|---|
| 291 | case FR30_OPERAND_U4 :
|
|---|
| 292 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U4, &fields->f_u4);
|
|---|
| 293 | break;
|
|---|
| 294 | case FR30_OPERAND_U4C :
|
|---|
| 295 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U4C, &fields->f_u4c);
|
|---|
| 296 | break;
|
|---|
| 297 | case FR30_OPERAND_U8 :
|
|---|
| 298 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U8, &fields->f_u8);
|
|---|
| 299 | break;
|
|---|
| 300 | case FR30_OPERAND_UDISP6 :
|
|---|
| 301 | errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_UDISP6, &fields->f_udisp6);
|
|---|
| 302 | break;
|
|---|
| 303 |
|
|---|
| 304 | default :
|
|---|
| 305 | /* xgettext:c-format */
|
|---|
| 306 | fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
|
|---|
| 307 | abort ();
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | return errmsg;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | cgen_parse_fn * const fr30_cgen_parse_handlers[] =
|
|---|
| 314 | {
|
|---|
| 315 | parse_insn_normal,
|
|---|
| 316 | };
|
|---|
| 317 |
|
|---|
| 318 | void
|
|---|
| 319 | fr30_cgen_init_asm (cd)
|
|---|
| 320 | CGEN_CPU_DESC cd;
|
|---|
| 321 | {
|
|---|
| 322 | fr30_cgen_init_opcode_table (cd);
|
|---|
| 323 | fr30_cgen_init_ibld_table (cd);
|
|---|
| 324 | cd->parse_handlers = & fr30_cgen_parse_handlers[0];
|
|---|
| 325 | cd->parse_operand = fr30_cgen_parse_operand;
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | |
|---|
| 329 |
|
|---|
| 330 | /* Default insn parser.
|
|---|
| 331 |
|
|---|
| 332 | The syntax string is scanned and operands are parsed and stored in FIELDS.
|
|---|
| 333 | Relocs are queued as we go via other callbacks.
|
|---|
| 334 |
|
|---|
| 335 | ??? Note that this is currently an all-or-nothing parser. If we fail to
|
|---|
| 336 | parse the instruction, we return 0 and the caller will start over from
|
|---|
| 337 | the beginning. Backtracking will be necessary in parsing subexpressions,
|
|---|
| 338 | but that can be handled there. Not handling backtracking here may get
|
|---|
| 339 | expensive in the case of the m68k. Deal with later.
|
|---|
| 340 |
|
|---|
| 341 | Returns NULL for success, an error message for failure.
|
|---|
| 342 | */
|
|---|
| 343 |
|
|---|
| 344 | static const char *
|
|---|
| 345 | parse_insn_normal (cd, insn, strp, fields)
|
|---|
| 346 | CGEN_CPU_DESC cd;
|
|---|
| 347 | const CGEN_INSN *insn;
|
|---|
| 348 | const char **strp;
|
|---|
| 349 | CGEN_FIELDS *fields;
|
|---|
| 350 | {
|
|---|
| 351 | /* ??? Runtime added insns not handled yet. */
|
|---|
| 352 | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
|
|---|
| 353 | const char *str = *strp;
|
|---|
| 354 | const char *errmsg;
|
|---|
| 355 | const char *p;
|
|---|
| 356 | const unsigned char * syn;
|
|---|
| 357 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 358 | /* FIXME: wip */
|
|---|
| 359 | int past_opcode_p;
|
|---|
| 360 | #endif
|
|---|
| 361 |
|
|---|
| 362 | /* For now we assume the mnemonic is first (there are no leading operands).
|
|---|
| 363 | We can parse it without needing to set up operand parsing.
|
|---|
| 364 | GAS's input scrubber will ensure mnemonics are lowercase, but we may
|
|---|
| 365 | not be called from GAS. */
|
|---|
| 366 | p = CGEN_INSN_MNEMONIC (insn);
|
|---|
| 367 | while (*p && tolower (*p) == tolower (*str))
|
|---|
| 368 | ++p, ++str;
|
|---|
| 369 |
|
|---|
| 370 | if (* p)
|
|---|
| 371 | return _("unrecognized instruction");
|
|---|
| 372 |
|
|---|
| 373 | #ifndef CGEN_MNEMONIC_OPERANDS
|
|---|
| 374 | if (* str && !isspace (* str))
|
|---|
| 375 | return _("unrecognized instruction");
|
|---|
| 376 | #endif
|
|---|
| 377 |
|
|---|
| 378 | CGEN_INIT_PARSE (cd);
|
|---|
| 379 | cgen_init_parse_operand (cd);
|
|---|
| 380 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 381 | past_opcode_p = 0;
|
|---|
| 382 | #endif
|
|---|
| 383 |
|
|---|
| 384 | /* We don't check for (*str != '\0') here because we want to parse
|
|---|
| 385 | any trailing fake arguments in the syntax string. */
|
|---|
| 386 | syn = CGEN_SYNTAX_STRING (syntax);
|
|---|
| 387 |
|
|---|
| 388 | /* Mnemonics come first for now, ensure valid string. */
|
|---|
| 389 | if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
|
|---|
| 390 | abort ();
|
|---|
| 391 |
|
|---|
| 392 | ++syn;
|
|---|
| 393 |
|
|---|
| 394 | while (* syn != 0)
|
|---|
| 395 | {
|
|---|
| 396 | /* Non operand chars must match exactly. */
|
|---|
| 397 | if (CGEN_SYNTAX_CHAR_P (* syn))
|
|---|
| 398 | {
|
|---|
| 399 | /* FIXME: While we allow for non-GAS callers above, we assume the
|
|---|
| 400 | first char after the mnemonic part is a space. */
|
|---|
| 401 | /* FIXME: We also take inappropriate advantage of the fact that
|
|---|
| 402 | GAS's input scrubber will remove extraneous blanks. */
|
|---|
| 403 | if (tolower (*str) == tolower (CGEN_SYNTAX_CHAR (* syn)))
|
|---|
| 404 | {
|
|---|
| 405 | #ifdef CGEN_MNEMONIC_OPERANDS
|
|---|
| 406 | if (* syn == ' ')
|
|---|
| 407 | past_opcode_p = 1;
|
|---|
| 408 | #endif
|
|---|
| 409 | ++ syn;
|
|---|
| 410 | ++ str;
|
|---|
| 411 | }
|
|---|
| 412 | else
|
|---|
| 413 | {
|
|---|
| 414 | /* Syntax char didn't match. Can't be this insn. */
|
|---|
| 415 | static char msg [80];
|
|---|
| 416 | /* xgettext:c-format */
|
|---|
| 417 | sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
|
|---|
| 418 | *syn, *str);
|
|---|
| 419 | return msg;
|
|---|
| 420 | }
|
|---|
| 421 | continue;
|
|---|
| 422 | }
|
|---|
| 423 |
|
|---|
| 424 | /* We have an operand of some sort. */
|
|---|
| 425 | errmsg = fr30_cgen_parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
|
|---|
| 426 | &str, fields);
|
|---|
| 427 | if (errmsg)
|
|---|
| 428 | return errmsg;
|
|---|
| 429 |
|
|---|
| 430 | /* Done with this operand, continue with next one. */
|
|---|
| 431 | ++ syn;
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | /* If we're at the end of the syntax string, we're done. */
|
|---|
| 435 | if (* syn == '\0')
|
|---|
| 436 | {
|
|---|
| 437 | /* FIXME: For the moment we assume a valid `str' can only contain
|
|---|
| 438 | blanks now. IE: We needn't try again with a longer version of
|
|---|
| 439 | the insn and it is assumed that longer versions of insns appear
|
|---|
| 440 | before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
|
|---|
| 441 | while (isspace (* str))
|
|---|
| 442 | ++ str;
|
|---|
| 443 |
|
|---|
| 444 | if (* str != '\0')
|
|---|
| 445 | return _("junk at end of line"); /* FIXME: would like to include `str' */
|
|---|
| 446 |
|
|---|
| 447 | return NULL;
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | /* We couldn't parse it. */
|
|---|
| 451 | return _("unrecognized instruction");
|
|---|
| 452 | }
|
|---|
| 453 | |
|---|
| 454 |
|
|---|
| 455 | /* Main entry point.
|
|---|
| 456 | This routine is called for each instruction to be assembled.
|
|---|
| 457 | STR points to the insn to be assembled.
|
|---|
| 458 | We assume all necessary tables have been initialized.
|
|---|
| 459 | The assembled instruction, less any fixups, is stored in BUF.
|
|---|
| 460 | Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
|
|---|
| 461 | still needs to be converted to target byte order, otherwise BUF is an array
|
|---|
| 462 | of bytes in target byte order.
|
|---|
| 463 | The result is a pointer to the insn's entry in the opcode table,
|
|---|
| 464 | or NULL if an error occured (an error message will have already been
|
|---|
| 465 | printed).
|
|---|
| 466 |
|
|---|
| 467 | Note that when processing (non-alias) macro-insns,
|
|---|
| 468 | this function recurses.
|
|---|
| 469 |
|
|---|
| 470 | ??? It's possible to make this cpu-independent.
|
|---|
| 471 | One would have to deal with a few minor things.
|
|---|
| 472 | At this point in time doing so would be more of a curiosity than useful
|
|---|
| 473 | [for example this file isn't _that_ big], but keeping the possibility in
|
|---|
| 474 | mind helps keep the design clean. */
|
|---|
| 475 |
|
|---|
| 476 | const CGEN_INSN *
|
|---|
| 477 | fr30_cgen_assemble_insn (cd, str, fields, buf, errmsg)
|
|---|
| 478 | CGEN_CPU_DESC cd;
|
|---|
| 479 | const char *str;
|
|---|
| 480 | CGEN_FIELDS *fields;
|
|---|
| 481 | CGEN_INSN_BYTES_PTR buf;
|
|---|
| 482 | char **errmsg;
|
|---|
| 483 | {
|
|---|
| 484 | const char *start;
|
|---|
| 485 | CGEN_INSN_LIST *ilist;
|
|---|
| 486 | const char *tmp_errmsg = NULL;
|
|---|
| 487 |
|
|---|
| 488 | /* Skip leading white space. */
|
|---|
| 489 | while (isspace (* str))
|
|---|
| 490 | ++ str;
|
|---|
| 491 |
|
|---|
| 492 | /* The instructions are stored in hashed lists.
|
|---|
| 493 | Get the first in the list. */
|
|---|
| 494 | ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
|
|---|
| 495 |
|
|---|
| 496 | /* Keep looking until we find a match. */
|
|---|
| 497 |
|
|---|
| 498 | start = str;
|
|---|
| 499 | for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
|
|---|
| 500 | {
|
|---|
| 501 | const CGEN_INSN *insn = ilist->insn;
|
|---|
| 502 |
|
|---|
| 503 | #ifdef CGEN_VALIDATE_INSN_SUPPORTED
|
|---|
| 504 | /* not usually needed as unsupported opcodes shouldn't be in the hash lists */
|
|---|
| 505 | /* Is this insn supported by the selected cpu? */
|
|---|
| 506 | if (! fr30_cgen_insn_supported (cd, insn))
|
|---|
| 507 | continue;
|
|---|
| 508 | #endif
|
|---|
| 509 |
|
|---|
| 510 | /* If the RELAX attribute is set, this is an insn that shouldn't be
|
|---|
| 511 | chosen immediately. Instead, it is used during assembler/linker
|
|---|
| 512 | relaxation if possible. */
|
|---|
| 513 | if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAX) != 0)
|
|---|
| 514 | continue;
|
|---|
| 515 |
|
|---|
| 516 | str = start;
|
|---|
| 517 |
|
|---|
| 518 | /* Allow parse/insert handlers to obtain length of insn. */
|
|---|
| 519 | CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
|
|---|
| 520 |
|
|---|
| 521 | tmp_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
|
|---|
| 522 | if (tmp_errmsg != NULL)
|
|---|
| 523 | continue;
|
|---|
| 524 |
|
|---|
| 525 | /* ??? 0 is passed for `pc' */
|
|---|
| 526 | tmp_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
|
|---|
| 527 | (bfd_vma) 0);
|
|---|
| 528 | if (tmp_errmsg != NULL)
|
|---|
| 529 | continue;
|
|---|
| 530 |
|
|---|
| 531 | /* It is up to the caller to actually output the insn and any
|
|---|
| 532 | queued relocs. */
|
|---|
| 533 | return insn;
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | /* Make sure we leave this with something at this point. */
|
|---|
| 537 | if (tmp_errmsg == NULL)
|
|---|
| 538 | tmp_errmsg = "unknown mnemonic";
|
|---|
| 539 |
|
|---|
| 540 | {
|
|---|
| 541 | static char errbuf[150];
|
|---|
| 542 |
|
|---|
| 543 | #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
|
|---|
| 544 | /* if verbose error messages, use errmsg from CGEN_PARSE_FN */
|
|---|
| 545 | if (strlen (start) > 50)
|
|---|
| 546 | /* xgettext:c-format */
|
|---|
| 547 | sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
|
|---|
| 548 | else
|
|---|
| 549 | /* xgettext:c-format */
|
|---|
| 550 | sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
|
|---|
| 551 | #else
|
|---|
| 552 | if (strlen (start) > 50)
|
|---|
| 553 | /* xgettext:c-format */
|
|---|
| 554 | sprintf (errbuf, _("bad instruction `%.50s...'"), start);
|
|---|
| 555 | else
|
|---|
| 556 | /* xgettext:c-format */
|
|---|
| 557 | sprintf (errbuf, _("bad instruction `%.50s'"), start);
|
|---|
| 558 | #endif
|
|---|
| 559 |
|
|---|
| 560 | *errmsg = errbuf;
|
|---|
| 561 | return NULL;
|
|---|
| 562 | }
|
|---|
| 563 | }
|
|---|
| 564 | |
|---|
| 565 |
|
|---|
| 566 | #if 0 /* This calls back to GAS which we can't do without care. */
|
|---|
| 567 |
|
|---|
| 568 | /* Record each member of OPVALS in the assembler's symbol table.
|
|---|
| 569 | This lets GAS parse registers for us.
|
|---|
| 570 | ??? Interesting idea but not currently used. */
|
|---|
| 571 |
|
|---|
| 572 | /* Record each member of OPVALS in the assembler's symbol table.
|
|---|
| 573 | FIXME: Not currently used. */
|
|---|
| 574 |
|
|---|
| 575 | void
|
|---|
| 576 | fr30_cgen_asm_hash_keywords (cd, opvals)
|
|---|
| 577 | CGEN_CPU_DESC cd;
|
|---|
| 578 | CGEN_KEYWORD *opvals;
|
|---|
| 579 | {
|
|---|
| 580 | CGEN_KEYWORD_SEARCH search = cgen_keyword_search_init (opvals, NULL);
|
|---|
| 581 | const CGEN_KEYWORD_ENTRY * ke;
|
|---|
| 582 |
|
|---|
| 583 | while ((ke = cgen_keyword_search_next (& search)) != NULL)
|
|---|
| 584 | {
|
|---|
| 585 | #if 0 /* Unnecessary, should be done in the search routine. */
|
|---|
| 586 | if (! fr30_cgen_opval_supported (ke))
|
|---|
| 587 | continue;
|
|---|
| 588 | #endif
|
|---|
| 589 | cgen_asm_record_register (cd, ke->name, ke->value);
|
|---|
| 590 | }
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | #endif /* 0 */
|
|---|