1 /* Copyright (C) 1992, 93, 95-99, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
4 ARM changes by Philip Blundell, <pjb27@cam.ac.uk>, May 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef _LINUX_ARM_SYSDEP_H
22 #define _LINUX_ARM_SYSDEP_H 1
24 /* There is some commonality. */
25 #include <sysdeps/unix/arm/sysdep.h>
27 /* For Linux we can use the system call table in the header file
28 /usr/include/asm/unistd.h
29 of the kernel. But these symbols do not follow the SYS_* syntax
30 so we have to redefine the `SYS_ify' macro here. */
32 #define SWI_BASE (0x900000)
33 #define SYS_ify(syscall_name) (__NR_##syscall_name)
38 /* Linux uses a negative return value to indicate syscall errors,
39 unlike most Unices, which use the condition codes' carry flag.
41 Since version 2.1 the return value of a system call might be
42 negative even if the call succeeded. E.g., the `lseek' system call
43 might return a large offset. Therefore we must not anymore test
44 for < 0, but test for a real error by making sure the value in R0
45 is a real error number. Linus said he will make sure the no syscall
46 returns a value in -1 .. -4095 as a valid result so we can savely
50 #define PSEUDO(name, syscall_name, args) \
52 .type syscall_error,%function; \
54 DO_CALL (args, syscall_name); \
58 RETINSTR(movcc, pc, lr); \
59 b PLTJMP(__syscall_error)
61 #define ret PSEUDO_RET
64 #define PSEUDO_END(name) \
65 SYSCALL_ERROR_HANDLER \
68 #define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
70 /* Linux takes system call args in registers:
71 syscall number in the SWI instruction
76 arg 5 r4 (this is different from the APCS convention)
80 The compiler is going to form a call by coming here, through PSEUDO, with
82 syscall number in the DO_CALL macro
91 We need to shuffle values between R4..R6 and the stack so that the
92 caller's v1..v3 and stack frame are not corrupted, and the kernel
93 sees the right arguments.
98 #define DO_CALL(args, syscall_name) \
100 swi SYS_ify (syscall_name); \
103 #define DOARGS_0 /* nothing */
104 #define DOARGS_1 /* nothing */
105 #define DOARGS_2 /* nothing */
106 #define DOARGS_3 /* nothing */
107 #define DOARGS_4 /* nothing */
108 #define DOARGS_5 str r4, [sp, $-4]!; ldr r4, [sp, $4];
109 #define DOARGS_6 mov ip, sp; stmfd sp!, {r4, r5}; ldmia ip, {r4, r5};
110 #define DOARGS_7 mov ip, sp; stmfd sp!, {r4, r5, r6}; ldmia ip, {r4, r5, r6};
112 #define UNDOARGS_0 /* nothing */
113 #define UNDOARGS_1 /* nothing */
114 #define UNDOARGS_2 /* nothing */
115 #define UNDOARGS_3 /* nothing */
116 #define UNDOARGS_4 /* nothing */
117 #define UNDOARGS_5 ldr r4, [sp], $4;
118 #define UNDOARGS_6 ldmfd sp!, {r4, r5};
119 #define UNDOARGS_7 ldmfd sp!, {r4, r5, r6};
121 #else /* not __ASSEMBLER__ */
123 /* Define a macro which expands into the inline wrapper code for a system
125 #undef INLINE_SYSCALL
126 #define INLINE_SYSCALL(name, nr, args...) \
127 ({ unsigned int _sys_result; \
129 register int _a1 asm ("a1"); \
130 LOAD_ARGS_##nr (args) \
131 asm volatile ("swi %1 @ syscall " #name \
133 : "i" (SYS_ify(name)) ASM_ARGS_##nr \
137 if (_sys_result >= (unsigned int) -4095) \
139 __set_errno (-_sys_result); \
140 _sys_result = (unsigned int) -1; \
142 (int) _sys_result; })
144 #define LOAD_ARGS_0()
146 #define LOAD_ARGS_1(a1) \
149 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
150 #define LOAD_ARGS_2(a1, a2) \
151 register int _a2 asm ("a2") = (int) (a2); \
153 #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
154 #define LOAD_ARGS_3(a1, a2, a3) \
155 register int _a3 asm ("a3") = (int) (a3); \
157 #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
158 #define LOAD_ARGS_4(a1, a2, a3, a4) \
159 register int _a4 asm ("a4") = (int) (a4); \
160 LOAD_ARGS_3 (a1, a2, a3)
161 #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
162 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
163 register int _v1 asm ("v1") = (int) (a5); \
164 LOAD_ARGS_4 (a1, a2, a3, a4)
165 #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
166 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
167 register int _v2 asm ("v2") = (int) (a6); \
168 LOAD_ARGS_5 (a1, a2, a3, a4, a5)
169 #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
170 #define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
171 register int _v3 asm ("v3") = (int) (a7); \
172 LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
173 #define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
175 #endif /* __ASSEMBLER__ */
177 #endif /* linux/arm/sysdep.h */