Back to index

glibc  2.9
sysdep.h
Go to the documentation of this file.
00001 /* Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _LINUX_MIPS_SYSDEP_H
00021 #define _LINUX_MIPS_SYSDEP_H 1
00022 
00023 /* There is some commonality.  */
00024 #include <sysdeps/unix/mips/mips64/n32/sysdep.h>
00025 
00026 #include <tls.h>
00027 
00028 /* For Linux we can use the system call table in the header file
00029        /usr/include/asm/unistd.h
00030    of the kernel.  But these symbols do not follow the SYS_* syntax
00031    so we have to redefine the `SYS_ify' macro here.  */
00032 #undef SYS_ify
00033 #ifdef __STDC__
00034 # define SYS_ify(syscall_name)     __NR_##syscall_name
00035 #else
00036 # define SYS_ify(syscall_name)     __NR_syscall_name
00037 #endif
00038 
00039 #ifdef __ASSEMBLER__
00040 
00041 /* We don't want the label for the error handler to be visible in the symbol
00042    table when we define it here.  */
00043 #ifdef __PIC__
00044 # define SYSCALL_ERROR_LABEL 99b
00045 #endif
00046 
00047 #else   /* ! __ASSEMBLER__ */
00048 
00049 /* Convert X to a long long, without losing any bits if it is one
00050    already or warning if it is a 32-bit pointer.  */
00051 #define ARGIFY(X) ((long long) (__typeof__ ((X) - (X))) (X))
00052 
00053 /* Define a macro which expands into the inline wrapper code for a system
00054    call.  */
00055 #undef INLINE_SYSCALL
00056 #define INLINE_SYSCALL(name, nr, args...)                               \
00057   ({ INTERNAL_SYSCALL_DECL(err);                               \
00058      long result_var = INTERNAL_SYSCALL (name, err, nr, args);        \
00059      if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) )                \
00060        {                                                                \
00061          __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err));             \
00062          result_var = -1L;                                            \
00063        }                                                                \
00064      result_var; })
00065 
00066 #undef INTERNAL_SYSCALL_DECL
00067 #define INTERNAL_SYSCALL_DECL(err) long err
00068 
00069 #undef INTERNAL_SYSCALL_ERROR_P
00070 #define INTERNAL_SYSCALL_ERROR_P(val, err)   ((long) (err))
00071 
00072 #undef INTERNAL_SYSCALL_ERRNO
00073 #define INTERNAL_SYSCALL_ERRNO(val, err)     (val)
00074 
00075 #undef INTERNAL_SYSCALL
00076 #define INTERNAL_SYSCALL(name, err, nr, args...) \
00077        internal_syscall##nr (, "li\t$2, %2\t\t\t# " #name "\n\t",     \
00078                            "i" (SYS_ify (name)), err, args)
00079 
00080 #undef INTERNAL_SYSCALL_NCS
00081 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
00082        internal_syscall##nr (= number, , "r" (__v0), err, args)
00083 
00084 #define internal_syscall0(ncs_init, cs_init, input, err, dummy...)    \
00085 ({                                                             \
00086        long _sys_result;                                       \
00087                                                                \
00088        {                                                       \
00089        register long long __v0 asm("$2") ncs_init;                    \
00090        register long long __a3 asm("$7");                      \
00091        __asm__ volatile (                                      \
00092        ".set\tnoreorder\n\t"                                          \
00093        cs_init                                                        \
00094        "syscall\n\t"                                                  \
00095        ".set reorder"                                                 \
00096        : "=r" (__v0), "=r" (__a3)                              \
00097        : input                                                        \
00098        : __SYSCALL_CLOBBERS);                                         \
00099        err = __a3;                                             \
00100        _sys_result = __v0;                                     \
00101        }                                                       \
00102        _sys_result;                                            \
00103 })
00104 
00105 #define internal_syscall1(ncs_init, cs_init, input, err, arg1)        \
00106 ({                                                             \
00107        long _sys_result;                                       \
00108                                                                \
00109        {                                                       \
00110        register long long __v0 asm("$2") ncs_init;                    \
00111        register long long __a0 asm("$4") = ARGIFY (arg1);             \
00112        register long long __a3 asm("$7");                             \
00113        __asm__ volatile (                                      \
00114        ".set\tnoreorder\n\t"                                          \
00115        cs_init                                                        \
00116        "syscall\n\t"                                                  \
00117        ".set reorder"                                                 \
00118        : "=r" (__v0), "=r" (__a3)                              \
00119        : input, "r" (__a0)                                     \
00120        : __SYSCALL_CLOBBERS);                                         \
00121        err = __a3;                                             \
00122        _sys_result = __v0;                                     \
00123        }                                                       \
00124        _sys_result;                                            \
00125 })
00126 
00127 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2)  \
00128 ({                                                             \
00129        long _sys_result;                                       \
00130                                                                \
00131        {                                                       \
00132        register long long __v0 asm("$2") ncs_init;                    \
00133        register long long __a0 asm("$4") = ARGIFY (arg1);             \
00134        register long long __a1 asm("$5") = ARGIFY (arg2);             \
00135        register long long __a3 asm("$7");                             \
00136        __asm__ volatile (                                      \
00137        ".set\tnoreorder\n\t"                                          \
00138        cs_init                                                        \
00139        "syscall\n\t"                                                  \
00140        ".set\treorder"                                         \
00141        : "=r" (__v0), "=r" (__a3)                              \
00142        : input, "r" (__a0), "r" (__a1)                                \
00143        : __SYSCALL_CLOBBERS);                                         \
00144        err = __a3;                                             \
00145        _sys_result = __v0;                                     \
00146        }                                                       \
00147        _sys_result;                                            \
00148 })
00149 
00150 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3) \
00151 ({                                                             \
00152        long _sys_result;                                       \
00153                                                                \
00154        {                                                       \
00155        register long long __v0 asm("$2") ncs_init;                    \
00156        register long long __a0 asm("$4") = ARGIFY (arg1);             \
00157        register long long __a1 asm("$5") = ARGIFY (arg2);             \
00158        register long long __a2 asm("$6") = ARGIFY (arg3);             \
00159        register long long __a3 asm("$7");                             \
00160        __asm__ volatile (                                      \
00161        ".set\tnoreorder\n\t"                                          \
00162        cs_init                                                        \
00163        "syscall\n\t"                                                  \
00164        ".set\treorder"                                         \
00165        : "=r" (__v0), "=r" (__a3)                              \
00166        : input, "r" (__a0), "r" (__a1), "r" (__a2)                    \
00167        : __SYSCALL_CLOBBERS);                                         \
00168        err = __a3;                                             \
00169        _sys_result = __v0;                                     \
00170        }                                                       \
00171        _sys_result;                                            \
00172 })
00173 
00174 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4) \
00175 ({                                                             \
00176        long _sys_result;                                       \
00177                                                                \
00178        {                                                       \
00179        register long long __v0 asm("$2") ncs_init;                    \
00180        register long long __a0 asm("$4") = ARGIFY (arg1);             \
00181        register long long __a1 asm("$5") = ARGIFY (arg2);             \
00182        register long long __a2 asm("$6") = ARGIFY (arg3);             \
00183        register long long __a3 asm("$7") = ARGIFY (arg4);             \
00184        __asm__ volatile (                                      \
00185        ".set\tnoreorder\n\t"                                          \
00186        cs_init                                                        \
00187        "syscall\n\t"                                                  \
00188        ".set\treorder"                                         \
00189        : "=r" (__v0), "+r" (__a3)                              \
00190        : input, "r" (__a0), "r" (__a1), "r" (__a2)                    \
00191        : __SYSCALL_CLOBBERS);                                         \
00192        err = __a3;                                             \
00193        _sys_result = __v0;                                     \
00194        }                                                       \
00195        _sys_result;                                            \
00196 })
00197 
00198 #define internal_syscall5(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5) \
00199 ({                                                             \
00200        long _sys_result;                                       \
00201                                                                \
00202        {                                                       \
00203        register long long __v0 asm("$2") ncs_init;                    \
00204        register long long __a0 asm("$4") = ARGIFY (arg1);             \
00205        register long long __a1 asm("$5") = ARGIFY (arg2);             \
00206        register long long __a2 asm("$6") = ARGIFY (arg3);             \
00207        register long long __a3 asm("$7") = ARGIFY (arg4);             \
00208        register long long __a4 asm("$8") = ARGIFY (arg5);             \
00209        __asm__ volatile (                                      \
00210        ".set\tnoreorder\n\t"                                          \
00211        cs_init                                                        \
00212        "syscall\n\t"                                                  \
00213        ".set\treorder"                                         \
00214        : "=r" (__v0), "+r" (__a3)                              \
00215        : input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4)        \
00216        : __SYSCALL_CLOBBERS);                                         \
00217        err = __a3;                                             \
00218        _sys_result = __v0;                                     \
00219        }                                                       \
00220        _sys_result;                                            \
00221 })
00222 
00223 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6) \
00224 ({                                                             \
00225        long _sys_result;                                       \
00226                                                                \
00227        {                                                       \
00228        register long long __v0 asm("$2") ncs_init;                    \
00229        register long long __a0 asm("$4") = ARGIFY (arg1);             \
00230        register long long __a1 asm("$5") = ARGIFY (arg2);             \
00231        register long long __a2 asm("$6") = ARGIFY (arg3);             \
00232        register long long __a3 asm("$7") = ARGIFY (arg4);             \
00233        register long long __a4 asm("$8") = ARGIFY (arg5);             \
00234        register long long __a5 asm("$9") = ARGIFY (arg6);             \
00235        __asm__ volatile (                                      \
00236        ".set\tnoreorder\n\t"                                          \
00237        cs_init                                                        \
00238        "syscall\n\t"                                                  \
00239        ".set\treorder"                                         \
00240        : "=r" (__v0), "+r" (__a3)                              \
00241        : input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4),       \
00242          "r" (__a5)                                            \
00243        : __SYSCALL_CLOBBERS);                                         \
00244        err = __a3;                                             \
00245        _sys_result = __v0;                                     \
00246        }                                                       \
00247        _sys_result;                                            \
00248 })
00249 
00250 #define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \
00251        "$14", "$15", "$24", "$25", "memory"
00252 #endif /* __ASSEMBLER__ */
00253 
00254 /* Pointer mangling is not yet supported for MIPS.  */
00255 #define PTR_MANGLE(var) (void) (var)
00256 #define PTR_DEMANGLE(var) (void) (var)
00257 
00258 #endif /* linux/mips/sysdep.h */