Back to index

glibc  2.9
sysdep.h
Go to the documentation of this file.
00001 /* Copyright (C) 1992,1997-2003,2004,2005,2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _LINUX_POWERPC_SYSDEP_H
00020 #define _LINUX_POWERPC_SYSDEP_H 1
00021 
00022 #include <sysdeps/unix/powerpc/sysdep.h>
00023 #include <tls.h>
00024 
00025 /* Some systen calls got renamed over time, but retained the same semantics.
00026    Handle them here so they can be catched by both C and assembler stubs in
00027    glibc.  */
00028 
00029 #ifdef __NR_pread64
00030 # ifdef __NR_pread
00031 #  error "__NR_pread and __NR_pread64 both defined???"
00032 # endif
00033 # define __NR_pread __NR_pread64
00034 #endif
00035 
00036 #ifdef __NR_pwrite64
00037 # ifdef __NR_pwrite
00038 #  error "__NR_pwrite and __NR_pwrite64 both defined???"
00039 # endif
00040 # define __NR_pwrite __NR_pwrite64
00041 #endif
00042 
00043 /* For Linux we can use the system call table in the header file
00044        /usr/include/asm/unistd.h
00045    of the kernel.  But these symbols do not follow the SYS_* syntax
00046    so we have to redefine the `SYS_ify' macro here.  */
00047 #undef SYS_ify
00048 #ifdef __STDC__
00049 # define SYS_ify(syscall_name)     __NR_##syscall_name
00050 #else
00051 # define SYS_ify(syscall_name)     __NR_syscall_name
00052 #endif
00053 
00054 #ifndef __ASSEMBLER__
00055 
00056 # include <errno.h>
00057 
00058 # ifdef SHARED
00059 #  define INLINE_VSYSCALL(name, nr, args...) \
00060   ({                                                                 \
00061     __label__ out;                                                   \
00062     __label__ iserr;                                                 \
00063     INTERNAL_SYSCALL_DECL (sc_err);                                         \
00064     long int sc_ret;                                                 \
00065                                                                      \
00066     if (__vdso_##name != NULL)                                              \
00067       {                                                                     \
00068        sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, sc_err, nr, ##args);   \
00069        if (!INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))                      \
00070          goto out;                                                   \
00071        if (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err) != ENOSYS)               \
00072          goto iserr;                                                 \
00073       }                                                                     \
00074                                                                      \
00075     sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, ##args);                   \
00076     if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))                          \
00077       {                                                                     \
00078       iserr:                                                         \
00079         __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));              \
00080         sc_ret = -1L;                                                       \
00081       }                                                                     \
00082   out:                                                               \
00083     sc_ret;                                                          \
00084   })
00085 # else
00086 #  define INLINE_VSYSCALL(name, nr, args...) \
00087   INLINE_SYSCALL (name, nr, ##args)
00088 # endif
00089 
00090 # ifdef SHARED
00091 #  define INTERNAL_VSYSCALL(name, err, nr, args...) \
00092   ({                                                                 \
00093     __label__ out;                                                   \
00094     long int v_ret;                                                  \
00095                                                                      \
00096     if (__vdso_##name != NULL)                                              \
00097       {                                                                     \
00098        v_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args);             \
00099        if (!INTERNAL_SYSCALL_ERROR_P (v_ret, err)                           \
00100            || INTERNAL_SYSCALL_ERRNO (v_ret, err) != ENOSYS)                \
00101          goto out;                                                   \
00102       }                                                                     \
00103     v_ret = INTERNAL_SYSCALL (name, err, nr, ##args);                       \
00104   out:                                                               \
00105     v_ret;                                                           \
00106   })
00107 # else
00108 #  define INTERNAL_VSYSCALL(name, err, nr, args...) \
00109   INTERNAL_SYSCALL (name, err, nr, ##args)
00110 # endif
00111 
00112 # define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, nr, args...)             \
00113   ({                                                                 \
00114     long int sc_ret = ENOSYS;                                               \
00115                                                                      \
00116     if (__vdso_##name != NULL)                                              \
00117       sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args);             \
00118     else                                                             \
00119       err = 1 << 28;                                                 \
00120     sc_ret;                                                          \
00121   })
00122 
00123 /* List of system calls which are supported as vsyscalls.  */
00124 # define HAVE_CLOCK_GETRES_VSYSCALL       1
00125 # define HAVE_CLOCK_GETTIME_VSYSCALL      1
00126 
00127 /* Define a macro which expands inline into the wrapper code for a VDSO
00128    call. This use is for internal calls that do not need to handle errors
00129    normally. It will never touch errno.
00130    On powerpc a system call basically clobbers the same registers like a
00131    function call, with the exception of LR (which is needed for the
00132    "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
00133    an error return status).  */
00134 # define INTERNAL_VSYSCALL_NCS(funcptr, err, nr, args...) \
00135   ({                                                                 \
00136     register void *r0  __asm__ ("r0");                                      \
00137     register long int r3  __asm__ ("r3");                            \
00138     register long int r4  __asm__ ("r4");                            \
00139     register long int r5  __asm__ ("r5");                            \
00140     register long int r6  __asm__ ("r6");                            \
00141     register long int r7  __asm__ ("r7");                            \
00142     register long int r8  __asm__ ("r8");                            \
00143     register long int r9  __asm__ ("r9");                            \
00144     register long int r10 __asm__ ("r10");                                  \
00145     register long int r11 __asm__ ("r11");                                  \
00146     register long int r12 __asm__ ("r12");                                  \
00147     LOADARGS_##nr (funcptr, args);                                   \
00148     __asm__ __volatile__                                             \
00149       ("mtctr %0\n\t"                                                       \
00150        "bctrl\n\t"                                                   \
00151        "mfcr %0"                                                     \
00152        : "=&r" (r0),                                                 \
00153         "=&r" (r3), "=&r" (r4), "=&r" (r5),  "=&r" (r6),  "=&r" (r7),       \
00154         "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12)       \
00155        : ASM_INPUT_##nr                                                     \
00156        : "cr0", "ctr", "lr", "memory");                                     \
00157     err = (long int) r0;                                             \
00158     (int) r3;                                                        \
00159   })
00160 
00161 # undef INLINE_SYSCALL
00162 # define INLINE_SYSCALL(name, nr, args...)                            \
00163   ({                                                           \
00164     INTERNAL_SYSCALL_DECL (sc_err);                                   \
00165     long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args);      \
00166     if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))                    \
00167       {                                                               \
00168        __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));         \
00169        sc_ret = -1L;                                           \
00170       }                                                               \
00171     sc_ret;                                                    \
00172   })
00173 
00174 /* Define a macro which expands inline into the wrapper code for a system
00175    call. This use is for internal calls that do not need to handle errors
00176    normally. It will never touch errno.
00177    On powerpc a system call basically clobbers the same registers like a
00178    function call, with the exception of LR (which is needed for the
00179    "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
00180    an error return status).  */
00181 
00182 # undef INTERNAL_SYSCALL_DECL
00183 # define INTERNAL_SYSCALL_DECL(err) long int err
00184 
00185 # undef INTERNAL_SYSCALL
00186 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...)                 \
00187   ({                                                           \
00188     register long int r0  __asm__ ("r0");                      \
00189     register long int r3  __asm__ ("r3");                      \
00190     register long int r4  __asm__ ("r4");                      \
00191     register long int r5  __asm__ ("r5");                      \
00192     register long int r6  __asm__ ("r6");                      \
00193     register long int r7  __asm__ ("r7");                      \
00194     register long int r8  __asm__ ("r8");                      \
00195     register long int r9  __asm__ ("r9");                      \
00196     register long int r10 __asm__ ("r10");                            \
00197     register long int r11 __asm__ ("r11");                            \
00198     register long int r12 __asm__ ("r12");                            \
00199     LOADARGS_##nr(name, args);                                 \
00200     __asm__ __volatile__                                       \
00201       ("sc   \n\t"                                             \
00202        "mfcr %0"                                               \
00203        : "=&r" (r0),                                           \
00204         "=&r" (r3), "=&r" (r4), "=&r" (r5),  "=&r" (r6),  "=&r" (r7), \
00205         "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \
00206        : ASM_INPUT_##nr                                               \
00207        : "cr0", "ctr", "memory");                              \
00208     err = r0;                                                  \
00209     (int) r3;                                                  \
00210   })
00211 # define INTERNAL_SYSCALL(name, err, nr, args...) \
00212   INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
00213 
00214 # undef INTERNAL_SYSCALL_ERROR_P
00215 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
00216   ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
00217 
00218 # undef INTERNAL_SYSCALL_ERRNO
00219 # define INTERNAL_SYSCALL_ERRNO(val, err)     (val)
00220 
00221 # define LOADARGS_0(name, dummy)                                     \
00222        r0 = name
00223 # define LOADARGS_1(name, __arg1) \
00224        long int arg1 = (long int) (__arg1);      \
00225   LOADARGS_0(name, 0);                                     \
00226        extern void __illegally_sized_syscall_arg1 (void); \
00227        if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
00228          __illegally_sized_syscall_arg1 (); \
00229        r3 = arg1
00230 # define LOADARGS_2(name, __arg1, __arg2) \
00231        long int arg2 = (long int) (__arg2); \
00232        LOADARGS_1(name, __arg1); \
00233        extern void __illegally_sized_syscall_arg2 (void); \
00234        if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
00235          __illegally_sized_syscall_arg2 (); \
00236        r4 = arg2
00237 # define LOADARGS_3(name, __arg1, __arg2, __arg3) \
00238        long int arg3 = (long int) (__arg3); \
00239        LOADARGS_2(name, __arg1, __arg2); \
00240        extern void __illegally_sized_syscall_arg3 (void); \
00241        if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
00242          __illegally_sized_syscall_arg3 (); \
00243        r5 = arg3
00244 # define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
00245        long int arg4 = (long int) (__arg4); \
00246        LOADARGS_3(name, __arg1, __arg2, __arg3); \
00247        extern void __illegally_sized_syscall_arg4 (void); \
00248        if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \
00249          __illegally_sized_syscall_arg4 (); \
00250        r6 = arg4
00251 # define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
00252        long int arg5 = (long int) (__arg5); \
00253        LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
00254        extern void __illegally_sized_syscall_arg5 (void); \
00255        if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
00256          __illegally_sized_syscall_arg5 (); \
00257        r7 = arg5
00258 # define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
00259        long int arg6 = (long int) (__arg6); \
00260        LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
00261        extern void __illegally_sized_syscall_arg6 (void); \
00262        if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
00263          __illegally_sized_syscall_arg6 (); \
00264        r8 = arg6
00265 
00266 # define ASM_INPUT_0 "0" (r0)
00267 # define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
00268 # define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
00269 # define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
00270 # define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
00271 # define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
00272 # define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
00273 
00274 #endif /* __ASSEMBLER__ */
00275 
00276 
00277 /* Pointer mangling support.  */
00278 #if defined NOT_IN_libc && defined IS_IN_rtld
00279 /* We cannot use the thread descriptor because in ld.so we use setjmp
00280    earlier than the descriptor is initialized.  */
00281 #else
00282 # ifdef __ASSEMBLER__
00283 #  define PTR_MANGLE(reg, tmpreg) \
00284        lwz    tmpreg,POINTER_GUARD(r2); \
00285        xor    reg,tmpreg,reg
00286 #  define PTR_MANGLE2(reg, tmpreg) \
00287        xor    reg,tmpreg,reg
00288 #  define PTR_MANGLE3(destreg, reg, tmpreg) \
00289        lwz    tmpreg,POINTER_GUARD(r2); \
00290        xor    destreg,tmpreg,reg
00291 #  define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
00292 #  define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
00293 #  define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
00294 # else
00295 #  define PTR_MANGLE(var) \
00296   (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
00297 #  define PTR_DEMANGLE(var) PTR_MANGLE (var)
00298 # endif
00299 #endif
00300 
00301 #endif /* linux/powerpc/powerpc32/sysdep.h */