* ld-elf/header.d: Allow arbitrary lines between "Program Header"
[binutils.git] / include / gdb / remote-sim.h
blob90cff00123abc9a7b1fd8705bff85c28142a936e
1 /* This file defines the interface between the simulator and gdb.
3 Copyright 1993, 1994, 1996, 1997, 1998, 2000, 2002, 2007
4 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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. */
22 #if !defined (REMOTE_SIM_H)
23 #define REMOTE_SIM_H 1
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
29 /* This file is used when building stand-alone simulators, so isolate this
30 file from gdb. */
32 /* Pick up CORE_ADDR_TYPE if defined (from gdb), otherwise use same value as
33 gdb does (unsigned int - from defs.h). */
35 #ifndef CORE_ADDR_TYPE
36 typedef unsigned int SIM_ADDR;
37 #else
38 typedef CORE_ADDR_TYPE SIM_ADDR;
39 #endif
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'. */
46 typedef struct sim_state *SIM_DESC;
49 /* Values for `kind' arg to sim_open. */
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;
57 /* Return codes from various functions. */
59 typedef enum {
60 SIM_RC_FAIL = 0,
61 SIM_RC_OK = 1
62 } SIM_RC;
65 /* The bfd struct, as an opaque type. */
67 struct bfd;
70 /* Main simulator entry points. */
73 /* Create a fully initialized simulator instance.
75 (This function is called when the simulator is selected from the
76 gdb command line.)
78 KIND specifies how the simulator shall be used. Currently there
79 are only two kinds: stand-alone and debug.
81 CALLBACK specifies a standard host callback (defined in callback.h).
83 ABFD, when non NULL, designates a target program. The program is
84 not loaded.
86 ARGV is a standard ARGV pointer such as that passed from the
87 command line. The syntax of the argument list is is assumed to be
88 ``SIM-PROG { SIM-OPTION } [ TARGET-PROGRAM { TARGET-OPTION } ]''.
89 The trailing TARGET-PROGRAM and args are only valid for a
90 stand-alone simulator.
92 On success, the result is a non NULL descriptor that shall be
93 passed to the other sim_foo functions. While the simulator
94 configuration can be parameterized by (in decreasing precedence)
95 ARGV's SIM-OPTION, ARGV's TARGET-PROGRAM and the ABFD argument, the
96 successful creation of the simulator shall not dependent on the
97 presence of any of these arguments/options.
99 Hardware simulator: The created simulator shall be sufficiently
100 initialized to handle, with out restrictions any client requests
101 (including memory reads/writes, register fetch/stores and a
102 resume).
104 Process simulator: that process is not created until a call to
105 sim_create_inferior. FIXME: What should the state of the simulator
106 be? */
108 SIM_DESC sim_open PARAMS ((SIM_OPEN_KIND kind, struct host_callback_struct *callback, struct bfd *abfd, char **argv));
111 /* Destory a simulator instance.
113 QUITTING is non-zero if we cannot hang on errors.
115 This may involve freeing target memory and closing any open files
116 and mmap'd areas. You cannot assume sim_kill has already been
117 called. */
119 void sim_close PARAMS ((SIM_DESC sd, int quitting));
122 /* Load program PROG into the simulators memory.
124 If ABFD is non-NULL, the bfd for the file has already been opened.
125 The result is a return code indicating success.
127 Hardware simulator: Normally, each program section is written into
128 memory according to that sections LMA using physical (direct)
129 addressing. The exception being systems, such as PPC/CHRP, which
130 support more complicated program loaders. A call to this function
131 should not effect the state of the processor registers. Multiple
132 calls to this function are permitted and have an accumulative
133 effect.
135 Process simulator: Calls to this function may be ignored.
137 FIXME: Most hardware simulators load the image at the VMA using
138 virtual addressing.
140 FIXME: For some hardware targets, before a loaded program can be
141 executed, it requires the manipulation of VM registers and tables.
142 Such manipulation should probably (?) occure in
143 sim_create_inferior. */
145 SIM_RC sim_load PARAMS ((SIM_DESC sd, char *prog, struct bfd *abfd, int from_tty));
148 /* Prepare to run the simulated program.
150 ABFD, if not NULL, provides initial processor state information.
151 ARGV and ENV, if non NULL, are NULL terminated lists of pointers.
153 Hardware simulator: This function shall initialize the processor
154 registers to a known value. The program counter and possibly stack
155 pointer shall be set using information obtained from ABFD (or
156 hardware reset defaults). ARGV and ENV, dependant on the target
157 ABI, may be written to memory.
159 Process simulator: After a call to this function, a new process
160 instance shall exist. The TEXT, DATA, BSS and stack regions shall
161 all be initialized, ARGV and ENV shall be written to process
162 address space (according to the applicable ABI) and the program
163 counter and stack pointer set accordingly. */
165 SIM_RC sim_create_inferior PARAMS ((SIM_DESC sd, struct bfd *abfd, char **argv, char **env));
168 /* Fetch LENGTH bytes of the simulated program's memory. Start fetch
169 at virtual address MEM and store in BUF. Result is number of bytes
170 read, or zero if error. */
172 int sim_read PARAMS ((SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length));
175 /* Store LENGTH bytes from BUF into the simulated program's
176 memory. Store bytes starting at virtual address MEM. Result is
177 number of bytes write, or zero if error. */
179 int sim_write PARAMS ((SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length));
182 /* Fetch register REGNO storing its raw (target endian) value in the
183 LENGTH byte buffer BUF. Return the actual size of the register or
184 zero if REGNO is not applicable.
186 Legacy implementations ignore LENGTH and always return -1.
188 If LENGTH does not match the size of REGNO no data is transfered
189 (the actual register size is still returned). */
191 int sim_fetch_register PARAMS ((SIM_DESC sd, int regno, unsigned char *buf, int length));
194 /* Store register REGNO from the raw (target endian) value in BUF.
195 Return the actual size of the register or zero if REGNO is not
196 applicable.
198 Legacy implementations ignore LENGTH and always return -1.
200 If LENGTH does not match the size of REGNO no data is transfered
201 (the actual register size is still returned). */
203 int sim_store_register PARAMS ((SIM_DESC sd, int regno, unsigned char *buf, int length));
206 /* Print whatever statistics the simulator has collected.
208 VERBOSE is currently unused and must always be zero. */
210 void sim_info PARAMS ((SIM_DESC sd, int verbose));
213 /* Run (or resume) the simulated program.
215 STEP, when non-zero indicates that only a single simulator cycle
216 should be emulated.
218 SIGGNAL, if non-zero is a (HOST) SIGRC value indicating the type of
219 event (hardware interrupt, signal) to be delivered to the simulated
220 program.
222 Hardware simulator: If the SIGRC value returned by
223 sim_stop_reason() is passed back to the simulator via SIGGNAL then
224 the hardware simulator shall correctly deliver the hardware event
225 indicated by that signal. If a value of zero is passed in then the
226 simulation will continue as if there were no outstanding signal.
227 The effect of any other SIGGNAL value is is implementation
228 dependant.
230 Process simulator: If SIGRC is non-zero then the corresponding
231 signal is delivered to the simulated program and execution is then
232 continued. A zero SIGRC value indicates that the program should
233 continue as normal. */
235 void sim_resume PARAMS ((SIM_DESC sd, int step, int siggnal));
238 /* Asynchronous request to stop the simulation.
239 A nonzero return indicates that the simulator is able to handle
240 the request */
242 int sim_stop PARAMS ((SIM_DESC sd));
245 /* Fetch the REASON why the program stopped.
247 SIM_EXITED: The program has terminated. SIGRC indicates the target
248 dependant exit status.
250 SIM_STOPPED: The program has stopped. SIGRC uses the host's signal
251 numbering as a way of identifying the reaon: program interrupted by
252 user via a sim_stop request (SIGINT); a breakpoint instruction
253 (SIGTRAP); a completed single step (SIGTRAP); an internal error
254 condition (SIGABRT); an illegal instruction (SIGILL); Access to an
255 undefined memory region (SIGSEGV); Mis-aligned memory access
256 (SIGBUS). For some signals information in addition to the signal
257 number may be retained by the simulator (e.g. offending address),
258 that information is not directly accessable via this interface.
260 SIM_SIGNALLED: The program has been terminated by a signal. The
261 simulator has encountered target code that causes the the program
262 to exit with signal SIGRC.
264 SIM_RUNNING, SIM_POLLING: The return of one of these values
265 indicates a problem internal to the simulator. */
267 enum sim_stop { sim_running, sim_polling, sim_exited, sim_stopped, sim_signalled };
269 void sim_stop_reason PARAMS ((SIM_DESC sd, enum sim_stop *reason, int *sigrc));
272 /* Passthru for other commands that the simulator might support.
273 Simulators should be prepared to deal with any combination of NULL
274 or empty CMD. */
276 void sim_do_command PARAMS ((SIM_DESC sd, char *cmd));
278 #ifdef __cplusplus
280 #endif
282 #endif /* !defined (REMOTE_SIM_H) */