GDB (API)
/home/stan/gdb/src/include/gdb/remote-sim.h
Go to the documentation of this file.
00001 /* This file defines the interface between the simulator and gdb.
00002 
00003    Copyright 1993-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #if !defined (REMOTE_SIM_H)
00021 #define REMOTE_SIM_H 1
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 /* This file is used when building stand-alone simulators, so isolate this
00028    file from gdb.  */
00029 
00030 /* Pick up CORE_ADDR_TYPE if defined (from gdb), otherwise use same value as
00031    gdb does (unsigned int - from defs.h).  */
00032 
00033 #ifndef CORE_ADDR_TYPE
00034 typedef unsigned int SIM_ADDR;
00035 #else
00036 typedef CORE_ADDR_TYPE SIM_ADDR;
00037 #endif
00038 
00039 
00040 /* Semi-opaque type used as result of sim_open and passed back to all
00041    other routines.  "desc" is short for "descriptor".
00042    It is up to each simulator to define `sim_state'.  */
00043 
00044 typedef struct sim_state *SIM_DESC;
00045 
00046 
00047 /* Values for `kind' arg to sim_open.  */
00048 
00049 typedef enum {
00050   SIM_OPEN_STANDALONE, /* simulator used standalone (run.c) */
00051   SIM_OPEN_DEBUG       /* simulator used by debugger (gdb) */
00052 } SIM_OPEN_KIND;
00053 
00054 
00055 /* Return codes from various functions.  */
00056 
00057 typedef enum {
00058   SIM_RC_FAIL = 0,
00059   SIM_RC_OK = 1
00060 } SIM_RC;
00061 
00062 
00063 /* The bfd struct, as an opaque type.  */
00064 
00065 struct bfd;
00066 
00067 
00068 /* Main simulator entry points.  */
00069 
00070 
00071 /* Create a fully initialized simulator instance.
00072 
00073    (This function is called when the simulator is selected from the
00074    gdb command line.)
00075 
00076    KIND specifies how the simulator shall be used.  Currently there
00077    are only two kinds: stand-alone and debug.
00078 
00079    CALLBACK specifies a standard host callback (defined in callback.h).
00080 
00081    ABFD, when non NULL, designates a target program.  The program is
00082    not loaded.
00083 
00084    ARGV is a standard ARGV pointer such as that passed from the
00085    command line.  The syntax of the argument list is is assumed to be
00086    ``SIM-PROG { SIM-OPTION } [ TARGET-PROGRAM { TARGET-OPTION } ]''.
00087    The trailing TARGET-PROGRAM and args are only valid for a
00088    stand-alone simulator.
00089 
00090    On success, the result is a non NULL descriptor that shall be
00091    passed to the other sim_foo functions.  While the simulator
00092    configuration can be parameterized by (in decreasing precedence)
00093    ARGV's SIM-OPTION, ARGV's TARGET-PROGRAM and the ABFD argument, the
00094    successful creation of the simulator shall not dependent on the
00095    presence of any of these arguments/options.
00096 
00097    Hardware simulator: The created simulator shall be sufficiently
00098    initialized to handle, with out restrictions any client requests
00099    (including memory reads/writes, register fetch/stores and a
00100    resume).
00101 
00102    Process simulator: that process is not created until a call to
00103    sim_create_inferior.  FIXME: What should the state of the simulator
00104    be? */
00105 
00106 SIM_DESC sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *callback, struct bfd *abfd, char **argv);
00107 
00108 
00109 /* Destory a simulator instance.
00110 
00111    QUITTING is non-zero if we cannot hang on errors.
00112 
00113    This may involve freeing target memory and closing any open files
00114    and mmap'd areas.  You cannot assume sim_kill has already been
00115    called. */
00116 
00117 void sim_close (SIM_DESC sd, int quitting);
00118 
00119 
00120 /* Load program PROG into the simulators memory.
00121 
00122    If ABFD is non-NULL, the bfd for the file has already been opened.
00123    The result is a return code indicating success.
00124 
00125    Hardware simulator: Normally, each program section is written into
00126    memory according to that sections LMA using physical (direct)
00127    addressing.  The exception being systems, such as PPC/CHRP, which
00128    support more complicated program loaders.  A call to this function
00129    should not effect the state of the processor registers.  Multiple
00130    calls to this function are permitted and have an accumulative
00131    effect.
00132 
00133    Process simulator: Calls to this function may be ignored.
00134 
00135    FIXME: Most hardware simulators load the image at the VMA using
00136    virtual addressing.
00137 
00138    FIXME: For some hardware targets, before a loaded program can be
00139    executed, it requires the manipulation of VM registers and tables.
00140    Such manipulation should probably (?) occure in
00141    sim_create_inferior. */
00142 
00143 SIM_RC sim_load (SIM_DESC sd, char *prog, struct bfd *abfd, int from_tty);
00144 
00145 
00146 /* Prepare to run the simulated program.
00147 
00148    ABFD, if not NULL, provides initial processor state information.
00149    ARGV and ENV, if non NULL, are NULL terminated lists of pointers.
00150 
00151    Hardware simulator: This function shall initialize the processor
00152    registers to a known value.  The program counter and possibly stack
00153    pointer shall be set using information obtained from ABFD (or
00154    hardware reset defaults).  ARGV and ENV, dependant on the target
00155    ABI, may be written to memory.
00156 
00157    Process simulator: After a call to this function, a new process
00158    instance shall exist. The TEXT, DATA, BSS and stack regions shall
00159    all be initialized, ARGV and ENV shall be written to process
00160    address space (according to the applicable ABI) and the program
00161    counter and stack pointer set accordingly. */
00162 
00163 SIM_RC sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env);
00164 
00165 
00166 /* Fetch LENGTH bytes of the simulated program's memory.  Start fetch
00167    at virtual address MEM and store in BUF.  Result is number of bytes
00168    read, or zero if error.  */
00169 
00170 int sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length);
00171 
00172 
00173 /* Store LENGTH bytes from BUF into the simulated program's
00174    memory. Store bytes starting at virtual address MEM. Result is
00175    number of bytes write, or zero if error.  */
00176 
00177 int sim_write (SIM_DESC sd, SIM_ADDR mem, const unsigned char *buf, int length);
00178 
00179 
00180 /* Fetch register REGNO storing its raw (target endian) value in the
00181    LENGTH byte buffer BUF.  Return the actual size of the register or
00182    zero if REGNO is not applicable.
00183 
00184    Legacy implementations ignore LENGTH and always return -1.
00185 
00186    If LENGTH does not match the size of REGNO no data is transfered
00187    (the actual register size is still returned). */
00188 
00189 int sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf, int length);
00190 
00191 
00192 /* Store register REGNO from the raw (target endian) value in BUF.
00193 
00194    Return the actual size of the register, any size not equal to
00195    LENGTH indicates the register was not updated correctly.
00196 
00197    Return a LENGTH of -1 to indicate the register was not updated
00198    and an error has occurred.
00199 
00200    Return a LENGTH of 0 to indicate the register was not updated
00201    but no error has occurred. */
00202 
00203 int sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length);
00204 
00205 
00206 /* Print whatever statistics the simulator has collected.
00207 
00208    VERBOSE is currently unused and must always be zero.  */
00209 
00210 void sim_info (SIM_DESC sd, int verbose);
00211 
00212 
00213 /* Run (or resume) the simulated program.
00214 
00215    STEP, when non-zero indicates that only a single simulator cycle
00216    should be emulated.
00217 
00218    SIGGNAL, if non-zero is a (HOST) SIGRC value indicating the type of
00219    event (hardware interrupt, signal) to be delivered to the simulated
00220    program.
00221 
00222    Hardware simulator: If the SIGRC value returned by
00223    sim_stop_reason() is passed back to the simulator via SIGGNAL then
00224    the hardware simulator shall correctly deliver the hardware event
00225    indicated by that signal.  If a value of zero is passed in then the
00226    simulation will continue as if there were no outstanding signal.
00227    The effect of any other SIGGNAL value is is implementation
00228    dependant.
00229 
00230    Process simulator: If SIGRC is non-zero then the corresponding
00231    signal is delivered to the simulated program and execution is then
00232    continued.  A zero SIGRC value indicates that the program should
00233    continue as normal. */
00234 
00235 void sim_resume (SIM_DESC sd, int step, int siggnal);
00236 
00237 
00238 /* Asynchronous request to stop the simulation.
00239    A nonzero return indicates that the simulator is able to handle
00240    the request */
00241 
00242 int sim_stop (SIM_DESC sd);
00243 
00244 
00245 /* Fetch the REASON why the program stopped.
00246 
00247    SIM_EXITED: The program has terminated. SIGRC indicates the target
00248    dependant exit status.
00249 
00250    SIM_STOPPED: The program has stopped.  SIGRC uses the host's signal
00251    numbering as a way of identifying the reaon: program interrupted by
00252    user via a sim_stop request (SIGINT); a breakpoint instruction
00253    (SIGTRAP); a completed single step (SIGTRAP); an internal error
00254    condition (SIGABRT); an illegal instruction (SIGILL); Access to an
00255    undefined memory region (SIGSEGV); Mis-aligned memory access
00256    (SIGBUS).  For some signals information in addition to the signal
00257    number may be retained by the simulator (e.g. offending address),
00258    that information is not directly accessable via this interface.
00259 
00260    SIM_SIGNALLED: The program has been terminated by a signal. The
00261    simulator has encountered target code that causes the the program
00262    to exit with signal SIGRC.
00263 
00264    SIM_RUNNING, SIM_POLLING: The return of one of these values
00265    indicates a problem internal to the simulator. */
00266 
00267 enum sim_stop { sim_running, sim_polling, sim_exited, sim_stopped, sim_signalled };
00268 
00269 void sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc);
00270 
00271 
00272 /* Passthru for other commands that the simulator might support.
00273    Simulators should be prepared to deal with any combination of NULL
00274    or empty CMD. */
00275 
00276 void sim_do_command (SIM_DESC sd, char *cmd);
00277 
00278 /* Complete a command based on the available sim commands.  Returns an
00279    array of possible matches.  */
00280 
00281 char **sim_complete_command (SIM_DESC sd, const char *text, const char *word);
00282 
00283 #ifdef __cplusplus
00284 }
00285 #endif
00286 
00287 #endif /* !defined (REMOTE_SIM_H) */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines