blob: c38d801ba0bb2823d9b41c899b535c279de39d79 [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
57EBX = 0x00
58ECX = 0x04
59EDX = 0x08
60ESI = 0x0C
61EDI = 0x10
62EBP = 0x14
63EAX = 0x18
64DS = 0x1C
65ES = 0x20
66ORIG_EAX = 0x24
67EIP = 0x28
68CS = 0x2C
69EFLAGS = 0x30
70OLDESP = 0x34
71OLDSS = 0x38
72
73CF_MASK = 0x00000001
74TF_MASK = 0x00000100
75IF_MASK = 0x00000200
76DF_MASK = 0x00000400
77NT_MASK = 0x00004000
78VM_MASK = 0x00020000
79
Rusty Russell0da5db32006-09-26 10:52:39 +020080/* These are replaces for paravirtualization */
81#define DISABLE_INTERRUPTS cli
82#define ENABLE_INTERRUPTS sti
83#define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
84#define INTERRUPT_RETURN iret
85#define GET_CR0_INTO_EAX movl %cr0, %eax
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#ifdef CONFIG_PREEMPT
Rusty Russell0da5db32006-09-26 10:52:39 +020088#define preempt_stop DISABLE_INTERRUPTS; TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#else
90#define preempt_stop
91#define resume_kernel restore_nocheck
92#endif
93
Ingo Molnar55f327f2006-07-03 00:24:43 -070094.macro TRACE_IRQS_IRET
95#ifdef CONFIG_TRACE_IRQFLAGS
96 testl $IF_MASK,EFLAGS(%esp) # interrupts off?
97 jz 1f
98 TRACE_IRQS_ON
991:
100#endif
101.endm
102
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700103#ifdef CONFIG_VM86
104#define resume_userspace_sig check_userspace
105#else
106#define resume_userspace_sig resume_userspace
107#endif
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define SAVE_ALL \
110 cld; \
111 pushl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200112 CFI_ADJUST_CFA_OFFSET 4;\
113 /*CFI_REL_OFFSET es, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 pushl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200115 CFI_ADJUST_CFA_OFFSET 4;\
116 /*CFI_REL_OFFSET ds, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200118 CFI_ADJUST_CFA_OFFSET 4;\
119 CFI_REL_OFFSET eax, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 pushl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200121 CFI_ADJUST_CFA_OFFSET 4;\
122 CFI_REL_OFFSET ebp, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 pushl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200124 CFI_ADJUST_CFA_OFFSET 4;\
125 CFI_REL_OFFSET edi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 pushl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200127 CFI_ADJUST_CFA_OFFSET 4;\
128 CFI_REL_OFFSET esi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 pushl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200130 CFI_ADJUST_CFA_OFFSET 4;\
131 CFI_REL_OFFSET edx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 pushl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200133 CFI_ADJUST_CFA_OFFSET 4;\
134 CFI_REL_OFFSET ecx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 pushl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200136 CFI_ADJUST_CFA_OFFSET 4;\
137 CFI_REL_OFFSET ebx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 movl $(__USER_DS), %edx; \
139 movl %edx, %ds; \
140 movl %edx, %es;
141
142#define RESTORE_INT_REGS \
143 popl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200144 CFI_ADJUST_CFA_OFFSET -4;\
145 CFI_RESTORE ebx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 popl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200147 CFI_ADJUST_CFA_OFFSET -4;\
148 CFI_RESTORE ecx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 popl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200150 CFI_ADJUST_CFA_OFFSET -4;\
151 CFI_RESTORE edx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 popl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200153 CFI_ADJUST_CFA_OFFSET -4;\
154 CFI_RESTORE esi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 popl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200156 CFI_ADJUST_CFA_OFFSET -4;\
157 CFI_RESTORE edi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 popl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200159 CFI_ADJUST_CFA_OFFSET -4;\
160 CFI_RESTORE ebp;\
161 popl %eax; \
162 CFI_ADJUST_CFA_OFFSET -4;\
163 CFI_RESTORE eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165#define RESTORE_REGS \
166 RESTORE_INT_REGS; \
1671: popl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200168 CFI_ADJUST_CFA_OFFSET -4;\
169 /*CFI_RESTORE ds;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702: popl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200171 CFI_ADJUST_CFA_OFFSET -4;\
172 /*CFI_RESTORE es;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173.section .fixup,"ax"; \
1743: movl $0,(%esp); \
175 jmp 1b; \
1764: movl $0,(%esp); \
177 jmp 2b; \
178.previous; \
179.section __ex_table,"a";\
180 .align 4; \
181 .long 1b,3b; \
182 .long 2b,4b; \
183.previous
184
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200185#define RING0_INT_FRAME \
186 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200187 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200188 CFI_DEF_CFA esp, 3*4;\
189 /*CFI_OFFSET cs, -2*4;*/\
190 CFI_OFFSET eip, -3*4
191
192#define RING0_EC_FRAME \
193 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200194 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200195 CFI_DEF_CFA esp, 4*4;\
196 /*CFI_OFFSET cs, -2*4;*/\
197 CFI_OFFSET eip, -3*4
198
199#define RING0_PTREGS_FRAME \
200 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200201 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200202 CFI_DEF_CFA esp, OLDESP-EBX;\
203 /*CFI_OFFSET cs, CS-OLDESP;*/\
204 CFI_OFFSET eip, EIP-OLDESP;\
205 /*CFI_OFFSET es, ES-OLDESP;*/\
206 /*CFI_OFFSET ds, DS-OLDESP;*/\
207 CFI_OFFSET eax, EAX-OLDESP;\
208 CFI_OFFSET ebp, EBP-OLDESP;\
209 CFI_OFFSET edi, EDI-OLDESP;\
210 CFI_OFFSET esi, ESI-OLDESP;\
211 CFI_OFFSET edx, EDX-OLDESP;\
212 CFI_OFFSET ecx, ECX-OLDESP;\
213 CFI_OFFSET ebx, EBX-OLDESP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200216 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 pushl %eax
Markus Armbruster25d7dfd2006-07-30 03:04:08 -0700218 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 call schedule_tail
220 GET_THREAD_INFO(%ebp)
221 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200222 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds47a5c6f2006-09-18 16:20:40 -0700223 pushl $0x0202 # Reset kernel eflags
224 CFI_ADJUST_CFA_OFFSET 4
225 popfl
226 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200228 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230/*
231 * Return to user mode is not as complex as all this looks,
232 * but we want the default path for a system call return to
233 * go as quickly as possible which is why some of this is
234 * less clear than it otherwise should be.
235 */
236
237 # userspace resumption stub bypassing syscall exit tracing
238 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200239 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240ret_from_exception:
241 preempt_stop
242ret_from_intr:
243 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700244check_userspace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 movl EFLAGS(%esp), %eax # mix EFLAGS and CS
246 movb CS(%esp), %al
Rusty Russell78be3702006-09-26 10:52:39 +0200247 andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
248 cmpl $USER_RPL, %eax
249 jb resume_kernel # not returning to v8086 or userspace
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250ENTRY(resume_userspace)
Rusty Russell0da5db32006-09-26 10:52:39 +0200251 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 # setting need_resched or sigpending
253 # between sampling and the iret
254 movl TI_flags(%ebp), %ecx
255 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
256 # int/exception return?
257 jne work_pending
258 jmp restore_all
259
260#ifdef CONFIG_PREEMPT
261ENTRY(resume_kernel)
Rusty Russell0da5db32006-09-26 10:52:39 +0200262 DISABLE_INTERRUPTS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
264 jnz restore_nocheck
265need_resched:
266 movl TI_flags(%ebp), %ecx # need_resched set ?
267 testb $_TIF_NEED_RESCHED, %cl
268 jz restore_all
269 testl $IF_MASK,EFLAGS(%esp) # interrupts off (exception path) ?
270 jz restore_all
271 call preempt_schedule_irq
272 jmp need_resched
273#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200274 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276/* SYSENTER_RETURN points to after the "sysenter" instruction in
277 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
278
279 # sysenter call handler stub
280ENTRY(sysenter_entry)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200281 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200282 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200283 CFI_DEF_CFA esp, 0
284 CFI_REGISTER esp, ebp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 movl TSS_sysenter_esp0(%esp),%esp
286sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700287 /*
288 * No need to follow this irqs on/off section: the syscall
289 * disabled irqs and here we enable it straight after entry:
290 */
Rusty Russell0da5db32006-09-26 10:52:39 +0200291 ENABLE_INTERRUPTS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200293 CFI_ADJUST_CFA_OFFSET 4
294 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200296 CFI_ADJUST_CFA_OFFSET 4
297 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 pushfl
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200299 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200301 CFI_ADJUST_CFA_OFFSET 4
302 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700303 /*
304 * Push current_thread_info()->sysenter_return to the stack.
305 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
306 * pushed above; +8 corresponds to copy_thread's esp0 setting.
307 */
308 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200309 CFI_ADJUST_CFA_OFFSET 4
310 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312/*
313 * Load the potential sixth argument from user stack.
314 * Careful about security.
315 */
316 cmpl $__PAGE_OFFSET-3,%ebp
317 jae syscall_fault
3181: movl (%ebp),%ebp
319.section __ex_table,"a"
320 .align 4
321 .long 1b,syscall_fault
322.previous
323
324 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200325 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 SAVE_ALL
327 GET_THREAD_INFO(%ebp)
328
329 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700330 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 jnz syscall_trace_entry
332 cmpl $(nr_syscalls), %eax
333 jae syscall_badsys
334 call *sys_call_table(,%eax,4)
335 movl %eax,EAX(%esp)
Rusty Russell0da5db32006-09-26 10:52:39 +0200336 DISABLE_INTERRUPTS
Ingo Molnar55f327f2006-07-03 00:24:43 -0700337 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 movl TI_flags(%ebp), %ecx
339 testw $_TIF_ALLWORK_MASK, %cx
340 jne syscall_exit_work
341/* if something modifies registers it must also disable sysexit */
342 movl EIP(%esp), %edx
343 movl OLDESP(%esp), %ecx
344 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700345 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200346 ENABLE_INTERRUPTS_SYSEXIT
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200347 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349
350 # system call handler stub
351ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200352 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200354 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 SAVE_ALL
356 GET_THREAD_INFO(%ebp)
Chuck Ebbert635cf992006-03-23 02:59:48 -0800357 testl $TF_MASK,EFLAGS(%esp)
358 jz no_singlestep
359 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
360no_singlestep:
Laurent Viviered75e8d2005-09-03 15:57:18 -0700361 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700363 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 jnz syscall_trace_entry
365 cmpl $(nr_syscalls), %eax
366 jae syscall_badsys
367syscall_call:
368 call *sys_call_table(,%eax,4)
369 movl %eax,EAX(%esp) # store the return value
370syscall_exit:
Rusty Russell0da5db32006-09-26 10:52:39 +0200371 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 # setting need_resched or sigpending
373 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700374 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 movl TI_flags(%ebp), %ecx
376 testw $_TIF_ALLWORK_MASK, %cx # current->work
377 jne syscall_exit_work
378
379restore_all:
380 movl EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
Stas Sergeev5df24082005-04-16 15:24:01 -0700381 # Warning: OLDSS(%esp) contains the wrong/random values if we
382 # are returning to the kernel.
383 # See comments in process.c:copy_thread() for details.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 movb OLDSS(%esp), %ah
385 movb CS(%esp), %al
Rusty Russell78be3702006-09-26 10:52:39 +0200386 andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
387 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200388 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 je ldt_ss # returning to user-space with LDT SS
390restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700391 TRACE_IRQS_IRET
392restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 RESTORE_REGS
394 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200395 CFI_ADJUST_CFA_OFFSET -4
Rusty Russell0da5db32006-09-26 10:52:39 +02003961: INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397.section .fixup,"ax"
398iret_exc:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700399 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200400 ENABLE_INTERRUPTS
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700401 pushl $0 # no error code
402 pushl $do_iret_error
403 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404.previous
405.section __ex_table,"a"
406 .align 4
407 .long 1b,iret_exc
408.previous
409
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200410 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411ldt_ss:
412 larl OLDSS(%esp), %eax
413 jnz restore_nocheck
414 testl $0x00400000, %eax # returning to 32bit stack?
415 jnz restore_nocheck # allright, normal return
416 /* If returning to userspace with 16bit stack,
417 * try to fix the higher word of ESP, as the CPU
418 * won't restore it.
419 * This is an "official" bug of all the x86-compatible
420 * CPUs, which we can try to work around to make
421 * dosemu and wine happy. */
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100422 movl OLDESP(%esp), %eax
423 movl %esp, %edx
424 call patch_espfix_desc
425 pushl $__ESPFIX_SS
426 CFI_ADJUST_CFA_OFFSET 4
427 pushl %eax
428 CFI_ADJUST_CFA_OFFSET 4
Rusty Russell0da5db32006-09-26 10:52:39 +0200429 DISABLE_INTERRUPTS
Ingo Molnar55f327f2006-07-03 00:24:43 -0700430 TRACE_IRQS_OFF
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100431 lss (%esp), %esp
432 CFI_ADJUST_CFA_OFFSET -8
433 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200434 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 # perform work that needs to be done immediately before resumption
437 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200438 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439work_pending:
440 testb $_TIF_NEED_RESCHED, %cl
441 jz work_notifysig
442work_resched:
443 call schedule
Rusty Russell0da5db32006-09-26 10:52:39 +0200444 DISABLE_INTERRUPTS # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 # setting need_resched or sigpending
446 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700447 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 movl TI_flags(%ebp), %ecx
449 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
450 # than syscall tracing?
451 jz restore_all
452 testb $_TIF_NEED_RESCHED, %cl
453 jnz work_resched
454
455work_notifysig: # deal with pending signals and
456 # notify-resume requests
457 testl $VM_MASK, EFLAGS(%esp)
458 movl %esp, %eax
459 jne work_notifysig_v86 # returning to kernel-space or
460 # vm86-space
461 xorl %edx, %edx
462 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700463 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 ALIGN
466work_notifysig_v86:
Matt Mackall64ca9002006-01-08 01:05:26 -0800467#ifdef CONFIG_VM86
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200469 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 call save_v86_state # %eax contains pt_regs pointer
471 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200472 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 movl %eax, %esp
474 xorl %edx, %edx
475 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700476 jmp resume_userspace_sig
Matt Mackall64ca9002006-01-08 01:05:26 -0800477#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 # perform syscall exit tracing
480 ALIGN
481syscall_trace_entry:
482 movl $-ENOSYS,EAX(%esp)
483 movl %esp, %eax
484 xorl %edx,%edx
485 call do_syscall_trace
Laurent Viviered75e8d2005-09-03 15:57:18 -0700486 cmpl $0, %eax
Paolo 'Blaisorblade' Giarrusso640aa462005-09-03 15:57:22 -0700487 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
Laurent Viviered75e8d2005-09-03 15:57:18 -0700488 # so must skip actual syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 movl ORIG_EAX(%esp), %eax
490 cmpl $(nr_syscalls), %eax
491 jnae syscall_call
492 jmp syscall_exit
493
494 # perform syscall exit tracing
495 ALIGN
496syscall_exit_work:
497 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
498 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700499 TRACE_IRQS_ON
Rusty Russell0da5db32006-09-26 10:52:39 +0200500 ENABLE_INTERRUPTS # could let do_syscall_trace() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 # schedule() instead
502 movl %esp, %eax
503 movl $1, %edx
504 call do_syscall_trace
505 jmp resume_userspace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200506 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200508 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509syscall_fault:
510 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200511 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 SAVE_ALL
513 GET_THREAD_INFO(%ebp)
514 movl $-EFAULT,EAX(%esp)
515 jmp resume_userspace
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517syscall_badsys:
518 movl $-ENOSYS,EAX(%esp)
519 jmp resume_userspace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200520 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522#define FIXUP_ESPFIX_STACK \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100523 /* since we are on a wrong stack, we cant make it a C code :( */ \
524 GET_THREAD_INFO(%ebp); \
525 movl TI_cpu(%ebp), %ebx; \
526 PER_CPU(cpu_gdt_descr, %ebx); \
527 movl GDS_address(%ebx), %ebx; \
528 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
529 addl %esp, %eax; \
530 pushl $__KERNEL_DS; \
531 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200533 CFI_ADJUST_CFA_OFFSET 4; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100534 lss (%esp), %esp; \
535 CFI_ADJUST_CFA_OFFSET -8;
536#define UNWIND_ESPFIX_STACK \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 movl %ss, %eax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100538 /* see if on espfix stack */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 cmpw $__ESPFIX_SS, %ax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100540 jne 27f; \
541 movl $__KERNEL_DS, %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200542 movl %eax, %ds; \
543 movl %eax, %es; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100544 /* switch to normal stack */ \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200545 FIXUP_ESPFIX_STACK; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010054627:;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548/*
549 * Build the entry stubs and pointer table with
550 * some assembler magic.
551 */
552.data
553ENTRY(interrupt)
554.text
555
556vector=0
557ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200558 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559.rept NR_IRQS
560 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200561 .if vector
562 CFI_ADJUST_CFA_OFFSET -4
563 .endif
Rusty Russell19eadf92006-06-27 02:53:44 -07005641: pushl $~(vector)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200565 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 jmp common_interrupt
567.data
568 .long 1b
569.text
570vector=vector+1
571.endr
572
Ingo Molnar55f327f2006-07-03 00:24:43 -0700573/*
574 * the CPU automatically disables interrupts when executing an IRQ vector,
575 * so IRQ-flags tracing has to follow that:
576 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 ALIGN
578common_interrupt:
579 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700580 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 movl %esp,%eax
582 call do_IRQ
583 jmp ret_from_intr
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200584 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586#define BUILD_INTERRUPT(name, nr) \
587ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200588 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700589 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200590 CFI_ADJUST_CFA_OFFSET 4; \
591 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700592 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 movl %esp,%eax; \
594 call smp_/**/name; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700595 jmp ret_from_intr; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200596 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598/* The include is where all of the SMP etc. interrupts come from */
599#include "entry_arch.h"
600
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200601KPROBE_ENTRY(page_fault)
602 RING0_EC_FRAME
603 pushl $do_page_fault
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200604 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 ALIGN
606error_code:
607 pushl %ds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200608 CFI_ADJUST_CFA_OFFSET 4
609 /*CFI_REL_OFFSET ds, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200611 CFI_ADJUST_CFA_OFFSET 4
612 CFI_REL_OFFSET eax, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 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 pushl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200626 CFI_ADJUST_CFA_OFFSET 4
627 CFI_REL_OFFSET ecx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 pushl %ebx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200629 CFI_ADJUST_CFA_OFFSET 4
630 CFI_REL_OFFSET ebx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 cld
632 pushl %es
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200633 CFI_ADJUST_CFA_OFFSET 4
634 /*CFI_REL_OFFSET es, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 UNWIND_ESPFIX_STACK
636 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200637 CFI_ADJUST_CFA_OFFSET -4
638 /*CFI_REGISTER es, ecx*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 movl ES(%esp), %edi # get the function address
640 movl ORIG_EAX(%esp), %edx # get the error code
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100641 movl $-1, ORIG_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 movl %ecx, ES(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200643 /*CFI_REL_OFFSET es, ES*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 movl $(__USER_DS), %ecx
645 movl %ecx, %ds
646 movl %ecx, %es
647 movl %esp,%eax # pt_regs pointer
648 call *%edi
649 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200650 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200651KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200654 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200656 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200658 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200660 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200663 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200665 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200667 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200669 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200672 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200674 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 SAVE_ALL
Rusty Russell0da5db32006-09-26 10:52:39 +0200676 GET_CR0_INTO_EAX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 testl $0x4, %eax # EM (math emulation bit)
678 jne device_not_available_emulate
679 preempt_stop
680 call math_state_restore
681 jmp ret_from_exception
682device_not_available_emulate:
683 pushl $0 # temporary storage for ORIG_EIP
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200684 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 call math_emulate
686 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200687 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200689 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691/*
692 * Debug traps and NMI can happen at the one SYSENTER instruction
693 * that sets up the real kernel stack. Check here, since we can't
694 * allow the wrong stack to be used.
695 *
696 * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
697 * already pushed 3 words if it hits on the sysenter instruction:
698 * eflags, cs and eip.
699 *
700 * We just load the right stack, and push the three (known) values
701 * by hand onto the new stack - while updating the return eip past
702 * the instruction that would have done it for sysenter.
703 */
704#define FIX_STACK(offset, ok, label) \
705 cmpw $__KERNEL_CS,4(%esp); \
706 jne ok; \
707label: \
708 movl TSS_sysenter_esp0+offset(%esp),%esp; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200709 CFI_DEF_CFA esp, 0; \
710 CFI_UNDEFINED eip; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 pushfl; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200712 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 pushl $__KERNEL_CS; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200714 CFI_ADJUST_CFA_OFFSET 4; \
715 pushl $sysenter_past_esp; \
716 CFI_ADJUST_CFA_OFFSET 4; \
717 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700719KPROBE_ENTRY(debug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200720 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 cmpl $sysenter_entry,(%esp)
722 jne debug_stack_correct
723 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
724debug_stack_correct:
725 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200726 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 SAVE_ALL
728 xorl %edx,%edx # error code 0
729 movl %esp,%eax # pt_regs pointer
730 call do_debug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200732 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200733KPROBE_END(debug)
734
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735/*
736 * NMI is doubly nasty. It can happen _while_ we're handling
737 * a debug fault, and the debug fault hasn't yet been able to
738 * clear up the stack. So we first check whether we got an
739 * NMI on the sysenter entry path, but after that we need to
740 * check whether we got an NMI on the debug path where the debug
741 * fault happened on the sysenter path.
742 */
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200743KPROBE_ENTRY(nmi)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200744 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200746 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 movl %ss, %eax
748 cmpw $__ESPFIX_SS, %ax
749 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200750 CFI_ADJUST_CFA_OFFSET -4
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100751 je nmi_espfix_stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 cmpl $sysenter_entry,(%esp)
753 je nmi_stack_fixup
754 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200755 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 movl %esp,%eax
757 /* Do not access memory above the end of our stack page,
758 * it might not exist.
759 */
760 andl $(THREAD_SIZE-1),%eax
761 cmpl $(THREAD_SIZE-20),%eax
762 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200763 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 jae nmi_stack_correct
765 cmpl $sysenter_entry,12(%esp)
766 je nmi_debug_stack_check
767nmi_stack_correct:
Chuck Ebberta549b862006-09-26 10:52:37 +0200768 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200770 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 SAVE_ALL
772 xorl %edx,%edx # zero error code
773 movl %esp,%eax # pt_regs pointer
774 call do_nmi
Ingo Molnar55f327f2006-07-03 00:24:43 -0700775 jmp restore_nocheck_notrace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200776 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778nmi_stack_fixup:
Chuck Ebberta549b862006-09-26 10:52:37 +0200779 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 FIX_STACK(12,nmi_stack_correct, 1)
781 jmp nmi_stack_correct
Chuck Ebberta549b862006-09-26 10:52:37 +0200782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783nmi_debug_stack_check:
Chuck Ebberta549b862006-09-26 10:52:37 +0200784 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 cmpw $__KERNEL_CS,16(%esp)
786 jne nmi_stack_correct
Jan Beuliche2718202005-11-13 16:06:52 -0800787 cmpl $debug,(%esp)
788 jb nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 cmpl $debug_esp_fix_insn,(%esp)
Jan Beuliche2718202005-11-13 16:06:52 -0800790 ja nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 FIX_STACK(24,nmi_stack_correct, 1)
792 jmp nmi_stack_correct
793
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100794nmi_espfix_stack:
Chuck Ebberta549b862006-09-26 10:52:37 +0200795 /* We have a RING0_INT_FRAME here.
796 *
797 * create the pointer to lss back
798 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 pushl %ss
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200800 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 pushl %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200802 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 addw $4, (%esp)
804 /* copy the iret frame of 12 bytes */
805 .rept 3
806 pushl 16(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200807 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 .endr
809 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200810 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 SAVE_ALL
812 FIXUP_ESPFIX_STACK # %eax == %esp
813 xorl %edx,%edx # zero error code
814 call do_nmi
815 RESTORE_REGS
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100816 lss 12+4(%esp), %esp # back to espfix stack
817 CFI_ADJUST_CFA_OFFSET -24
Rusty Russell0da5db32006-09-26 10:52:39 +02008181: INTERRUPT_RETURN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200819 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820.section __ex_table,"a"
821 .align 4
822 .long 1b,iret_exc
823.previous
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200824KPROBE_END(nmi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700826KPROBE_ENTRY(int3)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200827 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200829 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 SAVE_ALL
831 xorl %edx,%edx # zero error code
832 movl %esp,%eax # pt_regs pointer
833 call do_int3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200835 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200836KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200839 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200841 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 pushl $do_overflow
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200843 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200845 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200848 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200850 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 pushl $do_bounds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200852 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200854 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
856ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200857 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200859 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 pushl $do_invalid_op
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(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200866 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200868 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 pushl $do_coprocessor_segment_overrun
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200870 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200872 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200875 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 pushl $do_invalid_TSS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200877 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200879 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200882 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 pushl $do_segment_not_present
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200884 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200886 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200889 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 pushl $do_stack_segment
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
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700895KPROBE_ENTRY(general_protection)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200896 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 pushl $do_general_protection
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200898 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200900 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200901KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200904 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200906 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200908 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200910ENTRY(divide_error)
911 RING0_INT_FRAME
912 pushl $0 # no error code
913 CFI_ADJUST_CFA_OFFSET 4
914 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200915 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200917 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919#ifdef CONFIG_X86_MCE
920ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200921 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200923 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200925 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200927 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928#endif
929
930ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200931 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200933 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200935 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200937 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Jan Beulich176a2712006-06-26 13:57:41 +0200939#ifdef CONFIG_STACK_UNWIND
940ENTRY(arch_unwind_init_running)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200941 CFI_STARTPROC
Jan Beulich176a2712006-06-26 13:57:41 +0200942 movl 4(%esp), %edx
943 movl (%esp), %ecx
944 leal 4(%esp), %eax
945 movl %ebx, EBX(%edx)
946 xorl %ebx, %ebx
947 movl %ebx, ECX(%edx)
948 movl %ebx, EDX(%edx)
949 movl %esi, ESI(%edx)
950 movl %edi, EDI(%edx)
951 movl %ebp, EBP(%edx)
952 movl %ebx, EAX(%edx)
953 movl $__USER_DS, DS(%edx)
954 movl $__USER_DS, ES(%edx)
955 movl %ebx, ORIG_EAX(%edx)
956 movl %ecx, EIP(%edx)
957 movl 12(%esp), %ecx
958 movl $__KERNEL_CS, CS(%edx)
959 movl %ebx, EFLAGS(%edx)
960 movl %eax, OLDESP(%edx)
961 movl 8(%esp), %eax
962 movl %ecx, 8(%esp)
963 movl EBX(%edx), %ebx
964 movl $__KERNEL_DS, OLDSS(%edx)
965 jmpl *%eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200966 CFI_ENDPROC
Jan Beulich176a2712006-06-26 13:57:41 +0200967ENDPROC(arch_unwind_init_running)
968#endif
969
Andi Kleen02ba1a32006-09-26 10:52:35 +0200970ENTRY(kernel_thread_helper)
971 pushl $0 # fake return address for unwinder
972 CFI_STARTPROC
973 movl %edx,%eax
974 push %edx
975 CFI_ADJUST_CFA_OFFSET 4
976 call *%ebx
977 push %eax
978 CFI_ADJUST_CFA_OFFSET 4
979 call do_exit
980 CFI_ENDPROC
981ENDPROC(kernel_thread_helper)
982
Arjan van de Venbb152f52006-01-06 00:12:05 -0800983.section .rodata,"a"
Paolo 'Blaisorblade' Giarrusso5e7b83f2005-05-01 08:58:55 -0700984#include "syscall_table.S"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986syscall_table_size=(.-sys_call_table)