* cgen-mem.h, cgen-scache.[ch], cgen-sem.h, cgen-sim.h: New files.
[external/binutils.git] / sim / common / cgen-sim.h
1 /* Simulator header for Cpu tools GENerated simulators.
2    Copyright (C) 1996, 1997 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 (STATE_CPU_CPU (current_state, 0)->pc)
25
26 /* Execution state.  */
27 enum exec_state {
28   EXEC_STATE_RUNNING, EXEC_STATE_EXITED,
29   EXEC_STATE_STOPPED, EXEC_STATE_SIGNALLED
30 };
31
32 /* Signals we use.  */
33 enum sim_signal_type {
34   SIM_SIGNONE,
35   SIM_SIGILL,    /* illegal insn */
36   SIM_SIGTRAP,
37   SIM_SIGALIGN,  /* misaligned memory access */
38   SIM_SIGACCESS, /* tried to read/write memory that's not readable/writable */
39   SIM_SIGXCPU    /* cpu limit exceeded */
40 };
41
42 void engine_halt PARAMS ((struct _sim_cpu *, enum exec_state, int));
43 void engine_signal PARAMS ((struct _sim_cpu *, enum sim_signal_type));
44 \f
45 /* Decode,extract,semantics.  */
46
47 typedef void (EXTRACT_FN) PARAMS ((SIM_CPU *, PCADDR, insn_t, struct argbuf *));
48 /*typedef CIA (SEMANTIC_FN) PARAMS ((SEM_ARG));*/
49 typedef PCADDR (SEMANTIC_FN) PARAMS ((SIM_CPU *, struct argbuf *));
50 #if 0 /* wip */
51 typedef void (EXTRACT_CACHE_FN) PARAMS ((SIM_CPU *, PCADDR, insn_t, struct argbuf *));
52 #endif
53 typedef PCADDR (SEMANTIC_CACHE_FN) PARAMS ((SIM_CPU *, struct scache *));
54
55 typedef struct {
56   /* Using cgen_insn_type requires <cpu>-opc.h.  */
57   int /*enum cgen_insn_type*/ insn_type;
58   const struct cgen_insn *opcode;
59   /* FIXME: Perhaps rename these to normal/fast versions to associate them
60      with the normal/fast args to genmloop.sh.  */
61   EXTRACT_FN *extract;
62   SEMANTIC_FN *semantic;
63 #if 0 /* wip */
64   EXTRACT_CACHE_FN *extract_fast;
65 #endif
66   SEMANTIC_CACHE_FN *semantic_fast;
67 #if defined (USE_SEM_SWITCH) && defined (__GNUC__)
68   void *semantic_lab;
69 #endif
70 } DECODE;
71
72 /* FIXME: length parm to decode() is currently unneeded.  */
73 extern DECODE *decode PARAMS ((insn_t /*, int*/));
74 \f
75 /* Simulator state.  */
76
77 #if WITH_SCACHE
78 #include "cgen-scache.h"
79 #endif
80
81 /* ??? Do we *need* to pass state to the semantic routines?  */
82 extern SIM_DESC current_state;
83
84 /* FIXME: Until sim_open creates one.  */
85 extern struct sim_state sim_global_state;
86
87 /* Simulator state.  */
88
89 /* Main state struct.
90    CGEN_STATE contains addition state information not present in
91    sim_state_base.  */
92
93 typedef struct cgen_state {
94   /* argv, env */
95   char **argv;
96 #define STATE_ARGV(s) ((s)->cgen_state.argv)
97   char **envp;
98 #define STATE_ENVP(s) ((s)->cgen_state.envp)
99 } CGEN_STATE;
100
101 /* Additional per-cpu data.  */
102
103 typedef struct {
104   /* Simulator's execution cache.  */
105 #if WITH_SCACHE
106   CPU_SCACHE scache;
107 #endif /* WITH_SCACHE */
108
109   enum exec_state exec_state;
110 #define CPU_EXEC_STATE(cpu) ((cpu)->cgen_cpu.exec_state)
111
112   int halt_sigrc;
113 #define CPU_HALT_SIGRC(cpu) ((cpu)->cgen_cpu.halt_sigrc)
114
115   jmp_buf halt_jmp_buf;
116 #define CPU_HALT_JMP_BUF(cpu) ((cpu)->cgen_cpu.halt_jmp_buf)
117
118   CPU_DATA cpu;
119 #define CPU_CPU(c) (& (c)->cgen_cpu.cpu)
120   CPU_PROFILE profile_state;
121 #define CPU_PROFILE_STATE(cpu) (& (cpu)->cgen_cpu.profile_state)
122 } CGEN_CPU;
123 \f
124 /* Various utilities.  */
125
126 int engine_stop (SIM_DESC);
127 void engine_run (SIM_DESC, int, int);
128 void engine_resume (SIM_DESC, int, int);
129 void engine_halt (SIM_CPU *, enum exec_state, int);
130 void engine_signal (SIM_CPU *, enum sim_signal_type);
131
132 int sim_signal_to_host (int);
133
134 void
135 sim_disassemble_insn (const struct cgen_insn *, const struct argbuf *,
136                       PCADDR, char *);
137
138 #endif /* CGEN_SIM_H */