traps.c 22 KB

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