1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
#ifndef _BITS_SYSCALLS_H
#define _BITS_SYSCALLS_H
#ifndef _SYSCALL_H
# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
#endif
#include <errno.h>
/* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
* header files. It also defines the traditional `SYS_<name>' macros for older
* programs. */
#include <bits/sysnum.h>
/* m68k headers does stupid stuff with __NR_iopl / __NR_vm86:
* #define __NR_iopl not supported
* #define __NR_vm86 not supported
*/
#undef __NR_iopl
#undef __NR_vm86
#ifndef __ASSEMBLER__
/* Linux takes system call arguments in registers:
syscall number %d0 call-clobbered
arg 1 %d1 call-clobbered
arg 2 %d2 call-saved
arg 3 %d3 call-saved
arg 4 %d4 call-saved
arg 5 %d5 call-saved
The stack layout upon entering the function is:
20(%sp) Arg# 5
16(%sp) Arg# 4
12(%sp) Arg# 3
8(%sp) Arg# 2
4(%sp) Arg# 1
(%sp) Return address
(Of course a function with say 3 arguments does not have entries for
arguments 4 and 5.)
Separate move's are faster than movem, but need more space. Since
speed is more important, we don't use movem. Since %a0 and %a1 are
scratch registers, we can use them for saving as well. */
#define __syscall_return(type, res) \
do { \
if ((unsigned long)(res) >= (unsigned long)(-125)) { \
/* avoid using res which is declared to be in register d0; \
errno might expand to a function call and clobber it. */ \
int __err = -(res); \
__set_errno(__err); \
res = -1; \
} \
return (type) (res); \
} while (0)
#define _syscall0(type, name) \
type name(void) \
{ \
long __res; \
__asm__ __volatile__ ( \
"movel %1, %%d0\n\t" \
"trap #0\n\t" \
"movel %%d0, %0" \
: "=g" (__res) \
: "i" (__NR_##name) \
: "memory", "cc", "%d0"); \
__syscall_return(type, __res); \
}
#define _syscall1(type, name, atype, a) \
type name(atype a) \
{ \
long __res; \
__asm__ __volatile__ ( \
"movel %2, %%d1\n\t" \
"movel %1, %%d0\n\t" \
"trap #0\n\t" \
"movel %%d0, %0" \
: "=g" (__res) \
: "i" (__NR_##name), \
"g" ((long)a) \
: "memory", "cc", "%d0", "%d1"); \
__syscall_return(type, __res); \
}
#define _syscall2(type, name, atype, a, btype, b) \
type name(atype a, btype b) \
{ \
long __res; \
__asm__ __volatile__ ( \
"movel %3, %%d2\n\t" \
"movel %2, %%d1\n\t" \
"movel %1, %%d0\n\t" \
"trap #0\n\t" \
"movel %%d0, %0" \
: "=g" (__res) \
: "i" (__NR_##name), \
"a" ((long)a), \
"g" ((long)b) \
: "memory", "cc", "%d0", "%d1", "%d2"); \
__syscall_return(type, __res); \
}
#define _syscall3(type, name, atype, a, btype, b, ctype, c) \
type name(atype a, btype b, ctype c) \
{ \
long __res; \
__asm__ __volatile__ ( \
"movel %4, %%d3\n\t" \
"movel %3, %%d2\n\t" \
"movel %2, %%d1\n\t" \
"movel %1, %%d0\n\t" \
"trap #0\n\t" \
"movel %%d0, %0" \
: "=g" (__res) \
: "i" (__NR_##name), \
"a" ((long)a), \
"a" ((long)b), \
"g" ((long)c) \
: "memory", "cc", "%d0", "%d1", "%d2", "%d3"); \
__syscall_return(type, __res); \
}
#define _syscall4(type, name, atype, a, btype, b, ctype, c, dtype, d) \
type name(atype a, btype b, ctype c, dtype d) \
{ \
long __res; \
__asm__ __volatile__ ( \
"movel %5, %%d4\n\t" \
"movel %4, %%d3\n\t" \
"movel %3, %%d2\n\t" \
"movel %2, %%d1\n\t" \
"movel %1, %%d0\n\t" \
"trap #0\n\t" \
"movel %%d0, %0" \
: "=g" (__res) \
: "i" (__NR_##name), \
"a" ((long)a), \
"a" ((long)b), \
"a" ((long)c), \
"g" ((long)d) \
: "memory", "cc", "%d0", "%d1", "%d2", "%d3", \
"%d4"); \
__syscall_return(type, __res); \
}
#define _syscall5(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e) \
type name(atype a, btype b, ctype c, dtype d, etype e) \
{ \
long __res; \
__asm__ __volatile__ ( \
"movel %6, %%d5\n\t" \
"movel %5, %%d4\n\t" \
"movel %4, %%d3\n\t" \
"movel %3, %%d2\n\t" \
"movel %2, %%d1\n\t" \
"movel %1, %%d0\n\t" \
"trap #0\n\t" \
"movel %%d0, %0" \
: "=g" (__res) \
: "i" (__NR_##name), \
"a" ((long)a), \
"a" ((long)b), \
"a" ((long)c), \
"a" ((long)d), \
"g" ((long)e) \
: "memory", "cc", "%d0", "%d1", "%d2", "%d3", \
"%d4", "%d5"); \
__syscall_return(type, __res); \
}
#define _syscall6(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e, ftype, f) \
type name(atype a, btype b, ctype c, dtype d, etype e, ftype f) \
{ \
long __res; \
__asm__ __volatile__ ( \
"movel %7, %%a0\n\t" \
"movel %6, %%d5\n\t" \
"movel %5, %%d4\n\t" \
"movel %4, %%d3\n\t" \
"movel %3, %%d2\n\t" \
"movel %2, %%d1\n\t" \
"movel %1, %%d0\n\t" \
"trap #0\n\t" \
"movel %%d0, %0" \
: "=g" (__res) \
: "i" (__NR_##name), \
"a" ((long)a), \
"a" ((long)b), \
"a" ((long)c), \
"a" ((long)d), \
"g" ((long)e), \
"g" ((long)f) \
: "memory", "cc", "%d0", "%d1", "%d2", "%d3", \
"%d4", "%d5", "%a0"); \
__syscall_return(type, __res); \
}
#endif /* __ASSEMBLER__ */
#endif /* _BITS_SYSCALLS_H */
|