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