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. */
26 /* Instruction field support macros. */
28 #define EXTRACT_SIGNED(val, total, start, length) \
29 (((((val) >> ((total) - ((start) + (length)))) & ((1 << (length)) - 1)) \
30 ^ (1 << ((length) - 1))) \
31 - (1 << ((length) - 1)))
33 #define EXTRACT_UNSIGNED(val, total, start, length) \
34 (((val) >> ((total) - ((start) + (length)))) & ((1 << (length)) - 1))
36 /* Compute number of longs required to hold N bits. */
37 #define HOST_LONGS_FOR_BITS(n) \
38 (((n) + sizeof (long) * 8 - 1) / sizeof (long) * 8)
40 /* Execution support. */
42 /* Forward decls. Defined in the machine generated files. */
43 typedef struct argbuf ARGBUF
;
44 typedef struct scache SCACHE
;
45 typedef struct parexec PAREXEC
;
46 typedef struct idesc IDESC
;
50 /* instruction address */
52 /* current instruction address */
54 /* argument to semantic functions */
55 typedef SCACHE
*SEM_ARG
;
57 #else /* ! SCACHE_P */
59 /* instruction address */
61 /* current instruction address */
63 /* argument to semantic functions */
64 typedef ARGBUF
*SEM_ARG
;
66 #endif /* ! SCACHE_P */
68 /* Semantic functions come in two versions on two axes:
69 fast and full (featured), and using or not using scache.
70 A full featured simulator is always provided. --enable-sim-fast includes
71 support for fast execution by duplicating the semantic code but leaving
72 out all features like tracing and profiling.
73 Using the scache is selected with --enable-sim-scache. */
74 /* FIXME: --enable-sim-fast not implemented yet. */
76 /* Types of the machine generated extract and semantic fns. */
77 /* FIXME: Eventually conditionalize EXTRACT_FN on WITH_SCACHE. */
78 typedef void (EXTRACT_FN
) (SIM_CPU
*, PCADDR
, insn_t
, ARGBUF
*);
80 #ifdef HAVE_PARALLEL_EXEC
81 typedef CIA (SEMANTIC_FN
) (SIM_CPU
*, SCACHE
*, PAREXEC
*);
83 typedef CIA (SEMANTIC_FN
) (SIM_CPU
*, SCACHE
*);
85 #else /* ! WITH_SCACHE */
86 #ifdef HAVE_PARALLEL_EXEC
87 typedef CIA (SEMANTIC_FN
) (SIM_CPU
*, ARGBUF
*, PAREXEC
*);
89 typedef CIA (SEMANTIC_FN
) (SIM_CPU
*, ARGBUF
*);
93 /* Scache data for each cpu. */
95 typedef struct cpu_scache
{
96 /* Simulator cache size. */
98 #define CPU_SCACHE_SIZE(cpu) ((cpu) -> cgen_cpu.scache.size)
101 #define CPU_SCACHE_CACHE(cpu) ((cpu) -> cgen_cpu.scache.cache)
102 #if 0 /* FIXME: wip */
105 #define CPU_SCACHE_FREE(cpu) ((cpu) -> cgen_cpu.scache.free)
108 #define CPU_SCACHE_HASH_TABLE(cpu) ((cpu) -> cgen_cpu.scache.hash_table)
111 #if WITH_PROFILE_SCACHE_P
112 /* Cache hits, misses. */
113 unsigned long hits
, misses
;
114 #define CPU_SCACHE_HITS(cpu) ((cpu) -> cgen_cpu.scache.hits)
115 #define CPU_SCACHE_MISSES(cpu) ((cpu) -> cgen_cpu.scache.misses)
119 /* Default number of cached blocks. */
120 #ifdef CONFIG_SIM_CACHE_SIZE
121 #define SCACHE_DEFAULT_CACHE_SIZE CONFIG_SIM_CACHE_SIZE
123 #define SCACHE_DEFAULT_CACHE_SIZE 1024
126 /* Hash a PC value. */
127 /* FIXME: cpu specific */
128 #define SCACHE_HASH_PC(state, pc) \
129 (((pc) >> 1) & (STATE_SCACHE_SIZE (sd) - 1))
131 /* Non-zero if cache is in use. */
132 #define USING_SCACHE_P(sd) (STATE_SCACHE_SIZE (sd) > 0)
134 /* Install the simulator cache into the simulator. */
135 MODULE_INSTALL_FN scache_install
;
137 /* Flush all cpu's caches. */
138 void scache_flush (SIM_DESC
);
140 /* Scache profiling support. */
142 /* Print summary scache usage information. */
143 void scache_print_profile (SIM_CPU
*cpu
, int verbose
);
145 #if WITH_PROFILE_SCACHE_P
146 #define PROFILE_COUNT_SCACHE_HIT(cpu) \
148 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_SCACHE_IDX]) \
149 ++ CPU_SCACHE_HITS (cpu); \
151 #define PROFILE_COUNT_SCACHE_MISS(cpu) \
153 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_SCACHE_IDX]) \
154 ++ CPU_SCACHE_MISSES (cpu); \
157 #define PROFILE_COUNT_SCACHE_HIT(cpu)
158 #define PROFILE_COUNT_SCACHE_MISS(cpu)
161 /* Engine support. */
163 /* Values to denote parallel/sequential execution. */
164 #define EXEC_SEQUENCE 0
165 #define EXEC_PARALLEL 1
167 /* These are used so that we can compile two copies of the semantic code,
168 one with full feature support and one without. */
169 /* FIXME: Eventually delete extraction if not using scache. */
170 #define EX_FN_NAME(cpu,fn) XCONCAT3 (cpu,_ex_,fn)
171 #define SEM_FN_NAME(cpu,fn) XCONCAT3 (cpu,_sem_,fn)
175 #define CIA_ADDR(cia) (cia)
177 /* semantics.c support */
178 #define SEM_ARGBUF(sem_arg) (&(sem_arg) -> argbuf)
179 #define SEM_INSN(sem_arg) shouldnt_be_used
180 #define SEM_NEXT_PC(sc, len) ((sc) -> next)
181 #define SEM_BRANCH_VIA_CACHE(sc, newval) (newval)
182 #define SEM_BRANCH_VIA_ADDR(sc, newval) (newval)
183 /* Return address a branch insn will branch to.
184 This is only used during tracing. */
185 #define SEM_NEW_PC_ADDR(new_pc) (new_pc)
187 #else /* ! SCACHE_P */
189 #define CIA_ADDR(cia) (cia)
191 /* semantics.c support */
192 #define SEM_ARGBUF(sem_arg) (sem_arg)
193 #define SEM_INSN(sem_arg) (SEM_ARGBUF (sem_arg) -> insn)
195 #define SEM_NEXT_PC(abuf, len) (abuf -> addr + abuf -> length)
196 #define SEM_BRANCH_VIA_CACHE(abuf, newval) (newval)
197 #define SEM_BRANCH_VIA_ADDR(abuf, newval) (newval)
198 #define SEM_NEW_PC_ADDR(new_pc) (new_pc)
200 #endif /* ! SCACHE_P */
202 /* GNU C's "computed goto" facility is used to speed things up where
203 possible. These macros provide a portable way to use them.
204 Nesting of these switch statements is done by providing an extra argument
205 that distinguishes them. `N' can be a number or symbol.
206 Variable `labels_##N' must be initialized with the labels of each case. */
208 #define SWITCH(N, X) goto *X;
209 #define CASE(N, X) case_##N##_##X
210 #define BREAK(N) goto end_switch_##N
211 #define DEFAULT(N) default_##N
212 #define ENDSWITCH(N) end_switch_##N:
214 #define SWITCH(N, X) switch (X)
215 #define CASE(N, X) case X /* FIXME: old sem-switch had (@arch@_,X) here */
216 #define BREAK(N) break
217 #define DEFAULT(N) default
221 /* Engine control (FIXME). */
222 int engine_stop (SIM_DESC
);
223 void engine_run (SIM_DESC
, int, int);
224 /*void engine_resume (SIM_DESC, int, int);*/
226 /* Simulator state. */
228 /* Records simulator descriptor so utilities like @cpu@_dump_regs can be
230 extern SIM_DESC current_state
;
232 /* Simulator state. */
234 /* CGEN_STATE contains additional state information not present in
237 typedef struct cgen_state
{
238 /* FIXME: Moved to sim_state_base. */
241 #define STATE_ARGV(s) ((s) -> cgen_state.argv)
242 /* FIXME: Move to sim_state_base. */
244 #define STATE_ENVP(s) ((s) -> cgen_state.envp)
246 /* Non-zero if no tracing or profiling is selected. */
248 #define STATE_RUN_FAST_P(sd) ((sd) -> cgen_state.run_fast_p)
251 /* Additional non-machine generated per-cpu data to go in SIM_CPU.
252 The member's name must be `cgen_cpu'. */
255 /* Simulator's execution cache.
256 Allocate space for this even if not used as some simulators may have
257 one machine variant that uses the scache and another that doesn't and
258 we don't want members in this struct to move about. */
261 /* Instruction descriptor table. */
263 #define CPU_IDESC(cpu) ((cpu)->cgen_cpu.idesc)
265 /* Whether the read,semantic entries have been initialized or not.
266 These are computed goto labels. */
267 int idesc_read_init_p
;
268 #define CPU_IDESC_READ_INIT_P(cpu) ((cpu)->cgen_cpu.idesc_read_init_p)
269 int idesc_sem_init_p
;
270 #define CPU_IDESC_SEM_INIT_P(cpu) ((cpu)->cgen_cpu.idesc_sem_init_p)
272 /* Function to fetch the opcode table entry in the IDESC. */
273 const CGEN_INSN
* (*opcode
) (SIM_CPU
*, int);
274 #define CPU_OPCODE(cpu) ((cpu)->cgen_cpu.opcode)
275 /* Return name of instruction numbered INUM. */
276 #define INSN_NAME(cpu, inum) CGEN_INSN_NAME ((* CPU_OPCODE (cpu)) ((cpu), (inum)))
278 /* Allow slop in size calcs for case where multiple cpu types are supported
279 and space for the specified cpu is malloc'd at run time. */
283 /* Various utilities. */
285 /* Called after sim_post_argv_init to do any cgen initialization. */
286 extern void cgen_init (SIM_DESC
);
288 /* Return the maximum number of extra bytes required for a sim_cpu struct. */
289 extern int cgen_cpu_max_extra_bytes (void);
292 sim_disassemble_insn (SIM_CPU
*, const CGEN_INSN
*,
293 const struct argbuf
*, PCADDR
, char *);
295 #endif /* CGEN_SIM_H */