* callback.h (CB_TARGET_DEFS_MAP): Renamed from target_defs_map.
authorDoug Evans <dje@google.com>
Mon, 17 Nov 1997 22:12:52 +0000 (22:12 +0000)
committerDoug Evans <dje@google.com>
Mon, 17 Nov 1997 22:12:52 +0000 (22:12 +0000)
(host_callback): Add stat, fstat, syscall_map, errno_map, open_map,
signal_map, stat_map.
(errn_map,open_map): Renamed to cb_init_foo_map.
(cb_host_to_target_errno,cb_target_to_host_open): Renamed from
host_to_target_errno,target_to_host_open.
(cb_read_target_syscall_maps): Add prototype.
(cb_target_to_host_syscall): Likewise.
(cb_host_to_target_stat): Likewise.
(cb_syscall): Likewise.
(CB_SYS_{exit,open,close,read,write,lseek,unlink,getpid,kill,fstat,
argvlen,argv,chdir,stat,chmod,utime,time}): Define.
(CB_SYSCALL): New type.
(CB_RC): New enum.

include/ChangeLog
include/callback.h

index c6bdee6..614cad0 100644 (file)
@@ -1,3 +1,27 @@
+Mon Nov 17 14:00:51 1997  Doug Evans  <devans@seba.cygnus.com>
+
+       * callback.h (CB_TARGET_DEFS_MAP): Renamed from target_defs_map.
+       (host_callback): Add stat, fstat, syscall_map, errno_map, open_map,
+       signal_map, stat_map.
+       (errn_map,open_map): Renamed to cb_init_foo_map.
+       (cb_host_to_target_errno,cb_target_to_host_open): Renamed from
+       host_to_target_errno,target_to_host_open.
+       (cb_read_target_syscall_maps): Add prototype.
+       (cb_target_to_host_syscall): Likewise.
+       (cb_host_to_target_stat): Likewise.
+       (cb_syscall): Likewise.
+       (CB_SYS_{exit,open,close,read,write,lseek,unlink,getpid,kill,fstat,
+       argvlen,argv,chdir,stat,chmod,utime,time}): Define.
+       (CB_SYSCALL): New type.
+       (CB_RC): New enum.
+
+Tue Oct 14 16:07:51 1997  Nick Clifton  <nickc@cygnus.com>
+
+       * dis-asm.h (struct disassemble_info): New field
+       'symbol_at_address_func'.
+       (INIT_DISASSEMBLE_INFO_NO_ARCH): Initialise new field with
+       generic_symbol_at_address. 
+
 Mon Oct 13 10:17:15 1997  Andrew Cagney  <cagney@b1.cygnus.com>
 
        * remote-sim.h: Clarify sim_read, sim_write MEM argument.
@@ -235,12 +259,10 @@ Mon Sep 30 13:56:11 1996  Fred Fish  <fnf@cygnus.com>
 
        * libiberty.h: Remove #ifndef PRIVATE_XMALLOC.
 
-start-sanitize-v850
 Sat Aug 31 13:27:06 1996  Jeffrey A Law  (law@cygnus.com)
 
        * dis-asm.h (print_insn_v850): Declare.
 
-end-sanitize-v850
 Tue Aug 13 16:10:30 1996  Stu Grossman  (grossman@critters.cygnus.com)
 
        * obstack.h:  Change bcopy to memcpy.  Works better on Posix
index 4e3c9ef..ec11cc8 100644 (file)
@@ -1,5 +1,6 @@
 /* Remote target system call callback support.
    Copyright 1997 Free Software Foundation, Inc.
+   Contributed by Cygnus Solutions.
 
 This file is part of GDB.
 
@@ -17,19 +18,36 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-/* ??? This interface isn't intended to be specific to any particular kind
-   of remote (hardware, simulator, whatever).  However, at the present
-   time it is only used by the simulators.  At some point this should be
-   an entity onto itself.  For example, it's wrong that the definitions of the
-   functions host_to_target_errno, target_to_host_open live in the simulator
-   sources.  It would also be wrong for such functions to live in gdb
-   sources.  Until such time perhaps it would be best to avoid adding
-   prototypes of functions (and thus expanding the definition of the
-   interface).  */
+/* This interface isn't intended to be specific to any particular kind
+   of remote (hardware, simulator, whatever).  As such, support for it
+   (e.g. sim/common/callback.c) should *not* live in the simulator source
+   tree, nor should it live in the gdb source tree.  */
+
+/* There are various ways to handle system calls:
+
+   1) Have a simulator intercept the appropriate trap instruction and
+   directly perform the system call on behalf of the target program.
+   This is the typical way of handling system calls for embedded targets.
+   [Handling system calls for embedded targets isn't that much of an
+   oxymoron as running compiler testsuites make use of the capability.]
+
+   This method of system call handling is done when STATE_ENVIRONMENT
+   is ENVIRONMENT_USER.
+
+   2) Have a simulator emulate the hardware as much as possible.
+   If the program running on the real hardware communicates with some sort
+   of target manager, one would want to be able to run this program on the
+   simulator as well.
+
+   This method of system call handling is done when STATE_ENVIRONMENT
+   is ENVIRONMENT_OPERATING.
+*/
 
 #ifndef CALLBACK_H
 #define CALLBACK_H
 
+/* ??? The reason why we check for va_start here should be documented.  */
+
 #ifndef va_start
 #include <ansidecl.h>
 #ifdef ANSI_PROTOTYPES
@@ -38,11 +56,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include <varargs.h>
 #endif
 #endif
+\f
+/* Mapping of host/target values.  */
+/* ??? For debugging purposes, one might want to add a string of the
+   name of the symbol.  */
 
-typedef struct host_callback_struct host_callback;
+typedef struct {
+  int host_val;
+  int target_val;
+} CB_TARGET_DEFS_MAP;
 
 #define MAX_CALLBACK_FDS 10
 
+typedef struct host_callback_struct host_callback;
+
 struct host_callback_struct 
 {
   int (*close) PARAMS ((host_callback *,int));
@@ -61,6 +88,9 @@ struct host_callback_struct
   void (*flush_stdout) PARAMS ((host_callback *));
   int (*write_stderr) PARAMS ((host_callback *, const char *, int));
   void (*flush_stderr) PARAMS ((host_callback *));
+  /* PTR is not `struct stat' because the target's value is stored.  */
+  int (*stat) PARAMS ((host_callback *, const char *, PTR));
+  int (*fstat) PARAMS ((host_callback *, int, PTR));
 
   /* When present, call to the client to give it the oportunity to
      poll any io devices for a request to quit (indicated by a nonzero
@@ -92,28 +122,120 @@ struct host_callback_struct
   char fdopen[MAX_CALLBACK_FDS];
   char alwaysopen[MAX_CALLBACK_FDS];
 
-  /* Marker for thse wanting to do sanity checks.
-     This should remain the last memeber of this struct to help catch
+  /* System call numbers.  */
+  CB_TARGET_DEFS_MAP *syscall_map;
+  /* Errno values.  */
+  CB_TARGET_DEFS_MAP *errno_map;
+  /* Flags to the open system call.  */
+  CB_TARGET_DEFS_MAP *open_map;
+  /* Signal numbers.  */
+  CB_TARGET_DEFS_MAP *signal_map;
+  /* Layout of `stat' struct.
+     The format is a series of "name,length" pairs separated by colons.
+     Empty space is indicated with a `name' of "space".
+     All padding must be explicitly mentioned.
+     Lengths are in bytes.  If this needs to be extended to bits,
+     use "name.bits".
+     Example: "st_dev,4:st_ino,4:st_mode,4:..."  */
+  const char *stat_map;
+
+  /* Marker for those wanting to do sanity checks.
+     This should remain the last member of this struct to help catch
      miscompilation errors. */
 #define HOST_CALLBACK_MAGIC 4705 /* teds constant */
   int magic;
 };
 
 extern host_callback default_callback;
-
-/* Mapping of host/target values.  */
-/* ??? For debugging purposes, one might want to add a string of the
-   name of the symbol.  */
-
-typedef struct {
-  int host_val;
-  int target_val;
-} target_defs_map;
-
-extern target_defs_map errno_map[];
-extern target_defs_map open_map[];
-
-extern int host_to_target_errno PARAMS ((int));
-extern int target_to_host_open PARAMS ((int));
+\f
+/* Canonical versions of system call numbers.
+   It's not intended to willy-nilly throw every system call ever heard
+   of in here.  Only include those that have an important use.  */
+
+#define        CB_SYS_exit     1
+#define        CB_SYS_open     2
+#define        CB_SYS_close    3
+#define        CB_SYS_read     4
+#define        CB_SYS_write    5
+#define        CB_SYS_lseek    6
+#define        CB_SYS_unlink   7
+#define        CB_SYS_getpid   8
+#define        CB_SYS_kill     9
+#define CB_SYS_fstat       10
+/*#define CB_SYS_sbrk  11 - not currently a system call, but reserved.  */
+
+/* ARGV support.  */
+#define CB_SYS_argvlen 12
+#define CB_SYS_argv    13
+
+/* These are extras added for one reason or another.  */
+#define CB_SYS_chdir   20
+#define CB_SYS_stat    21
+#define CB_SYS_chmod   22
+#define CB_SYS_utime   23
+#define CB_SYS_time    24
+\f
+/* Struct use to pass and return information necessary to perform a
+   system call.  */
+/* FIXME: Need to consider target word size.  */
+
+typedef struct cb_syscall {
+  /* The target's value of what system call to perform.  */
+  int func;
+  /* The arguments to the syscall.  */
+  long arg1, arg2, arg3, arg4;
+
+  /* The result.  */
+  long result;
+  /* Some system calls have two results.  */
+  long result2;
+  /* The target's errno value, or 0 if success.
+     This is converted to the target's value with host_to_target_errno.  */
+  int errcode;
+
+  /* Working space to be used by memory read/write callbacks.  */
+  long x1,x2;
+
+  /* Callbacks for reading/writing memory (e.g. for read/write syscalls).  */
+  unsigned long (*read_mem) PARAMS ((host_callback *, struct cb_syscall *, unsigned long taddr, char *buf, unsigned long bytes));
+  unsigned long (*write_mem) PARAMS ((host_callback *, struct cb_syscall *, unsigned long taddr, const char *buf, unsigned long bytes));
+} CB_SYSCALL;
+\f
+/* Return codes for various interface routines.  */
+
+typedef enum {
+  CB_RC_OK = 0,
+  /* generic error */
+  CB_RC_ERR,
+  /* either file not found or no read access */
+  CB_RC_ACCESS,
+  CB_RC_NO_MEM
+} CB_RC;
+
+/* Read in target values for system call numbers, errno values, signals.  */
+CB_RC cb_read_target_syscall_maps PARAMS ((host_callback *, const char *));
+
+/* Translate target to host syscall function numbers.  */
+int cb_target_to_host_syscall PARAMS ((host_callback *, int));
+
+/* Translate host to target errno value.  */
+int cb_host_to_target_errno PARAMS ((host_callback *, int));
+
+/* Translate target to host open flags.  */
+int cb_target_to_host_open PARAMS ((host_callback *, int));
+
+/* Translate target signal number to host.  */
+int cb_target_to_host_signal PARAMS ((host_callback *, int));
+
+/* Translate host signal number to target.  */
+int cb_host_to_target_signal PARAMS ((host_callback *, int));
+
+/* Translate host stat struct to target.  */
+struct stat; /* forward decl */
+int cb_host_to_target_stat PARAMS ((host_callback *, const struct stat *,
+                                   PTR, int));
+
+/* Perform a system call.  */
+CB_RC cb_syscall PARAMS ((host_callback *, CB_SYSCALL *));
 
 #endif