* callback.c (os_stat): Make 3rd arg a host struct stat ptr.
[deliverable/binutils-gdb.git] / include / callback.h
CommitLineData
efa86080
DE
1/* Remote target system call callback support.
2 Copyright 1997 Free Software Foundation, Inc.
8d5306e7 3 Contributed by Cygnus Solutions.
efa86080
DE
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
8d5306e7
DE
21/* This interface isn't intended to be specific to any particular kind
22 of remote (hardware, simulator, whatever). As such, support for it
23 (e.g. sim/common/callback.c) should *not* live in the simulator source
24 tree, nor should it live in the gdb source tree. */
25
26/* There are various ways to handle system calls:
27
28 1) Have a simulator intercept the appropriate trap instruction and
29 directly perform the system call on behalf of the target program.
30 This is the typical way of handling system calls for embedded targets.
31 [Handling system calls for embedded targets isn't that much of an
32 oxymoron as running compiler testsuites make use of the capability.]
33
34 This method of system call handling is done when STATE_ENVIRONMENT
35 is ENVIRONMENT_USER.
36
37 2) Have a simulator emulate the hardware as much as possible.
38 If the program running on the real hardware communicates with some sort
39 of target manager, one would want to be able to run this program on the
40 simulator as well.
41
42 This method of system call handling is done when STATE_ENVIRONMENT
43 is ENVIRONMENT_OPERATING.
44*/
bf008f98 45
9d10b92d
DE
46#ifndef CALLBACK_H
47#define CALLBACK_H
48
8d5306e7
DE
49/* ??? The reason why we check for va_start here should be documented. */
50
8902803f
MM
51#ifndef va_start
52#include <ansidecl.h>
53#ifdef ANSI_PROTOTYPES
54#include <stdarg.h>
55#else
56#include <varargs.h>
57#endif
58#endif
8d5306e7
DE
59\f
60/* Mapping of host/target values. */
61/* ??? For debugging purposes, one might want to add a string of the
62 name of the symbol. */
8902803f 63
8d5306e7
DE
64typedef struct {
65 int host_val;
66 int target_val;
67} CB_TARGET_DEFS_MAP;
9d10b92d
DE
68
69#define MAX_CALLBACK_FDS 10
70
8d5306e7
DE
71typedef struct host_callback_struct host_callback;
72
9d10b92d
DE
73struct host_callback_struct
74{
75 int (*close) PARAMS ((host_callback *,int));
76 int (*get_errno) PARAMS ((host_callback *));
77 int (*isatty) PARAMS ((host_callback *, int));
78 int (*lseek) PARAMS ((host_callback *, int, long , int));
79 int (*open) PARAMS ((host_callback *, const char*, int mode));
80 int (*read) PARAMS ((host_callback *,int, char *, int));
81 int (*read_stdin) PARAMS (( host_callback *, char *, int));
82 int (*rename) PARAMS ((host_callback *, const char *, const char *));
83 int (*system) PARAMS ((host_callback *, const char *));
84 long (*time) PARAMS ((host_callback *, long *));
85 int (*unlink) PARAMS ((host_callback *, const char *));
86 int (*write) PARAMS ((host_callback *,int, const char *, int));
87 int (*write_stdout) PARAMS ((host_callback *, const char *, int));
6d685937
AC
88 void (*flush_stdout) PARAMS ((host_callback *));
89 int (*write_stderr) PARAMS ((host_callback *, const char *, int));
90 void (*flush_stderr) PARAMS ((host_callback *));
8d5306e7
DE
91 /* PTR is not `struct stat' because the target's value is stored. */
92 int (*stat) PARAMS ((host_callback *, const char *, PTR));
93 int (*fstat) PARAMS ((host_callback *, int, PTR));
9d10b92d 94
8517f62b
AC
95 /* When present, call to the client to give it the oportunity to
96 poll any io devices for a request to quit (indicated by a nonzero
97 return value). */
98 int (*poll_quit) PARAMS ((host_callback *));
99
9d10b92d 100 /* Used when the target has gone away, so we can close open
e1144153 101 handles and free memory etc etc. */
9d10b92d
DE
102 int (*shutdown) PARAMS ((host_callback *));
103 int (*init) PARAMS ((host_callback *));
104
6d685937 105 /* depreciated, use vprintf_filtered - Talk to the user on a console. */
9d10b92d 106 void (*printf_filtered) PARAMS ((host_callback *, const char *, ...));
6d685937 107
09e34873 108 /* Talk to the user on a console. */
8902803f 109 void (*vprintf_filtered) PARAMS ((host_callback *, const char *, va_list));
6d685937 110
efa86080 111 /* Same as vprintf_filtered but to stderr. */
8902803f 112 void (*evprintf_filtered) PARAMS ((host_callback *, const char *, va_list));
efa86080 113
e1144153
DE
114 /* Print an error message and "exit".
115 In the case of gdb "exiting" means doing a longjmp back to the main
116 command loop. */
117 void (*error) PARAMS ((host_callback *, const char *, ...));
9d10b92d
DE
118
119 int last_errno; /* host format */
120
121 int fdmap[MAX_CALLBACK_FDS];
122 char fdopen[MAX_CALLBACK_FDS];
123 char alwaysopen[MAX_CALLBACK_FDS];
8517f62b 124
8d5306e7
DE
125 /* System call numbers. */
126 CB_TARGET_DEFS_MAP *syscall_map;
127 /* Errno values. */
128 CB_TARGET_DEFS_MAP *errno_map;
129 /* Flags to the open system call. */
130 CB_TARGET_DEFS_MAP *open_map;
131 /* Signal numbers. */
132 CB_TARGET_DEFS_MAP *signal_map;
133 /* Layout of `stat' struct.
134 The format is a series of "name,length" pairs separated by colons.
135 Empty space is indicated with a `name' of "space".
136 All padding must be explicitly mentioned.
137 Lengths are in bytes. If this needs to be extended to bits,
138 use "name.bits".
139 Example: "st_dev,4:st_ino,4:st_mode,4:..." */
140 const char *stat_map;
141
142 /* Marker for those wanting to do sanity checks.
143 This should remain the last member of this struct to help catch
8517f62b
AC
144 miscompilation errors. */
145#define HOST_CALLBACK_MAGIC 4705 /* teds constant */
146 int magic;
9d10b92d
DE
147};
148
149extern host_callback default_callback;
8d5306e7
DE
150\f
151/* Canonical versions of system call numbers.
152 It's not intended to willy-nilly throw every system call ever heard
153 of in here. Only include those that have an important use. */
154
155#define CB_SYS_exit 1
156#define CB_SYS_open 2
157#define CB_SYS_close 3
158#define CB_SYS_read 4
159#define CB_SYS_write 5
160#define CB_SYS_lseek 6
161#define CB_SYS_unlink 7
162#define CB_SYS_getpid 8
163#define CB_SYS_kill 9
164#define CB_SYS_fstat 10
165/*#define CB_SYS_sbrk 11 - not currently a system call, but reserved. */
166
167/* ARGV support. */
168#define CB_SYS_argvlen 12
169#define CB_SYS_argv 13
170
171/* These are extras added for one reason or another. */
172#define CB_SYS_chdir 20
173#define CB_SYS_stat 21
174#define CB_SYS_chmod 22
175#define CB_SYS_utime 23
176#define CB_SYS_time 24
177\f
178/* Struct use to pass and return information necessary to perform a
179 system call. */
180/* FIXME: Need to consider target word size. */
181
182typedef struct cb_syscall {
183 /* The target's value of what system call to perform. */
184 int func;
185 /* The arguments to the syscall. */
186 long arg1, arg2, arg3, arg4;
187
188 /* The result. */
189 long result;
190 /* Some system calls have two results. */
191 long result2;
192 /* The target's errno value, or 0 if success.
193 This is converted to the target's value with host_to_target_errno. */
194 int errcode;
195
196 /* Working space to be used by memory read/write callbacks. */
197 long x1,x2;
198
199 /* Callbacks for reading/writing memory (e.g. for read/write syscalls). */
200 unsigned long (*read_mem) PARAMS ((host_callback *, struct cb_syscall *, unsigned long taddr, char *buf, unsigned long bytes));
201 unsigned long (*write_mem) PARAMS ((host_callback *, struct cb_syscall *, unsigned long taddr, const char *buf, unsigned long bytes));
202} CB_SYSCALL;
203\f
204/* Return codes for various interface routines. */
205
206typedef enum {
207 CB_RC_OK = 0,
208 /* generic error */
209 CB_RC_ERR,
210 /* either file not found or no read access */
211 CB_RC_ACCESS,
212 CB_RC_NO_MEM
213} CB_RC;
214
215/* Read in target values for system call numbers, errno values, signals. */
216CB_RC cb_read_target_syscall_maps PARAMS ((host_callback *, const char *));
217
218/* Translate target to host syscall function numbers. */
219int cb_target_to_host_syscall PARAMS ((host_callback *, int));
220
221/* Translate host to target errno value. */
222int cb_host_to_target_errno PARAMS ((host_callback *, int));
223
224/* Translate target to host open flags. */
225int cb_target_to_host_open PARAMS ((host_callback *, int));
226
227/* Translate target signal number to host. */
228int cb_target_to_host_signal PARAMS ((host_callback *, int));
229
230/* Translate host signal number to target. */
231int cb_host_to_target_signal PARAMS ((host_callback *, int));
232
233/* Translate host stat struct to target. */
234struct stat; /* forward decl */
235int cb_host_to_target_stat PARAMS ((host_callback *, const struct stat *,
236 PTR, int));
237
238/* Perform a system call. */
239CB_RC cb_syscall PARAMS ((host_callback *, CB_SYSCALL *));
9d10b92d
DE
240
241#endif
This page took 0.062791 seconds and 4 git commands to generate.