traps.c 19 KB

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