OSDN Git Service

b5c8fc58c1c1e321a716b554c9b6feed18fa4df2
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / metag / bits / syscalls.h
1 /*
2  * Copyright (C) 2013 Imagination Technologies Ltd.
3  *
4  * Licensed under LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
5  *
6  */
7
8 #ifndef _BITS_SYSCALLS_H
9 #define _BITS_SYSCALLS_H
10 #ifndef _SYSCALL_H
11 # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
12 #endif
13
14 /*
15   Meta version adapted from the ARM version.
16 */
17
18 #define SYS_ify(syscall_name)  (__NR_##syscall_name)
19
20 #ifdef __ASSEMBLER__
21
22 /* Call a given syscall, with arguments loaded. */
23 #undef DO_CALL
24 #define DO_CALL(syscall_name, args)             \
25   MOV D1Re0, #SYS_ify (syscall_name);           \
26   SWITCH #0x440001
27
28 #else
29
30 #include <errno.h>
31
32 #undef INLINE_SYSCALL_NCS
33 #define INLINE_SYSCALL_NCS(name, nr, args...)                           \
34 (__extension__                                                          \
35   ({ unsigned int _inline_sys_result = INTERNAL_SYSCALL_NCS (name, , nr, args); \
36     if (unlikely(INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, )))      \
37       {                                                                 \
38         __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, ));    \
39         _inline_sys_result = (unsigned int) -1;                         \
40       }                                                                 \
41     (int) _inline_sys_result; })                                        \
42 )
43
44 #undef INTERNAL_SYSCALL_DECL
45 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
46
47 #undef INTERNAL_SYSCALL_NCS
48 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...)                    \
49 (__extension__                                                          \
50   ({unsigned int __sys_result;                                          \
51     {                                                                   \
52       register int _result __asm__ ("D0Re0"), _nr __asm__ ("D1Re0");    \
53       LOAD_ARGS_##nr (args);                                            \
54       _nr = (name);                                                     \
55       __asm__ volatile ("SWITCH  #0x440001 ! syscall " #name            \
56                         : "=r" (_result)                                \
57                         : "d" (_nr) ASM_ARGS_##nr                       \
58                         : "memory");                                    \
59       __sys_result = _result;                                           \
60     }                                                                   \
61     (int) __sys_result; })                                              \
62 )
63
64 #undef INTERNAL_SYSCALL_ERROR_P
65 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
66   ((unsigned int) (val) >= 0xfffff001u)
67
68 #undef INTERNAL_SYSCALL_ERRNO
69 #define INTERNAL_SYSCALL_ERRNO(val, err)        (-(val))
70
71 #define LOAD_ARGS_0()
72 #define ASM_ARGS_0
73 #define LOAD_ARGS_1(a1)                                 \
74   register int _a1 __asm__ ("D1Ar1") = (int) (a1);      \
75   LOAD_ARGS_0 ()
76 #define ASM_ARGS_1      ASM_ARGS_0, "d" (_a1)
77 #define LOAD_ARGS_2(a1, a2)                             \
78   register int _a2 __asm__ ("D0Ar2") = (int) (a2);      \
79   LOAD_ARGS_1 (a1)
80 #define ASM_ARGS_2      ASM_ARGS_1, "d" (_a2)
81 #define LOAD_ARGS_3(a1, a2, a3)                         \
82   register int _a3 __asm__ ("D1Ar3") = (int) (a3);      \
83   LOAD_ARGS_2 (a1, a2)
84 #define ASM_ARGS_3      ASM_ARGS_2, "d" (_a3)
85 #define LOAD_ARGS_4(a1, a2, a3, a4)                     \
86   register int _a4 __asm__ ("D0Ar4") = (int) (a4);      \
87   LOAD_ARGS_3 (a1, a2, a3)
88 #define ASM_ARGS_4      ASM_ARGS_3, "d" (_a4)
89 #define LOAD_ARGS_5(a1, a2, a3, a4, a5)                 \
90   register int _a5 __asm__ ("D1Ar5") = (int) (a5);      \
91   LOAD_ARGS_4 (a1, a2, a3, a4)
92 #define ASM_ARGS_5      ASM_ARGS_4, "d" (_a5)
93 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6)             \
94   register int _a6 __asm__ ("D0Ar6") = (int) (a6);      \
95   LOAD_ARGS_5 (a1, a2, a3, a4, a5)
96 #define ASM_ARGS_6      ASM_ARGS_5, "d" (_a6)
97
98 #endif /* __ASSEMBLER__ */
99 #endif /* _BITS_SYSCALLS_H */