blob: 0069bf01603e2c8dc4821b71764720a881751953 [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
33 * 24(%esp) - orig_eax
34 * 28(%esp) - %eip
35 * 2C(%esp) - %cs
36 * 30(%esp) - %eflags
37 * 34(%esp) - %oldesp
38 * 38(%esp) - %oldss
39 *
40 * "current" is in register %ebx during any slow entries.
41 */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/linkage.h>
44#include <asm/thread_info.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070045#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/errno.h>
47#include <asm/segment.h>
48#include <asm/smp.h>
49#include <asm/page.h>
50#include <asm/desc.h>
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010051#include <asm/percpu.h>
Jan Beulichfe7cacc2006-06-26 13:57:44 +020052#include <asm/dwarf2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include "irq_vectors.h"
54
55#define nr_syscalls ((syscall_table_size)/4)
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057CF_MASK = 0x00000001
58TF_MASK = 0x00000100
59IF_MASK = 0x00000200
60DF_MASK = 0x00000400
61NT_MASK = 0x00004000
62VM_MASK = 0x00020000
63
Rusty Russell0da5db32006-09-26 10:52:39 +020064/* These are replaces for paravirtualization */
65#define DISABLE_INTERRUPTS cli
66#define ENABLE_INTERRUPTS sti
67#define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
68#define INTERRUPT_RETURN iret
69#define GET_CR0_INTO_EAX movl %cr0, %eax
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#ifdef CONFIG_PREEMPT
Rusty Russell0da5db32006-09-26 10:52:39 +020072#define preempt_stop DISABLE_INTERRUPTS; TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#else
74#define preempt_stop
75#define resume_kernel restore_nocheck
76#endif
77
Ingo Molnar55f327f2006-07-03 00:24:43 -070078.macro TRACE_IRQS_IRET
79#ifdef CONFIG_TRACE_IRQFLAGS
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +010080 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off?
Ingo Molnar55f327f2006-07-03 00:24:43 -070081 jz 1f
82 TRACE_IRQS_ON
831:
84#endif
85.endm
86
Aleksey Gorelov4031ff32006-06-27 02:53:48 -070087#ifdef CONFIG_VM86
88#define resume_userspace_sig check_userspace
89#else
90#define resume_userspace_sig resume_userspace
91#endif
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define SAVE_ALL \
94 cld; \
95 pushl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +020096 CFI_ADJUST_CFA_OFFSET 4;\
97 /*CFI_REL_OFFSET es, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 pushl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +020099 CFI_ADJUST_CFA_OFFSET 4;\
100 /*CFI_REL_OFFSET ds, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200102 CFI_ADJUST_CFA_OFFSET 4;\
103 CFI_REL_OFFSET eax, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 pushl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200105 CFI_ADJUST_CFA_OFFSET 4;\
106 CFI_REL_OFFSET ebp, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 pushl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200108 CFI_ADJUST_CFA_OFFSET 4;\
109 CFI_REL_OFFSET edi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 pushl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200111 CFI_ADJUST_CFA_OFFSET 4;\
112 CFI_REL_OFFSET esi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 pushl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200114 CFI_ADJUST_CFA_OFFSET 4;\
115 CFI_REL_OFFSET edx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 pushl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200117 CFI_ADJUST_CFA_OFFSET 4;\
118 CFI_REL_OFFSET ecx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 pushl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200120 CFI_ADJUST_CFA_OFFSET 4;\
121 CFI_REL_OFFSET ebx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 movl $(__USER_DS), %edx; \
123 movl %edx, %ds; \
124 movl %edx, %es;
125
126#define RESTORE_INT_REGS \
127 popl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200128 CFI_ADJUST_CFA_OFFSET -4;\
129 CFI_RESTORE ebx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 popl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200131 CFI_ADJUST_CFA_OFFSET -4;\
132 CFI_RESTORE ecx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 popl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200134 CFI_ADJUST_CFA_OFFSET -4;\
135 CFI_RESTORE edx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 popl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200137 CFI_ADJUST_CFA_OFFSET -4;\
138 CFI_RESTORE esi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 popl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200140 CFI_ADJUST_CFA_OFFSET -4;\
141 CFI_RESTORE edi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 popl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200143 CFI_ADJUST_CFA_OFFSET -4;\
144 CFI_RESTORE ebp;\
145 popl %eax; \
146 CFI_ADJUST_CFA_OFFSET -4;\
147 CFI_RESTORE eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149#define RESTORE_REGS \
150 RESTORE_INT_REGS; \
1511: popl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200152 CFI_ADJUST_CFA_OFFSET -4;\
153 /*CFI_RESTORE ds;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542: popl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200155 CFI_ADJUST_CFA_OFFSET -4;\
156 /*CFI_RESTORE es;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157.section .fixup,"ax"; \
1583: movl $0,(%esp); \
159 jmp 1b; \
1604: movl $0,(%esp); \
161 jmp 2b; \
162.previous; \
163.section __ex_table,"a";\
164 .align 4; \
165 .long 1b,3b; \
166 .long 2b,4b; \
167.previous
168
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200169#define RING0_INT_FRAME \
170 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200171 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200172 CFI_DEF_CFA esp, 3*4;\
173 /*CFI_OFFSET cs, -2*4;*/\
174 CFI_OFFSET eip, -3*4
175
176#define RING0_EC_FRAME \
177 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200178 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200179 CFI_DEF_CFA esp, 4*4;\
180 /*CFI_OFFSET cs, -2*4;*/\
181 CFI_OFFSET eip, -3*4
182
183#define RING0_PTREGS_FRAME \
184 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200185 CFI_SIGNAL_FRAME;\
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100186 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
187 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
188 CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
189 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
190 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
191 CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
192 CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
193 CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
194 CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
195 CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
196 CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
197 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200200 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 pushl %eax
Markus Armbruster25d7dfd2006-07-30 03:04:08 -0700202 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 call schedule_tail
204 GET_THREAD_INFO(%ebp)
205 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200206 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds47a5c6f2006-09-18 16:20:40 -0700207 pushl $0x0202 # Reset kernel eflags
208 CFI_ADJUST_CFA_OFFSET 4
209 popfl
210 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200212 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214/*
215 * Return to user mode is not as complex as all this looks,
216 * but we want the default path for a system call return to
217 * go as quickly as possible which is why some of this is
218 * less clear than it otherwise should be.
219 */
220
221 # userspace resumption stub bypassing syscall exit tracing
222 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200223 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224ret_from_exception:
225 preempt_stop
226ret_from_intr:
227 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700228check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100229 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
230 movb PT_CS(%esp), %al
Rusty Russell78be3702006-09-26 10:52:39 +0200231 andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
232 cmpl $USER_RPL, %eax
233 jb resume_kernel # not returning to v8086 or userspace
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234ENTRY(resume_userspace)
Rusty Russell0da5db32006-09-26 10:52:39 +0200235 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 # setting need_resched or sigpending
237 # between sampling and the iret
238 movl TI_flags(%ebp), %ecx
239 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
240 # int/exception return?
241 jne work_pending
242 jmp restore_all
243
244#ifdef CONFIG_PREEMPT
245ENTRY(resume_kernel)
Rusty Russell0da5db32006-09-26 10:52:39 +0200246 DISABLE_INTERRUPTS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
248 jnz restore_nocheck
249need_resched:
250 movl TI_flags(%ebp), %ecx # need_resched set ?
251 testb $_TIF_NEED_RESCHED, %cl
252 jz restore_all
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100253 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 jz restore_all
255 call preempt_schedule_irq
256 jmp need_resched
257#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200258 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260/* SYSENTER_RETURN points to after the "sysenter" instruction in
261 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
262
263 # sysenter call handler stub
264ENTRY(sysenter_entry)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200265 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200266 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200267 CFI_DEF_CFA esp, 0
268 CFI_REGISTER esp, ebp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 movl TSS_sysenter_esp0(%esp),%esp
270sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700271 /*
272 * No need to follow this irqs on/off section: the syscall
273 * disabled irqs and here we enable it straight after entry:
274 */
Rusty Russell0da5db32006-09-26 10:52:39 +0200275 ENABLE_INTERRUPTS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200277 CFI_ADJUST_CFA_OFFSET 4
278 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200280 CFI_ADJUST_CFA_OFFSET 4
281 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 pushfl
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200283 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200285 CFI_ADJUST_CFA_OFFSET 4
286 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700287 /*
288 * Push current_thread_info()->sysenter_return to the stack.
289 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
290 * pushed above; +8 corresponds to copy_thread's esp0 setting.
291 */
292 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200293 CFI_ADJUST_CFA_OFFSET 4
294 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296/*
297 * Load the potential sixth argument from user stack.
298 * Careful about security.
299 */
300 cmpl $__PAGE_OFFSET-3,%ebp
301 jae syscall_fault
3021: movl (%ebp),%ebp
303.section __ex_table,"a"
304 .align 4
305 .long 1b,syscall_fault
306.previous
307
308 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200309 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 SAVE_ALL
311 GET_THREAD_INFO(%ebp)
312
313 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700314 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 jnz syscall_trace_entry
316 cmpl $(nr_syscalls), %eax
317 jae syscall_badsys
318 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100319 movl %eax,PT_EAX(%esp)
Rusty Russell0da5db32006-09-26 10:52:39 +0200320 DISABLE_INTERRUPTS
Ingo Molnar55f327f2006-07-03 00:24:43 -0700321 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 movl TI_flags(%ebp), %ecx
323 testw $_TIF_ALLWORK_MASK, %cx
324 jne syscall_exit_work
325/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100326 movl PT_EIP(%esp), %edx
327 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700329 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200330 ENABLE_INTERRUPTS_SYSEXIT
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200331 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333
334 # system call handler stub
335ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200336 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200338 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 SAVE_ALL
340 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100341 testl $TF_MASK,PT_EFLAGS(%esp)
Chuck Ebbert635cf992006-03-23 02:59:48 -0800342 jz no_singlestep
343 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
344no_singlestep:
Laurent Viviered75e8d2005-09-03 15:57:18 -0700345 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700347 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 jnz syscall_trace_entry
349 cmpl $(nr_syscalls), %eax
350 jae syscall_badsys
351syscall_call:
352 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100353 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354syscall_exit:
Rusty Russell0da5db32006-09-26 10:52:39 +0200355 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 # setting need_resched or sigpending
357 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700358 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 movl TI_flags(%ebp), %ecx
360 testw $_TIF_ALLWORK_MASK, %cx # current->work
361 jne syscall_exit_work
362
363restore_all:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100364 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
365 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700366 # are returning to the kernel.
367 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100368 movb PT_OLDSS(%esp), %ah
369 movb PT_CS(%esp), %al
Rusty Russell78be3702006-09-26 10:52:39 +0200370 andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
371 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200372 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 je ldt_ss # returning to user-space with LDT SS
374restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700375 TRACE_IRQS_IRET
376restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 RESTORE_REGS
378 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200379 CFI_ADJUST_CFA_OFFSET -4
Rusty Russell0da5db32006-09-26 10:52:39 +02003801: INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381.section .fixup,"ax"
382iret_exc:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700383 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200384 ENABLE_INTERRUPTS
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700385 pushl $0 # no error code
386 pushl $do_iret_error
387 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388.previous
389.section __ex_table,"a"
390 .align 4
391 .long 1b,iret_exc
392.previous
393
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200394 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100396 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 jnz restore_nocheck
398 testl $0x00400000, %eax # returning to 32bit stack?
399 jnz restore_nocheck # allright, normal return
400 /* If returning to userspace with 16bit stack,
401 * try to fix the higher word of ESP, as the CPU
402 * won't restore it.
403 * This is an "official" bug of all the x86-compatible
404 * CPUs, which we can try to work around to make
405 * dosemu and wine happy. */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100406 movl PT_OLDESP(%esp), %eax
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100407 movl %esp, %edx
408 call patch_espfix_desc
409 pushl $__ESPFIX_SS
410 CFI_ADJUST_CFA_OFFSET 4
411 pushl %eax
412 CFI_ADJUST_CFA_OFFSET 4
Rusty Russell0da5db32006-09-26 10:52:39 +0200413 DISABLE_INTERRUPTS
Ingo Molnar55f327f2006-07-03 00:24:43 -0700414 TRACE_IRQS_OFF
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100415 lss (%esp), %esp
416 CFI_ADJUST_CFA_OFFSET -8
417 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200418 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 # perform work that needs to be done immediately before resumption
421 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200422 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423work_pending:
424 testb $_TIF_NEED_RESCHED, %cl
425 jz work_notifysig
426work_resched:
427 call schedule
Rusty Russell0da5db32006-09-26 10:52:39 +0200428 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 # setting need_resched or sigpending
430 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700431 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 movl TI_flags(%ebp), %ecx
433 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
434 # than syscall tracing?
435 jz restore_all
436 testb $_TIF_NEED_RESCHED, %cl
437 jnz work_resched
438
439work_notifysig: # deal with pending signals and
440 # notify-resume requests
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100441 testl $VM_MASK, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 movl %esp, %eax
443 jne work_notifysig_v86 # returning to kernel-space or
444 # vm86-space
445 xorl %edx, %edx
446 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700447 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 ALIGN
450work_notifysig_v86:
Matt Mackall64ca9002006-01-08 01:05:26 -0800451#ifdef CONFIG_VM86
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200453 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 call save_v86_state # %eax contains pt_regs pointer
455 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200456 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 movl %eax, %esp
458 xorl %edx, %edx
459 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700460 jmp resume_userspace_sig
Matt Mackall64ca9002006-01-08 01:05:26 -0800461#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 # perform syscall exit tracing
464 ALIGN
465syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100466 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 movl %esp, %eax
468 xorl %edx,%edx
469 call do_syscall_trace
Laurent Viviered75e8d2005-09-03 15:57:18 -0700470 cmpl $0, %eax
Paolo 'Blaisorblade' Giarrusso640aa462005-09-03 15:57:22 -0700471 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
Laurent Viviered75e8d2005-09-03 15:57:18 -0700472 # so must skip actual syscall
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100473 movl PT_ORIG_EAX(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 cmpl $(nr_syscalls), %eax
475 jnae syscall_call
476 jmp syscall_exit
477
478 # perform syscall exit tracing
479 ALIGN
480syscall_exit_work:
481 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
482 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700483 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200484 ENABLE_INTERRUPTS # could let do_syscall_trace() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 # schedule() instead
486 movl %esp, %eax
487 movl $1, %edx
488 call do_syscall_trace
489 jmp resume_userspace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200490 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200492 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493syscall_fault:
494 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200495 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 SAVE_ALL
497 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100498 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 jmp resume_userspace
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100502 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 jmp resume_userspace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200504 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506#define FIXUP_ESPFIX_STACK \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100507 /* since we are on a wrong stack, we cant make it a C code :( */ \
508 GET_THREAD_INFO(%ebp); \
509 movl TI_cpu(%ebp), %ebx; \
510 PER_CPU(cpu_gdt_descr, %ebx); \
511 movl GDS_address(%ebx), %ebx; \
512 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
513 addl %esp, %eax; \
514 pushl $__KERNEL_DS; \
515 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200517 CFI_ADJUST_CFA_OFFSET 4; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100518 lss (%esp), %esp; \
519 CFI_ADJUST_CFA_OFFSET -8;
520#define UNWIND_ESPFIX_STACK \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 movl %ss, %eax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100522 /* see if on espfix stack */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 cmpw $__ESPFIX_SS, %ax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100524 jne 27f; \
525 movl $__KERNEL_DS, %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200526 movl %eax, %ds; \
527 movl %eax, %es; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100528 /* switch to normal stack */ \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200529 FIXUP_ESPFIX_STACK; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010053027:;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532/*
533 * Build the entry stubs and pointer table with
534 * some assembler magic.
535 */
536.data
537ENTRY(interrupt)
538.text
539
540vector=0
541ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200542 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543.rept NR_IRQS
544 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200545 .if vector
546 CFI_ADJUST_CFA_OFFSET -4
547 .endif
Rusty Russell19eadf92006-06-27 02:53:44 -07005481: pushl $~(vector)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200549 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 jmp common_interrupt
551.data
552 .long 1b
553.text
554vector=vector+1
555.endr
556
Ingo Molnar55f327f2006-07-03 00:24:43 -0700557/*
558 * the CPU automatically disables interrupts when executing an IRQ vector,
559 * so IRQ-flags tracing has to follow that:
560 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 ALIGN
562common_interrupt:
563 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700564 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 movl %esp,%eax
566 call do_IRQ
567 jmp ret_from_intr
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200568 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570#define BUILD_INTERRUPT(name, nr) \
571ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200572 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700573 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200574 CFI_ADJUST_CFA_OFFSET 4; \
575 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700576 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 movl %esp,%eax; \
578 call smp_/**/name; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700579 jmp ret_from_intr; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200580 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582/* The include is where all of the SMP etc. interrupts come from */
583#include "entry_arch.h"
584
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200585KPROBE_ENTRY(page_fault)
586 RING0_EC_FRAME
587 pushl $do_page_fault
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200588 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 ALIGN
590error_code:
591 pushl %ds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200592 CFI_ADJUST_CFA_OFFSET 4
593 /*CFI_REL_OFFSET ds, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200595 CFI_ADJUST_CFA_OFFSET 4
596 CFI_REL_OFFSET eax, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200598 CFI_ADJUST_CFA_OFFSET 4
599 CFI_REL_OFFSET ebp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 pushl %edi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200601 CFI_ADJUST_CFA_OFFSET 4
602 CFI_REL_OFFSET edi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 pushl %esi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200604 CFI_ADJUST_CFA_OFFSET 4
605 CFI_REL_OFFSET esi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 pushl %edx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200607 CFI_ADJUST_CFA_OFFSET 4
608 CFI_REL_OFFSET edx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 pushl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200610 CFI_ADJUST_CFA_OFFSET 4
611 CFI_REL_OFFSET ecx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 pushl %ebx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200613 CFI_ADJUST_CFA_OFFSET 4
614 CFI_REL_OFFSET ebx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 cld
616 pushl %es
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200617 CFI_ADJUST_CFA_OFFSET 4
618 /*CFI_REL_OFFSET es, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 UNWIND_ESPFIX_STACK
620 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200621 CFI_ADJUST_CFA_OFFSET -4
622 /*CFI_REGISTER es, ecx*/
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100623 movl PT_ES(%esp), %edi # get the function address
624 movl PT_ORIG_EAX(%esp), %edx # get the error code
625 movl $-1, PT_ORIG_EAX(%esp)
626 movl %ecx, PT_ES(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200627 /*CFI_REL_OFFSET es, ES*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 movl $(__USER_DS), %ecx
629 movl %ecx, %ds
630 movl %ecx, %es
631 movl %esp,%eax # pt_regs pointer
632 call *%edi
633 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200634 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200635KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200638 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200640 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200642 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200644 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200647 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200649 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200651 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200653 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200656 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200658 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 SAVE_ALL
Rusty Russell0da5db32006-09-26 10:52:39 +0200660 GET_CR0_INTO_EAX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 testl $0x4, %eax # EM (math emulation bit)
662 jne device_not_available_emulate
663 preempt_stop
664 call math_state_restore
665 jmp ret_from_exception
666device_not_available_emulate:
667 pushl $0 # temporary storage for ORIG_EIP
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200668 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 call math_emulate
670 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200671 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200673 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675/*
676 * Debug traps and NMI can happen at the one SYSENTER instruction
677 * that sets up the real kernel stack. Check here, since we can't
678 * allow the wrong stack to be used.
679 *
680 * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
681 * already pushed 3 words if it hits on the sysenter instruction:
682 * eflags, cs and eip.
683 *
684 * We just load the right stack, and push the three (known) values
685 * by hand onto the new stack - while updating the return eip past
686 * the instruction that would have done it for sysenter.
687 */
688#define FIX_STACK(offset, ok, label) \
689 cmpw $__KERNEL_CS,4(%esp); \
690 jne ok; \
691label: \
692 movl TSS_sysenter_esp0+offset(%esp),%esp; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200693 CFI_DEF_CFA esp, 0; \
694 CFI_UNDEFINED eip; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 pushfl; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200696 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 pushl $__KERNEL_CS; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200698 CFI_ADJUST_CFA_OFFSET 4; \
699 pushl $sysenter_past_esp; \
700 CFI_ADJUST_CFA_OFFSET 4; \
701 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700703KPROBE_ENTRY(debug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200704 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 cmpl $sysenter_entry,(%esp)
706 jne debug_stack_correct
707 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
708debug_stack_correct:
709 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200710 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 SAVE_ALL
712 xorl %edx,%edx # error code 0
713 movl %esp,%eax # pt_regs pointer
714 call do_debug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200716 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200717KPROBE_END(debug)
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719/*
720 * NMI is doubly nasty. It can happen _while_ we're handling
721 * a debug fault, and the debug fault hasn't yet been able to
722 * clear up the stack. So we first check whether we got an
723 * NMI on the sysenter entry path, but after that we need to
724 * check whether we got an NMI on the debug path where the debug
725 * fault happened on the sysenter path.
726 */
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200727KPROBE_ENTRY(nmi)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200728 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200730 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 movl %ss, %eax
732 cmpw $__ESPFIX_SS, %ax
733 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200734 CFI_ADJUST_CFA_OFFSET -4
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100735 je nmi_espfix_stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 cmpl $sysenter_entry,(%esp)
737 je nmi_stack_fixup
738 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200739 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 movl %esp,%eax
741 /* Do not access memory above the end of our stack page,
742 * it might not exist.
743 */
744 andl $(THREAD_SIZE-1),%eax
745 cmpl $(THREAD_SIZE-20),%eax
746 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200747 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 jae nmi_stack_correct
749 cmpl $sysenter_entry,12(%esp)
750 je nmi_debug_stack_check
751nmi_stack_correct:
Chuck Ebberta549b862006-09-26 10:52:37 +0200752 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200754 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 SAVE_ALL
756 xorl %edx,%edx # zero error code
757 movl %esp,%eax # pt_regs pointer
758 call do_nmi
Ingo Molnar55f327f2006-07-03 00:24:43 -0700759 jmp restore_nocheck_notrace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200760 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762nmi_stack_fixup:
Chuck Ebberta549b862006-09-26 10:52:37 +0200763 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 FIX_STACK(12,nmi_stack_correct, 1)
765 jmp nmi_stack_correct
Chuck Ebberta549b862006-09-26 10:52:37 +0200766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767nmi_debug_stack_check:
Chuck Ebberta549b862006-09-26 10:52:37 +0200768 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 cmpw $__KERNEL_CS,16(%esp)
770 jne nmi_stack_correct
Jan Beuliche2718202005-11-13 16:06:52 -0800771 cmpl $debug,(%esp)
772 jb nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 cmpl $debug_esp_fix_insn,(%esp)
Jan Beuliche2718202005-11-13 16:06:52 -0800774 ja nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 FIX_STACK(24,nmi_stack_correct, 1)
776 jmp nmi_stack_correct
777
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100778nmi_espfix_stack:
Chuck Ebberta549b862006-09-26 10:52:37 +0200779 /* We have a RING0_INT_FRAME here.
780 *
781 * create the pointer to lss back
782 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 pushl %ss
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200784 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 pushl %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200786 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 addw $4, (%esp)
788 /* copy the iret frame of 12 bytes */
789 .rept 3
790 pushl 16(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200791 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .endr
793 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200794 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 SAVE_ALL
796 FIXUP_ESPFIX_STACK # %eax == %esp
797 xorl %edx,%edx # zero error code
798 call do_nmi
799 RESTORE_REGS
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100800 lss 12+4(%esp), %esp # back to espfix stack
801 CFI_ADJUST_CFA_OFFSET -24
Rusty Russell0da5db32006-09-26 10:52:39 +02008021: INTERRUPT_RETURN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200803 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804.section __ex_table,"a"
805 .align 4
806 .long 1b,iret_exc
807.previous
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200808KPROBE_END(nmi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700810KPROBE_ENTRY(int3)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200811 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200813 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 SAVE_ALL
815 xorl %edx,%edx # zero error code
816 movl %esp,%eax # pt_regs pointer
817 call do_int3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200819 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200820KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200823 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200825 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 pushl $do_overflow
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200827 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200829 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200832 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200834 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 pushl $do_bounds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200836 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200838 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200841 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200843 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 pushl $do_invalid_op
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200845 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200847 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200850 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200852 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 pushl $do_coprocessor_segment_overrun
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200854 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200856 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200859 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 pushl $do_invalid_TSS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200861 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200863 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200866 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 pushl $do_segment_not_present
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200868 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200870 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200873 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 pushl $do_stack_segment
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200875 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200877 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700879KPROBE_ENTRY(general_protection)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200880 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 pushl $do_general_protection
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
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200885KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200888 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200890 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200892 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200894ENTRY(divide_error)
895 RING0_INT_FRAME
896 pushl $0 # no error code
897 CFI_ADJUST_CFA_OFFSET 4
898 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200899 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200901 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903#ifdef CONFIG_X86_MCE
904ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200905 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200907 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200909 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200911 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912#endif
913
914ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200915 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200917 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200919 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200921 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
Jan Beulich176a2712006-06-26 13:57:41 +0200923#ifdef CONFIG_STACK_UNWIND
924ENTRY(arch_unwind_init_running)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200925 CFI_STARTPROC
Jan Beulich176a2712006-06-26 13:57:41 +0200926 movl 4(%esp), %edx
927 movl (%esp), %ecx
928 leal 4(%esp), %eax
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100929 movl %ebx, PT_EBX(%edx)
Jan Beulich176a2712006-06-26 13:57:41 +0200930 xorl %ebx, %ebx
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100931 movl %ebx, PT_ECX(%edx)
932 movl %ebx, PT_EDX(%edx)
933 movl %esi, PT_ESI(%edx)
934 movl %edi, PT_EDI(%edx)
935 movl %ebp, PT_EBP(%edx)
936 movl %ebx, PT_EAX(%edx)
937 movl $__USER_DS, PT_DS(%edx)
938 movl $__USER_DS, PT_ES(%edx)
939 movl %ebx, PT_ORIG_EAX(%edx)
940 movl %ecx, PT_EIP(%edx)
Jan Beulich176a2712006-06-26 13:57:41 +0200941 movl 12(%esp), %ecx
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100942 movl $__KERNEL_CS, PT_CS(%edx)
943 movl %ebx, PT_EFLAGS(%edx)
944 movl %eax, PT_OLDESP(%edx)
Jan Beulich176a2712006-06-26 13:57:41 +0200945 movl 8(%esp), %eax
946 movl %ecx, 8(%esp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100947 movl PT_EBX(%edx), %ebx
948 movl $__KERNEL_DS, PT_OLDSS(%edx)
Jan Beulich176a2712006-06-26 13:57:41 +0200949 jmpl *%eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200950 CFI_ENDPROC
Jan Beulich176a2712006-06-26 13:57:41 +0200951ENDPROC(arch_unwind_init_running)
952#endif
953
Andi Kleen02ba1a32006-09-26 10:52:35 +0200954ENTRY(kernel_thread_helper)
955 pushl $0 # fake return address for unwinder
956 CFI_STARTPROC
957 movl %edx,%eax
958 push %edx
959 CFI_ADJUST_CFA_OFFSET 4
960 call *%ebx
961 push %eax
962 CFI_ADJUST_CFA_OFFSET 4
963 call do_exit
964 CFI_ENDPROC
965ENDPROC(kernel_thread_helper)
966
Arjan van de Venbb152f52006-01-06 00:12:05 -0800967.section .rodata,"a"
Paolo 'Blaisorblade' Giarrusso5e7b83f2005-05-01 08:58:55 -0700968#include "syscall_table.S"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970syscall_table_size=(.-sys_call_table)