summaryrefslogtreecommitdiff
path: root/ldso/ldso/m68k/ld_syscalls.h
blob: 7d76c54229927160503e4733a5559847e21fd3f1 (plain)
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
#include <asm/unistd.h>

#undef __syscall_return
#undef _syscall0
#undef _syscall1
#undef _syscall2
#undef _syscall3
#undef _syscall4
#undef _syscall5

/* Here are the macros which define how this platform makes
 * system calls.  This particular variant does _not_ set 
 * errno (note how it is disabled in __syscall_return) since
 * these will get called before the errno symbol is dynamicly 
 * linked. */


#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); \
		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)				\
			: "cc", "%d0");					\
  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
    /* errno = -__res; */							\
    __res = -1;								\
  }									\
  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)					\
			: "cc", "%d0", "%d1");				\
  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
    /* errno = -__res; */							\
    __res = -1;								\
  }									\
  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)					\
			: "cc", "%d0", "%d1", "%d2");			\
  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
    /* errno = -__res; */							\
    __res = -1;								\
  }									\
  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)					\
			: "cc", "%d0", "%d1", "%d2", "%d3");		\
  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
    /* errno = -__res; */							\
    __res = -1;								\
  }									\
  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)					\
			: "cc", "%d0", "%d1", "%d2", "%d3",		\
			  "%d4");					\
  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
    /* errno = -__res; */							\
    __res = -1;								\
  }									\
  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)					\
			: "cc", "%d0", "%d1", "%d2", "%d3",		\
			  "%d4", "%d5");				\
  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
    /* errno = -__res; */							\
    __res = -1;								\
  }									\
  return (type)__res;							\
}