traps.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /*
  2. * arch/s390/kernel/traps.c
  3. *
  4. * S390 version
  5. * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  7. * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
  8. *
  9. * Derived from "arch/i386/kernel/traps.c"
  10. * Copyright (C) 1991, 1992 Linus Torvalds
  11. */
  12. /*
  13. * 'Traps.c' handles hardware traps and faults after we have saved some
  14. * state in 'asm.s'.
  15. */
  16. #include <linux/sched.h>
  17. #include <linux/kernel.h>
  18. #include <linux/string.h>
  19. #include <linux/errno.h>
  20. #include <linux/tracehook.h>
  21. #include <linux/timer.h>
  22. #include <linux/mm.h>
  23. #include <linux/smp.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/delay.h>
  28. #include <linux/module.h>
  29. #include <linux/kdebug.h>
  30. #include <linux/kallsyms.h>
  31. #include <linux/reboot.h>
  32. #include <linux/kprobes.h>
  33. #include <linux/bug.h>
  34. #include <linux/utsname.h>
  35. #include <asm/system.h>
  36. #include <asm/uaccess.h>
  37. #include <asm/io.h>
  38. #include <asm/atomic.h>
  39. #include <asm/mathemu.h>
  40. #include <asm/cpcmd.h>
  41. #include <asm/lowcore.h>
  42. #include <asm/debug.h>
  43. #include "entry.h"
  44. pgm_check_handler_t *pgm_check_table[128];
  45. int show_unhandled_signals;
  46. extern pgm_check_handler_t do_protection_exception;
  47. extern pgm_check_handler_t do_dat_exception;
  48. extern pgm_check_handler_t do_asce_exception;
  49. #define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
  50. #ifndef CONFIG_64BIT
  51. #define LONG "%08lx "
  52. #define FOURLONG "%08lx %08lx %08lx %08lx\n"
  53. static int kstack_depth_to_print = 12;
  54. #else /* CONFIG_64BIT */
  55. #define LONG "%016lx "
  56. #define FOURLONG "%016lx %016lx %016lx %016lx\n"
  57. static int kstack_depth_to_print = 20;
  58. #endif /* CONFIG_64BIT */
  59. /*
  60. * For show_trace we have tree different stack to consider:
  61. * - the panic stack which is used if the kernel stack has overflown
  62. * - the asynchronous interrupt stack (cpu related)
  63. * - the synchronous kernel stack (process related)
  64. * The stack trace can start at any of the three stack and can potentially
  65. * touch all of them. The order is: panic stack, async stack, sync stack.
  66. */
  67. static unsigned long
  68. __show_trace(unsigned long sp, unsigned long low, unsigned long high)
  69. {
  70. struct stack_frame *sf;
  71. struct pt_regs *regs;
  72. while (1) {
  73. sp = sp & PSW_ADDR_INSN;
  74. if (sp < low || sp > high - sizeof(*sf))
  75. return sp;
  76. sf = (struct stack_frame *) sp;
  77. printk("([<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
  78. print_symbol("%s)\n", sf->gprs[8] & PSW_ADDR_INSN);
  79. /* Follow the backchain. */
  80. while (1) {
  81. low = sp;
  82. sp = sf->back_chain & PSW_ADDR_INSN;
  83. if (!sp)
  84. break;
  85. if (sp <= low || sp > high - sizeof(*sf))
  86. return sp;
  87. sf = (struct stack_frame *) sp;
  88. printk(" [<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
  89. print_symbol("%s\n", sf->gprs[8] & PSW_ADDR_INSN);
  90. }
  91. /* Zero backchain detected, check for interrupt frame. */
  92. sp = (unsigned long) (sf + 1);
  93. if (sp <= low || sp > high - sizeof(*regs))
  94. return sp;
  95. regs = (struct pt_regs *) sp;
  96. printk(" [<%016lx>] ", regs->psw.addr & PSW_ADDR_INSN);
  97. print_symbol("%s\n", regs->psw.addr & PSW_ADDR_INSN);
  98. low = sp;
  99. sp = regs->gprs[15];
  100. }
  101. }
  102. static void show_trace(struct task_struct *task, unsigned long *stack)
  103. {
  104. register unsigned long __r15 asm ("15");
  105. unsigned long sp;
  106. sp = (unsigned long) stack;
  107. if (!sp)
  108. sp = task ? task->thread.ksp : __r15;
  109. printk("Call Trace:\n");
  110. #ifdef CONFIG_CHECK_STACK
  111. sp = __show_trace(sp, S390_lowcore.panic_stack - 4096,
  112. S390_lowcore.panic_stack);
  113. #endif
  114. sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE,
  115. S390_lowcore.async_stack);
  116. if (task)
  117. __show_trace(sp, (unsigned long) task_stack_page(task),
  118. (unsigned long) task_stack_page(task) + THREAD_SIZE);
  119. else
  120. __show_trace(sp, S390_lowcore.thread_info,
  121. S390_lowcore.thread_info + THREAD_SIZE);
  122. if (!task)
  123. task = current;
  124. debug_show_held_locks(task);
  125. }
  126. void show_stack(struct task_struct *task, unsigned long *sp)
  127. {
  128. register unsigned long * __r15 asm ("15");
  129. unsigned long *stack;
  130. int i;
  131. if (!sp)
  132. stack = task ? (unsigned long *) task->thread.ksp : __r15;
  133. else
  134. stack = sp;
  135. for (i = 0; i < kstack_depth_to_print; i++) {
  136. if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
  137. break;
  138. if (i && ((i * sizeof (long) % 32) == 0))
  139. printk("\n ");
  140. printk(LONG, *stack++);
  141. }
  142. printk("\n");
  143. show_trace(task, sp);
  144. }
  145. static void show_last_breaking_event(struct pt_regs *regs)
  146. {
  147. #ifdef CONFIG_64BIT
  148. printk("Last Breaking-Event-Address:\n");
  149. printk(" [<%016lx>] ", regs->args[0] & PSW_ADDR_INSN);
  150. print_symbol("%s\n", regs->args[0] & PSW_ADDR_INSN);
  151. #endif
  152. }
  153. /*
  154. * The architecture-independent dump_stack generator
  155. */
  156. void dump_stack(void)
  157. {
  158. printk("CPU: %d %s %s %.*s\n",
  159. task_thread_info(current)->cpu, print_tainted(),
  160. init_utsname()->release,
  161. (int)strcspn(init_utsname()->version, " "),
  162. init_utsname()->version);
  163. printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
  164. current->comm, current->pid, current,
  165. (void *) current->thread.ksp);
  166. show_stack(NULL, NULL);
  167. }
  168. EXPORT_SYMBOL(dump_stack);
  169. static inline int mask_bits(struct pt_regs *regs, unsigned long bits)
  170. {
  171. return (regs->psw.mask & bits) / ((~bits + 1) & bits);
  172. }
  173. void show_registers(struct pt_regs *regs)
  174. {
  175. char *mode;
  176. mode = (regs->psw.mask & PSW_MASK_PSTATE) ? "User" : "Krnl";
  177. printk("%s PSW : %p %p",
  178. mode, (void *) regs->psw.mask,
  179. (void *) regs->psw.addr);
  180. print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN);
  181. printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
  182. "P:%x AS:%x CC:%x PM:%x", mask_bits(regs, PSW_MASK_PER),
  183. mask_bits(regs, PSW_MASK_DAT), mask_bits(regs, PSW_MASK_IO),
  184. mask_bits(regs, PSW_MASK_EXT), mask_bits(regs, PSW_MASK_KEY),
  185. mask_bits(regs, PSW_MASK_MCHECK), mask_bits(regs, PSW_MASK_WAIT),
  186. mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC),
  187. mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM));
  188. #ifdef CONFIG_64BIT
  189. printk(" EA:%x", mask_bits(regs, PSW_BASE_BITS));
  190. #endif
  191. printk("\n%s GPRS: " FOURLONG, mode,
  192. regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
  193. printk(" " FOURLONG,
  194. regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
  195. printk(" " FOURLONG,
  196. regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
  197. printk(" " FOURLONG,
  198. regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
  199. show_code(regs);
  200. }
  201. void show_regs(struct pt_regs *regs)
  202. {
  203. print_modules();
  204. printk("CPU: %d %s %s %.*s\n",
  205. task_thread_info(current)->cpu, print_tainted(),
  206. init_utsname()->release,
  207. (int)strcspn(init_utsname()->version, " "),
  208. init_utsname()->version);
  209. printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
  210. current->comm, current->pid, current,
  211. (void *) current->thread.ksp);
  212. show_registers(regs);
  213. /* Show stack backtrace if pt_regs is from kernel mode */
  214. if (!(regs->psw.mask & PSW_MASK_PSTATE))
  215. show_trace(NULL, (unsigned long *) regs->gprs[15]);
  216. show_last_breaking_event(regs);
  217. }
  218. static DEFINE_SPINLOCK(die_lock);
  219. void die(const char * str, struct pt_regs * regs, long err)
  220. {
  221. static int die_counter;
  222. oops_enter();
  223. debug_stop_all();
  224. console_verbose();
  225. spin_lock_irq(&die_lock);
  226. bust_spinlocks(1);
  227. printk("%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter);
  228. #ifdef CONFIG_PREEMPT
  229. printk("PREEMPT ");
  230. #endif
  231. #ifdef CONFIG_SMP
  232. printk("SMP ");
  233. #endif
  234. #ifdef CONFIG_DEBUG_PAGEALLOC
  235. printk("DEBUG_PAGEALLOC");
  236. #endif
  237. printk("\n");
  238. notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV);
  239. show_regs(regs);
  240. bust_spinlocks(0);
  241. add_taint(TAINT_DIE);
  242. spin_unlock_irq(&die_lock);
  243. if (in_interrupt())
  244. panic("Fatal exception in interrupt");
  245. if (panic_on_oops)
  246. panic("Fatal exception: panic_on_oops");
  247. oops_exit();
  248. do_exit(SIGSEGV);
  249. }
  250. static void inline report_user_fault(struct pt_regs *regs, long int_code,
  251. int signr)
  252. {
  253. if ((task_pid_nr(current) > 1) && !show_unhandled_signals)
  254. return;
  255. if (!unhandled_signal(current, signr))
  256. return;
  257. if (!printk_ratelimit())
  258. return;
  259. printk("User process fault: interruption code 0x%lX ", int_code);
  260. print_vma_addr("in ", regs->psw.addr & PSW_ADDR_INSN);
  261. printk("\n");
  262. show_regs(regs);
  263. }
  264. int is_valid_bugaddr(unsigned long addr)
  265. {
  266. return 1;
  267. }
  268. static inline void __kprobes do_trap(long pgm_int_code, int signr, char *str,
  269. struct pt_regs *regs, siginfo_t *info)
  270. {
  271. if (notify_die(DIE_TRAP, str, regs, pgm_int_code,
  272. pgm_int_code, signr) == NOTIFY_STOP)
  273. return;
  274. if (regs->psw.mask & PSW_MASK_PSTATE) {
  275. struct task_struct *tsk = current;
  276. tsk->thread.trap_no = pgm_int_code & 0xffff;
  277. force_sig_info(signr, info, tsk);
  278. report_user_fault(regs, pgm_int_code, signr);
  279. } else {
  280. const struct exception_table_entry *fixup;
  281. fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
  282. if (fixup)
  283. regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
  284. else {
  285. enum bug_trap_type btt;
  286. btt = report_bug(regs->psw.addr & PSW_ADDR_INSN, regs);
  287. if (btt == BUG_TRAP_TYPE_WARN)
  288. return;
  289. die(str, regs, pgm_int_code);
  290. }
  291. }
  292. }
  293. static inline void __user *get_psw_address(struct pt_regs *regs,
  294. long pgm_int_code)
  295. {
  296. return (void __user *)
  297. ((regs->psw.addr - (pgm_int_code >> 16)) & PSW_ADDR_INSN);
  298. }
  299. void __kprobes do_per_trap(struct pt_regs *regs)
  300. {
  301. if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0, SIGTRAP) == NOTIFY_STOP)
  302. return;
  303. if (tracehook_consider_fatal_signal(current, SIGTRAP))
  304. force_sig(SIGTRAP, current);
  305. }
  306. static void default_trap_handler(struct pt_regs *regs, long pgm_int_code,
  307. unsigned long trans_exc_code)
  308. {
  309. if (regs->psw.mask & PSW_MASK_PSTATE) {
  310. report_user_fault(regs, pgm_int_code, SIGSEGV);
  311. do_exit(SIGSEGV);
  312. } else
  313. die("Unknown program exception", regs, pgm_int_code);
  314. }
  315. #define DO_ERROR_INFO(name, signr, sicode, str) \
  316. static void name(struct pt_regs *regs, long pgm_int_code, \
  317. unsigned long trans_exc_code) \
  318. { \
  319. siginfo_t info; \
  320. info.si_signo = signr; \
  321. info.si_errno = 0; \
  322. info.si_code = sicode; \
  323. info.si_addr = get_psw_address(regs, pgm_int_code); \
  324. do_trap(pgm_int_code, signr, str, regs, &info); \
  325. }
  326. DO_ERROR_INFO(addressing_exception, SIGILL, ILL_ILLADR,
  327. "addressing exception")
  328. DO_ERROR_INFO(execute_exception, SIGILL, ILL_ILLOPN,
  329. "execute exception")
  330. DO_ERROR_INFO(divide_exception, SIGFPE, FPE_INTDIV,
  331. "fixpoint divide exception")
  332. DO_ERROR_INFO(overflow_exception, SIGFPE, FPE_INTOVF,
  333. "fixpoint overflow exception")
  334. DO_ERROR_INFO(hfp_overflow_exception, SIGFPE, FPE_FLTOVF,
  335. "HFP overflow exception")
  336. DO_ERROR_INFO(hfp_underflow_exception, SIGFPE, FPE_FLTUND,
  337. "HFP underflow exception")
  338. DO_ERROR_INFO(hfp_significance_exception, SIGFPE, FPE_FLTRES,
  339. "HFP significance exception")
  340. DO_ERROR_INFO(hfp_divide_exception, SIGFPE, FPE_FLTDIV,
  341. "HFP divide exception")
  342. DO_ERROR_INFO(hfp_sqrt_exception, SIGFPE, FPE_FLTINV,
  343. "HFP square root exception")
  344. DO_ERROR_INFO(operand_exception, SIGILL, ILL_ILLOPN,
  345. "operand exception")
  346. DO_ERROR_INFO(privileged_op, SIGILL, ILL_PRVOPC,
  347. "privileged operation")
  348. DO_ERROR_INFO(special_op_exception, SIGILL, ILL_ILLOPN,
  349. "special operation exception")
  350. DO_ERROR_INFO(translation_exception, SIGILL, ILL_ILLOPN,
  351. "translation exception")
  352. static inline void do_fp_trap(struct pt_regs *regs, void __user *location,
  353. int fpc, long pgm_int_code)
  354. {
  355. siginfo_t si;
  356. si.si_signo = SIGFPE;
  357. si.si_errno = 0;
  358. si.si_addr = location;
  359. si.si_code = 0;
  360. /* FPC[2] is Data Exception Code */
  361. if ((fpc & 0x00000300) == 0) {
  362. /* bits 6 and 7 of DXC are 0 iff IEEE exception */
  363. if (fpc & 0x8000) /* invalid fp operation */
  364. si.si_code = FPE_FLTINV;
  365. else if (fpc & 0x4000) /* div by 0 */
  366. si.si_code = FPE_FLTDIV;
  367. else if (fpc & 0x2000) /* overflow */
  368. si.si_code = FPE_FLTOVF;
  369. else if (fpc & 0x1000) /* underflow */
  370. si.si_code = FPE_FLTUND;
  371. else if (fpc & 0x0800) /* inexact */
  372. si.si_code = FPE_FLTRES;
  373. }
  374. do_trap(pgm_int_code, SIGFPE,
  375. "floating point exception", regs, &si);
  376. }
  377. static void __kprobes illegal_op(struct pt_regs *regs, long pgm_int_code,
  378. unsigned long trans_exc_code)
  379. {
  380. siginfo_t info;
  381. __u8 opcode[6];
  382. __u16 __user *location;
  383. int signal = 0;
  384. location = get_psw_address(regs, pgm_int_code);
  385. if (regs->psw.mask & PSW_MASK_PSTATE) {
  386. if (get_user(*((__u16 *) opcode), (__u16 __user *) location))
  387. return;
  388. if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
  389. if (tracehook_consider_fatal_signal(current, SIGTRAP))
  390. force_sig(SIGTRAP, current);
  391. else
  392. signal = SIGILL;
  393. #ifdef CONFIG_MATHEMU
  394. } else if (opcode[0] == 0xb3) {
  395. if (get_user(*((__u16 *) (opcode+2)), location+1))
  396. return;
  397. signal = math_emu_b3(opcode, regs);
  398. } else if (opcode[0] == 0xed) {
  399. if (get_user(*((__u32 *) (opcode+2)),
  400. (__u32 __user *)(location+1)))
  401. return;
  402. signal = math_emu_ed(opcode, regs);
  403. } else if (*((__u16 *) opcode) == 0xb299) {
  404. if (get_user(*((__u16 *) (opcode+2)), location+1))
  405. return;
  406. signal = math_emu_srnm(opcode, regs);
  407. } else if (*((__u16 *) opcode) == 0xb29c) {
  408. if (get_user(*((__u16 *) (opcode+2)), location+1))
  409. return;
  410. signal = math_emu_stfpc(opcode, regs);
  411. } else if (*((__u16 *) opcode) == 0xb29d) {
  412. if (get_user(*((__u16 *) (opcode+2)), location+1))
  413. return;
  414. signal = math_emu_lfpc(opcode, regs);
  415. #endif
  416. } else
  417. signal = SIGILL;
  418. } else {
  419. /*
  420. * If we get an illegal op in kernel mode, send it through the
  421. * kprobes notifier. If kprobes doesn't pick it up, SIGILL
  422. */
  423. if (notify_die(DIE_BPT, "bpt", regs, pgm_int_code,
  424. 3, SIGTRAP) != NOTIFY_STOP)
  425. signal = SIGILL;
  426. }
  427. #ifdef CONFIG_MATHEMU
  428. if (signal == SIGFPE)
  429. do_fp_trap(regs, location,
  430. current->thread.fp_regs.fpc, pgm_int_code);
  431. else if (signal == SIGSEGV) {
  432. info.si_signo = signal;
  433. info.si_errno = 0;
  434. info.si_code = SEGV_MAPERR;
  435. info.si_addr = (void __user *) location;
  436. do_trap(pgm_int_code, signal,
  437. "user address fault", regs, &info);
  438. } else
  439. #endif
  440. if (signal) {
  441. info.si_signo = signal;
  442. info.si_errno = 0;
  443. info.si_code = ILL_ILLOPC;
  444. info.si_addr = (void __user *) location;
  445. do_trap(pgm_int_code, signal,
  446. "illegal operation", regs, &info);
  447. }
  448. }
  449. #ifdef CONFIG_MATHEMU
  450. asmlinkage void specification_exception(struct pt_regs *regs,
  451. long pgm_int_code,
  452. unsigned long trans_exc_code)
  453. {
  454. __u8 opcode[6];
  455. __u16 __user *location = NULL;
  456. int signal = 0;
  457. location = (__u16 __user *) get_psw_address(regs, pgm_int_code);
  458. if (regs->psw.mask & PSW_MASK_PSTATE) {
  459. get_user(*((__u16 *) opcode), location);
  460. switch (opcode[0]) {
  461. case 0x28: /* LDR Rx,Ry */
  462. signal = math_emu_ldr(opcode);
  463. break;
  464. case 0x38: /* LER Rx,Ry */
  465. signal = math_emu_ler(opcode);
  466. break;
  467. case 0x60: /* STD R,D(X,B) */
  468. get_user(*((__u16 *) (opcode+2)), location+1);
  469. signal = math_emu_std(opcode, regs);
  470. break;
  471. case 0x68: /* LD R,D(X,B) */
  472. get_user(*((__u16 *) (opcode+2)), location+1);
  473. signal = math_emu_ld(opcode, regs);
  474. break;
  475. case 0x70: /* STE R,D(X,B) */
  476. get_user(*((__u16 *) (opcode+2)), location+1);
  477. signal = math_emu_ste(opcode, regs);
  478. break;
  479. case 0x78: /* LE R,D(X,B) */
  480. get_user(*((__u16 *) (opcode+2)), location+1);
  481. signal = math_emu_le(opcode, regs);
  482. break;
  483. default:
  484. signal = SIGILL;
  485. break;
  486. }
  487. } else
  488. signal = SIGILL;
  489. if (signal == SIGFPE)
  490. do_fp_trap(regs, location,
  491. current->thread.fp_regs.fpc, pgm_int_code);
  492. else if (signal) {
  493. siginfo_t info;
  494. info.si_signo = signal;
  495. info.si_errno = 0;
  496. info.si_code = ILL_ILLOPN;
  497. info.si_addr = location;
  498. do_trap(pgm_int_code, signal,
  499. "specification exception", regs, &info);
  500. }
  501. }
  502. #else
  503. DO_ERROR_INFO(specification_exception, SIGILL, ILL_ILLOPN,
  504. "specification exception");
  505. #endif
  506. static void data_exception(struct pt_regs *regs, long pgm_int_code,
  507. unsigned long trans_exc_code)
  508. {
  509. __u16 __user *location;
  510. int signal = 0;
  511. location = get_psw_address(regs, pgm_int_code);
  512. if (MACHINE_HAS_IEEE)
  513. asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc));
  514. #ifdef CONFIG_MATHEMU
  515. else if (regs->psw.mask & PSW_MASK_PSTATE) {
  516. __u8 opcode[6];
  517. get_user(*((__u16 *) opcode), location);
  518. switch (opcode[0]) {
  519. case 0x28: /* LDR Rx,Ry */
  520. signal = math_emu_ldr(opcode);
  521. break;
  522. case 0x38: /* LER Rx,Ry */
  523. signal = math_emu_ler(opcode);
  524. break;
  525. case 0x60: /* STD R,D(X,B) */
  526. get_user(*((__u16 *) (opcode+2)), location+1);
  527. signal = math_emu_std(opcode, regs);
  528. break;
  529. case 0x68: /* LD R,D(X,B) */
  530. get_user(*((__u16 *) (opcode+2)), location+1);
  531. signal = math_emu_ld(opcode, regs);
  532. break;
  533. case 0x70: /* STE R,D(X,B) */
  534. get_user(*((__u16 *) (opcode+2)), location+1);
  535. signal = math_emu_ste(opcode, regs);
  536. break;
  537. case 0x78: /* LE R,D(X,B) */
  538. get_user(*((__u16 *) (opcode+2)), location+1);
  539. signal = math_emu_le(opcode, regs);
  540. break;
  541. case 0xb3:
  542. get_user(*((__u16 *) (opcode+2)), location+1);
  543. signal = math_emu_b3(opcode, regs);
  544. break;
  545. case 0xed:
  546. get_user(*((__u32 *) (opcode+2)),
  547. (__u32 __user *)(location+1));
  548. signal = math_emu_ed(opcode, regs);
  549. break;
  550. case 0xb2:
  551. if (opcode[1] == 0x99) {
  552. get_user(*((__u16 *) (opcode+2)), location+1);
  553. signal = math_emu_srnm(opcode, regs);
  554. } else if (opcode[1] == 0x9c) {
  555. get_user(*((__u16 *) (opcode+2)), location+1);
  556. signal = math_emu_stfpc(opcode, regs);
  557. } else if (opcode[1] == 0x9d) {
  558. get_user(*((__u16 *) (opcode+2)), location+1);
  559. signal = math_emu_lfpc(opcode, regs);
  560. } else
  561. signal = SIGILL;
  562. break;
  563. default:
  564. signal = SIGILL;
  565. break;
  566. }
  567. }
  568. #endif
  569. if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
  570. signal = SIGFPE;
  571. else
  572. signal = SIGILL;
  573. if (signal == SIGFPE)
  574. do_fp_trap(regs, location,
  575. current->thread.fp_regs.fpc, pgm_int_code);
  576. else if (signal) {
  577. siginfo_t info;
  578. info.si_signo = signal;
  579. info.si_errno = 0;
  580. info.si_code = ILL_ILLOPN;
  581. info.si_addr = location;
  582. do_trap(pgm_int_code, signal, "data exception", regs, &info);
  583. }
  584. }
  585. static void space_switch_exception(struct pt_regs *regs, long pgm_int_code,
  586. unsigned long trans_exc_code)
  587. {
  588. siginfo_t info;
  589. /* Set user psw back to home space mode. */
  590. if (regs->psw.mask & PSW_MASK_PSTATE)
  591. regs->psw.mask |= PSW_ASC_HOME;
  592. /* Send SIGILL. */
  593. info.si_signo = SIGILL;
  594. info.si_errno = 0;
  595. info.si_code = ILL_PRVOPC;
  596. info.si_addr = get_psw_address(regs, pgm_int_code);
  597. do_trap(pgm_int_code, SIGILL, "space switch event", regs, &info);
  598. }
  599. asmlinkage void __kprobes kernel_stack_overflow(struct pt_regs * regs)
  600. {
  601. bust_spinlocks(1);
  602. printk("Kernel stack overflow.\n");
  603. show_regs(regs);
  604. bust_spinlocks(0);
  605. panic("Corrupt kernel stack, can't continue.");
  606. }
  607. /* init is done in lowcore.S and head.S */
  608. void __init trap_init(void)
  609. {
  610. int i;
  611. for (i = 0; i < 128; i++)
  612. pgm_check_table[i] = &default_trap_handler;
  613. pgm_check_table[1] = &illegal_op;
  614. pgm_check_table[2] = &privileged_op;
  615. pgm_check_table[3] = &execute_exception;
  616. pgm_check_table[4] = &do_protection_exception;
  617. pgm_check_table[5] = &addressing_exception;
  618. pgm_check_table[6] = &specification_exception;
  619. pgm_check_table[7] = &data_exception;
  620. pgm_check_table[8] = &overflow_exception;
  621. pgm_check_table[9] = &divide_exception;
  622. pgm_check_table[0x0A] = &overflow_exception;
  623. pgm_check_table[0x0B] = &divide_exception;
  624. pgm_check_table[0x0C] = &hfp_overflow_exception;
  625. pgm_check_table[0x0D] = &hfp_underflow_exception;
  626. pgm_check_table[0x0E] = &hfp_significance_exception;
  627. pgm_check_table[0x0F] = &hfp_divide_exception;
  628. pgm_check_table[0x10] = &do_dat_exception;
  629. pgm_check_table[0x11] = &do_dat_exception;
  630. pgm_check_table[0x12] = &translation_exception;
  631. pgm_check_table[0x13] = &special_op_exception;
  632. #ifdef CONFIG_64BIT
  633. pgm_check_table[0x38] = &do_asce_exception;
  634. pgm_check_table[0x39] = &do_dat_exception;
  635. pgm_check_table[0x3A] = &do_dat_exception;
  636. pgm_check_table[0x3B] = &do_dat_exception;
  637. #endif /* CONFIG_64BIT */
  638. pgm_check_table[0x15] = &operand_exception;
  639. pgm_check_table[0x1C] = &space_switch_exception;
  640. pgm_check_table[0x1D] = &hfp_sqrt_exception;
  641. /* Enable machine checks early. */
  642. local_mcck_enable();
  643. }