traps.c 22 KB

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