#ifndef LIBURING_ARCH_X86_SYSCALL_H
#define LIBURING_ARCH_X86_SYSCALL_H
#if defined(__x86_64__)
#define __do_syscall0(NUM) ({ \
intptr_t rax; \
\
__asm__ volatile( \
"syscall" \
: "=a"(rax) \
: "a"(NUM) \
: "rcx", "r11", "memory" \
); \
rax; \
})
#define __do_syscall1(NUM, ARG1) ({ \
intptr_t rax; \
\
__asm__ volatile( \
"syscall" \
: "=a"(rax) \
: "a"((NUM)), \
"D"((ARG1)) \
: "rcx", "r11", "memory" \
); \
rax; \
})
#define __do_syscall2(NUM, ARG1, ARG2) ({ \
intptr_t rax; \
\
__asm__ volatile( \
"syscall" \
: "=a"(rax) \
: "a"((NUM)), \
"D"((ARG1)), \
"S"((ARG2)) \
: "rcx", "r11", "memory" \
); \
rax; \
})
#define __do_syscall3(NUM, ARG1, ARG2, ARG3) ({ \
intptr_t rax; \
\
__asm__ volatile( \
"syscall" \
: "=a"(rax) \
: "a"((NUM)), \
"D"((ARG1)), \
"S"((ARG2)), \
"d"((ARG3)) \
: "rcx", "r11", "memory" \
); \
rax; \
})
#define __do_syscall4(NUM, ARG1, ARG2, ARG3, ARG4) ({ \
intptr_t rax; \
register __typeof__(ARG4) __r10 __asm__("r10") = (ARG4); \
\
__asm__ volatile( \
"syscall" \
: "=a"(rax) \
: "a"((NUM)), \
"D"((ARG1)), \
"S"((ARG2)), \
"d"((ARG3)), \
"r"(__r10) \
: "rcx", "r11", "memory" \
); \
rax; \
})
#define __do_syscall5(NUM, ARG1, ARG2, ARG3, ARG4, ARG5) ({ \
intptr_t rax; \
register __typeof__(ARG4) __r10 __asm__("r10") = (ARG4); \
register __typeof__(ARG5) __r8 __asm__("r8") = (ARG5); \
\
__asm__ volatile( \
"syscall" \
: "=a"(rax) \
: "a"((NUM)), \
"D"((ARG1)), \
"S"((ARG2)), \
"d"((ARG3)), \
"r"(__r10), \
"r"(__r8) \
: "rcx", "r11", "memory" \
); \
rax; \
})
#define __do_syscall6(NUM, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) ({ \
intptr_t rax; \
register __typeof__(ARG4) __r10 __asm__("r10") = (ARG4); \
register __typeof__(ARG5) __r8 __asm__("r8") = (ARG5); \
register __typeof__(ARG6) __r9 __asm__("r9") = (ARG6); \
\
__asm__ volatile( \
"syscall" \
: "=a"(rax) \
: "a"((NUM)), \
"D"((ARG1)), \
"S"((ARG2)), \
"d"((ARG3)), \
"r"(__r10), \
"r"(__r8), \
"r"(__r9) \
: "rcx", "r11", "memory" \
); \
rax; \
})
#include "../syscall-defs.h"
#else
#ifdef CONFIG_NOLIBC
#define __do_syscall0(NUM) ({ \
intptr_t eax; \
\
__asm__ volatile( \
"int $0x80" \
: "=a"(eax) \
: "a"(NUM) \
: "memory" \
); \
eax; \
})
#define __do_syscall1(NUM, ARG1) ({ \
intptr_t eax; \
\
__asm__ volatile( \
"int $0x80" \
: "=a"(eax) \
: "a"(NUM), \
"b"((ARG1)) \
: "memory" \
); \
eax; \
})
#define __do_syscall2(NUM, ARG1, ARG2) ({ \
intptr_t eax; \
\
__asm__ volatile( \
"int $0x80" \
: "=a" (eax) \
: "a"(NUM), \
"b"((ARG1)), \
"c"((ARG2)) \
: "memory" \
); \
eax; \
})
#define __do_syscall3(NUM, ARG1, ARG2, ARG3) ({ \
intptr_t eax; \
\
__asm__ volatile( \
"int $0x80" \
: "=a" (eax) \
: "a"(NUM), \
"b"((ARG1)), \
"c"((ARG2)), \
"d"((ARG3)) \
: "memory" \
); \
eax; \
})
#define __do_syscall4(NUM, ARG1, ARG2, ARG3, ARG4) ({ \
intptr_t eax; \
\
__asm__ volatile( \
"int $0x80" \
: "=a" (eax) \
: "a"(NUM), \
"b"((ARG1)), \
"c"((ARG2)), \
"d"((ARG3)), \
"S"((ARG4)) \
: "memory" \
); \
eax; \
})
#define __do_syscall5(NUM, ARG1, ARG2, ARG3, ARG4, ARG5) ({ \
intptr_t eax; \
\
__asm__ volatile( \
"int $0x80" \
: "=a" (eax) \
: "a"(NUM), \
"b"((ARG1)), \
"c"((ARG2)), \
"d"((ARG3)), \
"S"((ARG4)), \
"D"((ARG5)) \
: "memory" \
); \
eax; \
})
#define __do_syscall6(NUM, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) ({ \
intptr_t eax = (intptr_t)(NUM); \
intptr_t arg6 = (intptr_t)(ARG6); \
__asm__ volatile ( \
"pushl %[_arg6]\n\t" \
"pushl %%ebp\n\t" \
"movl 4(%%esp),%%ebp\n\t" \
"int $0x80\n\t" \
"popl %%ebp\n\t" \
"addl $4,%%esp" \
: "+a"(eax) \
: "b"(ARG1), \
"c"(ARG2), \
"d"(ARG3), \
"S"(ARG4), \
"D"(ARG5), \
[_arg6]"m"(arg6) \
: "memory", "cc" \
); \
eax; \
})
#include "../syscall-defs.h"
#else
#include "../generic/syscall.h"
#endif
#endif
#endif