1 /* system calls for the Visium processor.
3 Copyright (c) 2015 Rolls-Royce Controls and Data Services Limited.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of Rolls-Royce Controls and Data Services Limited nor
15 the names of its contributors may be used to endorse or promote products
16 derived from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 THE POSSIBILITY OF SUCH DAMAGE. */
30 #include <sys/types.h>
45 unsigned p1
, p2
, p3
, p4
;
50 extern struct file_register2 _sim_fileio_register
;
52 static volatile struct file_register2
*const fileio
= &_sim_fileio_register
;
55 do_syscall (unsigned action
, unsigned p1
, unsigned p2
,
56 unsigned p3
, unsigned p4
, int *error
)
62 fileio
->action
= action
;
64 *error
= (int) fileio
->error
;
65 return (int) fileio
->retval
;
69 do_syscall (unsigned action
, unsigned p1
, unsigned p2
,
70 unsigned p3
, unsigned p4
, int *error
)
75 /* There is a two instruction delay after the software interrupt is
76 initiated, to allow it to take effect. */
82 moviu r5,%%u 0x20002208\n\
83 movil r5,%%l 0x20002208\n\
90 : "=r" (ret
), "=r" (err
)
91 : "r" (action
), "r" (p1
), "r" (p2
), "r" (p3
), "r" (p4
)
92 : "r1", "r2", "r3", "r4", "r5");
105 status
= do_syscall (SYS_close
, fildes
, 0, 0, 0, &error
);
108 errno
= __hosted_from_gdb_errno (error
);
113 void _exit (int) __attribute ((__noreturn__
));
119 asm volatile ("stop 0,%0" : : "r" (code
& 0xff));
122 do_syscall (SYS_exit
, code
, 0, 0, 0, &error
);
125 /* Should never reach this point. Since this function is not supposed to
126 return, pretend to get stuck in a loop. */
132 extern long long _sim_cmdline_header
;
137 return _sim_cmdline_header
;
142 fstat (int fildes
, struct stat
*st
)
148 status
= do_syscall (SYS_fstat
, fildes
, (unsigned) &gst
, 0, 0, &error
);
151 errno
= __hosted_from_gdb_errno (error
);
153 __hosted_from_gdb_stat (&gst
, st
);
159 gettimeofday (struct timeval
*__p
, void *__tz
)
161 struct timeval
*tv
= __p
;
162 struct timezone
*tz
= __tz
;
163 struct gdb_timeval gtv
;
167 status
= do_syscall (SYS_gettimeofday
, (unsigned) >v
, 0, 0, 0, &error
);
169 /* The timezone argument is not really supported so:
170 Local time is GMT, no daylight saving */
173 tz
->tz_minuteswest
= 0;
178 errno
= __hosted_from_gdb_errno (error
);
180 __hosted_from_gdb_timeval (>v
, tv
);
191 status
= do_syscall (SYS_isatty
, fildes
, 0, 0, 0, &error
);
194 errno
= __hosted_from_gdb_errno (error
);
200 lseek (int fildes
, off_t offset
, int whence
)
205 ret
= do_syscall (SYS_lseek
, fildes
, offset
,
206 __hosted_to_gdb_lseek_flags (whence
), 0, &error
);
208 if (ret
== (off_t
)-1)
209 errno
= __hosted_from_gdb_errno (error
);
215 open (const char *path
, int oflag
, ...)
220 int len
= strlen (path
) + 1;
225 va_start (ap
, oflag
);
226 mode
= va_arg (ap
, mode_t
);
230 status
= do_syscall (SYS_open
, (unsigned) path
, len
,
231 __hosted_to_gdb_open_flags (oflag
),
232 __hosted_to_gdb_mode_t (mode
), &error
);
235 errno
= __hosted_from_gdb_errno (error
);
241 read (int fildes
, void *buf
, size_t nbyte
)
246 status
= do_syscall (SYS_read
, fildes
, (unsigned) buf
, nbyte
, 0, &error
);
249 errno
= __hosted_from_gdb_errno (error
);
255 rename (const char *old
, const char *new)
259 int oldlen
= strlen (old
) + 1;
260 int newlen
= strlen (new) + 1;
262 status
= do_syscall (SYS_rename
, (unsigned) old
, oldlen
, (unsigned) new,
266 errno
= __hosted_from_gdb_errno (error
);
272 stat (const char *path
, struct stat
*st
)
277 int len
= strlen (path
) + 1;
279 status
= do_syscall (SYS_stat
, (unsigned) path
, len
, (unsigned) &gst
, 0,
283 errno
= __hosted_from_gdb_errno (error
);
285 __hosted_from_gdb_stat (&gst
, st
);
291 system (const char *string
)
295 int len
= strlen (string
) + 1;
297 status
= do_syscall (SYS_system
, (unsigned) string
, len
, 0, 0, &error
);
303 unlink (const char *path
)
307 int len
= strlen (path
) + 1;
309 status
= do_syscall (SYS_unlink
, (unsigned) path
, len
, 0, 0, &error
);
312 errno
= __hosted_from_gdb_errno (error
);
318 write (int fildes
, const void *buf
, size_t nbyte
)
323 status
= do_syscall (SYS_write
, fildes
, (unsigned) buf
, nbyte
, 0, &error
);
326 errno
= __hosted_from_gdb_errno (error
);
331 extern clock_t _sim_clock
;