traps.c 33 KB

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