OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [libposix/] [include/] [posix/] [bits/] [syscalls.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#ifndef _BITS_SYSCALLS_H
2
#define _BITS_SYSCALLS_H
3
#ifndef _SYSCALL_H
4
# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
5
#endif
6
 
7
/*
8
   Some of the sneaky macros in the code were taken from
9
   glibc-2.3.2/sysdeps/unix/sysv/linux/arm/sysdep.h
10
*/
11
 
12
#define SYS_ify(syscall_name)  (__NR_##syscall_name)
13
 
14
#ifdef __ASSEMBLER__
15
 
16
/* Call a given syscall, with arguments loaded.  For EABI, we must
17
   save and restore r7 for the syscall number.  Unlike the DO_CALL
18
   macro in glibc, this macro does not load syscall arguments.  */
19
#undef DO_CALL
20
#if defined(__ARM_EABI__)
21
#define DO_CALL(syscall_name)                   \
22
    mov ip, r7;                                 \
23
    ldr r7, =SYS_ify (syscall_name);            \
24
    swi 0x0;                                    \
25
    mov r7, ip;
26
#else
27
#define DO_CALL(syscall_name)                   \
28
    swi SYS_ify (syscall_name);
29
#endif
30
 
31
#else
32
 
33
#include <errno.h>
34
 
35
#undef _syscall0
36
#define _syscall0(type,name) \
37
type name(void) \
38
{ \
39
return (type) (INLINE_SYSCALL(name, 0)); \
40
}
41
 
42
#undef _syscall1
43
#define _syscall1(type,name,type1,arg1) \
44
type name(type1 arg1) \
45
{ \
46
return (type) (INLINE_SYSCALL(name, 1, arg1)); \
47
}
48
 
49
#undef _syscall2
50
#define _syscall2(type,name,type1,arg1,type2,arg2) \
51
type name(type1 arg1,type2 arg2) \
52
{ \
53
return (type) (INLINE_SYSCALL(name, 2, arg1, arg2)); \
54
}
55
 
56
#undef _syscall3
57
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
58
type name(type1 arg1,type2 arg2,type3 arg3) \
59
{ \
60
return (type) (INLINE_SYSCALL(name, 3, arg1, arg2, arg3)); \
61
}
62
 
63
#undef _syscall4
64
#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
65
type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
66
{ \
67
return (type) (INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4)); \
68
}
69
 
70
#undef _syscall5
71
#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
72
          type5,arg5) \
73
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
74
{ \
75
return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
76
}
77
 
78
#undef _syscall6
79
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
80
          type5,arg5,type6,arg6) \
81
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
82
{ \
83
return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \
84
}
85
 
86
#undef _syscall7
87
#define _syscall7(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
88
          type5,arg5,type6,arg6,type7,arg7) \
89
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6,type7 arg7) \
90
{ \
91
return (type) (INLINE_SYSCALL(name, 7, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); \
92
}
93
 
94
 
95
#undef INLINE_SYSCALL
96
#define INLINE_SYSCALL(name, nr, args...)                               \
97
  ({ unsigned int _inline_sys_result = INTERNAL_SYSCALL (name, , nr, args);     \
98
     if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ), 0))  \
99
       {                                                                \
100
         __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, ));           \
101
         _inline_sys_result = (unsigned int) -1;                                \
102
       }                                                                \
103
     (int) _inline_sys_result; })
104
 
105
#undef INTERNAL_SYSCALL_DECL
106
#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
107
 
108
#undef INTERNAL_SYSCALL
109
#if defined(__ARM_EABI__)
110
#if !defined(__thumb__)
111
#define INTERNAL_SYSCALL(name, err, nr, args...)                        \
112
  ({unsigned int __sys_result;                                          \
113
     {                                                                  \
114
       register int _a1 __asm__ ("r0"), _nr __asm__ ("r7");                     \
115
       LOAD_ARGS_##nr (args)                                            \
116
       _nr = SYS_ify(name);                                             \
117
       __asm__ volatile ("swi   0x0     @ syscall " #name               \
118
                     : "=r" (_a1)                                       \
119
                     : "r" (_nr) ASM_ARGS_##nr                          \
120
                     : "memory");                                       \
121
       __sys_result = _a1;                                              \
122
     }                                                                  \
123
     (int) __sys_result; })
124
#else /* !defined(__thumb__) */
125
/* So hide the use of r7 from the compiler, this would be a lot
126
 * easier but for the fact that the syscalls can exceed 255.
127
 * For the moment the LOAD_ARG_7 is sacrificed.
128
 */
129
#define INTERNAL_SYSCALL(name, err, nr, args...)                \
130
  ({ unsigned int __sys_result;                                  \
131
    {                                                           \
132
      register int _a1 asm ("a1");                              \
133
      LOAD_ARGS_##nr (args)                                     \
134
        register int _v3 asm ("v3") = (int) (SYS_ify(name));    \
135
      asm volatile ("push       {r7}\n"                         \
136
                    "\tmov      r7, v3\n"                       \
137
                    "\tswi      0       @ syscall " #name "\n"  \
138
                    "\tpop      {r7}"                           \
139
                   : "=r" (_a1)                                 \
140
                    : "r" (_v3) ASM_ARGS_##nr                   \
141
                    : "memory");                                \
142
      __sys_result = _a1;                                        \
143
    }                                                           \
144
    (int) __sys_result; })
145
#endif /*!defined(__thumb__)*/
146
#else /* !defined(__ARM_EABI__) */ 
147
#if !defined(__thumb__)
148
#define INTERNAL_SYSCALL(name, err, nr, args...)                \
149
  ({ unsigned int __sys_result;                                 \
150
     {                                                          \
151
       register int _a1 __asm__ ("a1");                         \
152
       LOAD_ARGS_##nr (args)                                    \
153
       __asm__ volatile ("swi   %1      @ syscall " #name       \
154
                     : "=r" (_a1)                               \
155
                     : "i" (SYS_ify(name)) ASM_ARGS_##nr        \
156
                     : "memory");                               \
157
       __sys_result = _a1;                                      \
158
     }                                                          \
159
     (int) __sys_result; })
160
#else
161
#if 0
162
/* This doesn't work because GCC uses r7 as a frame pointer in
163
 * some cases and doesn't notice that the _r7 value changes
164
 * it, resulting in mysterious crashes after the SWI.
165
 */
166
#define INTERNAL_SYSCALL(name, err, nr, args...)                \
167
  ({ unsigned int __sys_result;                                 \
168
     {                                                          \
169
       register int _a1 __asm__ ("a1");                         \
170
       LOAD_ARGS_##nr (args)                                    \
171
       register int _r7 __asm__ ("r7") = (int) (SYS_ify(name)); \
172
       __asm__ volatile ("swi   0        @ syscall " #name       \
173
                     : "=r" (_a1)                               \
174
                     : "r" (_r7) ASM_ARGS_##nr                  \
175
                     : "memory");                               \
176
       __sys_result = _a1;                                      \
177
     }                                                          \
178
     (int) __sys_result; })
179
#else
180
/* So hide the use of r7 from the compiler, this would be a lot
181
 * easier but for the fact that the syscalls can exceed 255.
182
 * For the moment the LOAD_ARG_7 is sacrificed.
183
 */
184
#define INTERNAL_SYSCALL(name, err, nr, args...)                \
185
  ({ unsigned int __sys_result;                                 \
186
     {                                                          \
187
       register int _a1 __asm__ ("a1");                         \
188
       LOAD_ARGS_##nr (args)                                    \
189
       register int _v3 __asm__ ("v3") = (int) (SYS_ify(name)); \
190
       __asm__ volatile ("push  {r7}\n"                         \
191
                     "\tmov     r7, v3\n"                       \
192
                     "\tswi     0        @ syscall " #name "\n"  \
193
                     "\tpop     {r7}"                           \
194
                     : "=r" (_a1)                               \
195
                     : "r" (_v3) ASM_ARGS_##nr                  \
196
                     : "memory");                               \
197
       __sys_result = _a1;                                      \
198
     }                                                          \
199
     (int) __sys_result; })
200
#endif
201
#endif
202
#endif /* !defined(__ARM_EABI__) */
203
 
204
#undef INTERNAL_SYSCALL_ERROR_P
205
#define INTERNAL_SYSCALL_ERROR_P(val, err) \
206
  ((unsigned int) (val) >= 0xfffff001u)
207
 
208
#undef INTERNAL_SYSCALL_ERRNO
209
#define INTERNAL_SYSCALL_ERRNO(val, err)        (-(val))
210
 
211
#define LOAD_ARGS_0()
212
#define ASM_ARGS_0
213
#define LOAD_ARGS_1(a1)                         \
214
  _a1 = (int) (a1);                             \
215
  LOAD_ARGS_0 ()
216
#define ASM_ARGS_1      ASM_ARGS_0, "r" (_a1)
217
#define LOAD_ARGS_2(a1, a2)                     \
218
  register int _a2 __asm__ ("a2") = (int) (a2); \
219
  LOAD_ARGS_1 (a1)
220
#define ASM_ARGS_2      ASM_ARGS_1, "r" (_a2)
221
#define LOAD_ARGS_3(a1, a2, a3)                 \
222
  register int _a3 __asm__ ("a3") = (int) (a3); \
223
  LOAD_ARGS_2 (a1, a2)
224
#define ASM_ARGS_3      ASM_ARGS_2, "r" (_a3)
225
#define LOAD_ARGS_4(a1, a2, a3, a4)             \
226
  register int _a4 __asm__ ("a4") = (int) (a4); \
227
  LOAD_ARGS_3 (a1, a2, a3)
228
#define ASM_ARGS_4      ASM_ARGS_3, "r" (_a4)
229
#define LOAD_ARGS_5(a1, a2, a3, a4, a5)         \
230
  register int _v1 __asm__ ("v1") = (int) (a5); \
231
  LOAD_ARGS_4 (a1, a2, a3, a4)
232
#define ASM_ARGS_5      ASM_ARGS_4, "r" (_v1)
233
#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6)     \
234
  register int _v2 __asm__ ("v2") = (int) (a6); \
235
  LOAD_ARGS_5 (a1, a2, a3, a4, a5)
236
#define ASM_ARGS_6      ASM_ARGS_5, "r" (_v2)
237
#define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
238
  register int _v3 __asm__ ("v3") = (int) (a7); \
239
  LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
240
#define ASM_ARGS_7      ASM_ARGS_6, "r" (_v3)
241
 
242
 
243
#endif /* __ASSEMBLER__ */
244
#endif /* _BITS_SYSCALLS_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.