00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _LINUX_I386_SYSDEP_H
00021 #define _LINUX_I386_SYSDEP_H 1
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #undef SYS_ify
00033 #define SYS_ify(syscall_name) __NR_##syscall_name
00034
00035
00036 #undef L
00037 #define L(name) .L##name
00038
00039 #ifdef __ASSEMBLER__
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifdef PIC
00055 # define SYSCALL_ERROR_LABEL 0f
00056 #else
00057 # define SYSCALL_ERROR_LABEL syscall_error
00058 #endif
00059
00060 #undef PSEUDO
00061 #define PSEUDO(name, syscall_name, args) \
00062 .text; \
00063 ENTRY (name) \
00064 DO_CALL (args, syscall_name); \
00065 cmpl _-4095, %eax; \
00066 jae SYSCALL_ERROR_LABEL; \
00067 L(pseudo_end):
00068
00069 #undef PSEUDO_END
00070 #define PSEUDO_END(name) \
00071 SYSCALL_ERROR_HANDLER \
00072 END (name)
00073
00074 #ifndef PIC
00075 #define SYSCALL_ERROR_HANDLER
00076 #else
00077
00078 #ifdef _LIBC_REENTRANT
00079 #define SYSCALL_ERROR_HANDLER \
00080 0:pushl %ebx; \
00081 call 1f; \
00082 1:popl %ebx; \
00083 xorl %edx, %edx; \
00084 addl __GLOBAL_OFFSET_TABLE_+[.-1b], %ebx; \
00085 subl %eax, %edx; \
00086 pushl %edx; \
00087 PUSH_ERRNO_LOCATION_RETURN; \
00088 call BP_SYM (__errno_location)@PLT; \
00089 POP_ERRNO_LOCATION_RETURN; \
00090 popl %ecx; \
00091 popl %ebx; \
00092 movl %ecx, (%eax); \
00093 orl _-1, %eax; \
00094 jmp L(pseudo_end);
00095
00096
00097 #else
00098 #define SYSCALL_ERROR_HANDLER \
00099 0:call 1f; \
00100 1:popl %ecx; \
00101 xorl %edx, %edx; \
00102 addl __GLOBAL_OFFSET_TABLE_+[.-1b], %ecx; \
00103 subl %eax, %edx; \
00104 movl errno@GOT(%ecx), %ecx; \
00105 movl %edx, (%ecx); \
00106 orl _-1, %eax; \
00107 jmp L(pseudo_end);
00108 #endif
00109 #endif
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 #undef DO_CALL
00156 #define DO_CALL(args, syscall_name) \
00157 PUSHARGS_##args \
00158 DOARGS_##args \
00159 movl _SYS_ify (syscall_name), %eax; \
00160 int _0x80 \
00161 POPARGS_##args
00162
00163 #define PUSHARGS_0
00164 #define DOARGS_0
00165 #define POPARGS_0
00166 #define _PUSHARGS_0
00167 #define _DOARGS_0(n)
00168 #define _POPARGS_0
00169
00170 #define PUSHARGS_1 movl %ebx, %edx; PUSHARGS_0
00171 #define DOARGS_1 _DOARGS_1 (4)
00172 #define POPARGS_1 POPARGS_0; movl %edx, %ebx
00173 #define _PUSHARGS_1 pushl %ebx; _PUSHARGS_0
00174 #define _DOARGS_1(n) movl n(%esp), %ebx; _DOARGS_0(n-4)
00175 #define _POPARGS_1 _POPARGS_0; popl %ebx
00176
00177 #define PUSHARGS_2 PUSHARGS_1
00178 #define DOARGS_2 _DOARGS_2 (8)
00179 #define POPARGS_2 POPARGS_1
00180 #define _PUSHARGS_2 _PUSHARGS_1
00181 #define _DOARGS_2(n) movl n(%esp), %ecx; _DOARGS_1 (n-4)
00182 #define _POPARGS_2 _POPARGS_1
00183
00184 #define PUSHARGS_3 _PUSHARGS_2
00185 #define DOARGS_3 _DOARGS_3 (16)
00186 #define POPARGS_3 _POPARGS_3
00187 #define _PUSHARGS_3 _PUSHARGS_2
00188 #define _DOARGS_3(n) movl n(%esp), %edx; _DOARGS_2 (n-4)
00189 #define _POPARGS_3 _POPARGS_2
00190
00191 #define PUSHARGS_4 _PUSHARGS_4
00192 #define DOARGS_4 _DOARGS_4 (24)
00193 #define POPARGS_4 _POPARGS_4
00194 #define _PUSHARGS_4 pushl %esi; _PUSHARGS_3
00195 #define _DOARGS_4(n) movl n(%esp), %esi; _DOARGS_3 (n-4)
00196 #define _POPARGS_4 _POPARGS_3; popl %esi
00197
00198 #define PUSHARGS_5 _PUSHARGS_5
00199 #define DOARGS_5 _DOARGS_5 (32)
00200 #define POPARGS_5 _POPARGS_5
00201 #define _PUSHARGS_5 pushl %edi; _PUSHARGS_4
00202 #define _DOARGS_5(n) movl n(%esp), %edi; _DOARGS_4 (n-4)
00203 #define _POPARGS_5 _POPARGS_4; popl %edi
00204
00205 #else
00206
00207
00208
00209 asm (".L__X'%ebx = 1\n\t"
00210 ".L__X'%ecx = 2\n\t"
00211 ".L__X'%edx = 2\n\t"
00212 ".L__X'%eax = 3\n\t"
00213 ".L__X'%esi = 3\n\t"
00214 ".L__X'%edi = 3\n\t"
00215 ".L__X'%ebp = 3\n\t"
00216 ".L__X'%esp = 3\n\t"
00217 ".macro bpushl name reg\n\t"
00218 ".if 1 - \\name\n\t"
00219 ".if 2 - \\name\n\t"
00220 "pushl %ebx\n\t"
00221 ".else\n\t"
00222 "xchgl \\reg, %ebx\n\t"
00223 ".endif\n\t"
00224 ".endif\n\t"
00225 ".endm\n\t"
00226 ".macro bpopl name reg\n\t"
00227 ".if 1 - \\name\n\t"
00228 ".if 2 - \\name\n\t"
00229 "popl %ebx\n\t"
00230 ".else\n\t"
00231 "xchgl \\reg, %ebx\n\t"
00232 ".endif\n\t"
00233 ".endif\n\t"
00234 ".endm\n\t"
00235 ".macro bmovl name reg\n\t"
00236 ".if 1 - \\name\n\t"
00237 ".if 2 - \\name\n\t"
00238 "movl \\reg, %ebx\n\t"
00239 ".endif\n\t"
00240 ".endif\n\t"
00241 ".endm\n\t");
00242
00243 extern int errno;
00244
00245
00246
00247 #undef INLINE_SYSCALL
00248 #define INLINE_SYSCALL(name, nr, args...) \
00249 ({ \
00250 unsigned int resultvar; \
00251 asm volatile ( \
00252 LOADARGS_##nr \
00253 "movl %1, %%eax\n\t" \
00254 "int _0x80\n\t" \
00255 RESTOREARGS_##nr \
00256 : "=a" (resultvar) \
00257 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00258 if (resultvar >= 0xfffff001) \
00259 { \
00260 errno= (-resultvar); \
00261 resultvar = 0xffffffff; \
00262 } \
00263 (int) resultvar; })
00264
00265 #undef INLINE_SYSCALL1
00266 #define INLINE_SYSCALL1(name, nr, args...) \
00267 ({ \
00268 unsigned int resultvar; \
00269 asm volatile ( \
00270 LOADARGS_##nr \
00271 "movl %1, %%eax\n\t" \
00272 "int _0x80\n\t" \
00273 RESTOREARGS_##nr \
00274 : "=a" (resultvar) \
00275 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00276 if (resultvar >= 0xfffff001) \
00277 { \
00278 errno= (-resultvar); \
00279 resultvar = 0xffffffff; \
00280 } \
00281 (int) resultvar; })
00282
00283 #undef INLINE_SYSCALL3
00284 #define INLINE_SYSCALL3(name, nr, args...) \
00285 ({ \
00286 unsigned int resultvar; \
00287 asm volatile ( \
00288 LOADARGS_##nr \
00289 "movl %1, %%eax\n\t" \
00290 "int _0x80\n\t" \
00291 RESTOREARGS_##nr \
00292 : "=a" (resultvar) \
00293 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00294 if (resultvar >= 0xfffff001) \
00295 { \
00296 errno= (-resultvar); \
00297 resultvar = 0xffffffff; \
00298 } \
00299 (int) resultvar; })
00300
00301 #undef INLINE_SYSCALLTEST
00302 #define INLINE_SYSCALLTEST(name, nr, args...) \
00303 ({ \
00304 unsigned int resultvar; \
00305 asm volatile ( \
00306 LOADARGS_##nr \
00307 "movl %1, %%eax\n\t" \
00308 "call 0xc0100010\n\t" \
00309 RESTOREARGS_##nr \
00310 : "=a" (resultvar) \
00311 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00312 if (resultvar >= 0xfffff001) \
00313 { \
00314 errno= (-resultvar); \
00315 resultvar = 0xffffffff; \
00316 } \
00317 (int) resultvar; })
00318
00319 #define LOADARGS_0
00320 #define LOADARGS_1 \
00321 "bpushl .L__X'%k2, %k2\n\t" \
00322 "bmovl .L__X'%k2, %k2\n\t"
00323 #define LOADARGS_2 LOADARGS_1
00324 #define LOADARGS_3 LOADARGS_1
00325 #define LOADARGS_4 LOADARGS_1
00326 #define LOADARGS_5 LOADARGS_1
00327
00328 #define RESTOREARGS_0
00329 #define RESTOREARGS_1 \
00330 "bpopl .L__X'%k2, %k2\n\t"
00331 #define RESTOREARGS_2 RESTOREARGS_1
00332 #define RESTOREARGS_3 RESTOREARGS_1
00333 #define RESTOREARGS_4 RESTOREARGS_1
00334 #define RESTOREARGS_5 RESTOREARGS_1
00335
00336 #define ASMFMT_0()
00337 #define ASMFMT_1(arg1) \
00338 , "acdSD" (arg1)
00339 #define ASMFMT_2(arg1, arg2) \
00340 , "adCD" (arg1), "c" (arg2)
00341 #define ASMFMT_3(arg1, arg2, arg3) \
00342 , "aCD" (arg1), "c" (arg2), "d" (arg3)
00343 #define ASMFMT_4(arg1, arg2, arg3, arg4) \
00344 , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
00345 #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
00346 , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
00347
00348 #endif
00349
00350 #endif
00351