traps.c 22 KB

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