traps_32.c 33 KB

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