3123c07e2b2cdb30e9aca923238d8b4556b0df5d
[deliverable/binutils-gdb.git] / sim / common / sim-base.h
1 /* Simulator pseudo baseclass.
2
3 Copyright 1997-2019 Free Software Foundation, Inc.
4
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
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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
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/>. */
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"
31 /-* If `sim_cia' is not an integral value (e.g. a struct), define
32 CIA_ADDR to return the integral value. *-/
33 /-* typedef struct {...} sim_cia; *-/
34 /-* #define CIA_ADDR(cia) (...) *-/
35 #include "sim-base.h"
36
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
45 struct sim_state {
46 sim_cpu *cpu[MAX_NR_PROCESSORS];
47 ... simulator specific members ...
48 sim_state_base base;
49 };
50
51 Note that `base' appears last. This makes `base.magic' appear last
52 in the entire struct and helps catch miscompilation errors. */
53
54
55 #ifndef SIM_BASE_H
56 #define SIM_BASE_H
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
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 typedef address_word sim_cia;
74 #endif
75 #ifndef INVALID_INSTRUCTION_ADDRESS
76 #define INVALID_INSTRUCTION_ADDRESS ((address_word)0 - 1)
77 #endif
78
79 /* TODO: Probably should just delete SIM_CPU. */
80 typedef struct _sim_cpu SIM_CPU;
81 typedef struct _sim_cpu sim_cpu;
82
83 #include "sim-module.h"
84
85 #include "sim-trace.h"
86 #include "sim-core.h"
87 #include "sim-events.h"
88 #include "sim-profile.h"
89 #include "sim-model.h"
90 #include "sim-io.h"
91 #include "sim-engine.h"
92 #include "sim-watch.h"
93 #include "sim-memopt.h"
94 #include "sim-cpu.h"
95
96
97 /* We require all sims to dynamically allocate cpus. See comment up top about
98 struct sim_state. */
99 #if (WITH_SMP)
100 # define STATE_CPU(sd, n) ((sd)->cpu[n])
101 #else
102 # define STATE_CPU(sd, n) ((sd)->cpu[0])
103 #endif
104
105
106 typedef struct {
107
108 /* Simulator's argv[0]. */
109 const char *my_name;
110 #define STATE_MY_NAME(sd) ((sd)->base.my_name)
111
112 /* Who opened the simulator. */
113 SIM_OPEN_KIND open_kind;
114 #define STATE_OPEN_KIND(sd) ((sd)->base.open_kind)
115
116 /* The host callbacks. */
117 struct host_callback_struct *callback;
118 #define STATE_CALLBACK(sd) ((sd)->base.callback)
119
120 /* The type of simulation environment (user/operating). */
121 enum sim_environment environment;
122 #define STATE_ENVIRONMENT(sd) ((sd)->base.environment)
123
124 #if 0 /* FIXME: Not ready yet. */
125 /* Stuff defined in sim-config.h. */
126 struct sim_config config;
127 #define STATE_CONFIG(sd) ((sd)->base.config)
128 #endif
129
130 /* List of installed module `init' handlers. */
131 struct module_list *modules;
132 #define STATE_MODULES(sd) ((sd)->base.modules)
133
134 /* Supported options. */
135 struct option_list *options;
136 #define STATE_OPTIONS(sd) ((sd)->base.options)
137
138 /* Non-zero if -v specified. */
139 int verbose_p;
140 #define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p)
141
142 /* Non cpu-specific trace data. See sim-trace.h. */
143 TRACE_DATA trace_data;
144 #define STATE_TRACE_DATA(sd) (& (sd)->base.trace_data)
145
146 /* If non NULL, the BFD architecture specified on the command line */
147 const struct bfd_arch_info *architecture;
148 #define STATE_ARCHITECTURE(sd) ((sd)->base.architecture)
149
150 /* If non NULL, the bfd target specified on the command line */
151 const char *target;
152 #define STATE_TARGET(sd) ((sd)->base.target)
153
154 /* In standalone simulator, this is the program's arguments passed
155 on the command line. */
156 char **prog_argv;
157 #define STATE_PROG_ARGV(sd) ((sd)->base.prog_argv)
158
159 /* The program's bfd. */
160 struct bfd *prog_bfd;
161 #define STATE_PROG_BFD(sd) ((sd)->base.prog_bfd)
162
163 /* Symbol table for prog_bfd */
164 struct bfd_symbol **prog_syms;
165 #define STATE_PROG_SYMS(sd) ((sd)->base.prog_syms)
166
167 /* Number of prog_syms symbols. */
168 long prog_syms_count;
169 #define STATE_PROG_SYMS_COUNT(sd) ((sd)->base.prog_syms_count)
170
171 /* The program's text section. */
172 struct bfd_section *text_section;
173 /* Starting and ending text section addresses from the bfd. */
174 bfd_vma text_start, text_end;
175 #define STATE_TEXT_SECTION(sd) ((sd)->base.text_section)
176 #define STATE_TEXT_START(sd) ((sd)->base.text_start)
177 #define STATE_TEXT_END(sd) ((sd)->base.text_end)
178
179 /* Start address, set when the program is loaded from the bfd. */
180 bfd_vma start_addr;
181 #define STATE_START_ADDR(sd) ((sd)->base.start_addr)
182
183 /* Size of the simulator's cache, if any.
184 This is not the target's cache. It is the cache the simulator uses
185 to process instructions. */
186 unsigned int scache_size;
187 #define STATE_SCACHE_SIZE(sd) ((sd)->base.scache_size)
188
189 /* core memory bus */
190 #define STATE_CORE(sd) (&(sd)->base.core)
191 sim_core core;
192
193 /* Record of memory sections added via the memory-options interface. */
194 #define STATE_MEMOPT(sd) ((sd)->base.memopt)
195 sim_memopt *memopt;
196
197 /* event handler */
198 #define STATE_EVENTS(sd) (&(sd)->base.events)
199 sim_events events;
200
201 /* generic halt/resume engine */
202 sim_engine engine;
203 #define STATE_ENGINE(sd) (&(sd)->base.engine)
204
205 /* generic watchpoint support */
206 sim_watchpoints watchpoints;
207 #define STATE_WATCHPOINTS(sd) (&(sd)->base.watchpoints)
208
209 #if WITH_HW
210 struct sim_hw *hw;
211 #define STATE_HW(sd) ((sd)->base.hw)
212 #endif
213
214 /* Should image loads be performed using the LMA or VMA? Older
215 simulators use the VMA while newer simulators prefer the LMA. */
216 int load_at_lma_p;
217 #define STATE_LOAD_AT_LMA_P(SD) ((SD)->base.load_at_lma_p)
218
219 /* Marker for those wanting to do sanity checks.
220 This should remain the last member of this struct to help catch
221 miscompilation errors. */
222 int magic;
223 #define SIM_MAGIC_NUMBER 0x4242
224 #define STATE_MAGIC(sd) ((sd)->base.magic)
225 } sim_state_base;
226
227 /* Functions for allocating/freeing a sim_state. */
228 SIM_DESC sim_state_alloc (SIM_OPEN_KIND kind, host_callback *callback);
229 void sim_state_free (SIM_DESC);
230
231 #ifdef __cplusplus
232 }
233 #endif
234
235 #endif /* SIM_BASE_H */
This page took 0.033972 seconds and 4 git commands to generate.