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_AE :
864 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_AE, &fields->f_ae);
866 case FRV_OPERAND_CCOND :
867 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_CCOND, &fields->f_ccond);
869 case FRV_OPERAND_COND :
870 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_COND, &fields->f_cond);
872 case FRV_OPERAND_D12 :
873 errmsg = parse_d12 (cd, strp, FRV_OPERAND_D12, &fields->f_d12);
875 case FRV_OPERAND_DEBUG :
876 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_DEBUG, &fields->f_debug);
878 case FRV_OPERAND_EIR :
879 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_EIR, &fields->f_eir);
881 case FRV_OPERAND_HINT :
882 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_HINT, &fields->f_hint);
884 case FRV_OPERAND_HINT_NOT_TAKEN :
885 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_hint_not_taken, & fields->f_hint);
887 case FRV_OPERAND_HINT_TAKEN :
888 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_hint_taken, & fields->f_hint);
890 case FRV_OPERAND_LABEL16 :
893 errmsg = cgen_parse_address (cd, strp, FRV_OPERAND_LABEL16, 0, NULL, & value);
894 fields->f_label16 = value;
897 case FRV_OPERAND_LABEL24 :
900 errmsg = cgen_parse_address (cd, strp, FRV_OPERAND_LABEL24, 0, NULL, & value);
901 fields->f_label24 = value;
904 case FRV_OPERAND_LOCK :
905 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LOCK, &fields->f_lock);
907 case FRV_OPERAND_PACK :
908 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_pack, & fields->f_pack);
910 case FRV_OPERAND_S10 :
911 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S10, &fields->f_s10);
913 case FRV_OPERAND_S12 :
914 errmsg = parse_s12 (cd, strp, FRV_OPERAND_S12, &fields->f_d12);
916 case FRV_OPERAND_S16 :
917 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S16, &fields->f_s16);
919 case FRV_OPERAND_S5 :
920 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S5, &fields->f_s5);
922 case FRV_OPERAND_S6 :
923 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S6, &fields->f_s6);
925 case FRV_OPERAND_S6_1 :
926 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S6_1, &fields->f_s6_1);
928 case FRV_OPERAND_SLO16 :
929 errmsg = parse_uslo16 (cd, strp, FRV_OPERAND_SLO16, &fields->f_s16);
931 case FRV_OPERAND_SPR :
932 errmsg = parse_spr (cd, strp, & frv_cgen_opval_spr_names, & fields->f_spr);
934 case FRV_OPERAND_U12 :
935 errmsg = parse_u12 (cd, strp, FRV_OPERAND_U12, &fields->f_u12);
937 case FRV_OPERAND_U16 :
938 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_U16, &fields->f_u16);
940 case FRV_OPERAND_U6 :
941 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_U6, &fields->f_u6);
943 case FRV_OPERAND_UHI16 :
944 errmsg = parse_uhi16 (cd, strp, FRV_OPERAND_UHI16, &fields->f_u16);
946 case FRV_OPERAND_ULO16 :
947 errmsg = parse_ulo16 (cd, strp, FRV_OPERAND_ULO16, &fields->f_u16);
951 /* xgettext:c-format */
952 fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
959 cgen_parse_fn * const frv_cgen_parse_handlers[] =
965 frv_cgen_init_asm (cd)
968 frv_cgen_init_opcode_table (cd);
969 frv_cgen_init_ibld_table (cd);
970 cd->parse_handlers = & frv_cgen_parse_handlers[0];
971 cd->parse_operand = frv_cgen_parse_operand;
976 /* Regex construction routine.
978 This translates an opcode syntax string into a regex string,
979 by replacing any non-character syntax element (such as an
980 opcode) with the pattern '.*'
982 It then compiles the regex and stores it in the opcode, for
983 later use by frv_cgen_assemble_insn
985 Returns NULL for success, an error message for failure. */
988 frv_cgen_build_insn_regex (CGEN_INSN *insn)
990 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
991 const char *mnem = CGEN_INSN_MNEMONIC (insn);
992 char rxbuf[CGEN_MAX_RX_ELEMENTS];
994 const CGEN_SYNTAX_CHAR_TYPE *syn;
997 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
999 /* Mnemonics come first in the syntax string. */
1000 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1001 return _("missing mnemonic in syntax string");
1004 /* Generate a case sensitive regular expression that emulates case
1005 insensitive matching in the "C" locale. We cannot generate a case
1006 insensitive regular expression because in Turkish locales, 'i' and 'I'
1007 are not equal modulo case conversion. */
1009 /* Copy the literal mnemonic out of the insn. */
1010 for (; *mnem; mnem++)
1017 *rx++ = TOLOWER (c);
1018 *rx++ = TOUPPER (c);
1025 /* Copy any remaining literals from the syntax string into the rx. */
1026 for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
1028 if (CGEN_SYNTAX_CHAR_P (* syn))
1030 char c = CGEN_SYNTAX_CHAR (* syn);
1034 /* Escape any regex metacharacters in the syntax. */
1035 case '.': case '[': case '\\':
1036 case '*': case '^': case '$':
1038 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
1039 case '?': case '{': case '}':
1040 case '(': case ')': case '*':
1041 case '|': case '+': case ']':
1051 *rx++ = TOLOWER (c);
1052 *rx++ = TOUPPER (c);
1062 /* Replace non-syntax fields with globs. */
1068 /* Trailing whitespace ok. */
1075 /* But anchor it after that. */
1079 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
1080 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
1086 static char msg[80];
1088 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
1089 regfree ((regex_t *) CGEN_INSN_RX (insn));
1090 free (CGEN_INSN_RX (insn));
1091 (CGEN_INSN_RX (insn)) = NULL;
1097 /* Default insn parser.
1099 The syntax string is scanned and operands are parsed and stored in FIELDS.
1100 Relocs are queued as we go via other callbacks.
1102 ??? Note that this is currently an all-or-nothing parser. If we fail to
1103 parse the instruction, we return 0 and the caller will start over from
1104 the beginning. Backtracking will be necessary in parsing subexpressions,
1105 but that can be handled there. Not handling backtracking here may get
1106 expensive in the case of the m68k. Deal with later.
1108 Returns NULL for success, an error message for failure. */
1111 parse_insn_normal (CGEN_CPU_DESC cd,
1112 const CGEN_INSN *insn,
1114 CGEN_FIELDS *fields)
1116 /* ??? Runtime added insns not handled yet. */
1117 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
1118 const char *str = *strp;
1121 const CGEN_SYNTAX_CHAR_TYPE * syn;
1122 #ifdef CGEN_MNEMONIC_OPERANDS
1127 /* For now we assume the mnemonic is first (there are no leading operands).
1128 We can parse it without needing to set up operand parsing.
1129 GAS's input scrubber will ensure mnemonics are lowercase, but we may
1130 not be called from GAS. */
1131 p = CGEN_INSN_MNEMONIC (insn);
1132 while (*p && TOLOWER (*p) == TOLOWER (*str))
1136 return _("unrecognized instruction");
1138 #ifndef CGEN_MNEMONIC_OPERANDS
1139 if (* str && ! ISSPACE (* str))
1140 return _("unrecognized instruction");
1143 CGEN_INIT_PARSE (cd);
1144 cgen_init_parse_operand (cd);
1145 #ifdef CGEN_MNEMONIC_OPERANDS
1149 /* We don't check for (*str != '\0') here because we want to parse
1150 any trailing fake arguments in the syntax string. */
1151 syn = CGEN_SYNTAX_STRING (syntax);
1153 /* Mnemonics come first for now, ensure valid string. */
1154 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1161 /* Non operand chars must match exactly. */
1162 if (CGEN_SYNTAX_CHAR_P (* syn))
1164 /* FIXME: While we allow for non-GAS callers above, we assume the
1165 first char after the mnemonic part is a space. */
1166 /* FIXME: We also take inappropriate advantage of the fact that
1167 GAS's input scrubber will remove extraneous blanks. */
1168 if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
1170 #ifdef CGEN_MNEMONIC_OPERANDS
1171 if (CGEN_SYNTAX_CHAR(* syn) == ' ')
1179 /* Syntax char didn't match. Can't be this insn. */
1180 static char msg [80];
1182 /* xgettext:c-format */
1183 sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
1184 CGEN_SYNTAX_CHAR(*syn), *str);
1189 /* Ran out of input. */
1190 static char msg [80];
1192 /* xgettext:c-format */
1193 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
1194 CGEN_SYNTAX_CHAR(*syn));
1200 /* We have an operand of some sort. */
1201 errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
1206 /* Done with this operand, continue with next one. */
1210 /* If we're at the end of the syntax string, we're done. */
1213 /* FIXME: For the moment we assume a valid `str' can only contain
1214 blanks now. IE: We needn't try again with a longer version of
1215 the insn and it is assumed that longer versions of insns appear
1216 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1217 while (ISSPACE (* str))
1221 return _("junk at end of line"); /* FIXME: would like to include `str' */
1226 /* We couldn't parse it. */
1227 return _("unrecognized instruction");
1230 /* Main entry point.
1231 This routine is called for each instruction to be assembled.
1232 STR points to the insn to be assembled.
1233 We assume all necessary tables have been initialized.
1234 The assembled instruction, less any fixups, is stored in BUF.
1235 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
1236 still needs to be converted to target byte order, otherwise BUF is an array
1237 of bytes in target byte order.
1238 The result is a pointer to the insn's entry in the opcode table,
1239 or NULL if an error occured (an error message will have already been
1242 Note that when processing (non-alias) macro-insns,
1243 this function recurses.
1245 ??? It's possible to make this cpu-independent.
1246 One would have to deal with a few minor things.
1247 At this point in time doing so would be more of a curiosity than useful
1248 [for example this file isn't _that_ big], but keeping the possibility in
1249 mind helps keep the design clean. */
1252 frv_cgen_assemble_insn (CGEN_CPU_DESC cd,
1254 CGEN_FIELDS *fields,
1255 CGEN_INSN_BYTES_PTR buf,
1259 CGEN_INSN_LIST *ilist;
1260 const char *parse_errmsg = NULL;
1261 const char *insert_errmsg = NULL;
1262 int recognized_mnemonic = 0;
1264 /* Skip leading white space. */
1265 while (ISSPACE (* str))
1268 /* The instructions are stored in hashed lists.
1269 Get the first in the list. */
1270 ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
1272 /* Keep looking until we find a match. */
1274 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
1276 const CGEN_INSN *insn = ilist->insn;
1277 recognized_mnemonic = 1;
1279 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
1280 /* Not usually needed as unsupported opcodes
1281 shouldn't be in the hash lists. */
1282 /* Is this insn supported by the selected cpu? */
1283 if (! frv_cgen_insn_supported (cd, insn))
1286 /* If the RELAXED attribute is set, this is an insn that shouldn't be
1287 chosen immediately. Instead, it is used during assembler/linker
1288 relaxation if possible. */
1289 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
1294 /* Skip this insn if str doesn't look right lexically. */
1295 if (CGEN_INSN_RX (insn) != NULL &&
1296 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
1299 /* Allow parse/insert handlers to obtain length of insn. */
1300 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
1302 parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
1303 if (parse_errmsg != NULL)
1306 /* ??? 0 is passed for `pc'. */
1307 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
1309 if (insert_errmsg != NULL)
1312 /* It is up to the caller to actually output the insn and any
1318 static char errbuf[150];
1319 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
1320 const char *tmp_errmsg;
1322 /* If requesting verbose error messages, use insert_errmsg.
1323 Failing that, use parse_errmsg. */
1324 tmp_errmsg = (insert_errmsg ? insert_errmsg :
1325 parse_errmsg ? parse_errmsg :
1326 recognized_mnemonic ?
1327 _("unrecognized form of instruction") :
1328 _("unrecognized instruction"));
1330 if (strlen (start) > 50)
1331 /* xgettext:c-format */
1332 sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
1334 /* xgettext:c-format */
1335 sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
1337 if (strlen (start) > 50)
1338 /* xgettext:c-format */
1339 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
1341 /* xgettext:c-format */
1342 sprintf (errbuf, _("bad instruction `%.50s'"), start);
1350 #if 0 /* This calls back to GAS which we can't do without care. */
1352 /* Record each member of OPVALS in the assembler's symbol table.
1353 This lets GAS parse registers for us.
1354 ??? Interesting idea but not currently used. */
1356 /* Record each member of OPVALS in the assembler's symbol table.
1357 FIXME: Not currently used. */
1360 frv_cgen_asm_hash_keywords (CGEN_CPU_DESC cd, CGEN_KEYWORD *opvals)
1362 CGEN_KEYWORD_SEARCH search = cgen_keyword_search_init (opvals, NULL);
1363 const CGEN_KEYWORD_ENTRY * ke;
1365 while ((ke = cgen_keyword_search_next (& search)) != NULL)
1367 #if 0 /* Unnecessary, should be done in the search routine. */
1368 if (! frv_cgen_opval_supported (ke))
1371 cgen_asm_record_register (cd, ke->name, ke->value);