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