traps.c 20 KB

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