]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-base.h
sim: invert sim_state storage
[thirdparty/binutils-gdb.git] / sim / common / sim-base.h
CommitLineData
c906108c 1/* Simulator pseudo baseclass.
836cc9f4 2
3666a048 3 Copyright 1997-2021 Free Software Foundation, Inc.
836cc9f4 4
c906108c
SS
5 Contributed by Cygnus Support.
6
7This file is part of GDB, the GNU debugger.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
4744ac1b
JB
11the Free Software Foundation; either version 3 of the License, or
12(at your option) any later version.
c906108c
SS
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
4744ac1b
JB
19You should have received a copy of the GNU General Public License
20along 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
52extern "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 66typedef 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. */
73typedef struct _sim_cpu SIM_CPU;
c906108c
SS
74typedef struct _sim_cpu sim_cpu;
75
76#include "sim-module.h"
77
ef986697 78#include "sim-arange.h"
c906108c
SS
79#include "sim-trace.h"
80#include "sim-core.h"
81#include "sim-events.h"
82#include "sim-profile.h"
c906108c 83#include "sim-model.h"
c906108c
SS
84#include "sim-io.h"
85#include "sim-engine.h"
86#include "sim-watch.h"
87#include "sim-memopt.h"
c906108c 88#include "sim-cpu.h"
d3fe0d7b 89#include "sim-assert.h"
c906108c 90
c906108c 91
78e9aa70
MF
92/* We require all sims to dynamically allocate cpus. See comment up top about
93 struct sim_state. */
94#if (WITH_SMP)
95# define STATE_CPU(sd, n) ((sd)->cpu[n])
96#else
97# define STATE_CPU(sd, n) ((sd)->cpu[0])
98#endif
99
100
c906108c
SS
101typedef struct {
102
103 /* Simulator's argv[0]. */
104 const char *my_name;
105#define STATE_MY_NAME(sd) ((sd)->base.my_name)
106
107 /* Who opened the simulator. */
108 SIM_OPEN_KIND open_kind;
109#define STATE_OPEN_KIND(sd) ((sd)->base.open_kind)
110
111 /* The host callbacks. */
112 struct host_callback_struct *callback;
113#define STATE_CALLBACK(sd) ((sd)->base.callback)
114
115 /* The type of simulation environment (user/operating). */
116 enum sim_environment environment;
117#define STATE_ENVIRONMENT(sd) ((sd)->base.environment)
118
119#if 0 /* FIXME: Not ready yet. */
120 /* Stuff defined in sim-config.h. */
121 struct sim_config config;
122#define STATE_CONFIG(sd) ((sd)->base.config)
123#endif
124
125 /* List of installed module `init' handlers. */
126 struct module_list *modules;
127#define STATE_MODULES(sd) ((sd)->base.modules)
128
129 /* Supported options. */
130 struct option_list *options;
131#define STATE_OPTIONS(sd) ((sd)->base.options)
132
133 /* Non-zero if -v specified. */
134 int verbose_p;
135#define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p)
136
137 /* Non cpu-specific trace data. See sim-trace.h. */
138 TRACE_DATA trace_data;
139#define STATE_TRACE_DATA(sd) (& (sd)->base.trace_data)
140
141 /* If non NULL, the BFD architecture specified on the command line */
142 const struct bfd_arch_info *architecture;
143#define STATE_ARCHITECTURE(sd) ((sd)->base.architecture)
144
145 /* If non NULL, the bfd target specified on the command line */
146 const char *target;
147#define STATE_TARGET(sd) ((sd)->base.target)
148
149 /* In standalone simulator, this is the program's arguments passed
150 on the command line. */
151 char **prog_argv;
152#define STATE_PROG_ARGV(sd) ((sd)->base.prog_argv)
153
154 /* The program's bfd. */
6b4a8935 155 struct bfd *prog_bfd;
c906108c
SS
156#define STATE_PROG_BFD(sd) ((sd)->base.prog_bfd)
157
158 /* Symbol table for prog_bfd */
fc0a2244 159 struct bfd_symbol **prog_syms;
c906108c
SS
160#define STATE_PROG_SYMS(sd) ((sd)->base.prog_syms)
161
5357150c
MF
162 /* Number of prog_syms symbols. */
163 long prog_syms_count;
164#define STATE_PROG_SYMS_COUNT(sd) ((sd)->base.prog_syms_count)
165
c906108c 166 /* The program's text section. */
198beae2 167 struct bfd_section *text_section;
c906108c 168 /* Starting and ending text section addresses from the bfd. */
7e129781 169 bfd_vma text_start, text_end;
c906108c
SS
170#define STATE_TEXT_SECTION(sd) ((sd)->base.text_section)
171#define STATE_TEXT_START(sd) ((sd)->base.text_start)
172#define STATE_TEXT_END(sd) ((sd)->base.text_end)
173
174 /* Start address, set when the program is loaded from the bfd. */
7e129781 175 bfd_vma start_addr;
c906108c
SS
176#define STATE_START_ADDR(sd) ((sd)->base.start_addr)
177
178 /* Size of the simulator's cache, if any.
179 This is not the target's cache. It is the cache the simulator uses
180 to process instructions. */
181 unsigned int scache_size;
182#define STATE_SCACHE_SIZE(sd) ((sd)->base.scache_size)
183
c906108c
SS
184 /* core memory bus */
185#define STATE_CORE(sd) (&(sd)->base.core)
186 sim_core core;
187
188 /* Record of memory sections added via the memory-options interface. */
189#define STATE_MEMOPT(sd) ((sd)->base.memopt)
190 sim_memopt *memopt;
191
192 /* event handler */
193#define STATE_EVENTS(sd) (&(sd)->base.events)
194 sim_events events;
195
196 /* generic halt/resume engine */
197 sim_engine engine;
198#define STATE_ENGINE(sd) (&(sd)->base.engine)
199
200 /* generic watchpoint support */
201 sim_watchpoints watchpoints;
202#define STATE_WATCHPOINTS(sd) (&(sd)->base.watchpoints)
203
c906108c
SS
204#if WITH_HW
205 struct sim_hw *hw;
206#define STATE_HW(sd) ((sd)->base.hw)
207#endif
208
43e526b9
JM
209 /* Should image loads be performed using the LMA or VMA? Older
210 simulators use the VMA while newer simulators prefer the LMA. */
211 int load_at_lma_p;
212#define STATE_LOAD_AT_LMA_P(SD) ((SD)->base.load_at_lma_p)
213
c906108c
SS
214 /* Marker for those wanting to do sanity checks.
215 This should remain the last member of this struct to help catch
216 miscompilation errors. */
217 int magic;
218#define SIM_MAGIC_NUMBER 0x4242
219#define STATE_MAGIC(sd) ((sd)->base.magic)
220} sim_state_base;
221
383861bd
MF
222#ifdef SIM_HAVE_COMMON_SIM_STATE
223/* TODO: Merge sim_state & sim_state_base. */
224struct sim_state {
225 /* All the cpus for this instance. */
226 sim_cpu *cpu[MAX_NR_PROCESSORS];
227
228 /* All the common state. */
229 sim_state_base base;
230
231 /* Pointer for sim target to store arbitrary state data. Normally the
232 target should define a struct and use it here. */
233 void *arch_data;
234#define STATE_ARCH_DATA(sd) ((sd)->arch_data)
235};
236#endif
237
c906108c 238/* Functions for allocating/freeing a sim_state. */
383861bd
MF
239SIM_DESC sim_state_alloc_extra (SIM_OPEN_KIND kind, host_callback *callback,
240 size_t extra_bytes);
241#define sim_state_alloc(kind, callback) sim_state_alloc_extra(kind, callback, 0)
242
bdca5ee4 243void sim_state_free (SIM_DESC);
c906108c 244
444b3fae
ПК
245#ifdef __cplusplus
246}
247#endif
248
c906108c 249#endif /* SIM_BASE_H */