Move all files into ports/ subdirectory in preparation for merge with glibc
[jlayton/glibc.git] / ports / sysdeps / unix / sysv / linux / mips / mips64 / n32 / sysdep.h
1 /* Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006, 2009, 2012
2    Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library.  If not, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _LINUX_MIPS_SYSDEP_H
20 #define _LINUX_MIPS_SYSDEP_H 1
21
22 /* There is some commonality.  */
23 #include <sysdeps/unix/mips/mips64/n32/sysdep.h>
24
25 #include <tls.h>
26
27 /* In order to get __set_errno() definition in INLINE_SYSCALL.  */
28 #ifndef __ASSEMBLER__
29 #include <errno.h>
30 #endif
31
32 /* For Linux we can use the system call table in the header file
33         /usr/include/asm/unistd.h
34    of the kernel.  But these symbols do not follow the SYS_* syntax
35    so we have to redefine the `SYS_ify' macro here.  */
36 #undef SYS_ify
37 #define SYS_ify(syscall_name)   __NR_##syscall_name
38
39 #ifdef __ASSEMBLER__
40
41 /* We don't want the label for the error handler to be visible in the symbol
42    table when we define it here.  */
43 #ifdef __PIC__
44 # define SYSCALL_ERROR_LABEL 99b
45 #endif
46
47 #else   /* ! __ASSEMBLER__ */
48
49 /* Convert X to a long long, without losing any bits if it is one
50    already or warning if it is a 32-bit pointer.  */
51 #define ARGIFY(X) ((long long) (__typeof__ ((X) - (X))) (X))
52
53 /* Define a macro which expands into the inline wrapper code for a system
54    call.  */
55 #undef INLINE_SYSCALL
56 #define INLINE_SYSCALL(name, nr, args...)                               \
57   ({ INTERNAL_SYSCALL_DECL(err);                                        \
58      long result_var = INTERNAL_SYSCALL (name, err, nr, args);          \
59      if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) )                  \
60        {                                                                \
61          __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err));        \
62          result_var = -1L;                                              \
63        }                                                                \
64      result_var; })
65
66 #undef INTERNAL_SYSCALL_DECL
67 #define INTERNAL_SYSCALL_DECL(err) long err
68
69 #undef INTERNAL_SYSCALL_ERROR_P
70 #define INTERNAL_SYSCALL_ERROR_P(val, err)   ((long) (err))
71
72 #undef INTERNAL_SYSCALL_ERRNO
73 #define INTERNAL_SYSCALL_ERRNO(val, err)     (val)
74
75 #undef INTERNAL_SYSCALL
76 #define INTERNAL_SYSCALL(name, err, nr, args...) \
77         internal_syscall##nr (, "li\t$2, %2\t\t\t# " #name "\n\t",      \
78                               "i" (SYS_ify (name)), err, args)
79
80 #undef INTERNAL_SYSCALL_NCS
81 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
82         internal_syscall##nr (= number, , "r" (__v0), err, args)
83
84 #define internal_syscall0(ncs_init, cs_init, input, err, dummy...)      \
85 ({                                                                      \
86         long _sys_result;                                               \
87                                                                         \
88         {                                                               \
89         register long long __v0 asm("$2") ncs_init;                     \
90         register long long __a3 asm("$7");                              \
91         __asm__ volatile (                                              \
92         ".set\tnoreorder\n\t"                                           \
93         cs_init                                                         \
94         "syscall\n\t"                                                   \
95         ".set reorder"                                                  \
96         : "=r" (__v0), "=r" (__a3)                                      \
97         : input                                                         \
98         : __SYSCALL_CLOBBERS);                                          \
99         err = __a3;                                                     \
100         _sys_result = __v0;                                             \
101         }                                                               \
102         _sys_result;                                                    \
103 })
104
105 #define internal_syscall1(ncs_init, cs_init, input, err, arg1)          \
106 ({                                                                      \
107         long _sys_result;                                               \
108                                                                         \
109         {                                                               \
110         register long long __v0 asm("$2") ncs_init;                     \
111         register long long __a0 asm("$4") = ARGIFY (arg1);              \
112         register long long __a3 asm("$7");                              \
113         __asm__ volatile (                                              \
114         ".set\tnoreorder\n\t"                                           \
115         cs_init                                                         \
116         "syscall\n\t"                                                   \
117         ".set reorder"                                                  \
118         : "=r" (__v0), "=r" (__a3)                                      \
119         : input, "r" (__a0)                                             \
120         : __SYSCALL_CLOBBERS);                                          \
121         err = __a3;                                                     \
122         _sys_result = __v0;                                             \
123         }                                                               \
124         _sys_result;                                                    \
125 })
126
127 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2)    \
128 ({                                                                      \
129         long _sys_result;                                               \
130                                                                         \
131         {                                                               \
132         register long long __v0 asm("$2") ncs_init;                     \
133         register long long __a0 asm("$4") = ARGIFY (arg1);              \
134         register long long __a1 asm("$5") = ARGIFY (arg2);              \
135         register long long __a3 asm("$7");                              \
136         __asm__ volatile (                                              \
137         ".set\tnoreorder\n\t"                                           \
138         cs_init                                                         \
139         "syscall\n\t"                                                   \
140         ".set\treorder"                                                 \
141         : "=r" (__v0), "=r" (__a3)                                      \
142         : input, "r" (__a0), "r" (__a1)                                 \
143         : __SYSCALL_CLOBBERS);                                          \
144         err = __a3;                                                     \
145         _sys_result = __v0;                                             \
146         }                                                               \
147         _sys_result;                                                    \
148 })
149
150 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3) \
151 ({                                                                      \
152         long _sys_result;                                               \
153                                                                         \
154         {                                                               \
155         register long long __v0 asm("$2") ncs_init;                     \
156         register long long __a0 asm("$4") = ARGIFY (arg1);              \
157         register long long __a1 asm("$5") = ARGIFY (arg2);              \
158         register long long __a2 asm("$6") = ARGIFY (arg3);              \
159         register long long __a3 asm("$7");                              \
160         __asm__ volatile (                                              \
161         ".set\tnoreorder\n\t"                                           \
162         cs_init                                                         \
163         "syscall\n\t"                                                   \
164         ".set\treorder"                                                 \
165         : "=r" (__v0), "=r" (__a3)                                      \
166         : input, "r" (__a0), "r" (__a1), "r" (__a2)                     \
167         : __SYSCALL_CLOBBERS);                                          \
168         err = __a3;                                                     \
169         _sys_result = __v0;                                             \
170         }                                                               \
171         _sys_result;                                                    \
172 })
173
174 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4) \
175 ({                                                                      \
176         long _sys_result;                                               \
177                                                                         \
178         {                                                               \
179         register long long __v0 asm("$2") ncs_init;                     \
180         register long long __a0 asm("$4") = ARGIFY (arg1);              \
181         register long long __a1 asm("$5") = ARGIFY (arg2);              \
182         register long long __a2 asm("$6") = ARGIFY (arg3);              \
183         register long long __a3 asm("$7") = ARGIFY (arg4);              \
184         __asm__ volatile (                                              \
185         ".set\tnoreorder\n\t"                                           \
186         cs_init                                                         \
187         "syscall\n\t"                                                   \
188         ".set\treorder"                                                 \
189         : "=r" (__v0), "+r" (__a3)                                      \
190         : input, "r" (__a0), "r" (__a1), "r" (__a2)                     \
191         : __SYSCALL_CLOBBERS);                                          \
192         err = __a3;                                                     \
193         _sys_result = __v0;                                             \
194         }                                                               \
195         _sys_result;                                                    \
196 })
197
198 #define internal_syscall5(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5) \
199 ({                                                                      \
200         long _sys_result;                                               \
201                                                                         \
202         {                                                               \
203         register long long __v0 asm("$2") ncs_init;                     \
204         register long long __a0 asm("$4") = ARGIFY (arg1);              \
205         register long long __a1 asm("$5") = ARGIFY (arg2);              \
206         register long long __a2 asm("$6") = ARGIFY (arg3);              \
207         register long long __a3 asm("$7") = ARGIFY (arg4);              \
208         register long long __a4 asm("$8") = ARGIFY (arg5);              \
209         __asm__ volatile (                                              \
210         ".set\tnoreorder\n\t"                                           \
211         cs_init                                                         \
212         "syscall\n\t"                                                   \
213         ".set\treorder"                                                 \
214         : "=r" (__v0), "+r" (__a3)                                      \
215         : input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4)         \
216         : __SYSCALL_CLOBBERS);                                          \
217         err = __a3;                                                     \
218         _sys_result = __v0;                                             \
219         }                                                               \
220         _sys_result;                                                    \
221 })
222
223 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6) \
224 ({                                                                      \
225         long _sys_result;                                               \
226                                                                         \
227         {                                                               \
228         register long long __v0 asm("$2") ncs_init;                     \
229         register long long __a0 asm("$4") = ARGIFY (arg1);              \
230         register long long __a1 asm("$5") = ARGIFY (arg2);              \
231         register long long __a2 asm("$6") = ARGIFY (arg3);              \
232         register long long __a3 asm("$7") = ARGIFY (arg4);              \
233         register long long __a4 asm("$8") = ARGIFY (arg5);              \
234         register long long __a5 asm("$9") = ARGIFY (arg6);              \
235         __asm__ volatile (                                              \
236         ".set\tnoreorder\n\t"                                           \
237         cs_init                                                         \
238         "syscall\n\t"                                                   \
239         ".set\treorder"                                                 \
240         : "=r" (__v0), "+r" (__a3)                                      \
241         : input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4),        \
242           "r" (__a5)                                                    \
243         : __SYSCALL_CLOBBERS);                                          \
244         err = __a3;                                                     \
245         _sys_result = __v0;                                             \
246         }                                                               \
247         _sys_result;                                                    \
248 })
249
250 #define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \
251         "$14", "$15", "$24", "$25", "hi", "lo", "memory"
252 #endif /* __ASSEMBLER__ */
253
254 /* Pointer mangling is not yet supported for MIPS.  */
255 #define PTR_MANGLE(var) (void) (var)
256 #define PTR_DEMANGLE(var) (void) (var)
257
258 #endif /* linux/mips/sysdep.h */