The Pedigree Project  0.1
armv7/syscall-stubs.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef SERVICE
21 #error syscall-stubs.h requires SERVICE to be defined
22 #endif
23 #ifndef SERVICE_ERROR
24 #error syscall-stubs.h requires SERVICE_ERROR to be defined
25 #endif
26 #ifndef SERVICE_INIT
27 #error syscall-stubs.h requires SERVICE_INIT to be defined
28 #endif
29 
30 static long syscall0(long function)
31 {
32  long num = ((SERVICE & 0xFFFF) << 16) | (function & 0xFFFF);
33  long ret;
34  SERVICE_INIT;
35  asm volatile("mov r0, %1; \
36  swi #0; \
37  mov %0, r0; \
38  mov %0, r1"
39  : "=r"(ret), "=r"(SERVICE_ERROR)
40  : "r"(num));
41  return ret;
42 }
43 
44 static long syscall1(long function, long p1)
45 {
46  long num = ((SERVICE & 0xFFFF) << 16) | (function & 0xFFFF);
47  long ret;
48  SERVICE_INIT;
49  asm volatile("mov r0, %1; \
50  mov r1, %1; \
51  swi #0; \
52  mov %0, r0; \
53  mov %0, r1"
54  : "=r"(ret), "=r"(SERVICE_ERROR)
55  : "r"(num), "r"(p1));
56  return ret;
57 }
58 
59 static long syscall2(long function, long p1, long p2)
60 {
61  long num = ((SERVICE & 0xFFFF) << 16) | (function & 0xFFFF);
62  long ret;
63  SERVICE_INIT;
64  asm volatile("mov r0, %1; \
65  mov r1, %1; \
66  mov r2, %1; \
67  swi #0; \
68  mov %0, r0; \
69  mov %0, r1"
70  : "=r"(ret), "=r"(SERVICE_ERROR)
71  : "r"(num), "r"(p1), "r"(p2));
72  return ret;
73 }
74 
75 static long syscall3(long function, long p1, long p2, long p3)
76 {
77  long num = ((SERVICE & 0xFFFF) << 16) | (function & 0xFFFF);
78  long ret;
79  SERVICE_INIT;
80  asm volatile("mov r0, %1; \
81  mov r1, %1; \
82  mov r2, %1; \
83  mov r3, %1; \
84  swi #0; \
85  mov %0, r0; \
86  mov %0, r1"
87  : "=r"(ret), "=r"(SERVICE_ERROR)
88  : "r"(num), "r"(p1), "r"(p2), "r"(p3));
89  return ret;
90 }
91 
93 
94 static long syscall4(long function, long p1, long p2, long p3, long p4)
95 {
96  long num = ((SERVICE & 0xFFFF) << 16) | (function & 0xFFFF);
97  long ret = 0;
98  SERVICE_INIT;
99  /*
100  asm volatile("mov r0, %1; \
101  mov r1, %1; \
102  mov r2, %1; \
103  mov r3, %1; \
104  swi #0; \
105  mov %0, r0; \
106  mov %0, r1" : "=r" (ret), "=r" (SERVICE_ERROR) : "r" (num),
107  "r" (p1), "r" (p2), "r" (p3));
108  */
109  return ret;
110 }
111 
112 static long syscall5(long function, long p1, long p2, long p3, long p4, long p5)
113 {
114  long num = ((SERVICE & 0xFFFF) << 16) | (function & 0xFFFF);
115  long ret = 0;
116  SERVICE_INIT;
117  /*
118  asm volatile("mov r0, %1; \
119  mov r1, %1; \
120  mov r2, %1; \
121  mov r3, %1; \
122  swi #0; \
123  mov %0, r0; \
124  mov %0, r1" : "=r" (ret), "=r" (SERVICE_ERROR) : "r" (num),
125  "r" (p1), "r" (p2), "r" (p3));
126  */
127  return ret;
128 }