* Make-common.in (sim-options.o, sim-load.o): Add rules for.
[deliverable/binutils-gdb.git] / sim / common / sim-base.h
CommitLineData
e77fd269
DE
1/* Simulator pseudo baseclass.
2 Copyright (C) 1997 Free Software Foundation, Inc.
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
21/* This file is meant to be included by sim-basics.h. */
22
23#ifndef SIM_BASE_H
24#define SIM_BASE_H
25
26/* Global pointer to current state while sim_resume is running.
27 On a machine with lots of registers, it might be possible to reserve
28 one of them for current_state. However on a machine with few registers
29 current_state can't permanently live in one and indirecting through it
30 will be slower [in which case one can have sim_resume set globals from
31 current_state for faster access].
32 If CURRENT_STATE_REG is defined, it means current_state is living in
33 a global register. */
34
35#ifdef CURRENT_STATE_REG
36/* FIXME: wip */
37#else
38extern struct sim_state *current_state;
39#endif
40
0f2811d1
DE
41/* The simulator may provide different (and faster) definition. */
42#ifndef CURRENT_STATE
43#define CURRENT_STATE current_state
44#endif
45
46/* Simulator state pseudo baseclass.
e77fd269
DE
47 Each simulator is required to have a sim-main.h file that includes
48 sim-basics.h and defines struct sim_state to be:
49
50 struct sim_state {
0f2811d1
DE
51 sim_cpu cpu;
52 #define STATE_CPU(sd,n) (&(sd)->cpu)
e77fd269 53 ... simulator specific members ...
0f2811d1 54 sim_state_base base;
e77fd269 55 };
e77fd269 56
0f2811d1
DE
57 for a single processor or
58
59 struct sim_state {
60 sim_cpu cpu[MAX_CPUS]; -- could be also be array of pointers
61 #define STATE_CPU(sd,n) (&(sd)->cpu[n])
62 ... simulator specific members ...
63 sim_state_base base;
64 };
65
66 for multiprocessors.
67 Note that `base' appears last. This makes `base.magic' appear last
68 in the entire struct and helps catch miscompilation errors.
69
70 sim_cpu is defined to be:
e77fd269 71
0f2811d1
DE
72 typedef struct {
73 ... simulator specific members ...
74 sim_cpu_base base;
75 } sim_cpu;
76 */
77
78typedef struct {
e77fd269
DE
79 /* Simulator's argv[0]. */
80 const char *my_name;
81#define STATE_MY_NAME(sd) ((sd)->base.my_name)
82
83 /* Who opened the simulator. */
84 SIM_OPEN_KIND open_kind;
85#define STATE_OPEN_KIND(sd) ((sd)->base.open_kind)
86
87 /* The host callbacks. */
88 struct host_callback_struct *callback;
89#define STATE_CALLBACK(sd) ((sd)->base.callback)
90
91#if 0 /* FIXME: Not ready yet. */
92 /* Stuff defined in sim-config.h. */
93 struct sim_config config;
94#define STATE_CONFIG(sd) ((sd)->base.config)
95#endif
0f2811d1
DE
96
97 /* Supported options. */
98 struct option_list *options;
99#define STATE_OPTIONS(sd) ((sd)->base.options)
100
101 /* Non-zero if -v specified. */
102 int verbose_p;
103#define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p)
104
105 /* In standalone simulator, this is the program's arguments passed
106 on the command line. */
107 char **prog_argv;
108#define STATE_PROG_ARGV(sd) ((sd)->base.prog_argv)
109
110 /* The program's bfd. */
111 struct _bfd *prog_bfd;
112#define STATE_PROG_BFD(sd) ((sd)->base.prog_bfd)
113
114 /* The program's text section. */
115 struct sec *text_section;
116 /* Starting and ending text section addresses from the bfd. */
117 SIM_ADDR text_start, text_end;
118#define STATE_TEXT_SECTION(sd) ((sd)->base.text_section)
119#define STATE_TEXT_START(sd) ((sd)->base.text_start)
120#define STATE_TEXT_END(sd) ((sd)->base.text_end)
121
122 /* Start address, set when the program is loaded from the bfd. */
123 SIM_ADDR start_addr;
124#define STATE_START_ADDR(sd) ((sd)->base.start_addr)
125
126 /* Size of the simulator's cache, if any.
127 This is not the target's cache. It is the cache the simulator uses
128 to process instructions. */
129 unsigned int simcache_size;
130#define STATE_SIMCACHE_SIZE(sd) ((sd)->base.simcache_size)
131
132 /* FIXME: Move to top level sim_state struct (as some struct)? */
133#ifdef SIM_HAVE_FLATMEM
134 unsigned int mem_size;
135#define STATE_MEM_SIZE(sd) ((sd)->base.mem_size)
136 unsigned char *memory;
137#define STATE_MEMORY(sd) ((sd)->base.memory)
138#endif
139
140 /* Marker for those wanting to do sanity checks.
141 This should remain the last member of this struct to help catch
142 miscompilation errors. */
143 int magic;
144#define SIM_MAGIC_NUMBER 0x4242
145#define STATE_MAGIC(sd) ((sd)->base.magic)
146} sim_state_base;
147
148/* Pseudo baseclass for each cpu. */
149
150typedef struct {
151 /* Backlink to main state struct. */
152 SIM_DESC sd;
153
154 /* Maximum number of traceable entities. */
155#ifndef MAX_TRACE_VALUES
156#define MAX_TRACE_VALUES 12
157#endif
158
159 /* Boolean array of specified tracing flags. */
160 /* ??? It's not clear that using an array vs a bit mask is faster.
161 Consider the case where one wants to test whether any of several bits
162 are set. */
163 char trace_flags[MAX_TRACE_VALUES];
164#define CPU_TRACE_FLAGS(cpu) ((cpu)->base.trace_flags)
165 /* Standard values. */
166#define TRACE_INSN_IDX 0
167#define TRACE_DECODE_IDX 1
168#define TRACE_EXTRACT_IDX 2
169#define TRACE_LINENUM_IDX 3
170#define TRACE_MEMORY_IDX 4
171#define TRACE_MODEL_IDX 5
172#define TRACE_ALU_IDX 6
173#define TRACE_NEXT_IDX 8 /* simulator specific trace bits begin here */
174
175 /* Tracing output goes to this or stdout if NULL.
176 We can't store `stdout' here as stdout goes through a callback. */
177 FILE *trace_file;
178
179 /* Maximum number of debuggable entities.
180 This debugging is not intended for normal use.
181 It is only enabled when the simulator is configured with --with-debug
182 which shouldn't normally be specified. */
183#ifndef MAX_DEBUG_VALUES
184#define MAX_DEBUG_VALUES 4
185#endif
186
187 /* Boolean array of specified debugging flags. */
188 char debug_flags[MAX_DEBUG_VALUES];
189#define CPU_DEBUG_FLAGS(cpu) ((cpu)->base.debug_flags)
190 /* Standard values. */
191#define DEBUG_INSN_IDX 0
192#define DEBUG_NEXT_IDX 2 /* simulator specific debug bits begin here */
193
194 /* Debugging output goes to this or stderr if NULL.
195 We can't store `stderr' here as stderr goes through a callback. */
196 FILE *debug_file;
197
198#ifdef SIM_HAVE_PROFILE
199 /* Maximum number of profilable entities. */
200#ifndef MAX_PROFILE_VALUES
201#define MAX_PROFILE_VALUES 8
202#endif
203
204 /* Boolean array of specified profiling flags. */
205 char profile_flags[MAX_PROFILE_VALUES];
206#define CPU_PROFILE_FLAGS(cpu) ((cpu)->base.profile_flags)
207 /* Standard masks. */
208#define PROFILE_INSN_MASK 0
209#define PROFILE_MEMORY_MASK 1
210#define PROFILE_MODEL_MASK 2
211#define PROFILE_SIMCACHE_MASK 3
212#define PROFILE_NEXT_MASK 6 /* simulator specific profile bits begin here */
213
214 /* PC profiling attempts to determine function usage by sampling the PC
215 every so many instructions. */
216#ifdef SIM_HAVE_PROFILE_PC
217 unsigned int profile_pc_freq;
218#define STATE_PROFILE_PC_FREQ(sd) ((sd)->base.profile_pc_freq)
219 unsigned int profile_pc_size;
220#define STATE_PROFILE_PC_SIZE(sd) ((sd)->base.profile_pc_size)
221#endif
222
223 /* Profile output goes to this or stdout if NULL.
224 We can't store `stderr' here as stdout goes through a callback. */
225 FILE *profile_file;
226#endif /* SIM_HAVE_PROFILE */
227} sim_cpu_base;
e77fd269
DE
228
229/* Functions for allocating/freeing a sim_state. */
230SIM_DESC sim_state_alloc PARAMS ((void));
231void sim_state_free PARAMS ((SIM_DESC));
232
233#endif /* SIM_BASE_H */
This page took 0.031831 seconds and 4 git commands to generate.