traps.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. * Handle hardware traps and faults.
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/kallsyms.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/kprobes.h>
  15. #include <linux/uaccess.h>
  16. #include <linux/kdebug.h>
  17. #include <linux/kgdb.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/string.h>
  22. #include <linux/delay.h>
  23. #include <linux/errno.h>
  24. #include <linux/kexec.h>
  25. #include <linux/sched.h>
  26. #include <linux/timer.h>
  27. #include <linux/init.h>
  28. #include <linux/bug.h>
  29. #include <linux/nmi.h>
  30. #include <linux/mm.h>
  31. #include <linux/smp.h>
  32. #include <linux/io.h>
  33. #ifdef CONFIG_EISA
  34. #include <linux/ioport.h>
  35. #include <linux/eisa.h>
  36. #endif
  37. #if defined(CONFIG_EDAC)
  38. #include <linux/edac.h>
  39. #endif
  40. #include <asm/kmemcheck.h>
  41. #include <asm/stacktrace.h>
  42. #include <asm/processor.h>
  43. #include <asm/debugreg.h>
  44. #include <linux/atomic.h>
  45. #include <asm/traps.h>
  46. #include <asm/desc.h>
  47. #include <asm/i387.h>
  48. #include <asm/fpu-internal.h>
  49. #include <asm/mce.h>
  50. #include <asm/mach_traps.h>
  51. #ifdef CONFIG_X86_64
  52. #include <asm/x86_init.h>
  53. #include <asm/pgalloc.h>
  54. #include <asm/proto.h>
  55. #else
  56. #include <asm/processor-flags.h>
  57. #include <asm/setup.h>
  58. asmlinkage int system_call(void);
  59. /* Do we ignore FPU interrupts ? */
  60. char ignore_fpu_irq;
  61. /*
  62. * The IDT has to be page-aligned to simplify the Pentium
  63. * F0 0F bug workaround.
  64. */
  65. gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
  66. #endif
  67. DECLARE_BITMAP(used_vectors, NR_VECTORS);
  68. EXPORT_SYMBOL_GPL(used_vectors);
  69. static inline void conditional_sti(struct pt_regs *regs)
  70. {
  71. if (regs->flags & X86_EFLAGS_IF)
  72. local_irq_enable();
  73. }
  74. static inline void preempt_conditional_sti(struct pt_regs *regs)
  75. {
  76. inc_preempt_count();
  77. if (regs->flags & X86_EFLAGS_IF)
  78. local_irq_enable();
  79. }
  80. static inline void conditional_cli(struct pt_regs *regs)
  81. {
  82. if (regs->flags & X86_EFLAGS_IF)
  83. local_irq_disable();
  84. }
  85. static inline void preempt_conditional_cli(struct pt_regs *regs)
  86. {
  87. if (regs->flags & X86_EFLAGS_IF)
  88. local_irq_disable();
  89. dec_preempt_count();
  90. }
  91. static void __kprobes
  92. do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
  93. long error_code, siginfo_t *info)
  94. {
  95. struct task_struct *tsk = current;
  96. #ifdef CONFIG_X86_32
  97. if (regs->flags & X86_VM_MASK) {
  98. /*
  99. * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
  100. * On nmi (interrupt 2), do_trap should not be called.
  101. */
  102. if (trapnr < X86_TRAP_UD)
  103. goto vm86_trap;
  104. goto trap_signal;
  105. }
  106. #endif
  107. if (!user_mode(regs))
  108. goto kernel_trap;
  109. #ifdef CONFIG_X86_32
  110. trap_signal:
  111. #endif
  112. /*
  113. * We want error_code and trap_nr set for userspace faults and
  114. * kernelspace faults which result in die(), but not
  115. * kernelspace faults which are fixed up. die() gives the
  116. * process no chance to handle the signal and notice the
  117. * kernel fault information, so that won't result in polluting
  118. * the information about previously queued, but not yet
  119. * delivered, faults. See also do_general_protection below.
  120. */
  121. tsk->thread.error_code = error_code;
  122. tsk->thread.trap_nr = trapnr;
  123. #ifdef CONFIG_X86_64
  124. if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
  125. printk_ratelimit()) {
  126. printk(KERN_INFO
  127. "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
  128. tsk->comm, tsk->pid, str,
  129. regs->ip, regs->sp, error_code);
  130. print_vma_addr(" in ", regs->ip);
  131. printk("\n");
  132. }
  133. #endif
  134. if (info)
  135. force_sig_info(signr, info, tsk);
  136. else
  137. force_sig(signr, tsk);
  138. return;
  139. kernel_trap:
  140. if (!fixup_exception(regs)) {
  141. tsk->thread.error_code = error_code;
  142. tsk->thread.trap_nr = trapnr;
  143. die(str, regs, error_code);
  144. }
  145. return;
  146. #ifdef CONFIG_X86_32
  147. vm86_trap:
  148. if (handle_vm86_trap((struct kernel_vm86_regs *) regs,
  149. error_code, trapnr))
  150. goto trap_signal;
  151. return;
  152. #endif
  153. }
  154. #define DO_ERROR(trapnr, signr, str, name) \
  155. dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
  156. { \
  157. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  158. == NOTIFY_STOP) \
  159. return; \
  160. conditional_sti(regs); \
  161. do_trap(trapnr, signr, str, regs, error_code, NULL); \
  162. }
  163. #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
  164. dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
  165. { \
  166. siginfo_t info; \
  167. info.si_signo = signr; \
  168. info.si_errno = 0; \
  169. info.si_code = sicode; \
  170. info.si_addr = (void __user *)siaddr; \
  171. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  172. == NOTIFY_STOP) \
  173. return; \
  174. conditional_sti(regs); \
  175. do_trap(trapnr, signr, str, regs, error_code, &info); \
  176. }
  177. DO_ERROR_INFO(X86_TRAP_DE, SIGFPE, "divide error", divide_error, FPE_INTDIV,
  178. regs->ip)
  179. DO_ERROR(X86_TRAP_OF, SIGSEGV, "overflow", overflow)
  180. DO_ERROR(X86_TRAP_BR, SIGSEGV, "bounds", bounds)
  181. DO_ERROR_INFO(X86_TRAP_UD, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN,
  182. regs->ip)
  183. DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, "coprocessor segment overrun",
  184. coprocessor_segment_overrun)
  185. DO_ERROR(X86_TRAP_TS, SIGSEGV, "invalid TSS", invalid_TSS)
  186. DO_ERROR(X86_TRAP_NP, SIGBUS, "segment not present", segment_not_present)
  187. #ifdef CONFIG_X86_32
  188. DO_ERROR(X86_TRAP_SS, SIGBUS, "stack segment", stack_segment)
  189. #endif
  190. DO_ERROR_INFO(X86_TRAP_AC, SIGBUS, "alignment check", alignment_check,
  191. BUS_ADRALN, 0)
  192. #ifdef CONFIG_X86_64
  193. /* Runs on IST stack */
  194. dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code)
  195. {
  196. if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
  197. X86_TRAP_SS, SIGBUS) == NOTIFY_STOP)
  198. return;
  199. preempt_conditional_sti(regs);
  200. do_trap(X86_TRAP_SS, SIGBUS, "stack segment", regs, error_code, NULL);
  201. preempt_conditional_cli(regs);
  202. }
  203. dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
  204. {
  205. static const char str[] = "double fault";
  206. struct task_struct *tsk = current;
  207. /* Return not checked because double check cannot be ignored */
  208. notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV);
  209. tsk->thread.error_code = error_code;
  210. tsk->thread.trap_nr = X86_TRAP_DF;
  211. /*
  212. * This is always a kernel trap and never fixable (and thus must
  213. * never return).
  214. */
  215. for (;;)
  216. die(str, regs, error_code);
  217. }
  218. #endif
  219. dotraplinkage void __kprobes
  220. do_general_protection(struct pt_regs *regs, long error_code)
  221. {
  222. struct task_struct *tsk;
  223. conditional_sti(regs);
  224. #ifdef CONFIG_X86_32
  225. if (regs->flags & X86_VM_MASK)
  226. goto gp_in_vm86;
  227. #endif
  228. tsk = current;
  229. if (!user_mode(regs))
  230. goto gp_in_kernel;
  231. tsk->thread.error_code = error_code;
  232. tsk->thread.trap_nr = X86_TRAP_GP;
  233. if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
  234. printk_ratelimit()) {
  235. printk(KERN_INFO
  236. "%s[%d] general protection ip:%lx sp:%lx error:%lx",
  237. tsk->comm, task_pid_nr(tsk),
  238. regs->ip, regs->sp, error_code);
  239. print_vma_addr(" in ", regs->ip);
  240. printk("\n");
  241. }
  242. force_sig(SIGSEGV, tsk);
  243. return;
  244. #ifdef CONFIG_X86_32
  245. gp_in_vm86:
  246. local_irq_enable();
  247. handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
  248. return;
  249. #endif
  250. gp_in_kernel:
  251. if (fixup_exception(regs))
  252. return;
  253. tsk->thread.error_code = error_code;
  254. tsk->thread.trap_nr = X86_TRAP_GP;
  255. if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
  256. X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
  257. return;
  258. die("general protection fault", regs, error_code);
  259. }
  260. /* May run on IST stack. */
  261. dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
  262. {
  263. #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
  264. if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
  265. SIGTRAP) == NOTIFY_STOP)
  266. return;
  267. #endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
  268. if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
  269. SIGTRAP) == NOTIFY_STOP)
  270. return;
  271. /*
  272. * Let others (NMI) know that the debug stack is in use
  273. * as we may switch to the interrupt stack.
  274. */
  275. debug_stack_usage_inc();
  276. preempt_conditional_sti(regs);
  277. do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
  278. preempt_conditional_cli(regs);
  279. debug_stack_usage_dec();
  280. }
  281. #ifdef CONFIG_X86_64
  282. /*
  283. * Help handler running on IST stack to switch back to user stack
  284. * for scheduling or signal handling. The actual stack switch is done in
  285. * entry.S
  286. */
  287. asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
  288. {
  289. struct pt_regs *regs = eregs;
  290. /* Did already sync */
  291. if (eregs == (struct pt_regs *)eregs->sp)
  292. ;
  293. /* Exception from user space */
  294. else if (user_mode(eregs))
  295. regs = task_pt_regs(current);
  296. /*
  297. * Exception from kernel and interrupts are enabled. Move to
  298. * kernel process stack.
  299. */
  300. else if (eregs->flags & X86_EFLAGS_IF)
  301. regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs));
  302. if (eregs != regs)
  303. *regs = *eregs;
  304. return regs;
  305. }
  306. #endif
  307. /*
  308. * Our handling of the processor debug registers is non-trivial.
  309. * We do not clear them on entry and exit from the kernel. Therefore
  310. * it is possible to get a watchpoint trap here from inside the kernel.
  311. * However, the code in ./ptrace.c has ensured that the user can
  312. * only set watchpoints on userspace addresses. Therefore the in-kernel
  313. * watchpoint trap can only occur in code which is reading/writing
  314. * from user space. Such code must not hold kernel locks (since it
  315. * can equally take a page fault), therefore it is safe to call
  316. * force_sig_info even though that claims and releases locks.
  317. *
  318. * Code in ./signal.c ensures that the debug control register
  319. * is restored before we deliver any signal, and therefore that
  320. * user code runs with the correct debug control register even though
  321. * we clear it here.
  322. *
  323. * Being careful here means that we don't have to be as careful in a
  324. * lot of more complicated places (task switching can be a bit lazy
  325. * about restoring all the debug state, and ptrace doesn't have to
  326. * find every occurrence of the TF bit that could be saved away even
  327. * by user code)
  328. *
  329. * May run on IST stack.
  330. */
  331. dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
  332. {
  333. struct task_struct *tsk = current;
  334. int user_icebp = 0;
  335. unsigned long dr6;
  336. int si_code;
  337. get_debugreg(dr6, 6);
  338. /* Filter out all the reserved bits which are preset to 1 */
  339. dr6 &= ~DR6_RESERVED;
  340. /*
  341. * If dr6 has no reason to give us about the origin of this trap,
  342. * then it's very likely the result of an icebp/int01 trap.
  343. * User wants a sigtrap for that.
  344. */
  345. if (!dr6 && user_mode(regs))
  346. user_icebp = 1;
  347. /* Catch kmemcheck conditions first of all! */
  348. if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
  349. return;
  350. /* DR6 may or may not be cleared by the CPU */
  351. set_debugreg(0, 6);
  352. /*
  353. * The processor cleared BTF, so don't mark that we need it set.
  354. */
  355. clear_tsk_thread_flag(tsk, TIF_BLOCKSTEP);
  356. /* Store the virtualized DR6 value */
  357. tsk->thread.debugreg6 = dr6;
  358. if (notify_die(DIE_DEBUG, "debug", regs, PTR_ERR(&dr6), error_code,
  359. SIGTRAP) == NOTIFY_STOP)
  360. return;
  361. /*
  362. * Let others (NMI) know that the debug stack is in use
  363. * as we may switch to the interrupt stack.
  364. */
  365. debug_stack_usage_inc();
  366. /* It's safe to allow irq's after DR6 has been saved */
  367. preempt_conditional_sti(regs);
  368. if (regs->flags & X86_VM_MASK) {
  369. handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
  370. X86_TRAP_DB);
  371. preempt_conditional_cli(regs);
  372. debug_stack_usage_dec();
  373. return;
  374. }
  375. /*
  376. * Single-stepping through system calls: ignore any exceptions in
  377. * kernel space, but re-enable TF when returning to user mode.
  378. *
  379. * We already checked v86 mode above, so we can check for kernel mode
  380. * by just checking the CPL of CS.
  381. */
  382. if ((dr6 & DR_STEP) && !user_mode(regs)) {
  383. tsk->thread.debugreg6 &= ~DR_STEP;
  384. set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
  385. regs->flags &= ~X86_EFLAGS_TF;
  386. }
  387. si_code = get_si_code(tsk->thread.debugreg6);
  388. if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp)
  389. send_sigtrap(tsk, regs, error_code, si_code);
  390. preempt_conditional_cli(regs);
  391. debug_stack_usage_dec();
  392. return;
  393. }
  394. /*
  395. * Note that we play around with the 'TS' bit in an attempt to get
  396. * the correct behaviour even in the presence of the asynchronous
  397. * IRQ13 behaviour
  398. */
  399. void math_error(struct pt_regs *regs, int error_code, int trapnr)
  400. {
  401. struct task_struct *task = current;
  402. siginfo_t info;
  403. unsigned short err;
  404. char *str = (trapnr == X86_TRAP_MF) ? "fpu exception" :
  405. "simd exception";
  406. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, SIGFPE) == NOTIFY_STOP)
  407. return;
  408. conditional_sti(regs);
  409. if (!user_mode_vm(regs))
  410. {
  411. if (!fixup_exception(regs)) {
  412. task->thread.error_code = error_code;
  413. task->thread.trap_nr = trapnr;
  414. die(str, regs, error_code);
  415. }
  416. return;
  417. }
  418. /*
  419. * Save the info for the exception handler and clear the error.
  420. */
  421. save_init_fpu(task);
  422. task->thread.trap_nr = trapnr;
  423. task->thread.error_code = error_code;
  424. info.si_signo = SIGFPE;
  425. info.si_errno = 0;
  426. info.si_addr = (void __user *)regs->ip;
  427. if (trapnr == X86_TRAP_MF) {
  428. unsigned short cwd, swd;
  429. /*
  430. * (~cwd & swd) will mask out exceptions that are not set to unmasked
  431. * status. 0x3f is the exception bits in these regs, 0x200 is the
  432. * C1 reg you need in case of a stack fault, 0x040 is the stack
  433. * fault bit. We should only be taking one exception at a time,
  434. * so if this combination doesn't produce any single exception,
  435. * then we have a bad program that isn't synchronizing its FPU usage
  436. * and it will suffer the consequences since we won't be able to
  437. * fully reproduce the context of the exception
  438. */
  439. cwd = get_fpu_cwd(task);
  440. swd = get_fpu_swd(task);
  441. err = swd & ~cwd;
  442. } else {
  443. /*
  444. * The SIMD FPU exceptions are handled a little differently, as there
  445. * is only a single status/control register. Thus, to determine which
  446. * unmasked exception was caught we must mask the exception mask bits
  447. * at 0x1f80, and then use these to mask the exception bits at 0x3f.
  448. */
  449. unsigned short mxcsr = get_fpu_mxcsr(task);
  450. err = ~(mxcsr >> 7) & mxcsr;
  451. }
  452. if (err & 0x001) { /* Invalid op */
  453. /*
  454. * swd & 0x240 == 0x040: Stack Underflow
  455. * swd & 0x240 == 0x240: Stack Overflow
  456. * User must clear the SF bit (0x40) if set
  457. */
  458. info.si_code = FPE_FLTINV;
  459. } else if (err & 0x004) { /* Divide by Zero */
  460. info.si_code = FPE_FLTDIV;
  461. } else if (err & 0x008) { /* Overflow */
  462. info.si_code = FPE_FLTOVF;
  463. } else if (err & 0x012) { /* Denormal, Underflow */
  464. info.si_code = FPE_FLTUND;
  465. } else if (err & 0x020) { /* Precision */
  466. info.si_code = FPE_FLTRES;
  467. } else {
  468. /*
  469. * If we're using IRQ 13, or supposedly even some trap
  470. * X86_TRAP_MF implementations, it's possible
  471. * we get a spurious trap, which is not an error.
  472. */
  473. return;
  474. }
  475. force_sig_info(SIGFPE, &info, task);
  476. }
  477. dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code)
  478. {
  479. #ifdef CONFIG_X86_32
  480. ignore_fpu_irq = 1;
  481. #endif
  482. math_error(regs, error_code, X86_TRAP_MF);
  483. }
  484. dotraplinkage void
  485. do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
  486. {
  487. math_error(regs, error_code, X86_TRAP_XF);
  488. }
  489. dotraplinkage void
  490. do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
  491. {
  492. conditional_sti(regs);
  493. #if 0
  494. /* No need to warn about this any longer. */
  495. printk(KERN_INFO "Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
  496. #endif
  497. }
  498. asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void)
  499. {
  500. }
  501. asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
  502. {
  503. }
  504. /*
  505. * 'math_state_restore()' saves the current math information in the
  506. * old math state array, and gets the new ones from the current task
  507. *
  508. * Careful.. There are problems with IBM-designed IRQ13 behaviour.
  509. * Don't touch unless you *really* know how it works.
  510. *
  511. * Must be called with kernel preemption disabled (eg with local
  512. * local interrupts as in the case of do_device_not_available).
  513. */
  514. void math_state_restore(void)
  515. {
  516. struct task_struct *tsk = current;
  517. if (!tsk_used_math(tsk)) {
  518. local_irq_enable();
  519. /*
  520. * does a slab alloc which can sleep
  521. */
  522. if (init_fpu(tsk)) {
  523. /*
  524. * ran out of memory!
  525. */
  526. do_group_exit(SIGKILL);
  527. return;
  528. }
  529. local_irq_disable();
  530. }
  531. __thread_fpu_begin(tsk);
  532. /*
  533. * Paranoid restore. send a SIGSEGV if we fail to restore the state.
  534. */
  535. if (unlikely(restore_fpu_checking(tsk))) {
  536. __thread_fpu_end(tsk);
  537. force_sig(SIGSEGV, tsk);
  538. return;
  539. }
  540. tsk->fpu_counter++;
  541. }
  542. EXPORT_SYMBOL_GPL(math_state_restore);
  543. dotraplinkage void __kprobes
  544. do_device_not_available(struct pt_regs *regs, long error_code)
  545. {
  546. #ifdef CONFIG_MATH_EMULATION
  547. if (read_cr0() & X86_CR0_EM) {
  548. struct math_emu_info info = { };
  549. conditional_sti(regs);
  550. info.regs = regs;
  551. math_emulate(&info);
  552. return;
  553. }
  554. #endif
  555. math_state_restore(); /* interrupts still off */
  556. #ifdef CONFIG_X86_32
  557. conditional_sti(regs);
  558. #endif
  559. }
  560. #ifdef CONFIG_X86_32
  561. dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
  562. {
  563. siginfo_t info;
  564. local_irq_enable();
  565. info.si_signo = SIGILL;
  566. info.si_errno = 0;
  567. info.si_code = ILL_BADSTK;
  568. info.si_addr = NULL;
  569. if (notify_die(DIE_TRAP, "iret exception", regs, error_code,
  570. X86_TRAP_IRET, SIGILL) == NOTIFY_STOP)
  571. return;
  572. do_trap(X86_TRAP_IRET, SIGILL, "iret exception", regs, error_code,
  573. &info);
  574. }
  575. #endif
  576. /* Set of traps needed for early debugging. */
  577. void __init early_trap_init(void)
  578. {
  579. set_intr_gate_ist(X86_TRAP_DB, &debug, DEBUG_STACK);
  580. /* int3 can be called from all */
  581. set_system_intr_gate_ist(X86_TRAP_BP, &int3, DEBUG_STACK);
  582. set_intr_gate(X86_TRAP_PF, &page_fault);
  583. load_idt(&idt_descr);
  584. }
  585. void __init trap_init(void)
  586. {
  587. int i;
  588. #ifdef CONFIG_EISA
  589. void __iomem *p = early_ioremap(0x0FFFD9, 4);
  590. if (readl(p) == 'E' + ('I'<<8) + ('S'<<16) + ('A'<<24))
  591. EISA_bus = 1;
  592. early_iounmap(p, 4);
  593. #endif
  594. set_intr_gate(X86_TRAP_DE, &divide_error);
  595. set_intr_gate_ist(X86_TRAP_NMI, &nmi, NMI_STACK);
  596. /* int4 can be called from all */
  597. set_system_intr_gate(X86_TRAP_OF, &overflow);
  598. set_intr_gate(X86_TRAP_BR, &bounds);
  599. set_intr_gate(X86_TRAP_UD, &invalid_op);
  600. set_intr_gate(X86_TRAP_NM, &device_not_available);
  601. #ifdef CONFIG_X86_32
  602. set_task_gate(X86_TRAP_DF, GDT_ENTRY_DOUBLEFAULT_TSS);
  603. #else
  604. set_intr_gate_ist(X86_TRAP_DF, &double_fault, DOUBLEFAULT_STACK);
  605. #endif
  606. set_intr_gate(X86_TRAP_OLD_MF, &coprocessor_segment_overrun);
  607. set_intr_gate(X86_TRAP_TS, &invalid_TSS);
  608. set_intr_gate(X86_TRAP_NP, &segment_not_present);
  609. set_intr_gate_ist(X86_TRAP_SS, &stack_segment, STACKFAULT_STACK);
  610. set_intr_gate(X86_TRAP_GP, &general_protection);
  611. set_intr_gate(X86_TRAP_SPURIOUS, &spurious_interrupt_bug);
  612. set_intr_gate(X86_TRAP_MF, &coprocessor_error);
  613. set_intr_gate(X86_TRAP_AC, &alignment_check);
  614. #ifdef CONFIG_X86_MCE
  615. set_intr_gate_ist(X86_TRAP_MC, &machine_check, MCE_STACK);
  616. #endif
  617. set_intr_gate(X86_TRAP_XF, &simd_coprocessor_error);
  618. /* Reserve all the builtin and the syscall vector: */
  619. for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++)
  620. set_bit(i, used_vectors);
  621. #ifdef CONFIG_IA32_EMULATION
  622. set_system_intr_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
  623. set_bit(IA32_SYSCALL_VECTOR, used_vectors);
  624. #endif
  625. #ifdef CONFIG_X86_32
  626. set_system_trap_gate(SYSCALL_VECTOR, &system_call);
  627. set_bit(SYSCALL_VECTOR, used_vectors);
  628. #endif
  629. /*
  630. * Should be a barrier for any external CPU state:
  631. */
  632. cpu_init();
  633. x86_init.irqs.trap_init();
  634. #ifdef CONFIG_X86_64
  635. memcpy(&nmi_idt_table, &idt_table, IDT_ENTRIES * 16);
  636. set_nmi_gate(X86_TRAP_DB, &debug);
  637. set_nmi_gate(X86_TRAP_BP, &int3);
  638. #endif
  639. }