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 (C) 1996-2016 Free Software Foundation, Inc.
9 This file is part of libopcodes.
11 This library 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 3, or (at your option)
16 It is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 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. */
26 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
38 #include "libiberty.h"
39 #include "safe-ctype.h"
42 #define min(a,b) ((a) < (b) ? (a) : (b))
44 #define max(a,b) ((a) > (b) ? (a) : (b))
46 static const char * parse_insn_normal
47 (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
49 /* -- assembler routines inserted here. */
52 inline static const char *
53 parse_symbolic_address (CGEN_CPU_DESC cd,
57 enum cgen_parse_operand_result *resultp,
60 enum cgen_parse_operand_result result_type;
61 const char *errmsg = (* cd->parse_operand_fn)
62 (cd, CGEN_PARSE_OPERAND_SYMBOLIC, strp, opindex, opinfo,
63 &result_type, valuep);
66 && result_type != CGEN_PARSE_OPERAND_RESULT_QUEUED)
67 return "symbolic expression required";
70 *resultp = result_type;
76 parse_ldd_annotation (CGEN_CPU_DESC cd,
79 unsigned long *valuep)
82 enum cgen_parse_operand_result result_type;
85 if (**strp == '#' || **strp == '%')
87 if (strncasecmp (*strp + 1, "tlsdesc(", 8) == 0)
90 errmsg = parse_symbolic_address (cd, strp, opindex,
91 BFD_RELOC_FRV_TLSDESC_RELAX,
92 &result_type, &value);
103 while (**strp == ' ' || **strp == '\t')
107 return "missing `@'";
115 parse_call_annotation (CGEN_CPU_DESC cd,
118 unsigned long *valuep)
121 enum cgen_parse_operand_result result_type;
124 if (**strp == '#' || **strp == '%')
126 if (strncasecmp (*strp + 1, "gettlsoff(", 10) == 0)
129 errmsg = parse_symbolic_address (cd, strp, opindex,
130 BFD_RELOC_FRV_GETTLSOFF_RELAX,
131 &result_type, &value);
133 return "missing ')'";
142 while (**strp == ' ' || **strp == '\t')
146 return "missing `@'";
154 parse_ld_annotation (CGEN_CPU_DESC cd,
157 unsigned long *valuep)
160 enum cgen_parse_operand_result result_type;
163 if (**strp == '#' || **strp == '%')
165 if (strncasecmp (*strp + 1, "tlsoff(", 7) == 0)
168 errmsg = parse_symbolic_address (cd, strp, opindex,
169 BFD_RELOC_FRV_TLSOFF_RELAX,
170 &result_type, &value);
172 return "missing ')'";
181 while (**strp == ' ' || **strp == '\t')
185 return "missing `@'";
193 parse_ulo16 (CGEN_CPU_DESC cd,
196 unsigned long *valuep)
199 enum cgen_parse_operand_result result_type;
202 if (**strp == '#' || **strp == '%')
204 if (strncasecmp (*strp + 1, "lo(", 3) == 0)
207 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_LO16,
208 & result_type, & value);
210 return "missing `)'";
213 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
218 if (strncasecmp (*strp + 1, "gprello(", 8) == 0)
221 errmsg = parse_symbolic_address (cd, strp, opindex,
222 BFD_RELOC_FRV_GPRELLO,
223 & result_type, & value);
225 return "missing ')'";
230 else if (strncasecmp (*strp + 1, "gotlo(", 6) == 0)
233 errmsg = parse_symbolic_address (cd, strp, opindex,
235 & result_type, & value);
237 return "missing ')'";
242 else if (strncasecmp (*strp + 1, "gotfuncdesclo(", 14) == 0)
245 errmsg = parse_symbolic_address (cd, strp, opindex,
246 BFD_RELOC_FRV_FUNCDESC_GOTLO,
247 & result_type, & value);
249 return "missing ')'";
254 else if (strncasecmp (*strp + 1, "gotofflo(", 9) == 0)
257 errmsg = parse_symbolic_address (cd, strp, opindex,
258 BFD_RELOC_FRV_GOTOFFLO,
259 & result_type, & value);
261 return "missing ')'";
266 else if (strncasecmp (*strp + 1, "gotofffuncdesclo(", 17) == 0)
269 errmsg = parse_symbolic_address (cd, strp, opindex,
270 BFD_RELOC_FRV_FUNCDESC_GOTOFFLO,
271 & result_type, & value);
273 return "missing ')'";
278 else if (strncasecmp (*strp + 1, "gottlsdesclo(", 13) == 0)
281 errmsg = parse_symbolic_address (cd, strp, opindex,
282 BFD_RELOC_FRV_GOTTLSDESCLO,
283 & result_type, & value);
285 return "missing ')'";
290 else if (strncasecmp (*strp + 1, "tlsmofflo(", 10) == 0)
293 errmsg = parse_symbolic_address (cd, strp, opindex,
294 BFD_RELOC_FRV_TLSMOFFLO,
295 & result_type, & value);
297 return "missing ')'";
302 else if (strncasecmp (*strp + 1, "gottlsofflo(", 12) == 0)
305 errmsg = parse_symbolic_address (cd, strp, opindex,
306 BFD_RELOC_FRV_GOTTLSOFFLO,
307 & result_type, & value);
309 return "missing ')'";
315 return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
319 parse_uslo16 (CGEN_CPU_DESC cd,
325 enum cgen_parse_operand_result result_type;
328 if (**strp == '#' || **strp == '%')
330 if (strncasecmp (*strp + 1, "lo(", 3) == 0)
333 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_LO16,
334 & result_type, & value);
336 return "missing `)'";
339 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
344 else if (strncasecmp (*strp + 1, "gprello(", 8) == 0)
347 errmsg = parse_symbolic_address (cd, strp, opindex,
348 BFD_RELOC_FRV_GPRELLO,
349 & result_type, & value);
351 return "missing ')'";
356 else if (strncasecmp (*strp + 1, "gotlo(", 6) == 0)
359 errmsg = parse_symbolic_address (cd, strp, opindex,
361 & result_type, & value);
363 return "missing ')'";
368 else if (strncasecmp (*strp + 1, "gotfuncdesclo(", 14) == 0)
371 errmsg = parse_symbolic_address (cd, strp, opindex,
372 BFD_RELOC_FRV_FUNCDESC_GOTLO,
373 & result_type, & value);
375 return "missing ')'";
380 else if (strncasecmp (*strp + 1, "gotofflo(", 9) == 0)
383 errmsg = parse_symbolic_address (cd, strp, opindex,
384 BFD_RELOC_FRV_GOTOFFLO,
385 & result_type, & value);
387 return "missing ')'";
392 else if (strncasecmp (*strp + 1, "gotofffuncdesclo(", 17) == 0)
395 errmsg = parse_symbolic_address (cd, strp, opindex,
396 BFD_RELOC_FRV_FUNCDESC_GOTOFFLO,
397 & result_type, & value);
399 return "missing ')'";
404 else if (strncasecmp (*strp + 1, "gottlsdesclo(", 13) == 0)
407 errmsg = parse_symbolic_address (cd, strp, opindex,
408 BFD_RELOC_FRV_GOTTLSDESCLO,
409 & result_type, & value);
411 return "missing ')'";
416 else if (strncasecmp (*strp + 1, "tlsmofflo(", 10) == 0)
419 errmsg = parse_symbolic_address (cd, strp, opindex,
420 BFD_RELOC_FRV_TLSMOFFLO,
421 & result_type, & value);
423 return "missing ')'";
428 else if (strncasecmp (*strp + 1, "gottlsofflo(", 12) == 0)
431 errmsg = parse_symbolic_address (cd, strp, opindex,
432 BFD_RELOC_FRV_GOTTLSOFFLO,
433 & result_type, & value);
435 return "missing ')'";
441 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
445 parse_uhi16 (CGEN_CPU_DESC cd,
448 unsigned long *valuep)
451 enum cgen_parse_operand_result result_type;
454 if (**strp == '#' || **strp == '%')
456 if (strncasecmp (*strp + 1, "hi(", 3) == 0)
459 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_HI16,
460 & result_type, & value);
462 return "missing `)'";
465 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
467 /* If value is wider than 32 bits then be
468 careful about how we extract bits 16-31. */
469 if (sizeof (value) > 4)
470 value &= (((bfd_vma)1 << 16) << 16) - 1;
477 else if (strncasecmp (*strp + 1, "gprelhi(", 8) == 0)
480 errmsg = parse_symbolic_address (cd, strp, opindex,
481 BFD_RELOC_FRV_GPRELHI,
482 & result_type, & value);
484 return "missing ')'";
489 else if (strncasecmp (*strp + 1, "gothi(", 6) == 0)
492 errmsg = parse_symbolic_address (cd, strp, opindex,
494 & result_type, & value);
496 return "missing ')'";
501 else if (strncasecmp (*strp + 1, "gotfuncdeschi(", 14) == 0)
504 errmsg = parse_symbolic_address (cd, strp, opindex,
505 BFD_RELOC_FRV_FUNCDESC_GOTHI,
506 & result_type, & value);
508 return "missing ')'";
513 else if (strncasecmp (*strp + 1, "gotoffhi(", 9) == 0)
516 errmsg = parse_symbolic_address (cd, strp, opindex,
517 BFD_RELOC_FRV_GOTOFFHI,
518 & result_type, & value);
520 return "missing ')'";
525 else if (strncasecmp (*strp + 1, "gotofffuncdeschi(", 17) == 0)
528 errmsg = parse_symbolic_address (cd, strp, opindex,
529 BFD_RELOC_FRV_FUNCDESC_GOTOFFHI,
530 & result_type, & value);
532 return "missing ')'";
537 else if (strncasecmp (*strp + 1, "gottlsdeschi(", 13) == 0)
540 errmsg = parse_symbolic_address (cd, strp, opindex,
541 BFD_RELOC_FRV_GOTTLSDESCHI,
542 &result_type, &value);
544 return "missing ')'";
549 else if (strncasecmp (*strp + 1, "tlsmoffhi(", 10) == 0)
552 errmsg = parse_symbolic_address (cd, strp, opindex,
553 BFD_RELOC_FRV_TLSMOFFHI,
554 & result_type, & value);
556 return "missing ')'";
561 else if (strncasecmp (*strp + 1, "gottlsoffhi(", 12) == 0)
564 errmsg = parse_symbolic_address (cd, strp, opindex,
565 BFD_RELOC_FRV_GOTTLSOFFHI,
566 & result_type, & value);
568 return "missing ')'";
574 return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
578 parse_register_number (const char **strp)
582 if (**strp < '0' || **strp > '9')
583 return -1; /* error */
585 regno = **strp - '0';
586 for (++*strp; **strp >= '0' && **strp <= '9'; ++*strp)
587 regno = regno * 10 + (**strp - '0');
593 parse_spr (CGEN_CPU_DESC cd,
595 CGEN_KEYWORD * table,
598 const char *save_strp;
601 /* Check for spr index notation. */
602 if (strncasecmp (*strp, "spr[", 4) == 0)
605 regno = parse_register_number (strp);
607 return _("missing `]'");
609 if (! spr_valid (regno))
610 return _("Special purpose register number is out of range");
616 regno = parse_register_number (strp);
619 if (! spr_valid (regno))
620 return _("Special purpose register number is out of range");
626 return cgen_parse_keyword (cd, strp, table, valuep);
630 parse_d12 (CGEN_CPU_DESC cd,
636 enum cgen_parse_operand_result result_type;
639 /* Check for small data reference. */
640 if (**strp == '#' || **strp == '%')
642 if (strncasecmp (*strp + 1, "gprel12(", 8) == 0)
645 errmsg = parse_symbolic_address (cd, strp, opindex,
646 BFD_RELOC_FRV_GPREL12,
647 & result_type, & value);
649 return "missing `)'";
654 else if (strncasecmp (*strp + 1, "got12(", 6) == 0)
657 errmsg = parse_symbolic_address (cd, strp, opindex,
659 & result_type, & value);
661 return "missing ')'";
666 else if (strncasecmp (*strp + 1, "gotfuncdesc12(", 14) == 0)
669 errmsg = parse_symbolic_address (cd, strp, opindex,
670 BFD_RELOC_FRV_FUNCDESC_GOT12,
671 & result_type, & value);
673 return "missing ')'";
678 else if (strncasecmp (*strp + 1, "gotoff12(", 9) == 0)
681 errmsg = parse_symbolic_address (cd, strp, opindex,
682 BFD_RELOC_FRV_GOTOFF12,
683 & result_type, & value);
685 return "missing ')'";
690 else if (strncasecmp (*strp + 1, "gotofffuncdesc12(", 17) == 0)
693 errmsg = parse_symbolic_address (cd, strp, opindex,
694 BFD_RELOC_FRV_FUNCDESC_GOTOFF12,
695 & result_type, & value);
697 return "missing ')'";
702 else if (strncasecmp (*strp + 1, "gottlsdesc12(", 13) == 0)
705 errmsg = parse_symbolic_address (cd, strp, opindex,
706 BFD_RELOC_FRV_GOTTLSDESC12,
707 & result_type, & value);
709 return "missing ')'";
714 else if (strncasecmp (*strp + 1, "tlsmoff12(", 10) == 0)
717 errmsg = parse_symbolic_address (cd, strp, opindex,
718 BFD_RELOC_FRV_TLSMOFF12,
719 & result_type, & value);
721 return "missing ')'";
726 else if (strncasecmp (*strp + 1, "gottlsoff12(", 12) == 0)
729 errmsg = parse_symbolic_address (cd, strp, opindex,
730 BFD_RELOC_FRV_GOTTLSOFF12,
731 & result_type, & value);
733 return "missing ')'";
739 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
743 parse_s12 (CGEN_CPU_DESC cd,
749 enum cgen_parse_operand_result result_type;
752 /* Check for small data reference. */
753 if (**strp == '#' || **strp == '%')
755 if (strncasecmp (*strp + 1, "gprel12(", 8) == 0)
758 errmsg = parse_symbolic_address (cd, strp, opindex,
759 BFD_RELOC_FRV_GPREL12,
760 & result_type, & value);
762 return "missing `)'";
767 else if (strncasecmp (*strp + 1, "got12(", 6) == 0)
770 errmsg = parse_symbolic_address (cd, strp, opindex,
772 & result_type, & value);
774 return "missing ')'";
779 else if (strncasecmp (*strp + 1, "gotfuncdesc12(", 14) == 0)
782 errmsg = parse_symbolic_address (cd, strp, opindex,
783 BFD_RELOC_FRV_FUNCDESC_GOT12,
784 & result_type, & value);
786 return "missing ')'";
791 else if (strncasecmp (*strp + 1, "gotoff12(", 9) == 0)
794 errmsg = parse_symbolic_address (cd, strp, opindex,
795 BFD_RELOC_FRV_GOTOFF12,
796 & result_type, & value);
798 return "missing ')'";
803 else if (strncasecmp (*strp + 1, "gotofffuncdesc12(", 17) == 0)
806 errmsg = parse_symbolic_address (cd, strp, opindex,
807 BFD_RELOC_FRV_FUNCDESC_GOTOFF12,
808 & result_type, & value);
810 return "missing ')'";
815 else if (strncasecmp (*strp + 1, "gottlsdesc12(", 13) == 0)
818 errmsg = parse_symbolic_address (cd, strp, opindex,
819 BFD_RELOC_FRV_GOTTLSDESC12,
820 & result_type, & value);
822 return "missing ')'";
827 else if (strncasecmp (*strp + 1, "tlsmoff12(", 10) == 0)
830 errmsg = parse_symbolic_address (cd, strp, opindex,
831 BFD_RELOC_FRV_TLSMOFF12,
832 & result_type, & value);
834 return "missing ')'";
839 else if (strncasecmp (*strp + 1, "gottlsoff12(", 12) == 0)
842 errmsg = parse_symbolic_address (cd, strp, opindex,
843 BFD_RELOC_FRV_GOTTLSOFF12,
844 & result_type, & value);
846 return "missing ')'";
855 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
859 parse_u12 (CGEN_CPU_DESC cd,
865 enum cgen_parse_operand_result result_type;
868 /* Check for small data reference. */
869 if ((**strp == '#' || **strp == '%')
870 && strncasecmp (*strp + 1, "gprel12(", 8) == 0)
873 errmsg = parse_symbolic_address (cd, strp, opindex,
874 BFD_RELOC_FRV_GPRELU12,
875 & result_type, & value);
877 return "missing `)'";
886 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
891 parse_A (CGEN_CPU_DESC cd,
894 unsigned long *valuep,
902 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
907 return _("Value of A operand must be 0 or 1");
913 parse_A0 (CGEN_CPU_DESC cd,
916 unsigned long *valuep)
918 return parse_A (cd, strp, opindex, valuep, 0);
922 parse_A1 (CGEN_CPU_DESC cd,
925 unsigned long *valuep)
927 return parse_A (cd, strp, opindex, valuep, 1);
931 parse_even_register (CGEN_CPU_DESC cd,
933 CGEN_KEYWORD * tableP,
937 const char * saved_star_strP = * strP;
939 errmsg = cgen_parse_keyword (cd, strP, tableP, valueP);
941 if (errmsg == NULL && ((* valueP) & 1))
943 errmsg = _("register number must be even");
944 * strP = saved_star_strP;
951 parse_call_label (CGEN_CPU_DESC cd,
955 enum cgen_parse_operand_result *resultp,
961 /* Check for small data reference. */
962 if (opinfo == 0 && (**strp == '#' || **strp == '%'))
964 if (strncasecmp (*strp + 1, "gettlsoff(", 10) == 0)
967 errmsg = parse_symbolic_address (cd, strp, opindex,
968 BFD_RELOC_FRV_GETTLSOFF,
971 return _("missing `)'");
978 return cgen_parse_address (cd, strp, opindex, opinfo, resultp, valuep);
983 const char * frv_cgen_parse_operand
984 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
986 /* Main entry point for operand parsing.
988 This function is basically just a big switch statement. Earlier versions
989 used tables to look up the function to use, but
990 - if the table contains both assembler and disassembler functions then
991 the disassembler contains much of the assembler and vice-versa,
992 - there's a lot of inlining possibilities as things grow,
993 - using a switch statement avoids the function call overhead.
995 This function could be moved into `parse_insn_normal', but keeping it
996 separate makes clear the interface between `parse_insn_normal' and each of
1000 frv_cgen_parse_operand (CGEN_CPU_DESC cd,
1003 CGEN_FIELDS * fields)
1005 const char * errmsg = NULL;
1006 /* Used by scalar operands that still need to be parsed. */
1007 long junk ATTRIBUTE_UNUSED;
1011 case FRV_OPERAND_A0 :
1012 errmsg = parse_A0 (cd, strp, FRV_OPERAND_A0, (unsigned long *) (& fields->f_A));
1014 case FRV_OPERAND_A1 :
1015 errmsg = parse_A1 (cd, strp, FRV_OPERAND_A1, (unsigned long *) (& fields->f_A));
1017 case FRV_OPERAND_ACC40SI :
1018 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Si);
1020 case FRV_OPERAND_ACC40SK :
1021 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Sk);
1023 case FRV_OPERAND_ACC40UI :
1024 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Ui);
1026 case FRV_OPERAND_ACC40UK :
1027 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Uk);
1029 case FRV_OPERAND_ACCGI :
1030 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_accg_names, & fields->f_ACCGi);
1032 case FRV_OPERAND_ACCGK :
1033 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_accg_names, & fields->f_ACCGk);
1035 case FRV_OPERAND_CCI :
1036 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CCi);
1038 case FRV_OPERAND_CPRDOUBLEK :
1039 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRk);
1041 case FRV_OPERAND_CPRI :
1042 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRi);
1044 case FRV_OPERAND_CPRJ :
1045 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRj);
1047 case FRV_OPERAND_CPRK :
1048 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRk);
1050 case FRV_OPERAND_CRI :
1051 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRi);
1053 case FRV_OPERAND_CRJ :
1054 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj);
1056 case FRV_OPERAND_CRJ_FLOAT :
1057 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj_float);
1059 case FRV_OPERAND_CRJ_INT :
1060 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj_int);
1062 case FRV_OPERAND_CRK :
1063 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRk);
1065 case FRV_OPERAND_FCCI_1 :
1066 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_1);
1068 case FRV_OPERAND_FCCI_2 :
1069 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_2);
1071 case FRV_OPERAND_FCCI_3 :
1072 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_3);
1074 case FRV_OPERAND_FCCK :
1075 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCk);
1077 case FRV_OPERAND_FRDOUBLEI :
1078 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
1080 case FRV_OPERAND_FRDOUBLEJ :
1081 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
1083 case FRV_OPERAND_FRDOUBLEK :
1084 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1086 case FRV_OPERAND_FRI :
1087 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
1089 case FRV_OPERAND_FRINTI :
1090 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
1092 case FRV_OPERAND_FRINTIEVEN :
1093 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
1095 case FRV_OPERAND_FRINTJ :
1096 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
1098 case FRV_OPERAND_FRINTJEVEN :
1099 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
1101 case FRV_OPERAND_FRINTK :
1102 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1104 case FRV_OPERAND_FRINTKEVEN :
1105 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1107 case FRV_OPERAND_FRJ :
1108 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
1110 case FRV_OPERAND_FRK :
1111 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1113 case FRV_OPERAND_FRKHI :
1114 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1116 case FRV_OPERAND_FRKLO :
1117 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1119 case FRV_OPERAND_GRDOUBLEK :
1120 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
1122 case FRV_OPERAND_GRI :
1123 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRi);
1125 case FRV_OPERAND_GRJ :
1126 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRj);
1128 case FRV_OPERAND_GRK :
1129 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
1131 case FRV_OPERAND_GRKHI :
1132 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
1134 case FRV_OPERAND_GRKLO :
1135 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
1137 case FRV_OPERAND_ICCI_1 :
1138 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_1);
1140 case FRV_OPERAND_ICCI_2 :
1141 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_2);
1143 case FRV_OPERAND_ICCI_3 :
1144 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_3);
1146 case FRV_OPERAND_LI :
1147 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LI, (unsigned long *) (& fields->f_LI));
1149 case FRV_OPERAND_LRAD :
1150 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAD, (unsigned long *) (& fields->f_LRAD));
1152 case FRV_OPERAND_LRAE :
1153 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAE, (unsigned long *) (& fields->f_LRAE));
1155 case FRV_OPERAND_LRAS :
1156 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAS, (unsigned long *) (& fields->f_LRAS));
1158 case FRV_OPERAND_TLBPRL :
1159 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_TLBPRL, (unsigned long *) (& fields->f_TLBPRL));
1161 case FRV_OPERAND_TLBPROPX :
1162 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_TLBPROPX, (unsigned long *) (& fields->f_TLBPRopx));
1164 case FRV_OPERAND_AE :
1165 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_AE, (unsigned long *) (& fields->f_ae));
1167 case FRV_OPERAND_CALLANN :
1168 errmsg = parse_call_annotation (cd, strp, FRV_OPERAND_CALLANN, (unsigned long *) (& fields->f_reloc_ann));
1170 case FRV_OPERAND_CCOND :
1171 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_CCOND, (unsigned long *) (& fields->f_ccond));
1173 case FRV_OPERAND_COND :
1174 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_COND, (unsigned long *) (& fields->f_cond));
1176 case FRV_OPERAND_D12 :
1177 errmsg = parse_d12 (cd, strp, FRV_OPERAND_D12, (long *) (& fields->f_d12));
1179 case FRV_OPERAND_DEBUG :
1180 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_DEBUG, (unsigned long *) (& fields->f_debug));
1182 case FRV_OPERAND_EIR :
1183 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_EIR, (unsigned long *) (& fields->f_eir));
1185 case FRV_OPERAND_HINT :
1186 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_HINT, (unsigned long *) (& fields->f_hint));
1188 case FRV_OPERAND_HINT_NOT_TAKEN :
1189 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_hint_not_taken, & fields->f_hint);
1191 case FRV_OPERAND_HINT_TAKEN :
1192 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_hint_taken, & fields->f_hint);
1194 case FRV_OPERAND_LABEL16 :
1197 errmsg = cgen_parse_address (cd, strp, FRV_OPERAND_LABEL16, 0, NULL, & value);
1198 fields->f_label16 = value;
1201 case FRV_OPERAND_LABEL24 :
1204 errmsg = parse_call_label (cd, strp, FRV_OPERAND_LABEL24, 0, NULL, & value);
1205 fields->f_label24 = value;
1208 case FRV_OPERAND_LDANN :
1209 errmsg = parse_ld_annotation (cd, strp, FRV_OPERAND_LDANN, (unsigned long *) (& fields->f_reloc_ann));
1211 case FRV_OPERAND_LDDANN :
1212 errmsg = parse_ldd_annotation (cd, strp, FRV_OPERAND_LDDANN, (unsigned long *) (& fields->f_reloc_ann));
1214 case FRV_OPERAND_LOCK :
1215 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LOCK, (unsigned long *) (& fields->f_lock));
1217 case FRV_OPERAND_PACK :
1218 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_pack, & fields->f_pack);
1220 case FRV_OPERAND_S10 :
1221 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S10, (long *) (& fields->f_s10));
1223 case FRV_OPERAND_S12 :
1224 errmsg = parse_s12 (cd, strp, FRV_OPERAND_S12, (long *) (& fields->f_d12));
1226 case FRV_OPERAND_S16 :
1227 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S16, (long *) (& fields->f_s16));
1229 case FRV_OPERAND_S5 :
1230 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S5, (long *) (& fields->f_s5));
1232 case FRV_OPERAND_S6 :
1233 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S6, (long *) (& fields->f_s6));
1235 case FRV_OPERAND_S6_1 :
1236 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S6_1, (long *) (& fields->f_s6_1));
1238 case FRV_OPERAND_SLO16 :
1239 errmsg = parse_uslo16 (cd, strp, FRV_OPERAND_SLO16, (long *) (& fields->f_s16));
1241 case FRV_OPERAND_SPR :
1242 errmsg = parse_spr (cd, strp, & frv_cgen_opval_spr_names, & fields->f_spr);
1244 case FRV_OPERAND_U12 :
1245 errmsg = parse_u12 (cd, strp, FRV_OPERAND_U12, (long *) (& fields->f_u12));
1247 case FRV_OPERAND_U16 :
1248 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_U16, (unsigned long *) (& fields->f_u16));
1250 case FRV_OPERAND_U6 :
1251 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_U6, (unsigned long *) (& fields->f_u6));
1253 case FRV_OPERAND_UHI16 :
1254 errmsg = parse_uhi16 (cd, strp, FRV_OPERAND_UHI16, (unsigned long *) (& fields->f_u16));
1256 case FRV_OPERAND_ULO16 :
1257 errmsg = parse_ulo16 (cd, strp, FRV_OPERAND_ULO16, (unsigned long *) (& fields->f_u16));
1261 /* xgettext:c-format */
1262 fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
1269 cgen_parse_fn * const frv_cgen_parse_handlers[] =
1275 frv_cgen_init_asm (CGEN_CPU_DESC cd)
1277 frv_cgen_init_opcode_table (cd);
1278 frv_cgen_init_ibld_table (cd);
1279 cd->parse_handlers = & frv_cgen_parse_handlers[0];
1280 cd->parse_operand = frv_cgen_parse_operand;
1281 #ifdef CGEN_ASM_INIT_HOOK
1288 /* Regex construction routine.
1290 This translates an opcode syntax string into a regex string,
1291 by replacing any non-character syntax element (such as an
1292 opcode) with the pattern '.*'
1294 It then compiles the regex and stores it in the opcode, for
1295 later use by frv_cgen_assemble_insn
1297 Returns NULL for success, an error message for failure. */
1300 frv_cgen_build_insn_regex (CGEN_INSN *insn)
1302 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
1303 const char *mnem = CGEN_INSN_MNEMONIC (insn);
1304 char rxbuf[CGEN_MAX_RX_ELEMENTS];
1306 const CGEN_SYNTAX_CHAR_TYPE *syn;
1309 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
1311 /* Mnemonics come first in the syntax string. */
1312 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1313 return _("missing mnemonic in syntax string");
1316 /* Generate a case sensitive regular expression that emulates case
1317 insensitive matching in the "C" locale. We cannot generate a case
1318 insensitive regular expression because in Turkish locales, 'i' and 'I'
1319 are not equal modulo case conversion. */
1321 /* Copy the literal mnemonic out of the insn. */
1322 for (; *mnem; mnem++)
1329 *rx++ = TOLOWER (c);
1330 *rx++ = TOUPPER (c);
1337 /* Copy any remaining literals from the syntax string into the rx. */
1338 for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
1340 if (CGEN_SYNTAX_CHAR_P (* syn))
1342 char c = CGEN_SYNTAX_CHAR (* syn);
1346 /* Escape any regex metacharacters in the syntax. */
1347 case '.': case '[': case '\\':
1348 case '*': case '^': case '$':
1350 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
1351 case '?': case '{': case '}':
1352 case '(': case ')': case '*':
1353 case '|': case '+': case ']':
1363 *rx++ = TOLOWER (c);
1364 *rx++ = TOUPPER (c);
1374 /* Replace non-syntax fields with globs. */
1380 /* Trailing whitespace ok. */
1387 /* But anchor it after that. */
1391 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
1392 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
1398 static char msg[80];
1400 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
1401 regfree ((regex_t *) CGEN_INSN_RX (insn));
1402 free (CGEN_INSN_RX (insn));
1403 (CGEN_INSN_RX (insn)) = NULL;
1409 /* Default insn parser.
1411 The syntax string is scanned and operands are parsed and stored in FIELDS.
1412 Relocs are queued as we go via other callbacks.
1414 ??? Note that this is currently an all-or-nothing parser. If we fail to
1415 parse the instruction, we return 0 and the caller will start over from
1416 the beginning. Backtracking will be necessary in parsing subexpressions,
1417 but that can be handled there. Not handling backtracking here may get
1418 expensive in the case of the m68k. Deal with later.
1420 Returns NULL for success, an error message for failure. */
1423 parse_insn_normal (CGEN_CPU_DESC cd,
1424 const CGEN_INSN *insn,
1426 CGEN_FIELDS *fields)
1428 /* ??? Runtime added insns not handled yet. */
1429 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
1430 const char *str = *strp;
1433 const CGEN_SYNTAX_CHAR_TYPE * syn;
1434 #ifdef CGEN_MNEMONIC_OPERANDS
1439 /* For now we assume the mnemonic is first (there are no leading operands).
1440 We can parse it without needing to set up operand parsing.
1441 GAS's input scrubber will ensure mnemonics are lowercase, but we may
1442 not be called from GAS. */
1443 p = CGEN_INSN_MNEMONIC (insn);
1444 while (*p && TOLOWER (*p) == TOLOWER (*str))
1448 return _("unrecognized instruction");
1450 #ifndef CGEN_MNEMONIC_OPERANDS
1451 if (* str && ! ISSPACE (* str))
1452 return _("unrecognized instruction");
1455 CGEN_INIT_PARSE (cd);
1456 cgen_init_parse_operand (cd);
1457 #ifdef CGEN_MNEMONIC_OPERANDS
1461 /* We don't check for (*str != '\0') here because we want to parse
1462 any trailing fake arguments in the syntax string. */
1463 syn = CGEN_SYNTAX_STRING (syntax);
1465 /* Mnemonics come first for now, ensure valid string. */
1466 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1473 /* Non operand chars must match exactly. */
1474 if (CGEN_SYNTAX_CHAR_P (* syn))
1476 /* FIXME: While we allow for non-GAS callers above, we assume the
1477 first char after the mnemonic part is a space. */
1478 /* FIXME: We also take inappropriate advantage of the fact that
1479 GAS's input scrubber will remove extraneous blanks. */
1480 if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
1482 #ifdef CGEN_MNEMONIC_OPERANDS
1483 if (CGEN_SYNTAX_CHAR(* syn) == ' ')
1491 /* Syntax char didn't match. Can't be this insn. */
1492 static char msg [80];
1494 /* xgettext:c-format */
1495 sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
1496 CGEN_SYNTAX_CHAR(*syn), *str);
1501 /* Ran out of input. */
1502 static char msg [80];
1504 /* xgettext:c-format */
1505 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
1506 CGEN_SYNTAX_CHAR(*syn));
1512 #ifdef CGEN_MNEMONIC_OPERANDS
1513 (void) past_opcode_p;
1515 /* We have an operand of some sort. */
1516 errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields);
1520 /* Done with this operand, continue with next one. */
1524 /* If we're at the end of the syntax string, we're done. */
1527 /* FIXME: For the moment we assume a valid `str' can only contain
1528 blanks now. IE: We needn't try again with a longer version of
1529 the insn and it is assumed that longer versions of insns appear
1530 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1531 while (ISSPACE (* str))
1535 return _("junk at end of line"); /* FIXME: would like to include `str' */
1540 /* We couldn't parse it. */
1541 return _("unrecognized instruction");
1544 /* Main entry point.
1545 This routine is called for each instruction to be assembled.
1546 STR points to the insn to be assembled.
1547 We assume all necessary tables have been initialized.
1548 The assembled instruction, less any fixups, is stored in BUF.
1549 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
1550 still needs to be converted to target byte order, otherwise BUF is an array
1551 of bytes in target byte order.
1552 The result is a pointer to the insn's entry in the opcode table,
1553 or NULL if an error occured (an error message will have already been
1556 Note that when processing (non-alias) macro-insns,
1557 this function recurses.
1559 ??? It's possible to make this cpu-independent.
1560 One would have to deal with a few minor things.
1561 At this point in time doing so would be more of a curiosity than useful
1562 [for example this file isn't _that_ big], but keeping the possibility in
1563 mind helps keep the design clean. */
1566 frv_cgen_assemble_insn (CGEN_CPU_DESC cd,
1568 CGEN_FIELDS *fields,
1569 CGEN_INSN_BYTES_PTR buf,
1573 CGEN_INSN_LIST *ilist;
1574 const char *parse_errmsg = NULL;
1575 const char *insert_errmsg = NULL;
1576 int recognized_mnemonic = 0;
1578 /* Skip leading white space. */
1579 while (ISSPACE (* str))
1582 /* The instructions are stored in hashed lists.
1583 Get the first in the list. */
1584 ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
1586 /* Keep looking until we find a match. */
1588 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
1590 const CGEN_INSN *insn = ilist->insn;
1591 recognized_mnemonic = 1;
1593 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
1594 /* Not usually needed as unsupported opcodes
1595 shouldn't be in the hash lists. */
1596 /* Is this insn supported by the selected cpu? */
1597 if (! frv_cgen_insn_supported (cd, insn))
1600 /* If the RELAXED attribute is set, this is an insn that shouldn't be
1601 chosen immediately. Instead, it is used during assembler/linker
1602 relaxation if possible. */
1603 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
1608 /* Skip this insn if str doesn't look right lexically. */
1609 if (CGEN_INSN_RX (insn) != NULL &&
1610 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
1613 /* Allow parse/insert handlers to obtain length of insn. */
1614 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
1616 parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
1617 if (parse_errmsg != NULL)
1620 /* ??? 0 is passed for `pc'. */
1621 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
1623 if (insert_errmsg != NULL)
1626 /* It is up to the caller to actually output the insn and any
1632 static char errbuf[150];
1633 const char *tmp_errmsg;
1634 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
1635 #define be_verbose 1
1637 #define be_verbose 0
1642 /* If requesting verbose error messages, use insert_errmsg.
1643 Failing that, use parse_errmsg. */
1644 tmp_errmsg = (insert_errmsg ? insert_errmsg :
1645 parse_errmsg ? parse_errmsg :
1646 recognized_mnemonic ?
1647 _("unrecognized form of instruction") :
1648 _("unrecognized instruction"));
1650 if (strlen (start) > 50)
1651 /* xgettext:c-format */
1652 sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
1654 /* xgettext:c-format */
1655 sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
1659 if (strlen (start) > 50)
1660 /* xgettext:c-format */
1661 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
1663 /* xgettext:c-format */
1664 sprintf (errbuf, _("bad instruction `%.50s'"), start);