traps.c 32 KB

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