OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [sid-decode.scm] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jlechner
; Decoder generation.
2
; Copyright (C) 2000, 2002, 2003, 2009 Red Hat, Inc.
3
; This file is part of CGEN.
4
 
5
; ??? At one point we generated one variable per instruction rather than one
6
; big array.  It doesn't matter too much (yet).  Generating one big array is
7
; simpler.
8
; Print the higher detailed stuff at higher verbosity.
9
 
10
// The instruction descriptor array.
11
\n""\
12
// Have label pointers been initialized?
13
 
14
// functions to handle machine variants.
15
bool @prefix@_idesc::idesc_table_initialized_p = false;\n\n""""\
16
@prefix@_idesc @prefix@_idesc::idesc_table[@PREFIX@_INSN_"" + 1] =
17
 
18
"\
19
// Given a canonical virtual insn id, return the target specific one.
20
 
21
@prefix@_insn_type
22
 
23
{
24
  switch (vit)
25
    {
26
      case VIRTUAL_INSN_INVALID: return @PREFIX@_INSN_X_INVALID;
27
""\
28
      case VIRTUAL_INSN_BEGIN: return @PREFIX@_INSN_X_BEGIN;
29
      case VIRTUAL_INSN_CHAIN: return @PREFIX@_INSN_X_CHAIN;
30
 
31
      case VIRTUAL_INSN_BEFORE: return @PREFIX@_INSN_X_BEFORE;
32
      case VIRTUAL_INSN_AFTER: return @PREFIX@_INSN_X_AFTER;
33
""""\
34
 
35
"; Unused, but may still be requested.  Just return X_INVALID.
36
"\
37
      case VIRTUAL_INSN_COND: return @PREFIX@_INSN_X_INVALID;
38
""\
39
    }
40
  abort ();
41
}\n\n"; Return enum name of format FMT.
42
; Return names of semantic fns for INSN.
43
; ??? Make global, call from gen-semantic-fn, blah blah blah.
44
"@prefix@_sem_"; Return decls of each semantic fn.
45
"// Decls of each semantic fn.\n\n""using @cpu@::@prefix@_sem_fn;\n""extern @prefix@_sem_fn "";\n""\n"; idesc, argbuf, and scache types
46
; Generate decls for the insn descriptor table type IDESC.
47
"
48
// Forward decls.
49
struct @cpu@_cpu;
50
struct @prefix@_scache;
51
""typedef void (@prefix@_sem_fn) (@cpu@_cpu* cpu, @prefix@_scache* sem, int tick, @prefix@::write_stacks &buf);""typedef sem_status (@prefix@_sem_fn) (@cpu@_cpu* cpu, @prefix@_scache* sem);""\n""\n""
52
// Instruction descriptor.
53
 
54
struct @prefix@_idesc {
55
\n""\
56
  // computed-goto label pointer (pbb engine)
57
 
58
  cgoto_label cgoto;\n\n""""\
59
  // scache engine executor for this insn
60
  @prefix@_sem_fn* execute;\n\n""""\
61
 
62
  enum @prefix@_insn_type sem_index;
63
 
64
 
65
  // idesc table: indexed by sem_index
66
  static @prefix@_idesc idesc_table[];
67
""\
68
 
69
  // semantic label pointers filled_in?
70
  static bool idesc_table_initialized_p;\n""""\
71
 
72
  static @prefix@_insn_type lookup_virtual (virtual_insn_type vit);
73
};
74
 
75
"; Utility of -gen-argbuf-fields-union to generate the definition for
76
 
77
"Processing sbuf format "" ...\n""  struct { /* "" */\n""    int empty;\n""    "" "";\n""  } "";\n"; Utility of -gen-scache-decls to generate the union of extracted ifields.
78
"\
79
// Instruction argument buffer.
80
 
81
union @prefix@_sem_fields {\n""\
82
  // This one is for chain/cti-chain virtual insns.
83
  struct {
84
    // Number of insns in pbb.
85
    unsigned insn_count;
86
    // This is used by chain insns and by untaken conditional branches.
87
    @prefix@_scache* next;
88
    @prefix@_scache* branch_target;
89
  } chain;
90
  // This one is for `before' virtual insns.
91
  struct {
92
    // The cache entry of the real insn.
93
    @prefix@_scache* insn;
94
  } before;
95
};\n\n""\
96
// Simulator instruction cache.
97
 
98
struct @prefix@_scache {
99
  // executor
100
  union {
101
 
102
    @prefix@_sem_fn* fn;
103
 
104
\n""\
105
  // condition
106
  UINT cond;
107
 
108
  // PC of this instruction.
109
  PCADDR addr;
110
 
111
  // instruction class
112
  @prefix@_idesc* idesc;
113
 
114
 
115
  @prefix@_sem_fields fields;
116
 
117
""
118
  // writeback flags
119
  // Only used if profiling or parallel execution support enabled during
120
  // file generation.
121
  unsigned long long written;
122
""""
123
 
124
  // decode given instruction
125
  void decode (@cpu@_cpu* current_cpu, PCADDR pc, @prefix@_insn_word base_insn, @prefix@_insn_word entire_insn);
126
};
127
 
128
"; Instruction field extraction support.
129
 
130
 
131
 
132
 
133
; extracted and stored in local variables.  Then any ifields requiring
134
 
135
; case the results are stored in a struct for later retrieval by the semantic
136
 
137
;
138
; The !with-scache case does this processing in the semantic function,
139
; except it doesn't need the last step (it doesn't need to store the results
140
; in a struct for later use).
141
;
142
; The with-scache case extracts the ifields in the decode function.
143
; Furthermore, we use <sformat-argbuf> to reduce the quantity of structures
144
; created (this helps semantic-fragment pbb engines).
145
; Return C code to record <ifield> F for the semantic handler
146
; in a local variable rather than an ARGBUF struct.
147
"  "" = "";\n"; Return three of arguments to TRACE:
148
; string argument to fprintf, character indicating type of third arg, value.
149
; The type is one of: x.
150
; FIXME: Add method to return fprintf format string.
151
 
152
; Hardware support.
153
; gen-extract method.
154
 
155
""; gen-trace-extract method.
156
; Return appropriate arguments for TRACE_EXTRACT.
157
""; Extract the necessary fields into ARGBUF.
158
"  "" = & "";\n"""; Return appropriate arguments for TRACE_EXTRACT.
159
; FIXME: Add method to return fprintf format string.
160
", \""" 0x%x\""", 'x'"", """; Extract the necessary fields into ARGBUF.
161
 
162
; FIXME: Add method to return fprintf format string.
163
", \""" 0x%x\""", 'x'"", "; Instruction field extraction support cont'd.
164
; Operand support.
165
; Return C code to record the field for the semantic handler.
166
; In the case of a register, this is usually the address of the register's
167
 
168
; LOCAL? indicates whether to record the value in a local variable or in
169
; the ARGBUF struct.
170
; ??? Later allow target to provide an `extract' expression.
171
; Return three of arguments to TRACE_EXTRACT:
172
 
173
; The type is one of: x.
174
; Return C code to define local vars to hold processed ifield data for
175
; <sformat> SFMT.
176
 
177
; Definitions of the extracted ifields is handled elsewhere.
178
"sfmt = "" operands=""  "" "";\n"""; Return C code to assign values to the local vars that hold processed ifield
179
 
180
; This is used when !with-scache.
181
; Assignment of the extracted ifields is handled elsewhere.
182
; Instruction field extraction support cont'd.
183
 
184
; Return C code to record insn field data for <sformat> SFMT.
185
 
186
"  /* Record the fields for the semantic handler.  */\n""  if (UNLIKELY(current_cpu->trace_extract_p))\n""    {\n""      current_cpu->trace_stream \n""        << \"0x\" << hex << pc << dec << \" ("")\\t\"\n"; NB: The following is not necessary any more, as the ifield list 
187
;     is a subset of the operand list.
188
 
189
;                       (string-list
190
;                        "        << \" " (gen-sym f) ":0x\" << hex << " (gen-sym f) " << dec\n"))
191
 
192
"        << \" "":0x\" << hex << "; Add (SI) or (USI) cast for byte-wide data, to prevent C++ iostreams
193
; from printing byte as plain raw char.
194
 
195
; Also recorded are operands not mentioned in the fields but mentioned
196
; in the semantic code.
197
;
198
; FIXME: Register usage may need to be tracked as an array of longs.
199
; If there are more than 32 regs, we can't know which until build time.
200
; ??? For now we only handle reg sets of 32 or less.
201
;
202
; ??? The other way to obtain register numbers is to defer computing them
203
; until they're actually needed.  It will speed up execution when not doing
204
; profiling, though the speed up is only for the extraction phase.
205
; On the other hand the current way has one memory reference per register
206
; number in the profiling routines.  For RISC this can be a lose, though for
207
; more complicated instruction sets it could be a win as all the computation
208
; is kept to the extraction phase.  If someone wants to put forth some real
209
; data, this might then be changed (or at least noted).
210
"""  /* Record the fields for profiling.  */\n""  if (UNLIKELY (current_cpu->trace_counter_p || current_cpu->final_insn_count_p))\n""    {\n""    }\n"; Return C code that extracts the fields of <sformat> SFMT.
211
 
212
; Extraction is based on formats to reduce the amount of code generated.
213
 
214
; by the semantic code.  This is currently done by recording this information
215
; with the format.
216
"Processing extractor for \"""\" ...\n""void
217
@prefix@_extract_"" (@prefix@_scache* abuf, @cpu@_cpu* current_cpu, PCADDR pc, @prefix@_insn_word base_insn, @prefix@_insn_word entire_insn)""{\n""    @prefix@_insn_word insn = ""entire_insn;\n""base_insn;\n""    ""\n""    ""\n""\n""}\n\n"; For each format, return its extraction function.
218
 
219
static void
220
@prefix@_extract_"" (@prefix@_scache* abuf, @cpu@_cpu* current_cpu, PCADDR pc, @prefix@_insn_word base_insn, @prefix@_insn_word entire_insn);"; Generate top level decoder.
221
; INITIAL-BITNUMS is a target supplied list of bit numbers to use to
222
; build the first decode table.  If nil, we compute 8 bits of it (FIXME)
223
; ourselves.
224
; LSB0? is non-#f if bit number 0 is the least significant bit.
225
; Compute the initial DECODE-BITSIZE as the minimum of all insn lengths.
226
; The caller of @prefix@_decode must fetch and pass exactly this number of bits
227
; of the instruction.
228
; ??? Make this a parameter later but only if necessary.
229
; Compute INITIAL-BITNUMS if not supplied.
230
; 0 is passed for the start bit (it is independent of lsb0?)
231
; dummy value
232
; startbit
233
; max
234
; All set.  gen-decoder does the hard part, we just print out the result. 
235
"    ""
236
// Declare extractor functions
237
""
238
 
239
// Fetch & decode instruction
240
void
241
@prefix@_scache::decode (@cpu@_cpu* current_cpu, PCADDR pc, @prefix@_insn_word base_insn, @prefix@_insn_word entire_insn)
242
{
243
  /* Result of decoder.  */
244
 
245
 
246
  {
247
    @prefix@_insn_word insn = base_insn;
248
\n""
249
  }
250
 
251
  /* The instruction has been decoded and fields extracted.  */
252
 
253
""  {\n""    ""    ""base_insn""    this->cond = "";\n""  }\n""""
254
  this->addr = pc;
255
  // FIXME: To be redone (to handle ISA variants).
256
  this->idesc = & @prefix@_idesc::idesc_table[itype];
257
  // ??? record semantic handler?
258
  assert(this->idesc->sem_index == itype);
259
 
260
 
261
"; Entry point.  Generate decode.h.
262
"Generating ""-decode.h ...\n"; Turn parallel execution support on if cpu needs it.
263
 
264
#ifndef @PREFIX@_DECODE_H
265
#define @PREFIX@_DECODE_H
266
 
267
""\
268
namespace @prefix@ {
269
 
270
struct write_stacks;
271
}
272
 
273
""""\
274
namespace @cpu@ {
275
 
276
using namespace cgen;
277
using namespace @arch@;
278
 
279
typedef UINT @prefix@_insn_word;
280
 
281
""\
282
 
283
\n"; ??? The semantic functions could go in the cpu's namespace.
284
; There's no pressing need for it though.
285
 
286
#endif /* @PREFIX@_DECODE_H */\n"; Entry point.  Generate decode.cxx.
287
"Generating ""-decode.cxx ...\n"; Turn parallel execution support on if cpu needs it.
288
; Tell the rtx->c translator we are the simulator.
289
"Simulator instruction decoder for @prefix@.""\
290
 
291
#if HAVE_CONFIG_H
292
#include \"config.h\"
293
#endif
294
#include \"@cpu@.h\"
295
 
296
using namespace @cpu@; // FIXME: namespace organization still wip
297
\n"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.