2.3.3-74
[glibc.git] / sysdeps / unix / sysv / linux / cris / sysdep.h
blob5013dd5d30fe6011a43a00edae619e19a9f7d48c
1 /* Assembler macros for CRIS.
2 Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <asm/unistd.h>
21 #include <sysdeps/cris/sysdep.h>
22 #include <sys/syscall.h>
23 #include "config.h"
25 #undef SYS_ify
26 #define SYS_ify(syscall_name) (__NR_##syscall_name)
29 #ifdef __ASSEMBLER__
31 /* For Linux we can use the system call table in the header file
32 /usr/include/asm/unistd.h
33 of the kernel. But these symbols do not follow the SYS_* syntax
34 so we have to redefine the `SYS_ify' macro here. */
35 #undef SYS_ify
36 #define SYS_ify(syscall_name) __NR_##syscall_name
38 /* ELF-like local names start with `.L'. */
39 #undef L
40 #define L(name) .L##name
42 /* Linux uses a negative return value to indicate syscall errors,
43 unlike most Unices, which use the condition codes' carry flag.
45 Since version 2.1 the return value of a system call might be
46 negative even if the call succeeded. E.g., the `lseek' system call
47 might return a large offset. Therefore we must not anymore test
48 for < 0, but test for a real error by making sure the value in %eax
49 is a real error number. Linus said he will make sure the no syscall
50 returns a value in -1 .. -4095 as a valid result so we can safely
51 test with -4095. */
53 /* Syscall wrappers consist of
54 #include <sysdep.h>
55 PSEUDO (...)
56 ret
57 PSEUDO_END (...)
59 which expand to the following. */
61 /* Linux takes system call arguments in registers:
62 syscall number R9
63 arg 1 R10
64 arg 2 R11
65 arg 3 R12
66 arg 4 R13
67 arg 5 MOF
68 arg 6 SRP
70 The compiler calls us by the C convention:
71 syscall number in the DO_CALL macro
72 arg 1 R10
73 arg 2 R11
74 arg 3 R12
75 arg 4 R13
76 arg 5 [SP]
77 arg 6 [SP + 4]
80 /* Note that we use "bhs", since we want to match
81 (unsigned) -4096 .. 0xffffffff. Using "ble" would match
82 -4096 .. -2**31. */
83 #define PSEUDO(name, syscall_name, args) \
84 ENTRY (name) @ \
85 DOARGS_##args @ \
86 movu.w SYS_ify (syscall_name),$r9 @ \
87 break 13 @ \
88 cmps.w -4096,$r10 @ \
89 bhs 0f @ \
90 nop @ \
91 UNDOARGS_return_##args
93 /* Ouch! We have to remember not to use "ret" in assembly-code.
94 ("Luckily", mnemonics are case-insensitive.)
95 Note that we assume usage is exactly:
96 PSEUDO (...)
97 ret
98 PSEUDO_END (...)
99 so we can put all payload into PSEUDO (except for error handling). */
101 #define ret
103 #define PSEUDO_END(name) \
104 0: @ \
105 SETUP_PIC @ \
106 PLTJUMP (syscall_error) @ \
107 END (name)
109 #define PSEUDO_NOERRNO(name, syscall_name, args) \
110 ENTRY (name) @ \
111 DOARGS_##args @ \
112 movu.w SYS_ify (syscall_name),$r9 @ \
113 break 13 @ \
114 UNDOARGS_return_##args
116 #define ret_NOERRNO
118 #define PSEUDO_END_NOERRNO(name) \
119 END (name)
121 #define DOARGS_0
122 #define DOARGS_1
123 #define DOARGS_2
124 #define DOARGS_3
125 #define DOARGS_4
126 #define DOARGS_5 \
127 move [$sp],$mof
129 /* To avoid allocating stack-space, we re-use the arg 5 (MOF) entry by
130 storing SRP into it. If called with too-few arguments, we will crash,
131 but that will happen in the general case too. */
132 #define DOARGS_6 \
133 DOARGS_5 @ \
134 move $srp,[$sp] @ \
135 move [$sp+4],$srp
137 #define UNDOARGS_return_0 \
138 Ret @ \
141 #define UNDOARGS_return_1 UNDOARGS_return_0
142 #define UNDOARGS_return_2 UNDOARGS_return_0
143 #define UNDOARGS_return_3 UNDOARGS_return_0
144 #define UNDOARGS_return_4 UNDOARGS_return_0
145 #define UNDOARGS_return_5 UNDOARGS_return_0
147 /* We assume the following code will be "ret" and "PSEUDO_END". */
148 #define UNDOARGS_return_return_6 \
149 jump [$sp]
151 #else /* not __ASSEMBLER__ */
153 #undef INLINE_SYSCALL
154 #define INLINE_SYSCALL(name, nr, args...) \
155 ({ \
156 unsigned long __sys_res; \
157 register unsigned long __res asm ("r10"); \
158 LOAD_ARGS_c_##nr (args) \
159 register unsigned long __callno asm ("r9") \
160 = SYS_ify (name); \
161 asm volatile (LOAD_ARGS_asm_##nr (args) \
162 "break 13" \
163 : "=r" (__res) \
164 : ASM_ARGS_##nr (args) \
165 : ASM_CLOBBER_##nr); \
166 __sys_res = __res; \
168 if (__sys_res >= (unsigned long) -4096) \
170 __set_errno (- __sys_res); \
171 __sys_res = (unsigned long) -1; \
173 (long int) __sys_res; \
176 #define LOAD_ARGS_c_0()
177 #define LOAD_ARGS_asm_0()
178 #define ASM_CLOBBER_0 "memory"
179 #define ASM_ARGS_0() "r" (__callno)
181 #define LOAD_ARGS_c_1(r10) \
182 LOAD_ARGS_c_0() \
183 register unsigned long __r10 __asm__ ("r10") = (unsigned long) (r10);
184 #define LOAD_ARGS_asm_1(r10) LOAD_ARGS_asm_0 ()
185 #define ASM_CLOBBER_1 ASM_CLOBBER_0
186 #define ASM_ARGS_1(r10) ASM_ARGS_0 (), "0" (__r10)
188 #define LOAD_ARGS_c_2(r10, r11) \
189 LOAD_ARGS_c_1(r10) \
190 register unsigned long __r11 __asm__ ("r11") = (unsigned long) (r11);
191 #define LOAD_ARGS_asm_2(r10, r11) LOAD_ARGS_asm_1 (r10)
192 #define ASM_CLOBBER_2 ASM_CLOBBER_1
193 #define ASM_ARGS_2(r10, r11) ASM_ARGS_1 (r10), "r" (__r11)
195 #define LOAD_ARGS_c_3(r10, r11, r12) \
196 LOAD_ARGS_c_2(r10, r11) \
197 register unsigned long __r12 __asm__ ("r12") = (unsigned long) (r12);
198 #define LOAD_ARGS_asm_3(r10, r11, r12) LOAD_ARGS_asm_2 (r10, r11)
199 #define ASM_CLOBBER_3 ASM_CLOBBER_2
200 #define ASM_ARGS_3(r10, r11, r12) ASM_ARGS_2 (r10, r11), "r" (__r12)
202 #define LOAD_ARGS_c_4(r10, r11, r12, r13) \
203 LOAD_ARGS_c_3(r10, r11, r12) \
204 register unsigned long __r13 __asm__ ("r13") = (unsigned long) (r13);
205 #define LOAD_ARGS_asm_4(r10, r11, r12, r13) LOAD_ARGS_asm_3 (r10, r11, r12)
206 #define ASM_CLOBBER_4 ASM_CLOBBER_3
207 #define ASM_ARGS_4(r10, r11, r12, r13) ASM_ARGS_3 (r10, r11, r12), "r" (__r13)
209 #define LOAD_ARGS_c_5(r10, r11, r12, r13, mof) \
210 LOAD_ARGS_c_4(r10, r11, r12, r13)
211 #define LOAD_ARGS_asm_5(r10, r11, r12, r13, mof) \
212 LOAD_ARGS_asm_4 (r10, r11, r12, r13) "move %6,$mof\n\t"
213 #define ASM_CLOBBER_5 ASM_CLOBBER_4
214 #define ASM_ARGS_5(r10, r11, r12, r13, mof) \
215 ASM_ARGS_4 (r10, r11, r12, r13), "g" (mof)
217 #define LOAD_ARGS_c_6(r10, r11, r12, r13, mof, srp) \
218 LOAD_ARGS_c_5(r10, r11, r12, r13, mof)
219 #define LOAD_ARGS_asm_6(r10, r11, r12, r13, mof, srp) \
220 LOAD_ARGS_asm_5(r10, r11, r12, r13, mof) \
221 "move %7,$srp\n\t"
222 #define ASM_CLOBBER_6 ASM_CLOBBER_5, "srp"
223 #define ASM_ARGS_6(r10, r11, r12, r13, mof, srp) \
224 ASM_ARGS_5 (r10, r11, r12, r13, mof), "g" (srp)
226 #endif /* not __ASSEMBLER__ */