1 /* syscalls.c --- implement system calls for the RX simulator.
3 Copyright (C) 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "gdb/callback.h"
36 /* The current syscall callbacks we're using. */
37 static struct host_callback_struct
*callbacks
;
40 set_callbacks (struct host_callback_struct
*cb
)
46 /* Arguments 1..4 are in R1..R4, remainder on stack.
48 Return value in R1..R4 as needed.
49 structs bigger than 16 bytes: pointer pushed on stack last
51 We only support arguments that fit in general registers.
53 The system call number is in R5. We expect ssycalls to look like
71 return get_reg (argp
);
73 rv
= mem_get_si (get_reg (sp
) + stackp
);
79 read_target (char *buffer
, int address
, int count
, int asciiz
)
84 byte
= mem_get_qi (address
++);
86 if (asciiz
&& (byte
== 0))
93 write_target (char *buffer
, int address
, int count
, int asciiz
)
99 mem_put_qi (address
++, byte
);
100 if (asciiz
&& (byte
== 0))
106 #define PTRSZ (A16 ? 2 : 3)
108 static char *callnames
[] = {
136 static char buf
[256];
142 printf ("\033[31m/* SYSCALL(%d) = %s */\033[0m\n", id
, id
<= SYS_link
? callnames
[id
] : "unknown");
149 printf ("[exit %d]\n", ec
);
150 return RX_MAKE_EXITED (ec
);
157 /* The open function is defined as taking a variable number of arguments
158 because the third parameter to it is optional:
159 open (const char * filename, int flags, ...);
160 Hence the oflags and cflags arguments will be on the stack and we need
161 to skip the (empty) argument registers r3 and r4. */
166 read_target (buf
, path
, 256, 1);
168 printf ("open(\"%s\",0x%x,%#o) = ", buf
, oflags
, cflags
);
171 /* The callback vector ignores CFLAGS. */
172 rv
= callbacks
->open (callbacks
, buf
, oflags
);
178 h_oflags
|= O_WRONLY
;
184 h_oflags
|= O_APPEND
;
187 rv
= open (buf
, h_oflags
, cflags
);
200 rv
= callbacks
->close (callbacks
, fd
);
206 printf ("close(%d) = %d\n", fd
, rv
);
217 if (count
> sizeof (buf
))
218 count
= sizeof (buf
);
220 rv
= callbacks
->read (callbacks
, fd
, buf
, count
);
222 rv
= read (fd
, buf
, count
);
224 printf ("read(%d,%d) = %d\n", fd
, count
, rv
);
226 write_target (buf
, addr
, rv
, 0);
237 if (count
> sizeof (buf
))
238 count
= sizeof (buf
);
240 printf ("write(%d,0x%x,%d)\n", fd
, addr
, count
);
241 read_target (buf
, addr
, count
, 0);
245 rv
= callbacks
->write (callbacks
, fd
, buf
, count
);
247 rv
= write (fd
, buf
, count
);
249 printf ("write(%d,%d) = %d\n", fd
, count
, rv
);
258 case SYS_gettimeofday
:
263 rv
= gettimeofday (&tv
, 0);
265 printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv
.tv_sec
,
267 mem_put_si (tvaddr
, tv
.tv_sec
);
268 mem_put_si (tvaddr
+ 4, tv
.tv_usec
);
280 printf ("[signal %d]\n", sig
);
281 return RX_MAKE_STOPPED (sig
);
288 int heaptop_arg
= arg ();
290 printf ("sbrk: heap top set to %x\n", heaptop_arg
);
291 heaptop
= heaptop_arg
;
293 heapbottom
= heaptop_arg
;
300 mem_put_si (addr
, rx_cycles
+ mem_usage_cycles());
305 return RX_MAKE_STEPPED ();
This page took 0.034736 seconds and 4 git commands to generate.