(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / sysdep.h
blob2ee3e60229c29f3f84cf701734826a3fb5fc5411
1 /* Copyright (C) 1992,1997-2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #ifndef _LINUX_POWERPC_SYSDEP_H
20 #define _LINUX_POWERPC_SYSDEP_H 1
22 #include <sysdeps/unix/powerpc/sysdep.h>
24 /* Some systen calls got renamed over time, but retained the same semantics.
25 Handle them here so they can be catched by both C and assembler stubs in
26 glibc. */
28 #ifdef __NR_pread64
29 # ifdef __NR_pread
30 # error "__NR_pread and __NR_pread64 both defined???"
31 # endif
32 # define __NR_pread __NR_pread64
33 #endif
35 #ifdef __NR_pwrite64
36 # ifdef __NR_pwrite
37 # error "__NR_pwrite and __NR_pwrite64 both defined???"
38 # endif
39 # define __NR_pwrite __NR_pwrite64
40 #endif
42 /* For Linux we can use the system call table in the header file
43 /usr/include/asm/unistd.h
44 of the kernel. But these symbols do not follow the SYS_* syntax
45 so we have to redefine the `SYS_ify' macro here. */
46 #undef SYS_ify
47 #ifdef __STDC__
48 # define SYS_ify(syscall_name) __NR_##syscall_name
49 #else
50 # define SYS_ify(syscall_name) __NR_/**/syscall_name
51 #endif
53 #ifndef __ASSEMBLER__
55 # include <errno.h>
57 # undef INLINE_SYSCALL
58 # define INLINE_SYSCALL(name, nr, args...) \
59 ({ \
60 INTERNAL_SYSCALL_DECL (sc_err); \
61 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
62 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
63 { \
64 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
65 sc_ret = -1L; \
66 } \
67 sc_ret; \
70 /* Define a macro which expands inline into the wrapper code for a system
71 call. This use is for internal calls that do not need to handle errors
72 normally. It will never touch errno.
73 On powerpc a system call basically clobbers the same registers like a
74 function call, with the exception of LR (which is needed for the
75 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
76 an error return status). */
78 # undef INTERNAL_SYSCALL_DECL
79 # define INTERNAL_SYSCALL_DECL(err) long int err
81 # undef INTERNAL_SYSCALL
82 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
83 ({ \
84 register long int r0 __asm__ ("r0"); \
85 register long int r3 __asm__ ("r3"); \
86 register long int r4 __asm__ ("r4"); \
87 register long int r5 __asm__ ("r5"); \
88 register long int r6 __asm__ ("r6"); \
89 register long int r7 __asm__ ("r7"); \
90 register long int r8 __asm__ ("r8"); \
91 register long int r9 __asm__ ("r9"); \
92 register long int r10 __asm__ ("r10"); \
93 register long int r11 __asm__ ("r11"); \
94 register long int r12 __asm__ ("r12"); \
95 LOADARGS_##nr(name, args); \
96 __asm__ __volatile__ \
97 ("sc \n\t" \
98 "mfcr %0" \
99 : "=&r" (r0), \
100 "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \
101 "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \
102 : ASM_INPUT_##nr \
103 : "cr0", "ctr", "memory"); \
104 err = r0; \
105 (int) r3; \
107 # define INTERNAL_SYSCALL(name, err, nr, args...) \
108 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
110 # undef INTERNAL_SYSCALL_ERROR_P
111 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
112 (__builtin_expect (err & (1 << 28), 0))
114 # undef INTERNAL_SYSCALL_ERRNO
115 # define INTERNAL_SYSCALL_ERRNO(val, err) (val)
117 # define LOADARGS_0(name, dummy) \
118 r0 = name
119 # define LOADARGS_1(name, __arg1) \
120 long int arg1 = (long int) (__arg1); \
121 LOADARGS_0(name, 0); \
122 extern void __illegally_sized_syscall_arg1 (void); \
123 if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
124 __illegally_sized_syscall_arg1 (); \
125 r3 = arg1
126 # define LOADARGS_2(name, __arg1, __arg2) \
127 long int arg2 = (long int) (__arg2); \
128 LOADARGS_1(name, __arg1); \
129 extern void __illegally_sized_syscall_arg2 (void); \
130 if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
131 __illegally_sized_syscall_arg2 (); \
132 r4 = arg2
133 # define LOADARGS_3(name, __arg1, __arg2, __arg3) \
134 long int arg3 = (long int) (__arg3); \
135 LOADARGS_2(name, __arg1, __arg2); \
136 extern void __illegally_sized_syscall_arg3 (void); \
137 if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
138 __illegally_sized_syscall_arg3 (); \
139 r5 = arg3
140 # define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
141 long int arg4 = (long int) (__arg4); \
142 LOADARGS_3(name, __arg1, __arg2, __arg3); \
143 extern void __illegally_sized_syscall_arg4 (void); \
144 if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \
145 __illegally_sized_syscall_arg4 (); \
146 r6 = arg4
147 # define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
148 long int arg5 = (long int) (__arg5); \
149 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
150 extern void __illegally_sized_syscall_arg5 (void); \
151 if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
152 __illegally_sized_syscall_arg5 (); \
153 r7 = arg5
154 # define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
155 long int arg6 = (long int) (__arg6); \
156 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
157 extern void __illegally_sized_syscall_arg6 (void); \
158 if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
159 __illegally_sized_syscall_arg6 (); \
160 r8 = arg6
162 # define ASM_INPUT_0 "0" (r0)
163 # define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
164 # define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
165 # define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
166 # define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
167 # define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
168 # define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
170 #endif /* __ASSEMBLER__ */
173 #endif /* linux/powerpc/powerpc32/sysdep.h */