1*3d8817e4Smiod /* CPU data for openrisc.
2*3d8817e4Smiod 
3*3d8817e4Smiod THIS FILE IS MACHINE GENERATED WITH CGEN.
4*3d8817e4Smiod 
5*3d8817e4Smiod Copyright 1996-2005 Free Software Foundation, Inc.
6*3d8817e4Smiod 
7*3d8817e4Smiod This file is part of the GNU Binutils and/or GDB, the GNU debugger.
8*3d8817e4Smiod 
9*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
10*3d8817e4Smiod it under the terms of the GNU General Public License as published by
11*3d8817e4Smiod the Free Software Foundation; either version 2, or (at your option)
12*3d8817e4Smiod any later version.
13*3d8817e4Smiod 
14*3d8817e4Smiod This program is distributed in the hope that it will be useful,
15*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
16*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*3d8817e4Smiod GNU General Public License for more details.
18*3d8817e4Smiod 
19*3d8817e4Smiod You should have received a copy of the GNU General Public License along
20*3d8817e4Smiod with this program; if not, write to the Free Software Foundation, Inc.,
21*3d8817e4Smiod 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
22*3d8817e4Smiod 
23*3d8817e4Smiod */
24*3d8817e4Smiod 
25*3d8817e4Smiod #include "sysdep.h"
26*3d8817e4Smiod #include <stdio.h>
27*3d8817e4Smiod #include <stdarg.h>
28*3d8817e4Smiod #include "ansidecl.h"
29*3d8817e4Smiod #include "bfd.h"
30*3d8817e4Smiod #include "symcat.h"
31*3d8817e4Smiod #include "openrisc-desc.h"
32*3d8817e4Smiod #include "openrisc-opc.h"
33*3d8817e4Smiod #include "opintl.h"
34*3d8817e4Smiod #include "libiberty.h"
35*3d8817e4Smiod #include "xregex.h"
36*3d8817e4Smiod 
37*3d8817e4Smiod /* Attributes.  */
38*3d8817e4Smiod 
39*3d8817e4Smiod static const CGEN_ATTR_ENTRY bool_attr[] =
40*3d8817e4Smiod {
41*3d8817e4Smiod   { "#f", 0 },
42*3d8817e4Smiod   { "#t", 1 },
43*3d8817e4Smiod   { 0, 0 }
44*3d8817e4Smiod };
45*3d8817e4Smiod 
46*3d8817e4Smiod static const CGEN_ATTR_ENTRY MACH_attr[] ATTRIBUTE_UNUSED =
47*3d8817e4Smiod {
48*3d8817e4Smiod   { "base", MACH_BASE },
49*3d8817e4Smiod   { "openrisc", MACH_OPENRISC },
50*3d8817e4Smiod   { "or1300", MACH_OR1300 },
51*3d8817e4Smiod   { "max", MACH_MAX },
52*3d8817e4Smiod   { 0, 0 }
53*3d8817e4Smiod };
54*3d8817e4Smiod 
55*3d8817e4Smiod static const CGEN_ATTR_ENTRY ISA_attr[] ATTRIBUTE_UNUSED =
56*3d8817e4Smiod {
57*3d8817e4Smiod   { "or32", ISA_OR32 },
58*3d8817e4Smiod   { "max", ISA_MAX },
59*3d8817e4Smiod   { 0, 0 }
60*3d8817e4Smiod };
61*3d8817e4Smiod 
62*3d8817e4Smiod static const CGEN_ATTR_ENTRY HAS_CACHE_attr[] ATTRIBUTE_UNUSED =
63*3d8817e4Smiod {
64*3d8817e4Smiod   { "DATA_CACHE", HAS_CACHE_DATA_CACHE },
65*3d8817e4Smiod   { "INSN_CACHE", HAS_CACHE_INSN_CACHE },
66*3d8817e4Smiod   { 0, 0 }
67*3d8817e4Smiod };
68*3d8817e4Smiod 
69*3d8817e4Smiod const CGEN_ATTR_TABLE openrisc_cgen_ifield_attr_table[] =
70*3d8817e4Smiod {
71*3d8817e4Smiod   { "MACH", & MACH_attr[0], & MACH_attr[0] },
72*3d8817e4Smiod   { "VIRTUAL", &bool_attr[0], &bool_attr[0] },
73*3d8817e4Smiod   { "PCREL-ADDR", &bool_attr[0], &bool_attr[0] },
74*3d8817e4Smiod   { "ABS-ADDR", &bool_attr[0], &bool_attr[0] },
75*3d8817e4Smiod   { "RESERVED", &bool_attr[0], &bool_attr[0] },
76*3d8817e4Smiod   { "SIGN-OPT", &bool_attr[0], &bool_attr[0] },
77*3d8817e4Smiod   { "SIGNED", &bool_attr[0], &bool_attr[0] },
78*3d8817e4Smiod   { 0, 0, 0 }
79*3d8817e4Smiod };
80*3d8817e4Smiod 
81*3d8817e4Smiod const CGEN_ATTR_TABLE openrisc_cgen_hardware_attr_table[] =
82*3d8817e4Smiod {
83*3d8817e4Smiod   { "MACH", & MACH_attr[0], & MACH_attr[0] },
84*3d8817e4Smiod   { "VIRTUAL", &bool_attr[0], &bool_attr[0] },
85*3d8817e4Smiod   { "CACHE-ADDR", &bool_attr[0], &bool_attr[0] },
86*3d8817e4Smiod   { "PC", &bool_attr[0], &bool_attr[0] },
87*3d8817e4Smiod   { "PROFILE", &bool_attr[0], &bool_attr[0] },
88*3d8817e4Smiod   { 0, 0, 0 }
89*3d8817e4Smiod };
90*3d8817e4Smiod 
91*3d8817e4Smiod const CGEN_ATTR_TABLE openrisc_cgen_operand_attr_table[] =
92*3d8817e4Smiod {
93*3d8817e4Smiod   { "MACH", & MACH_attr[0], & MACH_attr[0] },
94*3d8817e4Smiod   { "VIRTUAL", &bool_attr[0], &bool_attr[0] },
95*3d8817e4Smiod   { "PCREL-ADDR", &bool_attr[0], &bool_attr[0] },
96*3d8817e4Smiod   { "ABS-ADDR", &bool_attr[0], &bool_attr[0] },
97*3d8817e4Smiod   { "SIGN-OPT", &bool_attr[0], &bool_attr[0] },
98*3d8817e4Smiod   { "SIGNED", &bool_attr[0], &bool_attr[0] },
99*3d8817e4Smiod   { "NEGATIVE", &bool_attr[0], &bool_attr[0] },
100*3d8817e4Smiod   { "RELAX", &bool_attr[0], &bool_attr[0] },
101*3d8817e4Smiod   { "SEM-ONLY", &bool_attr[0], &bool_attr[0] },
102*3d8817e4Smiod   { 0, 0, 0 }
103*3d8817e4Smiod };
104*3d8817e4Smiod 
105*3d8817e4Smiod const CGEN_ATTR_TABLE openrisc_cgen_insn_attr_table[] =
106*3d8817e4Smiod {
107*3d8817e4Smiod   { "MACH", & MACH_attr[0], & MACH_attr[0] },
108*3d8817e4Smiod   { "ALIAS", &bool_attr[0], &bool_attr[0] },
109*3d8817e4Smiod   { "VIRTUAL", &bool_attr[0], &bool_attr[0] },
110*3d8817e4Smiod   { "UNCOND-CTI", &bool_attr[0], &bool_attr[0] },
111*3d8817e4Smiod   { "COND-CTI", &bool_attr[0], &bool_attr[0] },
112*3d8817e4Smiod   { "SKIP-CTI", &bool_attr[0], &bool_attr[0] },
113*3d8817e4Smiod   { "DELAY-SLOT", &bool_attr[0], &bool_attr[0] },
114*3d8817e4Smiod   { "RELAXABLE", &bool_attr[0], &bool_attr[0] },
115*3d8817e4Smiod   { "RELAXED", &bool_attr[0], &bool_attr[0] },
116*3d8817e4Smiod   { "NO-DIS", &bool_attr[0], &bool_attr[0] },
117*3d8817e4Smiod   { "PBB", &bool_attr[0], &bool_attr[0] },
118*3d8817e4Smiod   { "NOT-IN-DELAY-SLOT", &bool_attr[0], &bool_attr[0] },
119*3d8817e4Smiod   { 0, 0, 0 }
120*3d8817e4Smiod };
121*3d8817e4Smiod 
122*3d8817e4Smiod /* Instruction set variants.  */
123*3d8817e4Smiod 
124*3d8817e4Smiod static const CGEN_ISA openrisc_cgen_isa_table[] = {
125*3d8817e4Smiod   { "or32", 32, 32, 32, 32 },
126*3d8817e4Smiod   { 0, 0, 0, 0, 0 }
127*3d8817e4Smiod };
128*3d8817e4Smiod 
129*3d8817e4Smiod /* Machine variants.  */
130*3d8817e4Smiod 
131*3d8817e4Smiod static const CGEN_MACH openrisc_cgen_mach_table[] = {
132*3d8817e4Smiod   { "openrisc", "openrisc", MACH_OPENRISC, 0 },
133*3d8817e4Smiod   { "or1300", "openrisc:1300", MACH_OR1300, 0 },
134*3d8817e4Smiod   { 0, 0, 0, 0 }
135*3d8817e4Smiod };
136*3d8817e4Smiod 
137*3d8817e4Smiod static CGEN_KEYWORD_ENTRY openrisc_cgen_opval_h_gr_entries[] =
138*3d8817e4Smiod {
139*3d8817e4Smiod   { "r0", 0, {0, {{{0, 0}}}}, 0, 0 },
140*3d8817e4Smiod   { "r1", 1, {0, {{{0, 0}}}}, 0, 0 },
141*3d8817e4Smiod   { "r2", 2, {0, {{{0, 0}}}}, 0, 0 },
142*3d8817e4Smiod   { "r3", 3, {0, {{{0, 0}}}}, 0, 0 },
143*3d8817e4Smiod   { "r4", 4, {0, {{{0, 0}}}}, 0, 0 },
144*3d8817e4Smiod   { "r5", 5, {0, {{{0, 0}}}}, 0, 0 },
145*3d8817e4Smiod   { "r6", 6, {0, {{{0, 0}}}}, 0, 0 },
146*3d8817e4Smiod   { "r7", 7, {0, {{{0, 0}}}}, 0, 0 },
147*3d8817e4Smiod   { "r8", 8, {0, {{{0, 0}}}}, 0, 0 },
148*3d8817e4Smiod   { "r9", 9, {0, {{{0, 0}}}}, 0, 0 },
149*3d8817e4Smiod   { "r10", 10, {0, {{{0, 0}}}}, 0, 0 },
150*3d8817e4Smiod   { "r11", 11, {0, {{{0, 0}}}}, 0, 0 },
151*3d8817e4Smiod   { "r12", 12, {0, {{{0, 0}}}}, 0, 0 },
152*3d8817e4Smiod   { "r13", 13, {0, {{{0, 0}}}}, 0, 0 },
153*3d8817e4Smiod   { "r14", 14, {0, {{{0, 0}}}}, 0, 0 },
154*3d8817e4Smiod   { "r15", 15, {0, {{{0, 0}}}}, 0, 0 },
155*3d8817e4Smiod   { "r16", 16, {0, {{{0, 0}}}}, 0, 0 },
156*3d8817e4Smiod   { "r17", 17, {0, {{{0, 0}}}}, 0, 0 },
157*3d8817e4Smiod   { "r18", 18, {0, {{{0, 0}}}}, 0, 0 },
158*3d8817e4Smiod   { "r19", 19, {0, {{{0, 0}}}}, 0, 0 },
159*3d8817e4Smiod   { "r20", 20, {0, {{{0, 0}}}}, 0, 0 },
160*3d8817e4Smiod   { "r21", 21, {0, {{{0, 0}}}}, 0, 0 },
161*3d8817e4Smiod   { "r22", 22, {0, {{{0, 0}}}}, 0, 0 },
162*3d8817e4Smiod   { "r23", 23, {0, {{{0, 0}}}}, 0, 0 },
163*3d8817e4Smiod   { "r24", 24, {0, {{{0, 0}}}}, 0, 0 },
164*3d8817e4Smiod   { "r25", 25, {0, {{{0, 0}}}}, 0, 0 },
165*3d8817e4Smiod   { "r26", 26, {0, {{{0, 0}}}}, 0, 0 },
166*3d8817e4Smiod   { "r27", 27, {0, {{{0, 0}}}}, 0, 0 },
167*3d8817e4Smiod   { "r28", 28, {0, {{{0, 0}}}}, 0, 0 },
168*3d8817e4Smiod   { "r29", 29, {0, {{{0, 0}}}}, 0, 0 },
169*3d8817e4Smiod   { "r30", 30, {0, {{{0, 0}}}}, 0, 0 },
170*3d8817e4Smiod   { "r31", 31, {0, {{{0, 0}}}}, 0, 0 },
171*3d8817e4Smiod   { "lr", 11, {0, {{{0, 0}}}}, 0, 0 },
172*3d8817e4Smiod   { "sp", 1, {0, {{{0, 0}}}}, 0, 0 },
173*3d8817e4Smiod   { "fp", 2, {0, {{{0, 0}}}}, 0, 0 }
174*3d8817e4Smiod };
175*3d8817e4Smiod 
176*3d8817e4Smiod CGEN_KEYWORD openrisc_cgen_opval_h_gr =
177*3d8817e4Smiod {
178*3d8817e4Smiod   & openrisc_cgen_opval_h_gr_entries[0],
179*3d8817e4Smiod   35,
180*3d8817e4Smiod   0, 0, 0, 0, ""
181*3d8817e4Smiod };
182*3d8817e4Smiod 
183*3d8817e4Smiod 
184*3d8817e4Smiod /* The hardware table.  */
185*3d8817e4Smiod 
186*3d8817e4Smiod #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
187*3d8817e4Smiod #define A(a) (1 << CGEN_HW_##a)
188*3d8817e4Smiod #else
189*3d8817e4Smiod #define A(a) (1 << CGEN_HW_/**/a)
190*3d8817e4Smiod #endif
191*3d8817e4Smiod 
192*3d8817e4Smiod const CGEN_HW_ENTRY openrisc_cgen_hw_table[] =
193*3d8817e4Smiod {
194*3d8817e4Smiod   { "h-memory", HW_H_MEMORY, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
195*3d8817e4Smiod   { "h-sint", HW_H_SINT, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
196*3d8817e4Smiod   { "h-uint", HW_H_UINT, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
197*3d8817e4Smiod   { "h-addr", HW_H_ADDR, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
198*3d8817e4Smiod   { "h-iaddr", HW_H_IADDR, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
199*3d8817e4Smiod   { "h-pc", HW_H_PC, CGEN_ASM_NONE, 0, { 0|A(PROFILE)|A(PC), { { { (1<<MACH_BASE), 0 } } } } },
200*3d8817e4Smiod   { "h-gr", HW_H_GR, CGEN_ASM_KEYWORD, (PTR) & openrisc_cgen_opval_h_gr, { 0|A(PROFILE), { { { (1<<MACH_BASE), 0 } } } } },
201*3d8817e4Smiod   { "h-sr", HW_H_SR, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
202*3d8817e4Smiod   { "h-hi16", HW_H_HI16, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
203*3d8817e4Smiod   { "h-lo16", HW_H_LO16, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
204*3d8817e4Smiod   { "h-cbit", HW_H_CBIT, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
205*3d8817e4Smiod   { "h-delay-insn", HW_H_DELAY_INSN, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
206*3d8817e4Smiod   { 0, 0, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } }
207*3d8817e4Smiod };
208*3d8817e4Smiod 
209*3d8817e4Smiod #undef A
210*3d8817e4Smiod 
211*3d8817e4Smiod 
212*3d8817e4Smiod /* The instruction field table.  */
213*3d8817e4Smiod 
214*3d8817e4Smiod #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
215*3d8817e4Smiod #define A(a) (1 << CGEN_IFLD_##a)
216*3d8817e4Smiod #else
217*3d8817e4Smiod #define A(a) (1 << CGEN_IFLD_/**/a)
218*3d8817e4Smiod #endif
219*3d8817e4Smiod 
220*3d8817e4Smiod const CGEN_IFLD openrisc_cgen_ifld_table[] =
221*3d8817e4Smiod {
222*3d8817e4Smiod   { OPENRISC_F_NIL, "f-nil", 0, 0, 0, 0, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
223*3d8817e4Smiod   { OPENRISC_F_ANYOF, "f-anyof", 0, 0, 0, 0, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
224*3d8817e4Smiod   { OPENRISC_F_CLASS, "f-class", 0, 32, 31, 2, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
225*3d8817e4Smiod   { OPENRISC_F_SUB, "f-sub", 0, 32, 29, 4, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
226*3d8817e4Smiod   { OPENRISC_F_R1, "f-r1", 0, 32, 25, 5, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
227*3d8817e4Smiod   { OPENRISC_F_R2, "f-r2", 0, 32, 20, 5, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
228*3d8817e4Smiod   { OPENRISC_F_R3, "f-r3", 0, 32, 15, 5, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
229*3d8817e4Smiod   { OPENRISC_F_SIMM16, "f-simm16", 0, 32, 15, 16, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
230*3d8817e4Smiod   { OPENRISC_F_UIMM16, "f-uimm16", 0, 32, 15, 16, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
231*3d8817e4Smiod   { OPENRISC_F_UIMM5, "f-uimm5", 0, 32, 4, 5, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
232*3d8817e4Smiod   { OPENRISC_F_HI16, "f-hi16", 0, 32, 15, 16, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
233*3d8817e4Smiod   { OPENRISC_F_LO16, "f-lo16", 0, 32, 15, 16, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
234*3d8817e4Smiod   { OPENRISC_F_OP1, "f-op1", 0, 32, 31, 2, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
235*3d8817e4Smiod   { OPENRISC_F_OP2, "f-op2", 0, 32, 29, 4, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
236*3d8817e4Smiod   { OPENRISC_F_OP3, "f-op3", 0, 32, 25, 2, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
237*3d8817e4Smiod   { OPENRISC_F_OP4, "f-op4", 0, 32, 23, 3, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
238*3d8817e4Smiod   { OPENRISC_F_OP5, "f-op5", 0, 32, 25, 5, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
239*3d8817e4Smiod   { OPENRISC_F_OP6, "f-op6", 0, 32, 7, 3, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
240*3d8817e4Smiod   { OPENRISC_F_OP7, "f-op7", 0, 32, 3, 4, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
241*3d8817e4Smiod   { OPENRISC_F_I16_1, "f-i16-1", 0, 32, 10, 11, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
242*3d8817e4Smiod   { OPENRISC_F_I16_2, "f-i16-2", 0, 32, 25, 5, { 0, { { { (1<<MACH_BASE), 0 } } } }  },
243*3d8817e4Smiod   { OPENRISC_F_DISP26, "f-disp26", 0, 32, 25, 26, { 0|A(PCREL_ADDR), { { { (1<<MACH_BASE), 0 } } } }  },
244*3d8817e4Smiod   { OPENRISC_F_ABS26, "f-abs26", 0, 32, 25, 26, { 0|A(ABS_ADDR), { { { (1<<MACH_BASE), 0 } } } }  },
245*3d8817e4Smiod   { OPENRISC_F_I16NC, "f-i16nc", 0, 0, 0, 0,{ 0|A(SIGN_OPT)|A(VIRTUAL), { { { (1<<MACH_BASE), 0 } } } }  },
246*3d8817e4Smiod   { OPENRISC_F_F_15_8, "f-f-15-8", 0, 32, 15, 8, { 0|A(RESERVED), { { { (1<<MACH_BASE), 0 } } } }  },
247*3d8817e4Smiod   { OPENRISC_F_F_10_3, "f-f-10-3", 0, 32, 10, 3, { 0|A(RESERVED), { { { (1<<MACH_BASE), 0 } } } }  },
248*3d8817e4Smiod   { OPENRISC_F_F_4_1, "f-f-4-1", 0, 32, 4, 1, { 0|A(RESERVED), { { { (1<<MACH_BASE), 0 } } } }  },
249*3d8817e4Smiod   { OPENRISC_F_F_7_3, "f-f-7-3", 0, 32, 7, 3, { 0|A(RESERVED), { { { (1<<MACH_BASE), 0 } } } }  },
250*3d8817e4Smiod   { OPENRISC_F_F_10_7, "f-f-10-7", 0, 32, 10, 7, { 0|A(RESERVED), { { { (1<<MACH_BASE), 0 } } } }  },
251*3d8817e4Smiod   { OPENRISC_F_F_10_11, "f-f-10-11", 0, 32, 10, 11, { 0|A(RESERVED), { { { (1<<MACH_BASE), 0 } } } }  },
252*3d8817e4Smiod   { 0, 0, 0, 0, 0, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } }
253*3d8817e4Smiod };
254*3d8817e4Smiod 
255*3d8817e4Smiod #undef A
256*3d8817e4Smiod 
257*3d8817e4Smiod 
258*3d8817e4Smiod 
259*3d8817e4Smiod /* multi ifield declarations */
260*3d8817e4Smiod 
261*3d8817e4Smiod const CGEN_MAYBE_MULTI_IFLD OPENRISC_F_I16NC_MULTI_IFIELD [];
262*3d8817e4Smiod 
263*3d8817e4Smiod 
264*3d8817e4Smiod /* multi ifield definitions */
265*3d8817e4Smiod 
266*3d8817e4Smiod const CGEN_MAYBE_MULTI_IFLD OPENRISC_F_I16NC_MULTI_IFIELD [] =
267*3d8817e4Smiod {
268*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_I16_1] } },
269*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_I16_2] } },
270*3d8817e4Smiod     { 0, { (const PTR) 0 } }
271*3d8817e4Smiod };
272*3d8817e4Smiod 
273*3d8817e4Smiod /* The operand table.  */
274*3d8817e4Smiod 
275*3d8817e4Smiod #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
276*3d8817e4Smiod #define A(a) (1 << CGEN_OPERAND_##a)
277*3d8817e4Smiod #else
278*3d8817e4Smiod #define A(a) (1 << CGEN_OPERAND_/**/a)
279*3d8817e4Smiod #endif
280*3d8817e4Smiod #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
281*3d8817e4Smiod #define OPERAND(op) OPENRISC_OPERAND_##op
282*3d8817e4Smiod #else
283*3d8817e4Smiod #define OPERAND(op) OPENRISC_OPERAND_/**/op
284*3d8817e4Smiod #endif
285*3d8817e4Smiod 
286*3d8817e4Smiod const CGEN_OPERAND openrisc_cgen_operand_table[] =
287*3d8817e4Smiod {
288*3d8817e4Smiod /* pc: program counter */
289*3d8817e4Smiod   { "pc", OPENRISC_OPERAND_PC, HW_H_PC, 0, 0,
290*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_NIL] } },
291*3d8817e4Smiod     { 0|A(SEM_ONLY), { { { (1<<MACH_BASE), 0 } } } }  },
292*3d8817e4Smiod /* sr: special register */
293*3d8817e4Smiod   { "sr", OPENRISC_OPERAND_SR, HW_H_SR, 0, 0,
294*3d8817e4Smiod     { 0, { (const PTR) 0 } },
295*3d8817e4Smiod     { 0|A(SEM_ONLY), { { { (1<<MACH_BASE), 0 } } } }  },
296*3d8817e4Smiod /* cbit: condition bit */
297*3d8817e4Smiod   { "cbit", OPENRISC_OPERAND_CBIT, HW_H_CBIT, 0, 0,
298*3d8817e4Smiod     { 0, { (const PTR) 0 } },
299*3d8817e4Smiod     { 0|A(SEM_ONLY), { { { (1<<MACH_BASE), 0 } } } }  },
300*3d8817e4Smiod /* simm-16: 16 bit signed immediate */
301*3d8817e4Smiod   { "simm-16", OPENRISC_OPERAND_SIMM_16, HW_H_SINT, 15, 16,
302*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_SIMM16] } },
303*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }  },
304*3d8817e4Smiod /* uimm-16: 16 bit unsigned immediate */
305*3d8817e4Smiod   { "uimm-16", OPENRISC_OPERAND_UIMM_16, HW_H_UINT, 15, 16,
306*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_UIMM16] } },
307*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }  },
308*3d8817e4Smiod /* disp-26: pc-rel 26 bit */
309*3d8817e4Smiod   { "disp-26", OPENRISC_OPERAND_DISP_26, HW_H_IADDR, 25, 26,
310*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_DISP26] } },
311*3d8817e4Smiod     { 0|A(PCREL_ADDR), { { { (1<<MACH_BASE), 0 } } } }  },
312*3d8817e4Smiod /* abs-26: abs 26 bit */
313*3d8817e4Smiod   { "abs-26", OPENRISC_OPERAND_ABS_26, HW_H_IADDR, 25, 26,
314*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_ABS26] } },
315*3d8817e4Smiod     { 0|A(ABS_ADDR), { { { (1<<MACH_BASE), 0 } } } }  },
316*3d8817e4Smiod /* uimm-5: imm5 */
317*3d8817e4Smiod   { "uimm-5", OPENRISC_OPERAND_UIMM_5, HW_H_UINT, 4, 5,
318*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_UIMM5] } },
319*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }  },
320*3d8817e4Smiod /* rD: destination register */
321*3d8817e4Smiod   { "rD", OPENRISC_OPERAND_RD, HW_H_GR, 25, 5,
322*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_R1] } },
323*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }  },
324*3d8817e4Smiod /* rA: source register A */
325*3d8817e4Smiod   { "rA", OPENRISC_OPERAND_RA, HW_H_GR, 20, 5,
326*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_R2] } },
327*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }  },
328*3d8817e4Smiod /* rB: source register B */
329*3d8817e4Smiod   { "rB", OPENRISC_OPERAND_RB, HW_H_GR, 15, 5,
330*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_R3] } },
331*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }  },
332*3d8817e4Smiod /* op-f-23: f-op23 */
333*3d8817e4Smiod   { "op-f-23", OPENRISC_OPERAND_OP_F_23, HW_H_UINT, 23, 3,
334*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_OP4] } },
335*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }  },
336*3d8817e4Smiod /* op-f-3: f-op3 */
337*3d8817e4Smiod   { "op-f-3", OPENRISC_OPERAND_OP_F_3, HW_H_UINT, 25, 5,
338*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_OP5] } },
339*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }  },
340*3d8817e4Smiod /* hi16: high 16 bit immediate, sign optional */
341*3d8817e4Smiod   { "hi16", OPENRISC_OPERAND_HI16, HW_H_HI16, 15, 16,
342*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_SIMM16] } },
343*3d8817e4Smiod     { 0|A(SIGN_OPT), { { { (1<<MACH_BASE), 0 } } } }  },
344*3d8817e4Smiod /* lo16: low 16 bit immediate, sign optional */
345*3d8817e4Smiod   { "lo16", OPENRISC_OPERAND_LO16, HW_H_LO16, 15, 16,
346*3d8817e4Smiod     { 0, { (const PTR) &openrisc_cgen_ifld_table[OPENRISC_F_LO16] } },
347*3d8817e4Smiod     { 0|A(SIGN_OPT), { { { (1<<MACH_BASE), 0 } } } }  },
348*3d8817e4Smiod /* ui16nc: 16 bit immediate, sign optional */
349*3d8817e4Smiod   { "ui16nc", OPENRISC_OPERAND_UI16NC, HW_H_LO16, 10, 16,
350*3d8817e4Smiod     { 2, { (const PTR) &OPENRISC_F_I16NC_MULTI_IFIELD[0] } },
351*3d8817e4Smiod     { 0|A(SIGN_OPT)|A(VIRTUAL), { { { (1<<MACH_BASE), 0 } } } }  },
352*3d8817e4Smiod /* sentinel */
353*3d8817e4Smiod   { 0, 0, 0, 0, 0,
354*3d8817e4Smiod     { 0, { (const PTR) 0 } },
355*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } } }
356*3d8817e4Smiod };
357*3d8817e4Smiod 
358*3d8817e4Smiod #undef A
359*3d8817e4Smiod 
360*3d8817e4Smiod 
361*3d8817e4Smiod /* The instruction table.  */
362*3d8817e4Smiod 
363*3d8817e4Smiod #define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field))
364*3d8817e4Smiod #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
365*3d8817e4Smiod #define A(a) (1 << CGEN_INSN_##a)
366*3d8817e4Smiod #else
367*3d8817e4Smiod #define A(a) (1 << CGEN_INSN_/**/a)
368*3d8817e4Smiod #endif
369*3d8817e4Smiod 
370*3d8817e4Smiod static const CGEN_IBASE openrisc_cgen_insn_table[MAX_INSNS] =
371*3d8817e4Smiod {
372*3d8817e4Smiod   /* Special null first entry.
373*3d8817e4Smiod      A `num' value of zero is thus invalid.
374*3d8817e4Smiod      Also, the special `invalid' insn resides here.  */
375*3d8817e4Smiod   { 0, 0, 0, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
376*3d8817e4Smiod /* l.j ${abs-26} */
377*3d8817e4Smiod   {
378*3d8817e4Smiod     OPENRISC_INSN_L_J, "l-j", "l.j", 32,
379*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(UNCOND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
380*3d8817e4Smiod   },
381*3d8817e4Smiod /* l.jal ${abs-26} */
382*3d8817e4Smiod   {
383*3d8817e4Smiod     OPENRISC_INSN_L_JAL, "l-jal", "l.jal", 32,
384*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(UNCOND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
385*3d8817e4Smiod   },
386*3d8817e4Smiod /* l.jr $rA */
387*3d8817e4Smiod   {
388*3d8817e4Smiod     OPENRISC_INSN_L_JR, "l-jr", "l.jr", 32,
389*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(UNCOND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
390*3d8817e4Smiod   },
391*3d8817e4Smiod /* l.jalr $rA */
392*3d8817e4Smiod   {
393*3d8817e4Smiod     OPENRISC_INSN_L_JALR, "l-jalr", "l.jalr", 32,
394*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(UNCOND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
395*3d8817e4Smiod   },
396*3d8817e4Smiod /* l.bal ${disp-26} */
397*3d8817e4Smiod   {
398*3d8817e4Smiod     OPENRISC_INSN_L_BAL, "l-bal", "l.bal", 32,
399*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(UNCOND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
400*3d8817e4Smiod   },
401*3d8817e4Smiod /* l.bnf ${disp-26} */
402*3d8817e4Smiod   {
403*3d8817e4Smiod     OPENRISC_INSN_L_BNF, "l-bnf", "l.bnf", 32,
404*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(COND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
405*3d8817e4Smiod   },
406*3d8817e4Smiod /* l.bf ${disp-26} */
407*3d8817e4Smiod   {
408*3d8817e4Smiod     OPENRISC_INSN_L_BF, "l-bf", "l.bf", 32,
409*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(COND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
410*3d8817e4Smiod   },
411*3d8817e4Smiod /* l.brk ${uimm-16} */
412*3d8817e4Smiod   {
413*3d8817e4Smiod     OPENRISC_INSN_L_BRK, "l-brk", "l.brk", 32,
414*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
415*3d8817e4Smiod   },
416*3d8817e4Smiod /* l.rfe $rA */
417*3d8817e4Smiod   {
418*3d8817e4Smiod     OPENRISC_INSN_L_RFE, "l-rfe", "l.rfe", 32,
419*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(UNCOND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
420*3d8817e4Smiod   },
421*3d8817e4Smiod /* l.sys ${uimm-16} */
422*3d8817e4Smiod   {
423*3d8817e4Smiod     OPENRISC_INSN_L_SYS, "l-sys", "l.sys", 32,
424*3d8817e4Smiod     { 0|A(NOT_IN_DELAY_SLOT)|A(UNCOND_CTI)|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
425*3d8817e4Smiod   },
426*3d8817e4Smiod /* l.nop */
427*3d8817e4Smiod   {
428*3d8817e4Smiod     OPENRISC_INSN_L_NOP, "l-nop", "l.nop", 32,
429*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
430*3d8817e4Smiod   },
431*3d8817e4Smiod /* l.movhi $rD,$hi16 */
432*3d8817e4Smiod   {
433*3d8817e4Smiod     OPENRISC_INSN_L_MOVHI, "l-movhi", "l.movhi", 32,
434*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
435*3d8817e4Smiod   },
436*3d8817e4Smiod /* l.mfsr $rD,$rA */
437*3d8817e4Smiod   {
438*3d8817e4Smiod     OPENRISC_INSN_L_MFSR, "l-mfsr", "l.mfsr", 32,
439*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
440*3d8817e4Smiod   },
441*3d8817e4Smiod /* l.mtsr $rA,$rB */
442*3d8817e4Smiod   {
443*3d8817e4Smiod     OPENRISC_INSN_L_MTSR, "l-mtsr", "l.mtsr", 32,
444*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
445*3d8817e4Smiod   },
446*3d8817e4Smiod /* l.lw $rD,${simm-16}($rA) */
447*3d8817e4Smiod   {
448*3d8817e4Smiod     OPENRISC_INSN_L_LW, "l-lw", "l.lw", 32,
449*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
450*3d8817e4Smiod   },
451*3d8817e4Smiod /* l.lbz $rD,${simm-16}($rA) */
452*3d8817e4Smiod   {
453*3d8817e4Smiod     OPENRISC_INSN_L_LBZ, "l-lbz", "l.lbz", 32,
454*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
455*3d8817e4Smiod   },
456*3d8817e4Smiod /* l.lbs $rD,${simm-16}($rA) */
457*3d8817e4Smiod   {
458*3d8817e4Smiod     OPENRISC_INSN_L_LBS, "l-lbs", "l.lbs", 32,
459*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
460*3d8817e4Smiod   },
461*3d8817e4Smiod /* l.lhz $rD,${simm-16}($rA) */
462*3d8817e4Smiod   {
463*3d8817e4Smiod     OPENRISC_INSN_L_LHZ, "l-lhz", "l.lhz", 32,
464*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
465*3d8817e4Smiod   },
466*3d8817e4Smiod /* l.lhs $rD,${simm-16}($rA) */
467*3d8817e4Smiod   {
468*3d8817e4Smiod     OPENRISC_INSN_L_LHS, "l-lhs", "l.lhs", 32,
469*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
470*3d8817e4Smiod   },
471*3d8817e4Smiod /* l.sw ${ui16nc}($rA),$rB */
472*3d8817e4Smiod   {
473*3d8817e4Smiod     OPENRISC_INSN_L_SW, "l-sw", "l.sw", 32,
474*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
475*3d8817e4Smiod   },
476*3d8817e4Smiod /* l.sb ${ui16nc}($rA),$rB */
477*3d8817e4Smiod   {
478*3d8817e4Smiod     OPENRISC_INSN_L_SB, "l-sb", "l.sb", 32,
479*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
480*3d8817e4Smiod   },
481*3d8817e4Smiod /* l.sh ${ui16nc}($rA),$rB */
482*3d8817e4Smiod   {
483*3d8817e4Smiod     OPENRISC_INSN_L_SH, "l-sh", "l.sh", 32,
484*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
485*3d8817e4Smiod   },
486*3d8817e4Smiod /* l.sll $rD,$rA,$rB */
487*3d8817e4Smiod   {
488*3d8817e4Smiod     OPENRISC_INSN_L_SLL, "l-sll", "l.sll", 32,
489*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
490*3d8817e4Smiod   },
491*3d8817e4Smiod /* l.slli $rD,$rA,${uimm-5} */
492*3d8817e4Smiod   {
493*3d8817e4Smiod     OPENRISC_INSN_L_SLLI, "l-slli", "l.slli", 32,
494*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
495*3d8817e4Smiod   },
496*3d8817e4Smiod /* l.srl $rD,$rA,$rB */
497*3d8817e4Smiod   {
498*3d8817e4Smiod     OPENRISC_INSN_L_SRL, "l-srl", "l.srl", 32,
499*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
500*3d8817e4Smiod   },
501*3d8817e4Smiod /* l.srli $rD,$rA,${uimm-5} */
502*3d8817e4Smiod   {
503*3d8817e4Smiod     OPENRISC_INSN_L_SRLI, "l-srli", "l.srli", 32,
504*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
505*3d8817e4Smiod   },
506*3d8817e4Smiod /* l.sra $rD,$rA,$rB */
507*3d8817e4Smiod   {
508*3d8817e4Smiod     OPENRISC_INSN_L_SRA, "l-sra", "l.sra", 32,
509*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
510*3d8817e4Smiod   },
511*3d8817e4Smiod /* l.srai $rD,$rA,${uimm-5} */
512*3d8817e4Smiod   {
513*3d8817e4Smiod     OPENRISC_INSN_L_SRAI, "l-srai", "l.srai", 32,
514*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
515*3d8817e4Smiod   },
516*3d8817e4Smiod /* l.ror $rD,$rA,$rB */
517*3d8817e4Smiod   {
518*3d8817e4Smiod     OPENRISC_INSN_L_ROR, "l-ror", "l.ror", 32,
519*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
520*3d8817e4Smiod   },
521*3d8817e4Smiod /* l.rori $rD,$rA,${uimm-5} */
522*3d8817e4Smiod   {
523*3d8817e4Smiod     OPENRISC_INSN_L_RORI, "l-rori", "l.rori", 32,
524*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
525*3d8817e4Smiod   },
526*3d8817e4Smiod /* l.add $rD,$rA,$rB */
527*3d8817e4Smiod   {
528*3d8817e4Smiod     OPENRISC_INSN_L_ADD, "l-add", "l.add", 32,
529*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
530*3d8817e4Smiod   },
531*3d8817e4Smiod /* l.addi $rD,$rA,$lo16 */
532*3d8817e4Smiod   {
533*3d8817e4Smiod     OPENRISC_INSN_L_ADDI, "l-addi", "l.addi", 32,
534*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
535*3d8817e4Smiod   },
536*3d8817e4Smiod /* l.sub $rD,$rA,$rB */
537*3d8817e4Smiod   {
538*3d8817e4Smiod     OPENRISC_INSN_L_SUB, "l-sub", "l.sub", 32,
539*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
540*3d8817e4Smiod   },
541*3d8817e4Smiod /* l.subi $rD,$rA,$lo16 */
542*3d8817e4Smiod   {
543*3d8817e4Smiod     OPENRISC_INSN_L_SUBI, "l-subi", "l.subi", 32,
544*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
545*3d8817e4Smiod   },
546*3d8817e4Smiod /* l.and $rD,$rA,$rB */
547*3d8817e4Smiod   {
548*3d8817e4Smiod     OPENRISC_INSN_L_AND, "l-and", "l.and", 32,
549*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
550*3d8817e4Smiod   },
551*3d8817e4Smiod /* l.andi $rD,$rA,$lo16 */
552*3d8817e4Smiod   {
553*3d8817e4Smiod     OPENRISC_INSN_L_ANDI, "l-andi", "l.andi", 32,
554*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
555*3d8817e4Smiod   },
556*3d8817e4Smiod /* l.or $rD,$rA,$rB */
557*3d8817e4Smiod   {
558*3d8817e4Smiod     OPENRISC_INSN_L_OR, "l-or", "l.or", 32,
559*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
560*3d8817e4Smiod   },
561*3d8817e4Smiod /* l.ori $rD,$rA,$lo16 */
562*3d8817e4Smiod   {
563*3d8817e4Smiod     OPENRISC_INSN_L_ORI, "l-ori", "l.ori", 32,
564*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
565*3d8817e4Smiod   },
566*3d8817e4Smiod /* l.xor $rD,$rA,$rB */
567*3d8817e4Smiod   {
568*3d8817e4Smiod     OPENRISC_INSN_L_XOR, "l-xor", "l.xor", 32,
569*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
570*3d8817e4Smiod   },
571*3d8817e4Smiod /* l.xori $rD,$rA,$lo16 */
572*3d8817e4Smiod   {
573*3d8817e4Smiod     OPENRISC_INSN_L_XORI, "l-xori", "l.xori", 32,
574*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
575*3d8817e4Smiod   },
576*3d8817e4Smiod /* l.mul $rD,$rA,$rB */
577*3d8817e4Smiod   {
578*3d8817e4Smiod     OPENRISC_INSN_L_MUL, "l-mul", "l.mul", 32,
579*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
580*3d8817e4Smiod   },
581*3d8817e4Smiod /* l.muli $rD,$rA,$lo16 */
582*3d8817e4Smiod   {
583*3d8817e4Smiod     OPENRISC_INSN_L_MULI, "l-muli", "l.muli", 32,
584*3d8817e4Smiod     { 0, { { { (1<<MACH_BASE), 0 } } } }
585*3d8817e4Smiod   },
586*3d8817e4Smiod /* l.div $rD,$rA,$rB */
587*3d8817e4Smiod   {
588*3d8817e4Smiod     OPENRISC_INSN_L_DIV, "l-div", "l.div", 32,
589*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
590*3d8817e4Smiod   },
591*3d8817e4Smiod /* l.divu $rD,$rA,$rB */
592*3d8817e4Smiod   {
593*3d8817e4Smiod     OPENRISC_INSN_L_DIVU, "l-divu", "l.divu", 32,
594*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
595*3d8817e4Smiod   },
596*3d8817e4Smiod /* l.sfgts $rA,$rB */
597*3d8817e4Smiod   {
598*3d8817e4Smiod     OPENRISC_INSN_L_SFGTS, "l-sfgts", "l.sfgts", 32,
599*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
600*3d8817e4Smiod   },
601*3d8817e4Smiod /* l.sfgtu $rA,$rB */
602*3d8817e4Smiod   {
603*3d8817e4Smiod     OPENRISC_INSN_L_SFGTU, "l-sfgtu", "l.sfgtu", 32,
604*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
605*3d8817e4Smiod   },
606*3d8817e4Smiod /* l.sfges $rA,$rB */
607*3d8817e4Smiod   {
608*3d8817e4Smiod     OPENRISC_INSN_L_SFGES, "l-sfges", "l.sfges", 32,
609*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
610*3d8817e4Smiod   },
611*3d8817e4Smiod /* l.sfgeu $rA,$rB */
612*3d8817e4Smiod   {
613*3d8817e4Smiod     OPENRISC_INSN_L_SFGEU, "l-sfgeu", "l.sfgeu", 32,
614*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
615*3d8817e4Smiod   },
616*3d8817e4Smiod /* l.sflts $rA,$rB */
617*3d8817e4Smiod   {
618*3d8817e4Smiod     OPENRISC_INSN_L_SFLTS, "l-sflts", "l.sflts", 32,
619*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
620*3d8817e4Smiod   },
621*3d8817e4Smiod /* l.sfltu $rA,$rB */
622*3d8817e4Smiod   {
623*3d8817e4Smiod     OPENRISC_INSN_L_SFLTU, "l-sfltu", "l.sfltu", 32,
624*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
625*3d8817e4Smiod   },
626*3d8817e4Smiod /* l.sfles $rA,$rB */
627*3d8817e4Smiod   {
628*3d8817e4Smiod     OPENRISC_INSN_L_SFLES, "l-sfles", "l.sfles", 32,
629*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
630*3d8817e4Smiod   },
631*3d8817e4Smiod /* l.sfleu $rA,$rB */
632*3d8817e4Smiod   {
633*3d8817e4Smiod     OPENRISC_INSN_L_SFLEU, "l-sfleu", "l.sfleu", 32,
634*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
635*3d8817e4Smiod   },
636*3d8817e4Smiod /* l.sfgtsi $rA,${simm-16} */
637*3d8817e4Smiod   {
638*3d8817e4Smiod     OPENRISC_INSN_L_SFGTSI, "l-sfgtsi", "l.sfgtsi", 32,
639*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
640*3d8817e4Smiod   },
641*3d8817e4Smiod /* l.sfgtui $rA,${uimm-16} */
642*3d8817e4Smiod   {
643*3d8817e4Smiod     OPENRISC_INSN_L_SFGTUI, "l-sfgtui", "l.sfgtui", 32,
644*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
645*3d8817e4Smiod   },
646*3d8817e4Smiod /* l.sfgesi $rA,${simm-16} */
647*3d8817e4Smiod   {
648*3d8817e4Smiod     OPENRISC_INSN_L_SFGESI, "l-sfgesi", "l.sfgesi", 32,
649*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
650*3d8817e4Smiod   },
651*3d8817e4Smiod /* l.sfgeui $rA,${uimm-16} */
652*3d8817e4Smiod   {
653*3d8817e4Smiod     OPENRISC_INSN_L_SFGEUI, "l-sfgeui", "l.sfgeui", 32,
654*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
655*3d8817e4Smiod   },
656*3d8817e4Smiod /* l.sfltsi $rA,${simm-16} */
657*3d8817e4Smiod   {
658*3d8817e4Smiod     OPENRISC_INSN_L_SFLTSI, "l-sfltsi", "l.sfltsi", 32,
659*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
660*3d8817e4Smiod   },
661*3d8817e4Smiod /* l.sfltui $rA,${uimm-16} */
662*3d8817e4Smiod   {
663*3d8817e4Smiod     OPENRISC_INSN_L_SFLTUI, "l-sfltui", "l.sfltui", 32,
664*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
665*3d8817e4Smiod   },
666*3d8817e4Smiod /* l.sflesi $rA,${simm-16} */
667*3d8817e4Smiod   {
668*3d8817e4Smiod     OPENRISC_INSN_L_SFLESI, "l-sflesi", "l.sflesi", 32,
669*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
670*3d8817e4Smiod   },
671*3d8817e4Smiod /* l.sfleui $rA,${uimm-16} */
672*3d8817e4Smiod   {
673*3d8817e4Smiod     OPENRISC_INSN_L_SFLEUI, "l-sfleui", "l.sfleui", 32,
674*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
675*3d8817e4Smiod   },
676*3d8817e4Smiod /* l.sfeq $rA,$rB */
677*3d8817e4Smiod   {
678*3d8817e4Smiod     OPENRISC_INSN_L_SFEQ, "l-sfeq", "l.sfeq", 32,
679*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
680*3d8817e4Smiod   },
681*3d8817e4Smiod /* l.sfeqi $rA,${simm-16} */
682*3d8817e4Smiod   {
683*3d8817e4Smiod     OPENRISC_INSN_L_SFEQI, "l-sfeqi", "l.sfeqi", 32,
684*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
685*3d8817e4Smiod   },
686*3d8817e4Smiod /* l.sfne $rA,$rB */
687*3d8817e4Smiod   {
688*3d8817e4Smiod     OPENRISC_INSN_L_SFNE, "l-sfne", "l.sfne", 32,
689*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
690*3d8817e4Smiod   },
691*3d8817e4Smiod /* l.sfnei $rA,${simm-16} */
692*3d8817e4Smiod   {
693*3d8817e4Smiod     OPENRISC_INSN_L_SFNEI, "l-sfnei", "l.sfnei", 32,
694*3d8817e4Smiod     { 0|A(DELAY_SLOT), { { { (1<<MACH_BASE), 0 } } } }
695*3d8817e4Smiod   },
696*3d8817e4Smiod };
697*3d8817e4Smiod 
698*3d8817e4Smiod #undef OP
699*3d8817e4Smiod #undef A
700*3d8817e4Smiod 
701*3d8817e4Smiod /* Initialize anything needed to be done once, before any cpu_open call.  */
702*3d8817e4Smiod 
703*3d8817e4Smiod static void
init_tables(void)704*3d8817e4Smiod init_tables (void)
705*3d8817e4Smiod {
706*3d8817e4Smiod }
707*3d8817e4Smiod 
708*3d8817e4Smiod static const CGEN_MACH * lookup_mach_via_bfd_name (const CGEN_MACH *, const char *);
709*3d8817e4Smiod static void build_hw_table      (CGEN_CPU_TABLE *);
710*3d8817e4Smiod static void build_ifield_table  (CGEN_CPU_TABLE *);
711*3d8817e4Smiod static void build_operand_table (CGEN_CPU_TABLE *);
712*3d8817e4Smiod static void build_insn_table    (CGEN_CPU_TABLE *);
713*3d8817e4Smiod static void openrisc_cgen_rebuild_tables (CGEN_CPU_TABLE *);
714*3d8817e4Smiod 
715*3d8817e4Smiod /* Subroutine of openrisc_cgen_cpu_open to look up a mach via its bfd name.  */
716*3d8817e4Smiod 
717*3d8817e4Smiod static const CGEN_MACH *
lookup_mach_via_bfd_name(const CGEN_MACH * table,const char * name)718*3d8817e4Smiod lookup_mach_via_bfd_name (const CGEN_MACH *table, const char *name)
719*3d8817e4Smiod {
720*3d8817e4Smiod   while (table->name)
721*3d8817e4Smiod     {
722*3d8817e4Smiod       if (strcmp (name, table->bfd_name) == 0)
723*3d8817e4Smiod 	return table;
724*3d8817e4Smiod       ++table;
725*3d8817e4Smiod     }
726*3d8817e4Smiod   abort ();
727*3d8817e4Smiod }
728*3d8817e4Smiod 
729*3d8817e4Smiod /* Subroutine of openrisc_cgen_cpu_open to build the hardware table.  */
730*3d8817e4Smiod 
731*3d8817e4Smiod static void
build_hw_table(CGEN_CPU_TABLE * cd)732*3d8817e4Smiod build_hw_table (CGEN_CPU_TABLE *cd)
733*3d8817e4Smiod {
734*3d8817e4Smiod   int i;
735*3d8817e4Smiod   int machs = cd->machs;
736*3d8817e4Smiod   const CGEN_HW_ENTRY *init = & openrisc_cgen_hw_table[0];
737*3d8817e4Smiod   /* MAX_HW is only an upper bound on the number of selected entries.
738*3d8817e4Smiod      However each entry is indexed by it's enum so there can be holes in
739*3d8817e4Smiod      the table.  */
740*3d8817e4Smiod   const CGEN_HW_ENTRY **selected =
741*3d8817e4Smiod     (const CGEN_HW_ENTRY **) xmalloc (MAX_HW * sizeof (CGEN_HW_ENTRY *));
742*3d8817e4Smiod 
743*3d8817e4Smiod   cd->hw_table.init_entries = init;
744*3d8817e4Smiod   cd->hw_table.entry_size = sizeof (CGEN_HW_ENTRY);
745*3d8817e4Smiod   memset (selected, 0, MAX_HW * sizeof (CGEN_HW_ENTRY *));
746*3d8817e4Smiod   /* ??? For now we just use machs to determine which ones we want.  */
747*3d8817e4Smiod   for (i = 0; init[i].name != NULL; ++i)
748*3d8817e4Smiod     if (CGEN_HW_ATTR_VALUE (&init[i], CGEN_HW_MACH)
749*3d8817e4Smiod 	& machs)
750*3d8817e4Smiod       selected[init[i].type] = &init[i];
751*3d8817e4Smiod   cd->hw_table.entries = selected;
752*3d8817e4Smiod   cd->hw_table.num_entries = MAX_HW;
753*3d8817e4Smiod }
754*3d8817e4Smiod 
755*3d8817e4Smiod /* Subroutine of openrisc_cgen_cpu_open to build the hardware table.  */
756*3d8817e4Smiod 
757*3d8817e4Smiod static void
build_ifield_table(CGEN_CPU_TABLE * cd)758*3d8817e4Smiod build_ifield_table (CGEN_CPU_TABLE *cd)
759*3d8817e4Smiod {
760*3d8817e4Smiod   cd->ifld_table = & openrisc_cgen_ifld_table[0];
761*3d8817e4Smiod }
762*3d8817e4Smiod 
763*3d8817e4Smiod /* Subroutine of openrisc_cgen_cpu_open to build the hardware table.  */
764*3d8817e4Smiod 
765*3d8817e4Smiod static void
build_operand_table(CGEN_CPU_TABLE * cd)766*3d8817e4Smiod build_operand_table (CGEN_CPU_TABLE *cd)
767*3d8817e4Smiod {
768*3d8817e4Smiod   int i;
769*3d8817e4Smiod   int machs = cd->machs;
770*3d8817e4Smiod   const CGEN_OPERAND *init = & openrisc_cgen_operand_table[0];
771*3d8817e4Smiod   /* MAX_OPERANDS is only an upper bound on the number of selected entries.
772*3d8817e4Smiod      However each entry is indexed by it's enum so there can be holes in
773*3d8817e4Smiod      the table.  */
774*3d8817e4Smiod   const CGEN_OPERAND **selected = xmalloc (MAX_OPERANDS * sizeof (* selected));
775*3d8817e4Smiod 
776*3d8817e4Smiod   cd->operand_table.init_entries = init;
777*3d8817e4Smiod   cd->operand_table.entry_size = sizeof (CGEN_OPERAND);
778*3d8817e4Smiod   memset (selected, 0, MAX_OPERANDS * sizeof (CGEN_OPERAND *));
779*3d8817e4Smiod   /* ??? For now we just use mach to determine which ones we want.  */
780*3d8817e4Smiod   for (i = 0; init[i].name != NULL; ++i)
781*3d8817e4Smiod     if (CGEN_OPERAND_ATTR_VALUE (&init[i], CGEN_OPERAND_MACH)
782*3d8817e4Smiod 	& machs)
783*3d8817e4Smiod       selected[init[i].type] = &init[i];
784*3d8817e4Smiod   cd->operand_table.entries = selected;
785*3d8817e4Smiod   cd->operand_table.num_entries = MAX_OPERANDS;
786*3d8817e4Smiod }
787*3d8817e4Smiod 
788*3d8817e4Smiod /* Subroutine of openrisc_cgen_cpu_open to build the hardware table.
789*3d8817e4Smiod    ??? This could leave out insns not supported by the specified mach/isa,
790*3d8817e4Smiod    but that would cause errors like "foo only supported by bar" to become
791*3d8817e4Smiod    "unknown insn", so for now we include all insns and require the app to
792*3d8817e4Smiod    do the checking later.
793*3d8817e4Smiod    ??? On the other hand, parsing of such insns may require their hardware or
794*3d8817e4Smiod    operand elements to be in the table [which they mightn't be].  */
795*3d8817e4Smiod 
796*3d8817e4Smiod static void
build_insn_table(CGEN_CPU_TABLE * cd)797*3d8817e4Smiod build_insn_table (CGEN_CPU_TABLE *cd)
798*3d8817e4Smiod {
799*3d8817e4Smiod   int i;
800*3d8817e4Smiod   const CGEN_IBASE *ib = & openrisc_cgen_insn_table[0];
801*3d8817e4Smiod   CGEN_INSN *insns = xmalloc (MAX_INSNS * sizeof (CGEN_INSN));
802*3d8817e4Smiod 
803*3d8817e4Smiod   memset (insns, 0, MAX_INSNS * sizeof (CGEN_INSN));
804*3d8817e4Smiod   for (i = 0; i < MAX_INSNS; ++i)
805*3d8817e4Smiod     insns[i].base = &ib[i];
806*3d8817e4Smiod   cd->insn_table.init_entries = insns;
807*3d8817e4Smiod   cd->insn_table.entry_size = sizeof (CGEN_IBASE);
808*3d8817e4Smiod   cd->insn_table.num_init_entries = MAX_INSNS;
809*3d8817e4Smiod }
810*3d8817e4Smiod 
811*3d8817e4Smiod /* Subroutine of openrisc_cgen_cpu_open to rebuild the tables.  */
812*3d8817e4Smiod 
813*3d8817e4Smiod static void
openrisc_cgen_rebuild_tables(CGEN_CPU_TABLE * cd)814*3d8817e4Smiod openrisc_cgen_rebuild_tables (CGEN_CPU_TABLE *cd)
815*3d8817e4Smiod {
816*3d8817e4Smiod   int i;
817*3d8817e4Smiod   CGEN_BITSET *isas = cd->isas;
818*3d8817e4Smiod   unsigned int machs = cd->machs;
819*3d8817e4Smiod 
820*3d8817e4Smiod   cd->int_insn_p = CGEN_INT_INSN_P;
821*3d8817e4Smiod 
822*3d8817e4Smiod   /* Data derived from the isa spec.  */
823*3d8817e4Smiod #define UNSET (CGEN_SIZE_UNKNOWN + 1)
824*3d8817e4Smiod   cd->default_insn_bitsize = UNSET;
825*3d8817e4Smiod   cd->base_insn_bitsize = UNSET;
826*3d8817e4Smiod   cd->min_insn_bitsize = 65535; /* Some ridiculously big number.  */
827*3d8817e4Smiod   cd->max_insn_bitsize = 0;
828*3d8817e4Smiod   for (i = 0; i < MAX_ISAS; ++i)
829*3d8817e4Smiod     if (cgen_bitset_contains (isas, i))
830*3d8817e4Smiod       {
831*3d8817e4Smiod 	const CGEN_ISA *isa = & openrisc_cgen_isa_table[i];
832*3d8817e4Smiod 
833*3d8817e4Smiod 	/* Default insn sizes of all selected isas must be
834*3d8817e4Smiod 	   equal or we set the result to 0, meaning "unknown".  */
835*3d8817e4Smiod 	if (cd->default_insn_bitsize == UNSET)
836*3d8817e4Smiod 	  cd->default_insn_bitsize = isa->default_insn_bitsize;
837*3d8817e4Smiod 	else if (isa->default_insn_bitsize == cd->default_insn_bitsize)
838*3d8817e4Smiod 	  ; /* This is ok.  */
839*3d8817e4Smiod 	else
840*3d8817e4Smiod 	  cd->default_insn_bitsize = CGEN_SIZE_UNKNOWN;
841*3d8817e4Smiod 
842*3d8817e4Smiod 	/* Base insn sizes of all selected isas must be equal
843*3d8817e4Smiod 	   or we set the result to 0, meaning "unknown".  */
844*3d8817e4Smiod 	if (cd->base_insn_bitsize == UNSET)
845*3d8817e4Smiod 	  cd->base_insn_bitsize = isa->base_insn_bitsize;
846*3d8817e4Smiod 	else if (isa->base_insn_bitsize == cd->base_insn_bitsize)
847*3d8817e4Smiod 	  ; /* This is ok.  */
848*3d8817e4Smiod 	else
849*3d8817e4Smiod 	  cd->base_insn_bitsize = CGEN_SIZE_UNKNOWN;
850*3d8817e4Smiod 
851*3d8817e4Smiod 	/* Set min,max insn sizes.  */
852*3d8817e4Smiod 	if (isa->min_insn_bitsize < cd->min_insn_bitsize)
853*3d8817e4Smiod 	  cd->min_insn_bitsize = isa->min_insn_bitsize;
854*3d8817e4Smiod 	if (isa->max_insn_bitsize > cd->max_insn_bitsize)
855*3d8817e4Smiod 	  cd->max_insn_bitsize = isa->max_insn_bitsize;
856*3d8817e4Smiod       }
857*3d8817e4Smiod 
858*3d8817e4Smiod   /* Data derived from the mach spec.  */
859*3d8817e4Smiod   for (i = 0; i < MAX_MACHS; ++i)
860*3d8817e4Smiod     if (((1 << i) & machs) != 0)
861*3d8817e4Smiod       {
862*3d8817e4Smiod 	const CGEN_MACH *mach = & openrisc_cgen_mach_table[i];
863*3d8817e4Smiod 
864*3d8817e4Smiod 	if (mach->insn_chunk_bitsize != 0)
865*3d8817e4Smiod 	{
866*3d8817e4Smiod 	  if (cd->insn_chunk_bitsize != 0 && cd->insn_chunk_bitsize != mach->insn_chunk_bitsize)
867*3d8817e4Smiod 	    {
868*3d8817e4Smiod 	      fprintf (stderr, "openrisc_cgen_rebuild_tables: conflicting insn-chunk-bitsize values: `%d' vs. `%d'\n",
869*3d8817e4Smiod 		       cd->insn_chunk_bitsize, mach->insn_chunk_bitsize);
870*3d8817e4Smiod 	      abort ();
871*3d8817e4Smiod 	    }
872*3d8817e4Smiod 
873*3d8817e4Smiod  	  cd->insn_chunk_bitsize = mach->insn_chunk_bitsize;
874*3d8817e4Smiod 	}
875*3d8817e4Smiod       }
876*3d8817e4Smiod 
877*3d8817e4Smiod   /* Determine which hw elements are used by MACH.  */
878*3d8817e4Smiod   build_hw_table (cd);
879*3d8817e4Smiod 
880*3d8817e4Smiod   /* Build the ifield table.  */
881*3d8817e4Smiod   build_ifield_table (cd);
882*3d8817e4Smiod 
883*3d8817e4Smiod   /* Determine which operands are used by MACH/ISA.  */
884*3d8817e4Smiod   build_operand_table (cd);
885*3d8817e4Smiod 
886*3d8817e4Smiod   /* Build the instruction table.  */
887*3d8817e4Smiod   build_insn_table (cd);
888*3d8817e4Smiod }
889*3d8817e4Smiod 
890*3d8817e4Smiod /* Initialize a cpu table and return a descriptor.
891*3d8817e4Smiod    It's much like opening a file, and must be the first function called.
892*3d8817e4Smiod    The arguments are a set of (type/value) pairs, terminated with
893*3d8817e4Smiod    CGEN_CPU_OPEN_END.
894*3d8817e4Smiod 
895*3d8817e4Smiod    Currently supported values:
896*3d8817e4Smiod    CGEN_CPU_OPEN_ISAS:    bitmap of values in enum isa_attr
897*3d8817e4Smiod    CGEN_CPU_OPEN_MACHS:   bitmap of values in enum mach_attr
898*3d8817e4Smiod    CGEN_CPU_OPEN_BFDMACH: specify 1 mach using bfd name
899*3d8817e4Smiod    CGEN_CPU_OPEN_ENDIAN:  specify endian choice
900*3d8817e4Smiod    CGEN_CPU_OPEN_END:     terminates arguments
901*3d8817e4Smiod 
902*3d8817e4Smiod    ??? Simultaneous multiple isas might not make sense, but it's not (yet)
903*3d8817e4Smiod    precluded.
904*3d8817e4Smiod 
905*3d8817e4Smiod    ??? We only support ISO C stdargs here, not K&R.
906*3d8817e4Smiod    Laziness, plus experiment to see if anything requires K&R - eventually
907*3d8817e4Smiod    K&R will no longer be supported - e.g. GDB is currently trying this.  */
908*3d8817e4Smiod 
909*3d8817e4Smiod CGEN_CPU_DESC
openrisc_cgen_cpu_open(enum cgen_cpu_open_arg arg_type,...)910*3d8817e4Smiod openrisc_cgen_cpu_open (enum cgen_cpu_open_arg arg_type, ...)
911*3d8817e4Smiod {
912*3d8817e4Smiod   CGEN_CPU_TABLE *cd = (CGEN_CPU_TABLE *) xmalloc (sizeof (CGEN_CPU_TABLE));
913*3d8817e4Smiod   static int init_p;
914*3d8817e4Smiod   CGEN_BITSET *isas = 0;  /* 0 = "unspecified" */
915*3d8817e4Smiod   unsigned int machs = 0; /* 0 = "unspecified" */
916*3d8817e4Smiod   enum cgen_endian endian = CGEN_ENDIAN_UNKNOWN;
917*3d8817e4Smiod   va_list ap;
918*3d8817e4Smiod 
919*3d8817e4Smiod   if (! init_p)
920*3d8817e4Smiod     {
921*3d8817e4Smiod       init_tables ();
922*3d8817e4Smiod       init_p = 1;
923*3d8817e4Smiod     }
924*3d8817e4Smiod 
925*3d8817e4Smiod   memset (cd, 0, sizeof (*cd));
926*3d8817e4Smiod 
927*3d8817e4Smiod   va_start (ap, arg_type);
928*3d8817e4Smiod   while (arg_type != CGEN_CPU_OPEN_END)
929*3d8817e4Smiod     {
930*3d8817e4Smiod       switch (arg_type)
931*3d8817e4Smiod 	{
932*3d8817e4Smiod 	case CGEN_CPU_OPEN_ISAS :
933*3d8817e4Smiod 	  isas = va_arg (ap, CGEN_BITSET *);
934*3d8817e4Smiod 	  break;
935*3d8817e4Smiod 	case CGEN_CPU_OPEN_MACHS :
936*3d8817e4Smiod 	  machs = va_arg (ap, unsigned int);
937*3d8817e4Smiod 	  break;
938*3d8817e4Smiod 	case CGEN_CPU_OPEN_BFDMACH :
939*3d8817e4Smiod 	  {
940*3d8817e4Smiod 	    const char *name = va_arg (ap, const char *);
941*3d8817e4Smiod 	    const CGEN_MACH *mach =
942*3d8817e4Smiod 	      lookup_mach_via_bfd_name (openrisc_cgen_mach_table, name);
943*3d8817e4Smiod 
944*3d8817e4Smiod 	    machs |= 1 << mach->num;
945*3d8817e4Smiod 	    break;
946*3d8817e4Smiod 	  }
947*3d8817e4Smiod 	case CGEN_CPU_OPEN_ENDIAN :
948*3d8817e4Smiod 	  endian = va_arg (ap, enum cgen_endian);
949*3d8817e4Smiod 	  break;
950*3d8817e4Smiod 	default :
951*3d8817e4Smiod 	  fprintf (stderr, "openrisc_cgen_cpu_open: unsupported argument `%d'\n",
952*3d8817e4Smiod 		   arg_type);
953*3d8817e4Smiod 	  abort (); /* ??? return NULL? */
954*3d8817e4Smiod 	}
955*3d8817e4Smiod       arg_type = va_arg (ap, enum cgen_cpu_open_arg);
956*3d8817e4Smiod     }
957*3d8817e4Smiod   va_end (ap);
958*3d8817e4Smiod 
959*3d8817e4Smiod   /* Mach unspecified means "all".  */
960*3d8817e4Smiod   if (machs == 0)
961*3d8817e4Smiod     machs = (1 << MAX_MACHS) - 1;
962*3d8817e4Smiod   /* Base mach is always selected.  */
963*3d8817e4Smiod   machs |= 1;
964*3d8817e4Smiod   if (endian == CGEN_ENDIAN_UNKNOWN)
965*3d8817e4Smiod     {
966*3d8817e4Smiod       /* ??? If target has only one, could have a default.  */
967*3d8817e4Smiod       fprintf (stderr, "openrisc_cgen_cpu_open: no endianness specified\n");
968*3d8817e4Smiod       abort ();
969*3d8817e4Smiod     }
970*3d8817e4Smiod 
971*3d8817e4Smiod   cd->isas = cgen_bitset_copy (isas);
972*3d8817e4Smiod   cd->machs = machs;
973*3d8817e4Smiod   cd->endian = endian;
974*3d8817e4Smiod   /* FIXME: for the sparc case we can determine insn-endianness statically.
975*3d8817e4Smiod      The worry here is where both data and insn endian can be independently
976*3d8817e4Smiod      chosen, in which case this function will need another argument.
977*3d8817e4Smiod      Actually, will want to allow for more arguments in the future anyway.  */
978*3d8817e4Smiod   cd->insn_endian = endian;
979*3d8817e4Smiod 
980*3d8817e4Smiod   /* Table (re)builder.  */
981*3d8817e4Smiod   cd->rebuild_tables = openrisc_cgen_rebuild_tables;
982*3d8817e4Smiod   openrisc_cgen_rebuild_tables (cd);
983*3d8817e4Smiod 
984*3d8817e4Smiod   /* Default to not allowing signed overflow.  */
985*3d8817e4Smiod   cd->signed_overflow_ok_p = 0;
986*3d8817e4Smiod 
987*3d8817e4Smiod   return (CGEN_CPU_DESC) cd;
988*3d8817e4Smiod }
989*3d8817e4Smiod 
990*3d8817e4Smiod /* Cover fn to openrisc_cgen_cpu_open to handle the simple case of 1 isa, 1 mach.
991*3d8817e4Smiod    MACH_NAME is the bfd name of the mach.  */
992*3d8817e4Smiod 
993*3d8817e4Smiod CGEN_CPU_DESC
openrisc_cgen_cpu_open_1(const char * mach_name,enum cgen_endian endian)994*3d8817e4Smiod openrisc_cgen_cpu_open_1 (const char *mach_name, enum cgen_endian endian)
995*3d8817e4Smiod {
996*3d8817e4Smiod   return openrisc_cgen_cpu_open (CGEN_CPU_OPEN_BFDMACH, mach_name,
997*3d8817e4Smiod 			       CGEN_CPU_OPEN_ENDIAN, endian,
998*3d8817e4Smiod 			       CGEN_CPU_OPEN_END);
999*3d8817e4Smiod }
1000*3d8817e4Smiod 
1001*3d8817e4Smiod /* Close a cpu table.
1002*3d8817e4Smiod    ??? This can live in a machine independent file, but there's currently
1003*3d8817e4Smiod    no place to put this file (there's no libcgen).  libopcodes is the wrong
1004*3d8817e4Smiod    place as some simulator ports use this but they don't use libopcodes.  */
1005*3d8817e4Smiod 
1006*3d8817e4Smiod void
openrisc_cgen_cpu_close(CGEN_CPU_DESC cd)1007*3d8817e4Smiod openrisc_cgen_cpu_close (CGEN_CPU_DESC cd)
1008*3d8817e4Smiod {
1009*3d8817e4Smiod   unsigned int i;
1010*3d8817e4Smiod   const CGEN_INSN *insns;
1011*3d8817e4Smiod 
1012*3d8817e4Smiod   if (cd->macro_insn_table.init_entries)
1013*3d8817e4Smiod     {
1014*3d8817e4Smiod       insns = cd->macro_insn_table.init_entries;
1015*3d8817e4Smiod       for (i = 0; i < cd->macro_insn_table.num_init_entries; ++i, ++insns)
1016*3d8817e4Smiod 	if (CGEN_INSN_RX ((insns)))
1017*3d8817e4Smiod 	  regfree (CGEN_INSN_RX (insns));
1018*3d8817e4Smiod     }
1019*3d8817e4Smiod 
1020*3d8817e4Smiod   if (cd->insn_table.init_entries)
1021*3d8817e4Smiod     {
1022*3d8817e4Smiod       insns = cd->insn_table.init_entries;
1023*3d8817e4Smiod       for (i = 0; i < cd->insn_table.num_init_entries; ++i, ++insns)
1024*3d8817e4Smiod 	if (CGEN_INSN_RX (insns))
1025*3d8817e4Smiod 	  regfree (CGEN_INSN_RX (insns));
1026*3d8817e4Smiod     }
1027*3d8817e4Smiod 
1028*3d8817e4Smiod   if (cd->macro_insn_table.init_entries)
1029*3d8817e4Smiod     free ((CGEN_INSN *) cd->macro_insn_table.init_entries);
1030*3d8817e4Smiod 
1031*3d8817e4Smiod   if (cd->insn_table.init_entries)
1032*3d8817e4Smiod     free ((CGEN_INSN *) cd->insn_table.init_entries);
1033*3d8817e4Smiod 
1034*3d8817e4Smiod   if (cd->hw_table.entries)
1035*3d8817e4Smiod     free ((CGEN_HW_ENTRY *) cd->hw_table.entries);
1036*3d8817e4Smiod 
1037*3d8817e4Smiod   if (cd->operand_table.entries)
1038*3d8817e4Smiod     free ((CGEN_HW_ENTRY *) cd->operand_table.entries);
1039*3d8817e4Smiod 
1040*3d8817e4Smiod   free (cd);
1041*3d8817e4Smiod }
1042*3d8817e4Smiod 
1043