1 |
6 |
jlechner |
; Generate .c/.h versions of main elements of cpu description file.
|
2 |
|
|
; Copyright (C) 2000, 2001, 2002, 2003, 2005, 2009 Red Hat, Inc.
|
3 |
|
|
; This file is part of CGEN.
|
4 |
|
|
|
5 |
|
|
"Generating isa table defns ...\n""\
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
static const CGEN_ISA @arch@_cgen_isa_table[] = {
|
9 |
|
|
|
10 |
|
|
{ 0, 0, 0, 0, 0 }
|
11 |
|
|
};
|
12 |
|
|
\n"; Mach support code.
|
13 |
|
|
|
14 |
|
|
; Currently this is quite simple, the various cpu names and their mach numbers
|
15 |
|
|
; are recorded in a "keyword" table.
|
16 |
|
|
; ??? No longer used as there is the mach attribute.
|
17 |
|
|
;
|
18 |
|
|
;(set! mach-table (make <keyword> 'mach "machine list"
|
19 |
|
|
; (make <attr-list> "" nil) ; FIXME: sanitization?
|
20 |
|
|
; (map (lambda (elm) (list (obj:name elm) (mach-number elm)))
|
21 |
|
|
; (current-mach-list))))
|
22 |
|
|
"Generating machine table decls ...\n"""; (gen-decl mach-table)
|
23 |
|
|
"Generating machine table defns ...\n""\
|
24 |
|
|
/* Machine variants. */
|
25 |
|
|
|
26 |
|
|
static const CGEN_MACH @arch@_cgen_mach_table[] = {
|
27 |
|
|
"" { ""\"""\", ""\"""\", "", "" },\n""\
|
28 |
|
|
{ 0, 0, 0, 0 }
|
29 |
|
|
};
|
30 |
|
|
\n"; Attribute support code.
|
31 |
|
|
; Return C code to describe the various attributes.
|
32 |
|
|
"Generating attribute table decls ...\n""/* Attributes. */\n""extern const CGEN_ATTR_TABLE @arch@_cgen_hardware_attr_table[];\n""extern const CGEN_ATTR_TABLE @arch@_cgen_ifield_attr_table[];\n""extern const CGEN_ATTR_TABLE @arch@_cgen_operand_attr_table[];\n""extern const CGEN_ATTR_TABLE @arch@_cgen_insn_attr_table[];\n""\n"; Alternative GEN-MASK argument to gen-bool-attrs.
|
33 |
|
|
; This uses the `A' macro to abbreviate the attribute definition.
|
34 |
|
|
"A("")"; Instruction fields support code.
|
35 |
|
|
; Return C code to declare various ifield bits.
|
36 |
|
|
"Generating instruction field decls ...\n""/* Ifield support. */\n\n""/* Ifield attribute indices. */\n\n""cgen_ifld""cgen_ifld""@arch@ ifield types""@ARCH@_""#define MAX_IFLD ((int) @ARCH@_F_MAX)\n\n"; Return C code to define the instruction field table,
|
37 |
|
|
; and any other ifield related definitions.
|
38 |
|
|
"Generating ifield table ...\n""
|
39 |
|
|
/* The instruction field table. */
|
40 |
|
|
|
41 |
|
|
""A(a) (1 << CGEN_IFLD_""a)""
|
42 |
|
|
|
43 |
|
|
{
|
44 |
|
|
"" { "", ""\"""\", ""0, 0, 0, 0,"", "", "", "", "" },\n""\
|
45 |
|
|
{ 0, 0, 0, 0, 0, 0, "" }
|
46 |
|
|
};
|
47 |
|
|
|
48 |
|
|
#undef A
|
49 |
|
|
|
50 |
|
|
"; Hardware support.
|
51 |
|
|
; Return C code to declare the various hardware bits
|
52 |
|
|
|
53 |
|
|
"Generating hardware decls ...\n""/* Hardware attribute indices. */\n\n""cgen_hw""cgen_hw""@arch@ hardware types""HW_"; FIXME: @ARCH@_
|
54 |
|
|
"#define MAX_HW ((int) HW_MAX)\n\n"; Return declarations of variables tables used by HW.
|
55 |
|
|
""""; Return C code to declare the various hardware bits
|
56 |
|
|
; that must be defined after including opcode/cgen.h.
|
57 |
|
|
|
58 |
|
|
; Only do this for `PRIVATE' elements. Public ones are emitted elsewhere.
|
59 |
|
|
""""; Generate the tables for the various hardware bits (register names, etc.).
|
60 |
|
|
|
61 |
|
|
; which collects them all together.
|
62 |
|
|
; Uses include looking up a particular register set so that a new reg
|
63 |
|
|
; can be added to it [at runtime].
|
64 |
|
|
|
65 |
|
|
/* The hardware table. */
|
66 |
|
|
|
67 |
|
|
""A(a) (1 << CGEN_HW_""a)""
|
68 |
|
|
const CGEN_HW_ENTRY @arch@_cgen_hw_table[] =
|
69 |
|
|
{
|
70 |
|
|
"" { ""\"""\", "", "; ??? No element currently requires both indices and
|
71 |
|
|
; values specs so we only output the needed one.
|
72 |
|
|
"CGEN_ASM_NONE, 0, "" },\n""\
|
73 |
|
|
{ 0, 0, CGEN_ASM_NONE, 0, "" }
|
74 |
|
|
};
|
75 |
|
|
|
76 |
|
|
#undef A
|
77 |
|
|
|
78 |
|
|
"; Utilities of cgen-opc.h.
|
79 |
|
|
; Return #define's of several constants.
|
80 |
|
|
; FIXME: Some of these to be moved into table of structs, one per cpu family.
|
81 |
|
|
"Generating #define's ...\n""#include \"opcode/cgen-bitset.h\"\n""\n""#define CGEN_ARCH @arch@\n\n""/* Given symbol S, return @arch@_cgen_<S>. */\n""CGEN_SYM(s) @arch@""_cgen_""s""\n\n/* Selected cpu families. */\n"; FIXME: Move to sim's arch.h.
|
82 |
|
|
"#define HAVE_CPU_""\n""\n""#define CGEN_INSN_LSB0_P ""1""0""\n\n""/* Minimum size of any insn (in bytes). */\n""#define CGEN_MIN_INSN_SIZE ""\n\n""/* Maximum size of any insn (in bytes). */\n""#define CGEN_MAX_INSN_SIZE ""\n\n"; This tells the assembler/disassembler whether or not it can use an int to
|
83 |
|
|
|
84 |
|
|
; insn buffer, only enable this if all isas support it.
|
85 |
|
|
|
86 |
|
|
"\n""\n""/* CGEN_MNEMONIC_OPERANDS is defined if mnemonics have operands.\n"" e.g. In \"b,a foo\" the \",a\" is an operand. If mnemonics have operands\n"" we can't hash on everything up to the space. */\n""/*#define CGEN_MNEMONIC_OPERANDS*/\n""#define CGEN_MNEMONIC_OPERANDS\n""\n"; "/* Maximum number of operands any insn or macro-insn has. */\n"
|
87 |
|
|
|
88 |
|
|
; "#define CGEN_MAX_INSN_OPERANDS 16\n"
|
89 |
|
|
; "\n"
|
90 |
|
|
"/* Maximum number of fields in an instruction. */\n""#define CGEN_ACTUAL_MAX_IFMT_OPERANDS ""\n\n"; Operand support.
|
91 |
|
|
; Return C code to declare various operand bits.
|
92 |
|
|
"Generating operand decls ...\n""/* Operand attribute indices. */\n\n""cgen_operand""cgen_operand""@arch@ operand types""@ARCH@_OPERAND_""/* Number of operands types. */\n""#define MAX_OPERANDS ""\n\n"; was: "#define MAX_OPERANDS ((int) @ARCH@_OPERAND_MAX)\n\n"
|
93 |
|
|
"/* Maximum number of operands referenced by any insn. */\n""#define MAX_OPERAND_INSTANCES ""\n\n"; Generate C code to define the operand table.
|
94 |
|
|
"0""0""&""_MULTI_IFIELD[0]"; else
|
95 |
|
|
"&@arch@_cgen_ifld_table[""]""{ "", { (const PTR) "" } }""\n\n/* multi ifield declarations */\n\n""const CGEN_MAYBE_MULTI_IFLD ""_MULTI_IFIELD [];\n""\n\n/* multi ifield definitions */\n\n""const CGEN_MAYBE_MULTI_IFLD ""_MULTI_IFIELD [] =\n{""\n "",""\n { 0, { (const PTR) 0 } }\n};\n""Generating operand table ...\n""
|
96 |
|
|
/* The operand table. */
|
97 |
|
|
|
98 |
|
|
""A(a) (1 << CGEN_OPERAND_""a)""OPERAND(op) @ARCH@_OPERAND_""op""
|
99 |
|
|
|
100 |
|
|
{
|
101 |
|
|
""/* "": "" */\n"""" { ""\"""\", "", "", "", "",\n"" "", \n"" "" },\n""/* sentinel */\n\
|
102 |
|
|
|
103 |
|
|
};
|
104 |
|
|
|
105 |
|
|
#undef A
|
106 |
|
|
|
107 |
|
|
"; Instruction table support.
|
108 |
|
|
|
109 |
|
|
"Generating instruction decls ...\n""/* Insn attribute indices. */\n\n""cgen_insn""cgen_insn"; Generate an insn table entry for INSN.
|
110 |
|
|
|
111 |
|
|
; NUM-NON-BOOLS is the number of non-boolean insn attributes.
|
112 |
|
|
"/* "" */\n"" {\n"" ""-1"", ""\"""\", ""\"""\", ";(if (has-attr? insn 'ALIAS) "0" (number->string (insn-length insn))) ",\n"
|
113 |
|
|
",\n"; ??? There is currently a problem with embedded newlines, and this might
|
114 |
|
|
; best be put in another file [the table is already pretty big].
|
115 |
|
|
; Might also wish to output bytecodes instead.
|
116 |
|
|
; " "
|
117 |
|
|
; (if (insn-semantics insn)
|
118 |
|
|
; (string-append "\""
|
119 |
|
|
; (with-output-to-string
|
120 |
|
|
; ; ??? Should we do macro expansion here?
|
121 |
|
|
; (lambda () (display (insn-semantics insn))))
|
122 |
|
|
; "\"")
|
123 |
|
|
; "0")
|
124 |
|
|
; ",\n"
|
125 |
|
|
|
126 |
|
|
; (either as plain text or bytecodes).
|
127 |
|
|
; Values could be lazily computed and cached.
|
128 |
|
|
|
129 |
|
|
"Generating instruction table ...\n""
|
130 |
|
|
/* The instruction table. */
|
131 |
|
|
|
132 |
|
|
#define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field))
|
133 |
|
|
""A(a) (1 << CGEN_INSN_""a)""
|
134 |
|
|
static const CGEN_IBASE @arch@_cgen_insn_table[MAX_INSNS] =
|
135 |
|
|
{
|
136 |
|
|
/* Special null first entry.
|
137 |
|
|
|
138 |
|
|
Also, the special `invalid' insn resides here. */
|
139 |
|
|
{ 0, 0, 0, 0, "" },\n""Generating insn table entry for "" ...\n""\
|
140 |
|
|
};
|
141 |
|
|
|
142 |
|
|
#undef OP
|
143 |
|
|
#undef A
|
144 |
|
|
|
145 |
|
|
"; Cpu table handling support.
|
146 |
|
|
;
|
147 |
|
|
; ??? A lot of this can live in a machine independent file, but there's
|
148 |
|
|
; currently no place to put this file (there's no libcgen). libopcodes is the
|
149 |
|
|
; wrong place as some simulator ports use this but they don't use libopcodes.
|
150 |
|
|
; Return C routines to open/close a cpu description table.
|
151 |
|
|
; This is defined here and not in cgen-opc.in because it refers to
|
152 |
|
|
; CGEN_{ASM,DIS}_HASH and insn_table/macro_insn_table which is defined
|
153 |
|
|
; earlier in the file. ??? Things can certainly be rearranged though
|
154 |
|
|
; and opcodes/cgen.sh modified to insert the generated part into the middle
|
155 |
|
|
; of the file like is done for assembler/disassembler support.
|
156 |
|
|
"\
|
157 |
|
|
static const CGEN_MACH * lookup_mach_via_bfd_name (const CGEN_MACH *, const char *);
|
158 |
|
|
static void build_hw_table (CGEN_CPU_TABLE *);
|
159 |
|
|
static void build_ifield_table (CGEN_CPU_TABLE *);
|
160 |
|
|
static void build_operand_table (CGEN_CPU_TABLE *);
|
161 |
|
|
static void build_insn_table (CGEN_CPU_TABLE *);
|
162 |
|
|
static void @arch@_cgen_rebuild_tables (CGEN_CPU_TABLE *);
|
163 |
|
|
|
164 |
|
|
/* Subroutine of @arch@_cgen_cpu_open to look up a mach via its bfd name. */
|
165 |
|
|
|
166 |
|
|
static const CGEN_MACH *
|
167 |
|
|
|
168 |
|
|
{
|
169 |
|
|
|
170 |
|
|
{
|
171 |
|
|
if (strcmp (name, table->bfd_name) == 0)
|
172 |
|
|
return table;
|
173 |
|
|
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
static void
|
181 |
|
|
build_hw_table (CGEN_CPU_TABLE *cd)
|
182 |
|
|
{
|
183 |
|
|
int i;
|
184 |
|
|
int machs = cd->machs;
|
185 |
|
|
const CGEN_HW_ENTRY *init = & @arch@_cgen_hw_table[0];
|
186 |
|
|
/* MAX_HW is only an upper bound on the number of selected entries.
|
187 |
|
|
However each entry is indexed by it's enum so there can be holes in
|
188 |
|
|
the table. */
|
189 |
|
|
const CGEN_HW_ENTRY **selected =
|
190 |
|
|
(const CGEN_HW_ENTRY **) xmalloc (MAX_HW * sizeof (CGEN_HW_ENTRY *));
|
191 |
|
|
|
192 |
|
|
cd->hw_table.init_entries = init;
|
193 |
|
|
cd->hw_table.entry_size = sizeof (CGEN_HW_ENTRY);
|
194 |
|
|
memset (selected, 0, MAX_HW * sizeof (CGEN_HW_ENTRY *));
|
195 |
|
|
/* ??? For now we just use machs to determine which ones we want. */
|
196 |
|
|
for (i = 0; init[i].name != NULL; ++i)
|
197 |
|
|
if (CGEN_HW_ATTR_VALUE (&init[i], CGEN_HW_MACH)
|
198 |
|
|
|
199 |
|
|
selected[init[i].type] = &init[i];
|
200 |
|
|
|
201 |
|
|
cd->hw_table.num_entries = MAX_HW;
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
/* Subroutine of @arch@_cgen_cpu_open to build the hardware table. */
|
205 |
|
|
|
206 |
|
|
static void
|
207 |
|
|
build_ifield_table (CGEN_CPU_TABLE *cd)
|
208 |
|
|
{
|
209 |
|
|
cd->ifld_table = & @arch@_cgen_ifld_table[0];
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
/* Subroutine of @arch@_cgen_cpu_open to build the hardware table. */
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
build_operand_table (CGEN_CPU_TABLE *cd)
|
216 |
|
|
{
|
217 |
|
|
int i;
|
218 |
|
|
int machs = cd->machs;
|
219 |
|
|
const CGEN_OPERAND *init = & @arch@_cgen_operand_table[0];
|
220 |
|
|
/* MAX_OPERANDS is only an upper bound on the number of selected entries.
|
221 |
|
|
However each entry is indexed by it's enum so there can be holes in
|
222 |
|
|
the table. */
|
223 |
|
|
const CGEN_OPERAND **selected = xmalloc (MAX_OPERANDS * sizeof (* selected));
|
224 |
|
|
|
225 |
|
|
cd->operand_table.init_entries = init;
|
226 |
|
|
cd->operand_table.entry_size = sizeof (CGEN_OPERAND);
|
227 |
|
|
|
228 |
|
|
/* ??? For now we just use mach to determine which ones we want. */
|
229 |
|
|
for (i = 0; init[i].name != NULL; ++i)
|
230 |
|
|
if (CGEN_OPERAND_ATTR_VALUE (&init[i], CGEN_OPERAND_MACH)
|
231 |
|
|
& machs)
|
232 |
|
|
selected[init[i].type] = &init[i];
|
233 |
|
|
cd->operand_table.entries = selected;
|
234 |
|
|
cd->operand_table.num_entries = MAX_OPERANDS;
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
/* Subroutine of @arch@_cgen_cpu_open to build the hardware table.
|
238 |
|
|
??? This could leave out insns not supported by the specified mach/isa,
|
239 |
|
|
but that would cause errors like \"foo only supported by bar\" to become
|
240 |
|
|
|
241 |
|
|
do the checking later.
|
242 |
|
|
??? On the other hand, parsing of such insns may require their hardware or
|
243 |
|
|
operand elements to be in the table [which they mightn't be]. */
|
244 |
|
|
|
245 |
|
|
static void
|
246 |
|
|
|
247 |
|
|
{
|
248 |
|
|
int i;
|
249 |
|
|
const CGEN_IBASE *ib = & @arch@_cgen_insn_table[0];
|
250 |
|
|
CGEN_INSN *insns = xmalloc (MAX_INSNS * sizeof (CGEN_INSN));
|
251 |
|
|
|
252 |
|
|
memset (insns, 0, MAX_INSNS * sizeof (CGEN_INSN));
|
253 |
|
|
for (i = 0; i < MAX_INSNS; ++i)
|
254 |
|
|
insns[i].base = &ib[i];
|
255 |
|
|
cd->insn_table.init_entries = insns;
|
256 |
|
|
|
257 |
|
|
cd->insn_table.num_init_entries = MAX_INSNS;
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
/* Subroutine of @arch@_cgen_cpu_open to rebuild the tables. */
|
261 |
|
|
|
262 |
|
|
static void
|
263 |
|
|
@arch@_cgen_rebuild_tables (CGEN_CPU_TABLE *cd)
|
264 |
|
|
{
|
265 |
|
|
int i;
|
266 |
|
|
CGEN_BITSET *isas = cd->isas;
|
267 |
|
|
unsigned int machs = cd->machs;
|
268 |
|
|
|
269 |
|
|
cd->int_insn_p = CGEN_INT_INSN_P;
|
270 |
|
|
|
271 |
|
|
/* Data derived from the isa spec. */
|
272 |
|
|
#define UNSET (CGEN_SIZE_UNKNOWN + 1)
|
273 |
|
|
cd->default_insn_bitsize = UNSET;
|
274 |
|
|
cd->base_insn_bitsize = UNSET;
|
275 |
|
|
cd->min_insn_bitsize = 65535; /* Some ridiculously big number. */
|
276 |
|
|
cd->max_insn_bitsize = 0;
|
277 |
|
|
for (i = 0; i < MAX_ISAS; ++i)
|
278 |
|
|
if (cgen_bitset_contains (isas, i))
|
279 |
|
|
{
|
280 |
|
|
const CGEN_ISA *isa = & @arch@_cgen_isa_table[i];
|
281 |
|
|
|
282 |
|
|
/* Default insn sizes of all selected isas must be
|
283 |
|
|
equal or we set the result to 0, meaning \"unknown\". */
|
284 |
|
|
|
285 |
|
|
cd->default_insn_bitsize = isa->default_insn_bitsize;
|
286 |
|
|
|
287 |
|
|
; /* This is ok. */
|
288 |
|
|
else
|
289 |
|
|
cd->default_insn_bitsize = CGEN_SIZE_UNKNOWN;
|
290 |
|
|
|
291 |
|
|
/* Base insn sizes of all selected isas must be equal
|
292 |
|
|
|
293 |
|
|
if (cd->base_insn_bitsize == UNSET)
|
294 |
|
|
cd->base_insn_bitsize = isa->base_insn_bitsize;
|
295 |
|
|
|
296 |
|
|
; /* This is ok. */
|
297 |
|
|
else
|
298 |
|
|
cd->base_insn_bitsize = CGEN_SIZE_UNKNOWN;
|
299 |
|
|
|
300 |
|
|
/* Set min,max insn sizes. */
|
301 |
|
|
if (isa->min_insn_bitsize < cd->min_insn_bitsize)
|
302 |
|
|
cd->min_insn_bitsize = isa->min_insn_bitsize;
|
303 |
|
|
if (isa->max_insn_bitsize > cd->max_insn_bitsize)
|
304 |
|
|
cd->max_insn_bitsize = isa->max_insn_bitsize;
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
/* Data derived from the mach spec. */
|
308 |
|
|
for (i = 0; i < MAX_MACHS; ++i)
|
309 |
|
|
if (((1 << i) & machs) != 0)
|
310 |
|
|
{
|
311 |
|
|
const CGEN_MACH *mach = & @arch@_cgen_mach_table[i];
|
312 |
|
|
|
313 |
|
|
if (mach->insn_chunk_bitsize != 0)
|
314 |
|
|
{
|
315 |
|
|
if (cd->insn_chunk_bitsize != 0 && cd->insn_chunk_bitsize != mach->insn_chunk_bitsize)
|
316 |
|
|
{
|
317 |
|
|
fprintf (stderr, \"@arch@_cgen_rebuild_tables: conflicting insn-chunk-bitsize values: `%d' vs. `%d'\\n\",
|
318 |
|
|
cd->insn_chunk_bitsize, mach->insn_chunk_bitsize);
|
319 |
|
|
abort ();
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
cd->insn_chunk_bitsize = mach->insn_chunk_bitsize;
|
323 |
|
|
}
|
324 |
|
|
}
|
325 |
|
|
|
326 |
|
|
/* Determine which hw elements are used by MACH. */
|
327 |
|
|
build_hw_table (cd);
|
328 |
|
|
|
329 |
|
|
/* Build the ifield table. */
|
330 |
|
|
build_ifield_table (cd);
|
331 |
|
|
|
332 |
|
|
/* Determine which operands are used by MACH/ISA. */
|
333 |
|
|
build_operand_table (cd);
|
334 |
|
|
|
335 |
|
|
/* Build the instruction table. */
|
336 |
|
|
build_insn_table (cd);
|
337 |
|
|
}
|
338 |
|
|
|
339 |
|
|
/* Initialize a cpu table and return a descriptor.
|
340 |
|
|
It's much like opening a file, and must be the first function called.
|
341 |
|
|
The arguments are a set of (type/value) pairs, terminated with
|
342 |
|
|
CGEN_CPU_OPEN_END.
|
343 |
|
|
|
344 |
|
|
Currently supported values:
|
345 |
|
|
CGEN_CPU_OPEN_ISAS: bitmap of values in enum isa_attr
|
346 |
|
|
CGEN_CPU_OPEN_MACHS: bitmap of values in enum mach_attr
|
347 |
|
|
CGEN_CPU_OPEN_BFDMACH: specify 1 mach using bfd name
|
348 |
|
|
CGEN_CPU_OPEN_ENDIAN: specify endian choice
|
349 |
|
|
CGEN_CPU_OPEN_END: terminates arguments
|
350 |
|
|
|
351 |
|
|
??? Simultaneous multiple isas might not make sense, but it's not (yet)
|
352 |
|
|
precluded.
|
353 |
|
|
|
354 |
|
|
??? We only support ISO C stdargs here, not K&R.
|
355 |
|
|
Laziness, plus experiment to see if anything requires K&R - eventually
|
356 |
|
|
K&R will no longer be supported - e.g. GDB is currently trying this. */
|
357 |
|
|
|
358 |
|
|
|
359 |
|
|
@arch@_cgen_cpu_open (enum cgen_cpu_open_arg arg_type, ...)
|
360 |
|
|
|
361 |
|
|
CGEN_CPU_TABLE *cd = (CGEN_CPU_TABLE *) xmalloc (sizeof (CGEN_CPU_TABLE));
|
362 |
|
|
|
363 |
|
|
CGEN_BITSET *isas = 0; /* 0 = \"unspecified\" */
|
364 |
|
|
unsigned int machs = 0; /* 0 = \"unspecified\" */
|
365 |
|
|
enum cgen_endian endian = CGEN_ENDIAN_UNKNOWN;
|
366 |
|
|
va_list ap;
|
367 |
|
|
|
368 |
|
|
if (! init_p)
|
369 |
|
|
{
|
370 |
|
|
init_tables ();
|
371 |
|
|
init_p = 1;
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
memset (cd, 0, sizeof (*cd));
|
375 |
|
|
|
376 |
|
|
va_start (ap, arg_type);
|
377 |
|
|
while (arg_type != CGEN_CPU_OPEN_END)
|
378 |
|
|
{
|
379 |
|
|
switch (arg_type)
|
380 |
|
|
{
|
381 |
|
|
case CGEN_CPU_OPEN_ISAS :
|
382 |
|
|
isas = va_arg (ap, CGEN_BITSET *);
|
383 |
|
|
|
384 |
|
|
case CGEN_CPU_OPEN_MACHS :
|
385 |
|
|
|
386 |
|
|
break;
|
387 |
|
|
case CGEN_CPU_OPEN_BFDMACH :
|
388 |
|
|
{
|
389 |
|
|
const char *name = va_arg (ap, const char *);
|
390 |
|
|
const CGEN_MACH *mach =
|
391 |
|
|
lookup_mach_via_bfd_name (@arch@_cgen_mach_table, name);
|
392 |
|
|
|
393 |
|
|
machs |= 1 << mach->num;
|
394 |
|
|
break;
|
395 |
|
|
}
|
396 |
|
|
|
397 |
|
|
endian = va_arg (ap, enum cgen_endian);
|
398 |
|
|
break;
|
399 |
|
|
default :
|
400 |
|
|
fprintf (stderr, \"@arch@_cgen_cpu_open: unsupported argument `%d'\\n\",
|
401 |
|
|
arg_type);
|
402 |
|
|
|
403 |
|
|
}
|
404 |
|
|
arg_type = va_arg (ap, enum cgen_cpu_open_arg);
|
405 |
|
|
}
|
406 |
|
|
va_end (ap);
|
407 |
|
|
|
408 |
|
|
/* Mach unspecified means \"all\". */
|
409 |
|
|
if (machs == 0)
|
410 |
|
|
machs = (1 << MAX_MACHS) - 1;
|
411 |
|
|
/* Base mach is always selected. */
|
412 |
|
|
machs |= 1;
|
413 |
|
|
if (endian == CGEN_ENDIAN_UNKNOWN)
|
414 |
|
|
|
415 |
|
|
/* ??? If target has only one, could have a default. */
|
416 |
|
|
fprintf (stderr, \"@arch@_cgen_cpu_open: no endianness specified\\n\");
|
417 |
|
|
abort ();
|
418 |
|
|
}
|
419 |
|
|
|
420 |
|
|
cd->isas = cgen_bitset_copy (isas);
|
421 |
|
|
cd->machs = machs;
|
422 |
|
|
cd->endian = endian;
|
423 |
|
|
/* FIXME: for the sparc case we can determine insn-endianness statically.
|
424 |
|
|
The worry here is where both data and insn endian can be independently
|
425 |
|
|
chosen, in which case this function will need another argument.
|
426 |
|
|
Actually, will want to allow for more arguments in the future anyway. */
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
/* Table (re)builder. */
|
430 |
|
|
cd->rebuild_tables = @arch@_cgen_rebuild_tables;
|
431 |
|
|
@arch@_cgen_rebuild_tables (cd);
|
432 |
|
|
|
433 |
|
|
/* Default to not allowing signed overflow. */
|
434 |
|
|
cd->signed_overflow_ok_p = 0;
|
435 |
|
|
|
436 |
|
|
return (CGEN_CPU_DESC) cd;
|
437 |
|
|
}
|
438 |
|
|
|
439 |
|
|
|
440 |
|
|
MACH_NAME is the bfd name of the mach. */
|
441 |
|
|
|
442 |
|
|
CGEN_CPU_DESC
|
443 |
|
|
@arch@_cgen_cpu_open_1 (const char *mach_name, enum cgen_endian endian)
|
444 |
|
|
{
|
445 |
|
|
return @arch@_cgen_cpu_open (CGEN_CPU_OPEN_BFDMACH, mach_name,
|
446 |
|
|
CGEN_CPU_OPEN_ENDIAN, endian,
|
447 |
|
|
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
/* Close a cpu table.
|
451 |
|
|
??? This can live in a machine independent file, but there's currently
|
452 |
|
|
no place to put this file (there's no libcgen). libopcodes is the wrong
|
453 |
|
|
place as some simulator ports use this but they don't use libopcodes. */
|
454 |
|
|
|
455 |
|
|
void
|
456 |
|
|
@arch@_cgen_cpu_close (CGEN_CPU_DESC cd)
|
457 |
|
|
{
|
458 |
|
|
unsigned int i;
|
459 |
|
|
const CGEN_INSN *insns;
|
460 |
|
|
|
461 |
|
|
if (cd->macro_insn_table.init_entries)
|
462 |
|
|
{
|
463 |
|
|
insns = cd->macro_insn_table.init_entries;
|
464 |
|
|
for (i = 0; i < cd->macro_insn_table.num_init_entries; ++i, ++insns)
|
465 |
|
|
if (CGEN_INSN_RX ((insns)))
|
466 |
|
|
regfree (CGEN_INSN_RX (insns));
|
467 |
|
|
}
|
468 |
|
|
|
469 |
|
|
if (cd->insn_table.init_entries)
|
470 |
|
|
{
|
471 |
|
|
insns = cd->insn_table.init_entries;
|
472 |
|
|
for (i = 0; i < cd->insn_table.num_init_entries; ++i, ++insns)
|
473 |
|
|
if (CGEN_INSN_RX (insns))
|
474 |
|
|
regfree (CGEN_INSN_RX (insns));
|
475 |
|
|
}
|
476 |
|
|
|
477 |
|
|
if (cd->macro_insn_table.init_entries)
|
478 |
|
|
free ((CGEN_INSN *) cd->macro_insn_table.init_entries);
|
479 |
|
|
|
480 |
|
|
if (cd->insn_table.init_entries)
|
481 |
|
|
|
482 |
|
|
|
483 |
|
|
|
484 |
|
|
free ((CGEN_HW_ENTRY *) cd->hw_table.entries);
|
485 |
|
|
|
486 |
|
|
if (cd->operand_table.entries)
|
487 |
|
|
free ((CGEN_HW_ENTRY *) cd->operand_table.entries);
|
488 |
|
|
|
489 |
|
|
free (cd);
|
490 |
|
|
|
491 |
|
|
|
492 |
|
|
|
493 |
|
|
; Code is appended during processing.
|
494 |
|
|
""; Return the C code to define the various initialization functions.
|
495 |
|
|
; This does not include assembler/disassembler specific stuff.
|
496 |
|
|
; Generally, this function doesn't do anything.
|
497 |
|
|
; It exists to allow a global-static-constructor kind of thing should
|
498 |
|
|
; one ever be necessary.
|
499 |
|
|
"Generating init fns ...\n""\
|
500 |
|
|
/* Initialize anything needed to be done once, before any cpu_open call. */
|
501 |
|
|
|
502 |
|
|
static void
|
503 |
|
|
init_tables (void)
|
504 |
|
|
{\n""}\n\n"; Top level C code generators
|
505 |
|
|
|
506 |
|
|
; Then they'd be usable and we wouldn't have to special case them here.
|
507 |
|
|
"Generating ""-desc.h ...\n""CPU data header for @arch@.""\
|
508 |
|
|
#ifndef @ARCH@_CPU_H
|
509 |
|
|
#define @ARCH@_CPU_H
|
510 |
|
|
|
511 |
|
|
"; This is defined in arch.h. It's not defined here as there is yet to
|
512 |
|
|
; be a need for it in the assembler/disassembler.
|
513 |
|
|
;(gen-enum-decl 'model_type "model types"
|
514 |
|
|
; "MODEL_"
|
515 |
|
|
; (append (map list (map obj:name (current-model-list))) '((max))))
|
516 |
|
|
;"#define MAX_MODELS ((int) MODEL_MAX)\n\n"
|
517 |
|
|
"/* Enums. */\n\n""/* Attributes. */\n\n""/* Number of architecture variants. */\n"; If there is only 1 isa, leave out special handling. */
|
518 |
|
|
"#define MAX_ISAS 1\n""#define MAX_ISAS ((int) ISA_MAX)\n""#define MAX_MACHS ((int) MACH_MAX)\n\n""/* cgen.h uses things we just defined. */\n""#include \"opcode/cgen.h\"\n\n""extern const struct cgen_ifld @arch@_cgen_ifld_table[];\n\n""\n""""
|
519 |
|
|
|
520 |
|
|
#endif /* @ARCH@_CPU_H */
|
521 |
|
|
"; This file contains the "top level" definitions of the cpu.
|
522 |
|
|
; This includes various elements of the description file, expressed in C.
|
523 |
|
|
;
|
524 |
|
|
; ??? A lot of this file can go in a machine-independent file! However,
|
525 |
|
|
; some simulators don't use the cgen opcodes support so there is currently
|
526 |
|
|
; no place to put this file. To be revisited when we do have such a place.
|
527 |
|
|
"Generating ""-desc.c ...\n""CPU data for @arch@.""\
|
528 |
|
|
#include \"sysdep.h\"
|
529 |
|
|
#include <stdio.h>
|
530 |
|
|
#include <stdarg.h>
|
531 |
|
|
#include \"ansidecl.h\"
|
532 |
|
|
#include \"bfd.h\"
|
533 |
|
|
#include \"symcat.h\"
|
534 |
|
|
#include \"@arch@-desc.h\"
|
535 |
|
|
#include \"@arch@-opc.h\"
|
536 |
|
|
#include \"opintl.h\"
|
537 |
|
|
|
538 |
|
|
#include \"xregex.h\"
|
539 |
|
|
|