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