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