blob: b85c9e88427dd5f9384cd9da2996191777345da9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/i386/traps.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * Pentium III FXSR, SSE support
7 * Gareth Hughes <gareth@valinux.com>, May 2000
8 */
9
10/*
11 * 'Traps.c' handles hardware traps and faults after we have saved some
12 * state in 'asm.s'.
13 */
14#include <linux/config.h>
15#include <linux/sched.h>
16#include <linux/kernel.h>
17#include <linux/string.h>
18#include <linux/errno.h>
19#include <linux/timer.h>
20#include <linux/mm.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/spinlock.h>
24#include <linux/interrupt.h>
25#include <linux/highmem.h>
26#include <linux/kallsyms.h>
27#include <linux/ptrace.h>
28#include <linux/utsname.h>
29#include <linux/kprobes.h>
Alexander Nyberg6e274d12005-06-25 14:58:26 -070030#include <linux/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#ifdef CONFIG_EISA
33#include <linux/ioport.h>
34#include <linux/eisa.h>
35#endif
36
37#ifdef CONFIG_MCA
38#include <linux/mca.h>
39#endif
40
41#include <asm/processor.h>
42#include <asm/system.h>
43#include <asm/uaccess.h>
44#include <asm/io.h>
45#include <asm/atomic.h>
46#include <asm/debugreg.h>
47#include <asm/desc.h>
48#include <asm/i387.h>
49#include <asm/nmi.h>
50
51#include <asm/smp.h>
52#include <asm/arch_hooks.h>
53#include <asm/kdebug.h>
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/module.h>
56
57#include "mach_traps.h"
58
59asmlinkage int system_call(void);
60
61struct desc_struct default_ldt[] = { { 0, 0 }, { 0, 0 }, { 0, 0 },
62 { 0, 0 }, { 0, 0 } };
63
64/* Do we ignore FPU interrupts ? */
65char ignore_fpu_irq = 0;
66
67/*
68 * The IDT has to be page-aligned to simplify the Pentium
69 * F0 0F bug workaround.. We have a special link segment
70 * for this.
71 */
72struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, };
73
74asmlinkage void divide_error(void);
75asmlinkage void debug(void);
76asmlinkage void nmi(void);
77asmlinkage void int3(void);
78asmlinkage void overflow(void);
79asmlinkage void bounds(void);
80asmlinkage void invalid_op(void);
81asmlinkage void device_not_available(void);
82asmlinkage void coprocessor_segment_overrun(void);
83asmlinkage void invalid_TSS(void);
84asmlinkage void segment_not_present(void);
85asmlinkage void stack_segment(void);
86asmlinkage void general_protection(void);
87asmlinkage void page_fault(void);
88asmlinkage void coprocessor_error(void);
89asmlinkage void simd_coprocessor_error(void);
90asmlinkage void alignment_check(void);
91asmlinkage void spurious_interrupt_bug(void);
92asmlinkage void machine_check(void);
93
94static int kstack_depth_to_print = 24;
95struct notifier_block *i386die_chain;
96static DEFINE_SPINLOCK(die_notifier_lock);
97
98int register_die_notifier(struct notifier_block *nb)
99{
100 int err = 0;
101 unsigned long flags;
102 spin_lock_irqsave(&die_notifier_lock, flags);
103 err = notifier_chain_register(&i386die_chain, nb);
104 spin_unlock_irqrestore(&die_notifier_lock, flags);
105 return err;
106}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700107EXPORT_SYMBOL(register_die_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
110{
111 return p > (void *)tinfo &&
112 p < (void *)tinfo + THREAD_SIZE - 3;
113}
114
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800115static void print_addr_and_symbol(unsigned long addr, char *log_lvl)
116{
117 printk(log_lvl);
118 printk(" [<%08lx>] ", addr);
119 print_symbol("%s", addr);
120 printk("\n");
121}
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123static inline unsigned long print_context_stack(struct thread_info *tinfo,
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800124 unsigned long *stack, unsigned long ebp,
125 char *log_lvl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 unsigned long addr;
128
129#ifdef CONFIG_FRAME_POINTER
130 while (valid_stack_ptr(tinfo, (void *)ebp)) {
131 addr = *(unsigned long *)(ebp + 4);
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800132 print_addr_and_symbol(addr, log_lvl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 ebp = *(unsigned long *)ebp;
134 }
135#else
136 while (valid_stack_ptr(tinfo, stack)) {
137 addr = *stack++;
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800138 if (__kernel_text_address(addr))
139 print_addr_and_symbol(addr, log_lvl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141#endif
142 return ebp;
143}
144
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800145static void show_trace_log_lvl(struct task_struct *task,
146 unsigned long *stack, char *log_lvl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 unsigned long ebp;
149
150 if (!task)
151 task = current;
152
153 if (task == current) {
154 /* Grab ebp right from our regs */
155 asm ("movl %%ebp, %0" : "=r" (ebp) : );
156 } else {
157 /* ebp is the last reg pushed by switch_to */
158 ebp = *(unsigned long *) task->thread.esp;
159 }
160
161 while (1) {
162 struct thread_info *context;
163 context = (struct thread_info *)
164 ((unsigned long)stack & (~(THREAD_SIZE - 1)));
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800165 ebp = print_context_stack(context, stack, ebp, log_lvl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 stack = (unsigned long*)context->previous_esp;
167 if (!stack)
168 break;
Hugh Dickins165a2c12006-02-04 23:27:51 -0800169 printk(log_lvl);
170 printk(" =======================\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172}
173
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800174void show_trace(struct task_struct *task, unsigned long * stack)
175{
176 show_trace_log_lvl(task, stack, "");
177}
178
179static void show_stack_log_lvl(struct task_struct *task, unsigned long *esp,
180 char *log_lvl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 unsigned long *stack;
183 int i;
184
185 if (esp == NULL) {
186 if (task)
187 esp = (unsigned long*)task->thread.esp;
188 else
189 esp = (unsigned long *)&esp;
190 }
191
192 stack = esp;
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800193 printk(log_lvl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 for(i = 0; i < kstack_depth_to_print; i++) {
195 if (kstack_end(stack))
196 break;
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800197 if (i && ((i % 8) == 0)) {
198 printk("\n");
199 printk(log_lvl);
200 printk(" ");
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 printk("%08lx ", *stack++);
203 }
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800204 printk("\n");
205 printk(log_lvl);
206 printk("Call Trace:\n");
207 show_trace_log_lvl(task, esp, log_lvl);
208}
209
210void show_stack(struct task_struct *task, unsigned long *esp)
211{
212 show_stack_log_lvl(task, esp, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
215/*
216 * The architecture-independent dump_stack generator
217 */
218void dump_stack(void)
219{
220 unsigned long stack;
221
222 show_trace(current, &stack);
223}
224
225EXPORT_SYMBOL(dump_stack);
226
227void show_registers(struct pt_regs *regs)
228{
229 int i;
230 int in_kernel = 1;
231 unsigned long esp;
232 unsigned short ss;
233
234 esp = (unsigned long) (&regs->esp);
Zachary Amsden0998e422005-09-03 15:56:43 -0700235 savesegment(ss, ss);
Vincent Hanquez717b5942005-06-23 00:08:45 -0700236 if (user_mode(regs)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 in_kernel = 0;
238 esp = regs->esp;
239 ss = regs->xss & 0xffff;
240 }
241 print_modules();
Dave Jones9c107802006-01-09 20:51:32 -0800242 printk(KERN_EMERG "CPU: %d\nEIP: %04x:[<%08lx>] %s VLI\n"
243 "EFLAGS: %08lx (%s) \n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 smp_processor_id(), 0xffff & regs->xcs, regs->eip,
245 print_tainted(), regs->eflags, system_utsname.release);
Dave Jones9c107802006-01-09 20:51:32 -0800246 print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip);
247 printk(KERN_EMERG "eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 regs->eax, regs->ebx, regs->ecx, regs->edx);
Dave Jones9c107802006-01-09 20:51:32 -0800249 printk(KERN_EMERG "esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 regs->esi, regs->edi, regs->ebp, esp);
Dave Jones9c107802006-01-09 20:51:32 -0800251 printk(KERN_EMERG "ds: %04x es: %04x ss: %04x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 regs->xds & 0xffff, regs->xes & 0xffff, ss);
Dave Jones9c107802006-01-09 20:51:32 -0800253 printk(KERN_EMERG "Process %s (pid: %d, threadinfo=%p task=%p)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 current->comm, current->pid, current_thread_info(), current);
255 /*
256 * When in-kernel, we also print out the stack and code at the
257 * time of the fault..
258 */
259 if (in_kernel) {
Domen Puncer3f3ae342005-06-25 14:58:44 -0700260 u8 __user *eip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Dave Jones9c107802006-01-09 20:51:32 -0800262 printk("\n" KERN_EMERG "Stack: ");
Chuck Ebbert7aa89742006-01-14 13:20:52 -0800263 show_stack_log_lvl(NULL, (unsigned long *)esp, KERN_EMERG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Dave Jones9c107802006-01-09 20:51:32 -0800265 printk(KERN_EMERG "Code: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Domen Puncer3f3ae342005-06-25 14:58:44 -0700267 eip = (u8 __user *)regs->eip - 43;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 for (i = 0; i < 64; i++, eip++) {
269 unsigned char c;
270
Domen Puncer3f3ae342005-06-25 14:58:44 -0700271 if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 printk(" Bad EIP value.");
273 break;
274 }
Domen Puncer3f3ae342005-06-25 14:58:44 -0700275 if (eip == (u8 __user *)regs->eip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 printk("<%02x> ", c);
277 else
278 printk("%02x ", c);
279 }
280 }
281 printk("\n");
282}
283
284static void handle_BUG(struct pt_regs *regs)
285{
286 unsigned short ud2;
287 unsigned short line;
288 char *file;
289 char c;
290 unsigned long eip;
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 eip = regs->eip;
293
294 if (eip < PAGE_OFFSET)
295 goto no_bug;
Domen Puncer3f3ae342005-06-25 14:58:44 -0700296 if (__get_user(ud2, (unsigned short __user *)eip))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 goto no_bug;
298 if (ud2 != 0x0b0f)
299 goto no_bug;
Domen Puncer3f3ae342005-06-25 14:58:44 -0700300 if (__get_user(line, (unsigned short __user *)(eip + 2)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 goto bug;
Domen Puncer3f3ae342005-06-25 14:58:44 -0700302 if (__get_user(file, (char * __user *)(eip + 4)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 (unsigned long)file < PAGE_OFFSET || __get_user(c, file))
304 file = "<bad filename>";
305
Dave Jones9c107802006-01-09 20:51:32 -0800306 printk(KERN_EMERG "------------[ cut here ]------------\n");
307 printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309no_bug:
310 return;
311
312 /* Here we know it was a BUG but file-n-line is unavailable */
313bug:
Dave Jones9c107802006-01-09 20:51:32 -0800314 printk(KERN_EMERG "Kernel BUG\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700317/* This is gone through when something in the kernel
318 * has done something bad and is about to be terminated.
319*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320void die(const char * str, struct pt_regs * regs, long err)
321{
322 static struct {
323 spinlock_t lock;
324 u32 lock_owner;
325 int lock_owner_depth;
326 } die = {
327 .lock = SPIN_LOCK_UNLOCKED,
328 .lock_owner = -1,
329 .lock_owner_depth = 0
330 };
331 static int die_counter;
Jan Beuliche43d6742006-01-06 00:11:48 -0800332 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Ingo Molnar39c715b2005-06-21 17:14:34 -0700334 if (die.lock_owner != raw_smp_processor_id()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 console_verbose();
Jan Beuliche43d6742006-01-06 00:11:48 -0800336 spin_lock_irqsave(&die.lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 die.lock_owner = smp_processor_id();
338 die.lock_owner_depth = 0;
339 bust_spinlocks(1);
340 }
Jan Beuliche43d6742006-01-06 00:11:48 -0800341 else
342 local_save_flags(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 if (++die.lock_owner_depth < 3) {
345 int nl = 0;
346 handle_BUG(regs);
Dave Jones9c107802006-01-09 20:51:32 -0800347 printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348#ifdef CONFIG_PREEMPT
Dave Jones9c107802006-01-09 20:51:32 -0800349 printk(KERN_EMERG "PREEMPT ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 nl = 1;
351#endif
352#ifdef CONFIG_SMP
Dave Jones9c107802006-01-09 20:51:32 -0800353 if (!nl)
354 printk(KERN_EMERG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 printk("SMP ");
356 nl = 1;
357#endif
358#ifdef CONFIG_DEBUG_PAGEALLOC
Dave Jones9c107802006-01-09 20:51:32 -0800359 if (!nl)
360 printk(KERN_EMERG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 printk("DEBUG_PAGEALLOC");
362 nl = 1;
363#endif
364 if (nl)
365 printk("\n");
366 notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
367 show_registers(regs);
368 } else
Dave Jones9c107802006-01-09 20:51:32 -0800369 printk(KERN_EMERG "Recursive die() failure, output suppressed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 bust_spinlocks(0);
372 die.lock_owner = -1;
Jan Beuliche43d6742006-01-06 00:11:48 -0800373 spin_unlock_irqrestore(&die.lock, flags);
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700374
375 if (kexec_should_crash(current))
376 crash_kexec(regs);
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 if (in_interrupt())
379 panic("Fatal exception in interrupt");
380
381 if (panic_on_oops) {
382 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
383 ssleep(5);
384 panic("Fatal exception");
385 }
386 do_exit(SIGSEGV);
387}
388
389static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err)
390{
Vincent Hanquez717b5942005-06-23 00:08:45 -0700391 if (!user_mode_vm(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 die(str, regs, err);
393}
394
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700395static void __kprobes do_trap(int trapnr, int signr, char *str, int vm86,
396 struct pt_regs * regs, long error_code,
397 siginfo_t *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Alexander Nyberg4f339ec2005-06-25 14:58:27 -0700399 struct task_struct *tsk = current;
400 tsk->thread.error_code = error_code;
401 tsk->thread.trap_no = trapnr;
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (regs->eflags & VM_MASK) {
404 if (vm86)
405 goto vm86_trap;
406 goto trap_signal;
407 }
408
Vincent Hanquez717b5942005-06-23 00:08:45 -0700409 if (!user_mode(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 goto kernel_trap;
411
412 trap_signal: {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 if (info)
414 force_sig_info(signr, info, tsk);
415 else
416 force_sig(signr, tsk);
417 return;
418 }
419
420 kernel_trap: {
421 if (!fixup_exception(regs))
422 die(str, regs, error_code);
423 return;
424 }
425
426 vm86_trap: {
427 int ret = handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, trapnr);
428 if (ret) goto trap_signal;
429 return;
430 }
431}
432
433#define DO_ERROR(trapnr, signr, str, name) \
434fastcall void do_##name(struct pt_regs * regs, long error_code) \
435{ \
436 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
437 == NOTIFY_STOP) \
438 return; \
439 do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \
440}
441
442#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
443fastcall void do_##name(struct pt_regs * regs, long error_code) \
444{ \
445 siginfo_t info; \
446 info.si_signo = signr; \
447 info.si_errno = 0; \
448 info.si_code = sicode; \
449 info.si_addr = (void __user *)siaddr; \
450 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
451 == NOTIFY_STOP) \
452 return; \
453 do_trap(trapnr, signr, str, 0, regs, error_code, &info); \
454}
455
456#define DO_VM86_ERROR(trapnr, signr, str, name) \
457fastcall void do_##name(struct pt_regs * regs, long error_code) \
458{ \
459 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
460 == NOTIFY_STOP) \
461 return; \
462 do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \
463}
464
465#define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
466fastcall void do_##name(struct pt_regs * regs, long error_code) \
467{ \
468 siginfo_t info; \
469 info.si_signo = signr; \
470 info.si_errno = 0; \
471 info.si_code = sicode; \
472 info.si_addr = (void __user *)siaddr; \
473 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
474 == NOTIFY_STOP) \
475 return; \
476 do_trap(trapnr, signr, str, 1, regs, error_code, &info); \
477}
478
479DO_VM86_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->eip)
480#ifndef CONFIG_KPROBES
481DO_VM86_ERROR( 3, SIGTRAP, "int3", int3)
482#endif
483DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow)
484DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds)
Chuck Ebbert631b0342006-01-03 22:36:14 -0500485DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
487DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
488DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
489DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
490DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700491DO_ERROR_INFO(32, SIGSEGV, "iret exception", iret_error, ILL_BADSTK, 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700493fastcall void __kprobes do_general_protection(struct pt_regs * regs,
494 long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
496 int cpu = get_cpu();
497 struct tss_struct *tss = &per_cpu(init_tss, cpu);
498 struct thread_struct *thread = &current->thread;
499
500 /*
501 * Perform the lazy TSS's I/O bitmap copy. If the TSS has an
502 * invalid offset set (the LAZY one) and the faulting thread has
503 * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS
504 * and we set the offset field correctly. Then we let the CPU to
505 * restart the faulting instruction.
506 */
507 if (tss->io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY &&
508 thread->io_bitmap_ptr) {
509 memcpy(tss->io_bitmap, thread->io_bitmap_ptr,
510 thread->io_bitmap_max);
511 /*
512 * If the previously set map was extending to higher ports
513 * than the current one, pad extra space with 0xff (no access).
514 */
515 if (thread->io_bitmap_max < tss->io_bitmap_max)
516 memset((char *) tss->io_bitmap +
517 thread->io_bitmap_max, 0xff,
518 tss->io_bitmap_max - thread->io_bitmap_max);
519 tss->io_bitmap_max = thread->io_bitmap_max;
520 tss->io_bitmap_base = IO_BITMAP_OFFSET;
Bart Oldemand5cd4aa2005-10-30 14:59:29 -0800521 tss->io_bitmap_owner = thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 put_cpu();
523 return;
524 }
525 put_cpu();
526
Alexander Nyberg4f339ec2005-06-25 14:58:27 -0700527 current->thread.error_code = error_code;
528 current->thread.trap_no = 13;
529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (regs->eflags & VM_MASK)
531 goto gp_in_vm86;
532
Vincent Hanquez717b5942005-06-23 00:08:45 -0700533 if (!user_mode(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 goto gp_in_kernel;
535
536 current->thread.error_code = error_code;
537 current->thread.trap_no = 13;
538 force_sig(SIGSEGV, current);
539 return;
540
541gp_in_vm86:
542 local_irq_enable();
543 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
544 return;
545
546gp_in_kernel:
547 if (!fixup_exception(regs)) {
548 if (notify_die(DIE_GPF, "general protection fault", regs,
549 error_code, 13, SIGSEGV) == NOTIFY_STOP)
550 return;
551 die("general protection fault", regs, error_code);
552 }
553}
554
555static void mem_parity_error(unsigned char reason, struct pt_regs * regs)
556{
Dave Jones9c107802006-01-09 20:51:32 -0800557 printk(KERN_EMERG "Uhhuh. NMI received. Dazed and confused, but trying "
558 "to continue\n");
559 printk(KERN_EMERG "You probably have a hardware problem with your RAM "
560 "chips\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 /* Clear and disable the memory parity error line. */
563 clear_mem_error(reason);
564}
565
566static void io_check_error(unsigned char reason, struct pt_regs * regs)
567{
568 unsigned long i;
569
Dave Jones9c107802006-01-09 20:51:32 -0800570 printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 show_registers(regs);
572
573 /* Re-enable the IOCK line, wait for a few seconds */
574 reason = (reason & 0xf) | 8;
575 outb(reason, 0x61);
576 i = 2000;
577 while (--i) udelay(1000);
578 reason &= ~8;
579 outb(reason, 0x61);
580}
581
582static void unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
583{
584#ifdef CONFIG_MCA
585 /* Might actually be able to figure out what the guilty party
586 * is. */
587 if( MCA_bus ) {
588 mca_handle_nmi();
589 return;
590 }
591#endif
592 printk("Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
593 reason, smp_processor_id());
594 printk("Dazed and confused, but trying to continue\n");
595 printk("Do you have a strange power saving mode enabled?\n");
596}
597
598static DEFINE_SPINLOCK(nmi_print_lock);
599
600void die_nmi (struct pt_regs *regs, const char *msg)
601{
George Anzinger748f2ed2005-09-03 15:56:48 -0700602 if (notify_die(DIE_NMIWATCHDOG, msg, regs, 0, 0, SIGINT) ==
603 NOTIFY_STOP)
604 return;
605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 spin_lock(&nmi_print_lock);
607 /*
608 * We are in trouble anyway, lets at least try
609 * to get a message out.
610 */
611 bust_spinlocks(1);
Dave Jones9c107802006-01-09 20:51:32 -0800612 printk(KERN_EMERG "%s", msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 printk(" on CPU%d, eip %08lx, registers:\n",
614 smp_processor_id(), regs->eip);
615 show_registers(regs);
Dave Jones9c107802006-01-09 20:51:32 -0800616 printk(KERN_EMERG "console shuts up ...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 console_silent();
618 spin_unlock(&nmi_print_lock);
619 bust_spinlocks(0);
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700620
621 /* If we are in kernel we are probably nested up pretty bad
622 * and might aswell get out now while we still can.
623 */
624 if (!user_mode(regs)) {
625 current->thread.trap_no = 2;
626 crash_kexec(regs);
627 }
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 do_exit(SIGSEGV);
630}
631
632static void default_do_nmi(struct pt_regs * regs)
633{
634 unsigned char reason = 0;
635
636 /* Only the BSP gets external NMIs from the system. */
637 if (!smp_processor_id())
638 reason = get_nmi_reason();
639
640 if (!(reason & 0xc0)) {
641 if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 0, SIGINT)
642 == NOTIFY_STOP)
643 return;
644#ifdef CONFIG_X86_LOCAL_APIC
645 /*
646 * Ok, so this is none of the documented NMI sources,
647 * so it must be the NMI watchdog.
648 */
649 if (nmi_watchdog) {
650 nmi_watchdog_tick(regs);
651 return;
652 }
653#endif
654 unknown_nmi_error(reason, regs);
655 return;
656 }
657 if (notify_die(DIE_NMI, "nmi", regs, reason, 0, SIGINT) == NOTIFY_STOP)
658 return;
659 if (reason & 0x80)
660 mem_parity_error(reason, regs);
661 if (reason & 0x40)
662 io_check_error(reason, regs);
663 /*
664 * Reassert NMI in case it became active meanwhile
665 * as it's edge-triggered.
666 */
667 reassert_nmi();
668}
669
670static int dummy_nmi_callback(struct pt_regs * regs, int cpu)
671{
672 return 0;
673}
674
675static nmi_callback_t nmi_callback = dummy_nmi_callback;
676
677fastcall void do_nmi(struct pt_regs * regs, long error_code)
678{
679 int cpu;
680
681 nmi_enter();
682
683 cpu = smp_processor_id();
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 ++nmi_count(cpu);
686
Paul E. McKenney19306052005-09-06 15:16:35 -0700687 if (!rcu_dereference(nmi_callback)(regs, cpu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 default_do_nmi(regs);
689
690 nmi_exit();
691}
692
693void set_nmi_callback(nmi_callback_t callback)
694{
Paul E. McKenney19306052005-09-06 15:16:35 -0700695 rcu_assign_pointer(nmi_callback, callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700697EXPORT_SYMBOL_GPL(set_nmi_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699void unset_nmi_callback(void)
700{
701 nmi_callback = dummy_nmi_callback;
702}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700703EXPORT_SYMBOL_GPL(unset_nmi_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705#ifdef CONFIG_KPROBES
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700706fastcall void __kprobes do_int3(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
708 if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
709 == NOTIFY_STOP)
Stas Sergeev48c882112005-05-01 08:58:49 -0700710 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 /* This is an interrupt gate, because kprobes wants interrupts
712 disabled. Normal trap handlers don't. */
713 restore_interrupts(regs);
714 do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715}
716#endif
717
718/*
719 * Our handling of the processor debug registers is non-trivial.
720 * We do not clear them on entry and exit from the kernel. Therefore
721 * it is possible to get a watchpoint trap here from inside the kernel.
722 * However, the code in ./ptrace.c has ensured that the user can
723 * only set watchpoints on userspace addresses. Therefore the in-kernel
724 * watchpoint trap can only occur in code which is reading/writing
725 * from user space. Such code must not hold kernel locks (since it
726 * can equally take a page fault), therefore it is safe to call
727 * force_sig_info even though that claims and releases locks.
728 *
729 * Code in ./signal.c ensures that the debug control register
730 * is restored before we deliver any signal, and therefore that
731 * user code runs with the correct debug control register even though
732 * we clear it here.
733 *
734 * Being careful here means that we don't have to be as careful in a
735 * lot of more complicated places (task switching can be a bit lazy
736 * about restoring all the debug state, and ptrace doesn't have to
737 * find every occurrence of the TF bit that could be saved away even
738 * by user code)
739 */
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700740fastcall void __kprobes do_debug(struct pt_regs * regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
742 unsigned int condition;
743 struct task_struct *tsk = current;
744
Vincent Hanquez1cc6f122005-06-23 00:08:43 -0700745 get_debugreg(condition, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
748 SIGTRAP) == NOTIFY_STOP)
749 return;
750 /* It's safe to allow irq's after DR6 has been saved */
751 if (regs->eflags & X86_EFLAGS_IF)
752 local_irq_enable();
753
754 /* Mask out spurious debug traps due to lazy DR7 setting */
755 if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
756 if (!tsk->thread.debugreg[7])
757 goto clear_dr7;
758 }
759
760 if (regs->eflags & VM_MASK)
761 goto debug_vm86;
762
763 /* Save debug status register where ptrace can see it */
764 tsk->thread.debugreg[6] = condition;
765
766 /*
767 * Single-stepping through TF: make sure we ignore any events in
768 * kernel space (but re-enable TF when returning to user mode).
769 */
770 if (condition & DR_STEP) {
771 /*
772 * We already checked v86 mode above, so we can
773 * check for kernel mode by just checking the CPL
774 * of CS.
775 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700776 if (!user_mode(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 goto clear_TF_reenable;
778 }
779
780 /* Ok, finally something we can handle */
781 send_sigtrap(tsk, regs, error_code);
782
783 /* Disable additional traps. They'll be re-enabled when
784 * the signal is delivered.
785 */
786clear_dr7:
Vincent Hanquez1cc6f122005-06-23 00:08:43 -0700787 set_debugreg(0, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 return;
789
790debug_vm86:
791 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1);
792 return;
793
794clear_TF_reenable:
795 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
796 regs->eflags &= ~TF_MASK;
797 return;
798}
799
800/*
801 * Note that we play around with the 'TS' bit in an attempt to get
802 * the correct behaviour even in the presence of the asynchronous
803 * IRQ13 behaviour
804 */
805void math_error(void __user *eip)
806{
807 struct task_struct * task;
808 siginfo_t info;
809 unsigned short cwd, swd;
810
811 /*
812 * Save the info for the exception handler and clear the error.
813 */
814 task = current;
815 save_init_fpu(task);
816 task->thread.trap_no = 16;
817 task->thread.error_code = 0;
818 info.si_signo = SIGFPE;
819 info.si_errno = 0;
820 info.si_code = __SI_FAULT;
821 info.si_addr = eip;
822 /*
823 * (~cwd & swd) will mask out exceptions that are not set to unmasked
824 * status. 0x3f is the exception bits in these regs, 0x200 is the
825 * C1 reg you need in case of a stack fault, 0x040 is the stack
826 * fault bit. We should only be taking one exception at a time,
827 * so if this combination doesn't produce any single exception,
828 * then we have a bad program that isn't syncronizing its FPU usage
829 * and it will suffer the consequences since we won't be able to
830 * fully reproduce the context of the exception
831 */
832 cwd = get_fpu_cwd(task);
833 swd = get_fpu_swd(task);
Chuck Ebbertb1daec32005-08-23 21:36:40 -0400834 switch (swd & ~cwd & 0x3f) {
Chuck Ebbert33333372005-09-13 04:55:41 -0400835 case 0x000: /* No unmasked exception */
836 return;
837 default: /* Multiple exceptions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 break;
839 case 0x001: /* Invalid Op */
Chuck Ebbertb1daec32005-08-23 21:36:40 -0400840 /*
841 * swd & 0x240 == 0x040: Stack Underflow
842 * swd & 0x240 == 0x240: Stack Overflow
843 * User must clear the SF bit (0x40) if set
844 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 info.si_code = FPE_FLTINV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 break;
847 case 0x002: /* Denormalize */
848 case 0x010: /* Underflow */
849 info.si_code = FPE_FLTUND;
850 break;
851 case 0x004: /* Zero Divide */
852 info.si_code = FPE_FLTDIV;
853 break;
854 case 0x008: /* Overflow */
855 info.si_code = FPE_FLTOVF;
856 break;
857 case 0x020: /* Precision */
858 info.si_code = FPE_FLTRES;
859 break;
860 }
861 force_sig_info(SIGFPE, &info, task);
862}
863
864fastcall void do_coprocessor_error(struct pt_regs * regs, long error_code)
865{
866 ignore_fpu_irq = 1;
867 math_error((void __user *)regs->eip);
868}
869
870static void simd_math_error(void __user *eip)
871{
872 struct task_struct * task;
873 siginfo_t info;
874 unsigned short mxcsr;
875
876 /*
877 * Save the info for the exception handler and clear the error.
878 */
879 task = current;
880 save_init_fpu(task);
881 task->thread.trap_no = 19;
882 task->thread.error_code = 0;
883 info.si_signo = SIGFPE;
884 info.si_errno = 0;
885 info.si_code = __SI_FAULT;
886 info.si_addr = eip;
887 /*
888 * The SIMD FPU exceptions are handled a little differently, as there
889 * is only a single status/control register. Thus, to determine which
890 * unmasked exception was caught we must mask the exception mask bits
891 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
892 */
893 mxcsr = get_fpu_mxcsr(task);
894 switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
895 case 0x000:
896 default:
897 break;
898 case 0x001: /* Invalid Op */
899 info.si_code = FPE_FLTINV;
900 break;
901 case 0x002: /* Denormalize */
902 case 0x010: /* Underflow */
903 info.si_code = FPE_FLTUND;
904 break;
905 case 0x004: /* Zero Divide */
906 info.si_code = FPE_FLTDIV;
907 break;
908 case 0x008: /* Overflow */
909 info.si_code = FPE_FLTOVF;
910 break;
911 case 0x020: /* Precision */
912 info.si_code = FPE_FLTRES;
913 break;
914 }
915 force_sig_info(SIGFPE, &info, task);
916}
917
918fastcall void do_simd_coprocessor_error(struct pt_regs * regs,
919 long error_code)
920{
921 if (cpu_has_xmm) {
922 /* Handle SIMD FPU exceptions on PIII+ processors. */
923 ignore_fpu_irq = 1;
924 simd_math_error((void __user *)regs->eip);
925 } else {
926 /*
927 * Handle strange cache flush from user space exception
928 * in all other cases. This is undocumented behaviour.
929 */
930 if (regs->eflags & VM_MASK) {
931 handle_vm86_fault((struct kernel_vm86_regs *)regs,
932 error_code);
933 return;
934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 current->thread.trap_no = 19;
936 current->thread.error_code = error_code;
Alexander Nyberg4f339ec2005-06-25 14:58:27 -0700937 die_if_kernel("cache flush denied", regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 force_sig(SIGSEGV, current);
939 }
940}
941
942fastcall void do_spurious_interrupt_bug(struct pt_regs * regs,
943 long error_code)
944{
945#if 0
946 /* No need to warn about this any longer. */
947 printk("Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
948#endif
949}
950
951fastcall void setup_x86_bogus_stack(unsigned char * stk)
952{
953 unsigned long *switch16_ptr, *switch32_ptr;
954 struct pt_regs *regs;
955 unsigned long stack_top, stack_bot;
956 unsigned short iret_frame16_off;
957 int cpu = smp_processor_id();
958 /* reserve the space on 32bit stack for the magic switch16 pointer */
959 memmove(stk, stk + 8, sizeof(struct pt_regs));
960 switch16_ptr = (unsigned long *)(stk + sizeof(struct pt_regs));
961 regs = (struct pt_regs *)stk;
962 /* now the switch32 on 16bit stack */
963 stack_bot = (unsigned long)&per_cpu(cpu_16bit_stack, cpu);
964 stack_top = stack_bot + CPU_16BIT_STACK_SIZE;
965 switch32_ptr = (unsigned long *)(stack_top - 8);
966 iret_frame16_off = CPU_16BIT_STACK_SIZE - 8 - 20;
967 /* copy iret frame on 16bit stack */
968 memcpy((void *)(stack_bot + iret_frame16_off), &regs->eip, 20);
969 /* fill in the switch pointers */
970 switch16_ptr[0] = (regs->esp & 0xffff0000) | iret_frame16_off;
971 switch16_ptr[1] = __ESPFIX_SS;
972 switch32_ptr[0] = (unsigned long)stk + sizeof(struct pt_regs) +
973 8 - CPU_16BIT_STACK_SIZE;
974 switch32_ptr[1] = __KERNEL_DS;
975}
976
977fastcall unsigned char * fixup_x86_bogus_stack(unsigned short sp)
978{
979 unsigned long *switch32_ptr;
980 unsigned char *stack16, *stack32;
981 unsigned long stack_top, stack_bot;
982 int len;
983 int cpu = smp_processor_id();
984 stack_bot = (unsigned long)&per_cpu(cpu_16bit_stack, cpu);
985 stack_top = stack_bot + CPU_16BIT_STACK_SIZE;
986 switch32_ptr = (unsigned long *)(stack_top - 8);
987 /* copy the data from 16bit stack to 32bit stack */
988 len = CPU_16BIT_STACK_SIZE - 8 - sp;
989 stack16 = (unsigned char *)(stack_bot + sp);
990 stack32 = (unsigned char *)
991 (switch32_ptr[0] + CPU_16BIT_STACK_SIZE - 8 - len);
992 memcpy(stack32, stack16, len);
993 return stack32;
994}
995
996/*
997 * 'math_state_restore()' saves the current math information in the
998 * old math state array, and gets the new ones from the current task
999 *
1000 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
1001 * Don't touch unless you *really* know how it works.
1002 *
1003 * Must be called with kernel preemption disabled (in this case,
1004 * local interrupts are disabled at the call-site in entry.S).
1005 */
1006asmlinkage void math_state_restore(struct pt_regs regs)
1007{
1008 struct thread_info *thread = current_thread_info();
1009 struct task_struct *tsk = thread->task;
1010
1011 clts(); /* Allow maths ops (or we recurse) */
1012 if (!tsk_used_math(tsk))
1013 init_fpu(tsk);
1014 restore_fpu(tsk);
1015 thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */
1016}
1017
1018#ifndef CONFIG_MATH_EMULATION
1019
1020asmlinkage void math_emulate(long arg)
1021{
Dave Jones9c107802006-01-09 20:51:32 -08001022 printk(KERN_EMERG "math-emulation not enabled and no coprocessor found.\n");
1023 printk(KERN_EMERG "killing %s.\n",current->comm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 force_sig(SIGFPE,current);
1025 schedule();
1026}
1027
1028#endif /* CONFIG_MATH_EMULATION */
1029
1030#ifdef CONFIG_X86_F00F_BUG
1031void __init trap_init_f00f_bug(void)
1032{
1033 __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
1034
1035 /*
1036 * Update the IDT descriptor and reload the IDT so that
1037 * it uses the read-only mapped virtual address.
1038 */
1039 idt_descr.address = fix_to_virt(FIX_F00F_IDT);
Zachary Amsden4d37e7e2005-09-03 15:56:38 -07001040 load_idt(&idt_descr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041}
1042#endif
1043
1044#define _set_gate(gate_addr,type,dpl,addr,seg) \
1045do { \
1046 int __d0, __d1; \
1047 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
1048 "movw %4,%%dx\n\t" \
1049 "movl %%eax,%0\n\t" \
1050 "movl %%edx,%1" \
1051 :"=m" (*((long *) (gate_addr))), \
1052 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
1053 :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
1054 "3" ((char *) (addr)),"2" ((seg) << 16)); \
1055} while (0)
1056
1057
1058/*
1059 * This needs to use 'idt_table' rather than 'idt', and
1060 * thus use the _nonmapped_ version of the IDT, as the
1061 * Pentium F0 0F bugfix can have resulted in the mapped
1062 * IDT being write-protected.
1063 */
1064void set_intr_gate(unsigned int n, void *addr)
1065{
1066 _set_gate(idt_table+n,14,0,addr,__KERNEL_CS);
1067}
1068
1069/*
1070 * This routine sets up an interrupt gate at directory privilege level 3.
1071 */
1072static inline void set_system_intr_gate(unsigned int n, void *addr)
1073{
1074 _set_gate(idt_table+n, 14, 3, addr, __KERNEL_CS);
1075}
1076
1077static void __init set_trap_gate(unsigned int n, void *addr)
1078{
1079 _set_gate(idt_table+n,15,0,addr,__KERNEL_CS);
1080}
1081
1082static void __init set_system_gate(unsigned int n, void *addr)
1083{
1084 _set_gate(idt_table+n,15,3,addr,__KERNEL_CS);
1085}
1086
1087static void __init set_task_gate(unsigned int n, unsigned int gdt_entry)
1088{
1089 _set_gate(idt_table+n,5,0,0,(gdt_entry<<3));
1090}
1091
1092
1093void __init trap_init(void)
1094{
1095#ifdef CONFIG_EISA
1096 void __iomem *p = ioremap(0x0FFFD9, 4);
1097 if (readl(p) == 'E'+('I'<<8)+('S'<<16)+('A'<<24)) {
1098 EISA_bus = 1;
1099 }
1100 iounmap(p);
1101#endif
1102
1103#ifdef CONFIG_X86_LOCAL_APIC
1104 init_apic_mappings();
1105#endif
1106
1107 set_trap_gate(0,&divide_error);
1108 set_intr_gate(1,&debug);
1109 set_intr_gate(2,&nmi);
Jan Beulicheb05c322006-01-06 00:11:49 -08001110 set_system_intr_gate(3, &int3); /* int3/4 can be called from all */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 set_system_gate(4,&overflow);
Jan Beulicheb05c322006-01-06 00:11:49 -08001112 set_trap_gate(5,&bounds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 set_trap_gate(6,&invalid_op);
1114 set_trap_gate(7,&device_not_available);
1115 set_task_gate(8,GDT_ENTRY_DOUBLEFAULT_TSS);
1116 set_trap_gate(9,&coprocessor_segment_overrun);
1117 set_trap_gate(10,&invalid_TSS);
1118 set_trap_gate(11,&segment_not_present);
1119 set_trap_gate(12,&stack_segment);
1120 set_trap_gate(13,&general_protection);
1121 set_intr_gate(14,&page_fault);
1122 set_trap_gate(15,&spurious_interrupt_bug);
1123 set_trap_gate(16,&coprocessor_error);
1124 set_trap_gate(17,&alignment_check);
1125#ifdef CONFIG_X86_MCE
1126 set_trap_gate(18,&machine_check);
1127#endif
1128 set_trap_gate(19,&simd_coprocessor_error);
1129
Jan Beulichd43c6e82006-01-06 00:11:49 -08001130 if (cpu_has_fxsr) {
1131 /*
1132 * Verify that the FXSAVE/FXRSTOR data will be 16-byte aligned.
1133 * Generates a compile-time "error: zero width for bit-field" if
1134 * the alignment is wrong.
1135 */
1136 struct fxsrAlignAssert {
1137 int _:!(offsetof(struct task_struct,
1138 thread.i387.fxsave) & 15);
1139 };
1140
1141 printk(KERN_INFO "Enabling fast FPU save and restore... ");
1142 set_in_cr4(X86_CR4_OSFXSR);
1143 printk("done.\n");
1144 }
1145 if (cpu_has_xmm) {
1146 printk(KERN_INFO "Enabling unmasked SIMD FPU exception "
1147 "support... ");
1148 set_in_cr4(X86_CR4_OSXMMEXCPT);
1149 printk("done.\n");
1150 }
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 set_system_gate(SYSCALL_VECTOR,&system_call);
1153
1154 /*
1155 * Should be a barrier for any external CPU state.
1156 */
1157 cpu_init();
1158
1159 trap_init_hook();
1160}
1161
1162static int __init kstack_setup(char *s)
1163{
1164 kstack_depth_to_print = simple_strtoul(s, NULL, 0);
1165 return 0;
1166}
1167__setup("kstack=", kstack_setup);