traps.c 33 KB

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