1 /* Simulator header for Cpu tools GENerated simulators.
2 Copyright (C) 1996, 1997, 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. */
28 /* Instruction field support macros. */
30 #define EXTRACT_SIGNED(val, total, start, length) \
31 (((((val) >> ((total) - ((start) + (length)))) & ((1 << (length)) - 1)) \
32 ^ (1 << ((length) - 1))) \
33 - (1 << ((length) - 1)))
35 #define EXTRACT_UNSIGNED(val, total, start, length) \
36 (((val) >> ((total) - ((start) + (length)))) & ((1 << (length)) - 1))
38 /* Compute number of longs required to hold N bits. */
39 #define HOST_LONGS_FOR_BITS(n) \
40 (((n) + sizeof (long) * 8 - 1) / sizeof (long) * 8)
42 /* Execution support. */
44 /* Forward decls. Defined in the machine generated arch.h and cpu.h files. */
45 typedef struct argbuf ARGBUF;
46 typedef struct scache SCACHE;
47 typedef struct parallel_exec PARALLEL_EXEC;
49 /* Types of the machine generated extract and semantic fns. */
50 typedef void (EXTRACT_FN) (SIM_CPU *, PCADDR, insn_t, ARGBUF *);
51 /* ??? READ_FN isn't currently used anywhere, we always use a switch. */
52 typedef void (READ_FN) (SIM_CPU *, PCADDR, insn_t, PARALLEL_EXEC *);
53 /*typedef CIA (SEMANTIC_FN) (SEM_ARG);*/
54 typedef PCADDR (SEMANTIC_FN) (SIM_CPU *, ARGBUF *);
56 typedef void (EXTRACT_CACHE_FN) (SIM_CPU *, PCADDR, insn_t, ARGBUF *);
58 typedef PCADDR (SEMANTIC_CACHE_FN) (SIM_CPU *, SCACHE *);
61 /* Using cgen_insn_type requires <cpu>-opc.h. */
62 int /*enum cgen_insn_type*/ insn_type;
63 const struct cgen_insn *opcode;
65 #ifdef HAVE_PARALLEL_EXEC
72 SEMANTIC_FN *semantic;
73 SEMANTIC_CACHE_FN *semantic_fast;
74 #if WITH_SEM_SWITCH_FULL && defined (__GNUC__)
78 #if WITH_SEM_SWITCH_FAST && defined (__GNUC__)
80 void *semantic_lab; /* FIXME: Rename to sem_fast_lab. */
86 Semantic functions come in two versions.
87 One that uses the cache, and one that doesn't.
88 ??? The one that doesn't may eventually be thrown away or replaced with
93 /* instruction address */
95 /* current instruction address */
97 /* argument to semantic functions */
98 typedef SCACHE *SEM_ARG;
100 #else /* ! SCACHE_P */
102 /* instruction address */
103 typedef PCADDR IADDR;
104 /* current instruction address */
106 /* argument to semantic functions */
107 typedef ARGBUF *SEM_ARG;
109 #endif /* ! SCACHE_P */
111 /* Scache data for each cpu. */
113 typedef struct cpu_scache {
114 /* Simulator cache size. */
116 #define CPU_SCACHE_SIZE(cpu) ((cpu) -> cgen_cpu.scache.size)
119 #define CPU_SCACHE_CACHE(cpu) ((cpu) -> cgen_cpu.scache.cache)
120 #if 0 /* FIXME: wip */
123 #define CPU_SCACHE_FREE(cpu) ((cpu) -> cgen_cpu.scache.free)
126 #define CPU_SCACHE_HASH_TABLE(cpu) ((cpu) -> cgen_cpu.scache.hash_table)
129 #if WITH_PROFILE_SCACHE_P
130 /* Cache hits, misses. */
131 unsigned long hits, misses;
132 #define CPU_SCACHE_HITS(cpu) ((cpu) -> cgen_cpu.scache.hits)
133 #define CPU_SCACHE_MISSES(cpu) ((cpu) -> cgen_cpu.scache.misses)
137 /* Default number of cached blocks. */
138 #ifdef CONFIG_SIM_CACHE_SIZE
139 #define SCACHE_DEFAULT_CACHE_SIZE CONFIG_SIM_CACHE_SIZE
141 #define SCACHE_DEFAULT_CACHE_SIZE 1024
144 /* Hash a PC value. */
145 /* FIXME: cpu specific */
146 #define SCACHE_HASH_PC(state, pc) \
147 (((pc) >> 1) & (STATE_SCACHE_SIZE (sd) - 1))
149 /* Non-zero if cache is in use. */
150 #define USING_SCACHE_P(sd) (STATE_SCACHE_SIZE (sd) > 0)
152 /* Install the simulator cache into the simulator. */
153 MODULE_INSTALL_FN scache_install;
155 /* Flush all cpu's caches. */
156 void scache_flush (SIM_DESC);
158 /* Scache profiling support. */
160 /* Print summary scache usage information. */
161 void scache_print_profile (SIM_CPU *cpu, int verbose);
163 #if WITH_PROFILE_SCACHE_P
164 #define PROFILE_COUNT_SCACHE_HIT(cpu) \
166 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_SCACHE_IDX]) \
167 ++ CPU_SCACHE_HITS (cpu); \
169 #define PROFILE_COUNT_SCACHE_MISS(cpu) \
171 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_SCACHE_IDX]) \
172 ++ CPU_SCACHE_MISSES (cpu); \
175 #define PROFILE_COUNT_SCACHE_HIT(cpu)
176 #define PROFILE_COUNT_SCACHE_MISS(cpu)
179 /* Engine support. */
181 /* Values to denote parallel/sequential execution. */
182 #define EXEC_SEQUENCE 0
183 #define EXEC_PARALLEL 1
187 #define CIA_ADDR(cia) (cia)
189 /* These are used so that we can compile two copies of the semantic code,
190 one with scache support and one without. */
191 /* FIXME: Do we want _ex_ or _exc_? */
192 /*#define EX_FN_NAME(cpu,fn) XCONCAT3 (cpu,_exc_,fn)*/
193 #define EX_FN_NAME(cpu,fn) XCONCAT3 (cpu,_ex_,fn)
194 #define SEM_FN_NAME(cpu,fn) XCONCAT3 (cpu,_semc_,fn)
196 /* extract.c support */
197 /* scache_unset is a cache entry that is never used.
198 It's raison d'etre is so BRANCH_VIA_CACHE doesn't have to test for
199 newval.cache == NULL. */
200 extern struct scache scache_unset;
201 #define RECORD_IADDR(fld, val) \
202 do { (fld) = (val); } while (0)
204 /* semantics.c support */
205 #define SEM_ARGBUF(sem_arg) (&(sem_arg) -> argbuf)
206 #define SEM_INSN(sem_arg) shouldnt_be_used
207 #define SEM_NEXT_PC(sc) ((sc) -> next)
208 #define SEM_BRANCH_VIA_CACHE(sc, newval) (newval)
209 #define SEM_BRANCH_VIA_ADDR(sc, newval) (newval)
210 /* Return address a branch insn will branch to.
211 This is only used during tracing. */
212 #define SEM_NEW_PC_ADDR(new_pc) (new_pc)
214 #else /* ! SCACHE_P */
216 #define CIA_ADDR(cia) (cia)
218 /* These are used so that we can compile two copies of the semantic code,
219 one with scache support and one without. */
220 #define EX_FN_NAME(cpu,fn) XCONCAT3 (cpu,_ex_,fn)
221 #define SEM_FN_NAME(cpu,fn) XCONCAT3 (cpu,_sem_,fn)
223 /* extract.c support */
224 #define RECORD_IADDR(fld, val) \
225 do { (fld) = (val); } while (0)
227 /* semantics.c support */
228 #define SEM_ARGBUF(sem_arg) (sem_arg)
229 #define SEM_INSN(sem_arg) (SEM_ARGBUF (sem_arg) -> insn)
230 #define SEM_NEXT_PC(abuf) (abuf -> addr + abuf -> length)
231 #define SEM_BRANCH_VIA_CACHE(abuf, newval) (newval)
232 #define SEM_BRANCH_VIA_ADDR(abuf, newval) (newval)
233 #define SEM_NEW_PC_ADDR(new_pc) (new_pc)
235 #endif /* ! SCACHE_P */
237 /* GNU C's "computed goto" facility is used to speed things up where
238 possible. These macros provide a portable way to use them.
239 Nesting of these switch statements is done by providing an extra argument
240 that distinguishes them. `N' can be a number or symbol.
241 Variable `labels_##N' must be initialized with the labels of each case. */
243 #define SWITCH(N, X) goto *X;
244 #define CASE(N, X) case_##N##_##X
245 #define BREAK(N) goto end_switch_##N
246 #define DEFAULT(N) default_##N
247 #define ENDSWITCH(N) end_switch_##N:
249 #define SWITCH(N, X) switch (X)
250 #define CASE(N, X) case X /* FIXME: old sem-switch had (@arch@_,X) here */
251 #define BREAK(N) break
252 #define DEFAULT(N) default
256 /* Engine control (FIXME). */
257 int engine_stop (SIM_DESC);
258 void engine_run (SIM_DESC, int, int);
259 /*void engine_resume (SIM_DESC, int, int);*/
261 /* Simulator state. */
263 /* Records simulator descriptor so utilities like @cpu@_dump_regs can be
265 extern SIM_DESC current_state;
267 /* Simulator state. */
269 /* CGEN_STATE contains additional state information not present in
272 typedef struct cgen_state {
273 /* FIXME: Moved to sim_state_base. */
276 #define STATE_ARGV(s) ((s) -> cgen_state.argv)
277 /* FIXME: Move to sim_state_base. */
279 #define STATE_ENVP(s) ((s) -> cgen_state.envp)
281 /* Non-zero if no tracing or profiling is selected. */
283 #define STATE_RUN_FAST_P(sd) ((sd) -> cgen_state.run_fast_p)
286 /* Additional non-machine generated per-cpu data to go in SIM_CPU.
287 The member's name must be `cgen_cpu'. */
290 /* Simulator's execution cache. */
293 #endif /* WITH_SCACHE */
295 /* Allow slop in size calcs for case where multiple cpu types are supported
296 and space for the specified cpu is malloc'd at run time. */
300 /* Various utilities. */
302 /* Called after sim_post_argv_init to do any cgen initialization. */
303 void cgen_init (SIM_DESC);
306 sim_disassemble_insn (SIM_CPU *, const struct cgen_insn *,
307 const struct argbuf *, PCADDR, char *);
309 #endif /* CGEN_SIM_H */