summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/h8300/bits/syscalls.h
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-07-15 07:34:00 +0000
committerEric Andersen <andersen@codepoet.org>2004-07-15 07:34:00 +0000
commit71150804d1ac8ed2f7b9c6d3025fd415c58b129e (patch)
treeaab8c892a813847614070f73e711178cd3c9ec74 /libc/sysdeps/linux/h8300/bits/syscalls.h
parent255fbb6abcef56c5f8c36383d49a902686f258f5 (diff)
h8300 updates from Yoshinori Sato
Diffstat (limited to 'libc/sysdeps/linux/h8300/bits/syscalls.h')
-rw-r--r--libc/sysdeps/linux/h8300/bits/syscalls.h156
1 files changed, 147 insertions, 9 deletions
diff --git a/libc/sysdeps/linux/h8300/bits/syscalls.h b/libc/sysdeps/linux/h8300/bits/syscalls.h
index 62541b873..b734a6251 100644
--- a/libc/sysdeps/linux/h8300/bits/syscalls.h
+++ b/libc/sysdeps/linux/h8300/bits/syscalls.h
@@ -1,19 +1,157 @@
-#ifndef _BITS_SYSCALLS_H
-#define _BITS_SYSCALLS_H
+/* Unlike the asm/unistd.h kernel header file (which this is partly based on),
+ * this file must be able to cope with PIC and non-PIC code. For some arches
+ * there is no difference. For x86 (which has far too few registers) there is
+ * a difference. Regardless, including asm/unistd.h is hereby officially
+ * forbidden. Don't do it. It is bad for you.
+ */
#ifndef _SYSCALL_H
# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
#endif
-#include <features.h>
-
-/* Do something very evil for now. Until we create our own syscall
- * macros, short circuit bits/sysnum.h and use asm/unistd.h instead */
-#include <asm/unistd.h>
-
/* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
* header files. It also defines the traditional `SYS_<name>' macros for older
* programs. */
#include <bits/sysnum.h>
-#endif /* _BITS_SYSCALLS_H */
+
+#define __syscall_return(type, res) \
+do { \
+ if ((unsigned long)(res) >= (unsigned long)(-125)) { \
+ /* avoid using res which is declared to be in register d0; \
+ errno might expand to a function call and clobber it. */ \
+ int __err = -(res); \
+ errno = __err; \
+ res = -1; \
+ } \
+ return (type) (res); \
+} while (0)
+
+#define _syscall0(type, name) \
+type name(void) \
+{ \
+ register long __res __asm__("er0"); \
+ __asm__ __volatile__ ("mov.l %1,er0\n\t" \
+ "trapa #0\n\t" \
+ : "=r" (__res) \
+ : "ir" (__NR_##name) \
+ : "cc"); \
+ if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
+ errno = -__res; \
+ __res = -1; \
+ } \
+ return (type)__res; \
+}
+
+#define _syscall1(type, name, atype, a) \
+type name(atype a) \
+{ \
+ register long __res __asm__("er0"); \
+ __asm__ __volatile__ ("mov.l %2, er1\n\t" \
+ "mov.l %1, er0\n\t" \
+ "trapa #0\n\t" \
+ : "=r" (__res) \
+ : "ir" (__NR_##name), \
+ "g" ((long)a) \
+ : "cc", "er1"); \
+ if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
+ errno = -__res; \
+ __res = -1; \
+ } \
+ return (type)__res; \
+}
+
+#define _syscall2(type, name, atype, a, btype, b) \
+type name(atype a, btype b) \
+{ \
+ register long __res __asm__("er0"); \
+ __asm__ __volatile__ ("mov.l %3, er2\n\t" \
+ "mov.l %2, er1\n\t" \
+ "mov.l %1, er0\n\t" \
+ "trapa #0\n\t" \
+ : "=r" (__res) \
+ : "ir" (__NR_##name), \
+ "g" ((long)a), \
+ "g" ((long)b) \
+ : "cc", "er1", "er2"); \
+ if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
+ errno = -__res; \
+ __res = -1; \
+ } \
+ return (type)__res; \
+}
+
+#define _syscall3(type, name, atype, a, btype, b, ctype, c) \
+type name(atype a, btype b, ctype c) \
+{ \
+ register long __res __asm__("er0"); \
+ __asm__ __volatile__ ("mov.l %4, er3\n\t" \
+ "mov.l %3, er2\n\t" \
+ "mov.l %2, er1\n\t" \
+ "mov.l %1, er0\n\t" \
+ "trapa #0\n\t" \
+ : "=r" (__res) \
+ : "ir" (__NR_##name), \
+ "g" ((long)a), \
+ "g" ((long)b), \
+ "g" ((long)c) \
+ : "cc", "er1", "er2", "er3"); \
+ if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
+ errno = -__res; \
+ __res = -1; \
+ } \
+ return (type)__res; \
+}
+
+#define _syscall4(type, name, atype, a, btype, b, ctype, c, dtype, d) \
+type name(atype a, btype b, ctype c, dtype d) \
+{ \
+ register long __res __asm__("er0"); \
+ __asm__ __volatile__ ("mov.l %5, er4\n\t" \
+ "mov.l %4, er3\n\t" \
+ "mov.l %3, er2\n\t" \
+ "mov.l %2, er1\n\t" \
+ "mov.l %1, er0\n\t" \
+ "trapa #0\n\t" \
+ : "=r" (__res) \
+ : "ir" (__NR_##name), \
+ "g" ((long)a), \
+ "g" ((long)b), \
+ "g" ((long)c), \
+ "g" ((long)d) \
+ : "cc", "er1", "er2", "er3", "er4"); \
+ if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
+ errno = -__res; \
+ __res = -1; \
+ } \
+ return (type)__res; \
+}
+
+#define _syscall5(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e) \
+type name(atype a, btype b, ctype c, dtype d, etype e) \
+{ \
+ register long __res __asm__("er0"); \
+ __asm__ __volatile__ ( \
+ "mov.l er5,@-sp\n\t" \
+ "mov.l %5, er4\n\t" \
+ "mov.l %4, er3\n\t" \
+ "mov.l %3, er2\n\t" \
+ "mov.l %2, er1\n\t" \
+ "mov.l %1, er0\n\t" \
+ "mov.l %6, er5\n\t" \
+ "trapa #0\n\t" \
+ "mov.l @sp+,er5\n\t" \
+ : "=r" (__res) \
+ : "ir" (__NR_##name), \
+ "g" ((long)a), \
+ "g" ((long)b), \
+ "g" ((long)c), \
+ "g" ((long)d), \
+ "m" ((long)e) \
+ : "cc", "er1", "er2", "er3", "er4"); \
+ if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
+ errno = -__res; \
+ __res = -1; \
+ } \
+ return (type)__res; \
+}