Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Simulator pseudo baseclass. |
2 | Copyright (C) 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 | ||
22 | /* Simulator state pseudo baseclass. | |
23 | ||
24 | Each simulator is required to have the file ``sim-main.h''. That | |
25 | file includes ``sim-basics.h'', defines the base type ``sim_cia'' | |
26 | (the data type that contains complete current instruction address | |
27 | information), include ``sim-base.h'': | |
28 | ||
29 | #include "sim-basics.h" | |
30 | typedef address_word sim_cia; | |
31 | /-* If `sim_cia' is not an integral value (e.g. a struct), define | |
32 | CIA_ADDR to return the integral value. *-/ | |
33 | /-* #define CIA_ADDR(cia) (...) *-/ | |
34 | #include "sim-base.h" | |
35 | ||
36 | finally, two data types `struct _sim_cpu' and `struct sim_state' | |
37 | are defined: | |
38 | ||
39 | struct _sim_cpu { | |
40 | ... simulator specific members ... | |
41 | sim_cpu_base base; | |
42 | }; | |
43 | ||
44 | struct sim_state { | |
45 | sim_cpu cpu[MAX_NR_PROCESSORS]; | |
46 | #if (WITH_SMP) | |
47 | #define STATE_CPU(sd,n) (&(sd)->cpu[n]) | |
48 | #else | |
49 | #define STATE_CPU(sd,n) (&(sd)->cpu[0]) | |
50 | #endif | |
51 | ... simulator specific members ... | |
52 | sim_state_base base; | |
53 | }; | |
54 | ||
55 | Note that `base' appears last. This makes `base.magic' appear last | |
56 | in the entire struct and helps catch miscompilation errors. */ | |
57 | ||
58 | ||
59 | #ifndef SIM_BASE_H | |
60 | #define SIM_BASE_H | |
61 | ||
62 | /* Pre-declare certain types. */ | |
63 | ||
64 | /* typedef <target-dependant> sim_cia; */ | |
65 | #ifndef NULL_CIA | |
66 | #define NULL_CIA ((sim_cia) 0) | |
67 | #endif | |
68 | /* Return the current instruction address as a number. | |
69 | Some targets treat the current instruction address as a struct | |
70 | (e.g. for delay slot handling). */ | |
71 | #ifndef CIA_ADDR | |
72 | #define CIA_ADDR(cia) (cia) | |
73 | #endif | |
74 | #ifndef INVALID_INSTRUCTION_ADDRESS | |
75 | #define INVALID_INSTRUCTION_ADDRESS ((address_word)0 - 1) | |
76 | #endif | |
77 | ||
78 | typedef struct _sim_cpu sim_cpu; | |
79 | ||
80 | #include "sim-module.h" | |
81 | ||
82 | #include "sim-trace.h" | |
83 | #include "sim-core.h" | |
84 | #include "sim-events.h" | |
85 | #include "sim-profile.h" | |
86 | #ifdef SIM_HAVE_MODEL | |
87 | #include "sim-model.h" | |
88 | #endif | |
89 | #include "sim-io.h" | |
90 | #include "sim-engine.h" | |
91 | #include "sim-watch.h" | |
92 | #include "sim-memopt.h" | |
93 | #ifdef SIM_HAVE_BREAKPOINTS | |
94 | #include "sim-break.h" | |
95 | #endif | |
96 | #include "sim-cpu.h" | |
97 | ||
98 | /* Global pointer to current state while sim_resume is running. | |
99 | On a machine with lots of registers, it might be possible to reserve | |
100 | one of them for current_state. However on a machine with few registers | |
101 | current_state can't permanently live in one and indirecting through it | |
102 | will be slower [in which case one can have sim_resume set globals from | |
103 | current_state for faster access]. | |
104 | If CURRENT_STATE_REG is defined, it means current_state is living in | |
105 | a global register. */ | |
106 | ||
107 | ||
108 | #ifdef CURRENT_STATE_REG | |
109 | /* FIXME: wip */ | |
110 | #else | |
111 | extern struct sim_state *current_state; | |
112 | #endif | |
113 | ||
114 | ||
115 | /* The simulator may provide different (and faster) definition. */ | |
116 | #ifndef CURRENT_STATE | |
117 | #define CURRENT_STATE current_state | |
118 | #endif | |
119 | ||
120 | ||
121 | typedef struct { | |
122 | ||
123 | /* Simulator's argv[0]. */ | |
124 | const char *my_name; | |
125 | #define STATE_MY_NAME(sd) ((sd)->base.my_name) | |
126 | ||
127 | /* Who opened the simulator. */ | |
128 | SIM_OPEN_KIND open_kind; | |
129 | #define STATE_OPEN_KIND(sd) ((sd)->base.open_kind) | |
130 | ||
131 | /* The host callbacks. */ | |
132 | struct host_callback_struct *callback; | |
133 | #define STATE_CALLBACK(sd) ((sd)->base.callback) | |
134 | ||
135 | /* The type of simulation environment (user/operating). */ | |
136 | enum sim_environment environment; | |
137 | #define STATE_ENVIRONMENT(sd) ((sd)->base.environment) | |
138 | ||
139 | #if 0 /* FIXME: Not ready yet. */ | |
140 | /* Stuff defined in sim-config.h. */ | |
141 | struct sim_config config; | |
142 | #define STATE_CONFIG(sd) ((sd)->base.config) | |
143 | #endif | |
144 | ||
145 | /* List of installed module `init' handlers. */ | |
146 | struct module_list *modules; | |
147 | #define STATE_MODULES(sd) ((sd)->base.modules) | |
148 | ||
149 | /* Supported options. */ | |
150 | struct option_list *options; | |
151 | #define STATE_OPTIONS(sd) ((sd)->base.options) | |
152 | ||
153 | /* Non-zero if -v specified. */ | |
154 | int verbose_p; | |
155 | #define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p) | |
156 | ||
157 | /* Non cpu-specific trace data. See sim-trace.h. */ | |
158 | TRACE_DATA trace_data; | |
159 | #define STATE_TRACE_DATA(sd) (& (sd)->base.trace_data) | |
160 | ||
161 | /* If non NULL, the BFD architecture specified on the command line */ | |
162 | const struct bfd_arch_info *architecture; | |
163 | #define STATE_ARCHITECTURE(sd) ((sd)->base.architecture) | |
164 | ||
165 | /* If non NULL, the bfd target specified on the command line */ | |
166 | const char *target; | |
167 | #define STATE_TARGET(sd) ((sd)->base.target) | |
168 | ||
169 | /* In standalone simulator, this is the program's arguments passed | |
170 | on the command line. */ | |
171 | char **prog_argv; | |
172 | #define STATE_PROG_ARGV(sd) ((sd)->base.prog_argv) | |
173 | ||
174 | /* The program's bfd. */ | |
175 | struct _bfd *prog_bfd; | |
176 | #define STATE_PROG_BFD(sd) ((sd)->base.prog_bfd) | |
177 | ||
178 | /* Symbol table for prog_bfd */ | |
179 | struct symbol_cache_entry **prog_syms; | |
180 | #define STATE_PROG_SYMS(sd) ((sd)->base.prog_syms) | |
181 | ||
182 | /* The program's text section. */ | |
183 | struct sec *text_section; | |
184 | /* Starting and ending text section addresses from the bfd. */ | |
185 | SIM_ADDR text_start, text_end; | |
186 | #define STATE_TEXT_SECTION(sd) ((sd)->base.text_section) | |
187 | #define STATE_TEXT_START(sd) ((sd)->base.text_start) | |
188 | #define STATE_TEXT_END(sd) ((sd)->base.text_end) | |
189 | ||
190 | /* Start address, set when the program is loaded from the bfd. */ | |
191 | SIM_ADDR start_addr; | |
192 | #define STATE_START_ADDR(sd) ((sd)->base.start_addr) | |
193 | ||
194 | /* Size of the simulator's cache, if any. | |
195 | This is not the target's cache. It is the cache the simulator uses | |
196 | to process instructions. */ | |
197 | unsigned int scache_size; | |
198 | #define STATE_SCACHE_SIZE(sd) ((sd)->base.scache_size) | |
199 | ||
200 | /* FIXME: Move to top level sim_state struct (as some struct)? */ | |
201 | #ifdef SIM_HAVE_FLATMEM | |
202 | unsigned int mem_size; | |
203 | #define STATE_MEM_SIZE(sd) ((sd)->base.mem_size) | |
204 | unsigned int mem_base; | |
205 | #define STATE_MEM_BASE(sd) ((sd)->base.mem_base) | |
206 | unsigned char *memory; | |
207 | #define STATE_MEMORY(sd) ((sd)->base.memory) | |
208 | #endif | |
209 | ||
210 | /* core memory bus */ | |
211 | #define STATE_CORE(sd) (&(sd)->base.core) | |
212 | sim_core core; | |
213 | ||
214 | /* Record of memory sections added via the memory-options interface. */ | |
215 | #define STATE_MEMOPT(sd) ((sd)->base.memopt) | |
216 | sim_memopt *memopt; | |
217 | ||
218 | /* event handler */ | |
219 | #define STATE_EVENTS(sd) (&(sd)->base.events) | |
220 | sim_events events; | |
221 | ||
222 | /* generic halt/resume engine */ | |
223 | sim_engine engine; | |
224 | #define STATE_ENGINE(sd) (&(sd)->base.engine) | |
225 | ||
226 | /* generic watchpoint support */ | |
227 | sim_watchpoints watchpoints; | |
228 | #define STATE_WATCHPOINTS(sd) (&(sd)->base.watchpoints) | |
229 | ||
230 | /* Pointer to list of breakpoints */ | |
231 | struct sim_breakpoint *breakpoints; | |
232 | #define STATE_BREAKPOINTS(sd) ((sd)->base.breakpoints) | |
233 | ||
234 | #if WITH_HW | |
235 | struct sim_hw *hw; | |
236 | #define STATE_HW(sd) ((sd)->base.hw) | |
237 | #endif | |
238 | ||
43e526b9 JM |
239 | /* Should image loads be performed using the LMA or VMA? Older |
240 | simulators use the VMA while newer simulators prefer the LMA. */ | |
241 | int load_at_lma_p; | |
242 | #define STATE_LOAD_AT_LMA_P(SD) ((SD)->base.load_at_lma_p) | |
243 | ||
c906108c SS |
244 | /* Marker for those wanting to do sanity checks. |
245 | This should remain the last member of this struct to help catch | |
246 | miscompilation errors. */ | |
247 | int magic; | |
248 | #define SIM_MAGIC_NUMBER 0x4242 | |
249 | #define STATE_MAGIC(sd) ((sd)->base.magic) | |
250 | } sim_state_base; | |
251 | ||
252 | /* Functions for allocating/freeing a sim_state. */ | |
253 | SIM_DESC sim_state_alloc PARAMS ((SIM_OPEN_KIND kind, host_callback *callback)); | |
254 | void sim_state_free PARAMS ((SIM_DESC)); | |
255 | ||
256 | #endif /* SIM_BASE_H */ |