traps.c 34 KB

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