xref: /third_party/musl/arch/i386/syscall_arch.h (revision 570af302)
1570af302Sopenharmony_ci#define __SYSCALL_LL_E(x) \
2570af302Sopenharmony_ci((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
3570af302Sopenharmony_ci((union { long long ll; long l[2]; }){ .ll = x }).l[1]
4570af302Sopenharmony_ci#define __SYSCALL_LL_O(x) __SYSCALL_LL_E((x))
5570af302Sopenharmony_ci
6570af302Sopenharmony_ci#if SYSCALL_NO_TLS
7570af302Sopenharmony_ci#define SYSCALL_INSNS "int $128"
8570af302Sopenharmony_ci#else
9570af302Sopenharmony_ci#define SYSCALL_INSNS "call *%%gs:16"
10570af302Sopenharmony_ci#endif
11570af302Sopenharmony_ci
12570af302Sopenharmony_ci#define SYSCALL_INSNS_12 "xchg %%ebx,%%edx ; " SYSCALL_INSNS " ; xchg %%ebx,%%edx"
13570af302Sopenharmony_ci#define SYSCALL_INSNS_34 "xchg %%ebx,%%edi ; " SYSCALL_INSNS " ; xchg %%ebx,%%edi"
14570af302Sopenharmony_ci
15570af302Sopenharmony_cistatic inline long __syscall0(long n)
16570af302Sopenharmony_ci{
17570af302Sopenharmony_ci	unsigned long __ret;
18570af302Sopenharmony_ci	__asm__ __volatile__ (SYSCALL_INSNS : "=a"(__ret) : "a"(n) : "memory");
19570af302Sopenharmony_ci	return __ret;
20570af302Sopenharmony_ci}
21570af302Sopenharmony_ci
22570af302Sopenharmony_cistatic inline long __syscall1(long n, long a1)
23570af302Sopenharmony_ci{
24570af302Sopenharmony_ci	unsigned long __ret;
25570af302Sopenharmony_ci	__asm__ __volatile__ (SYSCALL_INSNS_12 : "=a"(__ret) : "a"(n), "d"(a1) : "memory");
26570af302Sopenharmony_ci	return __ret;
27570af302Sopenharmony_ci}
28570af302Sopenharmony_ci
29570af302Sopenharmony_cistatic inline long __syscall2(long n, long a1, long a2)
30570af302Sopenharmony_ci{
31570af302Sopenharmony_ci	unsigned long __ret;
32570af302Sopenharmony_ci	__asm__ __volatile__ (SYSCALL_INSNS_12 : "=a"(__ret) : "a"(n), "d"(a1), "c"(a2) : "memory");
33570af302Sopenharmony_ci	return __ret;
34570af302Sopenharmony_ci}
35570af302Sopenharmony_ci
36570af302Sopenharmony_cistatic inline long __syscall3(long n, long a1, long a2, long a3)
37570af302Sopenharmony_ci{
38570af302Sopenharmony_ci	unsigned long __ret;
39570af302Sopenharmony_ci#if !defined(__PIC__) || !defined(BROKEN_EBX_ASM)
40570af302Sopenharmony_ci	__asm__ __volatile__ (SYSCALL_INSNS : "=a"(__ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3) : "memory");
41570af302Sopenharmony_ci#else
42570af302Sopenharmony_ci	__asm__ __volatile__ (SYSCALL_INSNS_34 : "=a"(__ret) : "a"(n), "D"(a1), "c"(a2), "d"(a3) : "memory");
43570af302Sopenharmony_ci#endif
44570af302Sopenharmony_ci	return __ret;
45570af302Sopenharmony_ci}
46570af302Sopenharmony_ci
47570af302Sopenharmony_cistatic inline long __syscall4(long n, long a1, long a2, long a3, long a4)
48570af302Sopenharmony_ci{
49570af302Sopenharmony_ci	unsigned long __ret;
50570af302Sopenharmony_ci#if !defined(__PIC__) || !defined(BROKEN_EBX_ASM)
51570af302Sopenharmony_ci	__asm__ __volatile__ (SYSCALL_INSNS : "=a"(__ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4) : "memory");
52570af302Sopenharmony_ci#else
53570af302Sopenharmony_ci	__asm__ __volatile__ (SYSCALL_INSNS_34 : "=a"(__ret) : "a"(n), "D"(a1), "c"(a2), "d"(a3), "S"(a4) : "memory");
54570af302Sopenharmony_ci#endif
55570af302Sopenharmony_ci	return __ret;
56570af302Sopenharmony_ci}
57570af302Sopenharmony_ci
58570af302Sopenharmony_cistatic inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5)
59570af302Sopenharmony_ci{
60570af302Sopenharmony_ci	unsigned long __ret;
61570af302Sopenharmony_ci#if !defined(__PIC__) || !defined(BROKEN_EBX_ASM)
62570af302Sopenharmony_ci	__asm__ __volatile__ (SYSCALL_INSNS
63570af302Sopenharmony_ci		: "=a"(__ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5) : "memory");
64570af302Sopenharmony_ci#else
65570af302Sopenharmony_ci	__asm__ __volatile__ ("pushl %2 ; push %%ebx ; mov 4(%%esp),%%ebx ; " SYSCALL_INSNS " ; pop %%ebx ; add $4,%%esp"
66570af302Sopenharmony_ci		: "=a"(__ret) : "a"(n), "g"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5) : "memory");
67570af302Sopenharmony_ci#endif
68570af302Sopenharmony_ci	return __ret;
69570af302Sopenharmony_ci}
70570af302Sopenharmony_ci
71570af302Sopenharmony_cistatic inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6)
72570af302Sopenharmony_ci{
73570af302Sopenharmony_ci	unsigned long __ret;
74570af302Sopenharmony_ci#if !defined(__PIC__) || !defined(BROKEN_EBX_ASM)
75570af302Sopenharmony_ci	__asm__ __volatile__ ("pushl %7 ; push %%ebp ; mov 4(%%esp),%%ebp ; " SYSCALL_INSNS " ; pop %%ebp ; add $4,%%esp"
76570af302Sopenharmony_ci		: "=a"(__ret) : "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5), "g"(a6) : "memory");
77570af302Sopenharmony_ci#else
78570af302Sopenharmony_ci	unsigned long a1a6[2] = { a1, a6 };
79570af302Sopenharmony_ci	__asm__ __volatile__ ("pushl %1 ; push %%ebx ; push %%ebp ; mov 8(%%esp),%%ebx ; mov 4(%%ebx),%%ebp ; mov (%%ebx),%%ebx ; " SYSCALL_INSNS " ; pop %%ebp ; pop %%ebx ; add $4,%%esp"
80570af302Sopenharmony_ci		: "=a"(__ret) : "g"(&a1a6), "a"(n), "c"(a2), "d"(a3), "S"(a4), "D"(a5) : "memory");
81570af302Sopenharmony_ci#endif
82570af302Sopenharmony_ci	return __ret;
83570af302Sopenharmony_ci}
84570af302Sopenharmony_ci
85570af302Sopenharmony_ci#define VDSO_USEFUL
86570af302Sopenharmony_ci#define VDSO_CGT32_SYM "__vdso_clock_gettime"
87570af302Sopenharmony_ci#define VDSO_CGT32_VER "LINUX_2.6"
88570af302Sopenharmony_ci#define VDSO_CGT_SYM "__vdso_clock_gettime64"
89570af302Sopenharmony_ci#define VDSO_CGT_VER "LINUX_2.6"
90