1 /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
2 /* Assembler interface for targets using CGEN. -*- C -*-
3 CGEN: Cpu tools GENerator
5 THIS FILE IS MACHINE GENERATED WITH CGEN.
6 - the resultant file is machine generated, cgen-asm.in isn't
8 Copyright (C) 1996-2017 Free Software Foundation, Inc.
10 This file is part of libopcodes.
12 This library is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 It is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
27 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
39 #include "libiberty.h"
40 #include "safe-ctype.h"
43 #define min(a,b) ((a) < (b) ? (a) : (b))
45 #define max(a,b) ((a) > (b) ? (a) : (b))
47 static const char * parse_insn_normal
48 (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
50 /* -- assembler routines inserted here. */
53 inline static const char *
54 parse_symbolic_address (CGEN_CPU_DESC cd,
58 enum cgen_parse_operand_result *resultp,
61 enum cgen_parse_operand_result result_type;
62 const char *errmsg = (* cd->parse_operand_fn)
63 (cd, CGEN_PARSE_OPERAND_SYMBOLIC, strp, opindex, opinfo,
64 &result_type, valuep);
67 && result_type != CGEN_PARSE_OPERAND_RESULT_QUEUED)
68 return "symbolic expression required";
71 *resultp = result_type;
77 parse_ldd_annotation (CGEN_CPU_DESC cd,
80 unsigned long *valuep)
83 enum cgen_parse_operand_result result_type;
86 if (**strp == '#' || **strp == '%')
88 if (strncasecmp (*strp + 1, "tlsdesc(", 8) == 0)
91 errmsg = parse_symbolic_address (cd, strp, opindex,
92 BFD_RELOC_FRV_TLSDESC_RELAX,
93 &result_type, &value);
104 while (**strp == ' ' || **strp == '\t')
108 return "missing `@'";
116 parse_call_annotation (CGEN_CPU_DESC cd,
119 unsigned long *valuep)
122 enum cgen_parse_operand_result result_type;
125 if (**strp == '#' || **strp == '%')
127 if (strncasecmp (*strp + 1, "gettlsoff(", 10) == 0)
130 errmsg = parse_symbolic_address (cd, strp, opindex,
131 BFD_RELOC_FRV_GETTLSOFF_RELAX,
132 &result_type, &value);
134 return "missing ')'";
143 while (**strp == ' ' || **strp == '\t')
147 return "missing `@'";
155 parse_ld_annotation (CGEN_CPU_DESC cd,
158 unsigned long *valuep)
161 enum cgen_parse_operand_result result_type;
164 if (**strp == '#' || **strp == '%')
166 if (strncasecmp (*strp + 1, "tlsoff(", 7) == 0)
169 errmsg = parse_symbolic_address (cd, strp, opindex,
170 BFD_RELOC_FRV_TLSOFF_RELAX,
171 &result_type, &value);
173 return "missing ')'";
182 while (**strp == ' ' || **strp == '\t')
186 return "missing `@'";
194 parse_ulo16 (CGEN_CPU_DESC cd,
197 unsigned long *valuep)
200 enum cgen_parse_operand_result result_type;
203 if (**strp == '#' || **strp == '%')
205 if (strncasecmp (*strp + 1, "lo(", 3) == 0)
208 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_LO16,
209 & result_type, & value);
211 return "missing `)'";
214 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
219 if (strncasecmp (*strp + 1, "gprello(", 8) == 0)
222 errmsg = parse_symbolic_address (cd, strp, opindex,
223 BFD_RELOC_FRV_GPRELLO,
224 & result_type, & value);
226 return "missing ')'";
231 else if (strncasecmp (*strp + 1, "gotlo(", 6) == 0)
234 errmsg = parse_symbolic_address (cd, strp, opindex,
236 & result_type, & value);
238 return "missing ')'";
243 else if (strncasecmp (*strp + 1, "gotfuncdesclo(", 14) == 0)
246 errmsg = parse_symbolic_address (cd, strp, opindex,
247 BFD_RELOC_FRV_FUNCDESC_GOTLO,
248 & result_type, & value);
250 return "missing ')'";
255 else if (strncasecmp (*strp + 1, "gotofflo(", 9) == 0)
258 errmsg = parse_symbolic_address (cd, strp, opindex,
259 BFD_RELOC_FRV_GOTOFFLO,
260 & result_type, & value);
262 return "missing ')'";
267 else if (strncasecmp (*strp + 1, "gotofffuncdesclo(", 17) == 0)
270 errmsg = parse_symbolic_address (cd, strp, opindex,
271 BFD_RELOC_FRV_FUNCDESC_GOTOFFLO,
272 & result_type, & value);
274 return "missing ')'";
279 else if (strncasecmp (*strp + 1, "gottlsdesclo(", 13) == 0)
282 errmsg = parse_symbolic_address (cd, strp, opindex,
283 BFD_RELOC_FRV_GOTTLSDESCLO,
284 & result_type, & value);
286 return "missing ')'";
291 else if (strncasecmp (*strp + 1, "tlsmofflo(", 10) == 0)
294 errmsg = parse_symbolic_address (cd, strp, opindex,
295 BFD_RELOC_FRV_TLSMOFFLO,
296 & result_type, & value);
298 return "missing ')'";
303 else if (strncasecmp (*strp + 1, "gottlsofflo(", 12) == 0)
306 errmsg = parse_symbolic_address (cd, strp, opindex,
307 BFD_RELOC_FRV_GOTTLSOFFLO,
308 & result_type, & value);
310 return "missing ')'";
316 return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
320 parse_uslo16 (CGEN_CPU_DESC cd,
326 enum cgen_parse_operand_result result_type;
329 if (**strp == '#' || **strp == '%')
331 if (strncasecmp (*strp + 1, "lo(", 3) == 0)
334 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_LO16,
335 & result_type, & value);
337 return "missing `)'";
340 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
345 else if (strncasecmp (*strp + 1, "gprello(", 8) == 0)
348 errmsg = parse_symbolic_address (cd, strp, opindex,
349 BFD_RELOC_FRV_GPRELLO,
350 & result_type, & value);
352 return "missing ')'";
357 else if (strncasecmp (*strp + 1, "gotlo(", 6) == 0)
360 errmsg = parse_symbolic_address (cd, strp, opindex,
362 & result_type, & value);
364 return "missing ')'";
369 else if (strncasecmp (*strp + 1, "gotfuncdesclo(", 14) == 0)
372 errmsg = parse_symbolic_address (cd, strp, opindex,
373 BFD_RELOC_FRV_FUNCDESC_GOTLO,
374 & result_type, & value);
376 return "missing ')'";
381 else if (strncasecmp (*strp + 1, "gotofflo(", 9) == 0)
384 errmsg = parse_symbolic_address (cd, strp, opindex,
385 BFD_RELOC_FRV_GOTOFFLO,
386 & result_type, & value);
388 return "missing ')'";
393 else if (strncasecmp (*strp + 1, "gotofffuncdesclo(", 17) == 0)
396 errmsg = parse_symbolic_address (cd, strp, opindex,
397 BFD_RELOC_FRV_FUNCDESC_GOTOFFLO,
398 & result_type, & value);
400 return "missing ')'";
405 else if (strncasecmp (*strp + 1, "gottlsdesclo(", 13) == 0)
408 errmsg = parse_symbolic_address (cd, strp, opindex,
409 BFD_RELOC_FRV_GOTTLSDESCLO,
410 & result_type, & value);
412 return "missing ')'";
417 else if (strncasecmp (*strp + 1, "tlsmofflo(", 10) == 0)
420 errmsg = parse_symbolic_address (cd, strp, opindex,
421 BFD_RELOC_FRV_TLSMOFFLO,
422 & result_type, & value);
424 return "missing ')'";
429 else if (strncasecmp (*strp + 1, "gottlsofflo(", 12) == 0)
432 errmsg = parse_symbolic_address (cd, strp, opindex,
433 BFD_RELOC_FRV_GOTTLSOFFLO,
434 & result_type, & value);
436 return "missing ')'";
442 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
446 parse_uhi16 (CGEN_CPU_DESC cd,
449 unsigned long *valuep)
452 enum cgen_parse_operand_result result_type;
455 if (**strp == '#' || **strp == '%')
457 if (strncasecmp (*strp + 1, "hi(", 3) == 0)
460 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_HI16,
461 & result_type, & value);
463 return "missing `)'";
466 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
468 /* If value is wider than 32 bits then be
469 careful about how we extract bits 16-31. */
470 if (sizeof (value) > 4)
471 value &= (((bfd_vma)1 << 16) << 16) - 1;
478 else if (strncasecmp (*strp + 1, "gprelhi(", 8) == 0)
481 errmsg = parse_symbolic_address (cd, strp, opindex,
482 BFD_RELOC_FRV_GPRELHI,
483 & result_type, & value);
485 return "missing ')'";
490 else if (strncasecmp (*strp + 1, "gothi(", 6) == 0)
493 errmsg = parse_symbolic_address (cd, strp, opindex,
495 & result_type, & value);
497 return "missing ')'";
502 else if (strncasecmp (*strp + 1, "gotfuncdeschi(", 14) == 0)
505 errmsg = parse_symbolic_address (cd, strp, opindex,
506 BFD_RELOC_FRV_FUNCDESC_GOTHI,
507 & result_type, & value);
509 return "missing ')'";
514 else if (strncasecmp (*strp + 1, "gotoffhi(", 9) == 0)
517 errmsg = parse_symbolic_address (cd, strp, opindex,
518 BFD_RELOC_FRV_GOTOFFHI,
519 & result_type, & value);
521 return "missing ')'";
526 else if (strncasecmp (*strp + 1, "gotofffuncdeschi(", 17) == 0)
529 errmsg = parse_symbolic_address (cd, strp, opindex,
530 BFD_RELOC_FRV_FUNCDESC_GOTOFFHI,
531 & result_type, & value);
533 return "missing ')'";
538 else if (strncasecmp (*strp + 1, "gottlsdeschi(", 13) == 0)
541 errmsg = parse_symbolic_address (cd, strp, opindex,
542 BFD_RELOC_FRV_GOTTLSDESCHI,
543 &result_type, &value);
545 return "missing ')'";
550 else if (strncasecmp (*strp + 1, "tlsmoffhi(", 10) == 0)
553 errmsg = parse_symbolic_address (cd, strp, opindex,
554 BFD_RELOC_FRV_TLSMOFFHI,
555 & result_type, & value);
557 return "missing ')'";
562 else if (strncasecmp (*strp + 1, "gottlsoffhi(", 12) == 0)
565 errmsg = parse_symbolic_address (cd, strp, opindex,
566 BFD_RELOC_FRV_GOTTLSOFFHI,
567 & result_type, & value);
569 return "missing ')'";
575 return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
579 parse_register_number (const char **strp)
583 if (**strp < '0' || **strp > '9')
584 return -1; /* error */
586 regno = **strp - '0';
587 for (++*strp; **strp >= '0' && **strp <= '9'; ++*strp)
588 regno = regno * 10 + (**strp - '0');
594 parse_spr (CGEN_CPU_DESC cd,
596 CGEN_KEYWORD * table,
599 const char *save_strp;
602 /* Check for spr index notation. */
603 if (strncasecmp (*strp, "spr[", 4) == 0)
606 regno = parse_register_number (strp);
608 return _("missing `]'");
610 if (! spr_valid (regno))
611 return _("Special purpose register number is out of range");
617 regno = parse_register_number (strp);
620 if (! spr_valid (regno))
621 return _("Special purpose register number is out of range");
627 return cgen_parse_keyword (cd, strp, table, valuep);
631 parse_d12 (CGEN_CPU_DESC cd,
637 enum cgen_parse_operand_result result_type;
640 /* Check for small data reference. */
641 if (**strp == '#' || **strp == '%')
643 if (strncasecmp (*strp + 1, "gprel12(", 8) == 0)
646 errmsg = parse_symbolic_address (cd, strp, opindex,
647 BFD_RELOC_FRV_GPREL12,
648 & result_type, & value);
650 return "missing `)'";
655 else if (strncasecmp (*strp + 1, "got12(", 6) == 0)
658 errmsg = parse_symbolic_address (cd, strp, opindex,
660 & result_type, & value);
662 return "missing ')'";
667 else if (strncasecmp (*strp + 1, "gotfuncdesc12(", 14) == 0)
670 errmsg = parse_symbolic_address (cd, strp, opindex,
671 BFD_RELOC_FRV_FUNCDESC_GOT12,
672 & result_type, & value);
674 return "missing ')'";
679 else if (strncasecmp (*strp + 1, "gotoff12(", 9) == 0)
682 errmsg = parse_symbolic_address (cd, strp, opindex,
683 BFD_RELOC_FRV_GOTOFF12,
684 & result_type, & value);
686 return "missing ')'";
691 else if (strncasecmp (*strp + 1, "gotofffuncdesc12(", 17) == 0)
694 errmsg = parse_symbolic_address (cd, strp, opindex,
695 BFD_RELOC_FRV_FUNCDESC_GOTOFF12,
696 & result_type, & value);
698 return "missing ')'";
703 else if (strncasecmp (*strp + 1, "gottlsdesc12(", 13) == 0)
706 errmsg = parse_symbolic_address (cd, strp, opindex,
707 BFD_RELOC_FRV_GOTTLSDESC12,
708 & result_type, & value);
710 return "missing ')'";
715 else if (strncasecmp (*strp + 1, "tlsmoff12(", 10) == 0)
718 errmsg = parse_symbolic_address (cd, strp, opindex,
719 BFD_RELOC_FRV_TLSMOFF12,
720 & result_type, & value);
722 return "missing ')'";
727 else if (strncasecmp (*strp + 1, "gottlsoff12(", 12) == 0)
730 errmsg = parse_symbolic_address (cd, strp, opindex,
731 BFD_RELOC_FRV_GOTTLSOFF12,
732 & result_type, & value);
734 return "missing ')'";
740 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
744 parse_s12 (CGEN_CPU_DESC cd,
750 enum cgen_parse_operand_result result_type;
753 /* Check for small data reference. */
754 if (**strp == '#' || **strp == '%')
756 if (strncasecmp (*strp + 1, "gprel12(", 8) == 0)
759 errmsg = parse_symbolic_address (cd, strp, opindex,
760 BFD_RELOC_FRV_GPREL12,
761 & result_type, & value);
763 return "missing `)'";
768 else if (strncasecmp (*strp + 1, "got12(", 6) == 0)
771 errmsg = parse_symbolic_address (cd, strp, opindex,
773 & result_type, & value);
775 return "missing ')'";
780 else if (strncasecmp (*strp + 1, "gotfuncdesc12(", 14) == 0)
783 errmsg = parse_symbolic_address (cd, strp, opindex,
784 BFD_RELOC_FRV_FUNCDESC_GOT12,
785 & result_type, & value);
787 return "missing ')'";
792 else if (strncasecmp (*strp + 1, "gotoff12(", 9) == 0)
795 errmsg = parse_symbolic_address (cd, strp, opindex,
796 BFD_RELOC_FRV_GOTOFF12,
797 & result_type, & value);
799 return "missing ')'";
804 else if (strncasecmp (*strp + 1, "gotofffuncdesc12(", 17) == 0)
807 errmsg = parse_symbolic_address (cd, strp, opindex,
808 BFD_RELOC_FRV_FUNCDESC_GOTOFF12,
809 & result_type, & value);
811 return "missing ')'";
816 else if (strncasecmp (*strp + 1, "gottlsdesc12(", 13) == 0)
819 errmsg = parse_symbolic_address (cd, strp, opindex,
820 BFD_RELOC_FRV_GOTTLSDESC12,
821 & result_type, & value);
823 return "missing ')'";
828 else if (strncasecmp (*strp + 1, "tlsmoff12(", 10) == 0)
831 errmsg = parse_symbolic_address (cd, strp, opindex,
832 BFD_RELOC_FRV_TLSMOFF12,
833 & result_type, & value);
835 return "missing ')'";
840 else if (strncasecmp (*strp + 1, "gottlsoff12(", 12) == 0)
843 errmsg = parse_symbolic_address (cd, strp, opindex,
844 BFD_RELOC_FRV_GOTTLSOFF12,
845 & result_type, & value);
847 return "missing ')'";
856 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
860 parse_u12 (CGEN_CPU_DESC cd,
866 enum cgen_parse_operand_result result_type;
869 /* Check for small data reference. */
870 if ((**strp == '#' || **strp == '%')
871 && strncasecmp (*strp + 1, "gprel12(", 8) == 0)
874 errmsg = parse_symbolic_address (cd, strp, opindex,
875 BFD_RELOC_FRV_GPRELU12,
876 & result_type, & value);
878 return "missing `)'";
887 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
892 parse_A (CGEN_CPU_DESC cd,
895 unsigned long *valuep,
903 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
908 return _("Value of A operand must be 0 or 1");
914 parse_A0 (CGEN_CPU_DESC cd,
917 unsigned long *valuep)
919 return parse_A (cd, strp, opindex, valuep, 0);
923 parse_A1 (CGEN_CPU_DESC cd,
926 unsigned long *valuep)
928 return parse_A (cd, strp, opindex, valuep, 1);
932 parse_even_register (CGEN_CPU_DESC cd,
934 CGEN_KEYWORD * tableP,
938 const char * saved_star_strP = * strP;
940 errmsg = cgen_parse_keyword (cd, strP, tableP, valueP);
942 if (errmsg == NULL && ((* valueP) & 1))
944 errmsg = _("register number must be even");
945 * strP = saved_star_strP;
952 parse_call_label (CGEN_CPU_DESC cd,
956 enum cgen_parse_operand_result *resultp,
962 /* Check for small data reference. */
963 if (opinfo == 0 && (**strp == '#' || **strp == '%'))
965 if (strncasecmp (*strp + 1, "gettlsoff(", 10) == 0)
968 errmsg = parse_symbolic_address (cd, strp, opindex,
969 BFD_RELOC_FRV_GETTLSOFF,
972 return _("missing `)'");
979 return cgen_parse_address (cd, strp, opindex, opinfo, resultp, valuep);
984 const char * frv_cgen_parse_operand
985 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
987 /* Main entry point for operand parsing.
989 This function is basically just a big switch statement. Earlier versions
990 used tables to look up the function to use, but
991 - if the table contains both assembler and disassembler functions then
992 the disassembler contains much of the assembler and vice-versa,
993 - there's a lot of inlining possibilities as things grow,
994 - using a switch statement avoids the function call overhead.
996 This function could be moved into `parse_insn_normal', but keeping it
997 separate makes clear the interface between `parse_insn_normal' and each of
1001 frv_cgen_parse_operand (CGEN_CPU_DESC cd,
1004 CGEN_FIELDS * fields)
1006 const char * errmsg = NULL;
1007 /* Used by scalar operands that still need to be parsed. */
1008 long junk ATTRIBUTE_UNUSED;
1012 case FRV_OPERAND_A0 :
1013 errmsg = parse_A0 (cd, strp, FRV_OPERAND_A0, (unsigned long *) (& fields->f_A));
1015 case FRV_OPERAND_A1 :
1016 errmsg = parse_A1 (cd, strp, FRV_OPERAND_A1, (unsigned long *) (& fields->f_A));
1018 case FRV_OPERAND_ACC40SI :
1019 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Si);
1021 case FRV_OPERAND_ACC40SK :
1022 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Sk);
1024 case FRV_OPERAND_ACC40UI :
1025 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Ui);
1027 case FRV_OPERAND_ACC40UK :
1028 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Uk);
1030 case FRV_OPERAND_ACCGI :
1031 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_accg_names, & fields->f_ACCGi);
1033 case FRV_OPERAND_ACCGK :
1034 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_accg_names, & fields->f_ACCGk);
1036 case FRV_OPERAND_CCI :
1037 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CCi);
1039 case FRV_OPERAND_CPRDOUBLEK :
1040 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRk);
1042 case FRV_OPERAND_CPRI :
1043 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRi);
1045 case FRV_OPERAND_CPRJ :
1046 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRj);
1048 case FRV_OPERAND_CPRK :
1049 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRk);
1051 case FRV_OPERAND_CRI :
1052 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRi);
1054 case FRV_OPERAND_CRJ :
1055 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj);
1057 case FRV_OPERAND_CRJ_FLOAT :
1058 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj_float);
1060 case FRV_OPERAND_CRJ_INT :
1061 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj_int);
1063 case FRV_OPERAND_CRK :
1064 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRk);
1066 case FRV_OPERAND_FCCI_1 :
1067 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_1);
1069 case FRV_OPERAND_FCCI_2 :
1070 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_2);
1072 case FRV_OPERAND_FCCI_3 :
1073 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_3);
1075 case FRV_OPERAND_FCCK :
1076 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCk);
1078 case FRV_OPERAND_FRDOUBLEI :
1079 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
1081 case FRV_OPERAND_FRDOUBLEJ :
1082 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
1084 case FRV_OPERAND_FRDOUBLEK :
1085 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1087 case FRV_OPERAND_FRI :
1088 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
1090 case FRV_OPERAND_FRINTI :
1091 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
1093 case FRV_OPERAND_FRINTIEVEN :
1094 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
1096 case FRV_OPERAND_FRINTJ :
1097 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
1099 case FRV_OPERAND_FRINTJEVEN :
1100 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
1102 case FRV_OPERAND_FRINTK :
1103 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1105 case FRV_OPERAND_FRINTKEVEN :
1106 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1108 case FRV_OPERAND_FRJ :
1109 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
1111 case FRV_OPERAND_FRK :
1112 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1114 case FRV_OPERAND_FRKHI :
1115 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1117 case FRV_OPERAND_FRKLO :
1118 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
1120 case FRV_OPERAND_GRDOUBLEK :
1121 errmsg = parse_even_register (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
1123 case FRV_OPERAND_GRI :
1124 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRi);
1126 case FRV_OPERAND_GRJ :
1127 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRj);
1129 case FRV_OPERAND_GRK :
1130 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
1132 case FRV_OPERAND_GRKHI :
1133 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
1135 case FRV_OPERAND_GRKLO :
1136 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
1138 case FRV_OPERAND_ICCI_1 :
1139 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_1);
1141 case FRV_OPERAND_ICCI_2 :
1142 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_2);
1144 case FRV_OPERAND_ICCI_3 :
1145 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_3);
1147 case FRV_OPERAND_LI :
1148 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LI, (unsigned long *) (& fields->f_LI));
1150 case FRV_OPERAND_LRAD :
1151 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAD, (unsigned long *) (& fields->f_LRAD));
1153 case FRV_OPERAND_LRAE :
1154 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAE, (unsigned long *) (& fields->f_LRAE));
1156 case FRV_OPERAND_LRAS :
1157 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAS, (unsigned long *) (& fields->f_LRAS));
1159 case FRV_OPERAND_TLBPRL :
1160 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_TLBPRL, (unsigned long *) (& fields->f_TLBPRL));
1162 case FRV_OPERAND_TLBPROPX :
1163 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_TLBPROPX, (unsigned long *) (& fields->f_TLBPRopx));
1165 case FRV_OPERAND_AE :
1166 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_AE, (unsigned long *) (& fields->f_ae));
1168 case FRV_OPERAND_CALLANN :
1169 errmsg = parse_call_annotation (cd, strp, FRV_OPERAND_CALLANN, (unsigned long *) (& fields->f_reloc_ann));
1171 case FRV_OPERAND_CCOND :
1172 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_CCOND, (unsigned long *) (& fields->f_ccond));
1174 case FRV_OPERAND_COND :
1175 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_COND, (unsigned long *) (& fields->f_cond));
1177 case FRV_OPERAND_D12 :
1178 errmsg = parse_d12 (cd, strp, FRV_OPERAND_D12, (long *) (& fields->f_d12));
1180 case FRV_OPERAND_DEBUG :
1181 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_DEBUG, (unsigned long *) (& fields->f_debug));
1183 case FRV_OPERAND_EIR :
1184 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_EIR, (unsigned long *) (& fields->f_eir));
1186 case FRV_OPERAND_HINT :
1187 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_HINT, (unsigned long *) (& fields->f_hint));
1189 case FRV_OPERAND_HINT_NOT_TAKEN :
1190 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_hint_not_taken, & fields->f_hint);
1192 case FRV_OPERAND_HINT_TAKEN :
1193 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_hint_taken, & fields->f_hint);
1195 case FRV_OPERAND_LABEL16 :
1198 errmsg = cgen_parse_address (cd, strp, FRV_OPERAND_LABEL16, 0, NULL, & value);
1199 fields->f_label16 = value;
1202 case FRV_OPERAND_LABEL24 :
1205 errmsg = parse_call_label (cd, strp, FRV_OPERAND_LABEL24, 0, NULL, & value);
1206 fields->f_label24 = value;
1209 case FRV_OPERAND_LDANN :
1210 errmsg = parse_ld_annotation (cd, strp, FRV_OPERAND_LDANN, (unsigned long *) (& fields->f_reloc_ann));
1212 case FRV_OPERAND_LDDANN :
1213 errmsg = parse_ldd_annotation (cd, strp, FRV_OPERAND_LDDANN, (unsigned long *) (& fields->f_reloc_ann));
1215 case FRV_OPERAND_LOCK :
1216 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LOCK, (unsigned long *) (& fields->f_lock));
1218 case FRV_OPERAND_PACK :
1219 errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_pack, & fields->f_pack);
1221 case FRV_OPERAND_S10 :
1222 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S10, (long *) (& fields->f_s10));
1224 case FRV_OPERAND_S12 :
1225 errmsg = parse_s12 (cd, strp, FRV_OPERAND_S12, (long *) (& fields->f_d12));
1227 case FRV_OPERAND_S16 :
1228 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S16, (long *) (& fields->f_s16));
1230 case FRV_OPERAND_S5 :
1231 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S5, (long *) (& fields->f_s5));
1233 case FRV_OPERAND_S6 :
1234 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S6, (long *) (& fields->f_s6));
1236 case FRV_OPERAND_S6_1 :
1237 errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S6_1, (long *) (& fields->f_s6_1));
1239 case FRV_OPERAND_SLO16 :
1240 errmsg = parse_uslo16 (cd, strp, FRV_OPERAND_SLO16, (long *) (& fields->f_s16));
1242 case FRV_OPERAND_SPR :
1243 errmsg = parse_spr (cd, strp, & frv_cgen_opval_spr_names, & fields->f_spr);
1245 case FRV_OPERAND_U12 :
1246 errmsg = parse_u12 (cd, strp, FRV_OPERAND_U12, (long *) (& fields->f_u12));
1248 case FRV_OPERAND_U16 :
1249 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_U16, (unsigned long *) (& fields->f_u16));
1251 case FRV_OPERAND_U6 :
1252 errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_U6, (unsigned long *) (& fields->f_u6));
1254 case FRV_OPERAND_UHI16 :
1255 errmsg = parse_uhi16 (cd, strp, FRV_OPERAND_UHI16, (unsigned long *) (& fields->f_u16));
1257 case FRV_OPERAND_ULO16 :
1258 errmsg = parse_ulo16 (cd, strp, FRV_OPERAND_ULO16, (unsigned long *) (& fields->f_u16));
1262 /* xgettext:c-format */
1263 fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
1270 cgen_parse_fn * const frv_cgen_parse_handlers[] =
1276 frv_cgen_init_asm (CGEN_CPU_DESC cd)
1278 frv_cgen_init_opcode_table (cd);
1279 frv_cgen_init_ibld_table (cd);
1280 cd->parse_handlers = & frv_cgen_parse_handlers[0];
1281 cd->parse_operand = frv_cgen_parse_operand;
1282 #ifdef CGEN_ASM_INIT_HOOK
1289 /* Regex construction routine.
1291 This translates an opcode syntax string into a regex string,
1292 by replacing any non-character syntax element (such as an
1293 opcode) with the pattern '.*'
1295 It then compiles the regex and stores it in the opcode, for
1296 later use by frv_cgen_assemble_insn
1298 Returns NULL for success, an error message for failure. */
1301 frv_cgen_build_insn_regex (CGEN_INSN *insn)
1303 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
1304 const char *mnem = CGEN_INSN_MNEMONIC (insn);
1305 char rxbuf[CGEN_MAX_RX_ELEMENTS];
1307 const CGEN_SYNTAX_CHAR_TYPE *syn;
1310 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
1312 /* Mnemonics come first in the syntax string. */
1313 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1314 return _("missing mnemonic in syntax string");
1317 /* Generate a case sensitive regular expression that emulates case
1318 insensitive matching in the "C" locale. We cannot generate a case
1319 insensitive regular expression because in Turkish locales, 'i' and 'I'
1320 are not equal modulo case conversion. */
1322 /* Copy the literal mnemonic out of the insn. */
1323 for (; *mnem; mnem++)
1330 *rx++ = TOLOWER (c);
1331 *rx++ = TOUPPER (c);
1338 /* Copy any remaining literals from the syntax string into the rx. */
1339 for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
1341 if (CGEN_SYNTAX_CHAR_P (* syn))
1343 char c = CGEN_SYNTAX_CHAR (* syn);
1347 /* Escape any regex metacharacters in the syntax. */
1348 case '.': case '[': case '\\':
1349 case '*': case '^': case '$':
1351 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
1352 case '?': case '{': case '}':
1353 case '(': case ')': case '*':
1354 case '|': case '+': case ']':
1364 *rx++ = TOLOWER (c);
1365 *rx++ = TOUPPER (c);
1375 /* Replace non-syntax fields with globs. */
1381 /* Trailing whitespace ok. */
1388 /* But anchor it after that. */
1392 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
1393 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
1399 static char msg[80];
1401 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
1402 regfree ((regex_t *) CGEN_INSN_RX (insn));
1403 free (CGEN_INSN_RX (insn));
1404 (CGEN_INSN_RX (insn)) = NULL;
1410 /* Default insn parser.
1412 The syntax string is scanned and operands are parsed and stored in FIELDS.
1413 Relocs are queued as we go via other callbacks.
1415 ??? Note that this is currently an all-or-nothing parser. If we fail to
1416 parse the instruction, we return 0 and the caller will start over from
1417 the beginning. Backtracking will be necessary in parsing subexpressions,
1418 but that can be handled there. Not handling backtracking here may get
1419 expensive in the case of the m68k. Deal with later.
1421 Returns NULL for success, an error message for failure. */
1424 parse_insn_normal (CGEN_CPU_DESC cd,
1425 const CGEN_INSN *insn,
1427 CGEN_FIELDS *fields)
1429 /* ??? Runtime added insns not handled yet. */
1430 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
1431 const char *str = *strp;
1434 const CGEN_SYNTAX_CHAR_TYPE * syn;
1435 #ifdef CGEN_MNEMONIC_OPERANDS
1440 /* For now we assume the mnemonic is first (there are no leading operands).
1441 We can parse it without needing to set up operand parsing.
1442 GAS's input scrubber will ensure mnemonics are lowercase, but we may
1443 not be called from GAS. */
1444 p = CGEN_INSN_MNEMONIC (insn);
1445 while (*p && TOLOWER (*p) == TOLOWER (*str))
1449 return _("unrecognized instruction");
1451 #ifndef CGEN_MNEMONIC_OPERANDS
1452 if (* str && ! ISSPACE (* str))
1453 return _("unrecognized instruction");
1456 CGEN_INIT_PARSE (cd);
1457 cgen_init_parse_operand (cd);
1458 #ifdef CGEN_MNEMONIC_OPERANDS
1462 /* We don't check for (*str != '\0') here because we want to parse
1463 any trailing fake arguments in the syntax string. */
1464 syn = CGEN_SYNTAX_STRING (syntax);
1466 /* Mnemonics come first for now, ensure valid string. */
1467 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1474 /* Non operand chars must match exactly. */
1475 if (CGEN_SYNTAX_CHAR_P (* syn))
1477 /* FIXME: While we allow for non-GAS callers above, we assume the
1478 first char after the mnemonic part is a space. */
1479 /* FIXME: We also take inappropriate advantage of the fact that
1480 GAS's input scrubber will remove extraneous blanks. */
1481 if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
1483 #ifdef CGEN_MNEMONIC_OPERANDS
1484 if (CGEN_SYNTAX_CHAR(* syn) == ' ')
1492 /* Syntax char didn't match. Can't be this insn. */
1493 static char msg [80];
1495 /* xgettext:c-format */
1496 sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
1497 CGEN_SYNTAX_CHAR(*syn), *str);
1502 /* Ran out of input. */
1503 static char msg [80];
1505 /* xgettext:c-format */
1506 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
1507 CGEN_SYNTAX_CHAR(*syn));
1513 #ifdef CGEN_MNEMONIC_OPERANDS
1514 (void) past_opcode_p;
1516 /* We have an operand of some sort. */
1517 errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields);
1521 /* Done with this operand, continue with next one. */
1525 /* If we're at the end of the syntax string, we're done. */
1528 /* FIXME: For the moment we assume a valid `str' can only contain
1529 blanks now. IE: We needn't try again with a longer version of
1530 the insn and it is assumed that longer versions of insns appear
1531 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1532 while (ISSPACE (* str))
1536 return _("junk at end of line"); /* FIXME: would like to include `str' */
1541 /* We couldn't parse it. */
1542 return _("unrecognized instruction");
1545 /* Main entry point.
1546 This routine is called for each instruction to be assembled.
1547 STR points to the insn to be assembled.
1548 We assume all necessary tables have been initialized.
1549 The assembled instruction, less any fixups, is stored in BUF.
1550 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
1551 still needs to be converted to target byte order, otherwise BUF is an array
1552 of bytes in target byte order.
1553 The result is a pointer to the insn's entry in the opcode table,
1554 or NULL if an error occured (an error message will have already been
1557 Note that when processing (non-alias) macro-insns,
1558 this function recurses.
1560 ??? It's possible to make this cpu-independent.
1561 One would have to deal with a few minor things.
1562 At this point in time doing so would be more of a curiosity than useful
1563 [for example this file isn't _that_ big], but keeping the possibility in
1564 mind helps keep the design clean. */
1567 frv_cgen_assemble_insn (CGEN_CPU_DESC cd,
1569 CGEN_FIELDS *fields,
1570 CGEN_INSN_BYTES_PTR buf,
1574 CGEN_INSN_LIST *ilist;
1575 const char *parse_errmsg = NULL;
1576 const char *insert_errmsg = NULL;
1577 int recognized_mnemonic = 0;
1579 /* Skip leading white space. */
1580 while (ISSPACE (* str))
1583 /* The instructions are stored in hashed lists.
1584 Get the first in the list. */
1585 ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
1587 /* Keep looking until we find a match. */
1589 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
1591 const CGEN_INSN *insn = ilist->insn;
1592 recognized_mnemonic = 1;
1594 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
1595 /* Not usually needed as unsupported opcodes
1596 shouldn't be in the hash lists. */
1597 /* Is this insn supported by the selected cpu? */
1598 if (! frv_cgen_insn_supported (cd, insn))
1601 /* If the RELAXED attribute is set, this is an insn that shouldn't be
1602 chosen immediately. Instead, it is used during assembler/linker
1603 relaxation if possible. */
1604 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
1609 /* Skip this insn if str doesn't look right lexically. */
1610 if (CGEN_INSN_RX (insn) != NULL &&
1611 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
1614 /* Allow parse/insert handlers to obtain length of insn. */
1615 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
1617 parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
1618 if (parse_errmsg != NULL)
1621 /* ??? 0 is passed for `pc'. */
1622 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
1624 if (insert_errmsg != NULL)
1627 /* It is up to the caller to actually output the insn and any
1633 static char errbuf[150];
1634 const char *tmp_errmsg;
1635 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
1636 #define be_verbose 1
1638 #define be_verbose 0
1643 /* If requesting verbose error messages, use insert_errmsg.
1644 Failing that, use parse_errmsg. */
1645 tmp_errmsg = (insert_errmsg ? insert_errmsg :
1646 parse_errmsg ? parse_errmsg :
1647 recognized_mnemonic ?
1648 _("unrecognized form of instruction") :
1649 _("unrecognized instruction"));
1651 if (strlen (start) > 50)
1652 /* xgettext:c-format */
1653 sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
1655 /* xgettext:c-format */
1656 sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
1660 if (strlen (start) > 50)
1661 /* xgettext:c-format */
1662 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
1664 /* xgettext:c-format */
1665 sprintf (errbuf, _("bad instruction `%.50s'"), start);