1 /* Engine header for Cpu tools GENerated simulators.
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file must be included after eng.h and before ${cpu}.h. */
23 /* Semantic functions come in six versions on two axes:
24 fast/full-featured, and using one of the simple/scache/compilation engines.
25 A full featured simulator is always provided. --enable-sim-fast includes
26 support for fast execution by duplicating the semantic code but leaving
27 out all features like tracing and profiling.
28 Using the scache is selected with --enable-sim-scache. */
29 /* FIXME: --enable-sim-fast not implemented yet. */
30 /* FIXME: undecided how to handle WITH_SCACHE_PBB. */
32 /* There are several styles of engines, all generally supported by the
35 WITH_SCACHE && WITH_SCACHE_PBB - pseudo-basic-block scaching
36 WITH_SCACHE && !WITH_SCACHE_PBB - scaching on an insn by insn basis
37 !WITH_SCACHE - simple engine: fetch an insn, execute an insn
39 The !WITH_SCACHE case can also be broken up into two flavours:
40 extract the fields of the insn into an ARGBUF struct, or defer the
41 extraction to the semantic handler. The former can be viewed as the
42 WITH_SCACHE case with a cache size of 1 (thus there's no need for a
43 WITH_EXTRACTION macro). The WITH_SCACHE case always extracts the fields
44 into an ARGBUF struct. */
49 /* Instruction field support macros. */
51 #define EXTRACT_MSB0_INT(val, total, start, length) \
52 (((INT) (val) << ((sizeof (INT) * 8) - (total) + (start))) \
53 >> ((sizeof (INT) * 8) - (length)))
54 #define EXTRACT_MSB0_UINT(val, total, start, length) \
55 (((UINT) (val) << ((sizeof (UINT) * 8) - (total) + (start))) \
56 >> ((sizeof (UINT) * 8) - (length)))
58 #define EXTRACT_LSB0_INT(val, total, start, length) \
59 (((INT) (val) << ((sizeof (INT) * 8) - (start) - 1)) \
60 >> ((sizeof (INT) * 8) - (length)))
61 #define EXTRACT_LSB0_UINT(val, total, start, length) \
62 (((UINT) (val) << ((sizeof (UINT) * 8) - (start) - 1)) \
63 >> ((sizeof (UINT) * 8) - (length)))
67 #define EXTRACT_INT(val, total, start, length) \
68 EXTRACT_LSB0_INT ((val), (total), (start), (length))
69 #define EXTRACT_UINT(val, total, start, length) \
70 EXTRACT_LSB0_UINT ((val), (total), (start), (length))
74 #define EXTRACT_INT(val, total, start, length) \
75 EXTRACT_MSB0_INT ((val), (total), (start), (length))
76 #define EXTRACT_UINT(val, total, start, length) \
77 EXTRACT_MSB0_UINT ((val), (total), (start), (length))
81 /* Semantic routines. */
83 /* Type of the machine generated extraction fns. */
84 /* ??? No longer used. */
85 typedef void (EXTRACT_FN
) (SIM_CPU
*, IADDR
, CGEN_INSN_INT
, ARGBUF
*);
87 /* Type of the machine generated semantic fns. */
91 /* Instruction fields are extracted into ARGBUF before calling the
93 #if HAVE_PARALLEL_INSNS && ! WITH_PARALLEL_GENWRITE
94 typedef SEM_PC (SEMANTIC_FN
) (SIM_CPU
*, SEM_ARG
, PAREXEC
*);
96 typedef SEM_PC (SEMANTIC_FN
) (SIM_CPU
*, SEM_ARG
);
101 /* Result of semantic routines is a status indicator (wip). */
102 typedef unsigned int SEM_STATUS
;
104 /* Instruction fields are extracted by the semantic routine.
105 ??? TODO: multi word insns. */
106 #if HAVE_PARALLEL_INSNS && ! WITH_PARALLEL_GENWRITE
107 typedef SEM_STATUS (SEMANTIC_FN
) (SIM_CPU
*, SEM_ARG
, PAREXEC
*, CGEN_INSN_INT
);
109 typedef SEM_STATUS (SEMANTIC_FN
) (SIM_CPU
*, SEM_ARG
, CGEN_INSN_INT
);
114 /* In the ARGBUF struct, a pointer to the semantic routine for the insn. */
117 #if ! WITH_SEM_SWITCH_FULL
118 SEMANTIC_FN
*sem_full
;
120 #if ! WITH_SEM_SWITCH_FAST
121 SEMANTIC_FN
*sem_fast
;
123 #if WITH_SEM_SWITCH_FULL || WITH_SEM_SWITCH_FAST
132 /* Set the appropriate semantic handler in ABUF. */
134 #if WITH_SEM_SWITCH_FULL
136 #define SEM_SET_FULL_CODE(abuf, idesc) \
137 do { (abuf)->semantic.sem_case = (idesc)->sem_full_lab; } while (0)
139 #define SEM_SET_FULL_CODE(abuf, idesc) \
140 do { (abuf)->semantic.sem_case = (idesc)->num; } while (0)
143 #define SEM_SET_FULL_CODE(abuf, idesc) \
144 do { (abuf)->semantic.sem_full = (idesc)->sem_full; } while (0)
147 #if WITH_SEM_SWITCH_FAST
149 #define SEM_SET_FAST_CODE(abuf, idesc) \
150 do { (abuf)->semantic.sem_case = (idesc)->sem_fast_lab; } while (0)
152 #define SEM_SET_FAST_CODE(abuf, idesc) \
153 do { (abuf)->semantic.sem_case = (idesc)->num; } while (0)
156 #define SEM_SET_FAST_CODE(abuf, idesc) \
157 do { (abuf)->semantic.sem_fast = (idesc)->sem_fast; } while (0)
160 #define SEM_SET_CODE(abuf, idesc, fast_p) \
163 SEM_SET_FAST_CODE ((abuf), (idesc)); \
165 SEM_SET_FULL_CODE ((abuf), (idesc)); \
168 /* Return non-zero if IDESC is a conditional or unconditional CTI. */
170 #define IDESC_CTI_P(idesc) \
171 ((CGEN_ATTR_BOOLS (CGEN_INSN_ATTRS ((idesc)->idata)) \
172 & (CGEN_ATTR_MASK (CGEN_INSN_COND_CTI) \
173 | CGEN_ATTR_MASK (CGEN_INSN_UNCOND_CTI))) \
176 /* Return non-zero if IDESC is a skip insn. */
178 #define IDESC_SKIP_P(idesc) \
179 ((CGEN_ATTR_BOOLS (CGEN_INSN_ATTRS ((idesc)->idata)) \
180 & CGEN_ATTR_MASK (CGEN_INSN_SKIP_CTI)) \
183 /* Return pointer to ARGBUF given ptr to SCACHE. */
184 #define SEM_ARGBUF(sem_arg) (& (sem_arg) -> argbuf)
186 /* There are several styles of engines, all generally supported by the
189 WITH_SCACHE && WITH_SCACHE_PBB - pseudo-basic-block scaching
190 WITH_SCACHE && !WITH_SCACHE_PBB - scaching on an insn by insn basis
191 !WITH_SCACHE - simple engine: fetch an insn, execute an insn
193 ??? The !WITH_SCACHE case can also be broken up into two flavours:
194 extract the fields of the insn into an ARGBUF struct, or defer the
195 extraction to the semantic handler. The WITH_SCACHE case always
196 extracts the fields into an ARGBUF struct. */
200 #define CIA_ADDR(cia) (cia)
204 /* Return the scache pointer of the current insn. */
205 #define SEM_SEM_ARG(vpc, sc) (vpc)
207 /* Return the virtual pc of the next insn to execute
208 (assuming this isn't a cti or the branch isn't taken). */
209 #define SEM_NEXT_VPC(sem_arg, pc, len) ((sem_arg) + 1)
211 /* Update the instruction counter. */
212 #define PBB_UPDATE_INSN_COUNT(cpu,sc) \
213 (CPU_INSN_COUNT (cpu) += SEM_ARGBUF (sc) -> fields.chain.insn_count)
215 /* Do not append a `;' to invocations of this.
216 npc,br_type are for communication between the cti insn and cti-chain. */
217 #define SEM_BRANCH_INIT \
218 IADDR npc = 0; /* assign a value for -Wall */ \
219 SEM_BRANCH_TYPE br_type = SEM_BRANCH_UNTAKEN;
221 /* SEM_IN_SWITCH is defined at the top of the mainloop.c files
222 generated by genmloop.sh. It exists so generated semantic code needn't
223 care whether it's being put in a switch or in a function. */
225 #define SEM_BRANCH_FINI(pcvar) \
228 pbb_br_type = br_type; \
230 #else /* 1 semantic function per instruction */
231 #define SEM_BRANCH_FINI(pcvar) \
233 CPU_PBB_BR_NPC (current_cpu) = npc; \
234 CPU_PBB_BR_TYPE (current_cpu) = br_type; \
238 #define SEM_BRANCH_VIA_CACHE(cpu, sc, newval, pcvar) \
241 br_type = SEM_BRANCH_CACHEABLE; \
244 #define SEM_BRANCH_VIA_ADDR(cpu, sc, newval, pcvar) \
247 br_type = SEM_BRANCH_UNCACHEABLE; \
250 #define SEM_SKIP_COMPILE(cpu, sc, skip) \
252 SEM_ARGBUF (sc) -> skip_count = (skip); \
255 #define SEM_SKIP_INSN(cpu, sc, vpcvar) \
257 (vpcvar) += SEM_ARGBUF (sc) -> skip_count; \
260 #else /* ! WITH_SCACHE_PBB */
262 #define SEM_SEM_ARG(vpc, sc) (sc)
264 #define SEM_NEXT_VPC(sem_arg, pc, len) ((pc) + (len))
266 /* ??? May wish to move taken_p out of here and make it explicit. */
267 #define SEM_BRANCH_INIT \
270 #ifndef TARGET_SEM_BRANCH_FINI
271 #define TARGET_SEM_BRANCH_FINI(pcvar, taken_p)
273 #define SEM_BRANCH_FINI(pcvar) \
274 do { TARGET_SEM_BRANCH_FINI (pcvar, taken_p); } while (0)
276 #define SEM_BRANCH_VIA_CACHE(cpu, sc, newval, pcvar) \
278 (pcvar) = (newval); \
282 #define SEM_BRANCH_VIA_ADDR(cpu, sc, newval, pcvar) \
284 (pcvar) = (newval); \
288 #endif /* ! WITH_SCACHE_PBB */
290 #else /* ! WITH_SCACHE */
292 /* This is the "simple" engine case. */
294 #define CIA_ADDR(cia) (cia)
296 #define SEM_SEM_ARG(vpc, sc) (sc)
298 #define SEM_NEXT_VPC(sem_arg, pc, len) ((pc) + (len))
300 #define SEM_BRANCH_INIT \
303 #define SEM_BRANCH_VIA_CACHE(cpu, abuf, newval, pcvar) \
305 (pcvar) = (newval); \
309 #define SEM_BRANCH_VIA_ADDR(cpu, abuf, newval, pcvar) \
311 (pcvar) = (newval); \
315 /* Finish off branch insns.
316 The target must define TARGET_SEM_BRANCH_FINI.
317 ??? This can probably go away when define-execute is finished. */
318 #define SEM_BRANCH_FINI(pcvar, bool_attrs) \
319 do { TARGET_SEM_BRANCH_FINI ((pcvar), (bool_attrs), taken_p); } while (0)
321 /* Finish off non-branch insns.
322 The target must define TARGET_SEM_NBRANCH_FINI.
323 ??? This can probably go away when define-execute is finished. */
324 #define SEM_NBRANCH_FINI(pcvar, bool_attrs) \
325 do { TARGET_SEM_NBRANCH_FINI ((pcvar), (bool_attrs)); } while (0)
327 #endif /* ! WITH_SCACHE */
329 /* Instruction information. */
331 /* Sanity check, at most one of these may be true. */
332 #if WITH_PARALLEL_READ + WITH_PARALLEL_WRITE + WITH_PARALLEL_GENWRITE > 1
333 #error "At most one of WITH_PARALLEL_{READ,WRITE,GENWRITE} can be true."
336 /* Compile time computable instruction data. */
339 /* The instruction type (a number that identifies each insn over the
340 entire architecture). */
343 /* Index in IDESC table. */
346 /* Semantic format number. */
349 #if HAVE_PARALLEL_INSNS && ! WITH_PARALLEL_ONLY
350 /* Index in IDESC table of parallel handler. */
354 #if WITH_PARALLEL_READ
355 /* Index in IDESC table of read handler. */
359 #if WITH_PARALLEL_WRITE
360 /* Index in IDESC table of writeback handler. */
365 /* Entry in semantic function table.
366 This information is copied to the insn descriptor table at run-time. */
369 /* Index in IDESC table. */
372 /* Function to perform the semantics of the insn. */
376 /* Run-time computed instruction descriptor. */
379 #if WITH_SEM_SWITCH_FAST
383 /* nothing needed, switch's on `num' member */
386 SEMANTIC_FN
*sem_fast
;
389 #if WITH_SEM_SWITCH_FULL
393 /* nothing needed, switch's on `num' member */
396 SEMANTIC_FN
*sem_full
;
399 /* Parallel support. */
400 #if HAVE_PARALLEL_INSNS && (! WITH_PARALLEL_ONLY || (WITH_PARALLEL_ONLY && ! WITH_PARALLEL_GENWRITE))
401 /* Pointer to parallel handler if serial insn.
402 Pointer to readahead/writeback handler if parallel insn. */
403 struct idesc
*par_idesc
;
406 /* Instruction number (index in IDESC table, profile table).
407 Also used to switch on in non-gcc semantic switches. */
410 /* Semantic format id. */
413 /* instruction data (name, attributes, size, etc.) */
414 const CGEN_INSN
*idata
;
416 /* instruction attributes, copied from `idata' for speed */
417 const CGEN_INSN_ATTR_TYPE
*attrs
;
419 /* instruction length in bytes, copied from `idata' for speed */
422 /* profiling/modelling support */
423 const INSN_TIMING
*timing
;
426 /* Tracing/profiling. */
428 /* Return non-zero if a before/after handler is needed.
429 When tracing/profiling a selected range there's no need to slow
430 down simulation of the other insns (except to get more accurate data!).
432 ??? May wish to profile all insns if doing insn tracing, or to
433 get more accurate cycle data.
435 First test ANY_P so we avoid a potentially expensive HIT_P call
436 [if there are lots of address ranges]. */
438 #define PC_IN_TRACE_RANGE_P(cpu, pc) \
440 && ADDR_RANGE_HIT_P (TRACE_RANGE (CPU_TRACE_DATA (cpu)), (pc)))
441 #define PC_IN_PROFILE_RANGE_P(cpu, pc) \
442 (PROFILE_ANY_P (cpu) \
443 && ADDR_RANGE_HIT_P (PROFILE_RANGE (CPU_PROFILE_DATA (cpu)), (pc)))
445 #endif /* CGEN_ENGINE_H */