traps_32.c 33 KB

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