mm: drop unneeded pgdat argument from free_area_init_node()
[deliverable/linux.git] / arch / x86 / kernel / entry_32.S
1 /*
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 *
17 * Stack layout in 'syscall_exit':
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
32 * 24(%esp) - %fs
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
39 *
40 * "current" is in register %ebx during any slow entries.
41 */
42
43 #include <linux/linkage.h>
44 #include <asm/thread_info.h>
45 #include <asm/irqflags.h>
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>
51 #include <asm/percpu.h>
52 #include <asm/dwarf2.h>
53 #include <asm/processor-flags.h>
54 #include <asm/ftrace.h>
55 #include <asm/irq_vectors.h>
56
57 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
58 #include <linux/elf-em.h>
59 #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
60 #define __AUDIT_ARCH_LE 0x40000000
61
62 #ifndef CONFIG_AUDITSYSCALL
63 #define sysenter_audit syscall_trace_entry
64 #define sysexit_audit syscall_exit_work
65 #endif
66
67 /*
68 * We use macros for low-level operations which need to be overridden
69 * for paravirtualization. The following will never clobber any registers:
70 * INTERRUPT_RETURN (aka. "iret")
71 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
72 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
73 *
74 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
75 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
76 * Allowing a register to be clobbered can shrink the paravirt replacement
77 * enough to patch inline, increasing performance.
78 */
79
80 #define nr_syscalls ((syscall_table_size)/4)
81
82 #ifdef CONFIG_PREEMPT
83 #define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
84 #else
85 #define preempt_stop(clobbers)
86 #define resume_kernel restore_nocheck
87 #endif
88
89 .macro TRACE_IRQS_IRET
90 #ifdef CONFIG_TRACE_IRQFLAGS
91 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
92 jz 1f
93 TRACE_IRQS_ON
94 1:
95 #endif
96 .endm
97
98 #ifdef CONFIG_VM86
99 #define resume_userspace_sig check_userspace
100 #else
101 #define resume_userspace_sig resume_userspace
102 #endif
103
104 #define SAVE_ALL \
105 cld; \
106 pushl %fs; \
107 CFI_ADJUST_CFA_OFFSET 4;\
108 /*CFI_REL_OFFSET fs, 0;*/\
109 pushl %es; \
110 CFI_ADJUST_CFA_OFFSET 4;\
111 /*CFI_REL_OFFSET es, 0;*/\
112 pushl %ds; \
113 CFI_ADJUST_CFA_OFFSET 4;\
114 /*CFI_REL_OFFSET ds, 0;*/\
115 pushl %eax; \
116 CFI_ADJUST_CFA_OFFSET 4;\
117 CFI_REL_OFFSET eax, 0;\
118 pushl %ebp; \
119 CFI_ADJUST_CFA_OFFSET 4;\
120 CFI_REL_OFFSET ebp, 0;\
121 pushl %edi; \
122 CFI_ADJUST_CFA_OFFSET 4;\
123 CFI_REL_OFFSET edi, 0;\
124 pushl %esi; \
125 CFI_ADJUST_CFA_OFFSET 4;\
126 CFI_REL_OFFSET esi, 0;\
127 pushl %edx; \
128 CFI_ADJUST_CFA_OFFSET 4;\
129 CFI_REL_OFFSET edx, 0;\
130 pushl %ecx; \
131 CFI_ADJUST_CFA_OFFSET 4;\
132 CFI_REL_OFFSET ecx, 0;\
133 pushl %ebx; \
134 CFI_ADJUST_CFA_OFFSET 4;\
135 CFI_REL_OFFSET ebx, 0;\
136 movl $(__USER_DS), %edx; \
137 movl %edx, %ds; \
138 movl %edx, %es; \
139 movl $(__KERNEL_PERCPU), %edx; \
140 movl %edx, %fs
141
142 #define RESTORE_INT_REGS \
143 popl %ebx; \
144 CFI_ADJUST_CFA_OFFSET -4;\
145 CFI_RESTORE ebx;\
146 popl %ecx; \
147 CFI_ADJUST_CFA_OFFSET -4;\
148 CFI_RESTORE ecx;\
149 popl %edx; \
150 CFI_ADJUST_CFA_OFFSET -4;\
151 CFI_RESTORE edx;\
152 popl %esi; \
153 CFI_ADJUST_CFA_OFFSET -4;\
154 CFI_RESTORE esi;\
155 popl %edi; \
156 CFI_ADJUST_CFA_OFFSET -4;\
157 CFI_RESTORE edi;\
158 popl %ebp; \
159 CFI_ADJUST_CFA_OFFSET -4;\
160 CFI_RESTORE ebp;\
161 popl %eax; \
162 CFI_ADJUST_CFA_OFFSET -4;\
163 CFI_RESTORE eax
164
165 #define RESTORE_REGS \
166 RESTORE_INT_REGS; \
167 1: popl %ds; \
168 CFI_ADJUST_CFA_OFFSET -4;\
169 /*CFI_RESTORE ds;*/\
170 2: popl %es; \
171 CFI_ADJUST_CFA_OFFSET -4;\
172 /*CFI_RESTORE es;*/\
173 3: popl %fs; \
174 CFI_ADJUST_CFA_OFFSET -4;\
175 /*CFI_RESTORE fs;*/\
176 .pushsection .fixup,"ax"; \
177 4: movl $0,(%esp); \
178 jmp 1b; \
179 5: movl $0,(%esp); \
180 jmp 2b; \
181 6: movl $0,(%esp); \
182 jmp 3b; \
183 .section __ex_table,"a";\
184 .align 4; \
185 .long 1b,4b; \
186 .long 2b,5b; \
187 .long 3b,6b; \
188 .popsection
189
190 #define RING0_INT_FRAME \
191 CFI_STARTPROC simple;\
192 CFI_SIGNAL_FRAME;\
193 CFI_DEF_CFA esp, 3*4;\
194 /*CFI_OFFSET cs, -2*4;*/\
195 CFI_OFFSET eip, -3*4
196
197 #define RING0_EC_FRAME \
198 CFI_STARTPROC simple;\
199 CFI_SIGNAL_FRAME;\
200 CFI_DEF_CFA esp, 4*4;\
201 /*CFI_OFFSET cs, -2*4;*/\
202 CFI_OFFSET eip, -3*4
203
204 #define RING0_PTREGS_FRAME \
205 CFI_STARTPROC simple;\
206 CFI_SIGNAL_FRAME;\
207 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
208 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
209 CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
210 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
211 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
212 CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
213 CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
214 CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
215 CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
216 CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
217 CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
218 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
219
220 ENTRY(ret_from_fork)
221 CFI_STARTPROC
222 pushl %eax
223 CFI_ADJUST_CFA_OFFSET 4
224 call schedule_tail
225 GET_THREAD_INFO(%ebp)
226 popl %eax
227 CFI_ADJUST_CFA_OFFSET -4
228 pushl $0x0202 # Reset kernel eflags
229 CFI_ADJUST_CFA_OFFSET 4
230 popfl
231 CFI_ADJUST_CFA_OFFSET -4
232 jmp syscall_exit
233 CFI_ENDPROC
234 END(ret_from_fork)
235
236 /*
237 * Return to user mode is not as complex as all this looks,
238 * but we want the default path for a system call return to
239 * go as quickly as possible which is why some of this is
240 * less clear than it otherwise should be.
241 */
242
243 # userspace resumption stub bypassing syscall exit tracing
244 ALIGN
245 RING0_PTREGS_FRAME
246 ret_from_exception:
247 preempt_stop(CLBR_ANY)
248 ret_from_intr:
249 GET_THREAD_INFO(%ebp)
250 check_userspace:
251 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
252 movb PT_CS(%esp), %al
253 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
254 cmpl $USER_RPL, %eax
255 jb resume_kernel # not returning to v8086 or userspace
256
257 ENTRY(resume_userspace)
258 LOCKDEP_SYS_EXIT
259 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
260 # setting need_resched or sigpending
261 # between sampling and the iret
262 TRACE_IRQS_OFF
263 movl TI_flags(%ebp), %ecx
264 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
265 # int/exception return?
266 jne work_pending
267 jmp restore_all
268 END(ret_from_exception)
269
270 #ifdef CONFIG_PREEMPT
271 ENTRY(resume_kernel)
272 DISABLE_INTERRUPTS(CLBR_ANY)
273 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
274 jnz restore_nocheck
275 need_resched:
276 movl TI_flags(%ebp), %ecx # need_resched set ?
277 testb $_TIF_NEED_RESCHED, %cl
278 jz restore_all
279 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
280 jz restore_all
281 call preempt_schedule_irq
282 jmp need_resched
283 END(resume_kernel)
284 #endif
285 CFI_ENDPROC
286
287 /* SYSENTER_RETURN points to after the "sysenter" instruction in
288 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
289
290 # sysenter call handler stub
291 ENTRY(ia32_sysenter_target)
292 CFI_STARTPROC simple
293 CFI_SIGNAL_FRAME
294 CFI_DEF_CFA esp, 0
295 CFI_REGISTER esp, ebp
296 movl TSS_sysenter_sp0(%esp),%esp
297 sysenter_past_esp:
298 /*
299 * Interrupts are disabled here, but we can't trace it until
300 * enough kernel state to call TRACE_IRQS_OFF can be called - but
301 * we immediately enable interrupts at that point anyway.
302 */
303 pushl $(__USER_DS)
304 CFI_ADJUST_CFA_OFFSET 4
305 /*CFI_REL_OFFSET ss, 0*/
306 pushl %ebp
307 CFI_ADJUST_CFA_OFFSET 4
308 CFI_REL_OFFSET esp, 0
309 pushfl
310 orl $X86_EFLAGS_IF, (%esp)
311 CFI_ADJUST_CFA_OFFSET 4
312 pushl $(__USER_CS)
313 CFI_ADJUST_CFA_OFFSET 4
314 /*CFI_REL_OFFSET cs, 0*/
315 /*
316 * Push current_thread_info()->sysenter_return to the stack.
317 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
318 * pushed above; +8 corresponds to copy_thread's esp0 setting.
319 */
320 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
321 CFI_ADJUST_CFA_OFFSET 4
322 CFI_REL_OFFSET eip, 0
323
324 pushl %eax
325 CFI_ADJUST_CFA_OFFSET 4
326 SAVE_ALL
327 ENABLE_INTERRUPTS(CLBR_NONE)
328
329 /*
330 * Load the potential sixth argument from user stack.
331 * Careful about security.
332 */
333 cmpl $__PAGE_OFFSET-3,%ebp
334 jae syscall_fault
335 1: movl (%ebp),%ebp
336 movl %ebp,PT_EBP(%esp)
337 .section __ex_table,"a"
338 .align 4
339 .long 1b,syscall_fault
340 .previous
341
342 GET_THREAD_INFO(%ebp)
343
344 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
345 testw $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
346 jnz sysenter_audit
347 sysenter_do_call:
348 cmpl $(nr_syscalls), %eax
349 jae syscall_badsys
350 call *sys_call_table(,%eax,4)
351 movl %eax,PT_EAX(%esp)
352 LOCKDEP_SYS_EXIT
353 DISABLE_INTERRUPTS(CLBR_ANY)
354 TRACE_IRQS_OFF
355 movl TI_flags(%ebp), %ecx
356 testw $_TIF_ALLWORK_MASK, %cx
357 jne sysexit_audit
358 sysenter_exit:
359 /* if something modifies registers it must also disable sysexit */
360 movl PT_EIP(%esp), %edx
361 movl PT_OLDESP(%esp), %ecx
362 xorl %ebp,%ebp
363 TRACE_IRQS_ON
364 1: mov PT_FS(%esp), %fs
365 ENABLE_INTERRUPTS_SYSEXIT
366
367 #ifdef CONFIG_AUDITSYSCALL
368 sysenter_audit:
369 testw $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
370 jnz syscall_trace_entry
371 addl $4,%esp
372 CFI_ADJUST_CFA_OFFSET -4
373 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
374 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
375 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
376 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
377 movl %eax,%edx /* 2nd arg: syscall number */
378 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
379 call audit_syscall_entry
380 pushl %ebx
381 CFI_ADJUST_CFA_OFFSET 4
382 movl PT_EAX(%esp),%eax /* reload syscall number */
383 jmp sysenter_do_call
384
385 sysexit_audit:
386 testw $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %cx
387 jne syscall_exit_work
388 TRACE_IRQS_ON
389 ENABLE_INTERRUPTS(CLBR_ANY)
390 movl %eax,%edx /* second arg, syscall return value */
391 cmpl $0,%eax /* is it < 0? */
392 setl %al /* 1 if so, 0 if not */
393 movzbl %al,%eax /* zero-extend that */
394 inc %eax /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
395 call audit_syscall_exit
396 DISABLE_INTERRUPTS(CLBR_ANY)
397 TRACE_IRQS_OFF
398 movl TI_flags(%ebp), %ecx
399 testw $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %cx
400 jne syscall_exit_work
401 movl PT_EAX(%esp),%eax /* reload syscall return value */
402 jmp sysenter_exit
403 #endif
404
405 CFI_ENDPROC
406 .pushsection .fixup,"ax"
407 2: movl $0,PT_FS(%esp)
408 jmp 1b
409 .section __ex_table,"a"
410 .align 4
411 .long 1b,2b
412 .popsection
413 ENDPROC(ia32_sysenter_target)
414
415 # system call handler stub
416 ENTRY(system_call)
417 RING0_INT_FRAME # can't unwind into user space anyway
418 pushl %eax # save orig_eax
419 CFI_ADJUST_CFA_OFFSET 4
420 SAVE_ALL
421 GET_THREAD_INFO(%ebp)
422 # system call tracing in operation / emulation
423 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
424 testw $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
425 jnz syscall_trace_entry
426 cmpl $(nr_syscalls), %eax
427 jae syscall_badsys
428 syscall_call:
429 call *sys_call_table(,%eax,4)
430 movl %eax,PT_EAX(%esp) # store the return value
431 syscall_exit:
432 LOCKDEP_SYS_EXIT
433 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
434 # setting need_resched or sigpending
435 # between sampling and the iret
436 TRACE_IRQS_OFF
437 movl TI_flags(%ebp), %ecx
438 testw $_TIF_ALLWORK_MASK, %cx # current->work
439 jne syscall_exit_work
440
441 restore_all:
442 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
443 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
444 # are returning to the kernel.
445 # See comments in process.c:copy_thread() for details.
446 movb PT_OLDSS(%esp), %ah
447 movb PT_CS(%esp), %al
448 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
449 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
450 CFI_REMEMBER_STATE
451 je ldt_ss # returning to user-space with LDT SS
452 restore_nocheck:
453 TRACE_IRQS_IRET
454 restore_nocheck_notrace:
455 RESTORE_REGS
456 addl $4, %esp # skip orig_eax/error_code
457 CFI_ADJUST_CFA_OFFSET -4
458 irq_return:
459 INTERRUPT_RETURN
460 .section .fixup,"ax"
461 ENTRY(iret_exc)
462 pushl $0 # no error code
463 pushl $do_iret_error
464 jmp error_code
465 .previous
466 .section __ex_table,"a"
467 .align 4
468 .long irq_return,iret_exc
469 .previous
470
471 CFI_RESTORE_STATE
472 ldt_ss:
473 larl PT_OLDSS(%esp), %eax
474 jnz restore_nocheck
475 testl $0x00400000, %eax # returning to 32bit stack?
476 jnz restore_nocheck # allright, normal return
477
478 #ifdef CONFIG_PARAVIRT
479 /*
480 * The kernel can't run on a non-flat stack if paravirt mode
481 * is active. Rather than try to fixup the high bits of
482 * ESP, bypass this code entirely. This may break DOSemu
483 * and/or Wine support in a paravirt VM, although the option
484 * is still available to implement the setting of the high
485 * 16-bits in the INTERRUPT_RETURN paravirt-op.
486 */
487 cmpl $0, pv_info+PARAVIRT_enabled
488 jne restore_nocheck
489 #endif
490
491 /* If returning to userspace with 16bit stack,
492 * try to fix the higher word of ESP, as the CPU
493 * won't restore it.
494 * This is an "official" bug of all the x86-compatible
495 * CPUs, which we can try to work around to make
496 * dosemu and wine happy. */
497 movl PT_OLDESP(%esp), %eax
498 movl %esp, %edx
499 call patch_espfix_desc
500 pushl $__ESPFIX_SS
501 CFI_ADJUST_CFA_OFFSET 4
502 pushl %eax
503 CFI_ADJUST_CFA_OFFSET 4
504 DISABLE_INTERRUPTS(CLBR_EAX)
505 TRACE_IRQS_OFF
506 lss (%esp), %esp
507 CFI_ADJUST_CFA_OFFSET -8
508 jmp restore_nocheck
509 CFI_ENDPROC
510 ENDPROC(system_call)
511
512 # perform work that needs to be done immediately before resumption
513 ALIGN
514 RING0_PTREGS_FRAME # can't unwind into user space anyway
515 work_pending:
516 testb $_TIF_NEED_RESCHED, %cl
517 jz work_notifysig
518 work_resched:
519 call schedule
520 LOCKDEP_SYS_EXIT
521 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
522 # setting need_resched or sigpending
523 # between sampling and the iret
524 TRACE_IRQS_OFF
525 movl TI_flags(%ebp), %ecx
526 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
527 # than syscall tracing?
528 jz restore_all
529 testb $_TIF_NEED_RESCHED, %cl
530 jnz work_resched
531
532 work_notifysig: # deal with pending signals and
533 # notify-resume requests
534 #ifdef CONFIG_VM86
535 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
536 movl %esp, %eax
537 jne work_notifysig_v86 # returning to kernel-space or
538 # vm86-space
539 xorl %edx, %edx
540 call do_notify_resume
541 jmp resume_userspace_sig
542
543 ALIGN
544 work_notifysig_v86:
545 pushl %ecx # save ti_flags for do_notify_resume
546 CFI_ADJUST_CFA_OFFSET 4
547 call save_v86_state # %eax contains pt_regs pointer
548 popl %ecx
549 CFI_ADJUST_CFA_OFFSET -4
550 movl %eax, %esp
551 #else
552 movl %esp, %eax
553 #endif
554 xorl %edx, %edx
555 call do_notify_resume
556 jmp resume_userspace_sig
557 END(work_pending)
558
559 # perform syscall exit tracing
560 ALIGN
561 syscall_trace_entry:
562 movl $-ENOSYS,PT_EAX(%esp)
563 movl %esp, %eax
564 call syscall_trace_enter
565 /* What it returned is what we'll actually use. */
566 cmpl $(nr_syscalls), %eax
567 jnae syscall_call
568 jmp syscall_exit
569 END(syscall_trace_entry)
570
571 # perform syscall exit tracing
572 ALIGN
573 syscall_exit_work:
574 testb $_TIF_WORK_SYSCALL_EXIT, %cl
575 jz work_pending
576 TRACE_IRQS_ON
577 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
578 # schedule() instead
579 movl %esp, %eax
580 call syscall_trace_leave
581 jmp resume_userspace
582 END(syscall_exit_work)
583 CFI_ENDPROC
584
585 RING0_INT_FRAME # can't unwind into user space anyway
586 syscall_fault:
587 GET_THREAD_INFO(%ebp)
588 movl $-EFAULT,PT_EAX(%esp)
589 jmp resume_userspace
590 END(syscall_fault)
591
592 syscall_badsys:
593 movl $-ENOSYS,PT_EAX(%esp)
594 jmp resume_userspace
595 END(syscall_badsys)
596 CFI_ENDPROC
597
598 #define FIXUP_ESPFIX_STACK \
599 /* since we are on a wrong stack, we cant make it a C code :( */ \
600 PER_CPU(gdt_page, %ebx); \
601 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
602 addl %esp, %eax; \
603 pushl $__KERNEL_DS; \
604 CFI_ADJUST_CFA_OFFSET 4; \
605 pushl %eax; \
606 CFI_ADJUST_CFA_OFFSET 4; \
607 lss (%esp), %esp; \
608 CFI_ADJUST_CFA_OFFSET -8;
609 #define UNWIND_ESPFIX_STACK \
610 movl %ss, %eax; \
611 /* see if on espfix stack */ \
612 cmpw $__ESPFIX_SS, %ax; \
613 jne 27f; \
614 movl $__KERNEL_DS, %eax; \
615 movl %eax, %ds; \
616 movl %eax, %es; \
617 /* switch to normal stack */ \
618 FIXUP_ESPFIX_STACK; \
619 27:;
620
621 /*
622 * Build the entry stubs and pointer table with
623 * some assembler magic.
624 */
625 .section .rodata,"a"
626 ENTRY(interrupt)
627 .text
628
629 ENTRY(irq_entries_start)
630 RING0_INT_FRAME
631 vector=0
632 .rept NR_IRQS
633 ALIGN
634 .if vector
635 CFI_ADJUST_CFA_OFFSET -4
636 .endif
637 1: pushl $~(vector)
638 CFI_ADJUST_CFA_OFFSET 4
639 jmp common_interrupt
640 .previous
641 .long 1b
642 .text
643 vector=vector+1
644 .endr
645 END(irq_entries_start)
646
647 .previous
648 END(interrupt)
649 .previous
650
651 /*
652 * the CPU automatically disables interrupts when executing an IRQ vector,
653 * so IRQ-flags tracing has to follow that:
654 */
655 ALIGN
656 common_interrupt:
657 SAVE_ALL
658 TRACE_IRQS_OFF
659 movl %esp,%eax
660 call do_IRQ
661 jmp ret_from_intr
662 ENDPROC(common_interrupt)
663 CFI_ENDPROC
664
665 #define BUILD_INTERRUPT(name, nr) \
666 ENTRY(name) \
667 RING0_INT_FRAME; \
668 pushl $~(nr); \
669 CFI_ADJUST_CFA_OFFSET 4; \
670 SAVE_ALL; \
671 TRACE_IRQS_OFF \
672 movl %esp,%eax; \
673 call smp_##name; \
674 jmp ret_from_intr; \
675 CFI_ENDPROC; \
676 ENDPROC(name)
677
678 /* The include is where all of the SMP etc. interrupts come from */
679 #include "entry_arch.h"
680
681 KPROBE_ENTRY(page_fault)
682 RING0_EC_FRAME
683 pushl $do_page_fault
684 CFI_ADJUST_CFA_OFFSET 4
685 ALIGN
686 error_code:
687 /* the function address is in %fs's slot on the stack */
688 pushl %es
689 CFI_ADJUST_CFA_OFFSET 4
690 /*CFI_REL_OFFSET es, 0*/
691 pushl %ds
692 CFI_ADJUST_CFA_OFFSET 4
693 /*CFI_REL_OFFSET ds, 0*/
694 pushl %eax
695 CFI_ADJUST_CFA_OFFSET 4
696 CFI_REL_OFFSET eax, 0
697 pushl %ebp
698 CFI_ADJUST_CFA_OFFSET 4
699 CFI_REL_OFFSET ebp, 0
700 pushl %edi
701 CFI_ADJUST_CFA_OFFSET 4
702 CFI_REL_OFFSET edi, 0
703 pushl %esi
704 CFI_ADJUST_CFA_OFFSET 4
705 CFI_REL_OFFSET esi, 0
706 pushl %edx
707 CFI_ADJUST_CFA_OFFSET 4
708 CFI_REL_OFFSET edx, 0
709 pushl %ecx
710 CFI_ADJUST_CFA_OFFSET 4
711 CFI_REL_OFFSET ecx, 0
712 pushl %ebx
713 CFI_ADJUST_CFA_OFFSET 4
714 CFI_REL_OFFSET ebx, 0
715 cld
716 pushl %fs
717 CFI_ADJUST_CFA_OFFSET 4
718 /*CFI_REL_OFFSET fs, 0*/
719 movl $(__KERNEL_PERCPU), %ecx
720 movl %ecx, %fs
721 UNWIND_ESPFIX_STACK
722 popl %ecx
723 CFI_ADJUST_CFA_OFFSET -4
724 /*CFI_REGISTER es, ecx*/
725 movl PT_FS(%esp), %edi # get the function address
726 movl PT_ORIG_EAX(%esp), %edx # get the error code
727 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
728 mov %ecx, PT_FS(%esp)
729 /*CFI_REL_OFFSET fs, ES*/
730 movl $(__USER_DS), %ecx
731 movl %ecx, %ds
732 movl %ecx, %es
733 movl %esp,%eax # pt_regs pointer
734 call *%edi
735 jmp ret_from_exception
736 CFI_ENDPROC
737 KPROBE_END(page_fault)
738
739 ENTRY(coprocessor_error)
740 RING0_INT_FRAME
741 pushl $0
742 CFI_ADJUST_CFA_OFFSET 4
743 pushl $do_coprocessor_error
744 CFI_ADJUST_CFA_OFFSET 4
745 jmp error_code
746 CFI_ENDPROC
747 END(coprocessor_error)
748
749 ENTRY(simd_coprocessor_error)
750 RING0_INT_FRAME
751 pushl $0
752 CFI_ADJUST_CFA_OFFSET 4
753 pushl $do_simd_coprocessor_error
754 CFI_ADJUST_CFA_OFFSET 4
755 jmp error_code
756 CFI_ENDPROC
757 END(simd_coprocessor_error)
758
759 ENTRY(device_not_available)
760 RING0_INT_FRAME
761 pushl $-1 # mark this as an int
762 CFI_ADJUST_CFA_OFFSET 4
763 SAVE_ALL
764 GET_CR0_INTO_EAX
765 testl $0x4, %eax # EM (math emulation bit)
766 jne device_not_available_emulate
767 preempt_stop(CLBR_ANY)
768 call math_state_restore
769 jmp ret_from_exception
770 device_not_available_emulate:
771 pushl $0 # temporary storage for ORIG_EIP
772 CFI_ADJUST_CFA_OFFSET 4
773 call math_emulate
774 addl $4, %esp
775 CFI_ADJUST_CFA_OFFSET -4
776 jmp ret_from_exception
777 CFI_ENDPROC
778 END(device_not_available)
779
780 /*
781 * Debug traps and NMI can happen at the one SYSENTER instruction
782 * that sets up the real kernel stack. Check here, since we can't
783 * allow the wrong stack to be used.
784 *
785 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
786 * already pushed 3 words if it hits on the sysenter instruction:
787 * eflags, cs and eip.
788 *
789 * We just load the right stack, and push the three (known) values
790 * by hand onto the new stack - while updating the return eip past
791 * the instruction that would have done it for sysenter.
792 */
793 #define FIX_STACK(offset, ok, label) \
794 cmpw $__KERNEL_CS,4(%esp); \
795 jne ok; \
796 label: \
797 movl TSS_sysenter_sp0+offset(%esp),%esp; \
798 CFI_DEF_CFA esp, 0; \
799 CFI_UNDEFINED eip; \
800 pushfl; \
801 CFI_ADJUST_CFA_OFFSET 4; \
802 pushl $__KERNEL_CS; \
803 CFI_ADJUST_CFA_OFFSET 4; \
804 pushl $sysenter_past_esp; \
805 CFI_ADJUST_CFA_OFFSET 4; \
806 CFI_REL_OFFSET eip, 0
807
808 KPROBE_ENTRY(debug)
809 RING0_INT_FRAME
810 cmpl $ia32_sysenter_target,(%esp)
811 jne debug_stack_correct
812 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
813 debug_stack_correct:
814 pushl $-1 # mark this as an int
815 CFI_ADJUST_CFA_OFFSET 4
816 SAVE_ALL
817 xorl %edx,%edx # error code 0
818 movl %esp,%eax # pt_regs pointer
819 call do_debug
820 jmp ret_from_exception
821 CFI_ENDPROC
822 KPROBE_END(debug)
823
824 /*
825 * NMI is doubly nasty. It can happen _while_ we're handling
826 * a debug fault, and the debug fault hasn't yet been able to
827 * clear up the stack. So we first check whether we got an
828 * NMI on the sysenter entry path, but after that we need to
829 * check whether we got an NMI on the debug path where the debug
830 * fault happened on the sysenter path.
831 */
832 KPROBE_ENTRY(nmi)
833 RING0_INT_FRAME
834 pushl %eax
835 CFI_ADJUST_CFA_OFFSET 4
836 movl %ss, %eax
837 cmpw $__ESPFIX_SS, %ax
838 popl %eax
839 CFI_ADJUST_CFA_OFFSET -4
840 je nmi_espfix_stack
841 cmpl $ia32_sysenter_target,(%esp)
842 je nmi_stack_fixup
843 pushl %eax
844 CFI_ADJUST_CFA_OFFSET 4
845 movl %esp,%eax
846 /* Do not access memory above the end of our stack page,
847 * it might not exist.
848 */
849 andl $(THREAD_SIZE-1),%eax
850 cmpl $(THREAD_SIZE-20),%eax
851 popl %eax
852 CFI_ADJUST_CFA_OFFSET -4
853 jae nmi_stack_correct
854 cmpl $ia32_sysenter_target,12(%esp)
855 je nmi_debug_stack_check
856 nmi_stack_correct:
857 /* We have a RING0_INT_FRAME here */
858 pushl %eax
859 CFI_ADJUST_CFA_OFFSET 4
860 SAVE_ALL
861 xorl %edx,%edx # zero error code
862 movl %esp,%eax # pt_regs pointer
863 call do_nmi
864 jmp restore_nocheck_notrace
865 CFI_ENDPROC
866
867 nmi_stack_fixup:
868 RING0_INT_FRAME
869 FIX_STACK(12,nmi_stack_correct, 1)
870 jmp nmi_stack_correct
871
872 nmi_debug_stack_check:
873 /* We have a RING0_INT_FRAME here */
874 cmpw $__KERNEL_CS,16(%esp)
875 jne nmi_stack_correct
876 cmpl $debug,(%esp)
877 jb nmi_stack_correct
878 cmpl $debug_esp_fix_insn,(%esp)
879 ja nmi_stack_correct
880 FIX_STACK(24,nmi_stack_correct, 1)
881 jmp nmi_stack_correct
882
883 nmi_espfix_stack:
884 /* We have a RING0_INT_FRAME here.
885 *
886 * create the pointer to lss back
887 */
888 pushl %ss
889 CFI_ADJUST_CFA_OFFSET 4
890 pushl %esp
891 CFI_ADJUST_CFA_OFFSET 4
892 addw $4, (%esp)
893 /* copy the iret frame of 12 bytes */
894 .rept 3
895 pushl 16(%esp)
896 CFI_ADJUST_CFA_OFFSET 4
897 .endr
898 pushl %eax
899 CFI_ADJUST_CFA_OFFSET 4
900 SAVE_ALL
901 FIXUP_ESPFIX_STACK # %eax == %esp
902 xorl %edx,%edx # zero error code
903 call do_nmi
904 RESTORE_REGS
905 lss 12+4(%esp), %esp # back to espfix stack
906 CFI_ADJUST_CFA_OFFSET -24
907 jmp irq_return
908 CFI_ENDPROC
909 KPROBE_END(nmi)
910
911 #ifdef CONFIG_PARAVIRT
912 ENTRY(native_iret)
913 iret
914 .section __ex_table,"a"
915 .align 4
916 .long native_iret, iret_exc
917 .previous
918 END(native_iret)
919
920 ENTRY(native_irq_enable_sysexit)
921 sti
922 sysexit
923 END(native_irq_enable_sysexit)
924 #endif
925
926 KPROBE_ENTRY(int3)
927 RING0_INT_FRAME
928 pushl $-1 # mark this as an int
929 CFI_ADJUST_CFA_OFFSET 4
930 SAVE_ALL
931 xorl %edx,%edx # zero error code
932 movl %esp,%eax # pt_regs pointer
933 call do_int3
934 jmp ret_from_exception
935 CFI_ENDPROC
936 KPROBE_END(int3)
937
938 ENTRY(overflow)
939 RING0_INT_FRAME
940 pushl $0
941 CFI_ADJUST_CFA_OFFSET 4
942 pushl $do_overflow
943 CFI_ADJUST_CFA_OFFSET 4
944 jmp error_code
945 CFI_ENDPROC
946 END(overflow)
947
948 ENTRY(bounds)
949 RING0_INT_FRAME
950 pushl $0
951 CFI_ADJUST_CFA_OFFSET 4
952 pushl $do_bounds
953 CFI_ADJUST_CFA_OFFSET 4
954 jmp error_code
955 CFI_ENDPROC
956 END(bounds)
957
958 ENTRY(invalid_op)
959 RING0_INT_FRAME
960 pushl $0
961 CFI_ADJUST_CFA_OFFSET 4
962 pushl $do_invalid_op
963 CFI_ADJUST_CFA_OFFSET 4
964 jmp error_code
965 CFI_ENDPROC
966 END(invalid_op)
967
968 ENTRY(coprocessor_segment_overrun)
969 RING0_INT_FRAME
970 pushl $0
971 CFI_ADJUST_CFA_OFFSET 4
972 pushl $do_coprocessor_segment_overrun
973 CFI_ADJUST_CFA_OFFSET 4
974 jmp error_code
975 CFI_ENDPROC
976 END(coprocessor_segment_overrun)
977
978 ENTRY(invalid_TSS)
979 RING0_EC_FRAME
980 pushl $do_invalid_TSS
981 CFI_ADJUST_CFA_OFFSET 4
982 jmp error_code
983 CFI_ENDPROC
984 END(invalid_TSS)
985
986 ENTRY(segment_not_present)
987 RING0_EC_FRAME
988 pushl $do_segment_not_present
989 CFI_ADJUST_CFA_OFFSET 4
990 jmp error_code
991 CFI_ENDPROC
992 END(segment_not_present)
993
994 ENTRY(stack_segment)
995 RING0_EC_FRAME
996 pushl $do_stack_segment
997 CFI_ADJUST_CFA_OFFSET 4
998 jmp error_code
999 CFI_ENDPROC
1000 END(stack_segment)
1001
1002 KPROBE_ENTRY(general_protection)
1003 RING0_EC_FRAME
1004 pushl $do_general_protection
1005 CFI_ADJUST_CFA_OFFSET 4
1006 jmp error_code
1007 CFI_ENDPROC
1008 KPROBE_END(general_protection)
1009
1010 ENTRY(alignment_check)
1011 RING0_EC_FRAME
1012 pushl $do_alignment_check
1013 CFI_ADJUST_CFA_OFFSET 4
1014 jmp error_code
1015 CFI_ENDPROC
1016 END(alignment_check)
1017
1018 ENTRY(divide_error)
1019 RING0_INT_FRAME
1020 pushl $0 # no error code
1021 CFI_ADJUST_CFA_OFFSET 4
1022 pushl $do_divide_error
1023 CFI_ADJUST_CFA_OFFSET 4
1024 jmp error_code
1025 CFI_ENDPROC
1026 END(divide_error)
1027
1028 #ifdef CONFIG_X86_MCE
1029 ENTRY(machine_check)
1030 RING0_INT_FRAME
1031 pushl $0
1032 CFI_ADJUST_CFA_OFFSET 4
1033 pushl machine_check_vector
1034 CFI_ADJUST_CFA_OFFSET 4
1035 jmp error_code
1036 CFI_ENDPROC
1037 END(machine_check)
1038 #endif
1039
1040 ENTRY(spurious_interrupt_bug)
1041 RING0_INT_FRAME
1042 pushl $0
1043 CFI_ADJUST_CFA_OFFSET 4
1044 pushl $do_spurious_interrupt_bug
1045 CFI_ADJUST_CFA_OFFSET 4
1046 jmp error_code
1047 CFI_ENDPROC
1048 END(spurious_interrupt_bug)
1049
1050 ENTRY(kernel_thread_helper)
1051 pushl $0 # fake return address for unwinder
1052 CFI_STARTPROC
1053 movl %edx,%eax
1054 push %edx
1055 CFI_ADJUST_CFA_OFFSET 4
1056 call *%ebx
1057 push %eax
1058 CFI_ADJUST_CFA_OFFSET 4
1059 call do_exit
1060 CFI_ENDPROC
1061 ENDPROC(kernel_thread_helper)
1062
1063 #ifdef CONFIG_XEN
1064 /* Xen doesn't set %esp to be precisely what the normal sysenter
1065 entrypoint expects, so fix it up before using the normal path. */
1066 ENTRY(xen_sysenter_target)
1067 RING0_INT_FRAME
1068 addl $5*4, %esp /* remove xen-provided frame */
1069 CFI_ADJUST_CFA_OFFSET -5*4
1070 jmp sysenter_past_esp
1071 CFI_ENDPROC
1072
1073 ENTRY(xen_hypervisor_callback)
1074 CFI_STARTPROC
1075 pushl $0
1076 CFI_ADJUST_CFA_OFFSET 4
1077 SAVE_ALL
1078 TRACE_IRQS_OFF
1079
1080 /* Check to see if we got the event in the critical
1081 region in xen_iret_direct, after we've reenabled
1082 events and checked for pending events. This simulates
1083 iret instruction's behaviour where it delivers a
1084 pending interrupt when enabling interrupts. */
1085 movl PT_EIP(%esp),%eax
1086 cmpl $xen_iret_start_crit,%eax
1087 jb 1f
1088 cmpl $xen_iret_end_crit,%eax
1089 jae 1f
1090
1091 jmp xen_iret_crit_fixup
1092
1093 ENTRY(xen_do_upcall)
1094 1: mov %esp, %eax
1095 call xen_evtchn_do_upcall
1096 jmp ret_from_intr
1097 CFI_ENDPROC
1098 ENDPROC(xen_hypervisor_callback)
1099
1100 # Hypervisor uses this for application faults while it executes.
1101 # We get here for two reasons:
1102 # 1. Fault while reloading DS, ES, FS or GS
1103 # 2. Fault while executing IRET
1104 # Category 1 we fix up by reattempting the load, and zeroing the segment
1105 # register if the load fails.
1106 # Category 2 we fix up by jumping to do_iret_error. We cannot use the
1107 # normal Linux return path in this case because if we use the IRET hypercall
1108 # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1109 # We distinguish between categories by maintaining a status value in EAX.
1110 ENTRY(xen_failsafe_callback)
1111 CFI_STARTPROC
1112 pushl %eax
1113 CFI_ADJUST_CFA_OFFSET 4
1114 movl $1,%eax
1115 1: mov 4(%esp),%ds
1116 2: mov 8(%esp),%es
1117 3: mov 12(%esp),%fs
1118 4: mov 16(%esp),%gs
1119 testl %eax,%eax
1120 popl %eax
1121 CFI_ADJUST_CFA_OFFSET -4
1122 lea 16(%esp),%esp
1123 CFI_ADJUST_CFA_OFFSET -16
1124 jz 5f
1125 addl $16,%esp
1126 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
1127 5: pushl $0 # EAX == 0 => Category 1 (Bad segment)
1128 CFI_ADJUST_CFA_OFFSET 4
1129 SAVE_ALL
1130 jmp ret_from_exception
1131 CFI_ENDPROC
1132
1133 .section .fixup,"ax"
1134 6: xorl %eax,%eax
1135 movl %eax,4(%esp)
1136 jmp 1b
1137 7: xorl %eax,%eax
1138 movl %eax,8(%esp)
1139 jmp 2b
1140 8: xorl %eax,%eax
1141 movl %eax,12(%esp)
1142 jmp 3b
1143 9: xorl %eax,%eax
1144 movl %eax,16(%esp)
1145 jmp 4b
1146 .previous
1147 .section __ex_table,"a"
1148 .align 4
1149 .long 1b,6b
1150 .long 2b,7b
1151 .long 3b,8b
1152 .long 4b,9b
1153 .previous
1154 ENDPROC(xen_failsafe_callback)
1155
1156 #endif /* CONFIG_XEN */
1157
1158 #ifdef CONFIG_FTRACE
1159 #ifdef CONFIG_DYNAMIC_FTRACE
1160
1161 ENTRY(mcount)
1162 pushl %eax
1163 pushl %ecx
1164 pushl %edx
1165 movl 0xc(%esp), %eax
1166 subl $MCOUNT_INSN_SIZE, %eax
1167
1168 .globl mcount_call
1169 mcount_call:
1170 call ftrace_stub
1171
1172 popl %edx
1173 popl %ecx
1174 popl %eax
1175
1176 ret
1177 END(mcount)
1178
1179 ENTRY(ftrace_caller)
1180 pushl %eax
1181 pushl %ecx
1182 pushl %edx
1183 movl 0xc(%esp), %eax
1184 movl 0x4(%ebp), %edx
1185 subl $MCOUNT_INSN_SIZE, %eax
1186
1187 .globl ftrace_call
1188 ftrace_call:
1189 call ftrace_stub
1190
1191 popl %edx
1192 popl %ecx
1193 popl %eax
1194
1195 .globl ftrace_stub
1196 ftrace_stub:
1197 ret
1198 END(ftrace_caller)
1199
1200 #else /* ! CONFIG_DYNAMIC_FTRACE */
1201
1202 ENTRY(mcount)
1203 cmpl $ftrace_stub, ftrace_trace_function
1204 jnz trace
1205 .globl ftrace_stub
1206 ftrace_stub:
1207 ret
1208
1209 /* taken from glibc */
1210 trace:
1211 pushl %eax
1212 pushl %ecx
1213 pushl %edx
1214 movl 0xc(%esp), %eax
1215 movl 0x4(%ebp), %edx
1216 subl $MCOUNT_INSN_SIZE, %eax
1217
1218 call *ftrace_trace_function
1219
1220 popl %edx
1221 popl %ecx
1222 popl %eax
1223
1224 jmp ftrace_stub
1225 END(mcount)
1226 #endif /* CONFIG_DYNAMIC_FTRACE */
1227 #endif /* CONFIG_FTRACE */
1228
1229 .section .rodata,"a"
1230 #include "syscall_table_32.S"
1231
1232 syscall_table_size=(.-sys_call_table)
This page took 0.07766 seconds and 5 git commands to generate.