arm: Support pac_key_* register operand for MRS/MSR in Armv8.1-M Mainline
[binutils-gdb.git] / sim / cr16 / gencode.c
blob2860b263a1cc8892c630c9ba9c95eb8bf1897b86
1 /* Simulation code for the CR16 processor.
2 Copyright (C) 2008-2024 Free Software Foundation, Inc.
3 Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com>
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This must come before any other includes. */
21 #include "defs.h"
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <limits.h>
26 #include <string.h>
27 #include "ansidecl.h"
28 #include "opcode/cr16.h"
30 static void write_header (void);
31 static void write_opcodes (void);
32 static void write_template (void);
34 int
35 main (int argc, char *argv[])
37 if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
38 write_header();
39 else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
40 write_template ();
41 else
42 write_opcodes();
43 return 0;
47 static void
48 write_header (void)
50 int i = 0;
52 /* Loop over instruction table until a full match is found. */
53 for ( ; i < NUMOPCODES; i++)
54 printf("void OP_%lX_%X (SIM_DESC, SIM_CPU *);\t\t/* %s */\n",
55 cr16_instruction[i].match, (32 - cr16_instruction[i].match_bits),
56 cr16_instruction[i].mnemonic);
60 /* write_template creates a file all required functions,
61 ready to be filled out. */
63 static void
64 write_template (void)
66 int i = 0, j, k;
68 printf ("#include \"defs.h\"\n");
69 printf ("#include \"sim-main.h\"\n");
70 printf ("#include \"cr16-sim.h\"\n");
71 printf ("#include \"simops.h\"\n\n");
73 for ( ; i < NUMOPCODES; i++)
75 if (cr16_instruction[i].size != 0)
77 printf ("/* %s */\nvoid\nOP_%lX_%X (SIM_DESC sd, SIM_CPU *cpu)\n{\n",
78 cr16_instruction[i].mnemonic, cr16_instruction[i].match,
79 (32 - cr16_instruction[i].match_bits));
81 /* count operands. */
82 j = 0;
83 for (k=0;k<5;k++)
85 if (cr16_instruction[i].operands[k].op_type == dummy)
86 break;
87 else
88 j++;
90 switch (j)
92 case 0:
93 printf ("printf(\" %s\\n\");\n",cr16_instruction[i].mnemonic);
94 break;
95 case 1:
96 printf ("printf(\" %s\\t%%x\\n\",OP[0]);\n",cr16_instruction[i].mnemonic);
97 break;
98 case 2:
99 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",cr16_instruction[i].mnemonic);
100 break;
101 case 3:
102 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",cr16_instruction[i].mnemonic);
103 break;
104 default:
105 fprintf (stderr,"Too many operands: %d\n",j);
107 printf ("}\n\n");
113 long Opcodes[512];
115 #if 0
116 static int curop=0;
118 static void
119 check_opcodes( long op)
121 int i;
123 for (i=0;i<curop;i++)
124 if (Opcodes[i] == op)
125 fprintf(stderr,"DUPLICATE OPCODES: %lx\n", op);
127 #endif
129 static void
130 write_opcodes (void)
132 int i = 0, j = 0, k;
134 /* write out opcode table. */
135 printf ("#include \"defs.h\"\n");
136 printf ("#include \"cr16-sim.h\"\n");
137 printf ("#include \"simops.h\"\n\n");
138 printf ("struct simops Simops[] = {\n");
140 for (i = NUMOPCODES-1; i >= 0; --i)
142 if (cr16_instruction[i].size != 0)
144 printf (" { \"%s\", %u, %d, %ld, %u, \"OP_%lX_%X\", OP_%lX_%X, ",
145 cr16_instruction[i].mnemonic, cr16_instruction[i].size,
146 cr16_instruction[i].match_bits, cr16_instruction[i].match,
147 cr16_instruction[i].flags, ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)),
148 (32 - cr16_instruction[i].match_bits),
149 ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)), (32 - cr16_instruction[i].match_bits));
151 j = 0;
152 for (k=0;k<5;k++)
154 if (cr16_instruction[i].operands[k].op_type == dummy)
155 break;
156 else
157 j++;
159 printf ("%d, ",j);
161 j = 0;
162 for (k=0;k<4;k++)
164 int optype = cr16_instruction[i].operands[k].op_type;
165 int shift = cr16_instruction[i].operands[k].shift;
166 if (j == 0)
167 printf ("{");
168 else
169 printf (", ");
170 printf ("{");
171 printf ("%d,%d",optype, shift);
172 printf ("}");
173 j = 1;
175 if (j)
176 printf ("}");
177 printf ("},\n");
180 printf (" { \"NULL\",1,8,0,0,\"OP_0_20\",OP_0_20,0,{{0,0},{0,0},{0,0},{0,0}}},\n};\n");