Updated to fedora-glibc-20051220T1028
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc64 / sysdep.h
blob3ece017563029c02b7ef8d0537216a22826f80d4
1 /* Copyright (C) 1992,1997,1998,1999,2000,2001,2002,2003,2004,2005
2 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 /* Alan Modra <amodra@bigpond.net.au> rewrote the INLINE_SYSCALL macro */
22 #ifndef _LINUX_POWERPC_SYSDEP_H
23 #define _LINUX_POWERPC_SYSDEP_H 1
25 #include <sysdeps/unix/powerpc/sysdep.h>
26 #include <tls.h>
28 /* Define __set_errno() for INLINE_SYSCALL macro below. */
29 #ifndef __ASSEMBLER__
30 #include <errno.h>
31 #endif
33 /* Some systen calls got renamed over time, but retained the same semantics.
34 Handle them here so they can be catched by both C and assembler stubs in
35 glibc. */
37 #ifdef __NR_pread64
38 # ifdef __NR_pread
39 # error "__NR_pread and __NR_pread64 both defined???"
40 # endif
41 # define __NR_pread __NR_pread64
42 #endif
44 #ifdef __NR_pwrite64
45 # ifdef __NR_pwrite
46 # error "__NR_pwrite and __NR_pwrite64 both defined???"
47 # endif
48 # define __NR_pwrite __NR_pwrite64
49 #endif
51 /* For Linux we can use the system call table in the header file
52 /usr/include/asm/unistd.h
53 of the kernel. But these symbols do not follow the SYS_* syntax
54 so we have to redefine the `SYS_ify' macro here. */
55 #undef SYS_ify
56 #ifdef __STDC__
57 # define SYS_ify(syscall_name) __NR_##syscall_name
58 #else
59 # define SYS_ify(syscall_name) __NR_/**/syscall_name
60 #endif
62 #ifdef __ASSEMBLER__
64 /* This seems to always be the case on PPC. */
65 #define ALIGNARG(log2) log2
66 /* For ELF we need the `.type' directive to make shared libs work right. */
67 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
68 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
70 #endif /* __ASSEMBLER__ */
72 #undef INLINE_SYSCALL
74 /* This version is for kernels that implement system calls that
75 behave like function calls as far as register saving. */
76 #define INLINE_SYSCALL(name, nr, args...) \
77 ({ \
78 INTERNAL_SYSCALL_DECL (sc_err); \
79 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
80 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
81 { \
82 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
83 sc_ret = -1L; \
84 } \
85 sc_ret; \
88 /* Define a macro which expands inline into the wrapper code for a system
89 call. This use is for internal calls that do not need to handle errors
90 normally. It will never touch errno. This returns just what the kernel
91 gave back in the non-error (CR0.SO cleared) case, otherwise (CR0.SO set)
92 the negation of the return value in the kernel gets reverted. */
94 #undef INTERNAL_SYSCALL
95 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
96 ({ \
97 register long int r0 __asm__ ("r0"); \
98 register long int r3 __asm__ ("r3"); \
99 register long int r4 __asm__ ("r4"); \
100 register long int r5 __asm__ ("r5"); \
101 register long int r6 __asm__ ("r6"); \
102 register long int r7 __asm__ ("r7"); \
103 register long int r8 __asm__ ("r8"); \
104 LOADARGS_##nr(name, args); \
105 __asm__ __volatile__ \
106 ("sc\n\t" \
107 "mfcr %0\n\t" \
108 "0:" \
109 : "=&r" (r0), \
110 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
111 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
112 : ASM_INPUT_##nr \
113 : "r9", "r10", "r11", "r12", \
114 "cr0", "ctr", "memory"); \
115 err = r0; \
116 (int) r3; \
118 #define INTERNAL_SYSCALL(name, err, nr, args...) \
119 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
121 #undef INTERNAL_SYSCALL_DECL
122 #define INTERNAL_SYSCALL_DECL(err) long int err
124 #undef INTERNAL_SYSCALL_ERROR_P
125 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
126 ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
128 #undef INTERNAL_SYSCALL_ERRNO
129 #define INTERNAL_SYSCALL_ERRNO(val, err) (val)
131 #define LOADARGS_0(name, dummy) \
132 r0 = name
133 #define LOADARGS_1(name, __arg1) \
134 long int arg1 = (long int) (__arg1); \
135 LOADARGS_0(name, 0); \
136 extern void __illegally_sized_syscall_arg1 (void); \
137 if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 8) \
138 __illegally_sized_syscall_arg1 (); \
139 r3 = arg1
140 #define LOADARGS_2(name, __arg1, __arg2) \
141 long int arg2 = (long int) (__arg2); \
142 LOADARGS_1(name, __arg1); \
143 extern void __illegally_sized_syscall_arg2 (void); \
144 if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 8) \
145 __illegally_sized_syscall_arg2 (); \
146 r4 = arg2
147 #define LOADARGS_3(name, __arg1, __arg2, __arg3) \
148 long int arg3 = (long int) (__arg3); \
149 LOADARGS_2(name, __arg1, __arg2); \
150 extern void __illegally_sized_syscall_arg3 (void); \
151 if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 8) \
152 __illegally_sized_syscall_arg3 (); \
153 r5 = arg3
154 #define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
155 long int arg4 = (long int) (__arg4); \
156 LOADARGS_3(name, __arg1, __arg2, __arg3); \
157 extern void __illegally_sized_syscall_arg4 (void); \
158 if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 8) \
159 __illegally_sized_syscall_arg4 (); \
160 r6 = arg4
161 #define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
162 long int arg5 = (long int) (__arg5); \
163 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
164 extern void __illegally_sized_syscall_arg5 (void); \
165 if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 8) \
166 __illegally_sized_syscall_arg5 (); \
167 r7 = arg5
168 #define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
169 long int arg6 = (long int) (__arg6); \
170 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
171 extern void __illegally_sized_syscall_arg6 (void); \
172 if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 8) \
173 __illegally_sized_syscall_arg6 (); \
174 r8 = arg6
176 #define ASM_INPUT_0 "0" (r0)
177 #define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
178 #define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
179 #define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
180 #define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
181 #define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
182 #define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
185 /* Pointer mangling support. */
186 #if defined NOT_IN_libc && defined IS_IN_rtld
187 /* We cannot use the thread descriptor because in ld.so we use setjmp
188 earlier than the descriptor is initialized. */
189 #else
190 # ifdef __ASSEMBLER__
191 # define PTR_MANGLE(reg, tmpreg) \
192 ld tmpreg,POINTER_GUARD(r13); \
193 xor reg,tmpreg,reg
194 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
195 # else
196 # define PTR_MANGLE(var) \
197 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
198 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
199 # endif
200 #endif
202 #endif /* linux/powerpc/powerpc64/sysdep.h */