]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/sim-base.h
1 /* Simulator pseudo baseclass.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file is meant to be included by sim-basics.h. */
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
35 #ifdef CURRENT_STATE_REG
38 extern struct sim_state
*current_state
;
41 /* The simulator may provide different (and faster) definition. */
43 #define CURRENT_STATE current_state
46 /* Simulator state pseudo baseclass.
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:
52 #define STATE_CPU(sd,n) (&(sd)->cpu)
53 ... simulator specific members ...
57 for a single processor or
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 ...
67 Note that `base' appears last. This makes `base.magic' appear last
68 in the entire struct and helps catch miscompilation errors.
70 sim_cpu is defined to be:
73 ... simulator specific members ...
79 /* Simulator's argv[0]. */
81 #define STATE_MY_NAME(sd) ((sd)->base.my_name)
83 /* Who opened the simulator. */
84 SIM_OPEN_KIND open_kind
;
85 #define STATE_OPEN_KIND(sd) ((sd)->base.open_kind)
87 /* The host callbacks. */
88 struct host_callback_struct
*callback
;
89 #define STATE_CALLBACK(sd) ((sd)->base.callback)
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)
97 /* Supported options. */
98 struct option_list
*options
;
99 #define STATE_OPTIONS(sd) ((sd)->base.options)
101 /* Non-zero if -v specified. */
103 #define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p)
105 /* In standalone simulator, this is the program's arguments passed
106 on the command line. */
108 #define STATE_PROG_ARGV(sd) ((sd)->base.prog_argv)
110 /* The program's bfd. */
111 struct _bfd
*prog_bfd
;
112 #define STATE_PROG_BFD(sd) ((sd)->base.prog_bfd)
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)
122 /* Start address, set when the program is loaded from the bfd. */
124 #define STATE_START_ADDR(sd) ((sd)->base.start_addr)
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)
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)
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. */
144 #define SIM_MAGIC_NUMBER 0x4242
145 #define STATE_MAGIC(sd) ((sd)->base.magic)
148 /* Pseudo baseclass for each cpu. */
151 /* Backlink to main state struct. */
154 /* Maximum number of traceable entities. */
155 #ifndef MAX_TRACE_VALUES
156 #define MAX_TRACE_VALUES 12
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
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 */
175 /* Tracing output goes to this or stdout if NULL.
176 We can't store `stdout' here as stdout goes through a callback. */
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
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 */
194 /* Debugging output goes to this or stderr if NULL.
195 We can't store `stderr' here as stderr goes through a callback. */
198 #ifdef SIM_HAVE_PROFILE
199 /* Maximum number of profilable entities. */
200 #ifndef MAX_PROFILE_VALUES
201 #define MAX_PROFILE_VALUES 8
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 */
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)
223 /* Profile output goes to this or stdout if NULL.
224 We can't store `stderr' here as stdout goes through a callback. */
226 #endif /* SIM_HAVE_PROFILE */
229 /* Functions for allocating/freeing a sim_state. */
230 SIM_DESC sim_state_alloc
PARAMS ((void));
231 void sim_state_free
PARAMS ((SIM_DESC
));
233 #endif /* SIM_BASE_H */