aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2004-01-30 21:46:12 +0000
committerH. Peter Anvin <hpa@zytor.com>2004-01-30 21:46:12 +0000
commitea1a9be1658d8d4eb2d07f185a37e8e0b4535631 (patch)
tree76fbdc938934d88e2a18e893b2a464ad8799b416
parent7e68ba9e00f2836001cd948a7f65765dfd392787 (diff)
downloadklibc-ea1a9be1658d8d4eb2d07f185a37e8e0b4535631.tar.gz
Much better x86-64 syscall macrosklibc-0.103
-rw-r--r--include/arch/x86_64/klibc/archsys.h85
-rw-r--r--klibc/arch/x86_64/include/klibc/archsys.h85
2 files changed, 162 insertions, 8 deletions
diff --git a/include/arch/x86_64/klibc/archsys.h b/include/arch/x86_64/klibc/archsys.h
index 3bd8b0a5d9862..2ec72cd397b2c 100644
--- a/include/arch/x86_64/klibc/archsys.h
+++ b/include/arch/x86_64/klibc/archsys.h
@@ -7,9 +7,88 @@
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
-/* x86-64 seems to miss _syscall6() from its headers */
+/* The x86-64 syscall headers are needlessly inefficient */
-#ifndef _syscall6
+#undef _syscall0
+#undef _syscall1
+#undef _syscall2
+#undef _syscall3
+#undef _syscall4
+#undef _syscall5
+#undef _syscall6
+
+#define _syscall0(type,name) \
+type name (void) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall1(type,name,type1,arg1) \
+type name (type1 arg1) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall2(type,name,type1,arg1,type2,arg2) \
+type name (type1 arg1,type2 arg2) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1),"S" (arg2) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
+type name (type1 arg1,type2 arg2,type3 arg3) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
+ "d" (arg3) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#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 type4 __r10 asm("%r10") = arg4; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
+ "d" (arg3),"r" (__r10) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
+ type5,arg5) \
+type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
+{ \
+long __res; \
+register type4 __r10 asm("%r10") = arg4; \
+register type5 __r8 asm("%r8") = arg5; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
+ "d" (arg3),"r" (__r10),"r" (__r8) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
type5,arg5,type6,arg6) \
@@ -27,6 +106,4 @@ __asm__ volatile (__syscall \
__syscall_return(type,__res); \
}
-#endif /* _syscall6 missing */
-
#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/arch/x86_64/include/klibc/archsys.h b/klibc/arch/x86_64/include/klibc/archsys.h
index 3bd8b0a5d9862..2ec72cd397b2c 100644
--- a/klibc/arch/x86_64/include/klibc/archsys.h
+++ b/klibc/arch/x86_64/include/klibc/archsys.h
@@ -7,9 +7,88 @@
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
-/* x86-64 seems to miss _syscall6() from its headers */
+/* The x86-64 syscall headers are needlessly inefficient */
-#ifndef _syscall6
+#undef _syscall0
+#undef _syscall1
+#undef _syscall2
+#undef _syscall3
+#undef _syscall4
+#undef _syscall5
+#undef _syscall6
+
+#define _syscall0(type,name) \
+type name (void) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall1(type,name,type1,arg1) \
+type name (type1 arg1) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall2(type,name,type1,arg1,type2,arg2) \
+type name (type1 arg1,type2 arg2) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1),"S" (arg2) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
+type name (type1 arg1,type2 arg2,type3 arg3) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
+ "d" (arg3) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#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 type4 __r10 asm("%r10") = arg4; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
+ "d" (arg3),"r" (__r10) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
+ type5,arg5) \
+type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
+{ \
+long __res; \
+register type4 __r10 asm("%r10") = arg4; \
+register type5 __r8 asm("%r8") = arg5; \
+__asm__ volatile (__syscall \
+ : "=a" (__res) \
+ : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
+ "d" (arg3),"r" (__r10),"r" (__r8) \
+ : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
type5,arg5,type6,arg6) \
@@ -27,6 +106,4 @@ __asm__ volatile (__syscall \
__syscall_return(type,__res); \
}
-#endif /* _syscall6 missing */
-
#endif /* _KLIBC_ARCHSYS_H */