traps.c 22 KB

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