traps.c 33 KB

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