x86/entry/32: Fix entry_INT80_32() to expect interrupts to be on
[linux-2.6-block.git] / arch / x86 / entry / entry_32.S
CommitLineData
1da177e4 1/*
a49976d1 2 * Copyright (C) 1991,1992 Linus Torvalds
1da177e4 3 *
a49976d1 4 * entry_32.S contains the system-call and low-level fault and trap handling routines.
1da177e4 5 *
39e8701f 6 * Stack layout while running C code:
a49976d1
IM
7 * ptrace needs to have all registers on the stack.
8 * If the order here is changed, it needs to be
9 * updated in fork.c:copy_process(), signal.c:do_signal(),
1da177e4
LT
10 * ptrace.c and ptrace.h
11 *
12 * 0(%esp) - %ebx
13 * 4(%esp) - %ecx
14 * 8(%esp) - %edx
9b47feb7 15 * C(%esp) - %esi
1da177e4
LT
16 * 10(%esp) - %edi
17 * 14(%esp) - %ebp
18 * 18(%esp) - %eax
19 * 1C(%esp) - %ds
20 * 20(%esp) - %es
464d1a78 21 * 24(%esp) - %fs
ccbeed3a
TH
22 * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
23 * 2C(%esp) - orig_eax
24 * 30(%esp) - %eip
25 * 34(%esp) - %cs
26 * 38(%esp) - %eflags
27 * 3C(%esp) - %oldesp
28 * 40(%esp) - %oldss
1da177e4
LT
29 */
30
1da177e4 31#include <linux/linkage.h>
d7e7528b 32#include <linux/err.h>
1da177e4 33#include <asm/thread_info.h>
55f327fa 34#include <asm/irqflags.h>
1da177e4
LT
35#include <asm/errno.h>
36#include <asm/segment.h>
37#include <asm/smp.h>
0341c14d 38#include <asm/page_types.h>
be44d2aa 39#include <asm/percpu.h>
ab68ed98 40#include <asm/processor-flags.h>
395a59d0 41#include <asm/ftrace.h>
9b7dc567 42#include <asm/irq_vectors.h>
40d2e763 43#include <asm/cpufeature.h>
b4ca46e4 44#include <asm/alternative-asm.h>
6837a54d 45#include <asm/asm.h>
e59d1b0a 46#include <asm/smap.h>
1da177e4 47
ea714547
JO
48 .section .entry.text, "ax"
49
139ec7c4
RR
50/*
51 * We use macros for low-level operations which need to be overridden
52 * for paravirtualization. The following will never clobber any registers:
53 * INTERRUPT_RETURN (aka. "iret")
54 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
d75cd22f 55 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
139ec7c4
RR
56 *
57 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
58 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
59 * Allowing a register to be clobbered can shrink the paravirt replacement
60 * enough to patch inline, increasing performance.
61 */
62
1da177e4 63#ifdef CONFIG_PREEMPT
a49976d1 64# define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
1da177e4 65#else
a49976d1
IM
66# define preempt_stop(clobbers)
67# define resume_kernel restore_all
1da177e4
LT
68#endif
69
55f327fa
IM
70.macro TRACE_IRQS_IRET
71#ifdef CONFIG_TRACE_IRQFLAGS
a49976d1
IM
72 testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off?
73 jz 1f
55f327fa
IM
74 TRACE_IRQS_ON
751:
76#endif
77.endm
78
ccbeed3a
TH
79/*
80 * User gs save/restore
81 *
82 * %gs is used for userland TLS and kernel only uses it for stack
83 * canary which is required to be at %gs:20 by gcc. Read the comment
84 * at the top of stackprotector.h for more info.
85 *
86 * Local labels 98 and 99 are used.
87 */
88#ifdef CONFIG_X86_32_LAZY_GS
89
90 /* unfortunately push/pop can't be no-op */
91.macro PUSH_GS
a49976d1 92 pushl $0
ccbeed3a
TH
93.endm
94.macro POP_GS pop=0
a49976d1 95 addl $(4 + \pop), %esp
ccbeed3a
TH
96.endm
97.macro POP_GS_EX
98.endm
99
100 /* all the rest are no-op */
101.macro PTGS_TO_GS
102.endm
103.macro PTGS_TO_GS_EX
104.endm
105.macro GS_TO_REG reg
106.endm
107.macro REG_TO_PTGS reg
108.endm
109.macro SET_KERNEL_GS reg
110.endm
111
112#else /* CONFIG_X86_32_LAZY_GS */
113
114.macro PUSH_GS
a49976d1 115 pushl %gs
ccbeed3a
TH
116.endm
117
118.macro POP_GS pop=0
a49976d1 11998: popl %gs
ccbeed3a 120 .if \pop <> 0
9b47feb7 121 add $\pop, %esp
ccbeed3a
TH
122 .endif
123.endm
124.macro POP_GS_EX
125.pushsection .fixup, "ax"
a49976d1
IM
12699: movl $0, (%esp)
127 jmp 98b
ccbeed3a 128.popsection
a49976d1 129 _ASM_EXTABLE(98b, 99b)
ccbeed3a
TH
130.endm
131
132.macro PTGS_TO_GS
a49976d1 13398: mov PT_GS(%esp), %gs
ccbeed3a
TH
134.endm
135.macro PTGS_TO_GS_EX
136.pushsection .fixup, "ax"
a49976d1
IM
13799: movl $0, PT_GS(%esp)
138 jmp 98b
ccbeed3a 139.popsection
a49976d1 140 _ASM_EXTABLE(98b, 99b)
ccbeed3a
TH
141.endm
142
143.macro GS_TO_REG reg
a49976d1 144 movl %gs, \reg
ccbeed3a
TH
145.endm
146.macro REG_TO_PTGS reg
a49976d1 147 movl \reg, PT_GS(%esp)
ccbeed3a
TH
148.endm
149.macro SET_KERNEL_GS reg
a49976d1
IM
150 movl $(__KERNEL_STACK_CANARY), \reg
151 movl \reg, %gs
ccbeed3a
TH
152.endm
153
a49976d1 154#endif /* CONFIG_X86_32_LAZY_GS */
ccbeed3a 155
150ac78d 156.macro SAVE_ALL pt_regs_ax=%eax
f0d96110 157 cld
ccbeed3a 158 PUSH_GS
a49976d1
IM
159 pushl %fs
160 pushl %es
161 pushl %ds
150ac78d 162 pushl \pt_regs_ax
a49976d1
IM
163 pushl %ebp
164 pushl %edi
165 pushl %esi
166 pushl %edx
167 pushl %ecx
168 pushl %ebx
169 movl $(__USER_DS), %edx
170 movl %edx, %ds
171 movl %edx, %es
172 movl $(__KERNEL_PERCPU), %edx
173 movl %edx, %fs
ccbeed3a 174 SET_KERNEL_GS %edx
f0d96110 175.endm
1da177e4 176
f0d96110 177.macro RESTORE_INT_REGS
a49976d1
IM
178 popl %ebx
179 popl %ecx
180 popl %edx
181 popl %esi
182 popl %edi
183 popl %ebp
184 popl %eax
f0d96110 185.endm
1da177e4 186
ccbeed3a 187.macro RESTORE_REGS pop=0
f0d96110 188 RESTORE_INT_REGS
a49976d1
IM
1891: popl %ds
1902: popl %es
1913: popl %fs
ccbeed3a 192 POP_GS \pop
f0d96110 193.pushsection .fixup, "ax"
a49976d1
IM
1944: movl $0, (%esp)
195 jmp 1b
1965: movl $0, (%esp)
197 jmp 2b
1986: movl $0, (%esp)
199 jmp 3b
f95d47ca 200.popsection
a49976d1
IM
201 _ASM_EXTABLE(1b, 4b)
202 _ASM_EXTABLE(2b, 5b)
203 _ASM_EXTABLE(3b, 6b)
ccbeed3a 204 POP_GS_EX
f0d96110 205.endm
1da177e4 206
1da177e4 207ENTRY(ret_from_fork)
a49976d1
IM
208 pushl %eax
209 call schedule_tail
1da177e4 210 GET_THREAD_INFO(%ebp)
a49976d1
IM
211 popl %eax
212 pushl $0x0202 # Reset kernel eflags
131484c8 213 popfl
39e8701f
AL
214
215 /* When we fork, we trace the syscall return in the child, too. */
216 movl %esp, %eax
217 call syscall_return_slowpath
218 jmp restore_all
47a55cd7 219END(ret_from_fork)
1da177e4 220
22e2430d 221ENTRY(ret_from_kernel_thread)
a49976d1
IM
222 pushl %eax
223 call schedule_tail
6783eaa2 224 GET_THREAD_INFO(%ebp)
a49976d1
IM
225 popl %eax
226 pushl $0x0202 # Reset kernel eflags
131484c8 227 popfl
a49976d1
IM
228 movl PT_EBP(%esp), %eax
229 call *PT_EBX(%esp)
230 movl $0, PT_EAX(%esp)
39e8701f
AL
231
232 /*
233 * Kernel threads return to userspace as if returning from a syscall.
234 * We should check whether anything actually uses this path and, if so,
235 * consider switching it over to ret_from_fork.
236 */
237 movl %esp, %eax
238 call syscall_return_slowpath
239 jmp restore_all
22e2430d 240ENDPROC(ret_from_kernel_thread)
6783eaa2 241
1da177e4
LT
242/*
243 * Return to user mode is not as complex as all this looks,
244 * but we want the default path for a system call return to
245 * go as quickly as possible which is why some of this is
246 * less clear than it otherwise should be.
247 */
248
249 # userspace resumption stub bypassing syscall exit tracing
250 ALIGN
251ret_from_exception:
139ec7c4 252 preempt_stop(CLBR_ANY)
1da177e4
LT
253ret_from_intr:
254 GET_THREAD_INFO(%ebp)
29a2e283 255#ifdef CONFIG_VM86
a49976d1
IM
256 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
257 movb PT_CS(%esp), %al
258 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
29a2e283
DA
259#else
260 /*
6783eaa2 261 * We can be coming here from child spawned by kernel_thread().
29a2e283 262 */
a49976d1
IM
263 movl PT_CS(%esp), %eax
264 andl $SEGMENT_RPL_MASK, %eax
29a2e283 265#endif
a49976d1
IM
266 cmpl $USER_RPL, %eax
267 jb resume_kernel # not returning to v8086 or userspace
f95d47ca 268
1da177e4 269ENTRY(resume_userspace)
5d73fc70 270 DISABLE_INTERRUPTS(CLBR_ANY)
e32e58a9 271 TRACE_IRQS_OFF
5d73fc70
AL
272 movl %esp, %eax
273 call prepare_exit_to_usermode
a49976d1 274 jmp restore_all
47a55cd7 275END(ret_from_exception)
1da177e4
LT
276
277#ifdef CONFIG_PREEMPT
278ENTRY(resume_kernel)
139ec7c4 279 DISABLE_INTERRUPTS(CLBR_ANY)
1da177e4 280need_resched:
a49976d1
IM
281 cmpl $0, PER_CPU_VAR(__preempt_count)
282 jnz restore_all
283 testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off (exception path) ?
284 jz restore_all
285 call preempt_schedule_irq
286 jmp need_resched
47a55cd7 287END(resume_kernel)
1da177e4
LT
288#endif
289
a49976d1 290 # SYSENTER call handler stub
4c8cd0c5 291ENTRY(entry_SYSENTER_32)
a49976d1 292 movl TSS_sysenter_sp0(%esp), %esp
1da177e4 293sysenter_past_esp:
5f310f73
AL
294 pushl $__USER_DS /* pt_regs->ss */
295 pushl %ecx /* pt_regs->cx */
296 pushfl /* pt_regs->flags (except IF = 0) */
297 orl $X86_EFLAGS_IF, (%esp) /* Fix IF */
298 pushl $__USER_CS /* pt_regs->cs */
299 pushl $0 /* pt_regs->ip = 0 (placeholder) */
300 pushl %eax /* pt_regs->orig_ax */
301 SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest */
302
55f327fa 303 /*
5f310f73
AL
304 * User mode is traced as though IRQs are on, and SYSENTER
305 * turned them off.
e6e5494c 306 */
55f327fa 307 TRACE_IRQS_OFF
5f310f73
AL
308
309 movl %esp, %eax
310 call do_fast_syscall_32
311 testl %eax, %eax
312 jz .Lsyscall_32_done
313
314/* Opportunistic SYSEXIT */
315 TRACE_IRQS_ON /* User mode traces as IRQs on. */
316 movl PT_EIP(%esp), %edx /* pt_regs->ip */
317 movl PT_OLDESP(%esp), %ecx /* pt_regs->sp */
318 popl %ebx /* pt_regs->bx */
319 addl $2*4, %esp /* skip pt_regs->cx and pt_regs->dx */
320 popl %esi /* pt_regs->si */
321 popl %edi /* pt_regs->di */
322 popl %ebp /* pt_regs->bp */
323 popl %eax /* pt_regs->ax */
a49976d1 3241: mov PT_FS(%esp), %fs
ccbeed3a 325 PTGS_TO_GS
5f310f73
AL
326
327 /*
328 * Return back to the vDSO, which will pop ecx and edx.
329 * Don't bother with DS and ES (they already contain __USER_DS).
330 */
d75cd22f 331 ENABLE_INTERRUPTS_SYSEXIT
af0575bb 332
a49976d1
IM
333.pushsection .fixup, "ax"
3342: movl $0, PT_FS(%esp)
335 jmp 1b
f95d47ca 336.popsection
a49976d1 337 _ASM_EXTABLE(1b, 2b)
ccbeed3a 338 PTGS_TO_GS_EX
4c8cd0c5 339ENDPROC(entry_SYSENTER_32)
1da177e4
LT
340
341 # system call handler stub
b2502b41 342ENTRY(entry_INT80_32)
e59d1b0a 343 ASM_CLAC
150ac78d 344 pushl %eax /* pt_regs->orig_ax */
5f310f73 345 SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest */
150ac78d
AL
346
347 /*
657c1eea
AL
348 * User mode is traced as though IRQs are on. Unlike the 64-bit
349 * case, INT80 is a trap gate on 32-bit kernels, so interrupts
350 * are already on (unless user code is messing around with iopl).
150ac78d 351 */
150ac78d
AL
352
353 movl %esp, %eax
657c1eea 354 call do_syscall_32_irqs_on
5f310f73 355.Lsyscall_32_done:
1da177e4
LT
356
357restore_all:
2e04bc76
AH
358 TRACE_IRQS_IRET
359restore_all_notrace:
34273f41 360#ifdef CONFIG_X86_ESPFIX32
a49976d1
IM
361 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
362 /*
363 * Warning: PT_OLDSS(%esp) contains the wrong/random values if we
364 * are returning to the kernel.
365 * See comments in process.c:copy_thread() for details.
366 */
367 movb PT_OLDSS(%esp), %ah
368 movb PT_CS(%esp), %al
369 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
370 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
371 je ldt_ss # returning to user-space with LDT SS
34273f41 372#endif
1da177e4 373restore_nocheck:
a49976d1 374 RESTORE_REGS 4 # skip orig_eax/error_code
f7f3d791 375irq_return:
3701d863 376 INTERRUPT_RETURN
a49976d1
IM
377.section .fixup, "ax"
378ENTRY(iret_exc )
379 pushl $0 # no error code
380 pushl $do_iret_error
381 jmp error_code
1da177e4 382.previous
a49976d1 383 _ASM_EXTABLE(irq_return, iret_exc)
1da177e4 384
34273f41 385#ifdef CONFIG_X86_ESPFIX32
1da177e4 386ldt_ss:
d3561b7f
RR
387#ifdef CONFIG_PARAVIRT
388 /*
389 * The kernel can't run on a non-flat stack if paravirt mode
390 * is active. Rather than try to fixup the high bits of
391 * ESP, bypass this code entirely. This may break DOSemu
392 * and/or Wine support in a paravirt VM, although the option
393 * is still available to implement the setting of the high
394 * 16-bits in the INTERRUPT_RETURN paravirt-op.
395 */
a49976d1
IM
396 cmpl $0, pv_info+PARAVIRT_enabled
397 jne restore_nocheck
d3561b7f
RR
398#endif
399
dc4c2a0a
AH
400/*
401 * Setup and switch to ESPFIX stack
402 *
403 * We're returning to userspace with a 16 bit stack. The CPU will not
404 * restore the high word of ESP for us on executing iret... This is an
405 * "official" bug of all the x86-compatible CPUs, which we can work
406 * around to make dosemu and wine happy. We do this by preloading the
407 * high word of ESP with the high word of the userspace ESP while
408 * compensating for the offset by changing to the ESPFIX segment with
409 * a base address that matches for the difference.
410 */
72c511dd 411#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
a49976d1
IM
412 mov %esp, %edx /* load kernel esp */
413 mov PT_OLDESP(%esp), %eax /* load userspace esp */
414 mov %dx, %ax /* eax: new kernel esp */
9b47feb7
DV
415 sub %eax, %edx /* offset (low word is 0) */
416 shr $16, %edx
a49976d1
IM
417 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
418 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
419 pushl $__ESPFIX_SS
420 pushl %eax /* new kernel esp */
421 /*
422 * Disable interrupts, but do not irqtrace this section: we
2e04bc76 423 * will soon execute iret and the tracer was already set to
a49976d1
IM
424 * the irqstate after the IRET:
425 */
139ec7c4 426 DISABLE_INTERRUPTS(CLBR_EAX)
a49976d1
IM
427 lss (%esp), %esp /* switch to espfix segment */
428 jmp restore_nocheck
34273f41 429#endif
b2502b41 430ENDPROC(entry_INT80_32)
1da177e4 431
f0d96110 432.macro FIXUP_ESPFIX_STACK
dc4c2a0a
AH
433/*
434 * Switch back for ESPFIX stack to the normal zerobased stack
435 *
436 * We can't call C functions using the ESPFIX stack. This code reads
437 * the high word of the segment base from the GDT and swiches to the
438 * normal stack and adjusts ESP with the matching offset.
439 */
34273f41 440#ifdef CONFIG_X86_ESPFIX32
dc4c2a0a 441 /* fixup the stack */
a49976d1
IM
442 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
443 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
9b47feb7 444 shl $16, %eax
a49976d1
IM
445 addl %esp, %eax /* the adjusted stack pointer */
446 pushl $__KERNEL_DS
447 pushl %eax
448 lss (%esp), %esp /* switch to the normal stack segment */
34273f41 449#endif
f0d96110
TH
450.endm
451.macro UNWIND_ESPFIX_STACK
34273f41 452#ifdef CONFIG_X86_ESPFIX32
a49976d1 453 movl %ss, %eax
f0d96110 454 /* see if on espfix stack */
a49976d1
IM
455 cmpw $__ESPFIX_SS, %ax
456 jne 27f
457 movl $__KERNEL_DS, %eax
458 movl %eax, %ds
459 movl %eax, %es
f0d96110
TH
460 /* switch to normal stack */
461 FIXUP_ESPFIX_STACK
46227:
34273f41 463#endif
f0d96110 464.endm
1da177e4
LT
465
466/*
3304c9c3
DV
467 * Build the entry stubs with some assembler magic.
468 * We pack 1 stub into every 8-byte block.
1da177e4 469 */
3304c9c3 470 .align 8
1da177e4 471ENTRY(irq_entries_start)
3304c9c3
DV
472 vector=FIRST_EXTERNAL_VECTOR
473 .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
a49976d1 474 pushl $(~vector+0x80) /* Note: always in signed byte range */
3304c9c3
DV
475 vector=vector+1
476 jmp common_interrupt
3304c9c3
DV
477 .align 8
478 .endr
47a55cd7
JB
479END(irq_entries_start)
480
55f327fa
IM
481/*
482 * the CPU automatically disables interrupts when executing an IRQ vector,
483 * so IRQ-flags tracing has to follow that:
484 */
b7c6244f 485 .p2align CONFIG_X86_L1_CACHE_SHIFT
1da177e4 486common_interrupt:
e59d1b0a 487 ASM_CLAC
a49976d1 488 addl $-0x80, (%esp) /* Adjust vector into the [-256, -1] range */
1da177e4 489 SAVE_ALL
55f327fa 490 TRACE_IRQS_OFF
a49976d1
IM
491 movl %esp, %eax
492 call do_IRQ
493 jmp ret_from_intr
47a55cd7 494ENDPROC(common_interrupt)
1da177e4 495
02cf94c3 496#define BUILD_INTERRUPT3(name, nr, fn) \
1da177e4 497ENTRY(name) \
e59d1b0a 498 ASM_CLAC; \
a49976d1 499 pushl $~(nr); \
fe7cacc1 500 SAVE_ALL; \
55f327fa 501 TRACE_IRQS_OFF \
a49976d1
IM
502 movl %esp, %eax; \
503 call fn; \
504 jmp ret_from_intr; \
47a55cd7 505ENDPROC(name)
1da177e4 506
cf910e83
SA
507
508#ifdef CONFIG_TRACING
a49976d1 509# define TRACE_BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(trace_##name, nr, smp_trace_##name)
cf910e83 510#else
a49976d1 511# define TRACE_BUILD_INTERRUPT(name, nr)
cf910e83
SA
512#endif
513
a49976d1
IM
514#define BUILD_INTERRUPT(name, nr) \
515 BUILD_INTERRUPT3(name, nr, smp_##name); \
cf910e83 516 TRACE_BUILD_INTERRUPT(name, nr)
02cf94c3 517
1da177e4 518/* The include is where all of the SMP etc. interrupts come from */
1164dd00 519#include <asm/entry_arch.h>
1da177e4 520
1da177e4 521ENTRY(coprocessor_error)
e59d1b0a 522 ASM_CLAC
a49976d1
IM
523 pushl $0
524 pushl $do_coprocessor_error
525 jmp error_code
47a55cd7 526END(coprocessor_error)
1da177e4
LT
527
528ENTRY(simd_coprocessor_error)
e59d1b0a 529 ASM_CLAC
a49976d1 530 pushl $0
40d2e763
BG
531#ifdef CONFIG_X86_INVD_BUG
532 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
a49976d1
IM
533 ALTERNATIVE "pushl $do_general_protection", \
534 "pushl $do_simd_coprocessor_error", \
8e65f6e0 535 X86_FEATURE_XMM
40d2e763 536#else
a49976d1 537 pushl $do_simd_coprocessor_error
40d2e763 538#endif
a49976d1 539 jmp error_code
47a55cd7 540END(simd_coprocessor_error)
1da177e4
LT
541
542ENTRY(device_not_available)
e59d1b0a 543 ASM_CLAC
a49976d1
IM
544 pushl $-1 # mark this as an int
545 pushl $do_device_not_available
546 jmp error_code
47a55cd7 547END(device_not_available)
1da177e4 548
d3561b7f
RR
549#ifdef CONFIG_PARAVIRT
550ENTRY(native_iret)
3701d863 551 iret
6837a54d 552 _ASM_EXTABLE(native_iret, iret_exc)
47a55cd7 553END(native_iret)
d3561b7f 554
d75cd22f 555ENTRY(native_irq_enable_sysexit)
d3561b7f
RR
556 sti
557 sysexit
d75cd22f 558END(native_irq_enable_sysexit)
d3561b7f
RR
559#endif
560
1da177e4 561ENTRY(overflow)
e59d1b0a 562 ASM_CLAC
a49976d1
IM
563 pushl $0
564 pushl $do_overflow
565 jmp error_code
47a55cd7 566END(overflow)
1da177e4
LT
567
568ENTRY(bounds)
e59d1b0a 569 ASM_CLAC
a49976d1
IM
570 pushl $0
571 pushl $do_bounds
572 jmp error_code
47a55cd7 573END(bounds)
1da177e4
LT
574
575ENTRY(invalid_op)
e59d1b0a 576 ASM_CLAC
a49976d1
IM
577 pushl $0
578 pushl $do_invalid_op
579 jmp error_code
47a55cd7 580END(invalid_op)
1da177e4
LT
581
582ENTRY(coprocessor_segment_overrun)
e59d1b0a 583 ASM_CLAC
a49976d1
IM
584 pushl $0
585 pushl $do_coprocessor_segment_overrun
586 jmp error_code
47a55cd7 587END(coprocessor_segment_overrun)
1da177e4
LT
588
589ENTRY(invalid_TSS)
e59d1b0a 590 ASM_CLAC
a49976d1
IM
591 pushl $do_invalid_TSS
592 jmp error_code
47a55cd7 593END(invalid_TSS)
1da177e4
LT
594
595ENTRY(segment_not_present)
e59d1b0a 596 ASM_CLAC
a49976d1
IM
597 pushl $do_segment_not_present
598 jmp error_code
47a55cd7 599END(segment_not_present)
1da177e4
LT
600
601ENTRY(stack_segment)
e59d1b0a 602 ASM_CLAC
a49976d1
IM
603 pushl $do_stack_segment
604 jmp error_code
47a55cd7 605END(stack_segment)
1da177e4 606
1da177e4 607ENTRY(alignment_check)
e59d1b0a 608 ASM_CLAC
a49976d1
IM
609 pushl $do_alignment_check
610 jmp error_code
47a55cd7 611END(alignment_check)
1da177e4 612
d28c4393 613ENTRY(divide_error)
e59d1b0a 614 ASM_CLAC
a49976d1
IM
615 pushl $0 # no error code
616 pushl $do_divide_error
617 jmp error_code
47a55cd7 618END(divide_error)
1da177e4
LT
619
620#ifdef CONFIG_X86_MCE
621ENTRY(machine_check)
e59d1b0a 622 ASM_CLAC
a49976d1
IM
623 pushl $0
624 pushl machine_check_vector
625 jmp error_code
47a55cd7 626END(machine_check)
1da177e4
LT
627#endif
628
629ENTRY(spurious_interrupt_bug)
e59d1b0a 630 ASM_CLAC
a49976d1
IM
631 pushl $0
632 pushl $do_spurious_interrupt_bug
633 jmp error_code
47a55cd7 634END(spurious_interrupt_bug)
1da177e4 635
5ead97c8 636#ifdef CONFIG_XEN
a49976d1
IM
637/*
638 * Xen doesn't set %esp to be precisely what the normal SYSENTER
639 * entry point expects, so fix it up before using the normal path.
640 */
e2a81baf 641ENTRY(xen_sysenter_target)
a49976d1
IM
642 addl $5*4, %esp /* remove xen-provided frame */
643 jmp sysenter_past_esp
e2a81baf 644
5ead97c8 645ENTRY(xen_hypervisor_callback)
a49976d1 646 pushl $-1 /* orig_ax = -1 => not a system call */
5ead97c8
JF
647 SAVE_ALL
648 TRACE_IRQS_OFF
9ec2b804 649
a49976d1
IM
650 /*
651 * Check to see if we got the event in the critical
652 * region in xen_iret_direct, after we've reenabled
653 * events and checked for pending events. This simulates
654 * iret instruction's behaviour where it delivers a
655 * pending interrupt when enabling interrupts:
656 */
657 movl PT_EIP(%esp), %eax
658 cmpl $xen_iret_start_crit, %eax
659 jb 1f
660 cmpl $xen_iret_end_crit, %eax
661 jae 1f
9ec2b804 662
a49976d1 663 jmp xen_iret_crit_fixup
e2a81baf 664
e2a81baf 665ENTRY(xen_do_upcall)
a49976d1
IM
6661: mov %esp, %eax
667 call xen_evtchn_do_upcall
fdfd811d 668#ifndef CONFIG_PREEMPT
a49976d1 669 call xen_maybe_preempt_hcall
fdfd811d 670#endif
a49976d1 671 jmp ret_from_intr
5ead97c8
JF
672ENDPROC(xen_hypervisor_callback)
673
a49976d1
IM
674/*
675 * Hypervisor uses this for application faults while it executes.
676 * We get here for two reasons:
677 * 1. Fault while reloading DS, ES, FS or GS
678 * 2. Fault while executing IRET
679 * Category 1 we fix up by reattempting the load, and zeroing the segment
680 * register if the load fails.
681 * Category 2 we fix up by jumping to do_iret_error. We cannot use the
682 * normal Linux return path in this case because if we use the IRET hypercall
683 * to pop the stack frame we end up in an infinite loop of failsafe callbacks.
684 * We distinguish between categories by maintaining a status value in EAX.
685 */
5ead97c8 686ENTRY(xen_failsafe_callback)
a49976d1
IM
687 pushl %eax
688 movl $1, %eax
6891: mov 4(%esp), %ds
6902: mov 8(%esp), %es
6913: mov 12(%esp), %fs
6924: mov 16(%esp), %gs
a349e23d
DV
693 /* EAX == 0 => Category 1 (Bad segment)
694 EAX != 0 => Category 2 (Bad IRET) */
a49976d1
IM
695 testl %eax, %eax
696 popl %eax
697 lea 16(%esp), %esp
698 jz 5f
699 jmp iret_exc
7005: pushl $-1 /* orig_ax = -1 => not a system call */
5ead97c8 701 SAVE_ALL
a49976d1
IM
702 jmp ret_from_exception
703
704.section .fixup, "ax"
7056: xorl %eax, %eax
706 movl %eax, 4(%esp)
707 jmp 1b
7087: xorl %eax, %eax
709 movl %eax, 8(%esp)
710 jmp 2b
7118: xorl %eax, %eax
712 movl %eax, 12(%esp)
713 jmp 3b
7149: xorl %eax, %eax
715 movl %eax, 16(%esp)
716 jmp 4b
5ead97c8 717.previous
a49976d1
IM
718 _ASM_EXTABLE(1b, 6b)
719 _ASM_EXTABLE(2b, 7b)
720 _ASM_EXTABLE(3b, 8b)
721 _ASM_EXTABLE(4b, 9b)
5ead97c8
JF
722ENDPROC(xen_failsafe_callback)
723
bc2b0331 724BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
38e20b07
SY
725 xen_evtchn_do_upcall)
726
a49976d1 727#endif /* CONFIG_XEN */
bc2b0331
S
728
729#if IS_ENABLED(CONFIG_HYPERV)
730
731BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
732 hyperv_vector_handler)
733
734#endif /* CONFIG_HYPERV */
5ead97c8 735
606576ce 736#ifdef CONFIG_FUNCTION_TRACER
d61f82d0
SR
737#ifdef CONFIG_DYNAMIC_FTRACE
738
739ENTRY(mcount)
d61f82d0
SR
740 ret
741END(mcount)
742
743ENTRY(ftrace_caller)
a49976d1
IM
744 pushl %eax
745 pushl %ecx
746 pushl %edx
747 pushl $0 /* Pass NULL as regs pointer */
748 movl 4*4(%esp), %eax
749 movl 0x4(%ebp), %edx
750 movl function_trace_op, %ecx
751 subl $MCOUNT_INSN_SIZE, %eax
d61f82d0
SR
752
753.globl ftrace_call
754ftrace_call:
a49976d1 755 call ftrace_stub
d61f82d0 756
a49976d1
IM
757 addl $4, %esp /* skip NULL pointer */
758 popl %edx
759 popl %ecx
760 popl %eax
4de72395 761ftrace_ret:
5a45cfe1
SR
762#ifdef CONFIG_FUNCTION_GRAPH_TRACER
763.globl ftrace_graph_call
764ftrace_graph_call:
a49976d1 765 jmp ftrace_stub
5a45cfe1 766#endif
d61f82d0
SR
767
768.globl ftrace_stub
769ftrace_stub:
770 ret
771END(ftrace_caller)
772
4de72395
SR
773ENTRY(ftrace_regs_caller)
774 pushf /* push flags before compare (in cs location) */
4de72395
SR
775
776 /*
777 * i386 does not save SS and ESP when coming from kernel.
778 * Instead, to get sp, &regs->sp is used (see ptrace.h).
779 * Unfortunately, that means eflags must be at the same location
780 * as the current return ip is. We move the return ip into the
781 * ip location, and move flags into the return ip location.
782 */
a49976d1
IM
783 pushl 4(%esp) /* save return ip into ip slot */
784
785 pushl $0 /* Load 0 into orig_ax */
786 pushl %gs
787 pushl %fs
788 pushl %es
789 pushl %ds
790 pushl %eax
791 pushl %ebp
792 pushl %edi
793 pushl %esi
794 pushl %edx
795 pushl %ecx
796 pushl %ebx
797
798 movl 13*4(%esp), %eax /* Get the saved flags */
799 movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
800 /* clobbering return ip */
801 movl $__KERNEL_CS, 13*4(%esp)
802
803 movl 12*4(%esp), %eax /* Load ip (1st parameter) */
804 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
805 movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
806 movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
807 pushl %esp /* Save pt_regs as 4th parameter */
4de72395
SR
808
809GLOBAL(ftrace_regs_call)
a49976d1
IM
810 call ftrace_stub
811
812 addl $4, %esp /* Skip pt_regs */
813 movl 14*4(%esp), %eax /* Move flags back into cs */
814 movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
815 movl 12*4(%esp), %eax /* Get return ip from regs->ip */
816 movl %eax, 14*4(%esp) /* Put return ip back for ret */
817
818 popl %ebx
819 popl %ecx
820 popl %edx
821 popl %esi
822 popl %edi
823 popl %ebp
824 popl %eax
825 popl %ds
826 popl %es
827 popl %fs
828 popl %gs
829 addl $8, %esp /* Skip orig_ax and ip */
830 popf /* Pop flags at end (no addl to corrupt flags) */
831 jmp ftrace_ret
4de72395 832
4de72395 833 popf
a49976d1 834 jmp ftrace_stub
d61f82d0
SR
835#else /* ! CONFIG_DYNAMIC_FTRACE */
836
16444a8a 837ENTRY(mcount)
a49976d1
IM
838 cmpl $__PAGE_OFFSET, %esp
839 jb ftrace_stub /* Paging not enabled yet? */
af058ab0 840
a49976d1
IM
841 cmpl $ftrace_stub, ftrace_trace_function
842 jnz trace
fb52607a 843#ifdef CONFIG_FUNCTION_GRAPH_TRACER
a49976d1
IM
844 cmpl $ftrace_stub, ftrace_graph_return
845 jnz ftrace_graph_caller
e49dc19c 846
a49976d1
IM
847 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
848 jnz ftrace_graph_caller
caf4b323 849#endif
16444a8a
ACM
850.globl ftrace_stub
851ftrace_stub:
852 ret
853
854 /* taken from glibc */
855trace:
a49976d1
IM
856 pushl %eax
857 pushl %ecx
858 pushl %edx
859 movl 0xc(%esp), %eax
860 movl 0x4(%ebp), %edx
861 subl $MCOUNT_INSN_SIZE, %eax
862
863 call *ftrace_trace_function
864
865 popl %edx
866 popl %ecx
867 popl %eax
868 jmp ftrace_stub
16444a8a 869END(mcount)
d61f82d0 870#endif /* CONFIG_DYNAMIC_FTRACE */
606576ce 871#endif /* CONFIG_FUNCTION_TRACER */
16444a8a 872
fb52607a
FW
873#ifdef CONFIG_FUNCTION_GRAPH_TRACER
874ENTRY(ftrace_graph_caller)
a49976d1
IM
875 pushl %eax
876 pushl %ecx
877 pushl %edx
878 movl 0xc(%esp), %eax
879 lea 0x4(%ebp), %edx
880 movl (%ebp), %ecx
881 subl $MCOUNT_INSN_SIZE, %eax
882 call prepare_ftrace_return
883 popl %edx
884 popl %ecx
885 popl %eax
e7d3737e 886 ret
fb52607a 887END(ftrace_graph_caller)
caf4b323
FW
888
889.globl return_to_handler
890return_to_handler:
a49976d1
IM
891 pushl %eax
892 pushl %edx
893 movl %ebp, %eax
894 call ftrace_return_to_handler
895 movl %eax, %ecx
896 popl %edx
897 popl %eax
898 jmp *%ecx
e7d3737e 899#endif
16444a8a 900
25c74b10
SA
901#ifdef CONFIG_TRACING
902ENTRY(trace_page_fault)
25c74b10 903 ASM_CLAC
a49976d1
IM
904 pushl $trace_do_page_fault
905 jmp error_code
25c74b10
SA
906END(trace_page_fault)
907#endif
908
d211af05 909ENTRY(page_fault)
e59d1b0a 910 ASM_CLAC
a49976d1 911 pushl $do_page_fault
d211af05
AH
912 ALIGN
913error_code:
ccbeed3a 914 /* the function address is in %gs's slot on the stack */
a49976d1
IM
915 pushl %fs
916 pushl %es
917 pushl %ds
918 pushl %eax
919 pushl %ebp
920 pushl %edi
921 pushl %esi
922 pushl %edx
923 pushl %ecx
924 pushl %ebx
d211af05 925 cld
a49976d1
IM
926 movl $(__KERNEL_PERCPU), %ecx
927 movl %ecx, %fs
d211af05 928 UNWIND_ESPFIX_STACK
ccbeed3a 929 GS_TO_REG %ecx
a49976d1
IM
930 movl PT_GS(%esp), %edi # get the function address
931 movl PT_ORIG_EAX(%esp), %edx # get the error code
932 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
ccbeed3a
TH
933 REG_TO_PTGS %ecx
934 SET_KERNEL_GS %ecx
a49976d1
IM
935 movl $(__USER_DS), %ecx
936 movl %ecx, %ds
937 movl %ecx, %es
d211af05 938 TRACE_IRQS_OFF
a49976d1
IM
939 movl %esp, %eax # pt_regs pointer
940 call *%edi
941 jmp ret_from_exception
d211af05
AH
942END(page_fault)
943
944/*
945 * Debug traps and NMI can happen at the one SYSENTER instruction
946 * that sets up the real kernel stack. Check here, since we can't
947 * allow the wrong stack to be used.
948 *
949 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
950 * already pushed 3 words if it hits on the sysenter instruction:
951 * eflags, cs and eip.
952 *
953 * We just load the right stack, and push the three (known) values
954 * by hand onto the new stack - while updating the return eip past
955 * the instruction that would have done it for sysenter.
956 */
f0d96110 957.macro FIX_STACK offset ok label
a49976d1
IM
958 cmpw $__KERNEL_CS, 4(%esp)
959 jne \ok
f0d96110 960\label:
a49976d1 961 movl TSS_sysenter_sp0 + \offset(%esp), %esp
131484c8 962 pushfl
a49976d1
IM
963 pushl $__KERNEL_CS
964 pushl $sysenter_past_esp
f0d96110 965.endm
d211af05
AH
966
967ENTRY(debug)
e59d1b0a 968 ASM_CLAC
a49976d1
IM
969 cmpl $entry_SYSENTER_32, (%esp)
970 jne debug_stack_correct
f0d96110 971 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
d211af05 972debug_stack_correct:
a49976d1 973 pushl $-1 # mark this as an int
d211af05
AH
974 SAVE_ALL
975 TRACE_IRQS_OFF
a49976d1
IM
976 xorl %edx, %edx # error code 0
977 movl %esp, %eax # pt_regs pointer
978 call do_debug
979 jmp ret_from_exception
d211af05
AH
980END(debug)
981
982/*
983 * NMI is doubly nasty. It can happen _while_ we're handling
984 * a debug fault, and the debug fault hasn't yet been able to
985 * clear up the stack. So we first check whether we got an
986 * NMI on the sysenter entry path, but after that we need to
987 * check whether we got an NMI on the debug path where the debug
988 * fault happened on the sysenter path.
989 */
990ENTRY(nmi)
e59d1b0a 991 ASM_CLAC
34273f41 992#ifdef CONFIG_X86_ESPFIX32
a49976d1
IM
993 pushl %eax
994 movl %ss, %eax
995 cmpw $__ESPFIX_SS, %ax
996 popl %eax
997 je nmi_espfix_stack
34273f41 998#endif
a49976d1
IM
999 cmpl $entry_SYSENTER_32, (%esp)
1000 je nmi_stack_fixup
1001 pushl %eax
1002 movl %esp, %eax
1003 /*
1004 * Do not access memory above the end of our stack page,
d211af05
AH
1005 * it might not exist.
1006 */
a49976d1
IM
1007 andl $(THREAD_SIZE-1), %eax
1008 cmpl $(THREAD_SIZE-20), %eax
1009 popl %eax
1010 jae nmi_stack_correct
1011 cmpl $entry_SYSENTER_32, 12(%esp)
1012 je nmi_debug_stack_check
d211af05 1013nmi_stack_correct:
a49976d1 1014 pushl %eax
d211af05 1015 SAVE_ALL
a49976d1
IM
1016 xorl %edx, %edx # zero error code
1017 movl %esp, %eax # pt_regs pointer
1018 call do_nmi
1019 jmp restore_all_notrace
d211af05
AH
1020
1021nmi_stack_fixup:
f0d96110 1022 FIX_STACK 12, nmi_stack_correct, 1
a49976d1 1023 jmp nmi_stack_correct
d211af05
AH
1024
1025nmi_debug_stack_check:
a49976d1
IM
1026 cmpw $__KERNEL_CS, 16(%esp)
1027 jne nmi_stack_correct
1028 cmpl $debug, (%esp)
1029 jb nmi_stack_correct
1030 cmpl $debug_esp_fix_insn, (%esp)
1031 ja nmi_stack_correct
f0d96110 1032 FIX_STACK 24, nmi_stack_correct, 1
a49976d1 1033 jmp nmi_stack_correct
d211af05 1034
34273f41 1035#ifdef CONFIG_X86_ESPFIX32
d211af05 1036nmi_espfix_stack:
131484c8 1037 /*
d211af05
AH
1038 * create the pointer to lss back
1039 */
a49976d1
IM
1040 pushl %ss
1041 pushl %esp
1042 addl $4, (%esp)
d211af05
AH
1043 /* copy the iret frame of 12 bytes */
1044 .rept 3
a49976d1 1045 pushl 16(%esp)
d211af05 1046 .endr
a49976d1 1047 pushl %eax
d211af05 1048 SAVE_ALL
a49976d1
IM
1049 FIXUP_ESPFIX_STACK # %eax == %esp
1050 xorl %edx, %edx # zero error code
1051 call do_nmi
d211af05 1052 RESTORE_REGS
a49976d1
IM
1053 lss 12+4(%esp), %esp # back to espfix stack
1054 jmp irq_return
34273f41 1055#endif
d211af05
AH
1056END(nmi)
1057
1058ENTRY(int3)
e59d1b0a 1059 ASM_CLAC
a49976d1 1060 pushl $-1 # mark this as an int
d211af05
AH
1061 SAVE_ALL
1062 TRACE_IRQS_OFF
a49976d1
IM
1063 xorl %edx, %edx # zero error code
1064 movl %esp, %eax # pt_regs pointer
1065 call do_int3
1066 jmp ret_from_exception
d211af05
AH
1067END(int3)
1068
1069ENTRY(general_protection)
a49976d1
IM
1070 pushl $do_general_protection
1071 jmp error_code
d211af05
AH
1072END(general_protection)
1073
631bc487
GN
1074#ifdef CONFIG_KVM_GUEST
1075ENTRY(async_page_fault)
e59d1b0a 1076 ASM_CLAC
a49976d1
IM
1077 pushl $do_async_page_fault
1078 jmp error_code
2ae9d293 1079END(async_page_fault)
631bc487 1080#endif