traps.c 22 KB

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