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 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 const char * parse_ulo16
52 PARAMS ((CGEN_CPU_DESC
, const char **, int, unsigned long *));
53 static const char * parse_uslo16
54 PARAMS ((CGEN_CPU_DESC
, const char **, int, unsigned long *));
55 static const char * parse_uhi16
56 PARAMS ((CGEN_CPU_DESC
, const char **, int, unsigned long *));
57 static long parse_register_number
58 PARAMS ((const char **));
59 static const char * parse_spr
60 PARAMS ((CGEN_CPU_DESC
, const char **, CGEN_KEYWORD
*, long *));
61 static const char * parse_d12
62 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *));
63 static const char * parse_s12
64 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *));
65 static const char * parse_u12
66 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *));
67 static const char * parse_even_register
68 PARAMS ((CGEN_CPU_DESC
, const char **, CGEN_KEYWORD
*, long *));
69 static const char * parse_A0
70 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *));
71 static const char * parse_A1
72 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *));
73 static const char * parse_A
74 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *, long));
77 parse_ulo16 (cd
, strp
, opindex
, valuep
)
81 unsigned long *valuep
;
84 enum cgen_parse_operand_result result_type
;
87 if (**strp
== '#' || **strp
== '%')
89 if (strncasecmp (*strp
+ 1, "lo(", 3) == 0)
92 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_LO16
,
93 &result_type
, &value
);
98 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
103 if (strncasecmp (*strp
+ 1, "gprello(", 8) == 0)
106 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPRELLO
,
107 &result_type
, &value
);
109 return "missing ')'";
112 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
117 else if (strncasecmp (*strp
+ 1, "gotlo(", 6) == 0)
120 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GOTLO
,
121 &result_type
, &value
);
123 return "missing ')'";
126 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
131 else if (strncasecmp (*strp
+ 1, "gotfuncdesclo(", 14) == 0)
134 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
135 BFD_RELOC_FRV_FUNCDESC_GOTLO
,
136 &result_type
, &value
);
138 return "missing ')'";
141 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
146 else if (strncasecmp (*strp
+ 1, "gotofflo(", 9) == 0)
149 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
150 BFD_RELOC_FRV_GOTOFFLO
,
151 &result_type
, &value
);
153 return "missing ')'";
156 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
161 else if (strncasecmp (*strp
+ 1, "gotofffuncdesclo(", 17) == 0)
164 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
165 BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
,
166 &result_type
, &value
);
168 return "missing ')'";
171 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
177 return cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
181 parse_uslo16 (cd
, strp
, opindex
, valuep
)
185 unsigned long *valuep
;
188 enum cgen_parse_operand_result result_type
;
191 if (**strp
== '#' || **strp
== '%')
193 if (strncasecmp (*strp
+ 1, "lo(", 3) == 0)
196 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_LO16
,
197 &result_type
, &value
);
199 return "missing `)'";
202 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
207 else if (strncasecmp (*strp
+ 1, "gprello(", 8) == 0)
210 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPRELLO
,
211 &result_type
, &value
);
213 return "missing ')'";
216 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
221 else if (strncasecmp (*strp
+ 1, "gotlo(", 6) == 0)
224 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GOTLO
,
225 &result_type
, &value
);
227 return "missing ')'";
230 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
235 else if (strncasecmp (*strp
+ 1, "gotfuncdesclo(", 14) == 0)
238 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
239 BFD_RELOC_FRV_FUNCDESC_GOTLO
,
240 &result_type
, &value
);
242 return "missing ')'";
245 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
250 else if (strncasecmp (*strp
+ 1, "gotofflo(", 9) == 0)
253 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
254 BFD_RELOC_FRV_GOTOFFLO
,
255 &result_type
, &value
);
257 return "missing ')'";
260 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
265 else if (strncasecmp (*strp
+ 1, "gotofffuncdesclo(", 17) == 0)
268 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
269 BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
,
270 &result_type
, &value
);
272 return "missing ')'";
275 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
281 return cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
285 parse_uhi16 (cd
, strp
, opindex
, valuep
)
289 unsigned long *valuep
;
292 enum cgen_parse_operand_result result_type
;
295 if (**strp
== '#' || **strp
== '%')
297 if (strncasecmp (*strp
+ 1, "hi(", 3) == 0)
300 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_HI16
,
301 &result_type
, &value
);
303 return "missing `)'";
306 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
311 else if (strncasecmp (*strp
+ 1, "gprelhi(", 8) == 0)
314 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPRELHI
,
315 &result_type
, &value
);
317 return "missing ')'";
320 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
325 else if (strncasecmp (*strp
+ 1, "gothi(", 6) == 0)
328 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GOTHI
,
329 &result_type
, &value
);
331 return "missing ')'";
334 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
339 else if (strncasecmp (*strp
+ 1, "gotfuncdeschi(", 14) == 0)
342 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
343 BFD_RELOC_FRV_FUNCDESC_GOTHI
,
344 &result_type
, &value
);
346 return "missing ')'";
349 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
354 else if (strncasecmp (*strp
+ 1, "gotoffhi(", 9) == 0)
357 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
358 BFD_RELOC_FRV_GOTOFFHI
,
359 &result_type
, &value
);
361 return "missing ')'";
364 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
369 else if (strncasecmp (*strp
+ 1, "gotofffuncdeschi(", 17) == 0)
372 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
373 BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
,
374 &result_type
, &value
);
376 return "missing ')'";
379 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
385 return cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
389 parse_register_number (strp
)
393 if (**strp
< '0' || **strp
> '9')
394 return -1; /* error */
396 regno
= **strp
- '0';
397 for (++*strp
; **strp
>= '0' && **strp
<= '9'; ++*strp
)
398 regno
= regno
* 10 + (**strp
- '0');
404 parse_spr (cd
, strp
, table
, valuep
)
407 CGEN_KEYWORD
* table
;
410 const char *save_strp
;
413 /* Check for spr index notation. */
414 if (strncasecmp (*strp
, "spr[", 4) == 0)
417 regno
= parse_register_number (strp
);
419 return "missing `]'";
421 if (! spr_valid (regno
))
422 return "Special purpose register number is out of range";
428 regno
= parse_register_number (strp
);
431 if (! spr_valid (regno
))
432 return "Special purpose register number is out of range";
438 return cgen_parse_keyword (cd
, strp
, table
, valuep
);
442 parse_d12 (cd
, strp
, opindex
, valuep
)
449 enum cgen_parse_operand_result result_type
;
452 /* Check for small data reference. */
453 if (**strp
== '#' || **strp
== '%')
455 if (strncasecmp (*strp
+ 1, "gprel12(", 8) == 0)
458 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPREL12
,
459 &result_type
, &value
);
461 return "missing `)'";
466 else if (strncasecmp (*strp
+ 1, "got12(", 6) == 0)
469 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GOT12
,
470 &result_type
, &value
);
472 return "missing ')'";
477 else if (strncasecmp (*strp
+ 1, "gotfuncdesc12(", 14) == 0)
480 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
481 BFD_RELOC_FRV_FUNCDESC_GOT12
,
482 &result_type
, &value
);
484 return "missing ')'";
489 else if (strncasecmp (*strp
+ 1, "gotoff12(", 9) == 0)
492 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
493 BFD_RELOC_FRV_GOTOFF12
,
494 &result_type
, &value
);
496 return "missing ')'";
501 else if (strncasecmp (*strp
+ 1, "gotofffuncdesc12(", 17) == 0)
504 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
505 BFD_RELOC_FRV_FUNCDESC_GOTOFF12
,
506 &result_type
, &value
);
508 return "missing ')'";
514 return cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
518 parse_s12 (cd
, strp
, opindex
, valuep
)
525 enum cgen_parse_operand_result result_type
;
528 /* Check for small data reference. */
529 if ((**strp
== '#' || **strp
== '%')
530 && strncasecmp (*strp
+ 1, "gprel12(", 8) == 0)
533 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPREL12
,
534 &result_type
, &value
);
536 return "missing `)'";
541 else if ((**strp
== '#' || **strp
== '%')
542 && strncasecmp (*strp
+ 1, "got12(", 6) == 0)
545 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GOT12
,
546 &result_type
, &value
);
548 return "missing ')'";
553 else if ((**strp
== '#' || **strp
== '%')
554 && strncasecmp (*strp
+ 1, "gotfuncdesc12(", 14) == 0)
557 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
558 BFD_RELOC_FRV_FUNCDESC_GOT12
,
559 &result_type
, &value
);
561 return "missing ')'";
566 else if ((**strp
== '#' || **strp
== '%')
567 && strncasecmp (*strp
+ 1, "gotoff12(", 9) == 0)
570 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GOTOFF12
,
571 &result_type
, &value
);
573 return "missing ')'";
578 else if ((**strp
== '#' || **strp
== '%')
579 && strncasecmp (*strp
+ 1, "gotofffuncdesc12(", 17) == 0)
582 errmsg
= cgen_parse_address (cd
, strp
, opindex
,
583 BFD_RELOC_FRV_FUNCDESC_GOTOFF12
,
584 &result_type
, &value
);
586 return "missing ')'";
595 return cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
600 parse_u12 (cd
, strp
, opindex
, valuep
)
607 enum cgen_parse_operand_result result_type
;
610 /* Check for small data reference. */
611 if ((**strp
== '#' || **strp
== '%')
612 && strncasecmp (*strp
+ 1, "gprel12(", 8) == 0)
615 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPRELU12
,
616 &result_type
, &value
);
618 return "missing `)'";
627 return cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
632 parse_A (cd
, strp
, opindex
, valuep
, A
)
644 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
649 return "Value of A operand must be 0 or 1";
655 parse_A0 (cd
, strp
, opindex
, valuep
)
661 return parse_A (cd
, strp
, opindex
, valuep
, 0);
665 parse_A1 (cd
, strp
, opindex
, valuep
)
671 return parse_A (cd
, strp
, opindex
, valuep
, 1);
675 parse_even_register (cd
, strP
, tableP
, valueP
)
678 CGEN_KEYWORD
* tableP
;
682 const char * saved_star_strP
= * strP
;
684 errmsg
= cgen_parse_keyword (cd
, strP
, tableP
, valueP
);
686 if (errmsg
== NULL
&& ((* valueP
) & 1))
688 errmsg
= _("register number must be even");
689 * strP
= saved_star_strP
;
696 const char * frv_cgen_parse_operand
697 PARAMS ((CGEN_CPU_DESC
, int, const char **, CGEN_FIELDS
*));
699 /* Main entry point for operand parsing.
701 This function is basically just a big switch statement. Earlier versions
702 used tables to look up the function to use, but
703 - if the table contains both assembler and disassembler functions then
704 the disassembler contains much of the assembler and vice-versa,
705 - there's a lot of inlining possibilities as things grow,
706 - using a switch statement avoids the function call overhead.
708 This function could be moved into `parse_insn_normal', but keeping it
709 separate makes clear the interface between `parse_insn_normal' and each of
713 frv_cgen_parse_operand (cd
, opindex
, strp
, fields
)
717 CGEN_FIELDS
* fields
;
719 const char * errmsg
= NULL
;
720 /* Used by scalar operands that still need to be parsed. */
721 long junk ATTRIBUTE_UNUSED
;
725 case FRV_OPERAND_A0
:
726 errmsg
= parse_A0 (cd
, strp
, FRV_OPERAND_A0
, &fields
->f_A
);
728 case FRV_OPERAND_A1
:
729 errmsg
= parse_A1 (cd
, strp
, FRV_OPERAND_A1
, &fields
->f_A
);
731 case FRV_OPERAND_ACC40SI
:
732 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_acc_names
, & fields
->f_ACC40Si
);
734 case FRV_OPERAND_ACC40SK
:
735 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_acc_names
, & fields
->f_ACC40Sk
);
737 case FRV_OPERAND_ACC40UI
:
738 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_acc_names
, & fields
->f_ACC40Ui
);
740 case FRV_OPERAND_ACC40UK
:
741 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_acc_names
, & fields
->f_ACC40Uk
);
743 case FRV_OPERAND_ACCGI
:
744 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_accg_names
, & fields
->f_ACCGi
);
746 case FRV_OPERAND_ACCGK
:
747 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_accg_names
, & fields
->f_ACCGk
);
749 case FRV_OPERAND_CCI
:
750 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CCi
);
752 case FRV_OPERAND_CPRDOUBLEK
:
753 errmsg
= parse_even_register (cd
, strp
, & frv_cgen_opval_cpr_names
, & fields
->f_CPRk
);
755 case FRV_OPERAND_CPRI
:
756 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cpr_names
, & fields
->f_CPRi
);
758 case FRV_OPERAND_CPRJ
:
759 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cpr_names
, & fields
->f_CPRj
);
761 case FRV_OPERAND_CPRK
:
762 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cpr_names
, & fields
->f_CPRk
);
764 case FRV_OPERAND_CRI
:
765 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRi
);
767 case FRV_OPERAND_CRJ
:
768 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRj
);
770 case FRV_OPERAND_CRJ_FLOAT
:
771 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRj_float
);
773 case FRV_OPERAND_CRJ_INT
:
774 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRj_int
);
776 case FRV_OPERAND_CRK
:
777 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRk
);
779 case FRV_OPERAND_FCCI_1
:
780 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fccr_names
, & fields
->f_FCCi_1
);
782 case FRV_OPERAND_FCCI_2
:
783 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fccr_names
, & fields
->f_FCCi_2
);
785 case FRV_OPERAND_FCCI_3
:
786 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fccr_names
, & fields
->f_FCCi_3
);
788 case FRV_OPERAND_FCCK
:
789 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fccr_names
, & fields
->f_FCCk
);
791 case FRV_OPERAND_FRDOUBLEI
:
792 errmsg
= parse_even_register (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRi
);
794 case FRV_OPERAND_FRDOUBLEJ
:
795 errmsg
= parse_even_register (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRj
);
797 case FRV_OPERAND_FRDOUBLEK
:
798 errmsg
= parse_even_register (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
800 case FRV_OPERAND_FRI
:
801 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRi
);
803 case FRV_OPERAND_FRINTI
:
804 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRi
);
806 case FRV_OPERAND_FRINTIEVEN
:
807 errmsg
= parse_even_register (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRi
);
809 case FRV_OPERAND_FRINTJ
:
810 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRj
);
812 case FRV_OPERAND_FRINTJEVEN
:
813 errmsg
= parse_even_register (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRj
);
815 case FRV_OPERAND_FRINTK
:
816 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
818 case FRV_OPERAND_FRINTKEVEN
:
819 errmsg
= parse_even_register (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
821 case FRV_OPERAND_FRJ
:
822 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRj
);
824 case FRV_OPERAND_FRK
:
825 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
827 case FRV_OPERAND_FRKHI
:
828 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
830 case FRV_OPERAND_FRKLO
:
831 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
833 case FRV_OPERAND_GRDOUBLEK
:
834 errmsg
= parse_even_register (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRk
);
836 case FRV_OPERAND_GRI
:
837 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRi
);
839 case FRV_OPERAND_GRJ
:
840 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRj
);
842 case FRV_OPERAND_GRK
:
843 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRk
);
845 case FRV_OPERAND_GRKHI
:
846 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRk
);
848 case FRV_OPERAND_GRKLO
:
849 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRk
);
851 case FRV_OPERAND_ICCI_1
:
852 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_iccr_names
, & fields
->f_ICCi_1
);
854 case FRV_OPERAND_ICCI_2
:
855 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_iccr_names
, & fields
->f_ICCi_2
);
857 case FRV_OPERAND_ICCI_3
:
858 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_iccr_names
, & fields
->f_ICCi_3
);
860 case FRV_OPERAND_LI
:
861 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_LI
, &fields
->f_LI
);
863 case FRV_OPERAND_LRAD
:
864 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_LRAD
, &fields
->f_LRAD
);
866 case FRV_OPERAND_LRAE
:
867 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_LRAE
, &fields
->f_LRAE
);
869 case FRV_OPERAND_LRAS
:
870 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_LRAS
, &fields
->f_LRAS
);
872 case FRV_OPERAND_TLBPRL
:
873 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_TLBPRL
, &fields
->f_TLBPRL
);
875 case FRV_OPERAND_TLBPROPX
:
876 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_TLBPROPX
, &fields
->f_TLBPRopx
);
878 case FRV_OPERAND_AE
:
879 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_AE
, &fields
->f_ae
);
881 case FRV_OPERAND_CCOND
:
882 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_CCOND
, &fields
->f_ccond
);
884 case FRV_OPERAND_COND
:
885 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_COND
, &fields
->f_cond
);
887 case FRV_OPERAND_D12
:
888 errmsg
= parse_d12 (cd
, strp
, FRV_OPERAND_D12
, &fields
->f_d12
);
890 case FRV_OPERAND_DEBUG
:
891 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_DEBUG
, &fields
->f_debug
);
893 case FRV_OPERAND_EIR
:
894 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_EIR
, &fields
->f_eir
);
896 case FRV_OPERAND_HINT
:
897 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_HINT
, &fields
->f_hint
);
899 case FRV_OPERAND_HINT_NOT_TAKEN
:
900 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_h_hint_not_taken
, & fields
->f_hint
);
902 case FRV_OPERAND_HINT_TAKEN
:
903 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_h_hint_taken
, & fields
->f_hint
);
905 case FRV_OPERAND_LABEL16
:
908 errmsg
= cgen_parse_address (cd
, strp
, FRV_OPERAND_LABEL16
, 0, NULL
, & value
);
909 fields
->f_label16
= value
;
912 case FRV_OPERAND_LABEL24
:
915 errmsg
= cgen_parse_address (cd
, strp
, FRV_OPERAND_LABEL24
, 0, NULL
, & value
);
916 fields
->f_label24
= value
;
919 case FRV_OPERAND_LOCK
:
920 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_LOCK
, &fields
->f_lock
);
922 case FRV_OPERAND_PACK
:
923 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_h_pack
, & fields
->f_pack
);
925 case FRV_OPERAND_S10
:
926 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S10
, &fields
->f_s10
);
928 case FRV_OPERAND_S12
:
929 errmsg
= parse_s12 (cd
, strp
, FRV_OPERAND_S12
, &fields
->f_d12
);
931 case FRV_OPERAND_S16
:
932 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S16
, &fields
->f_s16
);
934 case FRV_OPERAND_S5
:
935 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S5
, &fields
->f_s5
);
937 case FRV_OPERAND_S6
:
938 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S6
, &fields
->f_s6
);
940 case FRV_OPERAND_S6_1
:
941 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S6_1
, &fields
->f_s6_1
);
943 case FRV_OPERAND_SLO16
:
944 errmsg
= parse_uslo16 (cd
, strp
, FRV_OPERAND_SLO16
, &fields
->f_s16
);
946 case FRV_OPERAND_SPR
:
947 errmsg
= parse_spr (cd
, strp
, & frv_cgen_opval_spr_names
, & fields
->f_spr
);
949 case FRV_OPERAND_U12
:
950 errmsg
= parse_u12 (cd
, strp
, FRV_OPERAND_U12
, &fields
->f_u12
);
952 case FRV_OPERAND_U16
:
953 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_U16
, &fields
->f_u16
);
955 case FRV_OPERAND_U6
:
956 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_U6
, &fields
->f_u6
);
958 case FRV_OPERAND_UHI16
:
959 errmsg
= parse_uhi16 (cd
, strp
, FRV_OPERAND_UHI16
, &fields
->f_u16
);
961 case FRV_OPERAND_ULO16
:
962 errmsg
= parse_ulo16 (cd
, strp
, FRV_OPERAND_ULO16
, &fields
->f_u16
);
966 /* xgettext:c-format */
967 fprintf (stderr
, _("Unrecognized field %d while parsing.\n"), opindex
);
974 cgen_parse_fn
* const frv_cgen_parse_handlers
[] =
980 frv_cgen_init_asm (cd
)
983 frv_cgen_init_opcode_table (cd
);
984 frv_cgen_init_ibld_table (cd
);
985 cd
->parse_handlers
= & frv_cgen_parse_handlers
[0];
986 cd
->parse_operand
= frv_cgen_parse_operand
;
991 /* Regex construction routine.
993 This translates an opcode syntax string into a regex string,
994 by replacing any non-character syntax element (such as an
995 opcode) with the pattern '.*'
997 It then compiles the regex and stores it in the opcode, for
998 later use by frv_cgen_assemble_insn
1000 Returns NULL for success, an error message for failure. */
1003 frv_cgen_build_insn_regex (CGEN_INSN
*insn
)
1005 CGEN_OPCODE
*opc
= (CGEN_OPCODE
*) CGEN_INSN_OPCODE (insn
);
1006 const char *mnem
= CGEN_INSN_MNEMONIC (insn
);
1007 char rxbuf
[CGEN_MAX_RX_ELEMENTS
];
1009 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
1012 syn
= CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc
));
1014 /* Mnemonics come first in the syntax string. */
1015 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
1016 return _("missing mnemonic in syntax string");
1019 /* Generate a case sensitive regular expression that emulates case
1020 insensitive matching in the "C" locale. We cannot generate a case
1021 insensitive regular expression because in Turkish locales, 'i' and 'I'
1022 are not equal modulo case conversion. */
1024 /* Copy the literal mnemonic out of the insn. */
1025 for (; *mnem
; mnem
++)
1032 *rx
++ = TOLOWER (c
);
1033 *rx
++ = TOUPPER (c
);
1040 /* Copy any remaining literals from the syntax string into the rx. */
1041 for(; * syn
!= 0 && rx
<= rxbuf
+ (CGEN_MAX_RX_ELEMENTS
- 7 - 4); ++syn
)
1043 if (CGEN_SYNTAX_CHAR_P (* syn
))
1045 char c
= CGEN_SYNTAX_CHAR (* syn
);
1049 /* Escape any regex metacharacters in the syntax. */
1050 case '.': case '[': case '\\':
1051 case '*': case '^': case '$':
1053 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
1054 case '?': case '{': case '}':
1055 case '(': case ')': case '*':
1056 case '|': case '+': case ']':
1066 *rx
++ = TOLOWER (c
);
1067 *rx
++ = TOUPPER (c
);
1077 /* Replace non-syntax fields with globs. */
1083 /* Trailing whitespace ok. */
1090 /* But anchor it after that. */
1094 CGEN_INSN_RX (insn
) = xmalloc (sizeof (regex_t
));
1095 reg_err
= regcomp ((regex_t
*) CGEN_INSN_RX (insn
), rxbuf
, REG_NOSUB
);
1101 static char msg
[80];
1103 regerror (reg_err
, (regex_t
*) CGEN_INSN_RX (insn
), msg
, 80);
1104 regfree ((regex_t
*) CGEN_INSN_RX (insn
));
1105 free (CGEN_INSN_RX (insn
));
1106 (CGEN_INSN_RX (insn
)) = NULL
;
1112 /* Default insn parser.
1114 The syntax string is scanned and operands are parsed and stored in FIELDS.
1115 Relocs are queued as we go via other callbacks.
1117 ??? Note that this is currently an all-or-nothing parser. If we fail to
1118 parse the instruction, we return 0 and the caller will start over from
1119 the beginning. Backtracking will be necessary in parsing subexpressions,
1120 but that can be handled there. Not handling backtracking here may get
1121 expensive in the case of the m68k. Deal with later.
1123 Returns NULL for success, an error message for failure. */
1126 parse_insn_normal (CGEN_CPU_DESC cd
,
1127 const CGEN_INSN
*insn
,
1129 CGEN_FIELDS
*fields
)
1131 /* ??? Runtime added insns not handled yet. */
1132 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
1133 const char *str
= *strp
;
1136 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
1137 #ifdef CGEN_MNEMONIC_OPERANDS
1142 /* For now we assume the mnemonic is first (there are no leading operands).
1143 We can parse it without needing to set up operand parsing.
1144 GAS's input scrubber will ensure mnemonics are lowercase, but we may
1145 not be called from GAS. */
1146 p
= CGEN_INSN_MNEMONIC (insn
);
1147 while (*p
&& TOLOWER (*p
) == TOLOWER (*str
))
1151 return _("unrecognized instruction");
1153 #ifndef CGEN_MNEMONIC_OPERANDS
1154 if (* str
&& ! ISSPACE (* str
))
1155 return _("unrecognized instruction");
1158 CGEN_INIT_PARSE (cd
);
1159 cgen_init_parse_operand (cd
);
1160 #ifdef CGEN_MNEMONIC_OPERANDS
1164 /* We don't check for (*str != '\0') here because we want to parse
1165 any trailing fake arguments in the syntax string. */
1166 syn
= CGEN_SYNTAX_STRING (syntax
);
1168 /* Mnemonics come first for now, ensure valid string. */
1169 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
1176 /* Non operand chars must match exactly. */
1177 if (CGEN_SYNTAX_CHAR_P (* syn
))
1179 /* FIXME: While we allow for non-GAS callers above, we assume the
1180 first char after the mnemonic part is a space. */
1181 /* FIXME: We also take inappropriate advantage of the fact that
1182 GAS's input scrubber will remove extraneous blanks. */
1183 if (TOLOWER (*str
) == TOLOWER (CGEN_SYNTAX_CHAR (* syn
)))
1185 #ifdef CGEN_MNEMONIC_OPERANDS
1186 if (CGEN_SYNTAX_CHAR(* syn
) == ' ')
1194 /* Syntax char didn't match. Can't be this insn. */
1195 static char msg
[80];
1197 /* xgettext:c-format */
1198 sprintf (msg
, _("syntax error (expected char `%c', found `%c')"),
1199 CGEN_SYNTAX_CHAR(*syn
), *str
);
1204 /* Ran out of input. */
1205 static char msg
[80];
1207 /* xgettext:c-format */
1208 sprintf (msg
, _("syntax error (expected char `%c', found end of instruction)"),
1209 CGEN_SYNTAX_CHAR(*syn
));
1215 /* We have an operand of some sort. */
1216 errmsg
= cd
->parse_operand (cd
, CGEN_SYNTAX_FIELD (*syn
),
1221 /* Done with this operand, continue with next one. */
1225 /* If we're at the end of the syntax string, we're done. */
1228 /* FIXME: For the moment we assume a valid `str' can only contain
1229 blanks now. IE: We needn't try again with a longer version of
1230 the insn and it is assumed that longer versions of insns appear
1231 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1232 while (ISSPACE (* str
))
1236 return _("junk at end of line"); /* FIXME: would like to include `str' */
1241 /* We couldn't parse it. */
1242 return _("unrecognized instruction");
1245 /* Main entry point.
1246 This routine is called for each instruction to be assembled.
1247 STR points to the insn to be assembled.
1248 We assume all necessary tables have been initialized.
1249 The assembled instruction, less any fixups, is stored in BUF.
1250 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
1251 still needs to be converted to target byte order, otherwise BUF is an array
1252 of bytes in target byte order.
1253 The result is a pointer to the insn's entry in the opcode table,
1254 or NULL if an error occured (an error message will have already been
1257 Note that when processing (non-alias) macro-insns,
1258 this function recurses.
1260 ??? It's possible to make this cpu-independent.
1261 One would have to deal with a few minor things.
1262 At this point in time doing so would be more of a curiosity than useful
1263 [for example this file isn't _that_ big], but keeping the possibility in
1264 mind helps keep the design clean. */
1267 frv_cgen_assemble_insn (CGEN_CPU_DESC cd
,
1269 CGEN_FIELDS
*fields
,
1270 CGEN_INSN_BYTES_PTR buf
,
1274 CGEN_INSN_LIST
*ilist
;
1275 const char *parse_errmsg
= NULL
;
1276 const char *insert_errmsg
= NULL
;
1277 int recognized_mnemonic
= 0;
1279 /* Skip leading white space. */
1280 while (ISSPACE (* str
))
1283 /* The instructions are stored in hashed lists.
1284 Get the first in the list. */
1285 ilist
= CGEN_ASM_LOOKUP_INSN (cd
, str
);
1287 /* Keep looking until we find a match. */
1289 for ( ; ilist
!= NULL
; ilist
= CGEN_ASM_NEXT_INSN (ilist
))
1291 const CGEN_INSN
*insn
= ilist
->insn
;
1292 recognized_mnemonic
= 1;
1294 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
1295 /* Not usually needed as unsupported opcodes
1296 shouldn't be in the hash lists. */
1297 /* Is this insn supported by the selected cpu? */
1298 if (! frv_cgen_insn_supported (cd
, insn
))
1301 /* If the RELAXED attribute is set, this is an insn that shouldn't be
1302 chosen immediately. Instead, it is used during assembler/linker
1303 relaxation if possible. */
1304 if (CGEN_INSN_ATTR_VALUE (insn
, CGEN_INSN_RELAXED
) != 0)
1309 /* Skip this insn if str doesn't look right lexically. */
1310 if (CGEN_INSN_RX (insn
) != NULL
&&
1311 regexec ((regex_t
*) CGEN_INSN_RX (insn
), str
, 0, NULL
, 0) == REG_NOMATCH
)
1314 /* Allow parse/insert handlers to obtain length of insn. */
1315 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
1317 parse_errmsg
= CGEN_PARSE_FN (cd
, insn
) (cd
, insn
, & str
, fields
);
1318 if (parse_errmsg
!= NULL
)
1321 /* ??? 0 is passed for `pc'. */
1322 insert_errmsg
= CGEN_INSERT_FN (cd
, insn
) (cd
, insn
, fields
, buf
,
1324 if (insert_errmsg
!= NULL
)
1327 /* It is up to the caller to actually output the insn and any
1333 static char errbuf
[150];
1334 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
1335 const char *tmp_errmsg
;
1337 /* If requesting verbose error messages, use insert_errmsg.
1338 Failing that, use parse_errmsg. */
1339 tmp_errmsg
= (insert_errmsg
? insert_errmsg
:
1340 parse_errmsg
? parse_errmsg
:
1341 recognized_mnemonic
?
1342 _("unrecognized form of instruction") :
1343 _("unrecognized instruction"));
1345 if (strlen (start
) > 50)
1346 /* xgettext:c-format */
1347 sprintf (errbuf
, "%s `%.50s...'", tmp_errmsg
, start
);
1349 /* xgettext:c-format */
1350 sprintf (errbuf
, "%s `%.50s'", tmp_errmsg
, start
);
1352 if (strlen (start
) > 50)
1353 /* xgettext:c-format */
1354 sprintf (errbuf
, _("bad instruction `%.50s...'"), start
);
1356 /* xgettext:c-format */
1357 sprintf (errbuf
, _("bad instruction `%.50s'"), start
);
1365 #if 0 /* This calls back to GAS which we can't do without care. */
1367 /* Record each member of OPVALS in the assembler's symbol table.
1368 This lets GAS parse registers for us.
1369 ??? Interesting idea but not currently used. */
1371 /* Record each member of OPVALS in the assembler's symbol table.
1372 FIXME: Not currently used. */
1375 frv_cgen_asm_hash_keywords (CGEN_CPU_DESC cd
, CGEN_KEYWORD
*opvals
)
1377 CGEN_KEYWORD_SEARCH search
= cgen_keyword_search_init (opvals
, NULL
);
1378 const CGEN_KEYWORD_ENTRY
* ke
;
1380 while ((ke
= cgen_keyword_search_next (& search
)) != NULL
)
1382 #if 0 /* Unnecessary, should be done in the search routine. */
1383 if (! frv_cgen_opval_supported (ke
))
1386 cgen_asm_record_register (cd
, ke
->name
, ke
->value
);