1 | /* This file defines the interface between the simulator and gdb.
|
---|
2 | Copyright 1993, 1994, 1996, 1997, 1998, 2000
|
---|
3 | Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | This file is part of GDB.
|
---|
6 |
|
---|
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 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
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.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program; if not, write to the Free Software
|
---|
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
20 |
|
---|
21 | #if !defined (REMOTE_SIM_H)
|
---|
22 | #define REMOTE_SIM_H 1
|
---|
23 |
|
---|
24 | #ifdef __cplusplus
|
---|
25 | extern "C" {
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | /* This file is used when building stand-alone simulators, so isolate this
|
---|
29 | file from gdb. */
|
---|
30 |
|
---|
31 | /* Pick up CORE_ADDR_TYPE if defined (from gdb), otherwise use same value as
|
---|
32 | gdb does (unsigned int - from defs.h). */
|
---|
33 |
|
---|
34 | #ifndef CORE_ADDR_TYPE
|
---|
35 | typedef unsigned int SIM_ADDR;
|
---|
36 | #else
|
---|
37 | typedef CORE_ADDR_TYPE SIM_ADDR;
|
---|
38 | #endif
|
---|
39 |
|
---|
40 |
|
---|
41 | /* Semi-opaque type used as result of sim_open and passed back to all
|
---|
42 | other routines. "desc" is short for "descriptor".
|
---|
43 | It is up to each simulator to define `sim_state'. */
|
---|
44 |
|
---|
45 | typedef struct sim_state *SIM_DESC;
|
---|
46 |
|
---|
47 |
|
---|
48 | /* Values for `kind' arg to sim_open. */
|
---|
49 |
|
---|
50 | typedef enum {
|
---|
51 | SIM_OPEN_STANDALONE, /* simulator used standalone (run.c) */
|
---|
52 | SIM_OPEN_DEBUG /* simulator used by debugger (gdb) */
|
---|
53 | } SIM_OPEN_KIND;
|
---|
54 |
|
---|
55 |
|
---|
56 | /* Return codes from various functions. */
|
---|
57 |
|
---|
58 | typedef enum {
|
---|
59 | SIM_RC_FAIL = 0,
|
---|
60 | SIM_RC_OK = 1,
|
---|
61 | SIM_RC_UNKNOWN_BREAKPOINT = 2,
|
---|
62 | SIM_RC_INSUFFICIENT_RESOURCES = 3,
|
---|
63 | SIM_RC_DUPLICATE_BREAKPOINT = 4
|
---|
64 | } SIM_RC;
|
---|
65 |
|
---|
66 |
|
---|
67 | /* The bfd struct, as an opaque type. */
|
---|
68 |
|
---|
69 | struct _bfd;
|
---|
70 |
|
---|
71 |
|
---|
72 | /* Main simulator entry points. */
|
---|
73 |
|
---|
74 |
|
---|
75 | /* Create a fully initialized simulator instance.
|
---|
76 |
|
---|
77 | (This function is called when the simulator is selected from the
|
---|
78 | gdb command line.)
|
---|
79 |
|
---|
80 | KIND specifies how the simulator shall be used. Currently there
|
---|
81 | are only two kinds: stand-alone and debug.
|
---|
82 |
|
---|
83 | CALLBACK specifies a standard host callback (defined in callback.h).
|
---|
84 |
|
---|
85 | ABFD, when non NULL, designates a target program. The program is
|
---|
86 | not loaded.
|
---|
87 |
|
---|
88 | ARGV is a standard ARGV pointer such as that passed from the
|
---|
89 | command line. The syntax of the argument list is is assumed to be
|
---|
90 | ``SIM-PROG { SIM-OPTION } [ TARGET-PROGRAM { TARGET-OPTION } ]''.
|
---|
91 | The trailing TARGET-PROGRAM and args are only valid for a
|
---|
92 | stand-alone simulator.
|
---|
93 |
|
---|
94 | On success, the result is a non NULL descriptor that shall be
|
---|
95 | passed to the other sim_foo functions. While the simulator
|
---|
96 | configuration can be parameterized by (in decreasing precedence)
|
---|
97 | ARGV's SIM-OPTION, ARGV's TARGET-PROGRAM and the ABFD argument, the
|
---|
98 | successful creation of the simulator shall not dependent on the
|
---|
99 | presence of any of these arguments/options.
|
---|
100 |
|
---|
101 | Hardware simulator: The created simulator shall be sufficiently
|
---|
102 | initialized to handle, with out restrictions any client requests
|
---|
103 | (including memory reads/writes, register fetch/stores and a
|
---|
104 | resume).
|
---|
105 |
|
---|
106 | Process simulator: that process is not created until a call to
|
---|
107 | sim_create_inferior. FIXME: What should the state of the simulator
|
---|
108 | be? */
|
---|
109 |
|
---|
110 | SIM_DESC sim_open PARAMS ((SIM_OPEN_KIND kind, struct host_callback_struct *callback, struct _bfd *abfd, char **argv));
|
---|
111 |
|
---|
112 |
|
---|
113 | /* Destory a simulator instance.
|
---|
114 |
|
---|
115 | QUITTING is non-zero if we cannot hang on errors.
|
---|
116 |
|
---|
117 | This may involve freeing target memory and closing any open files
|
---|
118 | and mmap'd areas. You cannot assume sim_kill has already been
|
---|
119 | called. */
|
---|
120 |
|
---|
121 | void sim_close PARAMS ((SIM_DESC sd, int quitting));
|
---|
122 |
|
---|
123 |
|
---|
124 | /* Load program PROG into the simulators memory.
|
---|
125 |
|
---|
126 | If ABFD is non-NULL, the bfd for the file has already been opened.
|
---|
127 | The result is a return code indicating success.
|
---|
128 |
|
---|
129 | Hardware simulator: Normally, each program section is written into
|
---|
130 | memory according to that sections LMA using physical (direct)
|
---|
131 | addressing. The exception being systems, such as PPC/CHRP, which
|
---|
132 | support more complicated program loaders. A call to this function
|
---|
133 | should not effect the state of the processor registers. Multiple
|
---|
134 | calls to this function are permitted and have an accumulative
|
---|
135 | effect.
|
---|
136 |
|
---|
137 | Process simulator: Calls to this function may be ignored.
|
---|
138 |
|
---|
139 | FIXME: Most hardware simulators load the image at the VMA using
|
---|
140 | virtual addressing.
|
---|
141 |
|
---|
142 | FIXME: For some hardware targets, before a loaded program can be
|
---|
143 | executed, it requires the manipulation of VM registers and tables.
|
---|
144 | Such manipulation should probably (?) occure in
|
---|
145 | sim_create_inferior. */
|
---|
146 |
|
---|
147 | SIM_RC sim_load PARAMS ((SIM_DESC sd, char *prog, struct _bfd *abfd, int from_tty));
|
---|
148 |
|
---|
149 |
|
---|
150 | /* Prepare to run the simulated program.
|
---|
151 |
|
---|
152 | ABFD, if not NULL, provides initial processor state information.
|
---|
153 | ARGV and ENV, if non NULL, are NULL terminated lists of pointers.
|
---|
154 |
|
---|
155 | Hardware simulator: This function shall initialize the processor
|
---|
156 | registers to a known value. The program counter and possibly stack
|
---|
157 | pointer shall be set using information obtained from ABFD (or
|
---|
158 | hardware reset defaults). ARGV and ENV, dependant on the target
|
---|
159 | ABI, may be written to memory.
|
---|
160 |
|
---|
161 | Process simulator: After a call to this function, a new process
|
---|
162 | instance shall exist. The TEXT, DATA, BSS and stack regions shall
|
---|
163 | all be initialized, ARGV and ENV shall be written to process
|
---|
164 | address space (according to the applicable ABI) and the program
|
---|
165 | counter and stack pointer set accordingly. */
|
---|
166 |
|
---|
167 | SIM_RC sim_create_inferior PARAMS ((SIM_DESC sd, struct _bfd *abfd, char **argv, char **env));
|
---|
168 |
|
---|
169 |
|
---|
170 | /* Fetch LENGTH bytes of the simulated program's memory. Start fetch
|
---|
171 | at virtual address MEM and store in BUF. Result is number of bytes
|
---|
172 | read, or zero if error. */
|
---|
173 |
|
---|
174 | int sim_read PARAMS ((SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length));
|
---|
175 |
|
---|
176 |
|
---|
177 | /* Store LENGTH bytes from BUF into the simulated program's
|
---|
178 | memory. Store bytes starting at virtual address MEM. Result is
|
---|
179 | number of bytes write, or zero if error. */
|
---|
180 |
|
---|
181 | int sim_write PARAMS ((SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length));
|
---|
182 |
|
---|
183 |
|
---|
184 | /* Fetch register REGNO storing its raw (target endian) value in the
|
---|
185 | LENGTH byte buffer BUF. Return the actual size of the register or
|
---|
186 | zero if REGNO is not applicable.
|
---|
187 |
|
---|
188 | Legacy implementations ignore LENGTH and always return -1.
|
---|
189 |
|
---|
190 | If LENGTH does not match the size of REGNO no data is transfered
|
---|
191 | (the actual register size is still returned). */
|
---|
192 |
|
---|
193 | int sim_fetch_register PARAMS ((SIM_DESC sd, int regno, unsigned char *buf, int length));
|
---|
194 |
|
---|
195 |
|
---|
196 | /* Store register REGNO from the raw (target endian) value in BUF.
|
---|
197 | Return the actual size of the register or zero if REGNO is not
|
---|
198 | applicable.
|
---|
199 |
|
---|
200 | Legacy implementations ignore LENGTH and always return -1.
|
---|
201 |
|
---|
202 | If LENGTH does not match the size of REGNO no data is transfered
|
---|
203 | (the actual register size is still returned). */
|
---|
204 |
|
---|
205 | int sim_store_register PARAMS ((SIM_DESC sd, int regno, unsigned char *buf, int length));
|
---|
206 |
|
---|
207 |
|
---|
208 | /* Print whatever statistics the simulator has collected.
|
---|
209 |
|
---|
210 | VERBOSE is currently unused and must always be zero. */
|
---|
211 |
|
---|
212 | void sim_info PARAMS ((SIM_DESC sd, int verbose));
|
---|
213 |
|
---|
214 |
|
---|
215 | /* Run (or resume) the simulated program.
|
---|
216 |
|
---|
217 | STEP, when non-zero indicates that only a single simulator cycle
|
---|
218 | should be emulated.
|
---|
219 |
|
---|
220 | SIGGNAL, if non-zero is a (HOST) SIGRC value indicating the type of
|
---|
221 | event (hardware interrupt, signal) to be delivered to the simulated
|
---|
222 | program.
|
---|
223 |
|
---|
224 | Hardware simulator: If the SIGRC value returned by
|
---|
225 | sim_stop_reason() is passed back to the simulator via SIGGNAL then
|
---|
226 | the hardware simulator shall correctly deliver the hardware event
|
---|
227 | indicated by that signal. If a value of zero is passed in then the
|
---|
228 | simulation will continue as if there were no outstanding signal.
|
---|
229 | The effect of any other SIGGNAL value is is implementation
|
---|
230 | dependant.
|
---|
231 |
|
---|
232 | Process simulator: If SIGRC is non-zero then the corresponding
|
---|
233 | signal is delivered to the simulated program and execution is then
|
---|
234 | continued. A zero SIGRC value indicates that the program should
|
---|
235 | continue as normal. */
|
---|
236 |
|
---|
237 | void sim_resume PARAMS ((SIM_DESC sd, int step, int siggnal));
|
---|
238 |
|
---|
239 |
|
---|
240 | /* Asynchronous request to stop the simulation.
|
---|
241 | A nonzero return indicates that the simulator is able to handle
|
---|
242 | the request */
|
---|
243 |
|
---|
244 | int sim_stop PARAMS ((SIM_DESC sd));
|
---|
245 |
|
---|
246 |
|
---|
247 | /* Fetch the REASON why the program stopped.
|
---|
248 |
|
---|
249 | SIM_EXITED: The program has terminated. SIGRC indicates the target
|
---|
250 | dependant exit status.
|
---|
251 |
|
---|
252 | SIM_STOPPED: The program has stopped. SIGRC uses the host's signal
|
---|
253 | numbering as a way of identifying the reaon: program interrupted by
|
---|
254 | user via a sim_stop request (SIGINT); a breakpoint instruction
|
---|
255 | (SIGTRAP); a completed single step (SIGTRAP); an internal error
|
---|
256 | condition (SIGABRT); an illegal instruction (SIGILL); Access to an
|
---|
257 | undefined memory region (SIGSEGV); Mis-aligned memory access
|
---|
258 | (SIGBUS). For some signals information in addition to the signal
|
---|
259 | number may be retained by the simulator (e.g. offending address),
|
---|
260 | that information is not directly accessable via this interface.
|
---|
261 |
|
---|
262 | SIM_SIGNALLED: The program has been terminated by a signal. The
|
---|
263 | simulator has encountered target code that causes the the program
|
---|
264 | to exit with signal SIGRC.
|
---|
265 |
|
---|
266 | SIM_RUNNING, SIM_POLLING: The return of one of these values
|
---|
267 | indicates a problem internal to the simulator. */
|
---|
268 |
|
---|
269 | enum sim_stop { sim_running, sim_polling, sim_exited, sim_stopped, sim_signalled };
|
---|
270 |
|
---|
271 | void sim_stop_reason PARAMS ((SIM_DESC sd, enum sim_stop *reason, int *sigrc));
|
---|
272 |
|
---|
273 |
|
---|
274 | /* Passthru for other commands that the simulator might support.
|
---|
275 | Simulators should be prepared to deal with any combination of NULL
|
---|
276 | or empty CMD. */
|
---|
277 |
|
---|
278 | void sim_do_command PARAMS ((SIM_DESC sd, char *cmd));
|
---|
279 |
|
---|
280 | /* Call these functions to set and clear breakpoints at ADDR. */
|
---|
281 |
|
---|
282 | SIM_RC sim_set_breakpoint PARAMS ((SIM_DESC sd, SIM_ADDR addr));
|
---|
283 | SIM_RC sim_clear_breakpoint PARAMS ((SIM_DESC sd, SIM_ADDR addr));
|
---|
284 | SIM_RC sim_clear_all_breakpoints PARAMS ((SIM_DESC sd));
|
---|
285 |
|
---|
286 | /* These functions are used to enable and disable breakpoints. */
|
---|
287 |
|
---|
288 | SIM_RC sim_enable_breakpoint PARAMS ((SIM_DESC sd, SIM_ADDR addr));
|
---|
289 | SIM_RC sim_disable_breakpoint PARAMS ((SIM_DESC sd, SIM_ADDR addr));
|
---|
290 | SIM_RC sim_enable_all_breakpoints PARAMS ((SIM_DESC sd));
|
---|
291 | SIM_RC sim_disable_all_breakpoints PARAMS ((SIM_DESC sd));
|
---|
292 | |
---|
293 |
|
---|
294 |
|
---|
295 | /* Provide simulator with a default (global) host_callback_struct.
|
---|
296 | THIS PROCEDURE IS DEPRECIATED.
|
---|
297 | GDB and NRUN do not use this interface.
|
---|
298 | This procedure does not take a SIM_DESC argument as it is
|
---|
299 | used before sim_open. */
|
---|
300 |
|
---|
301 | void sim_set_callbacks PARAMS ((struct host_callback_struct *));
|
---|
302 |
|
---|
303 |
|
---|
304 | /* Set the size of the simulator memory array.
|
---|
305 | THIS PROCEDURE IS DEPRECIATED.
|
---|
306 | GDB and NRUN do not use this interface.
|
---|
307 | This procedure does not take a SIM_DESC argument as it is
|
---|
308 | used before sim_open. */
|
---|
309 |
|
---|
310 | void sim_size PARAMS ((int i));
|
---|
311 |
|
---|
312 |
|
---|
313 | /* Single-step simulator with tracing enabled.
|
---|
314 | THIS PROCEDURE IS DEPRECIATED.
|
---|
315 | THIS PROCEDURE IS EVEN MORE DEPRECATED THAN SIM_SET_TRACE
|
---|
316 | GDB and NRUN do not use this interface.
|
---|
317 | This procedure returns: ``0'' indicating that the simulator should
|
---|
318 | be continued using sim_trace() calls; ``1'' indicating that the
|
---|
319 | simulation has finished. */
|
---|
320 |
|
---|
321 | int sim_trace PARAMS ((SIM_DESC sd));
|
---|
322 |
|
---|
323 |
|
---|
324 | /* Enable tracing.
|
---|
325 | THIS PROCEDURE IS DEPRECIATED.
|
---|
326 | GDB and NRUN do not use this interface.
|
---|
327 | This procedure returns: ``0'' indicating that the simulator should
|
---|
328 | be continued using sim_trace() calls; ``1'' indicating that the
|
---|
329 | simulation has finished. */
|
---|
330 |
|
---|
331 | void sim_set_trace PARAMS ((void));
|
---|
332 |
|
---|
333 |
|
---|
334 | /* Configure the size of the profile buffer.
|
---|
335 | THIS PROCEDURE IS DEPRECIATED.
|
---|
336 | GDB and NRUN do not use this interface.
|
---|
337 | This procedure does not take a SIM_DESC argument as it is
|
---|
338 | used before sim_open. */
|
---|
339 |
|
---|
340 | void sim_set_profile_size PARAMS ((int n));
|
---|
341 |
|
---|
342 |
|
---|
343 | /* Kill the running program.
|
---|
344 | THIS PROCEDURE IS DEPRECIATED.
|
---|
345 | GDB and NRUN do not use this interface.
|
---|
346 | This procedure will be replaced as part of the introduction of
|
---|
347 | multi-cpu simulators. */
|
---|
348 |
|
---|
349 | void sim_kill PARAMS ((SIM_DESC sd));
|
---|
350 |
|
---|
351 | #ifdef __cplusplus
|
---|
352 | }
|
---|
353 | #endif
|
---|
354 |
|
---|
355 | #endif /* !defined (REMOTE_SIM_H) */
|
---|