traps.c 22 KB

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