x86: traps_xx: modify do_trap
[deliverable/linux.git] / arch / x86 / kernel / traps_32.c
CommitLineData
1da177e4 1/*
1da177e4 2 * Copyright (C) 1991, 1992 Linus Torvalds
a8c1be9d 3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
1da177e4
LT
4 *
5 * Pentium III FXSR, SSE support
6 * Gareth Hughes <gareth@valinux.com>, May 2000
7 */
8
9/*
10 * 'Traps.c' handles hardware traps and faults after we have saved some
11 * state in 'asm.s'.
12 */
b5964405
IM
13#include <linux/interrupt.h>
14#include <linux/kallsyms.h>
15#include <linux/spinlock.h>
16#include <linux/highmem.h>
17#include <linux/kprobes.h>
18#include <linux/uaccess.h>
19#include <linux/utsname.h>
20#include <linux/kdebug.h>
1da177e4 21#include <linux/kernel.h>
b5964405
IM
22#include <linux/module.h>
23#include <linux/ptrace.h>
1da177e4 24#include <linux/string.h>
b5964405
IM
25#include <linux/unwind.h>
26#include <linux/delay.h>
1da177e4 27#include <linux/errno.h>
b5964405
IM
28#include <linux/kexec.h>
29#include <linux/sched.h>
1da177e4 30#include <linux/timer.h>
1da177e4 31#include <linux/init.h>
91768d6c 32#include <linux/bug.h>
b5964405
IM
33#include <linux/nmi.h>
34#include <linux/mm.h>
1da177e4
LT
35
36#ifdef CONFIG_EISA
37#include <linux/ioport.h>
38#include <linux/eisa.h>
39#endif
40
41#ifdef CONFIG_MCA
42#include <linux/mca.h>
43#endif
44
c0d12172
DJ
45#if defined(CONFIG_EDAC)
46#include <linux/edac.h>
47#endif
48
b5964405
IM
49#include <asm/arch_hooks.h>
50#include <asm/stacktrace.h>
1da177e4 51#include <asm/processor.h>
1da177e4 52#include <asm/debugreg.h>
b5964405
IM
53#include <asm/atomic.h>
54#include <asm/system.h>
55#include <asm/unwind.h>
1da177e4
LT
56#include <asm/desc.h>
57#include <asm/i387.h>
58#include <asm/nmi.h>
1da177e4 59#include <asm/smp.h>
b5964405 60#include <asm/io.h>
1da177e4
LT
61
62#include "mach_traps.h"
63
dbeb2be2
RR
64DECLARE_BITMAP(used_vectors, NR_VECTORS);
65EXPORT_SYMBOL_GPL(used_vectors);
66
1da177e4
LT
67asmlinkage int system_call(void);
68
1da177e4 69/* Do we ignore FPU interrupts ? */
b5964405 70char ignore_fpu_irq;
1da177e4
LT
71
72/*
73 * The IDT has to be page-aligned to simplify the Pentium
74 * F0 0F bug workaround.. We have a special link segment
75 * for this.
76 */
010d4f82 77gate_desc idt_table[256]
6842ef0e 78 __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, };
1da177e4
LT
79
80asmlinkage void divide_error(void);
81asmlinkage void debug(void);
82asmlinkage void nmi(void);
83asmlinkage void int3(void);
84asmlinkage void overflow(void);
85asmlinkage void bounds(void);
86asmlinkage void invalid_op(void);
87asmlinkage void device_not_available(void);
88asmlinkage void coprocessor_segment_overrun(void);
89asmlinkage void invalid_TSS(void);
90asmlinkage void segment_not_present(void);
91asmlinkage void stack_segment(void);
92asmlinkage void general_protection(void);
93asmlinkage void page_fault(void);
94asmlinkage void coprocessor_error(void);
95asmlinkage void simd_coprocessor_error(void);
96asmlinkage void alignment_check(void);
97asmlinkage void spurious_interrupt_bug(void);
98asmlinkage void machine_check(void);
99
badc7652 100int panic_on_unrecovered_nmi;
0741f4d2 101int kstack_depth_to_print = 24;
86c41837 102static unsigned int code_bytes = 64;
badc7652
AH
103static int ignore_nmis;
104static int die_counter;
e041c683 105
a5ff677c
HH
106void printk_address(unsigned long address, int reliable)
107{
108#ifdef CONFIG_KALLSYMS
b5964405
IM
109 char namebuf[KSYM_NAME_LEN];
110 unsigned long offset = 0;
111 unsigned long symsize;
a5ff677c 112 const char *symname;
a5ff677c 113 char reliab[4] = "";
b5964405
IM
114 char *delim = ":";
115 char *modname;
a5ff677c
HH
116
117 symname = kallsyms_lookup(address, &symsize, &offset,
118 &modname, namebuf);
119 if (!symname) {
120 printk(" [<%08lx>]\n", address);
121 return;
122 }
123 if (!reliable)
124 strcpy(reliab, "? ");
125
126 if (!modname)
127 modname = delim = "";
128 printk(" [<%08lx>] %s%s%s%s%s+0x%lx/0x%lx\n",
129 address, reliab, delim, modname, delim, symname, offset, symsize);
130#else
131 printk(" [<%08lx>]\n", address);
132#endif
133}
134
a8c1be9d
AH
135static inline int valid_stack_ptr(struct thread_info *tinfo,
136 void *p, unsigned int size)
1da177e4
LT
137{
138 return p > (void *)tinfo &&
36ad4885 139 p <= (void *)tinfo + THREAD_SIZE - size;
1da177e4
LT
140}
141
36ad4885
LT
142/* The form of the top of the frame on the stack */
143struct stack_frame {
a8c1be9d
AH
144 struct stack_frame *next_frame;
145 unsigned long return_address;
36ad4885
LT
146};
147
b5964405
IM
148static inline unsigned long
149print_context_stack(struct thread_info *tinfo,
a8c1be9d
AH
150 unsigned long *stack, unsigned long bp,
151 const struct stacktrace_ops *ops, void *data)
1da177e4 152{
65ea5b03 153 struct stack_frame *frame = (struct stack_frame *)bp;
36ad4885 154
36ad4885
LT
155 while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) {
156 unsigned long addr;
157
e9d4efdd
AV
158 addr = *stack;
159 if (__kernel_text_address(addr)) {
160 if ((unsigned long) stack == bp + 4) {
161 ops->address(data, addr, 1);
162 frame = frame->next_frame;
163 bp = (unsigned long) frame;
164 } else {
5bc27dc2 165 ops->address(data, addr, bp == 0);
e9d4efdd
AV
166 }
167 }
168 stack++;
1da177e4 169 }
65ea5b03 170 return bp;
1da177e4
LT
171}
172
2b14a78c 173void dump_trace(struct task_struct *task, struct pt_regs *regs,
5bc27dc2 174 unsigned long *stack, unsigned long bp,
9689ba8a 175 const struct stacktrace_ops *ops, void *data)
1da177e4 176{
1da177e4
LT
177 if (!task)
178 task = current;
179
a32cf397 180 if (!stack) {
2b14a78c
AK
181 unsigned long dummy;
182 stack = &dummy;
028a690a 183 if (task != current)
faca6227 184 stack = (unsigned long *)task->thread.sp;
176a2718
JB
185 }
186
a32cf397 187#ifdef CONFIG_FRAME_POINTER
65ea5b03 188 if (!bp) {
a32cf397 189 if (task == current) {
65ea5b03 190 /* Grab bp right from our regs */
b5964405 191 asm("movl %%ebp, %0" : "=r" (bp) :);
a32cf397 192 } else {
65ea5b03 193 /* bp is the last reg pushed by switch_to */
faca6227 194 bp = *(unsigned long *) task->thread.sp;
a32cf397 195 }
1da177e4 196 }
a32cf397 197#endif
1da177e4 198
a8c1be9d 199 for (;;) {
1da177e4 200 struct thread_info *context;
b5964405 201
1da177e4
LT
202 context = (struct thread_info *)
203 ((unsigned long)stack & (~(THREAD_SIZE - 1)));
65ea5b03 204 bp = print_context_stack(context, stack, bp, ops, data);
b5964405
IM
205 /*
206 * Should be after the line below, but somewhere
207 * in early boot context comes out corrupted and we
208 * can't reference it:
209 */
2b14a78c
AK
210 if (ops->stack(data, "IRQ") < 0)
211 break;
b5964405 212 stack = (unsigned long *)context->previous_esp;
1da177e4
LT
213 if (!stack)
214 break;
a36df98a 215 touch_nmi_watchdog();
1da177e4
LT
216 }
217}
2b14a78c
AK
218EXPORT_SYMBOL(dump_trace);
219
220static void
221print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
222{
223 printk(data);
224 print_symbol(msg, symbol);
225 printk("\n");
226}
227
228static void print_trace_warning(void *data, char *msg)
229{
230 printk("%s%s\n", (char *)data, msg);
231}
232
233static int print_trace_stack(void *data, char *name)
234{
235 return 0;
236}
237
238/*
239 * Print one address/symbol entries per line.
240 */
bc850d6b 241static void print_trace_address(void *data, unsigned long addr, int reliable)
2b14a78c
AK
242{
243 printk("%s [<%08lx>] ", (char *)data, addr);
bc850d6b
AV
244 if (!reliable)
245 printk("? ");
2b14a78c 246 print_symbol("%s\n", addr);
601e6255 247 touch_nmi_watchdog();
2b14a78c
AK
248}
249
9689ba8a 250static const struct stacktrace_ops print_trace_ops = {
a8c1be9d
AH
251 .warning = print_trace_warning,
252 .warning_symbol = print_trace_warning_symbol,
253 .stack = print_trace_stack,
254 .address = print_trace_address,
2b14a78c
AK
255};
256
257static void
258show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
b5964405 259 unsigned long *stack, unsigned long bp, char *log_lvl)
2b14a78c 260{
5bc27dc2 261 dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl);
2b14a78c
AK
262 printk("%s =======================\n", log_lvl);
263}
1da177e4 264
2b14a78c 265void show_trace(struct task_struct *task, struct pt_regs *regs,
5bc27dc2 266 unsigned long *stack, unsigned long bp)
7aa89746 267{
5bc27dc2 268 show_trace_log_lvl(task, regs, stack, bp, "");
7aa89746
CE
269}
270
b5964405
IM
271static void
272show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
273 unsigned long *sp, unsigned long bp, char *log_lvl)
1da177e4
LT
274{
275 unsigned long *stack;
276 int i;
277
65ea5b03 278 if (sp == NULL) {
1da177e4 279 if (task)
b5964405 280 sp = (unsigned long *)task->thread.sp;
1da177e4 281 else
65ea5b03 282 sp = (unsigned long *)&sp;
1da177e4
LT
283 }
284
65ea5b03 285 stack = sp;
b5964405 286 for (i = 0; i < kstack_depth_to_print; i++) {
1da177e4
LT
287 if (kstack_end(stack))
288 break;
75874d5c
CE
289 if (i && ((i % 8) == 0))
290 printk("\n%s ", log_lvl);
1da177e4
LT
291 printk("%08lx ", *stack++);
292 }
75874d5c 293 printk("\n%sCall Trace:\n", log_lvl);
b5964405 294
5bc27dc2 295 show_trace_log_lvl(task, regs, sp, bp, log_lvl);
7aa89746
CE
296}
297
65ea5b03 298void show_stack(struct task_struct *task, unsigned long *sp)
7aa89746 299{
75874d5c 300 printk(" ");
5bc27dc2 301 show_stack_log_lvl(task, NULL, sp, 0, "");
1da177e4
LT
302}
303
304/*
305 * The architecture-independent dump_stack generator
306 */
307void dump_stack(void)
308{
5bc27dc2 309 unsigned long bp = 0;
b5964405 310 unsigned long stack;
5bc27dc2
AV
311
312#ifdef CONFIG_FRAME_POINTER
313 if (!bp)
314 asm("movl %%ebp, %0" : "=r" (bp):);
315#endif
1da177e4 316
57c351de
AV
317 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
318 current->pid, current->comm, print_tainted(),
319 init_utsname()->release,
320 (int)strcspn(init_utsname()->version, " "),
321 init_utsname()->version);
b5964405 322
5bc27dc2 323 show_trace(current, NULL, &stack, bp);
1da177e4
LT
324}
325
326EXPORT_SYMBOL(dump_stack);
327
328void show_registers(struct pt_regs *regs)
329{
330 int i;
9d975ebd 331
1da177e4 332 print_modules();
9d975ebd 333 __show_registers(regs, 0);
b5964405 334
7e04a118 335 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)",
19c5870c 336 TASK_COMM_LEN, current->comm, task_pid_nr(current),
c9f4f06d 337 current_thread_info(), current, task_thread_info(current));
1da177e4
LT
338 /*
339 * When in-kernel, we also print out the stack and code at the
340 * time of the fault..
341 */
9d975ebd 342 if (!user_mode_vm(regs)) {
86c41837
CE
343 unsigned int code_prologue = code_bytes * 43 / 64;
344 unsigned int code_len = code_bytes;
99325326 345 unsigned char c;
b5964405 346 u8 *ip;
1da177e4 347
9c107805 348 printk("\n" KERN_EMERG "Stack: ");
5bc27dc2 349 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
1da177e4 350
9c107805 351 printk(KERN_EMERG "Code: ");
1da177e4 352
65ea5b03 353 ip = (u8 *)regs->ip - code_prologue;
a8c1be9d 354 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
99325326 355 /* try starting at EIP */
65ea5b03 356 ip = (u8 *)regs->ip;
86c41837 357 code_len = code_len - code_prologue + 1;
99325326 358 }
65ea5b03
PA
359 for (i = 0; i < code_len; i++, ip++) {
360 if (ip < (u8 *)PAGE_OFFSET ||
a8c1be9d 361 probe_kernel_address(ip, c)) {
1da177e4
LT
362 printk(" Bad EIP value.");
363 break;
364 }
65ea5b03 365 if (ip == (u8 *)regs->ip)
1da177e4
LT
366 printk("<%02x> ", c);
367 else
368 printk("%02x ", c);
369 }
370 }
371 printk("\n");
b5964405 372}
1da177e4 373
65ea5b03 374int is_valid_bugaddr(unsigned long ip)
1da177e4
LT
375{
376 unsigned short ud2;
1da177e4 377
65ea5b03 378 if (ip < PAGE_OFFSET)
91768d6c 379 return 0;
65ea5b03 380 if (probe_kernel_address((unsigned short *)ip, ud2))
91768d6c 381 return 0;
1da177e4 382
91768d6c 383 return ud2 == 0x0b0f;
1da177e4
LT
384}
385
b5964405 386int __kprobes __die(const char *str, struct pt_regs *regs, long err)
a604b380 387{
a604b380 388 unsigned short ss;
b5964405 389 unsigned long sp;
a604b380
HH
390
391 printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter);
392#ifdef CONFIG_PREEMPT
393 printk("PREEMPT ");
394#endif
395#ifdef CONFIG_SMP
396 printk("SMP ");
397#endif
398#ifdef CONFIG_DEBUG_PAGEALLOC
399 printk("DEBUG_PAGEALLOC");
400#endif
401 printk("\n");
a604b380 402 if (notify_die(DIE_OOPS, str, regs, err,
e423f49f
AH
403 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
404 return 1;
405
406 show_registers(regs);
407 /* Executive summary in case the oops scrolled away */
408 sp = (unsigned long) (&regs->sp);
409 savesegment(ss, ss);
410 if (user_mode(regs)) {
411 sp = regs->sp;
412 ss = regs->ss & 0xffff;
a604b380 413 }
e423f49f
AH
414 printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip);
415 print_symbol("%s", regs->ip);
416 printk(" SS:ESP %04x:%08lx\n", ss, sp);
417 return 0;
a604b380
HH
418}
419
91768d6c 420/*
b5964405
IM
421 * This is gone through when something in the kernel has done something bad
422 * and is about to be terminated:
91768d6c 423 */
b5964405 424void die(const char *str, struct pt_regs *regs, long err)
1da177e4
LT
425{
426 static struct {
39743c9e 427 raw_spinlock_t lock;
1da177e4
LT
428 u32 lock_owner;
429 int lock_owner_depth;
430 } die = {
39743c9e 431 .lock = __RAW_SPIN_LOCK_UNLOCKED,
1da177e4
LT
432 .lock_owner = -1,
433 .lock_owner_depth = 0
434 };
e43d674f 435 unsigned long flags;
1da177e4 436
dd287796
AM
437 oops_enter();
438
39c715b7 439 if (die.lock_owner != raw_smp_processor_id()) {
1da177e4 440 console_verbose();
c0a698b7 441 raw_local_irq_save(flags);
39743c9e 442 __raw_spin_lock(&die.lock);
1da177e4
LT
443 die.lock_owner = smp_processor_id();
444 die.lock_owner_depth = 0;
445 bust_spinlocks(1);
b5964405 446 } else {
c0a698b7 447 raw_local_irq_save(flags);
b5964405 448 }
1da177e4
LT
449
450 if (++die.lock_owner_depth < 3) {
65ea5b03 451 report_bug(regs->ip, regs);
91768d6c 452
a604b380 453 if (__die(str, regs, err))
20c0d2d4 454 regs = NULL;
a604b380 455 } else {
9c107805 456 printk(KERN_EMERG "Recursive die() failure, output suppressed\n");
a604b380 457 }
1da177e4
LT
458
459 bust_spinlocks(0);
460 die.lock_owner = -1;
bcdcd8e7 461 add_taint(TAINT_DIE);
39743c9e
AK
462 __raw_spin_unlock(&die.lock);
463 raw_local_irq_restore(flags);
6e274d14 464
20c0d2d4
JB
465 if (!regs)
466 return;
467
6e274d14
AN
468 if (kexec_should_crash(current))
469 crash_kexec(regs);
470
1da177e4
LT
471 if (in_interrupt())
472 panic("Fatal exception in interrupt");
473
cea6a4ba 474 if (panic_on_oops)
012c437d 475 panic("Fatal exception");
cea6a4ba 476
dd287796 477 oops_exit();
1da177e4
LT
478 do_exit(SIGSEGV);
479}
480
b5964405
IM
481static inline void
482die_if_kernel(const char *str, struct pt_regs *regs, long err)
1da177e4 483{
717b594a 484 if (!user_mode_vm(regs))
1da177e4
LT
485 die(str, regs, err);
486}
487
b5964405
IM
488static void __kprobes
489do_trap(int trapnr, int signr, char *str, int vm86, struct pt_regs *regs,
490 long error_code, siginfo_t *info)
1da177e4 491{
4f339ecb 492 struct task_struct *tsk = current;
4f339ecb 493
6b6891f9 494 if (regs->flags & X86_VM_MASK) {
1da177e4
LT
495 if (vm86)
496 goto vm86_trap;
497 goto trap_signal;
498 }
499
717b594a 500 if (!user_mode(regs))
1da177e4
LT
501 goto kernel_trap;
502
b5964405
IM
503trap_signal:
504 /*
505 * We want error_code and trap_no set for userspace faults and
506 * kernelspace faults which result in die(), but not
507 * kernelspace faults which are fixed up. die() gives the
508 * process no chance to handle the signal and notice the
509 * kernel fault information, so that won't result in polluting
510 * the information about previously queued, but not yet
511 * delivered, faults. See also do_general_protection below.
512 */
513 tsk->thread.error_code = error_code;
514 tsk->thread.trap_no = trapnr;
d1895183 515
b5964405
IM
516 if (info)
517 force_sig_info(signr, info, tsk);
518 else
519 force_sig(signr, tsk);
520 return;
1da177e4 521
b5964405
IM
522kernel_trap:
523 if (!fixup_exception(regs)) {
524 tsk->thread.error_code = error_code;
525 tsk->thread.trap_no = trapnr;
526 die(str, regs, error_code);
1da177e4 527 }
b5964405 528 return;
1da177e4 529
b5964405
IM
530vm86_trap:
531 if (handle_vm86_trap((struct kernel_vm86_regs *) regs,
532 error_code, trapnr))
533 goto trap_signal;
534 return;
1da177e4
LT
535}
536
b5964405
IM
537#define DO_ERROR(trapnr, signr, str, name) \
538void do_##name(struct pt_regs *regs, long error_code) \
539{ \
4461145e 540 trace_hardirqs_fixup(); \
b5964405 541 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
a8c1be9d 542 == NOTIFY_STOP) \
b5964405
IM
543 return; \
544 do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \
1da177e4
LT
545}
546
b5964405
IM
547#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr, irq) \
548void do_##name(struct pt_regs *regs, long error_code) \
549{ \
550 siginfo_t info; \
551 if (irq) \
552 local_irq_enable(); \
553 info.si_signo = signr; \
554 info.si_errno = 0; \
555 info.si_code = sicode; \
556 info.si_addr = (void __user *)siaddr; \
557 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
a8c1be9d 558 == NOTIFY_STOP) \
b5964405
IM
559 return; \
560 do_trap(trapnr, signr, str, 0, regs, error_code, &info); \
1da177e4
LT
561}
562
b5964405
IM
563#define DO_VM86_ERROR(trapnr, signr, str, name) \
564void do_##name(struct pt_regs *regs, long error_code) \
565{ \
566 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
a8c1be9d 567 == NOTIFY_STOP) \
b5964405
IM
568 return; \
569 do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \
1da177e4
LT
570}
571
b5964405
IM
572#define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
573void do_##name(struct pt_regs *regs, long error_code) \
574{ \
575 siginfo_t info; \
576 info.si_signo = signr; \
577 info.si_errno = 0; \
578 info.si_code = sicode; \
579 info.si_addr = (void __user *)siaddr; \
580 trace_hardirqs_fixup(); \
581 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
a8c1be9d 582 == NOTIFY_STOP) \
b5964405
IM
583 return; \
584 do_trap(trapnr, signr, str, 1, regs, error_code, &info); \
1da177e4
LT
585}
586
a8c1be9d 587DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
1da177e4 588#ifndef CONFIG_KPROBES
b5964405 589DO_VM86_ERROR(3, SIGTRAP, "int3", int3)
1da177e4 590#endif
b5964405
IM
591DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
592DO_VM86_ERROR(5, SIGSEGV, "bounds", bounds)
a8c1be9d
AH
593DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
594DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
1da177e4 595DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
a8c1be9d
AH
596DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
597DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
a10d9a71 598DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
79bf0e03 599DO_ERROR_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
1da177e4 600
b5964405 601void __kprobes do_general_protection(struct pt_regs *regs, long error_code)
1da177e4 602{
b5964405
IM
603 struct thread_struct *thread;
604 struct tss_struct *tss;
605 int cpu;
606
607 cpu = get_cpu();
608 tss = &per_cpu(init_tss, cpu);
609 thread = &current->thread;
1da177e4
LT
610
611 /*
612 * Perform the lazy TSS's I/O bitmap copy. If the TSS has an
613 * invalid offset set (the LAZY one) and the faulting thread has
614 * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS
615 * and we set the offset field correctly. Then we let the CPU to
616 * restart the faulting instruction.
617 */
a75c54f9 618 if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY &&
1da177e4
LT
619 thread->io_bitmap_ptr) {
620 memcpy(tss->io_bitmap, thread->io_bitmap_ptr,
621 thread->io_bitmap_max);
622 /*
623 * If the previously set map was extending to higher ports
624 * than the current one, pad extra space with 0xff (no access).
625 */
b5964405 626 if (thread->io_bitmap_max < tss->io_bitmap_max) {
1da177e4
LT
627 memset((char *) tss->io_bitmap +
628 thread->io_bitmap_max, 0xff,
629 tss->io_bitmap_max - thread->io_bitmap_max);
b5964405 630 }
1da177e4 631 tss->io_bitmap_max = thread->io_bitmap_max;
a75c54f9 632 tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET;
d5cd4aad 633 tss->io_bitmap_owner = thread;
1da177e4 634 put_cpu();
b5964405 635
1da177e4
LT
636 return;
637 }
638 put_cpu();
639
6b6891f9 640 if (regs->flags & X86_VM_MASK)
1da177e4
LT
641 goto gp_in_vm86;
642
717b594a 643 if (!user_mode(regs))
1da177e4
LT
644 goto gp_in_kernel;
645
646 current->thread.error_code = error_code;
647 current->thread.trap_no = 13;
b5964405 648
abd4f750 649 if (show_unhandled_signals && unhandled_signal(current, SIGSEGV) &&
03252919 650 printk_ratelimit()) {
abd4f750 651 printk(KERN_INFO
03252919 652 "%s[%d] general protection ip:%lx sp:%lx error:%lx",
19c5870c 653 current->comm, task_pid_nr(current),
65ea5b03 654 regs->ip, regs->sp, error_code);
03252919
AK
655 print_vma_addr(" in ", regs->ip);
656 printk("\n");
657 }
abd4f750 658
1da177e4
LT
659 force_sig(SIGSEGV, current);
660 return;
661
662gp_in_vm86:
663 local_irq_enable();
664 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
665 return;
666
667gp_in_kernel:
668 if (!fixup_exception(regs)) {
d1895183
AK
669 current->thread.error_code = error_code;
670 current->thread.trap_no = 13;
1da177e4
LT
671 if (notify_die(DIE_GPF, "general protection fault", regs,
672 error_code, 13, SIGSEGV) == NOTIFY_STOP)
673 return;
674 die("general protection fault", regs, error_code);
675 }
676}
677
5deb45e3 678static notrace __kprobes void
b5964405 679mem_parity_error(unsigned char reason, struct pt_regs *regs)
1da177e4 680{
b5964405
IM
681 printk(KERN_EMERG
682 "Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
683 reason, smp_processor_id());
684
685 printk(KERN_EMERG
686 "You have some hardware problem, likely on the PCI bus.\n");
c0d12172
DJ
687
688#if defined(CONFIG_EDAC)
b5964405 689 if (edac_handler_set()) {
c0d12172
DJ
690 edac_atomic_assert_error();
691 return;
692 }
693#endif
694
8da5adda 695 if (panic_on_unrecovered_nmi)
b5964405 696 panic("NMI: Not continuing");
1da177e4 697
c41c5cd3 698 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
1da177e4
LT
699
700 /* Clear and disable the memory parity error line. */
701 clear_mem_error(reason);
702}
703
5deb45e3 704static notrace __kprobes void
b5964405 705io_check_error(unsigned char reason, struct pt_regs *regs)
1da177e4
LT
706{
707 unsigned long i;
708
9c107805 709 printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
1da177e4
LT
710 show_registers(regs);
711
712 /* Re-enable the IOCK line, wait for a few seconds */
713 reason = (reason & 0xf) | 8;
714 outb(reason, 0x61);
b5964405 715
1da177e4 716 i = 2000;
b5964405
IM
717 while (--i)
718 udelay(1000);
719
1da177e4
LT
720 reason &= ~8;
721 outb(reason, 0x61);
722}
723
5deb45e3 724static notrace __kprobes void
b5964405 725unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
1da177e4 726{
d3597524
JW
727 if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
728 return;
1da177e4 729#ifdef CONFIG_MCA
b5964405
IM
730 /*
731 * Might actually be able to figure out what the guilty party
732 * is:
733 */
734 if (MCA_bus) {
1da177e4
LT
735 mca_handle_nmi();
736 return;
737 }
738#endif
b5964405
IM
739 printk(KERN_EMERG
740 "Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
741 reason, smp_processor_id());
742
c41c5cd3 743 printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n");
8da5adda 744 if (panic_on_unrecovered_nmi)
b5964405 745 panic("NMI: Not continuing");
8da5adda 746
c41c5cd3 747 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
1da177e4
LT
748}
749
750static DEFINE_SPINLOCK(nmi_print_lock);
751
ddca03c9 752void notrace __kprobes die_nmi(char *str, struct pt_regs *regs, int do_panic)
1da177e4 753{
ddca03c9 754 if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP)
748f2edb
GA
755 return;
756
1da177e4
LT
757 spin_lock(&nmi_print_lock);
758 /*
759 * We are in trouble anyway, lets at least try
b5964405 760 * to get a message out:
1da177e4
LT
761 */
762 bust_spinlocks(1);
ddca03c9 763 printk(KERN_EMERG "%s", str);
65ea5b03
PA
764 printk(" on CPU%d, ip %08lx, registers:\n",
765 smp_processor_id(), regs->ip);
1da177e4 766 show_registers(regs);
ddca03c9
CG
767 if (do_panic)
768 panic("Non maskable interrupt");
1da177e4
LT
769 console_silent();
770 spin_unlock(&nmi_print_lock);
771 bust_spinlocks(0);
6e274d14 772
b5964405
IM
773 /*
774 * If we are in kernel we are probably nested up pretty bad
775 * and might aswell get out now while we still can:
776 */
db753bdf 777 if (!user_mode_vm(regs)) {
6e274d14
AN
778 current->thread.trap_no = 2;
779 crash_kexec(regs);
780 }
781
1da177e4
LT
782 do_exit(SIGSEGV);
783}
784
5deb45e3 785static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
1da177e4
LT
786{
787 unsigned char reason = 0;
788
b5964405 789 /* Only the BSP gets external NMIs from the system: */
1da177e4
LT
790 if (!smp_processor_id())
791 reason = get_nmi_reason();
b5964405 792
1da177e4 793 if (!(reason & 0xc0)) {
20c0d2d4 794 if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
a8c1be9d 795 == NOTIFY_STOP)
1da177e4
LT
796 return;
797#ifdef CONFIG_X86_LOCAL_APIC
798 /*
799 * Ok, so this is none of the documented NMI sources,
800 * so it must be the NMI watchdog.
801 */
3adbbcce 802 if (nmi_watchdog_tick(regs, reason))
1da177e4 803 return;
2fbe7b25 804 if (!do_nmi_callback(regs, smp_processor_id()))
3adbbcce 805 unknown_nmi_error(reason, regs);
b5964405
IM
806#else
807 unknown_nmi_error(reason, regs);
808#endif
2fbe7b25 809
1da177e4
LT
810 return;
811 }
20c0d2d4 812 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
1da177e4 813 return;
a8c1be9d
AH
814
815 /* AK: following checks seem to be broken on modern chipsets. FIXME */
1da177e4
LT
816 if (reason & 0x80)
817 mem_parity_error(reason, regs);
818 if (reason & 0x40)
819 io_check_error(reason, regs);
820 /*
821 * Reassert NMI in case it became active meanwhile
b5964405 822 * as it's edge-triggered:
1da177e4
LT
823 */
824 reassert_nmi();
825}
826
5deb45e3 827notrace __kprobes void do_nmi(struct pt_regs *regs, long error_code)
1da177e4
LT
828{
829 int cpu;
830
831 nmi_enter();
832
833 cpu = smp_processor_id();
f3705136 834
1da177e4
LT
835 ++nmi_count(cpu);
836
8f4e956b
AK
837 if (!ignore_nmis)
838 default_do_nmi(regs);
1da177e4
LT
839
840 nmi_exit();
841}
842
8f4e956b
AK
843void stop_nmi(void)
844{
845 acpi_nmi_disable();
846 ignore_nmis++;
847}
848
849void restart_nmi(void)
850{
851 ignore_nmis--;
852 acpi_nmi_enable();
853}
854
1da177e4 855#ifdef CONFIG_KPROBES
75604d7f 856void __kprobes do_int3(struct pt_regs *regs, long error_code)
1da177e4 857{
143a5d32
PZ
858 trace_hardirqs_fixup();
859
1da177e4
LT
860 if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
861 == NOTIFY_STOP)
48c88211 862 return;
b5964405
IM
863 /*
864 * This is an interrupt gate, because kprobes wants interrupts
865 * disabled. Normal trap handlers don't.
866 */
1da177e4 867 restore_interrupts(regs);
b5964405 868
1da177e4 869 do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
1da177e4
LT
870}
871#endif
872
873/*
874 * Our handling of the processor debug registers is non-trivial.
875 * We do not clear them on entry and exit from the kernel. Therefore
876 * it is possible to get a watchpoint trap here from inside the kernel.
877 * However, the code in ./ptrace.c has ensured that the user can
878 * only set watchpoints on userspace addresses. Therefore the in-kernel
879 * watchpoint trap can only occur in code which is reading/writing
880 * from user space. Such code must not hold kernel locks (since it
881 * can equally take a page fault), therefore it is safe to call
882 * force_sig_info even though that claims and releases locks.
b5964405 883 *
1da177e4
LT
884 * Code in ./signal.c ensures that the debug control register
885 * is restored before we deliver any signal, and therefore that
886 * user code runs with the correct debug control register even though
887 * we clear it here.
888 *
889 * Being careful here means that we don't have to be as careful in a
890 * lot of more complicated places (task switching can be a bit lazy
891 * about restoring all the debug state, and ptrace doesn't have to
892 * find every occurrence of the TF bit that could be saved away even
893 * by user code)
894 */
b5964405 895void __kprobes do_debug(struct pt_regs *regs, long error_code)
1da177e4 896{
1da177e4 897 struct task_struct *tsk = current;
b5964405 898 unsigned int condition;
1da177e4 899
000f4a9e
PZ
900 trace_hardirqs_fixup();
901
1cc6f12e 902 get_debugreg(condition, 6);
1da177e4 903
10faa81e
RM
904 /*
905 * The processor cleared BTF, so don't mark that we need it set.
906 */
907 clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
908 tsk->thread.debugctlmsr = 0;
909
1da177e4 910 if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
a8c1be9d 911 SIGTRAP) == NOTIFY_STOP)
1da177e4
LT
912 return;
913 /* It's safe to allow irq's after DR6 has been saved */
65ea5b03 914 if (regs->flags & X86_EFLAGS_IF)
1da177e4
LT
915 local_irq_enable();
916
917 /* Mask out spurious debug traps due to lazy DR7 setting */
918 if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
0f534093 919 if (!tsk->thread.debugreg7)
1da177e4
LT
920 goto clear_dr7;
921 }
922
6b6891f9 923 if (regs->flags & X86_VM_MASK)
1da177e4
LT
924 goto debug_vm86;
925
926 /* Save debug status register where ptrace can see it */
0f534093 927 tsk->thread.debugreg6 = condition;
1da177e4
LT
928
929 /*
930 * Single-stepping through TF: make sure we ignore any events in
931 * kernel space (but re-enable TF when returning to user mode).
932 */
933 if (condition & DR_STEP) {
934 /*
935 * We already checked v86 mode above, so we can
936 * check for kernel mode by just checking the CPL
937 * of CS.
938 */
717b594a 939 if (!user_mode(regs))
1da177e4
LT
940 goto clear_TF_reenable;
941 }
942
943 /* Ok, finally something we can handle */
944 send_sigtrap(tsk, regs, error_code);
945
b5964405
IM
946 /*
947 * Disable additional traps. They'll be re-enabled when
1da177e4
LT
948 * the signal is delivered.
949 */
950clear_dr7:
1cc6f12e 951 set_debugreg(0, 7);
1da177e4
LT
952 return;
953
954debug_vm86:
955 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1);
956 return;
957
958clear_TF_reenable:
959 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
6093015d 960 regs->flags &= ~X86_EFLAGS_TF;
1da177e4
LT
961 return;
962}
963
964/*
965 * Note that we play around with the 'TS' bit in an attempt to get
966 * the correct behaviour even in the presence of the asynchronous
967 * IRQ13 behaviour
968 */
65ea5b03 969void math_error(void __user *ip)
1da177e4 970{
b5964405
IM
971 struct task_struct *task;
972 unsigned short cwd;
973 unsigned short swd;
1da177e4 974 siginfo_t info;
1da177e4
LT
975
976 /*
977 * Save the info for the exception handler and clear the error.
978 */
979 task = current;
980 save_init_fpu(task);
981 task->thread.trap_no = 16;
982 task->thread.error_code = 0;
983 info.si_signo = SIGFPE;
984 info.si_errno = 0;
985 info.si_code = __SI_FAULT;
65ea5b03 986 info.si_addr = ip;
1da177e4
LT
987 /*
988 * (~cwd & swd) will mask out exceptions that are not set to unmasked
989 * status. 0x3f is the exception bits in these regs, 0x200 is the
990 * C1 reg you need in case of a stack fault, 0x040 is the stack
991 * fault bit. We should only be taking one exception at a time,
992 * so if this combination doesn't produce any single exception,
a8c1be9d 993 * then we have a bad program that isn't synchronizing its FPU usage
1da177e4
LT
994 * and it will suffer the consequences since we won't be able to
995 * fully reproduce the context of the exception
996 */
997 cwd = get_fpu_cwd(task);
998 swd = get_fpu_swd(task);
b1daec30 999 switch (swd & ~cwd & 0x3f) {
b5964405
IM
1000 case 0x000: /* No unmasked exception */
1001 return;
a8c1be9d 1002 default: /* Multiple exceptions */
b5964405
IM
1003 break;
1004 case 0x001: /* Invalid Op */
1005 /*
1006 * swd & 0x240 == 0x040: Stack Underflow
1007 * swd & 0x240 == 0x240: Stack Overflow
1008 * User must clear the SF bit (0x40) if set
1009 */
1010 info.si_code = FPE_FLTINV;
1011 break;
1012 case 0x002: /* Denormalize */
1013 case 0x010: /* Underflow */
1014 info.si_code = FPE_FLTUND;
1015 break;
1016 case 0x004: /* Zero Divide */
1017 info.si_code = FPE_FLTDIV;
1018 break;
1019 case 0x008: /* Overflow */
1020 info.si_code = FPE_FLTOVF;
1021 break;
1022 case 0x020: /* Precision */
1023 info.si_code = FPE_FLTRES;
1024 break;
1da177e4
LT
1025 }
1026 force_sig_info(SIGFPE, &info, task);
1027}
1028
b5964405 1029void do_coprocessor_error(struct pt_regs *regs, long error_code)
1da177e4
LT
1030{
1031 ignore_fpu_irq = 1;
65ea5b03 1032 math_error((void __user *)regs->ip);
1da177e4
LT
1033}
1034
65ea5b03 1035static void simd_math_error(void __user *ip)
1da177e4 1036{
b5964405 1037 struct task_struct *task;
1da177e4 1038 unsigned short mxcsr;
b5964405 1039 siginfo_t info;
1da177e4
LT
1040
1041 /*
1042 * Save the info for the exception handler and clear the error.
1043 */
1044 task = current;
1045 save_init_fpu(task);
1046 task->thread.trap_no = 19;
1047 task->thread.error_code = 0;
1048 info.si_signo = SIGFPE;
1049 info.si_errno = 0;
1050 info.si_code = __SI_FAULT;
65ea5b03 1051 info.si_addr = ip;
1da177e4
LT
1052 /*
1053 * The SIMD FPU exceptions are handled a little differently, as there
1054 * is only a single status/control register. Thus, to determine which
1055 * unmasked exception was caught we must mask the exception mask bits
1056 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
1057 */
1058 mxcsr = get_fpu_mxcsr(task);
1059 switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
b5964405
IM
1060 case 0x000:
1061 default:
1062 break;
1063 case 0x001: /* Invalid Op */
1064 info.si_code = FPE_FLTINV;
1065 break;
1066 case 0x002: /* Denormalize */
1067 case 0x010: /* Underflow */
1068 info.si_code = FPE_FLTUND;
1069 break;
1070 case 0x004: /* Zero Divide */
1071 info.si_code = FPE_FLTDIV;
1072 break;
1073 case 0x008: /* Overflow */
1074 info.si_code = FPE_FLTOVF;
1075 break;
1076 case 0x020: /* Precision */
1077 info.si_code = FPE_FLTRES;
1078 break;
1da177e4
LT
1079 }
1080 force_sig_info(SIGFPE, &info, task);
1081}
1082
b5964405 1083void do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
1da177e4
LT
1084{
1085 if (cpu_has_xmm) {
1086 /* Handle SIMD FPU exceptions on PIII+ processors. */
1087 ignore_fpu_irq = 1;
65ea5b03 1088 simd_math_error((void __user *)regs->ip);
b5964405
IM
1089 return;
1090 }
1091 /*
1092 * Handle strange cache flush from user space exception
1093 * in all other cases. This is undocumented behaviour.
1094 */
6b6891f9 1095 if (regs->flags & X86_VM_MASK) {
b5964405
IM
1096 handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
1097 return;
1da177e4 1098 }
b5964405
IM
1099 current->thread.trap_no = 19;
1100 current->thread.error_code = error_code;
1101 die_if_kernel("cache flush denied", regs, error_code);
1102 force_sig(SIGSEGV, current);
1da177e4
LT
1103}
1104
b5964405 1105void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
1da177e4
LT
1106{
1107#if 0
1108 /* No need to warn about this any longer. */
b5964405 1109 printk(KERN_INFO "Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
1da177e4
LT
1110#endif
1111}
1112
b5964405 1113unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp)
1da177e4 1114{
736f12bf 1115 struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id());
be44d2aa
SS
1116 unsigned long base = (kesp - uesp) & -THREAD_SIZE;
1117 unsigned long new_kesp = kesp - base;
1118 unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
1119 __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS];
b5964405 1120
be44d2aa 1121 /* Set up base for espfix segment */
b5964405
IM
1122 desc &= 0x00f0ff0000000000ULL;
1123 desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) |
be44d2aa
SS
1124 ((((__u64)base) << 32) & 0xff00000000000000ULL) |
1125 ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) |
1126 (lim_pages & 0xffff);
1127 *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc;
b5964405 1128
be44d2aa 1129 return new_kesp;
1da177e4
LT
1130}
1131
1132/*
b5964405 1133 * 'math_state_restore()' saves the current math information in the
1da177e4
LT
1134 * old math state array, and gets the new ones from the current task
1135 *
1136 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
1137 * Don't touch unless you *really* know how it works.
1138 *
1139 * Must be called with kernel preemption disabled (in this case,
1140 * local interrupts are disabled at the call-site in entry.S).
1141 */
acc20761 1142asmlinkage void math_state_restore(void)
1da177e4
LT
1143{
1144 struct thread_info *thread = current_thread_info();
1145 struct task_struct *tsk = thread->task;
1146
aa283f49
SS
1147 if (!tsk_used_math(tsk)) {
1148 local_irq_enable();
1149 /*
1150 * does a slab alloc which can sleep
1151 */
1152 if (init_fpu(tsk)) {
1153 /*
1154 * ran out of memory!
1155 */
1156 do_group_exit(SIGKILL);
1157 return;
1158 }
1159 local_irq_disable();
1160 }
1161
b5964405 1162 clts(); /* Allow maths ops (or we recurse) */
1da177e4
LT
1163 restore_fpu(tsk);
1164 thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */
acc20761 1165 tsk->fpu_counter++;
1da177e4 1166}
5992b6da 1167EXPORT_SYMBOL_GPL(math_state_restore);
1da177e4
LT
1168
1169#ifndef CONFIG_MATH_EMULATION
1170
1171asmlinkage void math_emulate(long arg)
1172{
b5964405
IM
1173 printk(KERN_EMERG
1174 "math-emulation not enabled and no coprocessor found.\n");
1175 printk(KERN_EMERG "killing %s.\n", current->comm);
1176 force_sig(SIGFPE, current);
1da177e4
LT
1177 schedule();
1178}
1179
1180#endif /* CONFIG_MATH_EMULATION */
1181
1da177e4
LT
1182void __init trap_init(void)
1183{
dbeb2be2
RR
1184 int i;
1185
1da177e4 1186#ifdef CONFIG_EISA
927222b1 1187 void __iomem *p = early_ioremap(0x0FFFD9, 4);
b5964405
IM
1188
1189 if (readl(p) == 'E' + ('I'<<8) + ('S'<<16) + ('A'<<24))
1da177e4 1190 EISA_bus = 1;
927222b1 1191 early_iounmap(p, 4);
1da177e4
LT
1192#endif
1193
a8c1be9d
AH
1194 set_trap_gate(0, &divide_error);
1195 set_intr_gate(1, &debug);
1196 set_intr_gate(2, &nmi);
1197 set_system_intr_gate(3, &int3); /* int3 can be called from all */
1198 set_system_gate(4, &overflow); /* int4 can be called from all */
1199 set_trap_gate(5, &bounds);
1200 set_trap_gate(6, &invalid_op);
1201 set_trap_gate(7, &device_not_available);
1202 set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
1203 set_trap_gate(9, &coprocessor_segment_overrun);
b5964405
IM
1204 set_trap_gate(10, &invalid_TSS);
1205 set_trap_gate(11, &segment_not_present);
1206 set_trap_gate(12, &stack_segment);
1207 set_trap_gate(13, &general_protection);
1208 set_intr_gate(14, &page_fault);
1209 set_trap_gate(15, &spurious_interrupt_bug);
1210 set_trap_gate(16, &coprocessor_error);
1211 set_trap_gate(17, &alignment_check);
1da177e4 1212#ifdef CONFIG_X86_MCE
b5964405 1213 set_trap_gate(18, &machine_check);
1da177e4 1214#endif
b5964405 1215 set_trap_gate(19, &simd_coprocessor_error);
1da177e4 1216
d43c6e80 1217 if (cpu_has_fxsr) {
d43c6e80
JB
1218 printk(KERN_INFO "Enabling fast FPU save and restore... ");
1219 set_in_cr4(X86_CR4_OSFXSR);
1220 printk("done.\n");
1221 }
1222 if (cpu_has_xmm) {
b5964405
IM
1223 printk(KERN_INFO
1224 "Enabling unmasked SIMD FPU exception support... ");
d43c6e80
JB
1225 set_in_cr4(X86_CR4_OSXMMEXCPT);
1226 printk("done.\n");
1227 }
1228
b5964405 1229 set_system_gate(SYSCALL_VECTOR, &system_call);
1da177e4 1230
b5964405 1231 /* Reserve all the builtin and the syscall vector: */
dbeb2be2
RR
1232 for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++)
1233 set_bit(i, used_vectors);
b5964405 1234
dbeb2be2
RR
1235 set_bit(SYSCALL_VECTOR, used_vectors);
1236
61c4628b 1237 init_thread_xstate();
1da177e4 1238 /*
b5964405 1239 * Should be a barrier for any external CPU state:
1da177e4
LT
1240 */
1241 cpu_init();
1242
1243 trap_init_hook();
1244}
1245
1246static int __init kstack_setup(char *s)
1247{
1248 kstack_depth_to_print = simple_strtoul(s, NULL, 0);
b5964405 1249
9b41046c 1250 return 1;
1da177e4
LT
1251}
1252__setup("kstack=", kstack_setup);
86c41837
CE
1253
1254static int __init code_bytes_setup(char *s)
1255{
1256 code_bytes = simple_strtoul(s, NULL, 0);
1257 if (code_bytes > 8192)
1258 code_bytes = 8192;
1259
1260 return 1;
1261}
1262__setup("code_bytes=", code_bytes_setup);
This page took 0.70261 seconds and 5 git commands to generate.