]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Simulator pseudo baseclass. |
836cc9f4 | 2 | |
213516ef | 3 | Copyright 1997-2023 Free Software Foundation, Inc. |
836cc9f4 | 4 | |
c906108c SS |
5 | Contributed by Cygnus Support. |
6 | ||
7 | This file is part of GDB, the GNU debugger. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
4744ac1b JB |
11 | the Free Software Foundation; either version 3 of the License, or |
12 | (at your option) any later version. | |
c906108c SS |
13 | |
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
4744ac1b JB |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
c906108c SS |
21 | |
22 | ||
23 | /* Simulator state pseudo baseclass. | |
24 | ||
25 | Each simulator is required to have the file ``sim-main.h''. That | |
26 | file includes ``sim-basics.h'', defines the base type ``sim_cia'' | |
27 | (the data type that contains complete current instruction address | |
28 | information), include ``sim-base.h'': | |
29 | ||
30 | #include "sim-basics.h" | |
c906108c SS |
31 | /-* If `sim_cia' is not an integral value (e.g. a struct), define |
32 | CIA_ADDR to return the integral value. *-/ | |
7e83aa92 | 33 | /-* typedef struct {...} sim_cia; *-/ |
c906108c SS |
34 | /-* #define CIA_ADDR(cia) (...) *-/ |
35 | #include "sim-base.h" | |
028f6515 | 36 | |
c906108c SS |
37 | finally, two data types `struct _sim_cpu' and `struct sim_state' |
38 | are defined: | |
39 | ||
40 | struct _sim_cpu { | |
41 | ... simulator specific members ... | |
42 | sim_cpu_base base; | |
43 | }; | |
44 | ||
383861bd | 45 | If your sim needs to allocate sim-wide state, use STATE_ARCH_DATA. */ |
c906108c SS |
46 | |
47 | ||
48 | #ifndef SIM_BASE_H | |
49 | #define SIM_BASE_H | |
50 | ||
444b3fae ПК |
51 | #ifdef __cplusplus |
52 | extern "C" { | |
53 | #endif | |
54 | ||
c906108c SS |
55 | /* Pre-declare certain types. */ |
56 | ||
57 | /* typedef <target-dependant> sim_cia; */ | |
58 | #ifndef NULL_CIA | |
59 | #define NULL_CIA ((sim_cia) 0) | |
60 | #endif | |
61 | /* Return the current instruction address as a number. | |
62 | Some targets treat the current instruction address as a struct | |
63 | (e.g. for delay slot handling). */ | |
64 | #ifndef CIA_ADDR | |
65 | #define CIA_ADDR(cia) (cia) | |
7e83aa92 | 66 | typedef address_word sim_cia; |
c906108c SS |
67 | #endif |
68 | #ifndef INVALID_INSTRUCTION_ADDRESS | |
69 | #define INVALID_INSTRUCTION_ADDRESS ((address_word)0 - 1) | |
70 | #endif | |
71 | ||
20bca71d MF |
72 | /* TODO: Probably should just delete SIM_CPU. */ |
73 | typedef struct _sim_cpu SIM_CPU; | |
c906108c SS |
74 | typedef struct _sim_cpu sim_cpu; |
75 | ||
6cf3ddd2 MF |
76 | #include "bfd.h" |
77 | ||
c906108c SS |
78 | #include "sim-module.h" |
79 | ||
ef986697 | 80 | #include "sim-arange.h" |
c906108c SS |
81 | #include "sim-trace.h" |
82 | #include "sim-core.h" | |
83 | #include "sim-events.h" | |
84 | #include "sim-profile.h" | |
c906108c | 85 | #include "sim-model.h" |
c906108c SS |
86 | #include "sim-io.h" |
87 | #include "sim-engine.h" | |
88 | #include "sim-watch.h" | |
89 | #include "sim-memopt.h" | |
c906108c | 90 | #include "sim-cpu.h" |
d3fe0d7b | 91 | #include "sim-assert.h" |
c906108c | 92 | |
f4fdd845 MF |
93 | struct sim_state { |
94 | /* All the cpus for this instance. */ | |
95 | sim_cpu *cpu[MAX_NR_PROCESSORS]; | |
78e9aa70 MF |
96 | #if (WITH_SMP) |
97 | # define STATE_CPU(sd, n) ((sd)->cpu[n]) | |
98 | #else | |
99 | # define STATE_CPU(sd, n) ((sd)->cpu[0]) | |
100 | #endif | |
101 | ||
c906108c SS |
102 | /* Simulator's argv[0]. */ |
103 | const char *my_name; | |
f4fdd845 | 104 | #define STATE_MY_NAME(sd) ((sd)->my_name) |
c906108c SS |
105 | |
106 | /* Who opened the simulator. */ | |
107 | SIM_OPEN_KIND open_kind; | |
f4fdd845 | 108 | #define STATE_OPEN_KIND(sd) ((sd)->open_kind) |
c906108c SS |
109 | |
110 | /* The host callbacks. */ | |
111 | struct host_callback_struct *callback; | |
f4fdd845 | 112 | #define STATE_CALLBACK(sd) ((sd)->callback) |
c906108c SS |
113 | |
114 | /* The type of simulation environment (user/operating). */ | |
115 | enum sim_environment environment; | |
f4fdd845 | 116 | #define STATE_ENVIRONMENT(sd) ((sd)->environment) |
c906108c SS |
117 | |
118 | #if 0 /* FIXME: Not ready yet. */ | |
119 | /* Stuff defined in sim-config.h. */ | |
120 | struct sim_config config; | |
f4fdd845 | 121 | #define STATE_CONFIG(sd) ((sd)->config) |
c906108c SS |
122 | #endif |
123 | ||
124 | /* List of installed module `init' handlers. */ | |
125 | struct module_list *modules; | |
f4fdd845 | 126 | #define STATE_MODULES(sd) ((sd)->modules) |
c906108c SS |
127 | |
128 | /* Supported options. */ | |
129 | struct option_list *options; | |
f4fdd845 | 130 | #define STATE_OPTIONS(sd) ((sd)->options) |
c906108c SS |
131 | |
132 | /* Non-zero if -v specified. */ | |
133 | int verbose_p; | |
f4fdd845 | 134 | #define STATE_VERBOSE_P(sd) ((sd)->verbose_p) |
c906108c SS |
135 | |
136 | /* Non cpu-specific trace data. See sim-trace.h. */ | |
137 | TRACE_DATA trace_data; | |
f4fdd845 | 138 | #define STATE_TRACE_DATA(sd) (& (sd)->trace_data) |
c906108c SS |
139 | |
140 | /* If non NULL, the BFD architecture specified on the command line */ | |
141 | const struct bfd_arch_info *architecture; | |
f4fdd845 | 142 | #define STATE_ARCHITECTURE(sd) ((sd)->architecture) |
c906108c SS |
143 | |
144 | /* If non NULL, the bfd target specified on the command line */ | |
145 | const char *target; | |
f4fdd845 | 146 | #define STATE_TARGET(sd) ((sd)->target) |
c906108c | 147 | |
1c636da0 MF |
148 | /* List of machs available. */ |
149 | const SIM_MACH * const *machs; | |
150 | #define STATE_MACHS(sd) ((sd)->machs) | |
151 | ||
d414eb3e MF |
152 | /* If non-NULL, the model to select for CPUs. */ |
153 | const char *model_name; | |
154 | #define STATE_MODEL_NAME(sd) ((sd)->model_name) | |
155 | ||
e8f20a28 MF |
156 | /* In standalone simulator, this is the program to run. Not to be confused |
157 | with argv which are the strings passed to the program itself. */ | |
158 | char *prog_file; | |
159 | #define STATE_PROG_FILE(sd) ((sd)->prog_file) | |
160 | ||
c906108c SS |
161 | /* In standalone simulator, this is the program's arguments passed |
162 | on the command line. */ | |
163 | char **prog_argv; | |
f4fdd845 | 164 | #define STATE_PROG_ARGV(sd) ((sd)->prog_argv) |
c906108c | 165 | |
852016f9 MF |
166 | /* Thie is the program's argv[0] override. */ |
167 | char *prog_argv0; | |
168 | #define STATE_PROG_ARGV0(sd) ((sd)->prog_argv0) | |
169 | ||
54f7a83a MF |
170 | /* The program's environment. */ |
171 | char **prog_envp; | |
172 | #define STATE_PROG_ENVP(sd) ((sd)->prog_envp) | |
173 | ||
c906108c | 174 | /* The program's bfd. */ |
6b4a8935 | 175 | struct bfd *prog_bfd; |
f4fdd845 | 176 | #define STATE_PROG_BFD(sd) ((sd)->prog_bfd) |
c906108c SS |
177 | |
178 | /* Symbol table for prog_bfd */ | |
fc0a2244 | 179 | struct bfd_symbol **prog_syms; |
f4fdd845 | 180 | #define STATE_PROG_SYMS(sd) ((sd)->prog_syms) |
c906108c | 181 | |
5357150c MF |
182 | /* Number of prog_syms symbols. */ |
183 | long prog_syms_count; | |
f4fdd845 | 184 | #define STATE_PROG_SYMS_COUNT(sd) ((sd)->prog_syms_count) |
5357150c | 185 | |
c906108c | 186 | /* The program's text section. */ |
198beae2 | 187 | struct bfd_section *text_section; |
c906108c | 188 | /* Starting and ending text section addresses from the bfd. */ |
7e129781 | 189 | bfd_vma text_start, text_end; |
f4fdd845 MF |
190 | #define STATE_TEXT_SECTION(sd) ((sd)->text_section) |
191 | #define STATE_TEXT_START(sd) ((sd)->text_start) | |
192 | #define STATE_TEXT_END(sd) ((sd)->text_end) | |
c906108c SS |
193 | |
194 | /* Start address, set when the program is loaded from the bfd. */ | |
7e129781 | 195 | bfd_vma start_addr; |
f4fdd845 | 196 | #define STATE_START_ADDR(sd) ((sd)->start_addr) |
c906108c SS |
197 | |
198 | /* Size of the simulator's cache, if any. | |
199 | This is not the target's cache. It is the cache the simulator uses | |
200 | to process instructions. */ | |
201 | unsigned int scache_size; | |
f4fdd845 | 202 | #define STATE_SCACHE_SIZE(sd) ((sd)->scache_size) |
c906108c | 203 | |
c906108c | 204 | /* core memory bus */ |
f4fdd845 | 205 | #define STATE_CORE(sd) (&(sd)->core) |
c906108c SS |
206 | sim_core core; |
207 | ||
208 | /* Record of memory sections added via the memory-options interface. */ | |
f4fdd845 | 209 | #define STATE_MEMOPT(sd) ((sd)->memopt) |
c906108c SS |
210 | sim_memopt *memopt; |
211 | ||
212 | /* event handler */ | |
f4fdd845 | 213 | #define STATE_EVENTS(sd) (&(sd)->events) |
c906108c SS |
214 | sim_events events; |
215 | ||
216 | /* generic halt/resume engine */ | |
217 | sim_engine engine; | |
f4fdd845 | 218 | #define STATE_ENGINE(sd) (&(sd)->engine) |
c906108c SS |
219 | |
220 | /* generic watchpoint support */ | |
221 | sim_watchpoints watchpoints; | |
f4fdd845 | 222 | #define STATE_WATCHPOINTS(sd) (&(sd)->watchpoints) |
c906108c | 223 | |
c906108c SS |
224 | #if WITH_HW |
225 | struct sim_hw *hw; | |
f4fdd845 | 226 | #define STATE_HW(sd) ((sd)->hw) |
c906108c SS |
227 | #endif |
228 | ||
43e526b9 JM |
229 | /* Should image loads be performed using the LMA or VMA? Older |
230 | simulators use the VMA while newer simulators prefer the LMA. */ | |
231 | int load_at_lma_p; | |
f4fdd845 | 232 | #define STATE_LOAD_AT_LMA_P(SD) ((SD)->load_at_lma_p) |
383861bd MF |
233 | |
234 | /* Pointer for sim target to store arbitrary state data. Normally the | |
235 | target should define a struct and use it here. */ | |
236 | void *arch_data; | |
237 | #define STATE_ARCH_DATA(sd) ((sd)->arch_data) | |
e106fc35 | 238 | |
f4fdd845 MF |
239 | /* Marker for those wanting to do sanity checks. |
240 | This should remain the last member of this struct to help catch | |
241 | miscompilation errors. */ | |
242 | int magic; | |
243 | #define SIM_MAGIC_NUMBER 0x4242 | |
244 | #define STATE_MAGIC(sd) ((sd)->magic) | |
383861bd | 245 | }; |
383861bd | 246 | |
c906108c | 247 | /* Functions for allocating/freeing a sim_state. */ |
383861bd MF |
248 | SIM_DESC sim_state_alloc_extra (SIM_OPEN_KIND kind, host_callback *callback, |
249 | size_t extra_bytes); | |
250 | #define sim_state_alloc(kind, callback) sim_state_alloc_extra(kind, callback, 0) | |
251 | ||
bdca5ee4 | 252 | void sim_state_free (SIM_DESC); |
c906108c | 253 | |
444b3fae ПК |
254 | #ifdef __cplusplus |
255 | } | |
256 | #endif | |
257 | ||
c906108c | 258 | #endif /* SIM_BASE_H */ |