traps.c 22 KB

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