Xenomai  3.0.8
syscall.h
1 /*
2  * Copyright (C) 2001,2002,2003,2004 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 
19 #ifndef _LIB_COBALT_POWERPC_SYSCALL_H
20 #define _LIB_COBALT_POWERPC_SYSCALL_H
21 
22 #include <cobalt/uapi/syscall.h>
23 
24 /* Some code pulled from glibc's inline syscalls. */
25 
26 #define LOADARGS_0(syscode, dummy...) \
27  __sc_0 = (unsigned long)(syscode)
28 #define LOADARGS_1(syscode, arg1) \
29  LOADARGS_0(syscode); \
30  __sc_3 = (unsigned long) (arg1)
31 #define LOADARGS_2(syscode, arg1, arg2) \
32  LOADARGS_1(syscode, arg1); \
33  __sc_4 = (unsigned long) (arg2)
34 #define LOADARGS_3(syscode, arg1, arg2, arg3) \
35  LOADARGS_2(syscode, arg1, arg2); \
36  __sc_5 = (unsigned long) (arg3)
37 #define LOADARGS_4(syscode, arg1, arg2, arg3, arg4) \
38  LOADARGS_3(syscode, arg1, arg2, arg3); \
39  __sc_6 = (unsigned long) (arg4)
40 #define LOADARGS_5(syscode, arg1, arg2, arg3, arg4, arg5) \
41  LOADARGS_4(syscode, arg1, arg2, arg3, arg4); \
42  __sc_7 = (unsigned long) (arg5)
43 
44 #define ASM_INPUT_0 "0" (__sc_0)
45 #define ASM_INPUT_1 ASM_INPUT_0, "1" (__sc_3)
46 #define ASM_INPUT_2 ASM_INPUT_1, "2" (__sc_4)
47 #define ASM_INPUT_3 ASM_INPUT_2, "3" (__sc_5)
48 #define ASM_INPUT_4 ASM_INPUT_3, "4" (__sc_6)
49 #define ASM_INPUT_5 ASM_INPUT_4, "5" (__sc_7)
50 
51 #define XENOMAI_DO_SYSCALL(nr, op, args...) \
52  ({ \
53  register unsigned long __sc_0 __asm__ ("r0"); \
54  register unsigned long __sc_3 __asm__ ("r3"); \
55  register unsigned long __sc_4 __asm__ ("r4"); \
56  register unsigned long __sc_5 __asm__ ("r5"); \
57  register unsigned long __sc_6 __asm__ ("r6"); \
58  register unsigned long __sc_7 __asm__ ("r7"); \
59  \
60  LOADARGS_##nr(__xn_syscode(op), args); \
61  __asm__ __volatile__ \
62  ("sc \n\t" \
63  "mfcr %0 " \
64  : "=&r" (__sc_0), \
65  "=&r" (__sc_3), "=&r" (__sc_4), \
66  "=&r" (__sc_5), "=&r" (__sc_6), \
67  "=&r" (__sc_7) \
68  : ASM_INPUT_##nr \
69  : "cr0", "ctr", "memory", \
70  "r8", "r9", "r10","r11", "r12"); \
71  (int)((__sc_0 & (1 << 28)) ? -__sc_3 : __sc_3); \
72  })
73 
74 #define XENOMAI_SYSCALL0(op) XENOMAI_DO_SYSCALL(0,op)
75 #define XENOMAI_SYSCALL1(op,a1) XENOMAI_DO_SYSCALL(1,op,a1)
76 #define XENOMAI_SYSCALL2(op,a1,a2) XENOMAI_DO_SYSCALL(2,op,a1,a2)
77 #define XENOMAI_SYSCALL3(op,a1,a2,a3) XENOMAI_DO_SYSCALL(3,op,a1,a2,a3)
78 #define XENOMAI_SYSCALL4(op,a1,a2,a3,a4) XENOMAI_DO_SYSCALL(4,op,a1,a2,a3,a4)
79 #define XENOMAI_SYSCALL5(op,a1,a2,a3,a4,a5) XENOMAI_DO_SYSCALL(5,op,a1,a2,a3,a4,a5)
80 #define XENOMAI_SYSBIND(breq) XENOMAI_DO_SYSCALL(1,sc_cobalt_bind,breq)
81 
82 #endif /* !_LIB_COBALT_POWERPC_SYSCALL_H */