source: trunk/libs/newlib/src/libgloss/riscv/internal_syscall.h @ 468

Last change on this file since 468 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.4 KB
Line 
1/* Copyright (c) 2017  SiFive Inc. All rights reserved.
2
3   This copyrighted material is made available to anyone wishing to use,
4   modify, copy, or redistribute it subject to the terms and conditions
5   of the FreeBSD License.   This program is distributed in the hope that
6   it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7   including the implied warranties of MERCHANTABILITY or FITNESS FOR
8   A PARTICULAR PURPOSE.  A copy of this license is available at
9   http://www.opensource.org/licenses.
10*/
11
12#ifndef _INTERNAL_SYSCALL_H
13#define _INTERNAL_SYSCALL_H
14
15#include <errno.h>
16
17static inline long
18__syscall_error(long a0)
19{
20  errno = -a0;
21  return -1;
22}
23
24static inline long
25__internal_syscall(long n, long _a0, long _a1, long _a2, long _a3, long _a4, long _a5)
26{
27  register long a0 asm("a0") = _a0;
28  register long a1 asm("a1") = _a1;
29  register long a2 asm("a2") = _a2;
30  register long a3 asm("a3") = _a3;
31  register long a4 asm("a4") = _a4;
32  register long a5 asm("a5") = _a5;
33
34#ifdef __riscv_32e
35  register long syscall_id asm("t0") = n;
36#else
37  register long syscall_id asm("a7") = n;
38#endif
39
40  asm volatile ("scall"
41                : "+r"(a0) : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(syscall_id));
42
43  if (a0 < 0)
44    return __syscall_error (a0);
45  else
46    return a0;
47}
48
49#define syscall_errno(n, a, b, c, d, e, f) \
50        __internal_syscall(n, (long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f))
51
52#endif
Note: See TracBrowser for help on using the repository browser.