blob: d274612e05cdbde1e2190d43646878551042d737 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
18 * Stack layout in 'ret_from_system_call':
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
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +010033 * 24(%esp) - %gs
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 *
41 * "current" is in register %ebx during any slow entries.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/linkage.h>
45#include <asm/thread_info.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070046#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/errno.h>
48#include <asm/segment.h>
49#include <asm/smp.h>
50#include <asm/page.h>
51#include <asm/desc.h>
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010052#include <asm/percpu.h>
Jan Beulichfe7cacc2006-06-26 13:57:44 +020053#include <asm/dwarf2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "irq_vectors.h"
55
56#define nr_syscalls ((syscall_table_size)/4)
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058CF_MASK = 0x00000001
59TF_MASK = 0x00000100
60IF_MASK = 0x00000200
61DF_MASK = 0x00000400
62NT_MASK = 0x00004000
63VM_MASK = 0x00020000
64
65#ifdef CONFIG_PREEMPT
Rusty Russell0da5db32006-09-26 10:52:39 +020066#define preempt_stop DISABLE_INTERRUPTS; TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#else
68#define preempt_stop
69#define resume_kernel restore_nocheck
70#endif
71
Ingo Molnar55f327f2006-07-03 00:24:43 -070072.macro TRACE_IRQS_IRET
73#ifdef CONFIG_TRACE_IRQFLAGS
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +010074 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off?
Ingo Molnar55f327f2006-07-03 00:24:43 -070075 jz 1f
76 TRACE_IRQS_ON
771:
78#endif
79.endm
80
Aleksey Gorelov4031ff32006-06-27 02:53:48 -070081#ifdef CONFIG_VM86
82#define resume_userspace_sig check_userspace
83#else
84#define resume_userspace_sig resume_userspace
85#endif
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define SAVE_ALL \
88 cld; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +010089 pushl %gs; \
90 CFI_ADJUST_CFA_OFFSET 4;\
91 /*CFI_REL_OFFSET gs, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 pushl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +020093 CFI_ADJUST_CFA_OFFSET 4;\
94 /*CFI_REL_OFFSET es, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 pushl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +020096 CFI_ADJUST_CFA_OFFSET 4;\
97 /*CFI_REL_OFFSET ds, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +020099 CFI_ADJUST_CFA_OFFSET 4;\
100 CFI_REL_OFFSET eax, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 pushl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200102 CFI_ADJUST_CFA_OFFSET 4;\
103 CFI_REL_OFFSET ebp, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 pushl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200105 CFI_ADJUST_CFA_OFFSET 4;\
106 CFI_REL_OFFSET edi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 pushl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200108 CFI_ADJUST_CFA_OFFSET 4;\
109 CFI_REL_OFFSET esi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 pushl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200111 CFI_ADJUST_CFA_OFFSET 4;\
112 CFI_REL_OFFSET edx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 pushl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200114 CFI_ADJUST_CFA_OFFSET 4;\
115 CFI_REL_OFFSET ecx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 pushl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200117 CFI_ADJUST_CFA_OFFSET 4;\
118 CFI_REL_OFFSET ebx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 movl $(__USER_DS), %edx; \
120 movl %edx, %ds; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100121 movl %edx, %es; \
122 movl $(__KERNEL_PDA), %edx; \
123 movl %edx, %gs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125#define RESTORE_INT_REGS \
126 popl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200127 CFI_ADJUST_CFA_OFFSET -4;\
128 CFI_RESTORE ebx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 popl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200130 CFI_ADJUST_CFA_OFFSET -4;\
131 CFI_RESTORE ecx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 popl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200133 CFI_ADJUST_CFA_OFFSET -4;\
134 CFI_RESTORE edx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 popl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200136 CFI_ADJUST_CFA_OFFSET -4;\
137 CFI_RESTORE esi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 popl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200139 CFI_ADJUST_CFA_OFFSET -4;\
140 CFI_RESTORE edi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 popl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200142 CFI_ADJUST_CFA_OFFSET -4;\
143 CFI_RESTORE ebp;\
144 popl %eax; \
145 CFI_ADJUST_CFA_OFFSET -4;\
146 CFI_RESTORE eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148#define RESTORE_REGS \
149 RESTORE_INT_REGS; \
1501: popl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200151 CFI_ADJUST_CFA_OFFSET -4;\
152 /*CFI_RESTORE ds;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532: popl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200154 CFI_ADJUST_CFA_OFFSET -4;\
155 /*CFI_RESTORE es;*/\
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +01001563: popl %gs; \
157 CFI_ADJUST_CFA_OFFSET -4;\
158 /*CFI_RESTORE gs;*/\
159.pushsection .fixup,"ax"; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604: movl $0,(%esp); \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100161 jmp 1b; \
1625: movl $0,(%esp); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 jmp 2b; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +01001646: movl $0,(%esp); \
165 jmp 3b; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166.section __ex_table,"a";\
167 .align 4; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100168 .long 1b,4b; \
169 .long 2b,5b; \
170 .long 3b,6b; \
171.popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200173#define RING0_INT_FRAME \
174 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200175 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200176 CFI_DEF_CFA esp, 3*4;\
177 /*CFI_OFFSET cs, -2*4;*/\
178 CFI_OFFSET eip, -3*4
179
180#define RING0_EC_FRAME \
181 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200182 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200183 CFI_DEF_CFA esp, 4*4;\
184 /*CFI_OFFSET cs, -2*4;*/\
185 CFI_OFFSET eip, -3*4
186
187#define RING0_PTREGS_FRAME \
188 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200189 CFI_SIGNAL_FRAME;\
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100190 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
191 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
192 CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
193 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
194 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
195 CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
196 CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
197 CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
198 CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
199 CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
200 CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
201 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200204 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 pushl %eax
Markus Armbruster25d7dfd2006-07-30 03:04:08 -0700206 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 call schedule_tail
208 GET_THREAD_INFO(%ebp)
209 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200210 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds47a5c6f2006-09-18 16:20:40 -0700211 pushl $0x0202 # Reset kernel eflags
212 CFI_ADJUST_CFA_OFFSET 4
213 popfl
214 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200216 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218/*
219 * Return to user mode is not as complex as all this looks,
220 * but we want the default path for a system call return to
221 * go as quickly as possible which is why some of this is
222 * less clear than it otherwise should be.
223 */
224
225 # userspace resumption stub bypassing syscall exit tracing
226 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200227 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228ret_from_exception:
229 preempt_stop
230ret_from_intr:
231 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700232check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100233 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
234 movb PT_CS(%esp), %al
Rusty Russell78be3702006-09-26 10:52:39 +0200235 andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
236 cmpl $USER_RPL, %eax
237 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239ENTRY(resume_userspace)
Rusty Russell0da5db32006-09-26 10:52:39 +0200240 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 # setting need_resched or sigpending
242 # between sampling and the iret
243 movl TI_flags(%ebp), %ecx
244 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
245 # int/exception return?
246 jne work_pending
247 jmp restore_all
248
249#ifdef CONFIG_PREEMPT
250ENTRY(resume_kernel)
Rusty Russell0da5db32006-09-26 10:52:39 +0200251 DISABLE_INTERRUPTS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
253 jnz restore_nocheck
254need_resched:
255 movl TI_flags(%ebp), %ecx # need_resched set ?
256 testb $_TIF_NEED_RESCHED, %cl
257 jz restore_all
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100258 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 jz restore_all
260 call preempt_schedule_irq
261 jmp need_resched
262#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200263 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265/* SYSENTER_RETURN points to after the "sysenter" instruction in
266 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
267
268 # sysenter call handler stub
269ENTRY(sysenter_entry)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200270 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200271 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200272 CFI_DEF_CFA esp, 0
273 CFI_REGISTER esp, ebp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 movl TSS_sysenter_esp0(%esp),%esp
275sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700276 /*
277 * No need to follow this irqs on/off section: the syscall
278 * disabled irqs and here we enable it straight after entry:
279 */
Rusty Russell0da5db32006-09-26 10:52:39 +0200280 ENABLE_INTERRUPTS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200282 CFI_ADJUST_CFA_OFFSET 4
283 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200285 CFI_ADJUST_CFA_OFFSET 4
286 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 pushfl
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200288 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200290 CFI_ADJUST_CFA_OFFSET 4
291 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700292 /*
293 * Push current_thread_info()->sysenter_return to the stack.
294 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
295 * pushed above; +8 corresponds to copy_thread's esp0 setting.
296 */
297 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200298 CFI_ADJUST_CFA_OFFSET 4
299 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301/*
302 * Load the potential sixth argument from user stack.
303 * Careful about security.
304 */
305 cmpl $__PAGE_OFFSET-3,%ebp
306 jae syscall_fault
3071: movl (%ebp),%ebp
308.section __ex_table,"a"
309 .align 4
310 .long 1b,syscall_fault
311.previous
312
313 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200314 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 SAVE_ALL
316 GET_THREAD_INFO(%ebp)
317
318 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700319 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 jnz syscall_trace_entry
321 cmpl $(nr_syscalls), %eax
322 jae syscall_badsys
323 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100324 movl %eax,PT_EAX(%esp)
Rusty Russell0da5db32006-09-26 10:52:39 +0200325 DISABLE_INTERRUPTS
Ingo Molnar55f327f2006-07-03 00:24:43 -0700326 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 movl TI_flags(%ebp), %ecx
328 testw $_TIF_ALLWORK_MASK, %cx
329 jne syscall_exit_work
330/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100331 movl PT_EIP(%esp), %edx
332 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700334 TRACE_IRQS_ON
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +01003351: mov PT_GS(%esp), %gs
Rusty Russell0da5db32006-09-26 10:52:39 +0200336 ENABLE_INTERRUPTS_SYSEXIT
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200337 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100338.pushsection .fixup,"ax"
3392: movl $0,PT_GS(%esp)
340 jmp 1b
341.section __ex_table,"a"
342 .align 4
343 .long 1b,2b
344.popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 # system call handler stub
347ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200348 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200350 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 SAVE_ALL
352 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100353 testl $TF_MASK,PT_EFLAGS(%esp)
Chuck Ebbert635cf992006-03-23 02:59:48 -0800354 jz no_singlestep
355 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
356no_singlestep:
Laurent Viviered75e8d2005-09-03 15:57:18 -0700357 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700359 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 jnz syscall_trace_entry
361 cmpl $(nr_syscalls), %eax
362 jae syscall_badsys
363syscall_call:
364 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100365 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366syscall_exit:
Rusty Russell0da5db32006-09-26 10:52:39 +0200367 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 # setting need_resched or sigpending
369 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700370 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 movl TI_flags(%ebp), %ecx
372 testw $_TIF_ALLWORK_MASK, %cx # current->work
373 jne syscall_exit_work
374
375restore_all:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100376 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
377 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700378 # are returning to the kernel.
379 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100380 movb PT_OLDSS(%esp), %ah
381 movb PT_CS(%esp), %al
Rusty Russell78be3702006-09-26 10:52:39 +0200382 andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
383 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200384 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 je ldt_ss # returning to user-space with LDT SS
386restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700387 TRACE_IRQS_IRET
388restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 RESTORE_REGS
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100390 addl $4, %esp # skip orig_eax/error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200391 CFI_ADJUST_CFA_OFFSET -4
Rusty Russell0da5db32006-09-26 10:52:39 +02003921: INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393.section .fixup,"ax"
394iret_exc:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700395 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200396 ENABLE_INTERRUPTS
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700397 pushl $0 # no error code
398 pushl $do_iret_error
399 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400.previous
401.section __ex_table,"a"
402 .align 4
403 .long 1b,iret_exc
404.previous
405
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200406 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100408 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 jnz restore_nocheck
410 testl $0x00400000, %eax # returning to 32bit stack?
411 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100412
413#ifdef CONFIG_PARAVIRT
414 /*
415 * The kernel can't run on a non-flat stack if paravirt mode
416 * is active. Rather than try to fixup the high bits of
417 * ESP, bypass this code entirely. This may break DOSemu
418 * and/or Wine support in a paravirt VM, although the option
419 * is still available to implement the setting of the high
420 * 16-bits in the INTERRUPT_RETURN paravirt-op.
421 */
422 cmpl $0, paravirt_ops+PARAVIRT_enabled
423 jne restore_nocheck
424#endif
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /* If returning to userspace with 16bit stack,
427 * try to fix the higher word of ESP, as the CPU
428 * won't restore it.
429 * This is an "official" bug of all the x86-compatible
430 * CPUs, which we can try to work around to make
431 * dosemu and wine happy. */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100432 movl PT_OLDESP(%esp), %eax
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100433 movl %esp, %edx
434 call patch_espfix_desc
435 pushl $__ESPFIX_SS
436 CFI_ADJUST_CFA_OFFSET 4
437 pushl %eax
438 CFI_ADJUST_CFA_OFFSET 4
Rusty Russell0da5db32006-09-26 10:52:39 +0200439 DISABLE_INTERRUPTS
Ingo Molnar55f327f2006-07-03 00:24:43 -0700440 TRACE_IRQS_OFF
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100441 lss (%esp), %esp
442 CFI_ADJUST_CFA_OFFSET -8
443 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200444 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 # perform work that needs to be done immediately before resumption
447 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200448 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449work_pending:
450 testb $_TIF_NEED_RESCHED, %cl
451 jz work_notifysig
452work_resched:
453 call schedule
Rusty Russell0da5db32006-09-26 10:52:39 +0200454 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 # setting need_resched or sigpending
456 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700457 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 movl TI_flags(%ebp), %ecx
459 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
460 # than syscall tracing?
461 jz restore_all
462 testb $_TIF_NEED_RESCHED, %cl
463 jnz work_resched
464
465work_notifysig: # deal with pending signals and
466 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100467#ifdef CONFIG_VM86
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100468 testl $VM_MASK, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 movl %esp, %eax
470 jne work_notifysig_v86 # returning to kernel-space or
471 # vm86-space
472 xorl %edx, %edx
473 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700474 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 ALIGN
477work_notifysig_v86:
478 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200479 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 call save_v86_state # %eax contains pt_regs pointer
481 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200482 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100484#else
485 movl %esp, %eax
486#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 xorl %edx, %edx
488 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700489 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 # perform syscall exit tracing
492 ALIGN
493syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100494 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 movl %esp, %eax
496 xorl %edx,%edx
497 call do_syscall_trace
Laurent Viviered75e8d2005-09-03 15:57:18 -0700498 cmpl $0, %eax
Paolo 'Blaisorblade' Giarrusso640aa462005-09-03 15:57:22 -0700499 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
Laurent Viviered75e8d2005-09-03 15:57:18 -0700500 # so must skip actual syscall
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100501 movl PT_ORIG_EAX(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 cmpl $(nr_syscalls), %eax
503 jnae syscall_call
504 jmp syscall_exit
505
506 # perform syscall exit tracing
507 ALIGN
508syscall_exit_work:
509 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
510 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700511 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200512 ENABLE_INTERRUPTS # could let do_syscall_trace() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 # schedule() instead
514 movl %esp, %eax
515 movl $1, %edx
516 call do_syscall_trace
517 jmp resume_userspace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200518 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200520 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521syscall_fault:
522 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200523 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 SAVE_ALL
525 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100526 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 jmp resume_userspace
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100530 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 jmp resume_userspace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200532 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534#define FIXUP_ESPFIX_STACK \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100535 /* since we are on a wrong stack, we cant make it a C code :( */ \
Jeremy Fitzhardingeb2938f82006-12-07 02:14:03 +0100536 movl %gs:PDA_cpu, %ebx; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100537 PER_CPU(cpu_gdt_descr, %ebx); \
538 movl GDS_address(%ebx), %ebx; \
539 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
540 addl %esp, %eax; \
541 pushl $__KERNEL_DS; \
542 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200544 CFI_ADJUST_CFA_OFFSET 4; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100545 lss (%esp), %esp; \
546 CFI_ADJUST_CFA_OFFSET -8;
547#define UNWIND_ESPFIX_STACK \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 movl %ss, %eax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100549 /* see if on espfix stack */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 cmpw $__ESPFIX_SS, %ax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100551 jne 27f; \
552 movl $__KERNEL_DS, %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200553 movl %eax, %ds; \
554 movl %eax, %es; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100555 /* switch to normal stack */ \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200556 FIXUP_ESPFIX_STACK; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010055727:;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559/*
560 * Build the entry stubs and pointer table with
561 * some assembler magic.
562 */
563.data
564ENTRY(interrupt)
565.text
566
567vector=0
568ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200569 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570.rept NR_IRQS
571 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200572 .if vector
573 CFI_ADJUST_CFA_OFFSET -4
574 .endif
Rusty Russell19eadf92006-06-27 02:53:44 -07005751: pushl $~(vector)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200576 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 jmp common_interrupt
578.data
579 .long 1b
580.text
581vector=vector+1
582.endr
583
Ingo Molnar55f327f2006-07-03 00:24:43 -0700584/*
585 * the CPU automatically disables interrupts when executing an IRQ vector,
586 * so IRQ-flags tracing has to follow that:
587 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 ALIGN
589common_interrupt:
590 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700591 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 movl %esp,%eax
593 call do_IRQ
594 jmp ret_from_intr
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200595 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597#define BUILD_INTERRUPT(name, nr) \
598ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200599 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700600 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200601 CFI_ADJUST_CFA_OFFSET 4; \
602 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700603 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 movl %esp,%eax; \
605 call smp_/**/name; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700606 jmp ret_from_intr; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200607 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609/* The include is where all of the SMP etc. interrupts come from */
610#include "entry_arch.h"
611
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200612KPROBE_ENTRY(page_fault)
613 RING0_EC_FRAME
614 pushl $do_page_fault
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200615 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 ALIGN
617error_code:
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100618 /* the function address is in %gs's slot on the stack */
619 pushl %es
620 CFI_ADJUST_CFA_OFFSET 4
621 /*CFI_REL_OFFSET es, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 pushl %ds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200623 CFI_ADJUST_CFA_OFFSET 4
624 /*CFI_REL_OFFSET ds, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200626 CFI_ADJUST_CFA_OFFSET 4
627 CFI_REL_OFFSET eax, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200629 CFI_ADJUST_CFA_OFFSET 4
630 CFI_REL_OFFSET ebp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 pushl %edi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200632 CFI_ADJUST_CFA_OFFSET 4
633 CFI_REL_OFFSET edi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 pushl %esi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200635 CFI_ADJUST_CFA_OFFSET 4
636 CFI_REL_OFFSET esi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 pushl %edx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200638 CFI_ADJUST_CFA_OFFSET 4
639 CFI_REL_OFFSET edx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 pushl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200641 CFI_ADJUST_CFA_OFFSET 4
642 CFI_REL_OFFSET ecx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 pushl %ebx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200644 CFI_ADJUST_CFA_OFFSET 4
645 CFI_REL_OFFSET ebx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 cld
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100647 pushl %gs
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200648 CFI_ADJUST_CFA_OFFSET 4
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100649 /*CFI_REL_OFFSET gs, 0*/
650 movl $(__KERNEL_PDA), %ecx
651 movl %ecx, %gs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 UNWIND_ESPFIX_STACK
653 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200654 CFI_ADJUST_CFA_OFFSET -4
655 /*CFI_REGISTER es, ecx*/
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100656 movl PT_GS(%esp), %edi # get the function address
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100657 movl PT_ORIG_EAX(%esp), %edx # get the error code
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100658 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
659 mov %ecx, PT_GS(%esp)
660 /*CFI_REL_OFFSET gs, ES*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 movl $(__USER_DS), %ecx
662 movl %ecx, %ds
663 movl %ecx, %es
664 movl %esp,%eax # pt_regs pointer
665 call *%edi
666 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200667 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200668KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200671 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200673 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200675 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200677 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200680 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200682 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200684 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200686 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200689 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200691 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 SAVE_ALL
Rusty Russell0da5db32006-09-26 10:52:39 +0200693 GET_CR0_INTO_EAX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 testl $0x4, %eax # EM (math emulation bit)
695 jne device_not_available_emulate
696 preempt_stop
697 call math_state_restore
698 jmp ret_from_exception
699device_not_available_emulate:
700 pushl $0 # temporary storage for ORIG_EIP
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200701 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 call math_emulate
703 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200704 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200706 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
708/*
709 * Debug traps and NMI can happen at the one SYSENTER instruction
710 * that sets up the real kernel stack. Check here, since we can't
711 * allow the wrong stack to be used.
712 *
713 * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
714 * already pushed 3 words if it hits on the sysenter instruction:
715 * eflags, cs and eip.
716 *
717 * We just load the right stack, and push the three (known) values
718 * by hand onto the new stack - while updating the return eip past
719 * the instruction that would have done it for sysenter.
720 */
721#define FIX_STACK(offset, ok, label) \
722 cmpw $__KERNEL_CS,4(%esp); \
723 jne ok; \
724label: \
725 movl TSS_sysenter_esp0+offset(%esp),%esp; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200726 CFI_DEF_CFA esp, 0; \
727 CFI_UNDEFINED eip; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 pushfl; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200729 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 pushl $__KERNEL_CS; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200731 CFI_ADJUST_CFA_OFFSET 4; \
732 pushl $sysenter_past_esp; \
733 CFI_ADJUST_CFA_OFFSET 4; \
734 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700736KPROBE_ENTRY(debug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200737 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 cmpl $sysenter_entry,(%esp)
739 jne debug_stack_correct
740 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
741debug_stack_correct:
742 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200743 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 SAVE_ALL
745 xorl %edx,%edx # error code 0
746 movl %esp,%eax # pt_regs pointer
747 call do_debug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200749 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200750KPROBE_END(debug)
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752/*
753 * NMI is doubly nasty. It can happen _while_ we're handling
754 * a debug fault, and the debug fault hasn't yet been able to
755 * clear up the stack. So we first check whether we got an
756 * NMI on the sysenter entry path, but after that we need to
757 * check whether we got an NMI on the debug path where the debug
758 * fault happened on the sysenter path.
759 */
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200760KPROBE_ENTRY(nmi)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200761 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200763 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 movl %ss, %eax
765 cmpw $__ESPFIX_SS, %ax
766 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200767 CFI_ADJUST_CFA_OFFSET -4
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100768 je nmi_espfix_stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 cmpl $sysenter_entry,(%esp)
770 je nmi_stack_fixup
771 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200772 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 movl %esp,%eax
774 /* Do not access memory above the end of our stack page,
775 * it might not exist.
776 */
777 andl $(THREAD_SIZE-1),%eax
778 cmpl $(THREAD_SIZE-20),%eax
779 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200780 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 jae nmi_stack_correct
782 cmpl $sysenter_entry,12(%esp)
783 je nmi_debug_stack_check
784nmi_stack_correct:
Chuck Ebberta549b862006-09-26 10:52:37 +0200785 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200787 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 SAVE_ALL
789 xorl %edx,%edx # zero error code
790 movl %esp,%eax # pt_regs pointer
791 call do_nmi
Ingo Molnar55f327f2006-07-03 00:24:43 -0700792 jmp restore_nocheck_notrace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200793 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795nmi_stack_fixup:
Chuck Ebberta549b862006-09-26 10:52:37 +0200796 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 FIX_STACK(12,nmi_stack_correct, 1)
798 jmp nmi_stack_correct
Chuck Ebberta549b862006-09-26 10:52:37 +0200799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800nmi_debug_stack_check:
Chuck Ebberta549b862006-09-26 10:52:37 +0200801 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 cmpw $__KERNEL_CS,16(%esp)
803 jne nmi_stack_correct
Jan Beuliche2718202005-11-13 16:06:52 -0800804 cmpl $debug,(%esp)
805 jb nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 cmpl $debug_esp_fix_insn,(%esp)
Jan Beuliche2718202005-11-13 16:06:52 -0800807 ja nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 FIX_STACK(24,nmi_stack_correct, 1)
809 jmp nmi_stack_correct
810
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100811nmi_espfix_stack:
Chuck Ebberta549b862006-09-26 10:52:37 +0200812 /* We have a RING0_INT_FRAME here.
813 *
814 * create the pointer to lss back
815 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 pushl %ss
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200817 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 pushl %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200819 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 addw $4, (%esp)
821 /* copy the iret frame of 12 bytes */
822 .rept 3
823 pushl 16(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200824 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 .endr
826 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200827 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 SAVE_ALL
829 FIXUP_ESPFIX_STACK # %eax == %esp
830 xorl %edx,%edx # zero error code
831 call do_nmi
832 RESTORE_REGS
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100833 lss 12+4(%esp), %esp # back to espfix stack
834 CFI_ADJUST_CFA_OFFSET -24
Rusty Russell0da5db32006-09-26 10:52:39 +02008351: INTERRUPT_RETURN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200836 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837.section __ex_table,"a"
838 .align 4
839 .long 1b,iret_exc
840.previous
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200841KPROBE_END(nmi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Rusty Russelld3561b72006-12-07 02:14:07 +0100843#ifdef CONFIG_PARAVIRT
844ENTRY(native_iret)
8451: iret
846.section __ex_table,"a"
847 .align 4
848 .long 1b,iret_exc
849.previous
850
851ENTRY(native_irq_enable_sysexit)
852 sti
853 sysexit
854#endif
855
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700856KPROBE_ENTRY(int3)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200857 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200859 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 SAVE_ALL
861 xorl %edx,%edx # zero error code
862 movl %esp,%eax # pt_regs pointer
863 call do_int3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200865 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200866KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200869 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200871 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 pushl $do_overflow
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200873 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200875 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200878 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200880 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 pushl $do_bounds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200882 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200884 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200887 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200889 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 pushl $do_invalid_op
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200893 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200896 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200898 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 pushl $do_coprocessor_segment_overrun
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200900 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200902 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200905 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 pushl $do_invalid_TSS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200907 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200909 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200912 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 pushl $do_segment_not_present
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200914 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200916 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200919 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 pushl $do_stack_segment
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200921 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200923 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700925KPROBE_ENTRY(general_protection)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200926 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 pushl $do_general_protection
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200928 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200930 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200931KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200934 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200936 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200938 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200940ENTRY(divide_error)
941 RING0_INT_FRAME
942 pushl $0 # no error code
943 CFI_ADJUST_CFA_OFFSET 4
944 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200945 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200947 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949#ifdef CONFIG_X86_MCE
950ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200951 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200953 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200955 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200957 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958#endif
959
960ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200961 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200963 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200965 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200967 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Jan Beulich176a2712006-06-26 13:57:41 +0200969#ifdef CONFIG_STACK_UNWIND
970ENTRY(arch_unwind_init_running)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200971 CFI_STARTPROC
Jan Beulich176a2712006-06-26 13:57:41 +0200972 movl 4(%esp), %edx
973 movl (%esp), %ecx
974 leal 4(%esp), %eax
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100975 movl %ebx, PT_EBX(%edx)
Jan Beulich176a2712006-06-26 13:57:41 +0200976 xorl %ebx, %ebx
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100977 movl %ebx, PT_ECX(%edx)
978 movl %ebx, PT_EDX(%edx)
979 movl %esi, PT_ESI(%edx)
980 movl %edi, PT_EDI(%edx)
981 movl %ebp, PT_EBP(%edx)
982 movl %ebx, PT_EAX(%edx)
983 movl $__USER_DS, PT_DS(%edx)
984 movl $__USER_DS, PT_ES(%edx)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100985 movl $0, PT_GS(%edx)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100986 movl %ebx, PT_ORIG_EAX(%edx)
987 movl %ecx, PT_EIP(%edx)
Jan Beulich176a2712006-06-26 13:57:41 +0200988 movl 12(%esp), %ecx
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100989 movl $__KERNEL_CS, PT_CS(%edx)
990 movl %ebx, PT_EFLAGS(%edx)
991 movl %eax, PT_OLDESP(%edx)
Jan Beulich176a2712006-06-26 13:57:41 +0200992 movl 8(%esp), %eax
993 movl %ecx, 8(%esp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100994 movl PT_EBX(%edx), %ebx
995 movl $__KERNEL_DS, PT_OLDSS(%edx)
Jan Beulich176a2712006-06-26 13:57:41 +0200996 jmpl *%eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200997 CFI_ENDPROC
Jan Beulich176a2712006-06-26 13:57:41 +0200998ENDPROC(arch_unwind_init_running)
999#endif
1000
Andi Kleen02ba1a32006-09-26 10:52:35 +02001001ENTRY(kernel_thread_helper)
1002 pushl $0 # fake return address for unwinder
1003 CFI_STARTPROC
1004 movl %edx,%eax
1005 push %edx
1006 CFI_ADJUST_CFA_OFFSET 4
1007 call *%ebx
1008 push %eax
1009 CFI_ADJUST_CFA_OFFSET 4
1010 call do_exit
1011 CFI_ENDPROC
1012ENDPROC(kernel_thread_helper)
1013
Arjan van de Venbb152f52006-01-06 00:12:05 -08001014.section .rodata,"a"
Paolo 'Blaisorblade' Giarrusso5e7b83f2005-05-01 08:58:55 -07001015#include "syscall_table.S"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017syscall_table_size=(.-sys_call_table)