]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m32c/syscalls.c
1 /* syscalls.c --- implement system calls for the M32C simulator.
3 Copyright (C) 2005-2021 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 "sim/callback.h"
33 #include "targ-vals.h"
35 /* The current syscall callbacks we're using. */
36 static struct host_callback_struct
*callbacks
;
39 set_callbacks (struct host_callback_struct
*cb
)
45 /* A16 ABI: arg1 in r1l (QI) or r1 (HI) or stack
46 arg2 in r2 (HI) or stack
50 A24 ABI: arg1 in r0l (QI) or r0 (HI) or stack
54 return value in r0l (QI) r0 (HI) r2r0 (SI)
55 structs: pointer pushed on stack last
99 rv
= mem_get_qi (get_reg (sp
) + stackp
);
104 rv
= mem_get_hi (get_reg (sp
) + stackp
);
107 rv
= mem_get_psi (get_reg (sp
) + stackp
);
112 rv
= mem_get_si (get_reg (sp
) + stackp
);
120 read_target (char *buffer
, int address
, int count
, int asciiz
)
125 byte
= mem_get_qi (address
++);
127 if (asciiz
&& (byte
== 0))
134 write_target (char *buffer
, int address
, int count
, int asciiz
)
140 mem_put_qi (address
++, byte
);
141 if (asciiz
&& (byte
== 0))
147 #define PTRSZ (A16 ? 2 : 3)
149 static char *callnames
[] = {
175 m32c_syscall (int id
)
177 static char buf
[256];
181 stackp
= A16
? 3 : 4;
183 printf ("\033[31m/* SYSCALL(%d) = %s */\033[0m\n", id
, callnames
[id
]);
186 case TARGET_SYS_exit
:
190 printf ("[exit %d]\n", ec
);
191 step_result
= M32C_MAKE_EXITED (ec
);
195 case TARGET_SYS_open
:
197 int path
= arg (PTRSZ
);
198 int oflags
= arg (2);
199 int cflags
= arg (2);
201 read_target (buf
, path
, 256, 1);
203 printf ("open(\"%s\",0x%x,%#o) = ", buf
, oflags
, cflags
);
206 /* The callback vector ignores CFLAGS. */
207 rv
= callbacks
->open (callbacks
, buf
, oflags
);
213 h_oflags
|= O_WRONLY
;
219 h_oflags
|= O_APPEND
;
222 rv
= open (buf
, h_oflags
, cflags
);
230 case TARGET_SYS_close
:
235 rv
= callbacks
->close (callbacks
, fd
);
241 printf ("close(%d) = %d\n", fd
, rv
);
246 case TARGET_SYS_read
:
249 int addr
= arg (PTRSZ
);
252 if (count
> sizeof (buf
))
253 count
= sizeof (buf
);
255 rv
= callbacks
->read (callbacks
, fd
, buf
, count
);
257 rv
= read (fd
, buf
, count
);
259 printf ("read(%d,%d) = %d\n", fd
, count
, rv
);
261 write_target (buf
, addr
, rv
, 0);
266 case TARGET_SYS_write
:
269 int addr
= arg (PTRSZ
);
272 if (count
> sizeof (buf
))
273 count
= sizeof (buf
);
275 printf ("write(%d,0x%x,%d)\n", fd
, addr
, count
);
276 read_target (buf
, addr
, count
, 0);
280 rv
= callbacks
->write (callbacks
, fd
, buf
, count
);
282 rv
= write (fd
, buf
, count
);
284 printf ("write(%d,%d) = %d\n", fd
, count
, rv
);
289 case TARGET_SYS_getpid
:
293 case TARGET_SYS_gettimeofday
:
295 int tvaddr
= arg (PTRSZ
);
298 rv
= gettimeofday (&tv
, 0);
300 printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv
.tv_sec
,
302 mem_put_si (tvaddr
, tv
.tv_sec
);
303 mem_put_si (tvaddr
+ 4, tv
.tv_usec
);
308 case TARGET_SYS_kill
:
315 printf ("[signal %d]\n", sig
);
316 step_result
= M32C_MAKE_STOPPED (sig
);
323 int heaptop_arg
= arg (PTRSZ
);
325 printf ("sbrk: heap top set to %x\n", heaptop_arg
);
326 heaptop
= heaptop_arg
;
328 heapbottom
= heaptop_arg
;