traps.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. /*
  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. * 'Traps.c' handles hardware traps and faults after we have saved some
  11. * state in 'asm.s'.
  12. */
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/string.h>
  16. #include <linux/errno.h>
  17. #include <linux/timer.h>
  18. #include <linux/mm.h>
  19. #include <linux/init.h>
  20. #include <linux/delay.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/highmem.h>
  24. #include <linux/kallsyms.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/utsname.h>
  27. #include <linux/kprobes.h>
  28. #include <linux/kexec.h>
  29. #include <linux/unwind.h>
  30. #include <linux/uaccess.h>
  31. #ifdef CONFIG_EISA
  32. #include <linux/ioport.h>
  33. #include <linux/eisa.h>
  34. #endif
  35. #ifdef CONFIG_MCA
  36. #include <linux/mca.h>
  37. #endif
  38. #include <asm/processor.h>
  39. #include <asm/system.h>
  40. #include <asm/io.h>
  41. #include <asm/atomic.h>
  42. #include <asm/debugreg.h>
  43. #include <asm/desc.h>
  44. #include <asm/i387.h>
  45. #include <asm/nmi.h>
  46. #include <asm/unwind.h>
  47. #include <asm/smp.h>
  48. #include <asm/arch_hooks.h>
  49. #include <asm/kdebug.h>
  50. #include <asm/stacktrace.h>
  51. #include <linux/module.h>
  52. #include "mach_traps.h"
  53. asmlinkage int system_call(void);
  54. struct desc_struct default_ldt[] = { { 0, 0 }, { 0, 0 }, { 0, 0 },
  55. { 0, 0 }, { 0, 0 } };
  56. /* Do we ignore FPU interrupts ? */
  57. char ignore_fpu_irq = 0;
  58. /*
  59. * The IDT has to be page-aligned to simplify the Pentium
  60. * F0 0F bug workaround.. We have a special link segment
  61. * for this.
  62. */
  63. struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, };
  64. asmlinkage void divide_error(void);
  65. asmlinkage void debug(void);
  66. asmlinkage void nmi(void);
  67. asmlinkage void int3(void);
  68. asmlinkage void overflow(void);
  69. asmlinkage void bounds(void);
  70. asmlinkage void invalid_op(void);
  71. asmlinkage void device_not_available(void);
  72. asmlinkage void coprocessor_segment_overrun(void);
  73. asmlinkage void invalid_TSS(void);
  74. asmlinkage void segment_not_present(void);
  75. asmlinkage void stack_segment(void);
  76. asmlinkage void general_protection(void);
  77. asmlinkage void page_fault(void);
  78. asmlinkage void coprocessor_error(void);
  79. asmlinkage void simd_coprocessor_error(void);
  80. asmlinkage void alignment_check(void);
  81. asmlinkage void spurious_interrupt_bug(void);
  82. asmlinkage void machine_check(void);
  83. static int kstack_depth_to_print = 24;
  84. #ifdef CONFIG_STACK_UNWIND
  85. static int call_trace = 1;
  86. #else
  87. #define call_trace (-1)
  88. #endif
  89. ATOMIC_NOTIFIER_HEAD(i386die_chain);
  90. int register_die_notifier(struct notifier_block *nb)
  91. {
  92. vmalloc_sync_all();
  93. return atomic_notifier_chain_register(&i386die_chain, nb);
  94. }
  95. EXPORT_SYMBOL(register_die_notifier); /* used modular by kdb */
  96. int unregister_die_notifier(struct notifier_block *nb)
  97. {
  98. return atomic_notifier_chain_unregister(&i386die_chain, nb);
  99. }
  100. EXPORT_SYMBOL(unregister_die_notifier); /* used modular by kdb */
  101. static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
  102. {
  103. return p > (void *)tinfo &&
  104. p < (void *)tinfo + THREAD_SIZE - 3;
  105. }
  106. static inline unsigned long print_context_stack(struct thread_info *tinfo,
  107. unsigned long *stack, unsigned long ebp,
  108. struct stacktrace_ops *ops, void *data)
  109. {
  110. unsigned long addr;
  111. #ifdef CONFIG_FRAME_POINTER
  112. while (valid_stack_ptr(tinfo, (void *)ebp)) {
  113. addr = *(unsigned long *)(ebp + 4);
  114. ops->address(data, addr);
  115. /*
  116. * break out of recursive entries (such as
  117. * end_of_stack_stop_unwind_function):
  118. */
  119. if (ebp == *(unsigned long *)ebp)
  120. break;
  121. ebp = *(unsigned long *)ebp;
  122. }
  123. #else
  124. while (valid_stack_ptr(tinfo, stack)) {
  125. addr = *stack++;
  126. if (__kernel_text_address(addr))
  127. ops->address(data, addr);
  128. }
  129. #endif
  130. return ebp;
  131. }
  132. struct ops_and_data {
  133. struct stacktrace_ops *ops;
  134. void *data;
  135. };
  136. static asmlinkage int
  137. dump_trace_unwind(struct unwind_frame_info *info, void *data)
  138. {
  139. struct ops_and_data *oad = (struct ops_and_data *)data;
  140. int n = 0;
  141. while (unwind(info) == 0 && UNW_PC(info)) {
  142. n++;
  143. oad->ops->address(oad->data, UNW_PC(info));
  144. if (arch_unw_user_mode(info))
  145. break;
  146. }
  147. return n;
  148. }
  149. void dump_trace(struct task_struct *task, struct pt_regs *regs,
  150. unsigned long *stack,
  151. struct stacktrace_ops *ops, void *data)
  152. {
  153. unsigned long ebp = 0;
  154. if (!task)
  155. task = current;
  156. if (call_trace >= 0) {
  157. int unw_ret = 0;
  158. struct unwind_frame_info info;
  159. struct ops_and_data oad = { .ops = ops, .data = data };
  160. if (regs) {
  161. if (unwind_init_frame_info(&info, task, regs) == 0)
  162. unw_ret = dump_trace_unwind(&info, &oad);
  163. } else if (task == current)
  164. unw_ret = unwind_init_running(&info, dump_trace_unwind, &oad);
  165. else {
  166. if (unwind_init_blocked(&info, task) == 0)
  167. unw_ret = dump_trace_unwind(&info, &oad);
  168. }
  169. if (unw_ret > 0) {
  170. if (call_trace == 1 && !arch_unw_user_mode(&info)) {
  171. ops->warning_symbol(data, "DWARF2 unwinder stuck at %s\n",
  172. UNW_PC(&info));
  173. if (UNW_SP(&info) >= PAGE_OFFSET) {
  174. ops->warning(data, "Leftover inexact backtrace:\n");
  175. stack = (void *)UNW_SP(&info);
  176. if (!stack)
  177. return;
  178. ebp = UNW_FP(&info);
  179. } else
  180. ops->warning(data, "Full inexact backtrace again:\n");
  181. } else if (call_trace >= 1)
  182. return;
  183. else
  184. ops->warning(data, "Full inexact backtrace again:\n");
  185. } else
  186. ops->warning(data, "Inexact backtrace:\n");
  187. }
  188. if (!stack) {
  189. unsigned long dummy;
  190. stack = &dummy;
  191. if (task && task != current)
  192. stack = (unsigned long *)task->thread.esp;
  193. }
  194. #ifdef CONFIG_FRAME_POINTER
  195. if (!ebp) {
  196. if (task == current) {
  197. /* Grab ebp right from our regs */
  198. asm ("movl %%ebp, %0" : "=r" (ebp) : );
  199. } else {
  200. /* ebp is the last reg pushed by switch_to */
  201. ebp = *(unsigned long *) task->thread.esp;
  202. }
  203. }
  204. #endif
  205. while (1) {
  206. struct thread_info *context;
  207. context = (struct thread_info *)
  208. ((unsigned long)stack & (~(THREAD_SIZE - 1)));
  209. ebp = print_context_stack(context, stack, ebp, ops, data);
  210. /* Should be after the line below, but somewhere
  211. in early boot context comes out corrupted and we
  212. can't reference it -AK */
  213. if (ops->stack(data, "IRQ") < 0)
  214. break;
  215. stack = (unsigned long*)context->previous_esp;
  216. if (!stack)
  217. break;
  218. }
  219. }
  220. EXPORT_SYMBOL(dump_trace);
  221. static void
  222. print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
  223. {
  224. printk(data);
  225. print_symbol(msg, symbol);
  226. printk("\n");
  227. }
  228. static void print_trace_warning(void *data, char *msg)
  229. {
  230. printk("%s%s\n", (char *)data, msg);
  231. }
  232. static int print_trace_stack(void *data, char *name)
  233. {
  234. return 0;
  235. }
  236. /*
  237. * Print one address/symbol entries per line.
  238. */
  239. static void print_trace_address(void *data, unsigned long addr)
  240. {
  241. printk("%s [<%08lx>] ", (char *)data, addr);
  242. print_symbol("%s\n", addr);
  243. }
  244. static struct stacktrace_ops print_trace_ops = {
  245. .warning = print_trace_warning,
  246. .warning_symbol = print_trace_warning_symbol,
  247. .stack = print_trace_stack,
  248. .address = print_trace_address,
  249. };
  250. static void
  251. show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
  252. unsigned long * stack, char *log_lvl)
  253. {
  254. dump_trace(task, regs, stack, &print_trace_ops, log_lvl);
  255. printk("%s =======================\n", log_lvl);
  256. }
  257. void show_trace(struct task_struct *task, struct pt_regs *regs,
  258. unsigned long * stack)
  259. {
  260. show_trace_log_lvl(task, regs, stack, "");
  261. }
  262. static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
  263. unsigned long *esp, char *log_lvl)
  264. {
  265. unsigned long *stack;
  266. int i;
  267. if (esp == NULL) {
  268. if (task)
  269. esp = (unsigned long*)task->thread.esp;
  270. else
  271. esp = (unsigned long *)&esp;
  272. }
  273. stack = esp;
  274. for(i = 0; i < kstack_depth_to_print; i++) {
  275. if (kstack_end(stack))
  276. break;
  277. if (i && ((i % 8) == 0))
  278. printk("\n%s ", log_lvl);
  279. printk("%08lx ", *stack++);
  280. }
  281. printk("\n%sCall Trace:\n", log_lvl);
  282. show_trace_log_lvl(task, regs, esp, log_lvl);
  283. }
  284. void show_stack(struct task_struct *task, unsigned long *esp)
  285. {
  286. printk(" ");
  287. show_stack_log_lvl(task, NULL, esp, "");
  288. }
  289. /*
  290. * The architecture-independent dump_stack generator
  291. */
  292. void dump_stack(void)
  293. {
  294. unsigned long stack;
  295. show_trace(current, NULL, &stack);
  296. }
  297. EXPORT_SYMBOL(dump_stack);
  298. void show_registers(struct pt_regs *regs)
  299. {
  300. int i;
  301. int in_kernel = 1;
  302. unsigned long esp;
  303. unsigned short ss;
  304. esp = (unsigned long) (&regs->esp);
  305. savesegment(ss, ss);
  306. if (user_mode_vm(regs)) {
  307. in_kernel = 0;
  308. esp = regs->esp;
  309. ss = regs->xss & 0xffff;
  310. }
  311. print_modules();
  312. printk(KERN_EMERG "CPU: %d\n"
  313. KERN_EMERG "EIP: %04x:[<%08lx>] %s VLI\n"
  314. KERN_EMERG "EFLAGS: %08lx (%s %.*s)\n",
  315. smp_processor_id(), 0xffff & regs->xcs, regs->eip,
  316. print_tainted(), regs->eflags, system_utsname.release,
  317. (int)strcspn(system_utsname.version, " "),
  318. system_utsname.version);
  319. print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip);
  320. printk(KERN_EMERG "eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
  321. regs->eax, regs->ebx, regs->ecx, regs->edx);
  322. printk(KERN_EMERG "esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n",
  323. regs->esi, regs->edi, regs->ebp, esp);
  324. printk(KERN_EMERG "ds: %04x es: %04x ss: %04x\n",
  325. regs->xds & 0xffff, regs->xes & 0xffff, ss);
  326. printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)",
  327. TASK_COMM_LEN, current->comm, current->pid,
  328. current_thread_info(), current, current->thread_info);
  329. /*
  330. * When in-kernel, we also print out the stack and code at the
  331. * time of the fault..
  332. */
  333. if (in_kernel) {
  334. u8 __user *eip;
  335. int code_bytes = 64;
  336. unsigned char c;
  337. printk("\n" KERN_EMERG "Stack: ");
  338. show_stack_log_lvl(NULL, regs, (unsigned long *)esp, KERN_EMERG);
  339. printk(KERN_EMERG "Code: ");
  340. eip = (u8 __user *)regs->eip - 43;
  341. if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) {
  342. /* try starting at EIP */
  343. eip = (u8 __user *)regs->eip;
  344. code_bytes = 32;
  345. }
  346. for (i = 0; i < code_bytes; i++, eip++) {
  347. if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) {
  348. printk(" Bad EIP value.");
  349. break;
  350. }
  351. if (eip == (u8 __user *)regs->eip)
  352. printk("<%02x> ", c);
  353. else
  354. printk("%02x ", c);
  355. }
  356. }
  357. printk("\n");
  358. }
  359. static void handle_BUG(struct pt_regs *regs)
  360. {
  361. unsigned long eip = regs->eip;
  362. unsigned short ud2;
  363. if (eip < PAGE_OFFSET)
  364. return;
  365. if (probe_kernel_address((unsigned short __user *)eip, ud2))
  366. return;
  367. if (ud2 != 0x0b0f)
  368. return;
  369. printk(KERN_EMERG "------------[ cut here ]------------\n");
  370. #ifdef CONFIG_DEBUG_BUGVERBOSE
  371. do {
  372. unsigned short line;
  373. char *file;
  374. char c;
  375. if (probe_kernel_address((unsigned short __user *)(eip + 2),
  376. line))
  377. break;
  378. if (__get_user(file, (char * __user *)(eip + 4)) ||
  379. (unsigned long)file < PAGE_OFFSET || __get_user(c, file))
  380. file = "<bad filename>";
  381. printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);
  382. return;
  383. } while (0);
  384. #endif
  385. printk(KERN_EMERG "Kernel BUG at [verbose debug info unavailable]\n");
  386. }
  387. /* This is gone through when something in the kernel
  388. * has done something bad and is about to be terminated.
  389. */
  390. void die(const char * str, struct pt_regs * regs, long err)
  391. {
  392. static struct {
  393. spinlock_t lock;
  394. u32 lock_owner;
  395. int lock_owner_depth;
  396. } die = {
  397. .lock = SPIN_LOCK_UNLOCKED,
  398. .lock_owner = -1,
  399. .lock_owner_depth = 0
  400. };
  401. static int die_counter;
  402. unsigned long flags;
  403. oops_enter();
  404. if (die.lock_owner != raw_smp_processor_id()) {
  405. console_verbose();
  406. spin_lock_irqsave(&die.lock, flags);
  407. die.lock_owner = smp_processor_id();
  408. die.lock_owner_depth = 0;
  409. bust_spinlocks(1);
  410. }
  411. else
  412. local_save_flags(flags);
  413. if (++die.lock_owner_depth < 3) {
  414. int nl = 0;
  415. unsigned long esp;
  416. unsigned short ss;
  417. handle_BUG(regs);
  418. printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
  419. #ifdef CONFIG_PREEMPT
  420. printk(KERN_EMERG "PREEMPT ");
  421. nl = 1;
  422. #endif
  423. #ifdef CONFIG_SMP
  424. if (!nl)
  425. printk(KERN_EMERG);
  426. printk("SMP ");
  427. nl = 1;
  428. #endif
  429. #ifdef CONFIG_DEBUG_PAGEALLOC
  430. if (!nl)
  431. printk(KERN_EMERG);
  432. printk("DEBUG_PAGEALLOC");
  433. nl = 1;
  434. #endif
  435. if (nl)
  436. printk("\n");
  437. if (notify_die(DIE_OOPS, str, regs, err,
  438. current->thread.trap_no, SIGSEGV) !=
  439. NOTIFY_STOP) {
  440. show_registers(regs);
  441. /* Executive summary in case the oops scrolled away */
  442. esp = (unsigned long) (&regs->esp);
  443. savesegment(ss, ss);
  444. if (user_mode(regs)) {
  445. esp = regs->esp;
  446. ss = regs->xss & 0xffff;
  447. }
  448. printk(KERN_EMERG "EIP: [<%08lx>] ", regs->eip);
  449. print_symbol("%s", regs->eip);
  450. printk(" SS:ESP %04x:%08lx\n", ss, esp);
  451. }
  452. else
  453. regs = NULL;
  454. } else
  455. printk(KERN_EMERG "Recursive die() failure, output suppressed\n");
  456. bust_spinlocks(0);
  457. die.lock_owner = -1;
  458. spin_unlock_irqrestore(&die.lock, flags);
  459. if (!regs)
  460. return;
  461. if (kexec_should_crash(current))
  462. crash_kexec(regs);
  463. if (in_interrupt())
  464. panic("Fatal exception in interrupt");
  465. if (panic_on_oops)
  466. panic("Fatal exception");
  467. oops_exit();
  468. do_exit(SIGSEGV);
  469. }
  470. static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err)
  471. {
  472. if (!user_mode_vm(regs))
  473. die(str, regs, err);
  474. }
  475. static void __kprobes do_trap(int trapnr, int signr, char *str, int vm86,
  476. struct pt_regs * regs, long error_code,
  477. siginfo_t *info)
  478. {
  479. struct task_struct *tsk = current;
  480. tsk->thread.error_code = error_code;
  481. tsk->thread.trap_no = trapnr;
  482. if (regs->eflags & VM_MASK) {
  483. if (vm86)
  484. goto vm86_trap;
  485. goto trap_signal;
  486. }
  487. if (!user_mode(regs))
  488. goto kernel_trap;
  489. trap_signal: {
  490. if (info)
  491. force_sig_info(signr, info, tsk);
  492. else
  493. force_sig(signr, tsk);
  494. return;
  495. }
  496. kernel_trap: {
  497. if (!fixup_exception(regs))
  498. die(str, regs, error_code);
  499. return;
  500. }
  501. vm86_trap: {
  502. int ret = handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, trapnr);
  503. if (ret) goto trap_signal;
  504. return;
  505. }
  506. }
  507. #define DO_ERROR(trapnr, signr, str, name) \
  508. fastcall void do_##name(struct pt_regs * regs, long error_code) \
  509. { \
  510. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  511. == NOTIFY_STOP) \
  512. return; \
  513. do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \
  514. }
  515. #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
  516. fastcall void do_##name(struct pt_regs * regs, long error_code) \
  517. { \
  518. siginfo_t info; \
  519. info.si_signo = signr; \
  520. info.si_errno = 0; \
  521. info.si_code = sicode; \
  522. info.si_addr = (void __user *)siaddr; \
  523. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  524. == NOTIFY_STOP) \
  525. return; \
  526. do_trap(trapnr, signr, str, 0, regs, error_code, &info); \
  527. }
  528. #define DO_VM86_ERROR(trapnr, signr, str, name) \
  529. fastcall void do_##name(struct pt_regs * regs, long error_code) \
  530. { \
  531. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  532. == NOTIFY_STOP) \
  533. return; \
  534. do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \
  535. }
  536. #define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
  537. fastcall void do_##name(struct pt_regs * regs, long error_code) \
  538. { \
  539. siginfo_t info; \
  540. info.si_signo = signr; \
  541. info.si_errno = 0; \
  542. info.si_code = sicode; \
  543. info.si_addr = (void __user *)siaddr; \
  544. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  545. == NOTIFY_STOP) \
  546. return; \
  547. do_trap(trapnr, signr, str, 1, regs, error_code, &info); \
  548. }
  549. DO_VM86_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->eip)
  550. #ifndef CONFIG_KPROBES
  551. DO_VM86_ERROR( 3, SIGTRAP, "int3", int3)
  552. #endif
  553. DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow)
  554. DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds)
  555. DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip)
  556. DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
  557. DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
  558. DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
  559. DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
  560. DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
  561. DO_ERROR_INFO(32, SIGSEGV, "iret exception", iret_error, ILL_BADSTK, 0)
  562. fastcall void __kprobes do_general_protection(struct pt_regs * regs,
  563. long error_code)
  564. {
  565. int cpu = get_cpu();
  566. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  567. struct thread_struct *thread = &current->thread;
  568. /*
  569. * Perform the lazy TSS's I/O bitmap copy. If the TSS has an
  570. * invalid offset set (the LAZY one) and the faulting thread has
  571. * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS
  572. * and we set the offset field correctly. Then we let the CPU to
  573. * restart the faulting instruction.
  574. */
  575. if (tss->io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY &&
  576. thread->io_bitmap_ptr) {
  577. memcpy(tss->io_bitmap, thread->io_bitmap_ptr,
  578. thread->io_bitmap_max);
  579. /*
  580. * If the previously set map was extending to higher ports
  581. * than the current one, pad extra space with 0xff (no access).
  582. */
  583. if (thread->io_bitmap_max < tss->io_bitmap_max)
  584. memset((char *) tss->io_bitmap +
  585. thread->io_bitmap_max, 0xff,
  586. tss->io_bitmap_max - thread->io_bitmap_max);
  587. tss->io_bitmap_max = thread->io_bitmap_max;
  588. tss->io_bitmap_base = IO_BITMAP_OFFSET;
  589. tss->io_bitmap_owner = thread;
  590. put_cpu();
  591. return;
  592. }
  593. put_cpu();
  594. current->thread.error_code = error_code;
  595. current->thread.trap_no = 13;
  596. if (regs->eflags & VM_MASK)
  597. goto gp_in_vm86;
  598. if (!user_mode(regs))
  599. goto gp_in_kernel;
  600. current->thread.error_code = error_code;
  601. current->thread.trap_no = 13;
  602. force_sig(SIGSEGV, current);
  603. return;
  604. gp_in_vm86:
  605. local_irq_enable();
  606. handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
  607. return;
  608. gp_in_kernel:
  609. if (!fixup_exception(regs)) {
  610. if (notify_die(DIE_GPF, "general protection fault", regs,
  611. error_code, 13, SIGSEGV) == NOTIFY_STOP)
  612. return;
  613. die("general protection fault", regs, error_code);
  614. }
  615. }
  616. static __kprobes void
  617. mem_parity_error(unsigned char reason, struct pt_regs * regs)
  618. {
  619. printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x on "
  620. "CPU %d.\n", reason, smp_processor_id());
  621. printk(KERN_EMERG "You probably have a hardware problem with your RAM "
  622. "chips\n");
  623. if (panic_on_unrecovered_nmi)
  624. panic("NMI: Not continuing");
  625. printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
  626. /* Clear and disable the memory parity error line. */
  627. clear_mem_error(reason);
  628. }
  629. static __kprobes void
  630. io_check_error(unsigned char reason, struct pt_regs * regs)
  631. {
  632. unsigned long i;
  633. printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
  634. show_registers(regs);
  635. /* Re-enable the IOCK line, wait for a few seconds */
  636. reason = (reason & 0xf) | 8;
  637. outb(reason, 0x61);
  638. i = 2000;
  639. while (--i) udelay(1000);
  640. reason &= ~8;
  641. outb(reason, 0x61);
  642. }
  643. static __kprobes void
  644. unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
  645. {
  646. #ifdef CONFIG_MCA
  647. /* Might actually be able to figure out what the guilty party
  648. * is. */
  649. if( MCA_bus ) {
  650. mca_handle_nmi();
  651. return;
  652. }
  653. #endif
  654. printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x on "
  655. "CPU %d.\n", reason, smp_processor_id());
  656. printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n");
  657. if (panic_on_unrecovered_nmi)
  658. panic("NMI: Not continuing");
  659. printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
  660. }
  661. static DEFINE_SPINLOCK(nmi_print_lock);
  662. void __kprobes die_nmi(struct pt_regs *regs, const char *msg)
  663. {
  664. if (notify_die(DIE_NMIWATCHDOG, msg, regs, 0, 2, SIGINT) ==
  665. NOTIFY_STOP)
  666. return;
  667. spin_lock(&nmi_print_lock);
  668. /*
  669. * We are in trouble anyway, lets at least try
  670. * to get a message out.
  671. */
  672. bust_spinlocks(1);
  673. printk(KERN_EMERG "%s", msg);
  674. printk(" on CPU%d, eip %08lx, registers:\n",
  675. smp_processor_id(), regs->eip);
  676. show_registers(regs);
  677. printk(KERN_EMERG "console shuts up ...\n");
  678. console_silent();
  679. spin_unlock(&nmi_print_lock);
  680. bust_spinlocks(0);
  681. /* If we are in kernel we are probably nested up pretty bad
  682. * and might aswell get out now while we still can.
  683. */
  684. if (!user_mode_vm(regs)) {
  685. current->thread.trap_no = 2;
  686. crash_kexec(regs);
  687. }
  688. do_exit(SIGSEGV);
  689. }
  690. static __kprobes void default_do_nmi(struct pt_regs * regs)
  691. {
  692. unsigned char reason = 0;
  693. /* Only the BSP gets external NMIs from the system. */
  694. if (!smp_processor_id())
  695. reason = get_nmi_reason();
  696. if (!(reason & 0xc0)) {
  697. if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
  698. == NOTIFY_STOP)
  699. return;
  700. #ifdef CONFIG_X86_LOCAL_APIC
  701. /*
  702. * Ok, so this is none of the documented NMI sources,
  703. * so it must be the NMI watchdog.
  704. */
  705. if (nmi_watchdog_tick(regs, reason))
  706. return;
  707. if (!do_nmi_callback(regs, smp_processor_id()))
  708. #endif
  709. unknown_nmi_error(reason, regs);
  710. return;
  711. }
  712. if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
  713. return;
  714. if (reason & 0x80)
  715. mem_parity_error(reason, regs);
  716. if (reason & 0x40)
  717. io_check_error(reason, regs);
  718. /*
  719. * Reassert NMI in case it became active meanwhile
  720. * as it's edge-triggered.
  721. */
  722. reassert_nmi();
  723. }
  724. fastcall __kprobes void do_nmi(struct pt_regs * regs, long error_code)
  725. {
  726. int cpu;
  727. nmi_enter();
  728. cpu = smp_processor_id();
  729. ++nmi_count(cpu);
  730. default_do_nmi(regs);
  731. nmi_exit();
  732. }
  733. #ifdef CONFIG_KPROBES
  734. fastcall void __kprobes do_int3(struct pt_regs *regs, long error_code)
  735. {
  736. if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
  737. == NOTIFY_STOP)
  738. return;
  739. /* This is an interrupt gate, because kprobes wants interrupts
  740. disabled. Normal trap handlers don't. */
  741. restore_interrupts(regs);
  742. do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
  743. }
  744. #endif
  745. /*
  746. * Our handling of the processor debug registers is non-trivial.
  747. * We do not clear them on entry and exit from the kernel. Therefore
  748. * it is possible to get a watchpoint trap here from inside the kernel.
  749. * However, the code in ./ptrace.c has ensured that the user can
  750. * only set watchpoints on userspace addresses. Therefore the in-kernel
  751. * watchpoint trap can only occur in code which is reading/writing
  752. * from user space. Such code must not hold kernel locks (since it
  753. * can equally take a page fault), therefore it is safe to call
  754. * force_sig_info even though that claims and releases locks.
  755. *
  756. * Code in ./signal.c ensures that the debug control register
  757. * is restored before we deliver any signal, and therefore that
  758. * user code runs with the correct debug control register even though
  759. * we clear it here.
  760. *
  761. * Being careful here means that we don't have to be as careful in a
  762. * lot of more complicated places (task switching can be a bit lazy
  763. * about restoring all the debug state, and ptrace doesn't have to
  764. * find every occurrence of the TF bit that could be saved away even
  765. * by user code)
  766. */
  767. fastcall void __kprobes do_debug(struct pt_regs * regs, long error_code)
  768. {
  769. unsigned int condition;
  770. struct task_struct *tsk = current;
  771. get_debugreg(condition, 6);
  772. if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
  773. SIGTRAP) == NOTIFY_STOP)
  774. return;
  775. /* It's safe to allow irq's after DR6 has been saved */
  776. if (regs->eflags & X86_EFLAGS_IF)
  777. local_irq_enable();
  778. /* Mask out spurious debug traps due to lazy DR7 setting */
  779. if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
  780. if (!tsk->thread.debugreg[7])
  781. goto clear_dr7;
  782. }
  783. if (regs->eflags & VM_MASK)
  784. goto debug_vm86;
  785. /* Save debug status register where ptrace can see it */
  786. tsk->thread.debugreg[6] = condition;
  787. /*
  788. * Single-stepping through TF: make sure we ignore any events in
  789. * kernel space (but re-enable TF when returning to user mode).
  790. */
  791. if (condition & DR_STEP) {
  792. /*
  793. * We already checked v86 mode above, so we can
  794. * check for kernel mode by just checking the CPL
  795. * of CS.
  796. */
  797. if (!user_mode(regs))
  798. goto clear_TF_reenable;
  799. }
  800. /* Ok, finally something we can handle */
  801. send_sigtrap(tsk, regs, error_code);
  802. /* Disable additional traps. They'll be re-enabled when
  803. * the signal is delivered.
  804. */
  805. clear_dr7:
  806. set_debugreg(0, 7);
  807. return;
  808. debug_vm86:
  809. handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1);
  810. return;
  811. clear_TF_reenable:
  812. set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
  813. regs->eflags &= ~TF_MASK;
  814. return;
  815. }
  816. /*
  817. * Note that we play around with the 'TS' bit in an attempt to get
  818. * the correct behaviour even in the presence of the asynchronous
  819. * IRQ13 behaviour
  820. */
  821. void math_error(void __user *eip)
  822. {
  823. struct task_struct * task;
  824. siginfo_t info;
  825. unsigned short cwd, swd;
  826. /*
  827. * Save the info for the exception handler and clear the error.
  828. */
  829. task = current;
  830. save_init_fpu(task);
  831. task->thread.trap_no = 16;
  832. task->thread.error_code = 0;
  833. info.si_signo = SIGFPE;
  834. info.si_errno = 0;
  835. info.si_code = __SI_FAULT;
  836. info.si_addr = eip;
  837. /*
  838. * (~cwd & swd) will mask out exceptions that are not set to unmasked
  839. * status. 0x3f is the exception bits in these regs, 0x200 is the
  840. * C1 reg you need in case of a stack fault, 0x040 is the stack
  841. * fault bit. We should only be taking one exception at a time,
  842. * so if this combination doesn't produce any single exception,
  843. * then we have a bad program that isn't syncronizing its FPU usage
  844. * and it will suffer the consequences since we won't be able to
  845. * fully reproduce the context of the exception
  846. */
  847. cwd = get_fpu_cwd(task);
  848. swd = get_fpu_swd(task);
  849. switch (swd & ~cwd & 0x3f) {
  850. case 0x000: /* No unmasked exception */
  851. return;
  852. default: /* Multiple exceptions */
  853. break;
  854. case 0x001: /* Invalid Op */
  855. /*
  856. * swd & 0x240 == 0x040: Stack Underflow
  857. * swd & 0x240 == 0x240: Stack Overflow
  858. * User must clear the SF bit (0x40) if set
  859. */
  860. info.si_code = FPE_FLTINV;
  861. break;
  862. case 0x002: /* Denormalize */
  863. case 0x010: /* Underflow */
  864. info.si_code = FPE_FLTUND;
  865. break;
  866. case 0x004: /* Zero Divide */
  867. info.si_code = FPE_FLTDIV;
  868. break;
  869. case 0x008: /* Overflow */
  870. info.si_code = FPE_FLTOVF;
  871. break;
  872. case 0x020: /* Precision */
  873. info.si_code = FPE_FLTRES;
  874. break;
  875. }
  876. force_sig_info(SIGFPE, &info, task);
  877. }
  878. fastcall void do_coprocessor_error(struct pt_regs * regs, long error_code)
  879. {
  880. ignore_fpu_irq = 1;
  881. math_error((void __user *)regs->eip);
  882. }
  883. static void simd_math_error(void __user *eip)
  884. {
  885. struct task_struct * task;
  886. siginfo_t info;
  887. unsigned short mxcsr;
  888. /*
  889. * Save the info for the exception handler and clear the error.
  890. */
  891. task = current;
  892. save_init_fpu(task);
  893. task->thread.trap_no = 19;
  894. task->thread.error_code = 0;
  895. info.si_signo = SIGFPE;
  896. info.si_errno = 0;
  897. info.si_code = __SI_FAULT;
  898. info.si_addr = eip;
  899. /*
  900. * The SIMD FPU exceptions are handled a little differently, as there
  901. * is only a single status/control register. Thus, to determine which
  902. * unmasked exception was caught we must mask the exception mask bits
  903. * at 0x1f80, and then use these to mask the exception bits at 0x3f.
  904. */
  905. mxcsr = get_fpu_mxcsr(task);
  906. switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
  907. case 0x000:
  908. default:
  909. break;
  910. case 0x001: /* Invalid Op */
  911. info.si_code = FPE_FLTINV;
  912. break;
  913. case 0x002: /* Denormalize */
  914. case 0x010: /* Underflow */
  915. info.si_code = FPE_FLTUND;
  916. break;
  917. case 0x004: /* Zero Divide */
  918. info.si_code = FPE_FLTDIV;
  919. break;
  920. case 0x008: /* Overflow */
  921. info.si_code = FPE_FLTOVF;
  922. break;
  923. case 0x020: /* Precision */
  924. info.si_code = FPE_FLTRES;
  925. break;
  926. }
  927. force_sig_info(SIGFPE, &info, task);
  928. }
  929. fastcall void do_simd_coprocessor_error(struct pt_regs * regs,
  930. long error_code)
  931. {
  932. if (cpu_has_xmm) {
  933. /* Handle SIMD FPU exceptions on PIII+ processors. */
  934. ignore_fpu_irq = 1;
  935. simd_math_error((void __user *)regs->eip);
  936. } else {
  937. /*
  938. * Handle strange cache flush from user space exception
  939. * in all other cases. This is undocumented behaviour.
  940. */
  941. if (regs->eflags & VM_MASK) {
  942. handle_vm86_fault((struct kernel_vm86_regs *)regs,
  943. error_code);
  944. return;
  945. }
  946. current->thread.trap_no = 19;
  947. current->thread.error_code = error_code;
  948. die_if_kernel("cache flush denied", regs, error_code);
  949. force_sig(SIGSEGV, current);
  950. }
  951. }
  952. fastcall void do_spurious_interrupt_bug(struct pt_regs * regs,
  953. long error_code)
  954. {
  955. #if 0
  956. /* No need to warn about this any longer. */
  957. printk("Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
  958. #endif
  959. }
  960. fastcall void setup_x86_bogus_stack(unsigned char * stk)
  961. {
  962. unsigned long *switch16_ptr, *switch32_ptr;
  963. struct pt_regs *regs;
  964. unsigned long stack_top, stack_bot;
  965. unsigned short iret_frame16_off;
  966. int cpu = smp_processor_id();
  967. /* reserve the space on 32bit stack for the magic switch16 pointer */
  968. memmove(stk, stk + 8, sizeof(struct pt_regs));
  969. switch16_ptr = (unsigned long *)(stk + sizeof(struct pt_regs));
  970. regs = (struct pt_regs *)stk;
  971. /* now the switch32 on 16bit stack */
  972. stack_bot = (unsigned long)&per_cpu(cpu_16bit_stack, cpu);
  973. stack_top = stack_bot + CPU_16BIT_STACK_SIZE;
  974. switch32_ptr = (unsigned long *)(stack_top - 8);
  975. iret_frame16_off = CPU_16BIT_STACK_SIZE - 8 - 20;
  976. /* copy iret frame on 16bit stack */
  977. memcpy((void *)(stack_bot + iret_frame16_off), &regs->eip, 20);
  978. /* fill in the switch pointers */
  979. switch16_ptr[0] = (regs->esp & 0xffff0000) | iret_frame16_off;
  980. switch16_ptr[1] = __ESPFIX_SS;
  981. switch32_ptr[0] = (unsigned long)stk + sizeof(struct pt_regs) +
  982. 8 - CPU_16BIT_STACK_SIZE;
  983. switch32_ptr[1] = __KERNEL_DS;
  984. }
  985. fastcall unsigned char * fixup_x86_bogus_stack(unsigned short sp)
  986. {
  987. unsigned long *switch32_ptr;
  988. unsigned char *stack16, *stack32;
  989. unsigned long stack_top, stack_bot;
  990. int len;
  991. int cpu = smp_processor_id();
  992. stack_bot = (unsigned long)&per_cpu(cpu_16bit_stack, cpu);
  993. stack_top = stack_bot + CPU_16BIT_STACK_SIZE;
  994. switch32_ptr = (unsigned long *)(stack_top - 8);
  995. /* copy the data from 16bit stack to 32bit stack */
  996. len = CPU_16BIT_STACK_SIZE - 8 - sp;
  997. stack16 = (unsigned char *)(stack_bot + sp);
  998. stack32 = (unsigned char *)
  999. (switch32_ptr[0] + CPU_16BIT_STACK_SIZE - 8 - len);
  1000. memcpy(stack32, stack16, len);
  1001. return stack32;
  1002. }
  1003. /*
  1004. * 'math_state_restore()' saves the current math information in the
  1005. * old math state array, and gets the new ones from the current task
  1006. *
  1007. * Careful.. There are problems with IBM-designed IRQ13 behaviour.
  1008. * Don't touch unless you *really* know how it works.
  1009. *
  1010. * Must be called with kernel preemption disabled (in this case,
  1011. * local interrupts are disabled at the call-site in entry.S).
  1012. */
  1013. asmlinkage void math_state_restore(struct pt_regs regs)
  1014. {
  1015. struct thread_info *thread = current_thread_info();
  1016. struct task_struct *tsk = thread->task;
  1017. clts(); /* Allow maths ops (or we recurse) */
  1018. if (!tsk_used_math(tsk))
  1019. init_fpu(tsk);
  1020. restore_fpu(tsk);
  1021. thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */
  1022. }
  1023. #ifndef CONFIG_MATH_EMULATION
  1024. asmlinkage void math_emulate(long arg)
  1025. {
  1026. printk(KERN_EMERG "math-emulation not enabled and no coprocessor found.\n");
  1027. printk(KERN_EMERG "killing %s.\n",current->comm);
  1028. force_sig(SIGFPE,current);
  1029. schedule();
  1030. }
  1031. #endif /* CONFIG_MATH_EMULATION */
  1032. #ifdef CONFIG_X86_F00F_BUG
  1033. void __init trap_init_f00f_bug(void)
  1034. {
  1035. __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
  1036. /*
  1037. * Update the IDT descriptor and reload the IDT so that
  1038. * it uses the read-only mapped virtual address.
  1039. */
  1040. idt_descr.address = fix_to_virt(FIX_F00F_IDT);
  1041. load_idt(&idt_descr);
  1042. }
  1043. #endif
  1044. /*
  1045. * This needs to use 'idt_table' rather than 'idt', and
  1046. * thus use the _nonmapped_ version of the IDT, as the
  1047. * Pentium F0 0F bugfix can have resulted in the mapped
  1048. * IDT being write-protected.
  1049. */
  1050. void set_intr_gate(unsigned int n, void *addr)
  1051. {
  1052. _set_gate(n, DESCTYPE_INT, addr, __KERNEL_CS);
  1053. }
  1054. /*
  1055. * This routine sets up an interrupt gate at directory privilege level 3.
  1056. */
  1057. static inline void set_system_intr_gate(unsigned int n, void *addr)
  1058. {
  1059. _set_gate(n, DESCTYPE_INT | DESCTYPE_DPL3, addr, __KERNEL_CS);
  1060. }
  1061. static void __init set_trap_gate(unsigned int n, void *addr)
  1062. {
  1063. _set_gate(n, DESCTYPE_TRAP, addr, __KERNEL_CS);
  1064. }
  1065. static void __init set_system_gate(unsigned int n, void *addr)
  1066. {
  1067. _set_gate(n, DESCTYPE_TRAP | DESCTYPE_DPL3, addr, __KERNEL_CS);
  1068. }
  1069. static void __init set_task_gate(unsigned int n, unsigned int gdt_entry)
  1070. {
  1071. _set_gate(n, DESCTYPE_TASK, (void *)0, (gdt_entry<<3));
  1072. }
  1073. void __init trap_init(void)
  1074. {
  1075. #ifdef CONFIG_EISA
  1076. void __iomem *p = ioremap(0x0FFFD9, 4);
  1077. if (readl(p) == 'E'+('I'<<8)+('S'<<16)+('A'<<24)) {
  1078. EISA_bus = 1;
  1079. }
  1080. iounmap(p);
  1081. #endif
  1082. #ifdef CONFIG_X86_LOCAL_APIC
  1083. init_apic_mappings();
  1084. #endif
  1085. set_trap_gate(0,&divide_error);
  1086. set_intr_gate(1,&debug);
  1087. set_intr_gate(2,&nmi);
  1088. set_system_intr_gate(3, &int3); /* int3/4 can be called from all */
  1089. set_system_gate(4,&overflow);
  1090. set_trap_gate(5,&bounds);
  1091. set_trap_gate(6,&invalid_op);
  1092. set_trap_gate(7,&device_not_available);
  1093. set_task_gate(8,GDT_ENTRY_DOUBLEFAULT_TSS);
  1094. set_trap_gate(9,&coprocessor_segment_overrun);
  1095. set_trap_gate(10,&invalid_TSS);
  1096. set_trap_gate(11,&segment_not_present);
  1097. set_trap_gate(12,&stack_segment);
  1098. set_trap_gate(13,&general_protection);
  1099. set_intr_gate(14,&page_fault);
  1100. set_trap_gate(15,&spurious_interrupt_bug);
  1101. set_trap_gate(16,&coprocessor_error);
  1102. set_trap_gate(17,&alignment_check);
  1103. #ifdef CONFIG_X86_MCE
  1104. set_trap_gate(18,&machine_check);
  1105. #endif
  1106. set_trap_gate(19,&simd_coprocessor_error);
  1107. if (cpu_has_fxsr) {
  1108. /*
  1109. * Verify that the FXSAVE/FXRSTOR data will be 16-byte aligned.
  1110. * Generates a compile-time "error: zero width for bit-field" if
  1111. * the alignment is wrong.
  1112. */
  1113. struct fxsrAlignAssert {
  1114. int _:!(offsetof(struct task_struct,
  1115. thread.i387.fxsave) & 15);
  1116. };
  1117. printk(KERN_INFO "Enabling fast FPU save and restore... ");
  1118. set_in_cr4(X86_CR4_OSFXSR);
  1119. printk("done.\n");
  1120. }
  1121. if (cpu_has_xmm) {
  1122. printk(KERN_INFO "Enabling unmasked SIMD FPU exception "
  1123. "support... ");
  1124. set_in_cr4(X86_CR4_OSXMMEXCPT);
  1125. printk("done.\n");
  1126. }
  1127. set_system_gate(SYSCALL_VECTOR,&system_call);
  1128. /*
  1129. * Should be a barrier for any external CPU state.
  1130. */
  1131. cpu_init();
  1132. trap_init_hook();
  1133. }
  1134. static int __init kstack_setup(char *s)
  1135. {
  1136. kstack_depth_to_print = simple_strtoul(s, NULL, 0);
  1137. return 1;
  1138. }
  1139. __setup("kstack=", kstack_setup);
  1140. #ifdef CONFIG_STACK_UNWIND
  1141. static int __init call_trace_setup(char *s)
  1142. {
  1143. if (strcmp(s, "old") == 0)
  1144. call_trace = -1;
  1145. else if (strcmp(s, "both") == 0)
  1146. call_trace = 0;
  1147. else if (strcmp(s, "newfallback") == 0)
  1148. call_trace = 1;
  1149. else if (strcmp(s, "new") == 2)
  1150. call_trace = 2;
  1151. return 1;
  1152. }
  1153. __setup("call_trace=", call_trace_setup);
  1154. #endif