This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / sim / common / sim-base.h
CommitLineData
e77fd269 1/* Simulator pseudo baseclass.
82ea14fd 2 Copyright (C) 1997-1998 Free Software Foundation, Inc.
e77fd269
DE
3 Contributed by Cygnus Support.
4
5This file is part of GDB, the GNU debugger.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License along
18with this program; if not, write to the Free Software Foundation, Inc.,
1959 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
e6a43446
DE
21
22/* Simulator state pseudo baseclass.
23
4b2a6aed
AC
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'':
e6a43446
DE
28
29 #include "sim-basics.h"
30 typedef address_word sim_cia;
966df580
DE
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) (...) *-/
e6a43446
DE
34 #include "sim-base.h"
35
966df580 36 finally, two data types `struct _sim_cpu' and `struct sim_state'
4b2a6aed 37 are defined:
e6a43446
DE
38
39 struct _sim_cpu {
40 ... simulator specific members ...
41 sim_cpu_base base;
42 };
43
e6a43446
DE
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
e77fd269
DE
58
59#ifndef SIM_BASE_H
60#define SIM_BASE_H
61
e6a43446
DE
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
e5ce1670
DE
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
4b2a6aed
AC
74#ifndef INVALID_INSTRUCTION_ADDRESS
75#define INVALID_INSTRUCTION_ADDRESS ((address_word)0 - 1)
76#endif
e5ce1670 77
e6a43446
DE
78typedef struct _sim_cpu sim_cpu;
79
80#include "sim-module.h"
18c319ae 81
e6a43446 82#include "sim-trace.h"
e6a43446
DE
83#include "sim-core.h"
84#include "sim-events.h"
4ca7d6d2
AC
85#include "sim-profile.h"
86#ifdef SIM_HAVE_MODEL
87#include "sim-model.h"
88#endif
e6a43446 89#include "sim-io.h"
18c319ae
AC
90#include "sim-engine.h"
91#include "sim-watch.h"
a34abff8 92#include "sim-memopt.h"
e5ce1670
DE
93#ifdef SIM_HAVE_BREAKPOINTS
94#include "sim-break.h"
95#endif
e6a43446 96
e77fd269
DE
97/* Global pointer to current state while sim_resume is running.
98 On a machine with lots of registers, it might be possible to reserve
99 one of them for current_state. However on a machine with few registers
100 current_state can't permanently live in one and indirecting through it
101 will be slower [in which case one can have sim_resume set globals from
102 current_state for faster access].
103 If CURRENT_STATE_REG is defined, it means current_state is living in
104 a global register. */
105
e6a43446 106
e77fd269
DE
107#ifdef CURRENT_STATE_REG
108/* FIXME: wip */
109#else
110extern struct sim_state *current_state;
111#endif
112
e6a43446 113
0f2811d1
DE
114/* The simulator may provide different (and faster) definition. */
115#ifndef CURRENT_STATE
116#define CURRENT_STATE current_state
117#endif
118
0f2811d1
DE
119
120typedef struct {
e6a43446 121
e77fd269
DE
122 /* Simulator's argv[0]. */
123 const char *my_name;
124#define STATE_MY_NAME(sd) ((sd)->base.my_name)
125
126 /* Who opened the simulator. */
127 SIM_OPEN_KIND open_kind;
128#define STATE_OPEN_KIND(sd) ((sd)->base.open_kind)
129
130 /* The host callbacks. */
131 struct host_callback_struct *callback;
132#define STATE_CALLBACK(sd) ((sd)->base.callback)
133
bda9d8a3
DE
134 /* The type of simulation environment (user/operating). */
135 enum sim_environment environment;
136#define STATE_ENVIRONMENT(sd) ((sd)->base.environment)
137
e77fd269
DE
138#if 0 /* FIXME: Not ready yet. */
139 /* Stuff defined in sim-config.h. */
140 struct sim_config config;
141#define STATE_CONFIG(sd) ((sd)->base.config)
142#endif
0f2811d1 143
c967f187 144 /* List of installed module `init' handlers. */
0e701ac3
AC
145 struct module_list *modules;
146#define STATE_MODULES(sd) ((sd)->base.modules)
c967f187 147
0f2811d1
DE
148 /* Supported options. */
149 struct option_list *options;
150#define STATE_OPTIONS(sd) ((sd)->base.options)
151
152 /* Non-zero if -v specified. */
153 int verbose_p;
154#define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p)
155
e5ce1670
DE
156 /* Non cpu-specific trace data. See sim-trace.h. */
157 TRACE_DATA trace_data;
158#define STATE_TRACE_DATA(sd) (& (sd)->base.trace_data)
159
18c319ae
AC
160 /* If non NULL, the BFD architecture specified on the command line */
161 const struct bfd_arch_info *architecture;
162#define STATE_ARCHITECTURE(sd) ((sd)->base.architecture)
163
164 /* If non NULL, the bfd target specified on the command line */
165 const char *target;
166#define STATE_TARGET(sd) ((sd)->base.target)
167
0f2811d1
DE
168 /* In standalone simulator, this is the program's arguments passed
169 on the command line. */
170 char **prog_argv;
171#define STATE_PROG_ARGV(sd) ((sd)->base.prog_argv)
172
173 /* The program's bfd. */
174 struct _bfd *prog_bfd;
175#define STATE_PROG_BFD(sd) ((sd)->base.prog_bfd)
176
82ea14fd
AC
177 /* Symbol table for prog_bfd */
178 struct symbol_cache_entry **prog_syms;
179#define STATE_PROG_SYMS(sd) ((sd)->base.prog_syms)
180
0f2811d1
DE
181 /* The program's text section. */
182 struct sec *text_section;
183 /* Starting and ending text section addresses from the bfd. */
184 SIM_ADDR text_start, text_end;
185#define STATE_TEXT_SECTION(sd) ((sd)->base.text_section)
186#define STATE_TEXT_START(sd) ((sd)->base.text_start)
187#define STATE_TEXT_END(sd) ((sd)->base.text_end)
188
189 /* Start address, set when the program is loaded from the bfd. */
190 SIM_ADDR start_addr;
191#define STATE_START_ADDR(sd) ((sd)->base.start_addr)
192
193 /* Size of the simulator's cache, if any.
194 This is not the target's cache. It is the cache the simulator uses
195 to process instructions. */
c967f187
DE
196 unsigned int scache_size;
197#define STATE_SCACHE_SIZE(sd) ((sd)->base.scache_size)
0f2811d1
DE
198
199 /* FIXME: Move to top level sim_state struct (as some struct)? */
200#ifdef SIM_HAVE_FLATMEM
201 unsigned int mem_size;
202#define STATE_MEM_SIZE(sd) ((sd)->base.mem_size)
18c319ae
AC
203 unsigned int mem_base;
204#define STATE_MEM_BASE(sd) ((sd)->base.mem_base)
0f2811d1
DE
205 unsigned char *memory;
206#define STATE_MEMORY(sd) ((sd)->base.memory)
207#endif
208
e6a43446
DE
209 /* core memory bus */
210#define STATE_CORE(sd) (&(sd)->base.core)
211 sim_core core;
212
b9bcce67 213 /* Record of memory sections added via the memory-options interface. */
a34abff8 214#define STATE_MEMOPT(sd) ((sd)->base.memopt)
a34abff8
AC
215 sim_memopt *memopt;
216
bd3aa7cb
JL
217/* start-sanitize-sky */
218#ifdef TARGET_SKY
219#ifdef SKY_FUNIT
220 /* Record of option for floating point implementation type. */
221#define STATE_FP_TYPE_OPT(sd) ((sd)->base.fp_type_opt)
222#define STATE_FP_TYPE_OPT_TARGET 0x80000000
223 int fp_type_opt;
224#endif
225#endif
226/* end-sanitize-sky */
227
e6a43446
DE
228 /* event handler */
229#define STATE_EVENTS(sd) (&(sd)->base.events)
230 sim_events events;
231
18c319ae
AC
232 /* generic halt/resume engine */
233 sim_engine engine;
234#define STATE_ENGINE(sd) (&(sd)->base.engine)
235
236 /* generic watchpoint support */
237 sim_watchpoints watchpoints;
238#define STATE_WATCHPOINTS(sd) (&(sd)->base.watchpoints)
239
e5ce1670
DE
240 /* Pointer to list of breakpoints */
241 struct sim_breakpoint *breakpoints;
242#define STATE_BREAKPOINTS(sd) ((sd)->base.breakpoints)
243
d8f53049
AC
244 /* start-sanitize-am30 */
245#if WITH_HW
246 struct sim_hw *hw;
247#define STATE_HW(sd) ((sd)->base.hw)
248#endif
249
250 /* end-sanitize-am30 */
0f2811d1
DE
251 /* Marker for those wanting to do sanity checks.
252 This should remain the last member of this struct to help catch
253 miscompilation errors. */
254 int magic;
255#define SIM_MAGIC_NUMBER 0x4242
256#define STATE_MAGIC(sd) ((sd)->base.magic)
257} sim_state_base;
258
e6a43446 259
0f2811d1
DE
260/* Pseudo baseclass for each cpu. */
261
262typedef struct {
e6a43446 263
0f2811d1 264 /* Backlink to main state struct. */
c967f187
DE
265 SIM_DESC state;
266#define CPU_STATE(cpu) ((cpu)->base.state)
0f2811d1 267
82ea14fd
AC
268 /* Processor index within the SD_DESC */
269 int index;
270#define CPU_INDEX(cpu) ((cpu)->base.index)
271
966df580
DE
272 /* The name of the cpu. */
273 const char *name;
274#define CPU_NAME(cpu) ((cpu)->base.name)
275
276 /* Options specific to this cpu. */
277 struct option_list *options;
278#define CPU_OPTIONS(cpu) ((cpu)->base.options)
279
7a418800 280 /* Processor specific core data */
7a418800 281 sim_cpu_core core;
18c319ae 282#define CPU_CORE(cpu) (& (cpu)->base.core)
7a418800 283
c967f187
DE
284 /* Trace data. See sim-trace.h. */
285 TRACE_DATA trace_data;
286#define CPU_TRACE_DATA(cpu) (& (cpu)->base.trace_data)
0f2811d1
DE
287
288 /* Maximum number of debuggable entities.
289 This debugging is not intended for normal use.
290 It is only enabled when the simulator is configured with --with-debug
291 which shouldn't normally be specified. */
292#ifndef MAX_DEBUG_VALUES
293#define MAX_DEBUG_VALUES 4
294#endif
295
296 /* Boolean array of specified debugging flags. */
297 char debug_flags[MAX_DEBUG_VALUES];
298#define CPU_DEBUG_FLAGS(cpu) ((cpu)->base.debug_flags)
299 /* Standard values. */
300#define DEBUG_INSN_IDX 0
301#define DEBUG_NEXT_IDX 2 /* simulator specific debug bits begin here */
302
303 /* Debugging output goes to this or stderr if NULL.
304 We can't store `stderr' here as stderr goes through a callback. */
305 FILE *debug_file;
5bfbd725 306#define CPU_DEBUG_FILE(cpu) ((cpu)->base.debug_file)
0f2811d1 307
c967f187
DE
308 /* Profile data. See sim-profile.h. */
309 PROFILE_DATA profile_data;
310#define CPU_PROFILE_DATA(cpu) (& (cpu)->base.profile_data)
e6a43446 311
966df580
DE
312#ifdef SIM_HAVE_MODEL
313 /* Machine tables for this cpu. See sim-model.h. */
314 const MACH *mach;
315#define CPU_MACH(cpu) ((cpu)->base.mach)
316 /* The selected model. */
317 const MODEL *model;
318#define CPU_MODEL(cpu) ((cpu)->base.model)
319#endif
320
0f2811d1 321} sim_cpu_base;
e77fd269 322
e6a43446 323
e77fd269 324/* Functions for allocating/freeing a sim_state. */
4b2a6aed 325SIM_DESC sim_state_alloc PARAMS ((SIM_OPEN_KIND kind, host_callback *callback));
e77fd269
DE
326void sim_state_free PARAMS ((SIM_DESC));
327
966df580
DE
328/* Return a pointer to the cpu data for CPU_NAME, or NULL if not found. */
329sim_cpu *sim_cpu_lookup (SIM_DESC sd, const char *cpu_name);
330
e6a43446 331
e77fd269 332#endif /* SIM_BASE_H */
This page took 0.100459 seconds and 4 git commands to generate.