summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libc/sysdeps/linux/sparc/bits/syscalls.h189
1 files changed, 119 insertions, 70 deletions
diff --git a/libc/sysdeps/linux/sparc/bits/syscalls.h b/libc/sysdeps/linux/sparc/bits/syscalls.h
index fdaa4dee1..4dd161ebf 100644
--- a/libc/sysdeps/linux/sparc/bits/syscalls.h
+++ b/libc/sysdeps/linux/sparc/bits/syscalls.h
@@ -31,6 +31,8 @@
# error unknown __WORDSIZE
#endif
+#define __SYSCALL_CLOBBERS "cc", "memory"
+
#define __SYSCALL_RETURN(type) \
if (__SYSCALL_RES_CHECK) \
return (type) __res; \
@@ -41,75 +43,35 @@
#define _syscall0(type,name) \
type name(void) \
{ \
-long __res; \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-__asm__ __volatile__ (__SYSCALL_STRING \
- : "=r" (__res)\
- : "r" (__g1) \
- : "o0", "cc"); \
-__SYSCALL_RETURN(type) \
+ return (type)(INLINE_SYSCALL(name,0)); \
}
#undef _syscall1
#define _syscall1(type,name,type1,arg1) \
type name(type1 arg1) \
{ \
-long __res; \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-register long __o0 __asm__ ("o0") = (long)(arg1); \
-__asm__ __volatile__ (__SYSCALL_STRING \
- : "=r" (__res), "=&r" (__o0) \
- : "1" (__o0), "r" (__g1) \
- : "cc"); \
-__SYSCALL_RETURN(type) \
+ return (type)(INLINE_SYSCALL(name,1,arg1)); \
}
#undef _syscall2
#define _syscall2(type,name,type1,arg1,type2,arg2) \
type name(type1 arg1,type2 arg2) \
{ \
-long __res; \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-register long __o0 __asm__ ("o0") = (long)(arg1); \
-register long __o1 __asm__ ("o1") = (long)(arg2); \
-__asm__ __volatile__ (__SYSCALL_STRING \
- : "=r" (__res), "=&r" (__o0) \
- : "1" (__o0), "r" (__o1), "r" (__g1) \
- : "cc"); \
-__SYSCALL_RETURN(type) \
+ return (type)(INLINE_SYSCALL(name,2,arg1,arg2)); \
}
#undef _syscall3
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
type name(type1 arg1,type2 arg2,type3 arg3) \
{ \
-long __res; \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-register long __o0 __asm__ ("o0") = (long)(arg1); \
-register long __o1 __asm__ ("o1") = (long)(arg2); \
-register long __o2 __asm__ ("o2") = (long)(arg3); \
-__asm__ __volatile__ (__SYSCALL_STRING \
- : "=r" (__res), "=&r" (__o0) \
- : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \
- : "cc"); \
-__SYSCALL_RETURN(type) \
+ return (type)(INLINE_SYSCALL(name,3,arg1,arg2,arg3)); \
}
#undef _syscall4
#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
{ \
-long __res; \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-register long __o0 __asm__ ("o0") = (long)(arg1); \
-register long __o1 __asm__ ("o1") = (long)(arg2); \
-register long __o2 __asm__ ("o2") = (long)(arg3); \
-register long __o3 __asm__ ("o3") = (long)(arg4); \
-__asm__ __volatile__ (__SYSCALL_STRING \
- : "=r" (__res), "=&r" (__o0) \
- : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \
- : "cc"); \
-__SYSCALL_RETURN(type) \
+ return (type)(INLINE_SYSCALL(name,4,arg1,arg2,arg3,arg4)); \
}
#undef _syscall5
@@ -117,18 +79,7 @@ __SYSCALL_RETURN(type) \
type5,arg5) \
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
{ \
-long __res; \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-register long __o0 __asm__ ("o0") = (long)(arg1); \
-register long __o1 __asm__ ("o1") = (long)(arg2); \
-register long __o2 __asm__ ("o2") = (long)(arg3); \
-register long __o3 __asm__ ("o3") = (long)(arg4); \
-register long __o4 __asm__ ("o4") = (long)(arg5); \
-__asm__ __volatile__ (__SYSCALL_STRING \
- : "=r" (__res), "=&r" (__o0) \
- : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__g1) \
- : "cc"); \
-__SYSCALL_RETURN(type) \
+ return (type)(INLINE_SYSCALL(name,5,arg1,arg2,arg3,arg4,arg5)); \
}
#undef _syscall6
@@ -136,20 +87,118 @@ __SYSCALL_RETURN(type) \
type5,arg5,type6,arg6) \
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
{ \
-long __res; \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-register long __o0 __asm__ ("o0") = (long)(arg1); \
-register long __o1 __asm__ ("o1") = (long)(arg2); \
-register long __o2 __asm__ ("o2") = (long)(arg3); \
-register long __o3 __asm__ ("o3") = (long)(arg4); \
-register long __o4 __asm__ ("o4") = (long)(arg5); \
-register long __o5 __asm__ ("o5") = (long)(arg6); \
-__asm__ __volatile__ (__SYSCALL_STRING \
- : "=r" (__res), "=&r" (__o0) \
- : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__o5), "r" (__g1) \
- : "cc"); \
-__SYSCALL_RETURN(type) \
+ return (type)(INLINE_SYSCALL(name,6,arg1,arg2,arg3,arg4,arg5,arg6)); \
+}
+
+#ifndef NOT_IN_libc
+#define DEBUG_SYSCALL(name) { \
+ char d[64];\
+ write( 2, d, snprintf( d, 64, "syscall %d error %d\n", __NR_##name, _inline_sys_result)); \
}
+#else
+#define DEBUG_SYSCALL(name) do{} while(0)
+#endif
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ unsigned int _inline_sys_result = INTERNAL_SYSCALL (name, , nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, )); \
+ _inline_sys_result = (unsigned int) -1; \
+ } \
+ (int) _inline_sys_result; })
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+
+#define INTERNAL_SYSCALL( name, err, nr, args...) \
+ INTERNAL_SYSCALL_NCS( __NR_##name, err, nr, args )
+
+
+#define INTERNAL_SYSCALL_NCS(sys_num, err, nr, args...) \
+ ({ \
+ unsigned int __res; \
+ { \
+ register long __o0 __asm__("o0"); \
+ register long __g1 __asm__("g1") = sys_num; \
+ LOAD_ARGS_##nr(args) \
+ __asm__ __volatile__( __SYSCALL_STRING \
+ : "=r" (__res), "=&r" (__o0) \
+ : "1" (__o0) ASM_ARGS_##nr, "r" (__g1) \
+ : __SYSCALL_CLOBBERS ); \
+ } \
+ (int)__res; \
+ })
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned int) (val) >= 0xfffff001u)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
+
+# define CALL_ERRNO_LOCATION "call __errno_location;"
+#define __CLONE_SYSCALL_STRING \
+ "ta 0x10;" \
+ "bcs 2f;" \
+ " sub %%o1, 1, %%o1;" \
+ "and %%o0, %%o1, %%o0;" \
+ "1:" \
+ ".subsection 2;" \
+ "2:" \
+ "save %%sp, -192, %%sp;" \
+ CALL_ERRNO_LOCATION \
+ " nop;" \
+ "st %%i0, [%%o0];" \
+ "ba 1b;" \
+ " restore %%g0, -1, %%o0;" \
+ ".previous;"
+
+#define INLINE_CLONE_SYSCALL(arg1,arg2,arg3,arg4,arg5) \
+({ \
+ register long __o0 __asm__ ("o0") = (long)(arg1); \
+ register long __o1 __asm__ ("o1") = (long)(arg2); \
+ register long __o2 __asm__ ("o2") = (long)(arg3); \
+ register long __o3 __asm__ ("o3") = (long)(arg4); \
+ register long __o4 __asm__ ("o4") = (long)(arg5); \
+ register long __g1 __asm__ ("g1") = __NR_clone; \
+ __asm __volatile (__CLONE_SYSCALL_STRING : \
+ "=r" (__g1), "=r" (__o0), "=r" (__o1) : \
+ "0" (__g1), "1" (__o0), "2" (__o1), \
+ "r" (__o2), "r" (__o3), "r" (__o4) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+#define LOAD_ARGS_0()
+#define ASM_ARGS_0
+#define LOAD_ARGS_1(o0) \
+ __o0 = (int)o0; \
+ LOAD_ARGS_0()
+#define ASM_ARGS_1 ASM_ARGS_0, "r" (__o0)
+#define LOAD_ARGS_2(o0, o1) \
+ register int __o1 __asm__ ("o1") = (int) (o1); \
+ LOAD_ARGS_1 (o0)
+#define ASM_ARGS_2 ASM_ARGS_1, "r" (__o1)
+#define LOAD_ARGS_3(o0, o1, o2) \
+ register int __o2 __asm__ ("o2") = (int) (o2); \
+ LOAD_ARGS_2 (o0, o1)
+#define ASM_ARGS_3 ASM_ARGS_2, "r" (__o2)
+#define LOAD_ARGS_4(o0, o1, o2, o3) \
+ register int __o3 __asm__ ("o3") = (int) (o3); \
+ LOAD_ARGS_3 (o0, o1, o2)
+#define ASM_ARGS_4 ASM_ARGS_3, "r" (__o3)
+#define LOAD_ARGS_5(o0, o1, o2, o3, o4) \
+ register int __o4 __asm__ ("o4") = (int) (o4); \
+ LOAD_ARGS_4 (o0, o1, o2, o3)
+#define ASM_ARGS_5 ASM_ARGS_4, "r" (__o4)
+#define LOAD_ARGS_6(o0, o1, o2, o3, o4, o5) \
+ register int __o5 __asm__ ("o5") = (int) (o5); \
+ LOAD_ARGS_5 (o0, o1, o2, o3, o4)
+#define ASM_ARGS_6 ASM_ARGS_5, "r" (__o5)
+
#endif /* __ASSEMBLER__ */
#endif /* _BITS_SYSCALLS_H */