summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/m68k
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux/m68k')
-rw-r--r--libc/sysdeps/linux/m68k/bits/syscalls.h290
1 files changed, 154 insertions, 136 deletions
diff --git a/libc/sysdeps/linux/m68k/bits/syscalls.h b/libc/sysdeps/linux/m68k/bits/syscalls.h
index c833cf777..777ff70c3 100644
--- a/libc/sysdeps/linux/m68k/bits/syscalls.h
+++ b/libc/sysdeps/linux/m68k/bits/syscalls.h
@@ -13,64 +13,8 @@
# define __set_errno(val) (*__errno_location ()) = (val)
#endif
-/*
- Some of the sneaky macros in the code were taken from
- glibc-2.2.5/sysdeps/unix/sysv/linux/m68k/sysdep.h
-*/
-
#ifndef __ASSEMBLER__
-#undef _syscall0
-#define _syscall0(type,name) \
-type name(void) \
-{ \
-return (type) (INLINE_SYSCALL(name, 0)); \
-}
-
-#undef _syscall1
-#define _syscall1(type,name,type1,arg1) \
-type name(type1 arg1) \
-{ \
-return (type) (INLINE_SYSCALL(name, 1, arg1)); \
-}
-
-#undef _syscall2
-#define _syscall2(type,name,type1,arg1,type2,arg2) \
-type name(type1 arg1,type2 arg2) \
-{ \
-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) \
-{ \
-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) \
-{ \
-return (type) (INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4)); \
-}
-
-#undef _syscall5
-#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) \
-{ \
-return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
-}
-
-#undef _syscall6
-#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
- type5,arg5,type6,arg6) \
-type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
-{ \
-return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \
-}
-
/* Linux takes system call arguments in registers:
syscall number %d0 call-clobbered
@@ -96,86 +40,160 @@ return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \
speed is more important, we don't use movem. Since %a0 and %a1 are
scratch registers, we can use them for saving as well. */
-#undef INLINE_SYSCALL
-#define INLINE_SYSCALL(name, nr, args...) \
- ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
- if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
- { \
- __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
- _sys_result = (unsigned int) -1; \
- } \
- (int) _sys_result; })
-
-#undef INTERNAL_SYSCALL
-#define INTERNAL_SYSCALL(name, err, nr, args...) \
- ({ unsigned int _sys_result; \
- { \
- /* Load argument values in temporary variables
- to perform side effects like function calls
- before the call used registers are set. */ \
- LOAD_ARGS_##nr (args) \
- LOAD_REGS_##nr \
- register int _d0 asm ("%d0") = __NR_##name; \
- asm volatile ("trap #0" \
- : "=d" (_d0) \
- : "0" (_d0) ASM_ARGS_##nr \
- : "memory"); \
- _sys_result = _d0; \
- } \
- (int) _sys_result; })
-
-#undef INTERNAL_SYSCALL_ERROR_P
-#define INTERNAL_SYSCALL_ERROR_P(val, err) \
- ((unsigned int) (val) >= -4095U)
-
-#undef INTERNAL_SYSCALL_ERRNO
-#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
-
-#define LOAD_ARGS_0()
-#define LOAD_REGS_0
-#define ASM_ARGS_0
-#define LOAD_ARGS_1(a1) \
- LOAD_ARGS_0 () \
- int __arg1 = (int) (a1);
-#define LOAD_REGS_1 \
- register int _d1 asm ("d1") = __arg1; \
- LOAD_REGS_0
-#define ASM_ARGS_1 ASM_ARGS_0, "d" (_d1)
-#define LOAD_ARGS_2(a1, a2) \
- LOAD_ARGS_1 (a1) \
- int __arg2 = (int) (a2);
-#define LOAD_REGS_2 \
- register int _d2 asm ("d2") = __arg2; \
- LOAD_REGS_1
-#define ASM_ARGS_2 ASM_ARGS_1, "d" (_d2)
-#define LOAD_ARGS_3(a1, a2, a3) \
- LOAD_ARGS_2 (a1, a2) \
- int __arg3 = (int) (a3);
-#define LOAD_REGS_3 \
- register int _d3 asm ("d3") = __arg3; \
- LOAD_REGS_2
-#define ASM_ARGS_3 ASM_ARGS_2, "d" (_d3)
-#define LOAD_ARGS_4(a1, a2, a3, a4) \
- LOAD_ARGS_3 (a1, a2, a3) \
- int __arg4 = (int) (a4);
-#define LOAD_REGS_4 \
- register int _d4 asm ("d4") = __arg4; \
- LOAD_REGS_3
-#define ASM_ARGS_4 ASM_ARGS_3, "d" (_d4)
-#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
- LOAD_ARGS_4 (a1, a2, a3, a4) \
- int __arg5 = (int) (a5);
-#define LOAD_REGS_5 \
- register int _d5 asm ("d5") = __arg5; \
- LOAD_REGS_4
-#define ASM_ARGS_5 ASM_ARGS_4, "d" (_d5)
-#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
- LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
- int __arg6 = (int) (a6);
-#define LOAD_REGS_6 \
- register int _a0 asm ("a0") = __arg6; \
- LOAD_REGS_5
-#define ASM_ARGS_6 ASM_ARGS_5, "a" (_a0)
+#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); \
+ __set_errno(__err); \
+ res = -1; \
+ } \
+ return (type) (res); \
+} while (0)
+
+#define _syscall0(type, name) \
+type name(void) \
+{ \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "movel %1, %%d0\n\t" \
+ "trap #0\n\t" \
+ "movel %%d0, %0" \
+ : "=g" (__res) \
+ : "i" (__NR_##name) \
+ : "cc", "%d0"); \
+ __syscall_return(type, __res); \
+}
+
+#define _syscall1(type, name, atype, a) \
+type name(atype a) \
+{ \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "movel %2, %%d1\n\t" \
+ "movel %1, %%d0\n\t" \
+ "trap #0\n\t" \
+ "movel %%d0, %0" \
+ : "=g" (__res) \
+ : "i" (__NR_##name), \
+ "g" ((long)a) \
+ : "cc", "%d0", "%d1"); \
+ __syscall_return(type, __res); \
+}
+
+#define _syscall2(type, name, atype, a, btype, b) \
+type name(atype a, btype b) \
+{ \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "movel %3, %%d2\n\t" \
+ "movel %2, %%d1\n\t" \
+ "movel %1, %%d0\n\t" \
+ "trap #0\n\t" \
+ "movel %%d0, %0" \
+ : "=g" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)a), \
+ "g" ((long)b) \
+ : "cc", "%d0", "%d1", "%d2"); \
+ __syscall_return(type, __res); \
+}
+
+#define _syscall3(type, name, atype, a, btype, b, ctype, c) \
+type name(atype a, btype b, ctype c) \
+{ \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "movel %4, %%d3\n\t" \
+ "movel %3, %%d2\n\t" \
+ "movel %2, %%d1\n\t" \
+ "movel %1, %%d0\n\t" \
+ "trap #0\n\t" \
+ "movel %%d0, %0" \
+ : "=g" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)a), \
+ "a" ((long)b), \
+ "g" ((long)c) \
+ : "cc", "%d0", "%d1", "%d2", "%d3"); \
+ __syscall_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) \
+{ \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "movel %5, %%d4\n\t" \
+ "movel %4, %%d3\n\t" \
+ "movel %3, %%d2\n\t" \
+ "movel %2, %%d1\n\t" \
+ "movel %1, %%d0\n\t" \
+ "trap #0\n\t" \
+ "movel %%d0, %0" \
+ : "=g" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)a), \
+ "a" ((long)b), \
+ "a" ((long)c), \
+ "g" ((long)d) \
+ : "cc", "%d0", "%d1", "%d2", "%d3", \
+ "%d4"); \
+ __syscall_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) \
+{ \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "movel %6, %%d5\n\t" \
+ "movel %5, %%d4\n\t" \
+ "movel %4, %%d3\n\t" \
+ "movel %3, %%d2\n\t" \
+ "movel %2, %%d1\n\t" \
+ "movel %1, %%d0\n\t" \
+ "trap #0\n\t" \
+ "movel %%d0, %0" \
+ : "=g" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)a), \
+ "a" ((long)b), \
+ "a" ((long)c), \
+ "a" ((long)d), \
+ "g" ((long)e) \
+ : "cc", "%d0", "%d1", "%d2", "%d3", \
+ "%d4", "%d5"); \
+ __syscall_return(type, __res); \
+}
+
+#define _syscall6(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e, ftype, f) \
+type name(atype a, btype b, ctype c, dtype d, etype e, ftype f) \
+{ \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "movel %7, %%a0\n\t" \
+ "movel %6, %%d5\n\t" \
+ "movel %5, %%d4\n\t" \
+ "movel %4, %%d3\n\t" \
+ "movel %3, %%d2\n\t" \
+ "movel %2, %%d1\n\t" \
+ "movel %1, %%d0\n\t" \
+ "trap #0\n\t" \
+ "movel %%d0, %0" \
+ : "=g" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)a), \
+ "a" ((long)b), \
+ "a" ((long)c), \
+ "a" ((long)d), \
+ "a" ((long)e), \
+ "g" ((long)f) \
+ : "cc", "%d0", "%d1", "%d2", "%d3", \
+ "%d4", "%d5", "%a0"); \
+ __syscall_return(type, __res); \
+}
#endif /* __ASSEMBLER__ */
#endif /* _BITS_SYSCALLS_H */