Home | History | Annotate | Download | only in gdb
      1 /* This file defines the interface between the simulator and gdb.
      2 
      3    Copyright (C) 1993-2014 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 3 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, see <http://www.gnu.org/licenses/>.  */
     19 
     20 #if !defined (REMOTE_SIM_H)
     21 #define REMOTE_SIM_H 1
     22 
     23 #ifdef __cplusplus
     24 extern "C" {
     25 #endif
     26 
     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 
     39 
     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 
     46 
     47 /* Values for `kind' arg to sim_open.  */
     48 
     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 
     54 
     55 /* Return codes from various functions.  */
     56 
     57 typedef enum {
     58   SIM_RC_FAIL = 0,
     59   SIM_RC_OK = 1
     60 } SIM_RC;
     61 
     62 
     63 /* The bfd struct, as an opaque type.  */
     64 
     65 struct bfd;
     66 
     67 
     68 /* Main simulator entry points.  */
     69 
     70 
     71 /* Create a fully initialized simulator instance.
     72 
     73    (This function is called when the simulator is selected from the
     74    gdb command line.)
     75 
     76    KIND specifies how the simulator shall be used.  Currently there
     77    are only two kinds: stand-alone and debug.
     78 
     79    CALLBACK specifies a standard host callback (defined in callback.h).
     80 
     81    ABFD, when non NULL, designates a target program.  The program is
     82    not loaded.
     83 
     84    ARGV is a standard ARGV pointer such as that passed from the
     85    command line.  The syntax of the argument list is is assumed to be
     86    ``SIM-PROG { SIM-OPTION } [ TARGET-PROGRAM { TARGET-OPTION } ]''.
     87    The trailing TARGET-PROGRAM and args are only valid for a
     88    stand-alone simulator.
     89 
     90    On success, the result is a non NULL descriptor that shall be
     91    passed to the other sim_foo functions.  While the simulator
     92    configuration can be parameterized by (in decreasing precedence)
     93    ARGV's SIM-OPTION, ARGV's TARGET-PROGRAM and the ABFD argument, the
     94    successful creation of the simulator shall not dependent on the
     95    presence of any of these arguments/options.
     96 
     97    Hardware simulator: The created simulator shall be sufficiently
     98    initialized to handle, with out restrictions any client requests
     99    (including memory reads/writes, register fetch/stores and a
    100    resume).
    101 
    102    Process simulator: that process is not created until a call to
    103    sim_create_inferior.  FIXME: What should the state of the simulator
    104    be? */
    105 
    106 SIM_DESC sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *callback, struct bfd *abfd, char **argv);
    107 
    108 
    109 /* Destory a simulator instance.
    110 
    111    QUITTING is non-zero if we cannot hang on errors.
    112 
    113    This may involve freeing target memory and closing any open files
    114    and mmap'd areas.  You cannot assume sim_kill has already been
    115    called. */
    116 
    117 void sim_close (SIM_DESC sd, int quitting);
    118 
    119 
    120 /* Load program PROG into the simulators memory.
    121 
    122    If ABFD is non-NULL, the bfd for the file has already been opened.
    123    The result is a return code indicating success.
    124 
    125    Hardware simulator: Normally, each program section is written into
    126    memory according to that sections LMA using physical (direct)
    127    addressing.  The exception being systems, such as PPC/CHRP, which
    128    support more complicated program loaders.  A call to this function
    129    should not effect the state of the processor registers.  Multiple
    130    calls to this function are permitted and have an accumulative
    131    effect.
    132 
    133    Process simulator: Calls to this function may be ignored.
    134 
    135    FIXME: Most hardware simulators load the image at the VMA using
    136    virtual addressing.
    137 
    138    FIXME: For some hardware targets, before a loaded program can be
    139    executed, it requires the manipulation of VM registers and tables.
    140    Such manipulation should probably (?) occure in
    141    sim_create_inferior. */
    142 
    143 SIM_RC sim_load (SIM_DESC sd, const char *prog, struct bfd *abfd, int from_tty);
    144 
    145 
    146 /* Prepare to run the simulated program.
    147 
    148    ABFD, if not NULL, provides initial processor state information.
    149    ARGV and ENV, if non NULL, are NULL terminated lists of pointers.
    150 
    151    Hardware simulator: This function shall initialize the processor
    152    registers to a known value.  The program counter and possibly stack
    153    pointer shall be set using information obtained from ABFD (or
    154    hardware reset defaults).  ARGV and ENV, dependant on the target
    155    ABI, may be written to memory.
    156 
    157    Process simulator: After a call to this function, a new process
    158    instance shall exist. The TEXT, DATA, BSS and stack regions shall
    159    all be initialized, ARGV and ENV shall be written to process
    160    address space (according to the applicable ABI) and the program
    161    counter and stack pointer set accordingly. */
    162 
    163 SIM_RC sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env);
    164 
    165 
    166 /* Fetch LENGTH bytes of the simulated program's memory.  Start fetch
    167    at virtual address MEM and store in BUF.  Result is number of bytes
    168    read, or zero if error.  */
    169 
    170 int sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length);
    171 
    172 
    173 /* Store LENGTH bytes from BUF into the simulated program's
    174    memory. Store bytes starting at virtual address MEM. Result is
    175    number of bytes write, or zero if error.  */
    176 
    177 int sim_write (SIM_DESC sd, SIM_ADDR mem, const unsigned char *buf, int length);
    178 
    179 
    180 /* Fetch register REGNO storing its raw (target endian) value in the
    181    LENGTH byte buffer BUF.  Return the actual size of the register or
    182    zero if REGNO is not applicable.
    183 
    184    Legacy implementations ignore LENGTH and always return -1.
    185 
    186    If LENGTH does not match the size of REGNO no data is transfered
    187    (the actual register size is still returned). */
    188 
    189 int sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf, int length);
    190 
    191 
    192 /* Store register REGNO from the raw (target endian) value in BUF.
    193 
    194    Return the actual size of the register, any size not equal to
    195    LENGTH indicates the register was not updated correctly.
    196 
    197    Return a LENGTH of -1 to indicate the register was not updated
    198    and an error has occurred.
    199 
    200    Return a LENGTH of 0 to indicate the register was not updated
    201    but no error has occurred. */
    202 
    203 int sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length);
    204 
    205 
    206 /* Print whatever statistics the simulator has collected.
    207 
    208    VERBOSE is currently unused and must always be zero.  */
    209 
    210 void sim_info (SIM_DESC sd, int verbose);
    211 
    212 
    213 /* Run (or resume) the simulated program.
    214 
    215    STEP, when non-zero indicates that only a single simulator cycle
    216    should be emulated.
    217 
    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.
    221 
    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.
    229 
    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. */
    234 
    235 void sim_resume (SIM_DESC sd, int step, int siggnal);
    236 
    237 
    238 /* Asynchronous request to stop the simulation.
    239    A nonzero return indicates that the simulator is able to handle
    240    the request */
    241 
    242 int sim_stop (SIM_DESC sd);
    243 
    244 
    245 /* Fetch the REASON why the program stopped.
    246 
    247    SIM_EXITED: The program has terminated. SIGRC indicates the target
    248    dependant exit status.
    249 
    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.
    259 
    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.
    263 
    264    SIM_RUNNING, SIM_POLLING: The return of one of these values
    265    indicates a problem internal to the simulator. */
    266 
    267 enum sim_stop { sim_running, sim_polling, sim_exited, sim_stopped, sim_signalled };
    268 
    269 void sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc);
    270 
    271 
    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. */
    275 
    276 void sim_do_command (SIM_DESC sd, const char *cmd);
    277 
    278 /* Complete a command based on the available sim commands.  Returns an
    279    array of possible matches.  */
    280 
    281 char **sim_complete_command (SIM_DESC sd, const char *text, const char *word);
    282 
    283 #ifdef __cplusplus
    284 }
    285 #endif
    286 
    287 #endif /* !defined (REMOTE_SIM_H) */
    288