* Make-common.in (SCHEME,SCHEMEFLAGS): Delete.
[external/binutils.git] / sim / common / cgen-sim.h
1 /* Simulator header for Cpu tools GENerated simulators.
2    Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3    Contributed by Cygnus Support.
4
5 This file is part of GDB, the GNU debugger.
6
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)
10 any later version.
11
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.
16
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.  */
20
21 #ifndef CGEN_SIM_H
22 #define CGEN_SIM_H
23
24 #define PC CPU (h_pc)
25 \f
26 /* Instruction field support macros.  */
27
28 #define EXTRACT_SIGNED(val, total, start, length) \
29 (((((val) >> ((total) - ((start) + (length)))) & ((1 << (length)) - 1)) \
30   ^ (1 << ((length) - 1))) \
31  - (1 << ((length) - 1)))
32
33 #define EXTRACT_UNSIGNED(val, total, start, length) \
34 (((val) >> ((total) - ((start) + (length)))) & ((1 << (length)) - 1))
35
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)
39 \f
40 /* Execution support.  */
41
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;
47
48 #ifdef SCACHE_P
49
50 /* instruction address */
51 typedef PCADDR IADDR;
52 /* current instruction address */
53 typedef PCADDR CIA;
54 /* argument to semantic functions */
55 typedef SCACHE *SEM_ARG;
56
57 #else /* ! SCACHE_P */
58
59 /* instruction address */
60 typedef PCADDR IADDR;
61 /* current instruction address */
62 typedef PCADDR CIA;
63 /* argument to semantic functions */
64 typedef ARGBUF *SEM_ARG;
65
66 #endif /* ! SCACHE_P */
67
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.  */
75
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 *);
79 #if WITH_SCACHE
80 #ifdef HAVE_PARALLEL_EXEC
81 typedef CIA (SEMANTIC_FN) (SIM_CPU *, SCACHE *, PAREXEC *);
82 #else
83 typedef CIA (SEMANTIC_FN) (SIM_CPU *, SCACHE *);
84 #endif
85 #else /* ! WITH_SCACHE */
86 #ifdef HAVE_PARALLEL_EXEC
87 typedef CIA (SEMANTIC_FN) (SIM_CPU *, ARGBUF *, PAREXEC *);
88 #else
89 typedef CIA (SEMANTIC_FN) (SIM_CPU *, ARGBUF *);
90 #endif
91 #endif
92
93 /* Scache data for each cpu.  */
94
95 typedef struct cpu_scache {
96   /* Simulator cache size.  */
97   int size;
98 #define CPU_SCACHE_SIZE(cpu) ((cpu) -> cgen_cpu.scache.size)
99   /* Cache.  */
100   SCACHE *cache;
101 #define CPU_SCACHE_CACHE(cpu) ((cpu) -> cgen_cpu.scache.cache)
102 #if 0 /* FIXME: wip */
103   /* Free list.  */
104   SCACHE *free;
105 #define CPU_SCACHE_FREE(cpu) ((cpu) -> cgen_cpu.scache.free)
106   /* Hash table.  */
107   SCACHE **hash_table;
108 #define CPU_SCACHE_HASH_TABLE(cpu) ((cpu) -> cgen_cpu.scache.hash_table)
109 #endif
110
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)
116 #endif
117 } CPU_SCACHE;
118
119 /* Default number of cached blocks.  */
120 #ifdef CONFIG_SIM_CACHE_SIZE
121 #define SCACHE_DEFAULT_CACHE_SIZE CONFIG_SIM_CACHE_SIZE
122 #else
123 #define SCACHE_DEFAULT_CACHE_SIZE 1024
124 #endif
125
126 /* Hash a PC value.  */
127 /* FIXME: cpu specific */
128 #define SCACHE_HASH_PC(state, pc) \
129 (((pc) >> 1) & (STATE_SCACHE_SIZE (sd) - 1))
130
131 /* Non-zero if cache is in use.  */
132 #define USING_SCACHE_P(sd) (STATE_SCACHE_SIZE (sd) > 0)
133
134 /* Install the simulator cache into the simulator.  */
135 MODULE_INSTALL_FN scache_install;
136
137 /* Flush all cpu's caches.  */
138 void scache_flush (SIM_DESC);
139 \f
140 /* Scache profiling support.  */
141
142 /* Print summary scache usage information.  */
143 void scache_print_profile (SIM_CPU *cpu, int verbose);
144
145 #if WITH_PROFILE_SCACHE_P
146 #define PROFILE_COUNT_SCACHE_HIT(cpu) \
147 do { \
148   if (CPU_PROFILE_FLAGS (cpu) [PROFILE_SCACHE_IDX]) \
149     ++ CPU_SCACHE_HITS (cpu); \
150 } while (0)
151 #define PROFILE_COUNT_SCACHE_MISS(cpu) \
152 do { \
153   if (CPU_PROFILE_FLAGS (cpu) [PROFILE_SCACHE_IDX]) \
154     ++ CPU_SCACHE_MISSES (cpu); \
155 } while (0)
156 #else
157 #define PROFILE_COUNT_SCACHE_HIT(cpu)
158 #define PROFILE_COUNT_SCACHE_MISS(cpu)
159 #endif
160 \f
161 /* Engine support.  */
162
163 /* Values to denote parallel/sequential execution.  */
164 #define EXEC_SEQUENCE 0
165 #define EXEC_PARALLEL 1
166
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)
172
173 #ifdef SCACHE_P
174
175 #define CIA_ADDR(cia) (cia)
176
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)
186
187 #else /* ! SCACHE_P */
188
189 #define CIA_ADDR(cia) (cia)
190
191 /* semantics.c support */
192 #define SEM_ARGBUF(sem_arg) (sem_arg)
193 #define SEM_INSN(sem_arg) (SEM_ARGBUF (sem_arg) -> insn)
194 /* FIXME:wip */
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)
199
200 #endif /* ! SCACHE_P */
201
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.  */
207 #ifdef __GNUC__
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:
213 #else
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
218 #define ENDSWITCH(N)
219 #endif
220
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);*/
225 \f
226 /* Simulator state.  */
227
228 /* Records simulator descriptor so utilities like @cpu@_dump_regs can be
229    called from gdb.  */
230 extern SIM_DESC current_state;
231
232 /* Simulator state.  */
233
234 /* CGEN_STATE contains additional state information not present in
235    sim_state_base.  */
236
237 typedef struct cgen_state {
238   /* FIXME: Moved to sim_state_base.  */
239   /* argv, env */
240   char **argv;
241 #define STATE_ARGV(s) ((s) -> cgen_state.argv)
242   /* FIXME: Move to sim_state_base.  */
243   char **envp;
244 #define STATE_ENVP(s) ((s) -> cgen_state.envp)
245
246   /* Non-zero if no tracing or profiling is selected.  */
247   int run_fast_p;
248 #define STATE_RUN_FAST_P(sd) ((sd) -> cgen_state.run_fast_p)
249 } CGEN_STATE;
250
251 /* Additional non-machine generated per-cpu data to go in SIM_CPU.
252    The member's name must be `cgen_cpu'.  */
253
254 typedef struct {
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.  */
259   CPU_SCACHE scache;
260
261   /* Instruction descriptor table.  */
262   IDESC *idesc;
263 #define CPU_IDESC(cpu) ((cpu)->cgen_cpu.idesc)
264
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)
271
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)))
277
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.  */
280   double slop;
281 } CGEN_CPU;
282 \f
283 /* Various utilities.  */
284
285 /* Called after sim_post_argv_init to do any cgen initialization.  */
286 extern void cgen_init (SIM_DESC);
287
288 /* Return the maximum number of extra bytes required for a sim_cpu struct.  */
289 extern int cgen_cpu_max_extra_bytes (void);
290
291 extern void
292 sim_disassemble_insn (SIM_CPU *, const CGEN_INSN *,
293                       const struct argbuf *, PCADDR, char *);
294
295 #endif /* CGEN_SIM_H */