1 /* Assembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS MACHINE GENERATED WITH CGEN.
5 - the resultant file is machine generated, cgen-asm.in isn't
7 Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
9 This file is part of the GNU Binutils and GDB, the GNU debugger.
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)
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.
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 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
37 #include "libiberty.h"
38 #include "safe-ctype.h"
41 #define min(a,b) ((a) < (b) ? (a) : (b))
43 #define max(a,b) ((a) > (b) ? (a) : (b))
45 static const char * parse_insn_normal
46 (CGEN_CPU_DESC
, const CGEN_INSN
*, const char **, CGEN_FIELDS
*);
48 /* -- assembler routines inserted here. */
51 static int signed_out_of_bounds (long);
52 static const char * parse_imm16 (CGEN_CPU_DESC
, const char **, int, long *);
53 static const char * parse_dup (CGEN_CPU_DESC
, const char **, int, long *);
54 static const char * parse_ball (CGEN_CPU_DESC
, const char **, int, long *);
55 static const char * parse_xmode (CGEN_CPU_DESC
, const char **, int, long *);
56 static const char * parse_rc (CGEN_CPU_DESC
, const char **, int, long *);
57 static const char * parse_cbrb (CGEN_CPU_DESC
, const char **, int, long *);
58 static const char * parse_rbbc (CGEN_CPU_DESC
, const char **, int, long *);
59 static const char * parse_type (CGEN_CPU_DESC
, const char **, int, long *);
61 /* Range checking for signed numbers. Returns 0 if acceptable
62 and 1 if the value is out of bounds for a signed quantity. */
65 signed_out_of_bounds (long val
)
67 if ((val
< -32768) || (val
> 32767))
73 parse_imm16 (CGEN_CPU_DESC cd
,
79 enum cgen_parse_operand_result result_type
;
80 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
83 /* Is it a control transfer instructions? */
84 if (opindex
== (CGEN_OPERAND_TYPE
) MS1_OPERAND_IMM16O
)
86 code
= BFD_RELOC_16_PCREL
;
87 errmsg
= cgen_parse_address (cd
, strp
, opindex
, code
,
88 & result_type
, & value
);
91 if (signed_out_of_bounds (value
))
92 errmsg
= _("Operand out of range. Must be between -32768 and 32767.");
98 /* If it's not a control transfer instruction, then
99 we have to check for %OP relocating operators. */
100 if (strncmp (*strp
, "%hi16", 5) == 0)
103 code
= BFD_RELOC_HI16
;
105 else if (strncmp (*strp
, "%lo16", 5) == 0)
108 code
= BFD_RELOC_LO16
;
111 /* If we found a %OP relocating operator, then parse it as an address.
112 If not, we need to parse it as an integer, either signed or unsigned
113 depending on which operand type we have. */
114 if (code
!= BFD_RELOC_NONE
)
116 /* %OP relocating operator found. */
117 errmsg
= cgen_parse_address (cd
, strp
, opindex
, code
,
118 & result_type
, & value
);
123 case (CGEN_PARSE_OPERAND_RESULT_NUMBER
):
124 if (code
== BFD_RELOC_HI16
)
125 value
= (value
>> 16) & 0xFFFF;
126 else if (code
== BFD_RELOC_LO16
)
127 value
= value
& 0xFFFF;
129 errmsg
= _("Biiiig Trouble in parse_imm16!");
132 case (CGEN_PARSE_OPERAND_RESULT_QUEUED
):
133 /* No special processing for this case. */
137 errmsg
= _("%operator operand is not a symbol");
145 /* Parse hex values like 0xffff as unsigned, and sign extend
147 int parse_signed
= (opindex
== (CGEN_OPERAND_TYPE
)MS1_OPERAND_IMM16
);
149 if ((*strp
)[0] == '0'
150 && ((*strp
)[1] == 'x' || (*strp
)[1] == 'X'))
153 /* No relocating operator. Parse as an number. */
156 /* Parse as as signed integer. */
158 errmsg
= cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
163 /* Manual range checking is needed for the signed case. */
164 if (*valuep
& 0x8000)
165 value
= 0xffff0000 | *valuep
;
169 if (signed_out_of_bounds (value
))
170 errmsg
= _("Operand out of range. Must be between -32768 and 32767.");
171 /* Truncate to 16 bits. This is necessary
172 because cgen will have sign extended *valuep. */
179 /* MS1_OPERAND_IMM16Z. Parse as an unsigned integer. */
180 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
182 if (opindex
== (CGEN_OPERAND_TYPE
)MS1_OPERAND_IMM16
184 && *valuep
<= 0xffff)
194 parse_dup (CGEN_CPU_DESC cd
,
199 const char *errmsg
= NULL
;
201 if (strncmp (*strp
, "dup", 3) == 0 || strncmp (*strp
, "DUP", 3) == 0)
206 else if (strncmp (*strp
, "xx", 2) == 0 || strncmp (*strp
, "XX", 2) == 0)
212 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
219 parse_ball (CGEN_CPU_DESC cd
,
224 const char *errmsg
= NULL
;
226 if (strncmp (*strp
, "all", 3) == 0 || strncmp (*strp
, "ALL", 3) == 0)
231 else if (strncmp (*strp
, "one", 3) == 0 || strncmp (*strp
, "ONE", 3) == 0)
237 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
243 parse_xmode (CGEN_CPU_DESC cd
,
248 const char *errmsg
= NULL
;
250 if (strncmp (*strp
, "pm", 2) == 0 || strncmp (*strp
, "PM", 2) == 0)
255 else if (strncmp (*strp
, "xm", 2) == 0 || strncmp (*strp
, "XM", 2) == 0)
261 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
267 parse_rc (CGEN_CPU_DESC cd
,
272 const char *errmsg
= NULL
;
274 if (strncmp (*strp
, "r", 1) == 0 || strncmp (*strp
, "R", 1) == 0)
279 else if (strncmp (*strp
, "c", 1) == 0 || strncmp (*strp
, "C", 1) == 0)
285 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
291 parse_cbrb (CGEN_CPU_DESC cd
,
296 const char *errmsg
= NULL
;
298 if (strncmp (*strp
, "rb", 2) == 0 || strncmp (*strp
, "RB", 2) == 0)
303 else if (strncmp (*strp
, "cb", 2) == 0 || strncmp (*strp
, "CB", 2) == 0)
309 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
315 parse_rbbc (CGEN_CPU_DESC cd
,
320 const char *errmsg
= NULL
;
322 if (strncmp (*strp
, "rt", 2) == 0 || strncmp (*strp
, "RT", 2) == 0)
327 else if (strncmp (*strp
, "br1", 3) == 0 || strncmp (*strp
, "BR1", 3) == 0)
332 else if (strncmp (*strp
, "br2", 3) == 0 || strncmp (*strp
, "BR2", 3) == 0)
337 else if (strncmp (*strp
, "cs", 2) == 0 || strncmp (*strp
, "CS", 2) == 0)
343 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
349 parse_type (CGEN_CPU_DESC cd
,
354 const char *errmsg
= NULL
;
356 if (strncmp (*strp
, "odd", 3) == 0 || strncmp (*strp
, "ODD", 3) == 0)
361 else if (strncmp (*strp
, "even", 4) == 0 || strncmp (*strp
, "EVEN", 4) == 0)
366 else if (strncmp (*strp
, "oe", 2) == 0 || strncmp (*strp
, "OE", 2) == 0)
372 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
374 if ((errmsg
== NULL
) && (*valuep
== 3))
375 errmsg
= _("invalid operand. type may have values 0,1,2 only.");
382 const char * ms1_cgen_parse_operand
383 PARAMS ((CGEN_CPU_DESC
, int, const char **, CGEN_FIELDS
*));
385 /* Main entry point for operand parsing.
387 This function is basically just a big switch statement. Earlier versions
388 used tables to look up the function to use, but
389 - if the table contains both assembler and disassembler functions then
390 the disassembler contains much of the assembler and vice-versa,
391 - there's a lot of inlining possibilities as things grow,
392 - using a switch statement avoids the function call overhead.
394 This function could be moved into `parse_insn_normal', but keeping it
395 separate makes clear the interface between `parse_insn_normal' and each of
399 ms1_cgen_parse_operand (cd
, opindex
, strp
, fields
)
403 CGEN_FIELDS
* fields
;
405 const char * errmsg
= NULL
;
406 /* Used by scalar operands that still need to be parsed. */
407 long junk ATTRIBUTE_UNUSED
;
411 case MS1_OPERAND_A23
:
412 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_A23
, (unsigned long *) (& fields
->f_a23
));
414 case MS1_OPERAND_BALL
:
415 errmsg
= parse_ball (cd
, strp
, MS1_OPERAND_BALL
, (unsigned long *) (& fields
->f_ball
));
417 case MS1_OPERAND_BALL2
:
418 errmsg
= parse_ball (cd
, strp
, MS1_OPERAND_BALL2
, (unsigned long *) (& fields
->f_ball2
));
420 case MS1_OPERAND_BANKADDR
:
421 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BANKADDR
, (unsigned long *) (& fields
->f_bankaddr
));
423 case MS1_OPERAND_BRC
:
424 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BRC
, (unsigned long *) (& fields
->f_brc
));
426 case MS1_OPERAND_BRC2
:
427 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BRC2
, (unsigned long *) (& fields
->f_brc2
));
429 case MS1_OPERAND_CBRB
:
430 errmsg
= parse_cbrb (cd
, strp
, MS1_OPERAND_CBRB
, (unsigned long *) (& fields
->f_cbrb
));
432 case MS1_OPERAND_CBS
:
433 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CBS
, (unsigned long *) (& fields
->f_cbs
));
435 case MS1_OPERAND_CBX
:
436 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CBX
, (unsigned long *) (& fields
->f_cbx
));
438 case MS1_OPERAND_CCB
:
439 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CCB
, (unsigned long *) (& fields
->f_ccb
));
441 case MS1_OPERAND_CDB
:
442 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CDB
, (unsigned long *) (& fields
->f_cdb
));
444 case MS1_OPERAND_CELL
:
445 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CELL
, (unsigned long *) (& fields
->f_cell
));
447 case MS1_OPERAND_COLNUM
:
448 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_COLNUM
, (unsigned long *) (& fields
->f_colnum
));
450 case MS1_OPERAND_CONTNUM
:
451 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CONTNUM
, (unsigned long *) (& fields
->f_contnum
));
453 case MS1_OPERAND_CR
:
454 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CR
, (unsigned long *) (& fields
->f_cr
));
456 case MS1_OPERAND_CTXDISP
:
457 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CTXDISP
, (unsigned long *) (& fields
->f_ctxdisp
));
459 case MS1_OPERAND_DUP
:
460 errmsg
= parse_dup (cd
, strp
, MS1_OPERAND_DUP
, (unsigned long *) (& fields
->f_dup
));
462 case MS1_OPERAND_FBDISP
:
463 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_FBDISP
, (unsigned long *) (& fields
->f_fbdisp
));
465 case MS1_OPERAND_FBINCR
:
466 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_FBINCR
, (unsigned long *) (& fields
->f_fbincr
));
468 case MS1_OPERAND_FRDR
:
469 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_dr
);
471 case MS1_OPERAND_FRDRRR
:
472 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_drrr
);
474 case MS1_OPERAND_FRSR1
:
475 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_sr1
);
477 case MS1_OPERAND_FRSR2
:
478 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_sr2
);
480 case MS1_OPERAND_ID
:
481 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ID
, (unsigned long *) (& fields
->f_id
));
483 case MS1_OPERAND_IMM16
:
484 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16
, (long *) (& fields
->f_imm16s
));
486 case MS1_OPERAND_IMM16O
:
487 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16O
, (unsigned long *) (& fields
->f_imm16s
));
489 case MS1_OPERAND_IMM16Z
:
490 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16Z
, (unsigned long *) (& fields
->f_imm16u
));
492 case MS1_OPERAND_INCAMT
:
493 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_INCAMT
, (unsigned long *) (& fields
->f_incamt
));
495 case MS1_OPERAND_INCR
:
496 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_INCR
, (unsigned long *) (& fields
->f_incr
));
498 case MS1_OPERAND_LENGTH
:
499 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_LENGTH
, (unsigned long *) (& fields
->f_length
));
501 case MS1_OPERAND_MASK
:
502 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MASK
, (unsigned long *) (& fields
->f_mask
));
504 case MS1_OPERAND_MASK1
:
505 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MASK1
, (unsigned long *) (& fields
->f_mask1
));
507 case MS1_OPERAND_MODE
:
508 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MODE
, (unsigned long *) (& fields
->f_mode
));
510 case MS1_OPERAND_PERM
:
511 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_PERM
, (unsigned long *) (& fields
->f_perm
));
513 case MS1_OPERAND_RBBC
:
514 errmsg
= parse_rbbc (cd
, strp
, MS1_OPERAND_RBBC
, (unsigned long *) (& fields
->f_rbbc
));
516 case MS1_OPERAND_RC
:
517 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC
, (unsigned long *) (& fields
->f_rc
));
519 case MS1_OPERAND_RC1
:
520 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC1
, (unsigned long *) (& fields
->f_rc1
));
522 case MS1_OPERAND_RC2
:
523 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC2
, (unsigned long *) (& fields
->f_rc2
));
525 case MS1_OPERAND_RCNUM
:
526 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_RCNUM
, (unsigned long *) (& fields
->f_rcnum
));
528 case MS1_OPERAND_RDA
:
529 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_RDA
, (unsigned long *) (& fields
->f_rda
));
531 case MS1_OPERAND_ROWNUM
:
532 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM
, (unsigned long *) (& fields
->f_rownum
));
534 case MS1_OPERAND_ROWNUM1
:
535 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM1
, (unsigned long *) (& fields
->f_rownum1
));
537 case MS1_OPERAND_ROWNUM2
:
538 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM2
, (unsigned long *) (& fields
->f_rownum2
));
540 case MS1_OPERAND_SIZE
:
541 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_SIZE
, (unsigned long *) (& fields
->f_size
));
543 case MS1_OPERAND_TYPE
:
544 errmsg
= parse_type (cd
, strp
, MS1_OPERAND_TYPE
, (unsigned long *) (& fields
->f_type
));
546 case MS1_OPERAND_WR
:
547 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_WR
, (unsigned long *) (& fields
->f_wr
));
549 case MS1_OPERAND_XMODE
:
550 errmsg
= parse_xmode (cd
, strp
, MS1_OPERAND_XMODE
, (unsigned long *) (& fields
->f_xmode
));
554 /* xgettext:c-format */
555 fprintf (stderr
, _("Unrecognized field %d while parsing.\n"), opindex
);
562 cgen_parse_fn
* const ms1_cgen_parse_handlers
[] =
568 ms1_cgen_init_asm (cd
)
571 ms1_cgen_init_opcode_table (cd
);
572 ms1_cgen_init_ibld_table (cd
);
573 cd
->parse_handlers
= & ms1_cgen_parse_handlers
[0];
574 cd
->parse_operand
= ms1_cgen_parse_operand
;
579 /* Regex construction routine.
581 This translates an opcode syntax string into a regex string,
582 by replacing any non-character syntax element (such as an
583 opcode) with the pattern '.*'
585 It then compiles the regex and stores it in the opcode, for
586 later use by ms1_cgen_assemble_insn
588 Returns NULL for success, an error message for failure. */
591 ms1_cgen_build_insn_regex (CGEN_INSN
*insn
)
593 CGEN_OPCODE
*opc
= (CGEN_OPCODE
*) CGEN_INSN_OPCODE (insn
);
594 const char *mnem
= CGEN_INSN_MNEMONIC (insn
);
595 char rxbuf
[CGEN_MAX_RX_ELEMENTS
];
597 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
600 syn
= CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc
));
602 /* Mnemonics come first in the syntax string. */
603 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
604 return _("missing mnemonic in syntax string");
607 /* Generate a case sensitive regular expression that emulates case
608 insensitive matching in the "C" locale. We cannot generate a case
609 insensitive regular expression because in Turkish locales, 'i' and 'I'
610 are not equal modulo case conversion. */
612 /* Copy the literal mnemonic out of the insn. */
613 for (; *mnem
; mnem
++)
628 /* Copy any remaining literals from the syntax string into the rx. */
629 for(; * syn
!= 0 && rx
<= rxbuf
+ (CGEN_MAX_RX_ELEMENTS
- 7 - 4); ++syn
)
631 if (CGEN_SYNTAX_CHAR_P (* syn
))
633 char c
= CGEN_SYNTAX_CHAR (* syn
);
637 /* Escape any regex metacharacters in the syntax. */
638 case '.': case '[': case '\\':
639 case '*': case '^': case '$':
641 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
642 case '?': case '{': case '}':
643 case '(': case ')': case '*':
644 case '|': case '+': case ']':
665 /* Replace non-syntax fields with globs. */
671 /* Trailing whitespace ok. */
678 /* But anchor it after that. */
682 CGEN_INSN_RX (insn
) = xmalloc (sizeof (regex_t
));
683 reg_err
= regcomp ((regex_t
*) CGEN_INSN_RX (insn
), rxbuf
, REG_NOSUB
);
691 regerror (reg_err
, (regex_t
*) CGEN_INSN_RX (insn
), msg
, 80);
692 regfree ((regex_t
*) CGEN_INSN_RX (insn
));
693 free (CGEN_INSN_RX (insn
));
694 (CGEN_INSN_RX (insn
)) = NULL
;
700 /* Default insn parser.
702 The syntax string is scanned and operands are parsed and stored in FIELDS.
703 Relocs are queued as we go via other callbacks.
705 ??? Note that this is currently an all-or-nothing parser. If we fail to
706 parse the instruction, we return 0 and the caller will start over from
707 the beginning. Backtracking will be necessary in parsing subexpressions,
708 but that can be handled there. Not handling backtracking here may get
709 expensive in the case of the m68k. Deal with later.
711 Returns NULL for success, an error message for failure. */
714 parse_insn_normal (CGEN_CPU_DESC cd
,
715 const CGEN_INSN
*insn
,
719 /* ??? Runtime added insns not handled yet. */
720 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
721 const char *str
= *strp
;
724 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
725 #ifdef CGEN_MNEMONIC_OPERANDS
730 /* For now we assume the mnemonic is first (there are no leading operands).
731 We can parse it without needing to set up operand parsing.
732 GAS's input scrubber will ensure mnemonics are lowercase, but we may
733 not be called from GAS. */
734 p
= CGEN_INSN_MNEMONIC (insn
);
735 while (*p
&& TOLOWER (*p
) == TOLOWER (*str
))
739 return _("unrecognized instruction");
741 #ifndef CGEN_MNEMONIC_OPERANDS
742 if (* str
&& ! ISSPACE (* str
))
743 return _("unrecognized instruction");
746 CGEN_INIT_PARSE (cd
);
747 cgen_init_parse_operand (cd
);
748 #ifdef CGEN_MNEMONIC_OPERANDS
752 /* We don't check for (*str != '\0') here because we want to parse
753 any trailing fake arguments in the syntax string. */
754 syn
= CGEN_SYNTAX_STRING (syntax
);
756 /* Mnemonics come first for now, ensure valid string. */
757 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
764 /* Non operand chars must match exactly. */
765 if (CGEN_SYNTAX_CHAR_P (* syn
))
767 /* FIXME: While we allow for non-GAS callers above, we assume the
768 first char after the mnemonic part is a space. */
769 /* FIXME: We also take inappropriate advantage of the fact that
770 GAS's input scrubber will remove extraneous blanks. */
771 if (TOLOWER (*str
) == TOLOWER (CGEN_SYNTAX_CHAR (* syn
)))
773 #ifdef CGEN_MNEMONIC_OPERANDS
774 if (CGEN_SYNTAX_CHAR(* syn
) == ' ')
782 /* Syntax char didn't match. Can't be this insn. */
783 static char msg
[80];
785 /* xgettext:c-format */
786 sprintf (msg
, _("syntax error (expected char `%c', found `%c')"),
787 CGEN_SYNTAX_CHAR(*syn
), *str
);
792 /* Ran out of input. */
793 static char msg
[80];
795 /* xgettext:c-format */
796 sprintf (msg
, _("syntax error (expected char `%c', found end of instruction)"),
797 CGEN_SYNTAX_CHAR(*syn
));
803 /* We have an operand of some sort. */
804 errmsg
= cd
->parse_operand (cd
, CGEN_SYNTAX_FIELD (*syn
),
809 /* Done with this operand, continue with next one. */
813 /* If we're at the end of the syntax string, we're done. */
816 /* FIXME: For the moment we assume a valid `str' can only contain
817 blanks now. IE: We needn't try again with a longer version of
818 the insn and it is assumed that longer versions of insns appear
819 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
820 while (ISSPACE (* str
))
824 return _("junk at end of line"); /* FIXME: would like to include `str' */
829 /* We couldn't parse it. */
830 return _("unrecognized instruction");
834 This routine is called for each instruction to be assembled.
835 STR points to the insn to be assembled.
836 We assume all necessary tables have been initialized.
837 The assembled instruction, less any fixups, is stored in BUF.
838 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
839 still needs to be converted to target byte order, otherwise BUF is an array
840 of bytes in target byte order.
841 The result is a pointer to the insn's entry in the opcode table,
842 or NULL if an error occured (an error message will have already been
845 Note that when processing (non-alias) macro-insns,
846 this function recurses.
848 ??? It's possible to make this cpu-independent.
849 One would have to deal with a few minor things.
850 At this point in time doing so would be more of a curiosity than useful
851 [for example this file isn't _that_ big], but keeping the possibility in
852 mind helps keep the design clean. */
855 ms1_cgen_assemble_insn (CGEN_CPU_DESC cd
,
858 CGEN_INSN_BYTES_PTR buf
,
862 CGEN_INSN_LIST
*ilist
;
863 const char *parse_errmsg
= NULL
;
864 const char *insert_errmsg
= NULL
;
865 int recognized_mnemonic
= 0;
867 /* Skip leading white space. */
868 while (ISSPACE (* str
))
871 /* The instructions are stored in hashed lists.
872 Get the first in the list. */
873 ilist
= CGEN_ASM_LOOKUP_INSN (cd
, str
);
875 /* Keep looking until we find a match. */
877 for ( ; ilist
!= NULL
; ilist
= CGEN_ASM_NEXT_INSN (ilist
))
879 const CGEN_INSN
*insn
= ilist
->insn
;
880 recognized_mnemonic
= 1;
882 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
883 /* Not usually needed as unsupported opcodes
884 shouldn't be in the hash lists. */
885 /* Is this insn supported by the selected cpu? */
886 if (! ms1_cgen_insn_supported (cd
, insn
))
889 /* If the RELAXED attribute is set, this is an insn that shouldn't be
890 chosen immediately. Instead, it is used during assembler/linker
891 relaxation if possible. */
892 if (CGEN_INSN_ATTR_VALUE (insn
, CGEN_INSN_RELAXED
) != 0)
897 /* Skip this insn if str doesn't look right lexically. */
898 if (CGEN_INSN_RX (insn
) != NULL
&&
899 regexec ((regex_t
*) CGEN_INSN_RX (insn
), str
, 0, NULL
, 0) == REG_NOMATCH
)
902 /* Allow parse/insert handlers to obtain length of insn. */
903 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
905 parse_errmsg
= CGEN_PARSE_FN (cd
, insn
) (cd
, insn
, & str
, fields
);
906 if (parse_errmsg
!= NULL
)
909 /* ??? 0 is passed for `pc'. */
910 insert_errmsg
= CGEN_INSERT_FN (cd
, insn
) (cd
, insn
, fields
, buf
,
912 if (insert_errmsg
!= NULL
)
915 /* It is up to the caller to actually output the insn and any
921 static char errbuf
[150];
922 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
923 const char *tmp_errmsg
;
925 /* If requesting verbose error messages, use insert_errmsg.
926 Failing that, use parse_errmsg. */
927 tmp_errmsg
= (insert_errmsg
? insert_errmsg
:
928 parse_errmsg
? parse_errmsg
:
929 recognized_mnemonic
?
930 _("unrecognized form of instruction") :
931 _("unrecognized instruction"));
933 if (strlen (start
) > 50)
934 /* xgettext:c-format */
935 sprintf (errbuf
, "%s `%.50s...'", tmp_errmsg
, start
);
937 /* xgettext:c-format */
938 sprintf (errbuf
, "%s `%.50s'", tmp_errmsg
, start
);
940 if (strlen (start
) > 50)
941 /* xgettext:c-format */
942 sprintf (errbuf
, _("bad instruction `%.50s...'"), start
);
944 /* xgettext:c-format */
945 sprintf (errbuf
, _("bad instruction `%.50s'"), start
);
953 #if 0 /* This calls back to GAS which we can't do without care. */
955 /* Record each member of OPVALS in the assembler's symbol table.
956 This lets GAS parse registers for us.
957 ??? Interesting idea but not currently used. */
959 /* Record each member of OPVALS in the assembler's symbol table.
960 FIXME: Not currently used. */
963 ms1_cgen_asm_hash_keywords (CGEN_CPU_DESC cd
, CGEN_KEYWORD
*opvals
)
965 CGEN_KEYWORD_SEARCH search
= cgen_keyword_search_init (opvals
, NULL
);
966 const CGEN_KEYWORD_ENTRY
* ke
;
968 while ((ke
= cgen_keyword_search_next (& search
)) != NULL
)
970 #if 0 /* Unnecessary, should be done in the search routine. */
971 if (! ms1_cgen_opval_supported (ke
))
974 cgen_asm_record_register (cd
, ke
->name
, ke
->value
);