[444] | 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 | |
---|
| 17 | static inline long |
---|
| 18 | __syscall_error(long a0) |
---|
| 19 | { |
---|
| 20 | errno = -a0; |
---|
| 21 | return -1; |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | static 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 |
---|