blob: 3872fca5c74a4fc0fe0d61a931805c53360f7e84 [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>
Jan Beulichfe7cacc2006-06-26 13:57:44 +020051#include <asm/dwarf2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include "irq_vectors.h"
53
54#define nr_syscalls ((syscall_table_size)/4)
55
56EBX = 0x00
57ECX = 0x04
58EDX = 0x08
59ESI = 0x0C
60EDI = 0x10
61EBP = 0x14
62EAX = 0x18
63DS = 0x1C
64ES = 0x20
65ORIG_EAX = 0x24
66EIP = 0x28
67CS = 0x2C
68EFLAGS = 0x30
69OLDESP = 0x34
70OLDSS = 0x38
71
72CF_MASK = 0x00000001
73TF_MASK = 0x00000100
74IF_MASK = 0x00000200
75DF_MASK = 0x00000400
76NT_MASK = 0x00004000
77VM_MASK = 0x00020000
78
Rusty Russell0da5db32006-09-26 10:52:39 +020079/* These are replaces for paravirtualization */
80#define DISABLE_INTERRUPTS cli
81#define ENABLE_INTERRUPTS sti
82#define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
83#define INTERRUPT_RETURN iret
84#define GET_CR0_INTO_EAX movl %cr0, %eax
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#ifdef CONFIG_PREEMPT
Rusty Russell0da5db32006-09-26 10:52:39 +020087#define preempt_stop DISABLE_INTERRUPTS; TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#else
89#define preempt_stop
90#define resume_kernel restore_nocheck
91#endif
92
Ingo Molnar55f327f2006-07-03 00:24:43 -070093.macro TRACE_IRQS_IRET
94#ifdef CONFIG_TRACE_IRQFLAGS
95 testl $IF_MASK,EFLAGS(%esp) # interrupts off?
96 jz 1f
97 TRACE_IRQS_ON
981:
99#endif
100.endm
101
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700102#ifdef CONFIG_VM86
103#define resume_userspace_sig check_userspace
104#else
105#define resume_userspace_sig resume_userspace
106#endif
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define SAVE_ALL \
109 cld; \
110 pushl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200111 CFI_ADJUST_CFA_OFFSET 4;\
112 /*CFI_REL_OFFSET es, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 pushl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200114 CFI_ADJUST_CFA_OFFSET 4;\
115 /*CFI_REL_OFFSET ds, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200117 CFI_ADJUST_CFA_OFFSET 4;\
118 CFI_REL_OFFSET eax, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 pushl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200120 CFI_ADJUST_CFA_OFFSET 4;\
121 CFI_REL_OFFSET ebp, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 pushl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200123 CFI_ADJUST_CFA_OFFSET 4;\
124 CFI_REL_OFFSET edi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 pushl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200126 CFI_ADJUST_CFA_OFFSET 4;\
127 CFI_REL_OFFSET esi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 pushl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200129 CFI_ADJUST_CFA_OFFSET 4;\
130 CFI_REL_OFFSET edx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 pushl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200132 CFI_ADJUST_CFA_OFFSET 4;\
133 CFI_REL_OFFSET ecx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 pushl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200135 CFI_ADJUST_CFA_OFFSET 4;\
136 CFI_REL_OFFSET ebx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 movl $(__USER_DS), %edx; \
138 movl %edx, %ds; \
139 movl %edx, %es;
140
141#define RESTORE_INT_REGS \
142 popl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200143 CFI_ADJUST_CFA_OFFSET -4;\
144 CFI_RESTORE ebx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 popl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200146 CFI_ADJUST_CFA_OFFSET -4;\
147 CFI_RESTORE ecx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 popl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200149 CFI_ADJUST_CFA_OFFSET -4;\
150 CFI_RESTORE edx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 popl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200152 CFI_ADJUST_CFA_OFFSET -4;\
153 CFI_RESTORE esi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 popl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200155 CFI_ADJUST_CFA_OFFSET -4;\
156 CFI_RESTORE edi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 popl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200158 CFI_ADJUST_CFA_OFFSET -4;\
159 CFI_RESTORE ebp;\
160 popl %eax; \
161 CFI_ADJUST_CFA_OFFSET -4;\
162 CFI_RESTORE eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164#define RESTORE_REGS \
165 RESTORE_INT_REGS; \
1661: popl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200167 CFI_ADJUST_CFA_OFFSET -4;\
168 /*CFI_RESTORE ds;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692: popl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200170 CFI_ADJUST_CFA_OFFSET -4;\
171 /*CFI_RESTORE es;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172.section .fixup,"ax"; \
1733: movl $0,(%esp); \
174 jmp 1b; \
1754: movl $0,(%esp); \
176 jmp 2b; \
177.previous; \
178.section __ex_table,"a";\
179 .align 4; \
180 .long 1b,3b; \
181 .long 2b,4b; \
182.previous
183
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200184#define RING0_INT_FRAME \
185 CFI_STARTPROC simple;\
186 CFI_DEF_CFA esp, 3*4;\
187 /*CFI_OFFSET cs, -2*4;*/\
188 CFI_OFFSET eip, -3*4
189
190#define RING0_EC_FRAME \
191 CFI_STARTPROC simple;\
192 CFI_DEF_CFA esp, 4*4;\
193 /*CFI_OFFSET cs, -2*4;*/\
194 CFI_OFFSET eip, -3*4
195
196#define RING0_PTREGS_FRAME \
197 CFI_STARTPROC simple;\
198 CFI_DEF_CFA esp, OLDESP-EBX;\
199 /*CFI_OFFSET cs, CS-OLDESP;*/\
200 CFI_OFFSET eip, EIP-OLDESP;\
201 /*CFI_OFFSET es, ES-OLDESP;*/\
202 /*CFI_OFFSET ds, DS-OLDESP;*/\
203 CFI_OFFSET eax, EAX-OLDESP;\
204 CFI_OFFSET ebp, EBP-OLDESP;\
205 CFI_OFFSET edi, EDI-OLDESP;\
206 CFI_OFFSET esi, ESI-OLDESP;\
207 CFI_OFFSET edx, EDX-OLDESP;\
208 CFI_OFFSET ecx, ECX-OLDESP;\
209 CFI_OFFSET ebx, EBX-OLDESP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200212 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 pushl %eax
Markus Armbruster25d7dfd2006-07-30 03:04:08 -0700214 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 call schedule_tail
216 GET_THREAD_INFO(%ebp)
217 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200218 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds47a5c6f2006-09-18 16:20:40 -0700219 pushl $0x0202 # Reset kernel eflags
220 CFI_ADJUST_CFA_OFFSET 4
221 popfl
222 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200224 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226/*
227 * Return to user mode is not as complex as all this looks,
228 * but we want the default path for a system call return to
229 * go as quickly as possible which is why some of this is
230 * less clear than it otherwise should be.
231 */
232
233 # userspace resumption stub bypassing syscall exit tracing
234 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200235 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236ret_from_exception:
237 preempt_stop
238ret_from_intr:
239 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700240check_userspace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 movl EFLAGS(%esp), %eax # mix EFLAGS and CS
242 movb CS(%esp), %al
243 testl $(VM_MASK | 3), %eax
244 jz resume_kernel
245ENTRY(resume_userspace)
Rusty Russell0da5db32006-09-26 10:52:39 +0200246 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 # setting need_resched or sigpending
248 # between sampling and the iret
249 movl TI_flags(%ebp), %ecx
250 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
251 # int/exception return?
252 jne work_pending
253 jmp restore_all
254
255#ifdef CONFIG_PREEMPT
256ENTRY(resume_kernel)
Rusty Russell0da5db32006-09-26 10:52:39 +0200257 DISABLE_INTERRUPTS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
259 jnz restore_nocheck
260need_resched:
261 movl TI_flags(%ebp), %ecx # need_resched set ?
262 testb $_TIF_NEED_RESCHED, %cl
263 jz restore_all
264 testl $IF_MASK,EFLAGS(%esp) # interrupts off (exception path) ?
265 jz restore_all
266 call preempt_schedule_irq
267 jmp need_resched
268#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200269 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271/* SYSENTER_RETURN points to after the "sysenter" instruction in
272 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
273
274 # sysenter call handler stub
275ENTRY(sysenter_entry)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200276 CFI_STARTPROC simple
277 CFI_DEF_CFA esp, 0
278 CFI_REGISTER esp, ebp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 movl TSS_sysenter_esp0(%esp),%esp
280sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700281 /*
282 * No need to follow this irqs on/off section: the syscall
283 * disabled irqs and here we enable it straight after entry:
284 */
Rusty Russell0da5db32006-09-26 10:52:39 +0200285 ENABLE_INTERRUPTS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200287 CFI_ADJUST_CFA_OFFSET 4
288 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200290 CFI_ADJUST_CFA_OFFSET 4
291 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 pushfl
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200293 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200295 CFI_ADJUST_CFA_OFFSET 4
296 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700297 /*
298 * Push current_thread_info()->sysenter_return to the stack.
299 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
300 * pushed above; +8 corresponds to copy_thread's esp0 setting.
301 */
302 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200303 CFI_ADJUST_CFA_OFFSET 4
304 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306/*
307 * Load the potential sixth argument from user stack.
308 * Careful about security.
309 */
310 cmpl $__PAGE_OFFSET-3,%ebp
311 jae syscall_fault
3121: movl (%ebp),%ebp
313.section __ex_table,"a"
314 .align 4
315 .long 1b,syscall_fault
316.previous
317
318 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200319 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 SAVE_ALL
321 GET_THREAD_INFO(%ebp)
322
323 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700324 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 jnz syscall_trace_entry
326 cmpl $(nr_syscalls), %eax
327 jae syscall_badsys
328 call *sys_call_table(,%eax,4)
329 movl %eax,EAX(%esp)
Rusty Russell0da5db32006-09-26 10:52:39 +0200330 DISABLE_INTERRUPTS
Ingo Molnar55f327f2006-07-03 00:24:43 -0700331 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 movl TI_flags(%ebp), %ecx
333 testw $_TIF_ALLWORK_MASK, %cx
334 jne syscall_exit_work
335/* if something modifies registers it must also disable sysexit */
336 movl EIP(%esp), %edx
337 movl OLDESP(%esp), %ecx
338 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700339 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200340 ENABLE_INTERRUPTS_SYSEXIT
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200341 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343
344 # system call handler stub
345ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200346 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200348 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 SAVE_ALL
350 GET_THREAD_INFO(%ebp)
Chuck Ebbert635cf992006-03-23 02:59:48 -0800351 testl $TF_MASK,EFLAGS(%esp)
352 jz no_singlestep
353 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
354no_singlestep:
Laurent Viviered75e8d2005-09-03 15:57:18 -0700355 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700357 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 jnz syscall_trace_entry
359 cmpl $(nr_syscalls), %eax
360 jae syscall_badsys
361syscall_call:
362 call *sys_call_table(,%eax,4)
363 movl %eax,EAX(%esp) # store the return value
364syscall_exit:
Rusty Russell0da5db32006-09-26 10:52:39 +0200365 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 # setting need_resched or sigpending
367 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700368 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 movl TI_flags(%ebp), %ecx
370 testw $_TIF_ALLWORK_MASK, %cx # current->work
371 jne syscall_exit_work
372
373restore_all:
374 movl EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
Stas Sergeev5df24082005-04-16 15:24:01 -0700375 # Warning: OLDSS(%esp) contains the wrong/random values if we
376 # are returning to the kernel.
377 # See comments in process.c:copy_thread() for details.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 movb OLDSS(%esp), %ah
379 movb CS(%esp), %al
380 andl $(VM_MASK | (4 << 8) | 3), %eax
381 cmpl $((4 << 8) | 3), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200382 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 je ldt_ss # returning to user-space with LDT SS
384restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700385 TRACE_IRQS_IRET
386restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 RESTORE_REGS
388 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200389 CFI_ADJUST_CFA_OFFSET -4
Rusty Russell0da5db32006-09-26 10:52:39 +02003901: INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391.section .fixup,"ax"
392iret_exc:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700393 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200394 ENABLE_INTERRUPTS
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700395 pushl $0 # no error code
396 pushl $do_iret_error
397 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398.previous
399.section __ex_table,"a"
400 .align 4
401 .long 1b,iret_exc
402.previous
403
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200404 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405ldt_ss:
406 larl OLDSS(%esp), %eax
407 jnz restore_nocheck
408 testl $0x00400000, %eax # returning to 32bit stack?
409 jnz restore_nocheck # allright, normal return
410 /* If returning to userspace with 16bit stack,
411 * try to fix the higher word of ESP, as the CPU
412 * won't restore it.
413 * This is an "official" bug of all the x86-compatible
414 * CPUs, which we can try to work around to make
415 * dosemu and wine happy. */
416 subl $8, %esp # reserve space for switch16 pointer
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200417 CFI_ADJUST_CFA_OFFSET 8
Rusty Russell0da5db32006-09-26 10:52:39 +0200418 DISABLE_INTERRUPTS
Ingo Molnar55f327f2006-07-03 00:24:43 -0700419 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 movl %esp, %eax
421 /* Set up the 16bit stack frame with switch32 pointer on top,
422 * and a switch16 pointer on top of the current frame. */
423 call setup_x86_bogus_stack
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200424 CFI_ADJUST_CFA_OFFSET -8 # frame has moved
Ingo Molnar55f327f2006-07-03 00:24:43 -0700425 TRACE_IRQS_IRET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 RESTORE_REGS
427 lss 20+4(%esp), %esp # switch to 16bit stack
Rusty Russell0da5db32006-09-26 10:52:39 +02004281: INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429.section __ex_table,"a"
430 .align 4
431 .long 1b,iret_exc
432.previous
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200433 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 # perform work that needs to be done immediately before resumption
436 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200437 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438work_pending:
439 testb $_TIF_NEED_RESCHED, %cl
440 jz work_notifysig
441work_resched:
442 call schedule
Rusty Russell0da5db32006-09-26 10:52:39 +0200443 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 # setting need_resched or sigpending
445 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700446 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 movl TI_flags(%ebp), %ecx
448 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
449 # than syscall tracing?
450 jz restore_all
451 testb $_TIF_NEED_RESCHED, %cl
452 jnz work_resched
453
454work_notifysig: # deal with pending signals and
455 # notify-resume requests
456 testl $VM_MASK, EFLAGS(%esp)
457 movl %esp, %eax
458 jne work_notifysig_v86 # returning to kernel-space or
459 # vm86-space
460 xorl %edx, %edx
461 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700462 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 ALIGN
465work_notifysig_v86:
Matt Mackall64ca9002006-01-08 01:05:26 -0800466#ifdef CONFIG_VM86
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200468 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 call save_v86_state # %eax contains pt_regs pointer
470 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200471 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 movl %eax, %esp
473 xorl %edx, %edx
474 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700475 jmp resume_userspace_sig
Matt Mackall64ca9002006-01-08 01:05:26 -0800476#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 # perform syscall exit tracing
479 ALIGN
480syscall_trace_entry:
481 movl $-ENOSYS,EAX(%esp)
482 movl %esp, %eax
483 xorl %edx,%edx
484 call do_syscall_trace
Laurent Viviered75e8d2005-09-03 15:57:18 -0700485 cmpl $0, %eax
Paolo 'Blaisorblade' Giarrusso640aa462005-09-03 15:57:22 -0700486 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
Laurent Viviered75e8d2005-09-03 15:57:18 -0700487 # so must skip actual syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 movl ORIG_EAX(%esp), %eax
489 cmpl $(nr_syscalls), %eax
490 jnae syscall_call
491 jmp syscall_exit
492
493 # perform syscall exit tracing
494 ALIGN
495syscall_exit_work:
496 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
497 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700498 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200499 ENABLE_INTERRUPTS # could let do_syscall_trace() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 # schedule() instead
501 movl %esp, %eax
502 movl $1, %edx
503 call do_syscall_trace
504 jmp resume_userspace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200505 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200507 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508syscall_fault:
509 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200510 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 SAVE_ALL
512 GET_THREAD_INFO(%ebp)
513 movl $-EFAULT,EAX(%esp)
514 jmp resume_userspace
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516syscall_badsys:
517 movl $-ENOSYS,EAX(%esp)
518 jmp resume_userspace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200519 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521#define FIXUP_ESPFIX_STACK \
522 movl %esp, %eax; \
523 /* switch to 32bit stack using the pointer on top of 16bit stack */ \
524 lss %ss:CPU_16BIT_STACK_SIZE-8, %esp; \
525 /* copy data from 16bit stack to 32bit stack */ \
526 call fixup_x86_bogus_stack; \
527 /* put ESP to the proper location */ \
528 movl %eax, %esp;
529#define UNWIND_ESPFIX_STACK \
530 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200531 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 movl %ss, %eax; \
533 /* see if on 16bit stack */ \
534 cmpw $__ESPFIX_SS, %ax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200535 je 28f; \
53627: popl %eax; \
537 CFI_ADJUST_CFA_OFFSET -4; \
538.section .fixup,"ax"; \
53928: movl $__KERNEL_DS, %eax; \
540 movl %eax, %ds; \
541 movl %eax, %es; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 /* switch to 32bit stack */ \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200543 FIXUP_ESPFIX_STACK; \
544 jmp 27b; \
545.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547/*
548 * Build the entry stubs and pointer table with
549 * some assembler magic.
550 */
551.data
552ENTRY(interrupt)
553.text
554
555vector=0
556ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200557 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558.rept NR_IRQS
559 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200560 .if vector
561 CFI_ADJUST_CFA_OFFSET -4
562 .endif
Rusty Russell19eadf92006-06-27 02:53:44 -07005631: pushl $~(vector)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200564 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 jmp common_interrupt
566.data
567 .long 1b
568.text
569vector=vector+1
570.endr
571
Ingo Molnar55f327f2006-07-03 00:24:43 -0700572/*
573 * the CPU automatically disables interrupts when executing an IRQ vector,
574 * so IRQ-flags tracing has to follow that:
575 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 ALIGN
577common_interrupt:
578 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700579 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 movl %esp,%eax
581 call do_IRQ
582 jmp ret_from_intr
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200583 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585#define BUILD_INTERRUPT(name, nr) \
586ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200587 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700588 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200589 CFI_ADJUST_CFA_OFFSET 4; \
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 smp_/**/name; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700594 jmp ret_from_intr; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200595 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597/* The include is where all of the SMP etc. interrupts come from */
598#include "entry_arch.h"
599
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200600KPROBE_ENTRY(page_fault)
601 RING0_EC_FRAME
602 pushl $do_page_fault
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200603 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 ALIGN
605error_code:
606 pushl %ds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200607 CFI_ADJUST_CFA_OFFSET 4
608 /*CFI_REL_OFFSET ds, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200610 CFI_ADJUST_CFA_OFFSET 4
611 CFI_REL_OFFSET eax, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 xorl %eax, %eax
613 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200614 CFI_ADJUST_CFA_OFFSET 4
615 CFI_REL_OFFSET ebp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 pushl %edi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200617 CFI_ADJUST_CFA_OFFSET 4
618 CFI_REL_OFFSET edi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 pushl %esi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200620 CFI_ADJUST_CFA_OFFSET 4
621 CFI_REL_OFFSET esi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 pushl %edx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200623 CFI_ADJUST_CFA_OFFSET 4
624 CFI_REL_OFFSET edx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 decl %eax # eax = -1
626 pushl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200627 CFI_ADJUST_CFA_OFFSET 4
628 CFI_REL_OFFSET ecx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 pushl %ebx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200630 CFI_ADJUST_CFA_OFFSET 4
631 CFI_REL_OFFSET ebx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 cld
633 pushl %es
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200634 CFI_ADJUST_CFA_OFFSET 4
635 /*CFI_REL_OFFSET es, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 UNWIND_ESPFIX_STACK
637 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200638 CFI_ADJUST_CFA_OFFSET -4
639 /*CFI_REGISTER es, ecx*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 movl ES(%esp), %edi # get the function address
641 movl ORIG_EAX(%esp), %edx # get the error code
642 movl %eax, ORIG_EAX(%esp)
643 movl %ecx, ES(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200644 /*CFI_REL_OFFSET es, ES*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 movl $(__USER_DS), %ecx
646 movl %ecx, %ds
647 movl %ecx, %es
648 movl %esp,%eax # pt_regs pointer
649 call *%edi
650 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200651 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200652KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200655 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200657 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200659 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200661 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200664 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200666 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200668 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200670 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200673 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200675 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 SAVE_ALL
Rusty Russell0da5db32006-09-26 10:52:39 +0200677 GET_CR0_INTO_EAX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 testl $0x4, %eax # EM (math emulation bit)
679 jne device_not_available_emulate
680 preempt_stop
681 call math_state_restore
682 jmp ret_from_exception
683device_not_available_emulate:
684 pushl $0 # temporary storage for ORIG_EIP
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200685 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 call math_emulate
687 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200688 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200690 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692/*
693 * Debug traps and NMI can happen at the one SYSENTER instruction
694 * that sets up the real kernel stack. Check here, since we can't
695 * allow the wrong stack to be used.
696 *
697 * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
698 * already pushed 3 words if it hits on the sysenter instruction:
699 * eflags, cs and eip.
700 *
701 * We just load the right stack, and push the three (known) values
702 * by hand onto the new stack - while updating the return eip past
703 * the instruction that would have done it for sysenter.
704 */
705#define FIX_STACK(offset, ok, label) \
706 cmpw $__KERNEL_CS,4(%esp); \
707 jne ok; \
708label: \
709 movl TSS_sysenter_esp0+offset(%esp),%esp; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200710 CFI_DEF_CFA esp, 0; \
711 CFI_UNDEFINED eip; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 pushfl; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200713 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 pushl $__KERNEL_CS; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200715 CFI_ADJUST_CFA_OFFSET 4; \
716 pushl $sysenter_past_esp; \
717 CFI_ADJUST_CFA_OFFSET 4; \
718 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700720KPROBE_ENTRY(debug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200721 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 cmpl $sysenter_entry,(%esp)
723 jne debug_stack_correct
724 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
725debug_stack_correct:
726 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200727 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 SAVE_ALL
729 xorl %edx,%edx # error code 0
730 movl %esp,%eax # pt_regs pointer
731 call do_debug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200733 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200734KPROBE_END(debug)
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736/*
737 * NMI is doubly nasty. It can happen _while_ we're handling
738 * a debug fault, and the debug fault hasn't yet been able to
739 * clear up the stack. So we first check whether we got an
740 * NMI on the sysenter entry path, but after that we need to
741 * check whether we got an NMI on the debug path where the debug
742 * fault happened on the sysenter path.
743 */
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200744KPROBE_ENTRY(nmi)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200745 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200747 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 movl %ss, %eax
749 cmpw $__ESPFIX_SS, %ax
750 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200751 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 je nmi_16bit_stack
753 cmpl $sysenter_entry,(%esp)
754 je nmi_stack_fixup
755 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200756 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 movl %esp,%eax
758 /* Do not access memory above the end of our stack page,
759 * it might not exist.
760 */
761 andl $(THREAD_SIZE-1),%eax
762 cmpl $(THREAD_SIZE-20),%eax
763 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200764 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 jae nmi_stack_correct
766 cmpl $sysenter_entry,12(%esp)
767 je nmi_debug_stack_check
768nmi_stack_correct:
Chuck Ebberta549b862006-09-26 10:52:37 +0200769 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200771 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 SAVE_ALL
773 xorl %edx,%edx # zero error code
774 movl %esp,%eax # pt_regs pointer
775 call do_nmi
Ingo Molnar55f327f2006-07-03 00:24:43 -0700776 jmp restore_nocheck_notrace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200777 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779nmi_stack_fixup:
Chuck Ebberta549b862006-09-26 10:52:37 +0200780 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 FIX_STACK(12,nmi_stack_correct, 1)
782 jmp nmi_stack_correct
Chuck Ebberta549b862006-09-26 10:52:37 +0200783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784nmi_debug_stack_check:
Chuck Ebberta549b862006-09-26 10:52:37 +0200785 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 cmpw $__KERNEL_CS,16(%esp)
787 jne nmi_stack_correct
Jan Beuliche2718202005-11-13 16:06:52 -0800788 cmpl $debug,(%esp)
789 jb nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 cmpl $debug_esp_fix_insn,(%esp)
Jan Beuliche2718202005-11-13 16:06:52 -0800791 ja nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 FIX_STACK(24,nmi_stack_correct, 1)
793 jmp nmi_stack_correct
794
795nmi_16bit_stack:
Chuck Ebberta549b862006-09-26 10:52:37 +0200796 /* We have a RING0_INT_FRAME here.
797 *
798 * create the pointer to lss back
799 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 pushl %ss
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200801 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 pushl %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200803 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 movzwl %sp, %esp
805 addw $4, (%esp)
806 /* copy the iret frame of 12 bytes */
807 .rept 3
808 pushl 16(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200809 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 .endr
811 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200812 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 SAVE_ALL
814 FIXUP_ESPFIX_STACK # %eax == %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200815 CFI_ADJUST_CFA_OFFSET -20 # the frame has now moved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 xorl %edx,%edx # zero error code
817 call do_nmi
818 RESTORE_REGS
819 lss 12+4(%esp), %esp # back to 16bit stack
Rusty Russell0da5db32006-09-26 10:52:39 +02008201: INTERRUPT_RETURN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200821 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822.section __ex_table,"a"
823 .align 4
824 .long 1b,iret_exc
825.previous
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200826KPROBE_END(nmi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700828KPROBE_ENTRY(int3)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200829 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200831 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 SAVE_ALL
833 xorl %edx,%edx # zero error code
834 movl %esp,%eax # pt_regs pointer
835 call do_int3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200837 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200838KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840ENTRY(overflow)
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_overflow
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(bounds)
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_bounds
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_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200859 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200861 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 pushl $do_invalid_op
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200863 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200865 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200868 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200870 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 pushl $do_coprocessor_segment_overrun
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200872 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200874 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200877 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 pushl $do_invalid_TSS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200879 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200881 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200884 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 pushl $do_segment_not_present
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200886 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200888 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 pushl $do_stack_segment
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200893 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200895 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700897KPROBE_ENTRY(general_protection)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200898 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 pushl $do_general_protection
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
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200903KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200906 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200908 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200910 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200912ENTRY(divide_error)
913 RING0_INT_FRAME
914 pushl $0 # no error code
915 CFI_ADJUST_CFA_OFFSET 4
916 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200917 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200919 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921#ifdef CONFIG_X86_MCE
922ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200923 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200925 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200927 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200929 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930#endif
931
932ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200933 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200935 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200937 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200939 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Jan Beulich176a2712006-06-26 13:57:41 +0200941#ifdef CONFIG_STACK_UNWIND
942ENTRY(arch_unwind_init_running)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200943 CFI_STARTPROC
Jan Beulich176a2712006-06-26 13:57:41 +0200944 movl 4(%esp), %edx
945 movl (%esp), %ecx
946 leal 4(%esp), %eax
947 movl %ebx, EBX(%edx)
948 xorl %ebx, %ebx
949 movl %ebx, ECX(%edx)
950 movl %ebx, EDX(%edx)
951 movl %esi, ESI(%edx)
952 movl %edi, EDI(%edx)
953 movl %ebp, EBP(%edx)
954 movl %ebx, EAX(%edx)
955 movl $__USER_DS, DS(%edx)
956 movl $__USER_DS, ES(%edx)
957 movl %ebx, ORIG_EAX(%edx)
958 movl %ecx, EIP(%edx)
959 movl 12(%esp), %ecx
960 movl $__KERNEL_CS, CS(%edx)
961 movl %ebx, EFLAGS(%edx)
962 movl %eax, OLDESP(%edx)
963 movl 8(%esp), %eax
964 movl %ecx, 8(%esp)
965 movl EBX(%edx), %ebx
966 movl $__KERNEL_DS, OLDSS(%edx)
967 jmpl *%eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200968 CFI_ENDPROC
Jan Beulich176a2712006-06-26 13:57:41 +0200969ENDPROC(arch_unwind_init_running)
970#endif
971
Andi Kleen02ba1a32006-09-26 10:52:35 +0200972ENTRY(kernel_thread_helper)
973 pushl $0 # fake return address for unwinder
974 CFI_STARTPROC
975 movl %edx,%eax
976 push %edx
977 CFI_ADJUST_CFA_OFFSET 4
978 call *%ebx
979 push %eax
980 CFI_ADJUST_CFA_OFFSET 4
981 call do_exit
982 CFI_ENDPROC
983ENDPROC(kernel_thread_helper)
984
Arjan van de Venbb152f52006-01-06 00:12:05 -0800985.section .rodata,"a"
Paolo 'Blaisorblade' Giarrusso5e7b83f2005-05-01 08:58:55 -0700986#include "syscall_table.S"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988syscall_table_size=(.-sys_call_table)