OSDN Git Service

Merge commit 'origin/master' into nptl
[uclinux-h8/uclibc-ng.git] / libc / sysdeps / linux / i386 / bits / syscalls.h
1 #ifndef _BITS_SYSCALLS_H
2 #define _BITS_SYSCALLS_H
3 #ifndef _SYSCALL_H
4 # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
5 #endif
6
7 /*
8    Some of the sneaky macros in the code were taken from
9    glibc-2.2.5/sysdeps/unix/sysv/linux/i386/sysdep.h
10 */
11
12 #ifndef __ASSEMBLER__
13
14 #include <errno.h>
15
16 /* We need some help from the assembler to generate optimal code.  We
17    define some macros here which later will be used.  */
18
19 #if defined  __SUPPORT_LD_DEBUG__ && defined __DOMULTI__
20 #error LD debugging and DOMULTI are incompatible
21 #endif
22
23 #ifdef __DOMULTI__
24 __asm__ (".L__X'%ebx = 1\n\t"
25      ".L__X'%ecx = 2\n\t"
26      ".L__X'%edx = 2\n\t"
27      ".L__X'%eax = 3\n\t"
28      ".L__X'%esi = 3\n\t"
29      ".L__X'%edi = 3\n\t"
30      ".L__X'%ebp = 3\n\t"
31      ".L__X'%esp = 3\n\t"
32      ".ifndef _BITS_SYSCALLS_ASM\n\t"
33      ".set _BITS_SYSCALLS_ASM,1\n\t"
34      ".macro bpushl name reg\n\t"
35      ".if 1 - \\name\n\t"
36      ".if 2 - \\name\n\t"
37      "pushl %ebx\n\t"
38      ".else\n\t"
39      "xchgl \\reg, %ebx\n\t"
40      ".endif\n\t"
41      ".endif\n\t"
42      ".endm\n\t"
43      ".macro bpopl name reg\n\t"
44      ".if 1 - \\name\n\t"
45      ".if 2 - \\name\n\t"
46      "popl %ebx\n\t"
47      ".else\n\t"
48      "xchgl \\reg, %ebx\n\t"
49      ".endif\n\t"
50      ".endif\n\t"
51      ".endm\n\t"
52      ".macro bmovl name reg\n\t"
53      ".if 1 - \\name\n\t"
54      ".if 2 - \\name\n\t"
55      "movl \\reg, %ebx\n\t"
56      ".endif\n\t"
57      ".endif\n\t"
58      ".endm\n\t"
59      ".endif\n\t");
60 #else
61 __asm__ (".L__X'%ebx = 1\n\t"
62      ".L__X'%ecx = 2\n\t"
63      ".L__X'%edx = 2\n\t"
64      ".L__X'%eax = 3\n\t"
65      ".L__X'%esi = 3\n\t"
66      ".L__X'%edi = 3\n\t"
67      ".L__X'%ebp = 3\n\t"
68      ".L__X'%esp = 3\n\t"
69      ".macro bpushl name reg\n\t"
70      ".if 1 - \\name\n\t"
71      ".if 2 - \\name\n\t"
72      "pushl %ebx\n\t"
73      ".else\n\t"
74      "xchgl \\reg, %ebx\n\t"
75      ".endif\n\t"
76      ".endif\n\t"
77      ".endm\n\t"
78      ".macro bpopl name reg\n\t"
79      ".if 1 - \\name\n\t"
80      ".if 2 - \\name\n\t"
81      "popl %ebx\n\t"
82      ".else\n\t"
83      "xchgl \\reg, %ebx\n\t"
84      ".endif\n\t"
85      ".endif\n\t"
86      ".endm\n\t"
87      ".macro bmovl name reg\n\t"
88      ".if 1 - \\name\n\t"
89      ".if 2 - \\name\n\t"
90      "movl \\reg, %ebx\n\t"
91      ".endif\n\t"
92      ".endif\n\t"
93      ".endm\n\t");
94 #endif
95
96 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
97   ({                                                                          \
98     register unsigned int resultvar;                                          \
99     __asm__ __volatile__ (                                                    \
100     LOADARGS_##nr                                                             \
101     "movl %1, %%eax\n\t"                                                      \
102     "int $0x80\n\t"                                                           \
103     RESTOREARGS_##nr                                                          \
104     : "=a" (resultvar)                                                        \
105     : "g" (name) ASMFMT_##nr(args) : "memory", "cc");                         \
106      (int) resultvar; })
107
108 #define LOADARGS_0
109 #define LOADARGS_1 \
110     "bpushl .L__X'%k2, %k2\n\t"                                               \
111     "bmovl .L__X'%k2, %k2\n\t"
112 #define LOADARGS_2      LOADARGS_1
113 #define LOADARGS_3      LOADARGS_1
114 #define LOADARGS_4      LOADARGS_1
115 #define LOADARGS_5      LOADARGS_1
116 #define LOADARGS_6      LOADARGS_1 "push %%ebp ; movl %7, %%ebp\n\t"
117
118 #define RESTOREARGS_0
119 #define RESTOREARGS_1 \
120     "bpopl .L__X'%k2, %k2\n\t"
121 #define RESTOREARGS_2   RESTOREARGS_1
122 #define RESTOREARGS_3   RESTOREARGS_1
123 #define RESTOREARGS_4   RESTOREARGS_1
124 #define RESTOREARGS_5   RESTOREARGS_1
125 #define RESTOREARGS_6   "pop %%ebp\n\t" RESTOREARGS_1
126
127 #define ASMFMT_0()
128 #define ASMFMT_1(arg1) \
129         , "acdSD" (arg1)
130 #define ASMFMT_2(arg1, arg2) \
131         , "adSD" (arg1), "c" (arg2)
132 #define ASMFMT_3(arg1, arg2, arg3) \
133         , "aSD" (arg1), "c" (arg2), "d" (arg3)
134 #define ASMFMT_4(arg1, arg2, arg3, arg4) \
135         , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
136 #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
137         , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
138 #define ASMFMT_6(arg1, arg2, arg3, arg4, arg5, arg6) \
139         , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5), "m" (arg6)
140
141 #endif /* __ASSEMBLER__ */
142 #endif /* _BITS_SYSCALLS_H */