1 |
6 |
jlechner |
; CPU family related simulator generator, excluding decoding and model support.
|
2 |
|
|
; Copyright (C) 2000, 2002, 2003, 2005, 2006, 2009 Red Hat, Inc.
|
3 |
|
|
; This file is part of CGEN.
|
4 |
|
|
|
5 |
|
|
; cgen-desc.h
|
6 |
|
|
; Declare the attributes.
|
7 |
|
|
|
8 |
|
|
"// Insn attributes.\n\n"; FIXME: maybe make class, but that'll require a constructor. Later.
|
9 |
|
|
"struct @arch@_insn_attr {\n"" unsigned int bools;\n"""" "" "";\n";"public:\n"
|
10 |
|
|
" inline "" get_""_attr"" () { return ""(bools & ""cgen_insn"") != 0""; }\n""};\n\n"; Emit a macro that specifies the word-bitsize for each machine.
|
11 |
|
|
|
12 |
|
|
"Generating ""-desc.h ...\n""Misc. entries in the @arch@ description file.""\
|
13 |
|
|
|
14 |
|
|
#define DESC_@ARCH@_H
|
15 |
|
|
|
16 |
|
|
#include \"opcode/cgen-bitset.h\"
|
17 |
|
|
|
18 |
|
|
namespace @arch@ {
|
19 |
|
|
\n""// Enums.\n\n""
|
20 |
|
|
} // end @arch@ namespace
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
; cgen-cpu.h
|
24 |
|
|
|
25 |
|
|
; Get/set fns for hardware element HW.
|
26 |
|
|
"return ""regno"";""return this->hardware.""""[regno]"";"; not `mode', sets have mode VOID
|
27 |
|
|
"newval""regno""newval""this->hardware.""""[regno]"" = newval;"" inline "" "" (""""UINT regno"") const"" { "" }""\n"" inline void "" (""""UINT regno, "" newval)"" { "" }""\n\n"; Return a boolean indicating if hardware element HW needs storage allocated
|
28 |
|
|
; for it in the SIM_CPU struct.
|
29 |
|
|
; Subroutine of -gen-hardware-types to generate the struct containing
|
30 |
|
|
; hardware elements of one isa.
|
31 |
|
|
; If struct is empty, leave it out to simplify generated code.
|
32 |
|
|
""" // Hardware elements for "".\n"" // Hardware elements.\n"" struct {\n"" } ""_""""hardware;\n\n"; Return C type declarations of all of the hardware elements.
|
33 |
|
|
; The name of the type is prepended with the cpu family name.
|
34 |
|
|
"// CPU state information.\n\n""0""_writes""_memory""hardware."" ost << "" << ' ';\n"" for (int i = 0; i < ""; i++)\n ost << ""[i] << ' ';\n""hardware."" ist >> "";\n"" for (int i = 0; i < ""; i++)\n ist >> ""[i];\n"" stream_stacks ( stacks."", ost);\n"" destream_stacks ( stacks."", ist);\n"" template <typename ST> \n"" void stream_stacks (const ST &st, std::ostream &ost) const\n"" {\n"" for (int i = 0; i < @prefix@::pipe_sz; i++)\n"" {\n"" ost << st[i].t << ' ';\n"" for (int j = 0; j <= st[i].t; j++)\n"" {\n"" ost << st[i].buf[j].pc << ' ';\n"" ost << st[i].buf[j].val << ' ';\n"" ost << st[i].buf[j].idx0 << ' ';\n"" }\n"" }\n"" }\n"" \n"" template <typename ST> \n"" void destream_stacks (ST &st, std::istream &ist)\n"" {\n"" for (int i = 0; i < @prefix@::pipe_sz; i++)\n"" {\n"" ist >> st[i].t;\n"" for (int j = 0; j <= st[i].t; j++)\n"" {\n"" ist >> st[i].buf[j].pc;\n"" ist >> st[i].buf[j].val;\n"" ist >> st[i].buf[j].idx0;\n"" }\n"" }\n"" }\n"" \n"" void stream_cgen_hardware (std::ostream &ost) const \n {\n"" }\n"" void destream_cgen_hardware (std::istream &ist) \n {\n"" }\n"" void stream_cgen_write_stacks (std::ostream &ost, ""const @prefix@::write_stacks &stacks) const \n {\n"" }\n"" void destream_cgen_write_stacks (std::istream &ist, ""@prefix@::write_stacks &stacks) \n {\n"" }\n"""; Generate <cpu>-cpu.h
|
35 |
|
|
"Generating ""-cpu.h ...\n"; Turn parallel execution support on if cpu needs it.
|
36 |
|
|
; Initialize rtl->c generation.
|
37 |
|
|
"CPU class elements for @cpu@.""\
|
38 |
|
|
// This file is included in the middle of the cpu class struct.
|
39 |
|
|
|
40 |
|
|
public:
|
41 |
|
|
\n"" // C++ register access function templates\n""#define current_cpu this\n\n""#undef current_cpu\n\n"; **********
|
42 |
|
|
; cgen-defs.h
|
43 |
|
|
; Print various parameters of the cpu family.
|
44 |
|
|
; A "cpu family" here is a collection of variants of a particular architecture
|
45 |
|
|
; that share sufficient commonality that they can be handled together.
|
46 |
|
|
"\
|
47 |
|
|
/* Maximum number of instructions that are fetched at a time.
|
48 |
|
|
This is for LIW type instructions sets (e.g. m32r). */\n""#define @CPU@_MAX_LIW_INSNS ""\n\n""/* Maximum number of instructions that can be executed in parallel. */\n""#define @CPU@_MAX_PARALLEL_INSNS ""\n""\n"; (gen-enum-decl '@prefix@_virtual
|
49 |
|
|
; "@prefix@ virtual insns"
|
50 |
|
|
; "@ARCH@_INSN_" ; not @CPU@ to match CGEN_INSN_TYPE in opc.h
|
51 |
|
|
; '((x-invalid 0)
|
52 |
|
|
; (x-before -1) (x-after -2)
|
53 |
|
|
; (x-begin -3) (x-chain -4) (x-cti-chain -5)))
|
54 |
|
|
; Generate type of struct holding model state while executing.
|
55 |
|
|
|
56 |
|
|
typedef int (@CPU@_MODEL_FN) (struct @cpu@_cpu*, void*);
|
57 |
|
|
|
58 |
|
|
typedef struct {
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
int num;
|
62 |
|
|
|
63 |
|
|
/* Function to handle insn-specific profiling. */
|
64 |
|
|
@CPU@_MODEL_FN *model_fn;
|
65 |
|
|
|
66 |
|
|
/* Array of function units used by this insn. */
|
67 |
|
|
UNIT units[MAX_UNITS];
|
68 |
|
|
} @CPU@_INSN_TIMING;";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
;; note: this doesn't really correctly approximate the worst case. user-supplied functions
|
72 |
|
|
|
73 |
|
|
;(define (-worst-case-number-of-writes-to hw-name)
|
74 |
|
|
; (let* ((sfmts (current-sfmt-list))
|
75 |
|
|
|
76 |
|
|
; (pred (lambda (op) (equal? hw-name (gen-c-symbol (obj:name (op:type op))))))
|
77 |
|
|
; (filtered-ops (map (lambda (ops) (find pred ops)) out-ops)))
|
78 |
|
|
; (apply max (cons 0 (map (lambda (ops) (length ops)) filtered-ops)))))
|
79 |
|
|
; for the time being, we're disabling this size-estimation stuff and just
|
80 |
|
|
; requiring the user to supply a parameter WRITE_BUF_SZ before they include -defs.h
|
81 |
|
|
; (pipe-sz (+ 1 (max-delay (cpu-max-delay (current-cpu)))))
|
82 |
|
|
|
83 |
|
|
"_writes"" write_stack< write<""> >""\t""\t[pipe_sz];\n""write (PCADDR _pc, MODE _val"", USI _idx""=0"") : pc(_pc), val(_val)"", idx""(_idx"")"" {} \n"" USI idx"";\n""\n\n"" template <typename MODE>\n"" struct write\n"" {\n"" USI pc;\n"" MODE val;\n"" "" write() {}\n"" };\n"; for memory accesses
|
84 |
|
|
|
85 |
|
|
;;; end stack-based write schedule
|
86 |
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
87 |
|
|
|
88 |
|
|
; for use during parallel execution.
|
89 |
|
|
"Generating write stack structure ...\n"" static const int max_delay = "";\n"" static const int pipe_sz = ""; // max_delay + 1\n""
|
90 |
|
|
|
91 |
|
|
struct write_stack
|
92 |
|
|
{
|
93 |
|
|
int t;
|
94 |
|
|
|
95 |
|
|
ELT buf[WRITE_BUF_SZ];
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
inline bool empty () { return (t == -1); }
|
99 |
|
|
inline void clear () { t = -1; }
|
100 |
|
|
inline void pop () { if (t > -1) t--;}
|
101 |
|
|
|
102 |
|
|
inline ELT &top () { return buf [t>0 ? ( t<sz ? t : sz-1) : 0];}
|
103 |
|
|
};
|
104 |
|
|
|
105 |
|
|
// look ahead for latest write with index = idx, where time of write is
|
106 |
|
|
|
107 |
|
|
// returning def if no scheduled write is found.
|
108 |
|
|
|
109 |
|
|
template <typename STKS, typename VAL>
|
110 |
|
|
inline VAL lookahead (int dist, int base, STKS &st, VAL def, int idx=0)
|
111 |
|
|
{
|
112 |
|
|
for (; dist > 0; --dist)
|
113 |
|
|
{
|
114 |
|
|
write_stack <VAL> &v = st [(base + dist) % pipe_sz];
|
115 |
|
|
for (int i = v.t; i > 0; --i)
|
116 |
|
|
if (v.buf [i].idx0 == idx) return v.buf [i];
|
117 |
|
|
}
|
118 |
|
|
return def;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
"; Generate the TRACE_RECORD struct definition.
|
122 |
|
|
"\
|
123 |
|
|
/* Collection of various things for the trace handler to use. */
|
124 |
|
|
|
125 |
|
|
typedef struct @prefix@_trace_record {
|
126 |
|
|
PCADDR pc;
|
127 |
|
|
/* FIXME:wip */
|
128 |
|
|
} @CPU@_TRACE_RECORD;
|
129 |
|
|
\n"; Generate <cpu>-defs.h
|
130 |
|
|
"Generating ""-defs.h ...\n"; Turn parallel execution support on if cpu needs it.
|
131 |
|
|
; Initialize rtl->c generation.
|
132 |
|
|
"CPU family header for @cpu@ / @prefix@.""\
|
133 |
|
|
#ifndef DEFS_@PREFIX@_H
|
134 |
|
|
#define DEFS_@PREFIX@_H
|
135 |
|
|
|
136 |
|
|
""\
|
137 |
|
|
#include <stack>
|
138 |
|
|
#include \"cgen-types.h\"
|
139 |
|
|
|
140 |
|
|
// forward declaration\n\n
|
141 |
|
|
namespace @cpu@ {
|
142 |
|
|
struct @cpu@_cpu;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
namespace @prefix@ {
|
146 |
|
|
|
147 |
|
|
using namespace cgen;
|
148 |
|
|
|
149 |
|
|
""\
|
150 |
|
|
} // end @prefix@ namespace
|
151 |
|
|
""\
|
152 |
|
|
|
153 |
|
|
#endif /* DEFS_@PREFIX@_H */\n"; **************
|
154 |
|
|
; cgen-write.cxx
|
155 |
|
|
; This is the other way of implementing parallel execution support.
|
156 |
|
|
; Instead of fetching all the input operands first, write all the output
|
157 |
|
|
; operands and their addresses to holding variables, and then run a
|
158 |
|
|
; post-processing pass to update the cpu state.
|
159 |
|
|
; Return C code to fetch and save all output operands to instructions with
|
160 |
|
|
; <sformat> SFMT.
|
161 |
|
|
; Generate <cpu>-write.cxx.
|
162 |
|
|
" ""w.idx"", ""while (! ""_writes[tick].empty())\n""{\n"" write<""> &w = ""_writes[tick].top();\n"" current_cpu->""_set(""w.val);\n"" ""_writes[tick].pop();\n""}\n\n"" "", w.idx""""while (! ""_writes[tick].empty())\n""{\n"" write<""> &w = ""_writes[tick].top();\n"" current_cpu->SETMEM"" (w.pc"", w.val);\n"" ""_writes[tick].pop();\n""}\n\n""_memory"" clear_stacks (""_writes);\n"" template <typename ST> \n"" static void clear_stacks (ST &st)\n"" {\n"" for (int i = 0; i < @prefix@::pipe_sz; i++)\n"" st[i].clear();\n"" }\n\n"" void @prefix@::write_stacks::reset ()\n {\n"" }""_memory""Generating writer function ...\n""
|
163 |
|
|
void @prefix@::write_stacks::writeback (int tick, @cpu@::@cpu@_cpu* current_cpu)
|
164 |
|
|
{
|
165 |
|
|
|
166 |
|
|
}
|
167 |
|
|
""Generating ""-write.cxx ...\n"; Turn parallel execution support off.
|
168 |
|
|
|
169 |
|
|
"Simulator instruction operand writer for "".""\
|
170 |
|
|
|
171 |
|
|
#include \"@cpu@.h\"
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
; cgen-semantics.cxx
|
175 |
|
|
; Return C code to perform the semantics of INSN.
|
176 |
|
|
; Indicate generating code for INSN.
|
177 |
|
|
|
178 |
|
|
; The case when they're not available is for virtual insns.
|
179 |
|
|
; Return definition of C function to perform INSN.
|
180 |
|
|
|
181 |
|
|
"Processing semantics for "": \"""\" ...\n""// ********** "": ""\n\n""void\n""sem_status\n""@prefix@_sem_"" (@cpu@_cpu* current_cpu, @prefix@_scache* sem, const int tick, \n\t""@prefix@::write_stacks &buf)\n"" (@cpu@_cpu* current_cpu, @prefix@_scache* sem)\n""{\n"" sem_status status = SEM_STATUS_NORMAL;\n"" @prefix@_scache* abuf = sem;\n"; Unconditionally written operands are not recorded here.
|
182 |
|
|
" unsigned long long written = 0;\n"""; The address of this insn, needed by extraction and semantic code.
|
183 |
|
|
; Note that the address recorded in the cpu state struct is not used.
|
184 |
|
|
; For faster engines that copy will be out of date.
|
185 |
|
|
" PCADDR pc = abuf->addr;\n"" PCADDR npc = pc + "";\n""\n""\n"; Only update what's been written if some are conditionally written.
|
186 |
|
|
; Otherwise we know they're all written so there's no point in
|
187 |
|
|
; keeping track.
|
188 |
|
|
" abuf->written = written;\n"""""" current_cpu->done_cti_insn (npc, status);\n"" current_cpu->done_insn (npc, status);\n"""" return status;\n""}\n\n""Processing semantics ...\n""must specify `with-scache'"; Generate <cpu>-sem.cxx.
|
189 |
|
|
; Each instruction is implemented in its own function.
|
190 |
|
|
"Generating ""-semantics.cxx ...\n"; Turn parallel execution support on if cpu needs it.
|
191 |
|
|
; Tell the rtx->c translator we are the simulator.
|
192 |
|
|
; Indicate we're currently not generating a pbb engine.
|
193 |
|
|
"Simulator instruction semantics for @prefix@.""\
|
194 |
|
|
|
195 |
|
|
#if HAVE_CONFIG_H
|
196 |
|
|
#include \"config.h\"
|
197 |
|
|
#endif
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
using namespace @cpu@; // FIXME: namespace organization still wip\n""\
|
201 |
|
|
|
202 |
|
|
#define GET_ATTR(name) GET_ATTR_##name ()
|
203 |
|
|
|
204 |
|
|
\n"; *******************
|
205 |
|
|
; cgen-sem-switch.cxx
|
206 |
|
|
;
|
207 |
|
|
|
208 |
|
|
; case per "frag" (where each insn is split into one or more fragments).
|
209 |
|
|
; Utility of -gen-sem-case to return the mask of operands always written
|
210 |
|
|
; to in <sformat> SFMT.
|
211 |
|
|
; ??? Not currently used.
|
212 |
|
|
; Utility of -gen-sem-case to return #t if any operand in <sformat> SFMT is
|
213 |
|
|
; conditionally written to.
|
214 |
|
|
; One case per insn version.
|
215 |
|
|
; Generate a switch case to perform INSN.
|
216 |
|
|
"Processing ""parallel """"semantic switch case for \"""\" ...\n"; INSN_ is prepended here and not elsewhere to avoid name collisions
|
217 |
|
|
; with symbols like AND, etc.
|
218 |
|
|
"\
|
219 |
|
|
// ********** ""
|
220 |
|
|
|
221 |
|
|
CASE (INSN_""PAR_""""):
|
222 |
|
|
{
|
223 |
|
|
@prefix@_scache* abuf = vpc;\n"""; Unconditionally written operands are not recorded here.
|
224 |
|
|
" unsigned long long written = 0;\n"""; The address of this insn, needed by extraction and semantic code.
|
225 |
|
|
; Note that the address recorded in the cpu state struct is not used.
|
226 |
|
|
" PCADDR pc = abuf->addr;\n"" PCADDR npc;\n"" branch_status br_status = BRANCH_UNTAKEN;\n"""" vpc = vpc + 1;\n"; Emit setup-semantics code for real insns.
|
227 |
|
|
" """"\n""\n"; Only update what's been written if some are conditionally written.
|
228 |
|
|
; Otherwise we know they're all written so there's no point in
|
229 |
|
|
; keeping track.
|
230 |
|
|
" abuf->written = written;\n"""""" pbb_br_npc = npc;\n"" pbb_br_status = br_status;\n"""""" }\n"" NEXT (vpc);\n\n""Processing semantic switch ...\n"; Turn parallel execution support off.
|
231 |
|
|
; Generate the guts of a C switch statement to execute parallel instructions.
|
232 |
|
|
; This switch is included after the non-parallel instructions in the semantic
|
233 |
|
|
; switch.
|
234 |
|
|
;
|
235 |
|
|
; ??? We duplicate the writeback case for each insn, even though we only need
|
236 |
|
|
; one case per insn format. The former keeps the code for each insn
|
237 |
|
|
; together and might improve cache usage. On the other hand the latter
|
238 |
|
|
; reduces the amount of code, though it is believed that in this particular
|
239 |
|
|
; instance the win isn't big enough.
|
240 |
|
|
"Processing parallel insn semantic switch ...\n"; Turn parallel execution support on.
|
241 |
|
|
; Return computed-goto engine.
|
242 |
|
|
"\
|
243 |
|
|
void
|
244 |
|
|
@cpu@_cpu::@prefix@_pbb_run ()
|
245 |
|
|
{
|
246 |
|
|
@cpu@_cpu* current_cpu = this;
|
247 |
|
|
@prefix@_scache* vpc;
|
248 |
|
|
// These two are used to pass data from cti insns to the cti-chain insn.
|
249 |
|
|
PCADDR pbb_br_npc;
|
250 |
|
|
branch_status pbb_br_status;
|
251 |
|
|
|
252 |
|
|
#ifdef __GNUC__
|
253 |
|
|
{
|
254 |
|
|
static const struct sem_labels
|
255 |
|
|
{
|
256 |
|
|
enum @prefix@_insn_type insn;
|
257 |
|
|
void *label;
|
258 |
|
|
}
|
259 |
|
|
labels[] =
|
260 |
|
|
{\n"" { ""@PREFIX@_INSN_"", && case_INSN_"" },\n"" { ""@PREFIX@_INSN_PAR_"", && case_INSN_PAR_"" },\n"" { ""@PREFIX@_INSN_WRITE_"", && case_INSN_WRITE_"" },\n"""" { (@prefix@_insn_type) 0, 0 }
|
261 |
|
|
};
|
262 |
|
|
|
263 |
|
|
if (! @prefix@_idesc::idesc_table_initialized_p)
|
264 |
|
|
{
|
265 |
|
|
for (int i=0; labels[i].label != 0; i++)
|
266 |
|
|
@prefix@_idesc::idesc_table[labels[i].insn].cgoto.label = labels[i].label;
|
267 |
|
|
|
268 |
|
|
// confirm that table is all filled up
|
269 |
|
|
for (int i = 0; i <= @PREFIX@_INSN_""; i++)
|
270 |
|
|
assert (@prefix@_idesc::idesc_table[i].cgoto.label != 0);
|
271 |
|
|
|
272 |
|
|
// Initialize the compiler virtual insn.
|
273 |
|
|
current_cpu->@prefix@_engine.compile_begin_insn (current_cpu);
|
274 |
|
|
|
275 |
|
|
@prefix@_idesc::idesc_table_initialized_p = true;
|
276 |
|
|
}
|
277 |
|
|
}
|
278 |
|
|
#endif
|
279 |
|
|
|
280 |
|
|
#ifdef __GNUC__
|
281 |
|
|
#define CASE(X) case_##X
|
282 |
|
|
// Branch to next handler without going around main loop.
|
283 |
|
|
#define NEXT(vpc) goto * vpc->execute.cgoto.label;
|
284 |
|
|
// Break out of threaded interpreter and return to \"main loop\".
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
#define CASE(X) case @PREFIX@_##X
|
288 |
|
|
|
289 |
|
|
#define BREAK(vpc) break
|
290 |
|
|
#endif
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
vpc = current_cpu->@prefix@_engine.get_next_vpc (current_cpu->h_pc_get ());
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
#ifdef __GNUC__
|
297 |
|
|
goto * vpc->execute.cgoto.label;
|
298 |
|
|
|
299 |
|
|
switch (vpc->idesc->sem_index)
|
300 |
|
|
#endif
|
301 |
|
|
|
302 |
|
|
{
|
303 |
|
|
""""
|
304 |
|
|
|
305 |
|
|
end_switch: ;
|
306 |
|
|
#else
|
307 |
|
|
|
308 |
|
|
#endif
|
309 |
|
|
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
current_cpu->@prefix@_engine.set_next_vpc (vpc);
|
313 |
|
|
}
|
314 |
|
|
\n"; Semantic frag version.
|
315 |
|
|
; Return declaration of frag enum.
|
316 |
|
|
"@prefix@_frag_type""semantic fragments in cpu family @prefix@""@PREFIX@_FRAG_"; Return header file decls for semantic frag threaded engine.
|
317 |
|
|
"namespace @cpu@ {\n\n"; FIXME: vector->list
|
318 |
|
|
"\
|
319 |
|
|
struct @prefix@_insn_frag {
|
320 |
|
|
|
321 |
|
|
// 4: header+middle+trailer+delimiter
|
322 |
|
|
@PREFIX@_FRAG_TYPE ftype[4];
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
struct @prefix@_pbb_label {
|
326 |
|
|
@PREFIX@_FRAG_TYPE frag;
|
327 |
|
|
|
328 |
|
|
};
|
329 |
|
|
|
330 |
|
|
} // end @cpu@ namespace
|
331 |
|
|
\n"; Return C code to perform the semantics of FRAG.
|
332 |
|
|
; LOCALS is a list of sequence locals made global to all frags.
|
333 |
|
|
; Each element is (symbol <mode> "c-var-name").
|
334 |
|
|
; Indicate generating code for FRAG.
|
335 |
|
|
; Use the compiled form if available.
|
336 |
|
|
; The case when they're not available is for virtual insns.
|
337 |
|
|
; If the frag has one owner, use it. Otherwise indicate the owner is
|
338 |
|
|
; unknown. In cases where the owner is needed by the semantics, the
|
339 |
|
|
; frag should have only one owner.
|
340 |
|
|
; Generate a switch case to perform FRAG.
|
341 |
|
|
; LOCALS is a list of sequence locals made global to all frags.
|
342 |
|
|
; Each element is (symbol <mode> "c-var-name").
|
343 |
|
|
"Processing ""parallel """"semantic switch case for \"""\" ...\n"; FRAG_ is prepended here and not elsewhere to avoid name collisions
|
344 |
|
|
; with symbols like AND, etc.
|
345 |
|
|
|
346 |
|
|
// ********** ""used only by:""used by:"", ""
|
347 |
|
|
|
348 |
|
|
CASE (FRAG_""):
|
349 |
|
|
{\n"" abuf = vpc;\n"" vpc = vpc + 1;\n"""; Unconditionally written operands are not recorded here.
|
350 |
|
|
" unsigned long long written = 0;\n"""; The address of this insn, needed by extraction and semantic code.
|
351 |
|
|
; Note that the address recorded in the cpu state struct is not used.
|
352 |
|
|
" PCADDR pc = abuf->addr;\n"; " npc = 0;\n" ??? needed?
|
353 |
|
|
" br_status = BRANCH_UNTAKEN;\n"""; Emit setup-semantics code for headers of real insns.
|
354 |
|
|
" """"\n""\n"; Only update what's been written if some are conditionally written.
|
355 |
|
|
; Otherwise we know they're all written so there's no point in
|
356 |
|
|
; keeping track.
|
357 |
|
|
" abuf->written = written;\n"""""" pbb_br_npc = npc;\n"" pbb_br_status = br_status;\n"""" }\n"" NEXT_INSN (vpc, fragpc);\n"" NEXT_FRAG (fragpc);\n""\n"; Convert locals from form computed by sem-find-common-frags to that needed by
|
358 |
|
|
; -gen-sfrag-engine-code (and ultimately rtl-c++).
|
359 |
|
|
; Return definition of insn frag usage table.
|
360 |
|
|
"\
|
361 |
|
|
// Table of frags used by each insn.
|
362 |
|
|
|
363 |
|
|
const @prefix@_insn_frag @prefix@_frag_usage[] = {\n"" { ""@PREFIX@_INSN_"", @PREFIX@_FRAG_"", @PREFIX@_FRAG_LIST_END },\n""""};\n\n"; Return sfrag computed-goto engine.
|
364 |
|
|
; LOCALS is a list of sequence locals made global to all frags.
|
365 |
|
|
; Each element is (symbol <mode> "c-var-name").
|
366 |
|
|
"\
|
367 |
|
|
void
|
368 |
|
|
@cpu@_cpu::@prefix@_pbb_run ()
|
369 |
|
|
{
|
370 |
|
|
|
371 |
|
|
@prefix@_scache* vpc;
|
372 |
|
|
@prefix@_scache* abuf;
|
373 |
|
|
#ifdef __GNUC__
|
374 |
|
|
void** fragpc;
|
375 |
|
|
|
376 |
|
|
ARM_FRAG_TYPE* fragpc;
|
377 |
|
|
#endif
|
378 |
|
|
|
379 |
|
|
#ifdef __GNUC__
|
380 |
|
|
{
|
381 |
|
|
static const @prefix@_pbb_label labels[] =
|
382 |
|
|
{
|
383 |
|
|
{ @PREFIX@_FRAG_LIST_END, 0 },
|
384 |
|
|
|
385 |
|
|
"\
|
386 |
|
|
{ @PREFIX@_FRAG_MAX, 0 }
|
387 |
|
|
};
|
388 |
|
|
|
389 |
|
|
if (! @prefix@_idesc::idesc_table_initialized_p)
|
390 |
|
|
|
391 |
|
|
// Several tables are in play here:
|
392 |
|
|
// idesc table: const table of misc things for each insn
|
393 |
|
|
// frag usage table: const set of frags used by each insn
|
394 |
|
|
// frag label table: same as frag usage table, but contains labels
|
395 |
|
|
// selected insn frag table: table of pointers to either the frag usage
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
// insn handler. FIXME: This one isn't implemented yet.
|
399 |
|
|
|
400 |
|
|
// Allocate frag label table and point idesc table entries at it.
|
401 |
|
|
// FIXME: Temporary hack, to be redone.
|
402 |
|
|
static void** frag_label_table;
|
403 |
|
|
int max_insns = @PREFIX@_INSN_"" + 1;
|
404 |
|
|
int tabsize = max_insns * 4;
|
405 |
|
|
frag_label_table = new void* [tabsize];
|
406 |
|
|
|
407 |
|
|
int i;
|
408 |
|
|
void** v;
|
409 |
|
|
for (i = 0, v = frag_label_table; i < max_insns; ++i)
|
410 |
|
|
{
|
411 |
|
|
@prefix@_idesc::idesc_table[@prefix@_frag_usage[i].itype].cgoto.frags = v;
|
412 |
|
|
for (int j = 0; @prefix@_frag_usage[i].ftype[j] != @PREFIX@_FRAG_LIST_END; ++j)
|
413 |
|
|
|
414 |
|
|
}
|
415 |
|
|
|
416 |
|
|
// Initialize the compiler virtual insn.
|
417 |
|
|
// FIXME: Also needed if !gnuc.
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
@prefix@_idesc::idesc_table_initialized_p = true;
|
421 |
|
|
}
|
422 |
|
|
}
|
423 |
|
|
#endif
|
424 |
|
|
|
425 |
|
|
#ifdef __GNUC__
|
426 |
|
|
#define CASE(X) case_##X
|
427 |
|
|
// Branch to next handler without going around main loop.
|
428 |
|
|
#define NEXT_INSN(vpc, fragpc) fragpc = vpc->execute.cgoto.frags; goto * *fragpc
|
429 |
|
|
#define NEXT_FRAG(fragpc) ++fragpc; goto * *fragpc
|
430 |
|
|
// Break out of threaded interpreter and return to \"main loop\".
|
431 |
|
|
#define BREAK(vpc) goto end_switch
|
432 |
|
|
#else
|
433 |
|
|
#define CASE(X) case @PREFIX@_##X
|
434 |
|
|
#define NEXT_INSN(vpc, fragpc) fragpc = vpc->idesc->frags; goto restart
|
435 |
|
|
#define NEXT_FRAG(fragpc) ++fragpc; goto restart
|
436 |
|
|
#define BREAK(vpc) break
|
437 |
|
|
#endif
|
438 |
|
|
|
439 |
|
|
// Get next insn to execute.
|
440 |
|
|
vpc = current_cpu->@prefix@_engine.get_next_vpc (current_cpu->h_pc_get ());
|
441 |
|
|
|
442 |
|
|
|
443 |
|
|
// These two are used to pass data from cti insns to the cti-chain insn.
|
444 |
|
|
PCADDR pbb_br_npc;
|
445 |
|
|
branch_status pbb_br_status;
|
446 |
|
|
// These two are used to build up values of the previous two.
|
447 |
|
|
PCADDR npc;
|
448 |
|
|
branch_status br_status;
|
449 |
|
|
|
450 |
|
|
|
451 |
|
|
|
452 |
|
|
restart:
|
453 |
|
|
#ifdef __GNUC__
|
454 |
|
|
fragpc = vpc->execute.cgoto.frags;
|
455 |
|
|
goto * *fragpc;
|
456 |
|
|
#else
|
457 |
|
|
fragpc = vpc->idesc->frags;
|
458 |
|
|
switch (*fragpc)
|
459 |
|
|
#endif
|
460 |
|
|
|
461 |
|
|
|
462 |
|
|
|
463 |
|
|
"; Turn parallel execution support off.
|
464 |
|
|
; ??? Still needed?
|
465 |
|
|
; FIXME: vector->list
|
466 |
|
|
"
|
467 |
|
|
#ifdef __GNUC__
|
468 |
|
|
end_switch: ;
|
469 |
|
|
#else
|
470 |
|
|
default: abort ();
|
471 |
|
|
#endif
|
472 |
|
|
}
|
473 |
|
|
}
|
474 |
|
|
|
475 |
|
|
// Save vpc for next time.
|
476 |
|
|
current_cpu->@prefix@_engine.set_next_vpc (vpc);
|
477 |
|
|
}
|
478 |
|
|
|
479 |
|
|
|
480 |
|
|
; It is later turned on/off when generating the actual semantic code.
|
481 |
|
|
; Tell the rtx->c translator we are the simulator.
|
482 |
|
|
|
483 |
|
|
"Simulator instruction semantics for @prefix@.""\
|
484 |
|
|
|
485 |
|
|
#include \"@cpu@.h\"
|
486 |
|
|
|
487 |
|
|
using namespace @cpu@; // FIXME: namespace organization still wip
|
488 |
|
|
|
489 |
|
|
#define GET_ATTR(name) GET_ATTR_##name ()
|
490 |
|
|
|
491 |
|
|
\n"""
|