8b1ac932acc9c3d077bc8586a53965445b5afd2f
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:
72 typedef struct _sim_cpu {
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. */
153 #define CPU_STATE(cpu) ((cpu)->base.sd)
155 /* Maximum number of traceable entities. */
156 #ifndef MAX_TRACE_VALUES
157 #define MAX_TRACE_VALUES 12
160 /* Boolean array of specified tracing flags. */
161 /* ??? It's not clear that using an array vs a bit mask is faster.
162 Consider the case where one wants to test whether any of several bits
164 char trace_flags
[MAX_TRACE_VALUES
];
165 #define CPU_TRACE_FLAGS(cpu) ((cpu)->base.trace_flags)
166 /* Standard values. */
167 #define TRACE_INSN_IDX 0
168 #define TRACE_DECODE_IDX 1
169 #define TRACE_EXTRACT_IDX 2
170 #define TRACE_LINENUM_IDX 3
171 #define TRACE_MEMORY_IDX 4
172 #define TRACE_MODEL_IDX 5
173 #define TRACE_ALU_IDX 6
174 #define TRACE_NEXT_IDX 8 /* simulator specific trace bits begin here */
176 /* Tracing output goes to this or stdout if NULL.
177 We can't store `stdout' here as stdout goes through a callback. */
179 #define CPU_TRACE_FILE(cpu) ((cpu)->base.trace_file)
181 /* Maximum number of debuggable entities.
182 This debugging is not intended for normal use.
183 It is only enabled when the simulator is configured with --with-debug
184 which shouldn't normally be specified. */
185 #ifndef MAX_DEBUG_VALUES
186 #define MAX_DEBUG_VALUES 4
189 /* Boolean array of specified debugging flags. */
190 char debug_flags
[MAX_DEBUG_VALUES
];
191 #define CPU_DEBUG_FLAGS(cpu) ((cpu)->base.debug_flags)
192 /* Standard values. */
193 #define DEBUG_INSN_IDX 0
194 #define DEBUG_NEXT_IDX 2 /* simulator specific debug bits begin here */
196 /* Debugging output goes to this or stderr if NULL.
197 We can't store `stderr' here as stderr goes through a callback. */
199 #define CPU_DEBUG_FILE(cpu) ((cpu)->base.debug_file)
201 #ifdef SIM_HAVE_PROFILE
202 /* Maximum number of profilable entities. */
203 #ifndef MAX_PROFILE_VALUES
204 #define MAX_PROFILE_VALUES 8
207 /* Boolean array of specified profiling flags. */
208 char profile_flags
[MAX_PROFILE_VALUES
];
209 #define CPU_PROFILE_FLAGS(cpu) ((cpu)->base.profile_flags)
210 /* Standard masks. */
211 #define PROFILE_INSN_MASK 0
212 #define PROFILE_MEMORY_MASK 1
213 #define PROFILE_MODEL_MASK 2
214 #define PROFILE_SIMCACHE_MASK 3
215 #define PROFILE_NEXT_MASK 6 /* simulator specific profile bits begin here */
217 /* PC profiling attempts to determine function usage by sampling the PC
218 every so many instructions. */
219 #ifdef SIM_HAVE_PROFILE_PC
220 unsigned int profile_pc_freq
;
221 #define STATE_PROFILE_PC_FREQ(sd) ((sd)->base.profile_pc_freq)
222 unsigned int profile_pc_size
;
223 #define STATE_PROFILE_PC_SIZE(sd) ((sd)->base.profile_pc_size)
226 /* Profile output goes to this or stdout if NULL.
227 We can't store `stderr' here as stdout goes through a callback. */
229 #define CPU_PROFILE_FILE(cpu) ((cpu)->base.profile_file)
230 #endif /* SIM_HAVE_PROFILE */
233 /* Functions for allocating/freeing a sim_state. */
234 SIM_DESC sim_state_alloc
PARAMS ((void));
235 void sim_state_free
PARAMS ((SIM_DESC
));
237 #endif /* SIM_BASE_H */
This page took 0.033473 seconds and 4 git commands to generate.