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