traps.c 22 KB

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