traps.c 34 KB

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