1 /* Remote target system call support.
2 Copyright 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
5 This file is part of GDB.
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 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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. K&R C must be
31 #ifdef ANSI_PROTOTYPES
44 #include "remote-sim.h"
45 #include "targ-vals.h"
51 /* When doing file read/writes, do this many bytes at a time. */
52 #define FILE_XFR_SIZE 4096
54 /* Maximum length of a path name. */
56 #define MAX_PATH_LEN 1024
59 /* Utility of cb_syscall to fetch a path name from the target.
60 The result is 0 for success or a target errno value. */
63 get_path (cb
, sc
, buf
, buflen
, addr
)
72 for (p
= buf
, pend
= buf
+ buflen
; p
< pend
; ++p
, ++addr
)
74 /* No, it isn't expected that this would cause one transaction with
75 the remote target for each byte. The target could send the
76 path name along with the syscall request, and cache the file
78 unsigned int count
= (*sc
->read_mem
) (cb
, sc
, addr
, p
, 1);
86 return TARGET_ENAMETOOLONG
;
90 /* Perform a system call on behalf of the target. */
97 /* ??? Need to consider target word size. */
98 long result
= 0, errcode
= 0;
100 switch (cb_target_to_host_syscall (cb
, sc
->func
))
102 #if 0 /* FIXME: wip */
103 case CB_SYS_argvlen
:
105 /* Compute how much space is required to store the argv,envp
106 strings so that the program can allocate the space and then
107 call SYS_argv to fetch the values. */
108 int addr_size
= cb
->addr_size
;
109 int argc
,envc
,arglen
,envlen
;
110 const char **argv
= cb
->init_argv
;
111 const char **envp
= cb
->init_envp
;
116 for ( ; argv
[argc
]; ++argc
)
117 arglen
+= strlen (argv
[argc
]) + 1;
122 for ( ; envp
[envc
]; ++envc
)
123 envlen
+= strlen (envp
[envc
]) + 1;
125 result
= arglen
+ envlen
;
131 /* Pointer to target's buffer. */
132 SIM_ADDR tbuf
= sc
->arg1
;
134 int bufsize
= sc
->arg2
;
135 /* Q is the target address of where all the strings go. */
137 int word_size
= cb
->word_size
;
139 const char **argv
= cb
->init_argv
;
140 const char **envp
= cb
->init_envp
;
145 for ( ; argv
[argc
]; ++argc
)
147 int len
= strlen (argv
[argc
]);
148 int written
= (*sc
->write_mem
) (cb
, sc
, tbuf
, argv
[argc
], len
+ 1);
152 errcode
= TARGET_EINVAL
;
158 if ((*sc
->write_mem
) (cb
, sc
, tbuf
, "", 1) != 1)
161 errcode
= TARGET_EINVAL
;
168 for ( ; envp
[envc
]; ++envc
)
170 int len
= strlen (envp
[envc
]);
171 int written
= (*sc
->write_mem
) (cb
, sc
, tbuf
, envp
[envc
], len
+ 1);
175 errcode
= TARGET_EINVAL
;
181 if ((*sc
->write_mem
) (cb
, sc
, tbuf
, "", 1) != 1)
184 errcode
= TARGET_EINVAL
;
194 /* Caller must catch and handle. */
199 char path
[MAX_PATH_LEN
];
202 errcode
= get_path (cb
, sc
, path
, MAX_PATH_LEN
, sc
->arg1
);
209 result
= (*cb
->open
) (cb
, path
, sc
->arg2
/*, sc->arg3*/);
214 result
= (*cb
->close
) (cb
, sc
->arg1
);
219 /* ??? Perfect handling of error conditions may require only one
220 call to cb->read. One can't assume all the data is
221 contiguously stored in host memory so that would require
222 malloc'ing/free'ing the space. Maybe later. */
223 char buf
[FILE_XFR_SIZE
];
225 SIM_ADDR addr
= sc
->arg2
;
226 size_t count
= sc
->arg3
;
227 size_t bytes_read
= 0;
232 result
= (int) (*cb
->read
) (cb
, fd
, buf
,
233 count
< FILE_XFR_SIZE
? count
: FILE_XFR_SIZE
);
236 bytes_written
= (*sc
->write_mem
) (cb
, sc
, addr
, buf
, result
);
237 if (bytes_written
!= result
)
240 errcode
= TARGET_EINVAL
;
243 bytes_read
+= result
;
253 /* ??? Perfect handling of error conditions may require only one
254 call to cb->write. One can't assume all the data is
255 contiguously stored in host memory so that would require
256 malloc'ing/free'ing the space. Maybe later. */
257 char buf
[FILE_XFR_SIZE
];
259 SIM_ADDR addr
= sc
->arg2
;
260 size_t count
= sc
->arg3
;
262 size_t bytes_written
= 0;
266 int bytes_to_read
= count
< FILE_XFR_SIZE
? count
: FILE_XFR_SIZE
;
267 bytes_read
= (*sc
->read_mem
) (cb
, sc
, addr
, buf
, bytes_to_read
);
268 if (bytes_read
!= bytes_to_read
)
271 errcode
= TARGET_EINVAL
;
275 result
= (int) (*cb
->write_stdout
) (cb
, buf
, bytes_read
);
277 result
= (int) (*cb
->write
) (cb
, fd
, buf
, bytes_read
);
280 bytes_written
+= result
;
284 result
= bytes_written
;
291 errcode
= TARGET_ENOSYS
;
293 errcode
= TARGET_EINVAL
;
301 sc
->errcode
= (*cb
->get_errno
) (cb
);
303 sc
->errcode
= errcode
;
This page took 0.056016 seconds and 5 git commands to generate.