Merge branches 'acpi-video' and 'cpufreq-fixes'
[linux-2.6-block.git] / arch / x86 / entry / entry_64_compat.S
CommitLineData
1da177e4 1/*
54ad726c
IM
2 * Compatibility mode system call entry point for x86-64.
3 *
1da177e4 4 * Copyright 2000-2002 Andi Kleen, SuSE Labs.
54ad726c 5 */
d36f9479 6#include "calling.h"
e2d5df93 7#include <asm/asm-offsets.h>
1da177e4
LT
8#include <asm/current.h>
9#include <asm/errno.h>
54ad726c
IM
10#include <asm/ia32_unistd.h>
11#include <asm/thread_info.h>
1da177e4 12#include <asm/segment.h>
2601e64d 13#include <asm/irqflags.h>
1ce6f868 14#include <asm/asm.h>
63bcff2a 15#include <asm/smap.h>
1da177e4 16#include <linux/linkage.h>
d7e7528b 17#include <linux/err.h>
1da177e4 18
5cbf1565
RM
19/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
20#include <linux/elf-em.h>
21#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
54ad726c 22#define __AUDIT_ARCH_LE 0x40000000
5cbf1565
RM
23
24#ifndef CONFIG_AUDITSYSCALL
54ad726c
IM
25# define sysexit_audit ia32_ret_from_sys_call
26# define sysretl_audit ia32_ret_from_sys_call
5cbf1565
RM
27#endif
28
ea714547
JO
29 .section .entry.text, "ax"
30
2be29982
JF
31#ifdef CONFIG_PARAVIRT
32ENTRY(native_usergs_sysret32)
33 swapgs
34 sysretl
35ENDPROC(native_usergs_sysret32)
2be29982
JF
36#endif
37
1da177e4 38/*
54ad726c 39 * 32-bit SYSENTER instruction entry.
1da177e4 40 *
b87cf63e
DV
41 * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs.
42 * IF and VM in rflags are cleared (IOW: interrupts are off).
43 * SYSENTER does not save anything on the stack,
44 * and does not save old rip (!!!) and rflags.
45 *
1da177e4 46 * Arguments:
b87cf63e
DV
47 * eax system call number
48 * ebx arg1
49 * ecx arg2
50 * edx arg3
51 * esi arg4
52 * edi arg5
53 * ebp user stack
54 * 0(%ebp) arg6
55 *
1da177e4 56 * This is purely a fast path. For anything complicated we use the int 0x80
b87cf63e 57 * path below. We set up a complete hardware stack frame to share code
1da177e4 58 * with the int 0x80 path.
b87cf63e 59 */
4c8cd0c5 60ENTRY(entry_SYSENTER_compat)
2601e64d 61 /*
a232e3d5
DV
62 * Interrupts are off on entry.
63 * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
64 * it is too small to ever cause noticeable irq latency.
2601e64d 65 */
a232e3d5 66 SWAPGS_UNSAFE_STACK
3a23208e 67 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
66804154 68 ENABLE_INTERRUPTS(CLBR_NONE)
a232e3d5 69
4ee8ec17
DV
70 /* Zero-extending 32-bit regs, do not remove */
71 movl %ebp, %ebp
72 movl %eax, %eax
73
4c9c0e91 74 movl ASM_THREAD_INFO(TI_sysenter_return, %rsp, 0), %r10d
4c9c0e91
DV
75
76 /* Construct struct pt_regs on stack */
131484c8
IM
77 pushq $__USER32_DS /* pt_regs->ss */
78 pushq %rbp /* pt_regs->sp */
79 pushfq /* pt_regs->flags */
80 pushq $__USER32_CS /* pt_regs->cs */
54ad726c 81 pushq %r10 /* pt_regs->ip = thread_info->sysenter_return */
131484c8
IM
82 pushq %rax /* pt_regs->orig_ax */
83 pushq %rdi /* pt_regs->di */
84 pushq %rsi /* pt_regs->si */
85 pushq %rdx /* pt_regs->dx */
86 pushq %rcx /* pt_regs->cx */
87 pushq $-ENOSYS /* pt_regs->ax */
1da177e4 88 cld
54ad726c 89 sub $(10*8), %rsp /* pt_regs->r8-11, bp, bx, r12-15 not saved */
4c9c0e91 90
b87cf63e
DV
91 /*
92 * no need to do an access_ok check here because rbp has been
54ad726c 93 * 32-bit zero extended
b87cf63e 94 */
63bcff2a 95 ASM_STAC
54ad726c
IM
961: movl (%rbp), %ebp
97 _ASM_EXTABLE(1b, ia32_badarg)
63bcff2a 98 ASM_CLAC
8c7aa698
AL
99
100 /*
101 * Sysenter doesn't filter flags, so we need to clear NT
102 * ourselves. To save a few cycles, we can check whether
103 * NT was set instead of doing an unconditional popfq.
104 */
54ad726c
IM
105 testl $X86_EFLAGS_NT, EFLAGS(%rsp)
106 jnz sysenter_fix_flags
8c7aa698
AL
107sysenter_flags_fixed:
108
9b47feb7
DV
109 orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
110 testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
54ad726c 111 jnz sysenter_tracesys
131484c8 112
d4d67150 113sysenter_do_call:
54ad726c
IM
114 /* 32-bit syscall -> 64-bit C ABI argument conversion */
115 movl %edi, %r8d /* arg5 */
116 movl %ebp, %r9d /* arg6 */
117 xchg %ecx, %esi /* rsi:arg2, rcx:arg4 */
118 movl %ebx, %edi /* arg1 */
119 movl %edx, %edx /* arg3 (zero extension) */
5cbf1565 120sysenter_dispatch:
54ad726c 121 cmpq $(IA32_NR_syscalls-1), %rax
3f5159a9 122 ja 1f
54ad726c
IM
123 call *ia32_sys_call_table(, %rax, 8)
124 movq %rax, RAX(%rsp)
3f5159a9 1251:
66804154 126 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 127 TRACE_IRQS_OFF
dca5b52a 128 testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
5cbf1565
RM
129 jnz sysexit_audit
130sysexit_from_sys_call:
4214a16b
AL
131 /*
132 * NB: SYSEXIT is not obviously safe for 64-bit kernels -- an
133 * NMI between STI and SYSEXIT has poorly specified behavior,
134 * and and NMI followed by an IRQ with usergs is fatal. So
135 * we just pretend we're using SYSEXIT but we really use
136 * SYSRETL instead.
137 *
138 * This code path is still called 'sysexit' because it pairs
139 * with 'sysenter' and it uses the SYSENTER calling convention.
140 */
9b47feb7 141 andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
54ad726c 142 movl RIP(%rsp), %ecx /* User %eip */
cd88ec23 143 movq RAX(%rsp), %rax
76f5df43 144 RESTORE_RSI_RDI
54ad726c
IM
145 xorl %edx, %edx /* Do not leak kernel information */
146 xorq %r8, %r8
147 xorq %r9, %r9
148 xorq %r10, %r10
149 movl EFLAGS(%rsp), %r11d /* User eflags */
2601e64d 150 TRACE_IRQS_ON
4214a16b
AL
151
152 /*
153 * SYSRETL works even on Intel CPUs. Use it in preference to SYSEXIT,
154 * since it avoids a dicey window with interrupts enabled.
155 */
54ad726c 156 movl RSP(%rsp), %esp
4214a16b 157
b87cf63e 158 /*
4214a16b
AL
159 * USERGS_SYSRET32 does:
160 * gsbase = user's gs base
161 * eip = ecx
162 * rflags = r11
163 * cs = __USER32_CS
164 * ss = __USER_DS
165 *
166 * The prologue set RIP(%rsp) to VDSO32_SYSENTER_RETURN, which does:
167 *
168 * pop %ebp
169 * pop %edx
170 * pop %ecx
171 *
172 * Therefore, we invoke SYSRETL with EDX and R8-R10 zeroed to
173 * avoid info leaks. R11 ends up with VDSO32_SYSENTER_RETURN's
174 * address (already known to user code), and R12-R15 are
175 * callee-saved and therefore don't contain any interesting
176 * kernel data.
b87cf63e 177 */
4214a16b 178 USERGS_SYSRET32
1da177e4 179
5cbf1565
RM
180#ifdef CONFIG_AUDITSYSCALL
181 .macro auditsys_entry_common
a92fde25
DV
182 /*
183 * At this point, registers hold syscall args in the 32-bit syscall ABI:
184 * EAX is syscall number, the 6 args are in EBX,ECX,EDX,ESI,EDI,EBP.
185 *
186 * We want to pass them to __audit_syscall_entry(), which is a 64-bit
187 * C function with 5 parameters, so shuffle them to match what
188 * the function expects: RDI,RSI,RDX,RCX,R8.
189 */
190 movl %esi, %r8d /* arg5 (R8 ) <= 4th syscall arg (ESI) */
191 xchg %ecx, %edx /* arg4 (RCX) <= 3rd syscall arg (EDX) */
192 /* arg3 (RDX) <= 2nd syscall arg (ECX) */
193 movl %ebx, %esi /* arg2 (RSI) <= 1st syscall arg (EBX) */
194 movl %eax, %edi /* arg1 (RDI) <= syscall number (EAX) */
54ad726c 195 call __audit_syscall_entry
a92fde25 196
1536bb46 197 /*
a92fde25
DV
198 * We are going to jump back to the syscall dispatch code.
199 * Prepare syscall args as required by the 64-bit C ABI.
200 * Registers clobbered by __audit_syscall_entry() are
201 * loaded from pt_regs on stack:
1536bb46
DV
202 */
203 movl ORIG_RAX(%rsp), %eax /* syscall number */
204 movl %ebx, %edi /* arg1 */
205 movl RCX(%rsp), %esi /* arg2 */
206 movl RDX(%rsp), %edx /* arg3 */
207 movl RSI(%rsp), %ecx /* arg4 */
208 movl RDI(%rsp), %r8d /* arg5 */
5cbf1565
RM
209 .endm
210
81766741 211 .macro auditsys_exit exit
54ad726c
IM
212 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
213 jnz ia32_ret_from_sys_call
5cbf1565 214 TRACE_IRQS_ON
40a1ef95 215 ENABLE_INTERRUPTS(CLBR_NONE)
54ad726c
IM
216 movl %eax, %esi /* second arg, syscall return value */
217 cmpl $-MAX_ERRNO, %eax /* is it an error ? */
218 jbe 1f
219 movslq %eax, %rsi /* if error sign extend to 64 bits */
2201: setbe %al /* 1 if error, 0 if not */
221 movzbl %al, %edi /* zero-extend that into %edi */
222 call __audit_syscall_exit
54ad726c 223 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %edi
40a1ef95 224 DISABLE_INTERRUPTS(CLBR_NONE)
5cbf1565 225 TRACE_IRQS_OFF
54ad726c
IM
226 testl %edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
227 jz \exit
228 xorl %eax, %eax /* Do not leak kernel information */
ef0cd5dc
DV
229 movq %rax, R11(%rsp)
230 movq %rax, R10(%rsp)
231 movq %rax, R9(%rsp)
232 movq %rax, R8(%rsp)
54ad726c 233 jmp int_with_check
5cbf1565
RM
234 .endm
235
236sysenter_auditsys:
5cbf1565 237 auditsys_entry_common
c0c3322e 238 movl %ebp, %r9d /* reload 6th syscall arg */
54ad726c 239 jmp sysenter_dispatch
5cbf1565
RM
240
241sysexit_audit:
242 auditsys_exit sysexit_from_sys_call
243#endif
244
8c7aa698 245sysenter_fix_flags:
9b47feb7 246 pushq $(X86_EFLAGS_IF|X86_EFLAGS_FIXED)
131484c8 247 popfq
54ad726c 248 jmp sysenter_flags_fixed
8c7aa698 249
5cbf1565 250sysenter_tracesys:
5cbf1565 251#ifdef CONFIG_AUDITSYSCALL
dca5b52a 252 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
5cbf1565
RM
253 jz sysenter_auditsys
254#endif
76f5df43 255 SAVE_EXTRA_REGS
54ad726c 256 xorl %eax, %eax /* Do not leak kernel information */
ef0cd5dc
DV
257 movq %rax, R11(%rsp)
258 movq %rax, R10(%rsp)
259 movq %rax, R9(%rsp)
260 movq %rax, R8(%rsp)
54ad726c 261 movq %rsp, %rdi /* &pt_regs -> arg1 */
1da177e4 262 call syscall_trace_enter
73cbf687
DV
263
264 /* Reload arg registers from stack. (see sysenter_tracesys) */
265 movl RCX(%rsp), %ecx
266 movl RDX(%rsp), %edx
267 movl RSI(%rsp), %esi
268 movl RDI(%rsp), %edi
54ad726c 269 movl %eax, %eax /* zero extension */
73cbf687 270
76f5df43 271 RESTORE_EXTRA_REGS
1da177e4 272 jmp sysenter_do_call
4c8cd0c5 273ENDPROC(entry_SYSENTER_compat)
1da177e4
LT
274
275/*
54ad726c 276 * 32-bit SYSCALL instruction entry.
1da177e4 277 *
54ad726c 278 * 32-bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
b87cf63e
DV
279 * then loads new ss, cs, and rip from previously programmed MSRs.
280 * rflags gets masked by a value from another MSR (so CLD and CLAC
281 * are not needed). SYSCALL does not save anything on the stack
282 * and does not change rsp.
283 *
284 * Note: rflags saving+masking-with-MSR happens only in Long mode
54ad726c 285 * (in legacy 32-bit mode, IF, RF and VM bits are cleared and that's it).
b87cf63e
DV
286 * Don't get confused: rflags saving+masking depends on Long Mode Active bit
287 * (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes
288 * or target CS descriptor's L bit (SYSCALL does not read segment descriptors).
289 *
1da177e4 290 * Arguments:
b87cf63e
DV
291 * eax system call number
292 * ecx return address
293 * ebx arg1
294 * ebp arg2 (note: not saved in the stack frame, should not be touched)
295 * edx arg3
296 * esi arg4
297 * edi arg5
298 * esp user stack
299 * 0(%esp) arg6
300 *
1da177e4 301 * This is purely a fast path. For anything complicated we use the int 0x80
b87cf63e
DV
302 * path below. We set up a complete hardware stack frame to share code
303 * with the int 0x80 path.
304 */
2cd23553 305ENTRY(entry_SYSCALL_compat)
a232e3d5
DV
306 /*
307 * Interrupts are off on entry.
308 * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
309 * it is too small to ever cause noticeable irq latency.
310 */
457da70e 311 SWAPGS_UNSAFE_STACK
54ad726c
IM
312 movl %esp, %r8d
313 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
66804154 314 ENABLE_INTERRUPTS(CLBR_NONE)
a232e3d5 315
4ee8ec17 316 /* Zero-extending 32-bit regs, do not remove */
54ad726c 317 movl %eax, %eax
4ee8ec17 318
4c9c0e91 319 /* Construct struct pt_regs on stack */
131484c8
IM
320 pushq $__USER32_DS /* pt_regs->ss */
321 pushq %r8 /* pt_regs->sp */
322 pushq %r11 /* pt_regs->flags */
323 pushq $__USER32_CS /* pt_regs->cs */
324 pushq %rcx /* pt_regs->ip */
325 pushq %rax /* pt_regs->orig_ax */
326 pushq %rdi /* pt_regs->di */
327 pushq %rsi /* pt_regs->si */
328 pushq %rdx /* pt_regs->dx */
329 pushq %rbp /* pt_regs->cx */
54ad726c 330 movl %ebp, %ecx
131484c8 331 pushq $-ENOSYS /* pt_regs->ax */
54ad726c 332 sub $(10*8), %rsp /* pt_regs->r8-11, bp, bx, r12-15 not saved */
4c9c0e91 333
b87cf63e 334 /*
54ad726c
IM
335 * No need to do an access_ok check here because r8 has been
336 * 32-bit zero extended:
b87cf63e 337 */
63bcff2a 338 ASM_STAC
c0c3322e 3391: movl (%r8), %r9d
54ad726c 340 _ASM_EXTABLE(1b, ia32_badarg)
63bcff2a 341 ASM_CLAC
9b47feb7
DV
342 orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
343 testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
344 jnz cstar_tracesys
131484c8 345
295286a8 346cstar_do_call:
54ad726c
IM
347 /* 32-bit syscall -> 64-bit C ABI argument conversion */
348 movl %edi, %r8d /* arg5 */
c0c3322e 349 /* r9 already loaded */ /* arg6 */
54ad726c
IM
350 xchg %ecx, %esi /* rsi:arg2, rcx:arg4 */
351 movl %ebx, %edi /* arg1 */
352 movl %edx, %edx /* arg3 (zero extension) */
353
5cbf1565 354cstar_dispatch:
54ad726c 355 cmpq $(IA32_NR_syscalls-1), %rax
3f5159a9 356 ja 1f
54ad726c
IM
357
358 call *ia32_sys_call_table(, %rax, 8)
359 movq %rax, RAX(%rsp)
3f5159a9 3601:
66804154 361 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 362 TRACE_IRQS_OFF
54ad726c
IM
363 testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
364 jnz sysretl_audit
365
5cbf1565 366sysretl_from_sys_call:
54ad726c 367 andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
76f5df43 368 RESTORE_RSI_RDI_RDX
54ad726c
IM
369 movl RIP(%rsp), %ecx
370 movl EFLAGS(%rsp), %r11d
cd88ec23 371 movq RAX(%rsp), %rax
54ad726c
IM
372 xorq %r10, %r10
373 xorq %r9, %r9
374 xorq %r8, %r8
2601e64d 375 TRACE_IRQS_ON
54ad726c 376 movl RSP(%rsp), %esp
b87cf63e 377 /*
54ad726c 378 * 64-bit->32-bit SYSRET restores eip from ecx,
b87cf63e
DV
379 * eflags from r11 (but RF and VM bits are forced to 0),
380 * cs and ss are loaded from MSRs.
54ad726c 381 * (Note: 32-bit->32-bit SYSRET is different: since r11
b87cf63e 382 * does not exist, it merely sets eflags.IF=1).
61f01dd9
AL
383 *
384 * NB: On AMD CPUs with the X86_BUG_SYSRET_SS_ATTRS bug, the ss
385 * descriptor is not reinitialized. This means that we must
386 * avoid SYSRET with SS == NULL, which could happen if we schedule,
387 * exit the kernel, and re-enter using an interrupt vector. (All
388 * interrupt entries on x86_64 set SS to NULL.) We prevent that
389 * from happening by reloading SS in __switch_to.
b87cf63e 390 */
2be29982 391 USERGS_SYSRET32
b87cf63e 392
5cbf1565
RM
393#ifdef CONFIG_AUDITSYSCALL
394cstar_auditsys:
c0c3322e 395 movl %r9d, R9(%rsp) /* register to be clobbered by call */
5cbf1565 396 auditsys_entry_common
c0c3322e 397 movl R9(%rsp), %r9d /* reload 6th syscall arg */
54ad726c 398 jmp cstar_dispatch
5cbf1565
RM
399
400sysretl_audit:
81766741 401 auditsys_exit sysretl_from_sys_call
5cbf1565
RM
402#endif
403
404cstar_tracesys:
405#ifdef CONFIG_AUDITSYSCALL
54ad726c
IM
406 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
407 jz cstar_auditsys
5cbf1565 408#endif
c0c3322e 409 xchgl %r9d, %ebp
76f5df43 410 SAVE_EXTRA_REGS
54ad726c 411 xorl %eax, %eax /* Do not leak kernel information */
ef0cd5dc
DV
412 movq %rax, R11(%rsp)
413 movq %rax, R10(%rsp)
c0c3322e 414 movq %r9, R9(%rsp)
ef0cd5dc 415 movq %rax, R8(%rsp)
54ad726c 416 movq %rsp, %rdi /* &pt_regs -> arg1 */
53e9accf 417 call syscall_trace_enter
c0c3322e 418 movl R9(%rsp), %r9d
73cbf687
DV
419
420 /* Reload arg registers from stack. (see sysenter_tracesys) */
421 movl RCX(%rsp), %ecx
422 movl RDX(%rsp), %edx
423 movl RSI(%rsp), %esi
424 movl RDI(%rsp), %edi
54ad726c 425 movl %eax, %eax /* zero extension */
73cbf687 426
76f5df43 427 RESTORE_EXTRA_REGS
c0c3322e 428 xchgl %ebp, %r9d
53e9accf 429 jmp cstar_do_call
2cd23553 430END(entry_SYSCALL_compat)
54ad726c 431
1da177e4 432ia32_badarg:
63bcff2a 433 ASM_CLAC
eb478544 434 movq $-EFAULT, RAX(%rsp)
61b1e3e7 435ia32_ret_from_sys_call:
54ad726c 436 xorl %eax, %eax /* Do not leak kernel information */
ef0cd5dc
DV
437 movq %rax, R11(%rsp)
438 movq %rax, R10(%rsp)
439 movq %rax, R9(%rsp)
440 movq %rax, R8(%rsp)
54ad726c 441 jmp int_ret_from_sys_call
61b1e3e7 442
b87cf63e
DV
443/*
444 * Emulated IA32 system calls via int 0x80.
1da177e4 445 *
b87cf63e
DV
446 * Arguments:
447 * eax system call number
448 * ebx arg1
449 * ecx arg2
450 * edx arg3
451 * esi arg4
452 * edi arg5
453 * ebp arg6 (note: not saved in the stack frame, should not be touched)
1da177e4
LT
454 *
455 * Notes:
b87cf63e
DV
456 * Uses the same stack frame as the x86-64 version.
457 * All registers except eax must be saved (but ptrace may violate that).
1da177e4
LT
458 * Arguments are zero extended. For system calls that want sign extension and
459 * take long arguments a wrapper is needed. Most calls can just be called
460 * directly.
b87cf63e
DV
461 * Assumes it is only called from user space and entered with interrupts off.
462 */
1da177e4 463
2cd23553 464ENTRY(entry_INT80_compat)
2601e64d 465 /*
a232e3d5
DV
466 * Interrupts are off on entry.
467 * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
468 * it is too small to ever cause noticeable irq latency.
2601e64d 469 */
a232e3d5
DV
470 PARAVIRT_ADJUST_EXCEPTION_FRAME
471 SWAPGS
66804154 472 ENABLE_INTERRUPTS(CLBR_NONE)
a232e3d5 473
4ee8ec17 474 /* Zero-extending 32-bit regs, do not remove */
54ad726c 475 movl %eax, %eax
4ee8ec17 476
4c9c0e91 477 /* Construct struct pt_regs on stack (iret frame is already on stack) */
131484c8
IM
478 pushq %rax /* pt_regs->orig_ax */
479 pushq %rdi /* pt_regs->di */
480 pushq %rsi /* pt_regs->si */
481 pushq %rdx /* pt_regs->dx */
482 pushq %rcx /* pt_regs->cx */
483 pushq $-ENOSYS /* pt_regs->ax */
61b1e3e7
DV
484 pushq $0 /* pt_regs->r8 */
485 pushq $0 /* pt_regs->r9 */
486 pushq $0 /* pt_regs->r10 */
487 pushq $0 /* pt_regs->r11 */
1da177e4 488 cld
54ad726c
IM
489 sub $(6*8), %rsp /* pt_regs->bp, bx, r12-15 not saved */
490
491 orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
492 testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
493 jnz ia32_tracesys
4c9c0e91 494
c09249f8 495ia32_do_call:
54ad726c
IM
496 /* 32-bit syscall -> 64-bit C ABI argument conversion */
497 movl %edi, %r8d /* arg5 */
498 movl %ebp, %r9d /* arg6 */
499 xchg %ecx, %esi /* rsi:arg2, rcx:arg4 */
500 movl %ebx, %edi /* arg1 */
501 movl %edx, %edx /* arg3 (zero extension) */
502 cmpq $(IA32_NR_syscalls-1), %rax
3f5159a9 503 ja 1f
54ad726c 504
eb478544 505 call *ia32_sys_call_table(, %rax, 8)
54ad726c 506 movq %rax, RAX(%rsp)
3f5159a9 5071:
54ad726c 508 jmp int_ret_from_sys_call
1da177e4 509
76f5df43
DV
510ia32_tracesys:
511 SAVE_EXTRA_REGS
54ad726c
IM
512 movq %rsp, %rdi /* &pt_regs -> arg1 */
513 call syscall_trace_enter
73cbf687
DV
514 /*
515 * Reload arg registers from stack in case ptrace changed them.
516 * Don't reload %eax because syscall_trace_enter() returned
517 * the %rax value we should see. But do truncate it to 32 bits.
518 * If it's -1 to make us punt the syscall, then (u32)-1 is still
519 * an appropriately invalid value.
520 */
521 movl RCX(%rsp), %ecx
522 movl RDX(%rsp), %edx
523 movl RSI(%rsp), %esi
524 movl RDI(%rsp), %edi
54ad726c 525 movl %eax, %eax /* zero extension */
76f5df43 526 RESTORE_EXTRA_REGS
54ad726c 527 jmp ia32_do_call
2cd23553 528END(entry_INT80_compat)
1da177e4 529
d2475b8f 530 .macro PTREGSCALL label, func
f6b2bc84
JB
531 ALIGN
532GLOBAL(\label)
54ad726c
IM
533 leaq \func(%rip), %rax
534 jmp ia32_ptregs_common
1da177e4
LT
535 .endm
536
54ad726c
IM
537 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn
538 PTREGSCALL stub32_sigreturn, sys32_sigreturn
539 PTREGSCALL stub32_fork, sys_fork
540 PTREGSCALL stub32_vfork, sys_vfork
1da177e4 541
1d4b4b29
AV
542 ALIGN
543GLOBAL(stub32_clone)
54ad726c 544 leaq sys_clone(%rip), %rax
5cdc683b 545 /*
7a5a9824
DV
546 * The 32-bit clone ABI is: clone(..., int tls_val, int *child_tidptr).
547 * The 64-bit clone ABI is: clone(..., int *child_tidptr, int tls_val).
548 *
549 * The native 64-bit kernel's sys_clone() implements the latter,
550 * so we need to swap arguments here before calling it:
5cdc683b 551 */
7a5a9824 552 xchg %r8, %rcx
54ad726c 553 jmp ia32_ptregs_common
1d4b4b29 554
f6b2bc84
JB
555 ALIGN
556ia32_ptregs_common:
76f5df43 557 SAVE_EXTRA_REGS 8
54ad726c 558 call *%rax
76f5df43
DV
559 RESTORE_EXTRA_REGS 8
560 ret
4b787e0b 561END(ia32_ptregs_common)