include/asm-x86/xor_64.h: checkpatch cleanups - formatting only
[linux-2.6-block.git] / arch / x86 / kernel / entry_32.S
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/i386/entry.S
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/*
8 * entry.S contains the system-call and fault low-level handling routines.
9 * This also contains the timer-interrupt handler, as well as all interrupts
10 * and faults that can result in a task-switch.
11 *
12 * NOTE: This code handles signal-recognition, which happens every time
13 * after a timer-interrupt and after each system call.
14 *
15 * I changed all the .align's to 4 (16 byte alignment), as that's faster
16 * on a 486.
17 *
889f21ce 18 * Stack layout in 'syscall_exit':
1da177e4
LT
19 * ptrace needs to have all regs on the stack.
20 * if the order here is changed, it needs to be
21 * updated in fork.c:copy_process, signal.c:do_signal,
22 * ptrace.c and ptrace.h
23 *
24 * 0(%esp) - %ebx
25 * 4(%esp) - %ecx
26 * 8(%esp) - %edx
27 * C(%esp) - %esi
28 * 10(%esp) - %edi
29 * 14(%esp) - %ebp
30 * 18(%esp) - %eax
31 * 1C(%esp) - %ds
32 * 20(%esp) - %es
464d1a78 33 * 24(%esp) - %fs
f95d47ca
JF
34 * 28(%esp) - orig_eax
35 * 2C(%esp) - %eip
36 * 30(%esp) - %cs
37 * 34(%esp) - %eflags
38 * 38(%esp) - %oldesp
39 * 3C(%esp) - %oldss
1da177e4
LT
40 *
41 * "current" is in register %ebx during any slow entries.
42 */
43
1da177e4
LT
44#include <linux/linkage.h>
45#include <asm/thread_info.h>
55f327fa 46#include <asm/irqflags.h>
1da177e4
LT
47#include <asm/errno.h>
48#include <asm/segment.h>
49#include <asm/smp.h>
50#include <asm/page.h>
51#include <asm/desc.h>
be44d2aa 52#include <asm/percpu.h>
fe7cacc1 53#include <asm/dwarf2.h>
1da177e4
LT
54#include "irq_vectors.h"
55
139ec7c4
RR
56/*
57 * We use macros for low-level operations which need to be overridden
58 * for paravirtualization. The following will never clobber any registers:
59 * INTERRUPT_RETURN (aka. "iret")
60 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
6abcd98f 61 * ENABLE_INTERRUPTS_SYSCALL_RET (aka "sti; sysexit").
139ec7c4
RR
62 *
63 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
64 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
65 * Allowing a register to be clobbered can shrink the paravirt replacement
66 * enough to patch inline, increasing performance.
67 */
68
1da177e4
LT
69#define nr_syscalls ((syscall_table_size)/4)
70
1da177e4
LT
71CF_MASK = 0x00000001
72TF_MASK = 0x00000100
73IF_MASK = 0x00000200
74DF_MASK = 0x00000400
75NT_MASK = 0x00004000
76VM_MASK = 0x00020000
77
78#ifdef CONFIG_PREEMPT
139ec7c4 79#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
1da177e4 80#else
139ec7c4 81#define preempt_stop(clobbers)
1da177e4
LT
82#define resume_kernel restore_nocheck
83#endif
84
55f327fa
IM
85.macro TRACE_IRQS_IRET
86#ifdef CONFIG_TRACE_IRQFLAGS
eb5b7b9d 87 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off?
55f327fa
IM
88 jz 1f
89 TRACE_IRQS_ON
901:
91#endif
92.endm
93
4031ff38
AG
94#ifdef CONFIG_VM86
95#define resume_userspace_sig check_userspace
96#else
97#define resume_userspace_sig resume_userspace
98#endif
99
1da177e4
LT
100#define SAVE_ALL \
101 cld; \
464d1a78 102 pushl %fs; \
f95d47ca 103 CFI_ADJUST_CFA_OFFSET 4;\
464d1a78 104 /*CFI_REL_OFFSET fs, 0;*/\
1da177e4 105 pushl %es; \
fe7cacc1
JB
106 CFI_ADJUST_CFA_OFFSET 4;\
107 /*CFI_REL_OFFSET es, 0;*/\
1da177e4 108 pushl %ds; \
fe7cacc1
JB
109 CFI_ADJUST_CFA_OFFSET 4;\
110 /*CFI_REL_OFFSET ds, 0;*/\
1da177e4 111 pushl %eax; \
fe7cacc1
JB
112 CFI_ADJUST_CFA_OFFSET 4;\
113 CFI_REL_OFFSET eax, 0;\
1da177e4 114 pushl %ebp; \
fe7cacc1
JB
115 CFI_ADJUST_CFA_OFFSET 4;\
116 CFI_REL_OFFSET ebp, 0;\
1da177e4 117 pushl %edi; \
fe7cacc1
JB
118 CFI_ADJUST_CFA_OFFSET 4;\
119 CFI_REL_OFFSET edi, 0;\
1da177e4 120 pushl %esi; \
fe7cacc1
JB
121 CFI_ADJUST_CFA_OFFSET 4;\
122 CFI_REL_OFFSET esi, 0;\
1da177e4 123 pushl %edx; \
fe7cacc1
JB
124 CFI_ADJUST_CFA_OFFSET 4;\
125 CFI_REL_OFFSET edx, 0;\
1da177e4 126 pushl %ecx; \
fe7cacc1
JB
127 CFI_ADJUST_CFA_OFFSET 4;\
128 CFI_REL_OFFSET ecx, 0;\
1da177e4 129 pushl %ebx; \
fe7cacc1
JB
130 CFI_ADJUST_CFA_OFFSET 4;\
131 CFI_REL_OFFSET ebx, 0;\
1da177e4
LT
132 movl $(__USER_DS), %edx; \
133 movl %edx, %ds; \
f95d47ca 134 movl %edx, %es; \
7c3576d2 135 movl $(__KERNEL_PERCPU), %edx; \
464d1a78 136 movl %edx, %fs
1da177e4
LT
137
138#define RESTORE_INT_REGS \
139 popl %ebx; \
fe7cacc1
JB
140 CFI_ADJUST_CFA_OFFSET -4;\
141 CFI_RESTORE ebx;\
1da177e4 142 popl %ecx; \
fe7cacc1
JB
143 CFI_ADJUST_CFA_OFFSET -4;\
144 CFI_RESTORE ecx;\
1da177e4 145 popl %edx; \
fe7cacc1
JB
146 CFI_ADJUST_CFA_OFFSET -4;\
147 CFI_RESTORE edx;\
1da177e4 148 popl %esi; \
fe7cacc1
JB
149 CFI_ADJUST_CFA_OFFSET -4;\
150 CFI_RESTORE esi;\
1da177e4 151 popl %edi; \
fe7cacc1
JB
152 CFI_ADJUST_CFA_OFFSET -4;\
153 CFI_RESTORE edi;\
1da177e4 154 popl %ebp; \
fe7cacc1
JB
155 CFI_ADJUST_CFA_OFFSET -4;\
156 CFI_RESTORE ebp;\
157 popl %eax; \
158 CFI_ADJUST_CFA_OFFSET -4;\
159 CFI_RESTORE eax
1da177e4
LT
160
161#define RESTORE_REGS \
162 RESTORE_INT_REGS; \
1631: popl %ds; \
fe7cacc1
JB
164 CFI_ADJUST_CFA_OFFSET -4;\
165 /*CFI_RESTORE ds;*/\
1da177e4 1662: popl %es; \
fe7cacc1
JB
167 CFI_ADJUST_CFA_OFFSET -4;\
168 /*CFI_RESTORE es;*/\
464d1a78 1693: popl %fs; \
f95d47ca 170 CFI_ADJUST_CFA_OFFSET -4;\
464d1a78 171 /*CFI_RESTORE fs;*/\
f95d47ca 172.pushsection .fixup,"ax"; \
1da177e4 1734: movl $0,(%esp); \
f95d47ca
JF
174 jmp 1b; \
1755: movl $0,(%esp); \
1da177e4 176 jmp 2b; \
f95d47ca
JF
1776: movl $0,(%esp); \
178 jmp 3b; \
1da177e4
LT
179.section __ex_table,"a";\
180 .align 4; \
f95d47ca
JF
181 .long 1b,4b; \
182 .long 2b,5b; \
183 .long 3b,6b; \
184.popsection
1da177e4 185
fe7cacc1
JB
186#define RING0_INT_FRAME \
187 CFI_STARTPROC simple;\
adf14236 188 CFI_SIGNAL_FRAME;\
fe7cacc1
JB
189 CFI_DEF_CFA esp, 3*4;\
190 /*CFI_OFFSET cs, -2*4;*/\
191 CFI_OFFSET eip, -3*4
192
193#define RING0_EC_FRAME \
194 CFI_STARTPROC simple;\
adf14236 195 CFI_SIGNAL_FRAME;\
fe7cacc1
JB
196 CFI_DEF_CFA esp, 4*4;\
197 /*CFI_OFFSET cs, -2*4;*/\
198 CFI_OFFSET eip, -3*4
199
200#define RING0_PTREGS_FRAME \
201 CFI_STARTPROC simple;\
adf14236 202 CFI_SIGNAL_FRAME;\
eb5b7b9d
JF
203 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
204 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
205 CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
206 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
207 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
208 CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
209 CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
210 CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
211 CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
212 CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
213 CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
214 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
1da177e4
LT
215
216ENTRY(ret_from_fork)
fe7cacc1 217 CFI_STARTPROC
1da177e4 218 pushl %eax
25d7dfda 219 CFI_ADJUST_CFA_OFFSET 4
1da177e4
LT
220 call schedule_tail
221 GET_THREAD_INFO(%ebp)
222 popl %eax
fe7cacc1 223 CFI_ADJUST_CFA_OFFSET -4
47a5c6fa
LT
224 pushl $0x0202 # Reset kernel eflags
225 CFI_ADJUST_CFA_OFFSET 4
226 popfl
227 CFI_ADJUST_CFA_OFFSET -4
1da177e4 228 jmp syscall_exit
fe7cacc1 229 CFI_ENDPROC
47a55cd7 230END(ret_from_fork)
1da177e4
LT
231
232/*
233 * Return to user mode is not as complex as all this looks,
234 * but we want the default path for a system call return to
235 * go as quickly as possible which is why some of this is
236 * less clear than it otherwise should be.
237 */
238
239 # userspace resumption stub bypassing syscall exit tracing
240 ALIGN
fe7cacc1 241 RING0_PTREGS_FRAME
1da177e4 242ret_from_exception:
139ec7c4 243 preempt_stop(CLBR_ANY)
1da177e4
LT
244ret_from_intr:
245 GET_THREAD_INFO(%ebp)
4031ff38 246check_userspace:
eb5b7b9d
JF
247 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
248 movb PT_CS(%esp), %al
78be3706
RR
249 andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
250 cmpl $USER_RPL, %eax
251 jb resume_kernel # not returning to v8086 or userspace
f95d47ca 252
1da177e4 253ENTRY(resume_userspace)
c7e872e7 254 LOCKDEP_SYS_EXIT
139ec7c4 255 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
1da177e4
LT
256 # setting need_resched or sigpending
257 # between sampling and the iret
258 movl TI_flags(%ebp), %ecx
259 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
260 # int/exception return?
261 jne work_pending
262 jmp restore_all
47a55cd7 263END(ret_from_exception)
1da177e4
LT
264
265#ifdef CONFIG_PREEMPT
266ENTRY(resume_kernel)
139ec7c4 267 DISABLE_INTERRUPTS(CLBR_ANY)
1da177e4
LT
268 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
269 jnz restore_nocheck
270need_resched:
271 movl TI_flags(%ebp), %ecx # need_resched set ?
272 testb $_TIF_NEED_RESCHED, %cl
273 jz restore_all
eb5b7b9d 274 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
1da177e4
LT
275 jz restore_all
276 call preempt_schedule_irq
277 jmp need_resched
47a55cd7 278END(resume_kernel)
1da177e4 279#endif
fe7cacc1 280 CFI_ENDPROC
1da177e4
LT
281
282/* SYSENTER_RETURN points to after the "sysenter" instruction in
283 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
284
285 # sysenter call handler stub
0aa97fb2 286ENTRY(ia32_sysenter_target)
fe7cacc1 287 CFI_STARTPROC simple
adf14236 288 CFI_SIGNAL_FRAME
fe7cacc1
JB
289 CFI_DEF_CFA esp, 0
290 CFI_REGISTER esp, ebp
faca6227 291 movl TSS_sysenter_sp0(%esp),%esp
1da177e4 292sysenter_past_esp:
55f327fa
IM
293 /*
294 * No need to follow this irqs on/off section: the syscall
295 * disabled irqs and here we enable it straight after entry:
296 */
139ec7c4 297 ENABLE_INTERRUPTS(CLBR_NONE)
1da177e4 298 pushl $(__USER_DS)
fe7cacc1
JB
299 CFI_ADJUST_CFA_OFFSET 4
300 /*CFI_REL_OFFSET ss, 0*/
1da177e4 301 pushl %ebp
fe7cacc1
JB
302 CFI_ADJUST_CFA_OFFSET 4
303 CFI_REL_OFFSET esp, 0
1da177e4 304 pushfl
fe7cacc1 305 CFI_ADJUST_CFA_OFFSET 4
1da177e4 306 pushl $(__USER_CS)
fe7cacc1
JB
307 CFI_ADJUST_CFA_OFFSET 4
308 /*CFI_REL_OFFSET cs, 0*/
e6e5494c
IM
309 /*
310 * Push current_thread_info()->sysenter_return to the stack.
311 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
312 * pushed above; +8 corresponds to copy_thread's esp0 setting.
313 */
314 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
fe7cacc1
JB
315 CFI_ADJUST_CFA_OFFSET 4
316 CFI_REL_OFFSET eip, 0
1da177e4
LT
317
318/*
319 * Load the potential sixth argument from user stack.
320 * Careful about security.
321 */
322 cmpl $__PAGE_OFFSET-3,%ebp
323 jae syscall_fault
3241: movl (%ebp),%ebp
325.section __ex_table,"a"
326 .align 4
327 .long 1b,syscall_fault
328.previous
329
330 pushl %eax
fe7cacc1 331 CFI_ADJUST_CFA_OFFSET 4
1da177e4
LT
332 SAVE_ALL
333 GET_THREAD_INFO(%ebp)
334
335 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
ed75e8d5 336 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
1da177e4
LT
337 jnz syscall_trace_entry
338 cmpl $(nr_syscalls), %eax
339 jae syscall_badsys
340 call *sys_call_table(,%eax,4)
eb5b7b9d 341 movl %eax,PT_EAX(%esp)
c7e872e7 342 LOCKDEP_SYS_EXIT
42c24fa2 343 DISABLE_INTERRUPTS(CLBR_ANY)
55f327fa 344 TRACE_IRQS_OFF
1da177e4
LT
345 movl TI_flags(%ebp), %ecx
346 testw $_TIF_ALLWORK_MASK, %cx
347 jne syscall_exit_work
348/* if something modifies registers it must also disable sysexit */
eb5b7b9d
JF
349 movl PT_EIP(%esp), %edx
350 movl PT_OLDESP(%esp), %ecx
1da177e4 351 xorl %ebp,%ebp
55f327fa 352 TRACE_IRQS_ON
464d1a78 3531: mov PT_FS(%esp), %fs
6abcd98f 354 ENABLE_INTERRUPTS_SYSCALL_RET
fe7cacc1 355 CFI_ENDPROC
f95d47ca 356.pushsection .fixup,"ax"
464d1a78 3572: movl $0,PT_FS(%esp)
f95d47ca
JF
358 jmp 1b
359.section __ex_table,"a"
360 .align 4
361 .long 1b,2b
362.popsection
0aa97fb2 363ENDPROC(ia32_sysenter_target)
1da177e4
LT
364
365 # system call handler stub
366ENTRY(system_call)
fe7cacc1 367 RING0_INT_FRAME # can't unwind into user space anyway
1da177e4 368 pushl %eax # save orig_eax
fe7cacc1 369 CFI_ADJUST_CFA_OFFSET 4
1da177e4
LT
370 SAVE_ALL
371 GET_THREAD_INFO(%ebp)
ed75e8d5 372 # system call tracing in operation / emulation
1da177e4 373 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
ed75e8d5 374 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
1da177e4
LT
375 jnz syscall_trace_entry
376 cmpl $(nr_syscalls), %eax
377 jae syscall_badsys
378syscall_call:
379 call *sys_call_table(,%eax,4)
eb5b7b9d 380 movl %eax,PT_EAX(%esp) # store the return value
1da177e4 381syscall_exit:
c7e872e7 382 LOCKDEP_SYS_EXIT
139ec7c4 383 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
1da177e4
LT
384 # setting need_resched or sigpending
385 # between sampling and the iret
55f327fa 386 TRACE_IRQS_OFF
1e2e99f0
JW
387 testl $TF_MASK,PT_EFLAGS(%esp) # If tracing set singlestep flag on exit
388 jz no_singlestep
389 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
390no_singlestep:
1da177e4
LT
391 movl TI_flags(%ebp), %ecx
392 testw $_TIF_ALLWORK_MASK, %cx # current->work
393 jne syscall_exit_work
394
395restore_all:
eb5b7b9d
JF
396 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
397 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
5df24082
SS
398 # are returning to the kernel.
399 # See comments in process.c:copy_thread() for details.
eb5b7b9d
JF
400 movb PT_OLDSS(%esp), %ah
401 movb PT_CS(%esp), %al
78be3706
RR
402 andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
403 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
fe7cacc1 404 CFI_REMEMBER_STATE
1da177e4
LT
405 je ldt_ss # returning to user-space with LDT SS
406restore_nocheck:
55f327fa
IM
407 TRACE_IRQS_IRET
408restore_nocheck_notrace:
1da177e4 409 RESTORE_REGS
f95d47ca 410 addl $4, %esp # skip orig_eax/error_code
fe7cacc1 411 CFI_ADJUST_CFA_OFFSET -4
f7f3d791 412irq_return:
3701d863 413 INTERRUPT_RETURN
1da177e4
LT
414.section .fixup,"ax"
415iret_exc:
a879cbbb
LT
416 pushl $0 # no error code
417 pushl $do_iret_error
418 jmp error_code
1da177e4
LT
419.previous
420.section __ex_table,"a"
421 .align 4
3701d863 422 .long irq_return,iret_exc
1da177e4
LT
423.previous
424
fe7cacc1 425 CFI_RESTORE_STATE
1da177e4 426ldt_ss:
eb5b7b9d 427 larl PT_OLDSS(%esp), %eax
1da177e4
LT
428 jnz restore_nocheck
429 testl $0x00400000, %eax # returning to 32bit stack?
430 jnz restore_nocheck # allright, normal return
d3561b7f
RR
431
432#ifdef CONFIG_PARAVIRT
433 /*
434 * The kernel can't run on a non-flat stack if paravirt mode
435 * is active. Rather than try to fixup the high bits of
436 * ESP, bypass this code entirely. This may break DOSemu
437 * and/or Wine support in a paravirt VM, although the option
438 * is still available to implement the setting of the high
439 * 16-bits in the INTERRUPT_RETURN paravirt-op.
440 */
93b1eab3 441 cmpl $0, pv_info+PARAVIRT_enabled
d3561b7f
RR
442 jne restore_nocheck
443#endif
444
1da177e4
LT
445 /* If returning to userspace with 16bit stack,
446 * try to fix the higher word of ESP, as the CPU
447 * won't restore it.
448 * This is an "official" bug of all the x86-compatible
449 * CPUs, which we can try to work around to make
450 * dosemu and wine happy. */
eb5b7b9d 451 movl PT_OLDESP(%esp), %eax
be44d2aa
SS
452 movl %esp, %edx
453 call patch_espfix_desc
454 pushl $__ESPFIX_SS
455 CFI_ADJUST_CFA_OFFSET 4
456 pushl %eax
457 CFI_ADJUST_CFA_OFFSET 4
139ec7c4 458 DISABLE_INTERRUPTS(CLBR_EAX)
55f327fa 459 TRACE_IRQS_OFF
be44d2aa
SS
460 lss (%esp), %esp
461 CFI_ADJUST_CFA_OFFSET -8
462 jmp restore_nocheck
fe7cacc1 463 CFI_ENDPROC
47a55cd7 464ENDPROC(system_call)
1da177e4
LT
465
466 # perform work that needs to be done immediately before resumption
467 ALIGN
fe7cacc1 468 RING0_PTREGS_FRAME # can't unwind into user space anyway
1da177e4
LT
469work_pending:
470 testb $_TIF_NEED_RESCHED, %cl
471 jz work_notifysig
472work_resched:
473 call schedule
c7e872e7 474 LOCKDEP_SYS_EXIT
139ec7c4 475 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
1da177e4
LT
476 # setting need_resched or sigpending
477 # between sampling and the iret
55f327fa 478 TRACE_IRQS_OFF
1da177e4
LT
479 movl TI_flags(%ebp), %ecx
480 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
481 # than syscall tracing?
482 jz restore_all
483 testb $_TIF_NEED_RESCHED, %cl
484 jnz work_resched
485
486work_notifysig: # deal with pending signals and
487 # notify-resume requests
74b47a78 488#ifdef CONFIG_VM86
eb5b7b9d 489 testl $VM_MASK, PT_EFLAGS(%esp)
1da177e4
LT
490 movl %esp, %eax
491 jne work_notifysig_v86 # returning to kernel-space or
492 # vm86-space
493 xorl %edx, %edx
494 call do_notify_resume
4031ff38 495 jmp resume_userspace_sig
1da177e4
LT
496
497 ALIGN
498work_notifysig_v86:
499 pushl %ecx # save ti_flags for do_notify_resume
fe7cacc1 500 CFI_ADJUST_CFA_OFFSET 4
1da177e4
LT
501 call save_v86_state # %eax contains pt_regs pointer
502 popl %ecx
fe7cacc1 503 CFI_ADJUST_CFA_OFFSET -4
1da177e4 504 movl %eax, %esp
74b47a78
JK
505#else
506 movl %esp, %eax
507#endif
1da177e4
LT
508 xorl %edx, %edx
509 call do_notify_resume
4031ff38 510 jmp resume_userspace_sig
47a55cd7 511END(work_pending)
1da177e4
LT
512
513 # perform syscall exit tracing
514 ALIGN
515syscall_trace_entry:
eb5b7b9d 516 movl $-ENOSYS,PT_EAX(%esp)
1da177e4
LT
517 movl %esp, %eax
518 xorl %edx,%edx
519 call do_syscall_trace
ed75e8d5 520 cmpl $0, %eax
640aa46e 521 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
ed75e8d5 522 # so must skip actual syscall
eb5b7b9d 523 movl PT_ORIG_EAX(%esp), %eax
1da177e4
LT
524 cmpl $(nr_syscalls), %eax
525 jnae syscall_call
526 jmp syscall_exit
47a55cd7 527END(syscall_trace_entry)
1da177e4
LT
528
529 # perform syscall exit tracing
530 ALIGN
531syscall_exit_work:
532 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
533 jz work_pending
55f327fa 534 TRACE_IRQS_ON
139ec7c4 535 ENABLE_INTERRUPTS(CLBR_ANY) # could let do_syscall_trace() call
1da177e4
LT
536 # schedule() instead
537 movl %esp, %eax
538 movl $1, %edx
539 call do_syscall_trace
540 jmp resume_userspace
47a55cd7 541END(syscall_exit_work)
fe7cacc1 542 CFI_ENDPROC
1da177e4 543
fe7cacc1 544 RING0_INT_FRAME # can't unwind into user space anyway
1da177e4
LT
545syscall_fault:
546 pushl %eax # save orig_eax
fe7cacc1 547 CFI_ADJUST_CFA_OFFSET 4
1da177e4
LT
548 SAVE_ALL
549 GET_THREAD_INFO(%ebp)
eb5b7b9d 550 movl $-EFAULT,PT_EAX(%esp)
1da177e4 551 jmp resume_userspace
47a55cd7 552END(syscall_fault)
1da177e4 553
1da177e4 554syscall_badsys:
eb5b7b9d 555 movl $-ENOSYS,PT_EAX(%esp)
1da177e4 556 jmp resume_userspace
47a55cd7 557END(syscall_badsys)
fe7cacc1 558 CFI_ENDPROC
1da177e4
LT
559
560#define FIXUP_ESPFIX_STACK \
be44d2aa 561 /* since we are on a wrong stack, we cant make it a C code :( */ \
7a61d35d 562 PER_CPU(gdt_page, %ebx); \
be44d2aa
SS
563 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
564 addl %esp, %eax; \
565 pushl $__KERNEL_DS; \
566 CFI_ADJUST_CFA_OFFSET 4; \
1da177e4 567 pushl %eax; \
fe7cacc1 568 CFI_ADJUST_CFA_OFFSET 4; \
be44d2aa
SS
569 lss (%esp), %esp; \
570 CFI_ADJUST_CFA_OFFSET -8;
571#define UNWIND_ESPFIX_STACK \
1da177e4 572 movl %ss, %eax; \
be44d2aa 573 /* see if on espfix stack */ \
1da177e4 574 cmpw $__ESPFIX_SS, %ax; \
be44d2aa
SS
575 jne 27f; \
576 movl $__KERNEL_DS, %eax; \
fe7cacc1
JB
577 movl %eax, %ds; \
578 movl %eax, %es; \
be44d2aa 579 /* switch to normal stack */ \
fe7cacc1 580 FIXUP_ESPFIX_STACK; \
be44d2aa 58127:;
1da177e4
LT
582
583/*
584 * Build the entry stubs and pointer table with
585 * some assembler magic.
586 */
3e7622f9 587.section .rodata,"a"
1da177e4
LT
588ENTRY(interrupt)
589.text
590
1da177e4 591ENTRY(irq_entries_start)
fe7cacc1 592 RING0_INT_FRAME
47a55cd7 593vector=0
1da177e4
LT
594.rept NR_IRQS
595 ALIGN
fe7cacc1
JB
596 .if vector
597 CFI_ADJUST_CFA_OFFSET -4
598 .endif
19eadf98 5991: pushl $~(vector)
fe7cacc1 600 CFI_ADJUST_CFA_OFFSET 4
1da177e4 601 jmp common_interrupt
47a55cd7 602 .previous
1da177e4 603 .long 1b
47a55cd7 604 .text
1da177e4
LT
605vector=vector+1
606.endr
47a55cd7
JB
607END(irq_entries_start)
608
609.previous
610END(interrupt)
611.previous
1da177e4 612
55f327fa
IM
613/*
614 * the CPU automatically disables interrupts when executing an IRQ vector,
615 * so IRQ-flags tracing has to follow that:
616 */
1da177e4
LT
617 ALIGN
618common_interrupt:
619 SAVE_ALL
55f327fa 620 TRACE_IRQS_OFF
1da177e4
LT
621 movl %esp,%eax
622 call do_IRQ
623 jmp ret_from_intr
47a55cd7 624ENDPROC(common_interrupt)
fe7cacc1 625 CFI_ENDPROC
1da177e4
LT
626
627#define BUILD_INTERRUPT(name, nr) \
628ENTRY(name) \
fe7cacc1 629 RING0_INT_FRAME; \
19eadf98 630 pushl $~(nr); \
fe7cacc1
JB
631 CFI_ADJUST_CFA_OFFSET 4; \
632 SAVE_ALL; \
55f327fa 633 TRACE_IRQS_OFF \
1da177e4 634 movl %esp,%eax; \
f76c3923 635 call smp_##name; \
55f327fa 636 jmp ret_from_intr; \
47a55cd7
JB
637 CFI_ENDPROC; \
638ENDPROC(name)
1da177e4
LT
639
640/* The include is where all of the SMP etc. interrupts come from */
641#include "entry_arch.h"
642
d28c4393
P
643KPROBE_ENTRY(page_fault)
644 RING0_EC_FRAME
645 pushl $do_page_fault
fe7cacc1 646 CFI_ADJUST_CFA_OFFSET 4
1da177e4
LT
647 ALIGN
648error_code:
464d1a78 649 /* the function address is in %fs's slot on the stack */
f95d47ca
JF
650 pushl %es
651 CFI_ADJUST_CFA_OFFSET 4
652 /*CFI_REL_OFFSET es, 0*/
1da177e4 653 pushl %ds
fe7cacc1
JB
654 CFI_ADJUST_CFA_OFFSET 4
655 /*CFI_REL_OFFSET ds, 0*/
1da177e4 656 pushl %eax
fe7cacc1
JB
657 CFI_ADJUST_CFA_OFFSET 4
658 CFI_REL_OFFSET eax, 0
1da177e4 659 pushl %ebp
fe7cacc1
JB
660 CFI_ADJUST_CFA_OFFSET 4
661 CFI_REL_OFFSET ebp, 0
1da177e4 662 pushl %edi
fe7cacc1
JB
663 CFI_ADJUST_CFA_OFFSET 4
664 CFI_REL_OFFSET edi, 0
1da177e4 665 pushl %esi
fe7cacc1
JB
666 CFI_ADJUST_CFA_OFFSET 4
667 CFI_REL_OFFSET esi, 0
1da177e4 668 pushl %edx
fe7cacc1
JB
669 CFI_ADJUST_CFA_OFFSET 4
670 CFI_REL_OFFSET edx, 0
1da177e4 671 pushl %ecx
fe7cacc1
JB
672 CFI_ADJUST_CFA_OFFSET 4
673 CFI_REL_OFFSET ecx, 0
1da177e4 674 pushl %ebx
fe7cacc1
JB
675 CFI_ADJUST_CFA_OFFSET 4
676 CFI_REL_OFFSET ebx, 0
1da177e4 677 cld
464d1a78 678 pushl %fs
fe7cacc1 679 CFI_ADJUST_CFA_OFFSET 4
464d1a78 680 /*CFI_REL_OFFSET fs, 0*/
7c3576d2 681 movl $(__KERNEL_PERCPU), %ecx
464d1a78 682 movl %ecx, %fs
1da177e4
LT
683 UNWIND_ESPFIX_STACK
684 popl %ecx
fe7cacc1
JB
685 CFI_ADJUST_CFA_OFFSET -4
686 /*CFI_REGISTER es, ecx*/
464d1a78 687 movl PT_FS(%esp), %edi # get the function address
eb5b7b9d 688 movl PT_ORIG_EAX(%esp), %edx # get the error code
f95d47ca 689 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
464d1a78
JF
690 mov %ecx, PT_FS(%esp)
691 /*CFI_REL_OFFSET fs, ES*/
1da177e4
LT
692 movl $(__USER_DS), %ecx
693 movl %ecx, %ds
694 movl %ecx, %es
695 movl %esp,%eax # pt_regs pointer
696 call *%edi
697 jmp ret_from_exception
fe7cacc1 698 CFI_ENDPROC
d28c4393 699KPROBE_END(page_fault)
1da177e4
LT
700
701ENTRY(coprocessor_error)
fe7cacc1 702 RING0_INT_FRAME
1da177e4 703 pushl $0
fe7cacc1 704 CFI_ADJUST_CFA_OFFSET 4
1da177e4 705 pushl $do_coprocessor_error
fe7cacc1 706 CFI_ADJUST_CFA_OFFSET 4
1da177e4 707 jmp error_code
fe7cacc1 708 CFI_ENDPROC
47a55cd7 709END(coprocessor_error)
1da177e4
LT
710
711ENTRY(simd_coprocessor_error)
fe7cacc1 712 RING0_INT_FRAME
1da177e4 713 pushl $0
fe7cacc1 714 CFI_ADJUST_CFA_OFFSET 4
1da177e4 715 pushl $do_simd_coprocessor_error
fe7cacc1 716 CFI_ADJUST_CFA_OFFSET 4
1da177e4 717 jmp error_code
fe7cacc1 718 CFI_ENDPROC
47a55cd7 719END(simd_coprocessor_error)
1da177e4
LT
720
721ENTRY(device_not_available)
fe7cacc1 722 RING0_INT_FRAME
1da177e4 723 pushl $-1 # mark this as an int
fe7cacc1 724 CFI_ADJUST_CFA_OFFSET 4
1da177e4 725 SAVE_ALL
0da5db31 726 GET_CR0_INTO_EAX
1da177e4
LT
727 testl $0x4, %eax # EM (math emulation bit)
728 jne device_not_available_emulate
139ec7c4 729 preempt_stop(CLBR_ANY)
1da177e4
LT
730 call math_state_restore
731 jmp ret_from_exception
732device_not_available_emulate:
733 pushl $0 # temporary storage for ORIG_EIP
fe7cacc1 734 CFI_ADJUST_CFA_OFFSET 4
1da177e4
LT
735 call math_emulate
736 addl $4, %esp
fe7cacc1 737 CFI_ADJUST_CFA_OFFSET -4
1da177e4 738 jmp ret_from_exception
fe7cacc1 739 CFI_ENDPROC
47a55cd7 740END(device_not_available)
1da177e4
LT
741
742/*
743 * Debug traps and NMI can happen at the one SYSENTER instruction
744 * that sets up the real kernel stack. Check here, since we can't
745 * allow the wrong stack to be used.
746 *
faca6227 747 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1da177e4
LT
748 * already pushed 3 words if it hits on the sysenter instruction:
749 * eflags, cs and eip.
750 *
751 * We just load the right stack, and push the three (known) values
752 * by hand onto the new stack - while updating the return eip past
753 * the instruction that would have done it for sysenter.
754 */
755#define FIX_STACK(offset, ok, label) \
756 cmpw $__KERNEL_CS,4(%esp); \
757 jne ok; \
758label: \
faca6227 759 movl TSS_sysenter_sp0+offset(%esp),%esp; \
a549b86d
CE
760 CFI_DEF_CFA esp, 0; \
761 CFI_UNDEFINED eip; \
1da177e4 762 pushfl; \
a549b86d 763 CFI_ADJUST_CFA_OFFSET 4; \
1da177e4 764 pushl $__KERNEL_CS; \
a549b86d
CE
765 CFI_ADJUST_CFA_OFFSET 4; \
766 pushl $sysenter_past_esp; \
767 CFI_ADJUST_CFA_OFFSET 4; \
768 CFI_REL_OFFSET eip, 0
1da177e4 769
3d97ae5b 770KPROBE_ENTRY(debug)
fe7cacc1 771 RING0_INT_FRAME
0aa97fb2 772 cmpl $ia32_sysenter_target,(%esp)
1da177e4
LT
773 jne debug_stack_correct
774 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
775debug_stack_correct:
776 pushl $-1 # mark this as an int
fe7cacc1 777 CFI_ADJUST_CFA_OFFSET 4
1da177e4
LT
778 SAVE_ALL
779 xorl %edx,%edx # error code 0
780 movl %esp,%eax # pt_regs pointer
781 call do_debug
1da177e4 782 jmp ret_from_exception
fe7cacc1 783 CFI_ENDPROC
d28c4393
P
784KPROBE_END(debug)
785
1da177e4
LT
786/*
787 * NMI is doubly nasty. It can happen _while_ we're handling
788 * a debug fault, and the debug fault hasn't yet been able to
789 * clear up the stack. So we first check whether we got an
790 * NMI on the sysenter entry path, but after that we need to
791 * check whether we got an NMI on the debug path where the debug
792 * fault happened on the sysenter path.
793 */