1 /* Engine header for Cpu tools GENerated simulators.
2 Copyright (C) 1998 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. */
35 /* Instruction field support macros. */
37 #define EXTRACT_MSB0_INT(val, total, start, length) \
38 (((INT) (val) << ((sizeof (INT) * 8) - (total) + (start))) \
39 >> ((sizeof (INT) * 8) - (length)))
40 #define EXTRACT_MSB0_UINT(val, total, start, length) \
41 (((UINT) (val) << ((sizeof (UINT) * 8) - (total) + (start))) \
42 >> ((sizeof (UINT) * 8) - (length)))
44 #define EXTRACT_LSB0_INT(val, total, start, length) \
45 (((INT) (val) << ((sizeof (INT) * 8) - (start) - (length))) \
46 >> ((sizeof (INT) * 8) - (length)))
47 #define EXTRACT_LSB0_UINT(val, total, start, length) \
48 (((UINT) (val) << ((sizeof (UINT) * 8) - (start) - (length))) \
49 >> ((sizeof (UINT) * 8) - (length)))
53 #define EXTRACT_INT(val, total, start, length) \
54 EXTRACT_LSB0_INT ((val), (total), (start), (length))
55 #define EXTRACT_UINT(val, total, start, length) \
56 EXTRACT_LSB0_UINT ((val), (total), (start), (length))
60 #define EXTRACT_INT(val, total, start, length) \
61 EXTRACT_MSB0_INT ((val), (total), (start), (length))
62 #define EXTRACT_UINT(val, total, start, length) \
63 EXTRACT_MSB0_UINT ((val), (total), (start), (length))
69 /* Types of the machine generated extract and semantic fns. */
70 typedef void (EXTRACT_FN
) (SIM_CPU
*, PCADDR
, insn_t
, ARGBUF
*);
71 #if HAVE_PARALLEL_INSNS
72 typedef SEM_PC (SEMANTIC_FN
) (SIM_CPU
*, SEM_ARG
, PAREXEC
*);
74 typedef SEM_PC (SEMANTIC_FN
) (SIM_CPU
*, SEM_ARG
);
78 #if ! WITH_SEM_SWITCH_FULL
79 SEMANTIC_FN
*sem_full
;
81 #if ! WITH_SEM_SWITCH_FAST
82 SEMANTIC_FN
*sem_fast
;
84 #if WITH_SEM_SWITCH_FULL || WITH_SEM_SWITCH_FAST
93 /* Set the appropriate semantic handler in ABUF. */
95 #if WITH_SEM_SWITCH_FULL
97 #define SEM_SET_FULL_CODE(abuf, idesc) \
98 do { (abuf)->semantic.sem_case = (idesc)->sem_full_lab; } while (0)
100 #define SEM_SET_FULL_CODE(abuf, idesc) \
101 do { (abuf)->semantic.sem_case = (idesc)->num; } while (0)
104 #define SEM_SET_FULL_CODE(abuf, idesc) \
105 do { (abuf)->semantic.sem_full = (idesc)->sem_full; } while (0)
108 #if WITH_SEM_SWITCH_FAST
110 #define SEM_SET_FAST_CODE(abuf, idesc) \
111 do { (abuf)->semantic.sem_case = (idesc)->sem_fast_lab; } while (0)
113 #define SEM_SET_FAST_CODE(abuf, idesc) \
114 do { (abuf)->semantic.sem_case = (idesc)->num; } while (0)
117 #define SEM_SET_FAST_CODE(abuf, idesc) \
118 do { (abuf)->semantic.sem_fast = (idesc)->sem_fast; } while (0)
121 #define SEM_SET_CODE(abuf, idesc, fast_p) \
124 SEM_SET_FAST_CODE ((abuf), (idesc)); \
126 SEM_SET_FULL_CODE ((abuf), (idesc)); \
129 #define IDESC_CTI_P(idesc) \
130 ((CGEN_ATTR_BOOLS (CGEN_INSN_ATTRS ((idesc)->opcode)) \
131 & (CGEN_ATTR_MASK (CGEN_INSN_COND_CTI) \
132 | CGEN_ATTR_MASK (CGEN_INSN_UNCOND_CTI))) \
134 #define IDESC_SKIP_P(idesc) \
135 ((CGEN_ATTR_BOOLS (CGEN_INSN_ATTRS ((idesc)->opcode)) \
136 & CGEN_ATTR_MASK (CGEN_INSN_SKIP_CTI)) \
139 /* These are used so that we can compile two copies of the semantic code,
140 one with full feature support and one without that runs fast(er). */
141 #define SEM_FN_NAME(cpu,fn) XCONCAT3 (cpu,_sem_,fn)
142 #define SEMF_FN_NAME(cpu,fn) XCONCAT3 (cpu,_semf_,fn)
146 #define CIA_ADDR(cia) (cia)
148 /* semantics.c support */
149 #define SEM_ARGBUF(sem_arg) (& (sem_arg) -> argbuf)
150 #define SEM_INSN(sem_arg) shouldnt_be_used
154 /* Return the scache pointer of the current insn. */
155 #define SEM_SEM_ARG(vpc, sc) (vpc)
156 /* Return the virtual pc of the next insn to execute
157 (assuming this isn't a cti). */
158 #define SEM_NEXT_VPC(sem_arg, pc, len) ((sem_arg) + 1)
160 /* Update the instruction counter. */
161 #define PBB_UPDATE_INSN_COUNT(cpu,sc) \
162 (CPU_INSN_COUNT (cpu) += SEM_ARGBUF (sc) -> fields.chain.insn_count)
164 /* Value for br_addr_ptr indicating branch wasn't taken. */
165 #define SEM_BRANCH_UNTAKEN ((SEM_PC *) 0)
166 /* Value for br_addr_ptr indicating branch was taken to uncacheable
167 address (e.g. j reg). */
168 #define SEM_BRANCH_UNCACHEABLE ((SEM_PC *) 1)
170 /* Initialize next-pbb link for SEM_BRANCH_VIA_CACHE. */
171 #define SEM_BRANCH_INIT_EXTRACT(abuf) \
172 do { (abuf)->fields.cti.addr_cache = 0; } while (0)
174 /* Do not append a `;' to invocations of this.
175 npc,npc_ptr are for communication between the cti insn and cti-chain. */
176 #define SEM_BRANCH_INIT \
177 PCADDR npc = 0; /* assign a value for -Wall */ \
178 SEM_PC *npc_ptr = SEM_BRANCH_UNTAKEN;
179 /* SEM_IN_SWITCH is defined at the top of the mainloop.c files
180 generated by genmloop.sh. It exists so generated semantic code needn't
181 care whether it's being put in a switch or in a function. */
183 #define SEM_BRANCH_FINI(pcvar) \
186 pbb_br_npc_ptr = npc_ptr; \
188 #else /* 1 semantic function per instruction */
189 #define SEM_BRANCH_FINI(pcvar) \
191 CPU_PBB_BR_NPC (current_cpu) = npc; \
192 CPU_PBB_BR_NPC_PTR (current_cpu) = npc_ptr; \
196 /* Return address of cached branch address value. */
197 #define SEM_BRANCH_ADDR_CACHE(sem_arg) \
198 (& SEM_ARGBUF (sem_arg)->fields.cti.addr_cache)
199 #define SEM_BRANCH_VIA_CACHE(cpu, sc, newval, pcvar, cachevarptr) \
202 npc_ptr = (cachevarptr); \
204 #define SEM_BRANCH_VIA_ADDR(cpu, sc, newval, pcvar) \
207 npc_ptr = SEM_BRANCH_UNCACHEABLE; \
210 #else /* ! WITH_SCACHE_PBB */
212 #define SEM_SEM_ARG(vpc, sc) (sc)
213 #define SEM_NEXT_VPC(sem_arg, pc, len) ((pc) + (len))
215 #define SEM_BRANCH_INIT_EXTRACT(abuf) do { } while (0)
217 #define SEM_BRANCH_INIT \
219 #ifndef TARGET_SEM_BRANCH_FINI(pcvar, taken_p)
220 #define TARGET_SEM_BRANCH_FINI(pcvar, taken_p)
222 #define SEM_BRANCH_FINI(pcvar) \
223 do { TARGET_SEM_BRANCH_FINI (pcvar, taken_p); } while (0)
225 #define SEM_BRANCH_ADDR_CACHE(sem_arg) shouldnt_be_used
226 #define SEM_BRANCH_VIA_CACHE(cpu, sc, newval, pcvar, cachevar) \
228 (pcvar) = (newval); \
231 #define SEM_BRANCH_VIA_ADDR(cpu, sc, newval, pcvar) \
233 (pcvar) = (newval); \
237 #endif /* ! WITH_SCACHE_PBB */
239 #else /* ! WITH_SCACHE */
241 #define CIA_ADDR(cia) (cia)
243 /* semantics.c support */
244 #define SEM_ARGBUF(sem_arg) (sem_arg)
245 #define SEM_INSN(sem_arg) (SEM_ARGBUF (sem_arg) -> base_insn)
247 #define SEM_SEM_ARG(vpc, sc) (sc)
248 #define SEM_NEXT_VPC(sem_arg, pc, len) ((pc) + (len))
250 #define SEM_BRANCH_INIT \
252 #ifndef TARGET_SEM_BRANCH_FINI
253 #define TARGET_SEM_BRANCH_FINI(pcvar, taken_p)
255 #define SEM_BRANCH_FINI(pcvar) \
256 do { TARGET_SEM_BRANCH_FINI (pcvar, taken_p); } while (0)
258 #define SEM_BRANCH_ADDR_CACHE(sem_arg) shouldnt_be_used
259 #define SEM_BRANCH_VIA_CACHE(cpu, abuf, newval, pcvar, cachevar) \
261 (pcvar) = (newval); \
264 #define SEM_BRANCH_VIA_ADDR(cpu, abuf, newval, pcvar) \
266 (pcvar) = (newval); \
270 #endif /* ! WITH_SCACHE */
272 /* Tracing/profiling. */
274 /* Return non-zero if a before/after handler is needed.
275 When tracing/profiling a selected range there's no need to slow
276 down simulation of the other insns (except to get more accurate data!).
278 ??? May wish to profile all insns if doing insn tracing, or to
279 get more accurate cycle data.
281 First test ANY_P so we avoid a potentially expensive HIT_P call
282 [if there are lots of address ranges]. */
284 #define PC_IN_TRACE_RANGE_P(cpu, pc) \
286 && ADDR_RANGE_HIT_P (TRACE_RANGE (CPU_TRACE_DATA (cpu)), (pc)))
287 #define PC_IN_PROFILE_RANGE_P(cpu, pc) \
288 (PROFILE_ANY_P (cpu) \
289 && ADDR_RANGE_HIT_P (PROFILE_RANGE (CPU_PROFILE_DATA (cpu)), (pc)))
291 #endif /* CGEN_ENGINE_H */
This page took 0.035927 seconds and 4 git commands to generate.