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/n64/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 /* Define a macro which expands into the inline wrapper code for a system
00050    call.  */
00051 #undef INLINE_SYSCALL
00052 #define INLINE_SYSCALL(name, nr, args...)                               \
00053   ({ INTERNAL_SYSCALL_DECL(err);                               \
00054      long result_var = INTERNAL_SYSCALL (name, err, nr, args);        \
00055      if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) )                \
00056        {                                                                \
00057          __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err));             \
00058          result_var = -1L;                                            \
00059        }                                                                \
00060      result_var; })
00061 
00062 #undef INTERNAL_SYSCALL_DECL
00063 #define INTERNAL_SYSCALL_DECL(err) long err
00064 
00065 #undef INTERNAL_SYSCALL_ERROR_P
00066 #define INTERNAL_SYSCALL_ERROR_P(val, err)   ((long) (err))
00067 
00068 #undef INTERNAL_SYSCALL_ERRNO
00069 #define INTERNAL_SYSCALL_ERRNO(val, err)     (val)
00070 
00071 #undef INTERNAL_SYSCALL
00072 #define INTERNAL_SYSCALL(name, err, nr, args...) \
00073        internal_syscall##nr (, "li\t$2, %2\t\t\t# " #name "\n\t",     \
00074                            "i" (SYS_ify (name)), err, args)
00075 
00076 #undef INTERNAL_SYSCALL_NCS
00077 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
00078        internal_syscall##nr (= number, , "r" (__v0), err, args)
00079 
00080 #define internal_syscall0(ncs_init, cs_init, input, err, dummy...)    \
00081 ({                                                             \
00082        long _sys_result;                                       \
00083                                                                \
00084        {                                                       \
00085        register long __v0 asm("$2") ncs_init;                         \
00086        register long __a3 asm("$7");                                  \
00087        __asm__ volatile (                                      \
00088        ".set\tnoreorder\n\t"                                          \
00089        cs_init                                                        \
00090        "syscall\n\t"                                                  \
00091        ".set reorder"                                                 \
00092        : "=r" (__v0), "=r" (__a3)                              \
00093        : input                                                        \
00094        : __SYSCALL_CLOBBERS);                                         \
00095        err = __a3;                                             \
00096        _sys_result = __v0;                                     \
00097        }                                                       \
00098        _sys_result;                                            \
00099 })
00100 
00101 #define internal_syscall1(ncs_init, cs_init, input, err, arg1)        \
00102 ({                                                             \
00103        long _sys_result;                                       \
00104                                                                \
00105        {                                                       \
00106        register long __v0 asm("$2") ncs_init;                         \
00107        register long __a0 asm("$4") = (long) arg1;                    \
00108        register long __a3 asm("$7");                                  \
00109        __asm__ volatile (                                      \
00110        ".set\tnoreorder\n\t"                                          \
00111        cs_init                                                        \
00112        "syscall\n\t"                                                  \
00113        ".set reorder"                                                 \
00114        : "=r" (__v0), "=r" (__a3)                              \
00115        : input, "r" (__a0)                                     \
00116        : __SYSCALL_CLOBBERS);                                         \
00117        err = __a3;                                             \
00118        _sys_result = __v0;                                     \
00119        }                                                       \
00120        _sys_result;                                            \
00121 })
00122 
00123 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2)  \
00124 ({                                                             \
00125        long _sys_result;                                       \
00126                                                                \
00127        {                                                       \
00128        register long __v0 asm("$2") ncs_init;                         \
00129        register long __a0 asm("$4") = (long) arg1;                    \
00130        register long __a1 asm("$5") = (long) arg2;                    \
00131        register long __a3 asm("$7");                                  \
00132        __asm__ volatile (                                      \
00133        ".set\tnoreorder\n\t"                                          \
00134        cs_init                                                        \
00135        "syscall\n\t"                                                  \
00136        ".set\treorder"                                         \
00137        : "=r" (__v0), "=r" (__a3)                              \
00138        : input, "r" (__a0), "r" (__a1)                                \
00139        : __SYSCALL_CLOBBERS);                                         \
00140        err = __a3;                                             \
00141        _sys_result = __v0;                                     \
00142        }                                                       \
00143        _sys_result;                                            \
00144 })
00145 
00146 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3) \
00147 ({                                                             \
00148        long _sys_result;                                       \
00149                                                                \
00150        {                                                       \
00151        register long __v0 asm("$2") ncs_init;                         \
00152        register long __a0 asm("$4") = (long) arg1;                    \
00153        register long __a1 asm("$5") = (long) arg2;                    \
00154        register long __a2 asm("$6") = (long) arg3;                    \
00155        register long __a3 asm("$7");                                  \
00156        __asm__ volatile (                                      \
00157        ".set\tnoreorder\n\t"                                          \
00158        cs_init                                                        \
00159        "syscall\n\t"                                                  \
00160        ".set\treorder"                                         \
00161        : "=r" (__v0), "=r" (__a3)                              \
00162        : input, "r" (__a0), "r" (__a1), "r" (__a2)                    \
00163        : __SYSCALL_CLOBBERS);                                         \
00164        err = __a3;                                             \
00165        _sys_result = __v0;                                     \
00166        }                                                       \
00167        _sys_result;                                            \
00168 })
00169 
00170 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4) \
00171 ({                                                             \
00172        long _sys_result;                                       \
00173                                                                \
00174        {                                                       \
00175        register long __v0 asm("$2") ncs_init;                         \
00176        register long __a0 asm("$4") = (long) arg1;                    \
00177        register long __a1 asm("$5") = (long) arg2;                    \
00178        register long __a2 asm("$6") = (long) arg3;                    \
00179        register long __a3 asm("$7") = (long) arg4;                    \
00180        __asm__ volatile (                                      \
00181        ".set\tnoreorder\n\t"                                          \
00182        cs_init                                                        \
00183        "syscall\n\t"                                                  \
00184        ".set\treorder"                                         \
00185        : "=r" (__v0), "+r" (__a3)                              \
00186        : input, "r" (__a0), "r" (__a1), "r" (__a2)                    \
00187        : __SYSCALL_CLOBBERS);                                         \
00188        err = __a3;                                             \
00189        _sys_result = __v0;                                     \
00190        }                                                       \
00191        _sys_result;                                            \
00192 })
00193 
00194 #define internal_syscall5(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5) \
00195 ({                                                             \
00196        long _sys_result;                                       \
00197                                                                \
00198        {                                                       \
00199        register long __v0 asm("$2") ncs_init;                         \
00200        register long __a0 asm("$4") = (long) arg1;                    \
00201        register long __a1 asm("$5") = (long) arg2;                    \
00202        register long __a2 asm("$6") = (long) arg3;                    \
00203        register long __a3 asm("$7") = (long) arg4;                    \
00204        register long __a4 asm("$8") = (long) arg5;                    \
00205        __asm__ volatile (                                      \
00206        ".set\tnoreorder\n\t"                                          \
00207        cs_init                                                        \
00208        "syscall\n\t"                                                  \
00209        ".set\treorder"                                         \
00210        : "=r" (__v0), "+r" (__a3)                              \
00211        : input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4)        \
00212        : __SYSCALL_CLOBBERS);                                         \
00213        err = __a3;                                             \
00214        _sys_result = __v0;                                     \
00215        }                                                       \
00216        _sys_result;                                            \
00217 })
00218 
00219 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6) \
00220 ({                                                             \
00221        long _sys_result;                                       \
00222                                                                \
00223        {                                                       \
00224        register long __v0 asm("$2") ncs_init;                         \
00225        register long __a0 asm("$4") = (long) arg1;                    \
00226        register long __a1 asm("$5") = (long) arg2;                    \
00227        register long __a2 asm("$6") = (long) arg3;                    \
00228        register long __a3 asm("$7") = (long) arg4;                    \
00229        register long __a4 asm("$8") = (long) arg5;                    \
00230        register long __a5 asm("$9") = (long) arg6;                    \
00231        __asm__ volatile (                                      \
00232        ".set\tnoreorder\n\t"                                          \
00233        cs_init                                                        \
00234        "syscall\n\t"                                                  \
00235        ".set\treorder"                                         \
00236        : "=r" (__v0), "+r" (__a3)                              \
00237        : input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4),       \
00238          "r" (__a5)                                            \
00239        : __SYSCALL_CLOBBERS);                                         \
00240        err = __a3;                                             \
00241        _sys_result = __v0;                                     \
00242        }                                                       \
00243        _sys_result;                                            \
00244 })
00245 
00246 #define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \
00247        "$14", "$15", "$24", "$25", "memory"
00248 #endif /* __ASSEMBLER__ */
00249 
00250 /* Pointer mangling is not yet supported for MIPS.  */
00251 #define PTR_MANGLE(var) (void) (var)
00252 #define PTR_DEMANGLE(var) (void) (var)
00253 
00254 #endif /* linux/mips/sysdep.h */