traps.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. /*
  2. * linux/arch/parisc/traps.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. * Copyright (C) 1999, 2000 Philipp Rumpf <prumpf@tux.org>
  6. */
  7. /*
  8. * 'Traps.c' handles hardware traps and faults after we have saved some
  9. * state in 'asm.s'.
  10. */
  11. #include <linux/sched.h>
  12. #include <linux/kernel.h>
  13. #include <linux/string.h>
  14. #include <linux/errno.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/timer.h>
  17. #include <linux/delay.h>
  18. #include <linux/mm.h>
  19. #include <linux/module.h>
  20. #include <linux/smp.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/console.h>
  25. #include <linux/bug.h>
  26. #include <linux/ratelimit.h>
  27. #include <linux/uaccess.h>
  28. #include <asm/assembly.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include <asm/traps.h>
  32. #include <asm/unaligned.h>
  33. #include <linux/atomic.h>
  34. #include <asm/smp.h>
  35. #include <asm/pdc.h>
  36. #include <asm/pdc_chassis.h>
  37. #include <asm/unwind.h>
  38. #include <asm/tlbflush.h>
  39. #include <asm/cacheflush.h>
  40. #include "../math-emu/math-emu.h" /* for handle_fpe() */
  41. #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  42. DEFINE_SPINLOCK(pa_dbit_lock);
  43. #endif
  44. static void parisc_show_stack(struct task_struct *task, unsigned long *sp,
  45. struct pt_regs *regs);
  46. static int printbinary(char *buf, unsigned long x, int nbits)
  47. {
  48. unsigned long mask = 1UL << (nbits - 1);
  49. while (mask != 0) {
  50. *buf++ = (mask & x ? '1' : '0');
  51. mask >>= 1;
  52. }
  53. *buf = '\0';
  54. return nbits;
  55. }
  56. #ifdef CONFIG_64BIT
  57. #define RFMT "%016lx"
  58. #else
  59. #define RFMT "%08lx"
  60. #endif
  61. #define FFMT "%016llx" /* fpregs are 64-bit always */
  62. #define PRINTREGS(lvl,r,f,fmt,x) \
  63. printk("%s%s%02d-%02d " fmt " " fmt " " fmt " " fmt "\n", \
  64. lvl, f, (x), (x+3), (r)[(x)+0], (r)[(x)+1], \
  65. (r)[(x)+2], (r)[(x)+3])
  66. static void print_gr(char *level, struct pt_regs *regs)
  67. {
  68. int i;
  69. char buf[64];
  70. printk("%s\n", level);
  71. printk("%s YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI\n", level);
  72. printbinary(buf, regs->gr[0], 32);
  73. printk("%sPSW: %s %s\n", level, buf, print_tainted());
  74. for (i = 0; i < 32; i += 4)
  75. PRINTREGS(level, regs->gr, "r", RFMT, i);
  76. }
  77. static void print_fr(char *level, struct pt_regs *regs)
  78. {
  79. int i;
  80. char buf[64];
  81. struct { u32 sw[2]; } s;
  82. /* FR are 64bit everywhere. Need to use asm to get the content
  83. * of fpsr/fper1, and we assume that we won't have a FP Identify
  84. * in our way, otherwise we're screwed.
  85. * The fldd is used to restore the T-bit if there was one, as the
  86. * store clears it anyway.
  87. * PA2.0 book says "thou shall not use fstw on FPSR/FPERs" - T-Bone */
  88. asm volatile ("fstd %%fr0,0(%1) \n\t"
  89. "fldd 0(%1),%%fr0 \n\t"
  90. : "=m" (s) : "r" (&s) : "r0");
  91. printk("%s\n", level);
  92. printk("%s VZOUICununcqcqcqcqcqcrmunTDVZOUI\n", level);
  93. printbinary(buf, s.sw[0], 32);
  94. printk("%sFPSR: %s\n", level, buf);
  95. printk("%sFPER1: %08x\n", level, s.sw[1]);
  96. /* here we'll print fr0 again, tho it'll be meaningless */
  97. for (i = 0; i < 32; i += 4)
  98. PRINTREGS(level, regs->fr, "fr", FFMT, i);
  99. }
  100. void show_regs(struct pt_regs *regs)
  101. {
  102. int i, user;
  103. char *level;
  104. unsigned long cr30, cr31;
  105. user = user_mode(regs);
  106. level = user ? KERN_DEBUG : KERN_CRIT;
  107. show_regs_print_info(level);
  108. print_gr(level, regs);
  109. for (i = 0; i < 8; i += 4)
  110. PRINTREGS(level, regs->sr, "sr", RFMT, i);
  111. if (user)
  112. print_fr(level, regs);
  113. cr30 = mfctl(30);
  114. cr31 = mfctl(31);
  115. printk("%s\n", level);
  116. printk("%sIASQ: " RFMT " " RFMT " IAOQ: " RFMT " " RFMT "\n",
  117. level, regs->iasq[0], regs->iasq[1], regs->iaoq[0], regs->iaoq[1]);
  118. printk("%s IIR: %08lx ISR: " RFMT " IOR: " RFMT "\n",
  119. level, regs->iir, regs->isr, regs->ior);
  120. printk("%s CPU: %8d CR30: " RFMT " CR31: " RFMT "\n",
  121. level, current_thread_info()->cpu, cr30, cr31);
  122. printk("%s ORIG_R28: " RFMT "\n", level, regs->orig_r28);
  123. if (user) {
  124. printk("%s IAOQ[0]: " RFMT "\n", level, regs->iaoq[0]);
  125. printk("%s IAOQ[1]: " RFMT "\n", level, regs->iaoq[1]);
  126. printk("%s RP(r2): " RFMT "\n", level, regs->gr[2]);
  127. } else {
  128. printk("%s IAOQ[0]: %pS\n", level, (void *) regs->iaoq[0]);
  129. printk("%s IAOQ[1]: %pS\n", level, (void *) regs->iaoq[1]);
  130. printk("%s RP(r2): %pS\n", level, (void *) regs->gr[2]);
  131. parisc_show_stack(current, NULL, regs);
  132. }
  133. }
  134. static DEFINE_RATELIMIT_STATE(_hppa_rs,
  135. DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);
  136. #define parisc_printk_ratelimited(critical, regs, fmt, ...) { \
  137. if ((critical || show_unhandled_signals) && __ratelimit(&_hppa_rs)) { \
  138. printk(fmt, ##__VA_ARGS__); \
  139. show_regs(regs); \
  140. } \
  141. }
  142. static void do_show_stack(struct unwind_frame_info *info)
  143. {
  144. int i = 1;
  145. printk(KERN_CRIT "Backtrace:\n");
  146. while (i <= 16) {
  147. if (unwind_once(info) < 0 || info->ip == 0)
  148. break;
  149. if (__kernel_text_address(info->ip)) {
  150. printk(KERN_CRIT " [<" RFMT ">] %pS\n",
  151. info->ip, (void *) info->ip);
  152. i++;
  153. }
  154. }
  155. printk(KERN_CRIT "\n");
  156. }
  157. static void parisc_show_stack(struct task_struct *task, unsigned long *sp,
  158. struct pt_regs *regs)
  159. {
  160. struct unwind_frame_info info;
  161. struct task_struct *t;
  162. t = task ? task : current;
  163. if (regs) {
  164. unwind_frame_init(&info, t, regs);
  165. goto show_stack;
  166. }
  167. if (t == current) {
  168. unsigned long sp;
  169. HERE:
  170. asm volatile ("copy %%r30, %0" : "=r"(sp));
  171. {
  172. struct pt_regs r;
  173. memset(&r, 0, sizeof(struct pt_regs));
  174. r.iaoq[0] = (unsigned long)&&HERE;
  175. r.gr[2] = (unsigned long)__builtin_return_address(0);
  176. r.gr[30] = sp;
  177. unwind_frame_init(&info, current, &r);
  178. }
  179. } else {
  180. unwind_frame_init_from_blocked_task(&info, t);
  181. }
  182. show_stack:
  183. do_show_stack(&info);
  184. }
  185. void show_stack(struct task_struct *t, unsigned long *sp)
  186. {
  187. return parisc_show_stack(t, sp, NULL);
  188. }
  189. int is_valid_bugaddr(unsigned long iaoq)
  190. {
  191. return 1;
  192. }
  193. void die_if_kernel(char *str, struct pt_regs *regs, long err)
  194. {
  195. if (user_mode(regs)) {
  196. if (err == 0)
  197. return; /* STFU */
  198. parisc_printk_ratelimited(1, regs,
  199. KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
  200. current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
  201. return;
  202. }
  203. oops_in_progress = 1;
  204. oops_enter();
  205. /* Amuse the user in a SPARC fashion */
  206. if (err) printk(KERN_CRIT
  207. " _______________________________ \n"
  208. " < Your System ate a SPARC! Gah! >\n"
  209. " ------------------------------- \n"
  210. " \\ ^__^\n"
  211. " (__)\\ )\\/\\\n"
  212. " U ||----w |\n"
  213. " || ||\n");
  214. /* unlock the pdc lock if necessary */
  215. pdc_emergency_unlock();
  216. /* maybe the kernel hasn't booted very far yet and hasn't been able
  217. * to initialize the serial or STI console. In that case we should
  218. * re-enable the pdc console, so that the user will be able to
  219. * identify the problem. */
  220. if (!console_drivers)
  221. pdc_console_restart();
  222. if (err)
  223. printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
  224. current->comm, task_pid_nr(current), str, err);
  225. /* Wot's wrong wif bein' racy? */
  226. if (current->thread.flags & PARISC_KERNEL_DEATH) {
  227. printk(KERN_CRIT "%s() recursion detected.\n", __func__);
  228. local_irq_enable();
  229. while (1);
  230. }
  231. current->thread.flags |= PARISC_KERNEL_DEATH;
  232. show_regs(regs);
  233. dump_stack();
  234. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  235. if (in_interrupt())
  236. panic("Fatal exception in interrupt");
  237. if (panic_on_oops) {
  238. printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
  239. ssleep(5);
  240. panic("Fatal exception");
  241. }
  242. oops_exit();
  243. do_exit(SIGSEGV);
  244. }
  245. /* gdb uses break 4,8 */
  246. #define GDB_BREAK_INSN 0x10004
  247. static void handle_gdb_break(struct pt_regs *regs, int wot)
  248. {
  249. struct siginfo si;
  250. si.si_signo = SIGTRAP;
  251. si.si_errno = 0;
  252. si.si_code = wot;
  253. si.si_addr = (void __user *) (regs->iaoq[0] & ~3);
  254. force_sig_info(SIGTRAP, &si, current);
  255. }
  256. static void handle_break(struct pt_regs *regs)
  257. {
  258. unsigned iir = regs->iir;
  259. if (unlikely(iir == PARISC_BUG_BREAK_INSN && !user_mode(regs))) {
  260. /* check if a BUG() or WARN() trapped here. */
  261. enum bug_trap_type tt;
  262. tt = report_bug(regs->iaoq[0] & ~3, regs);
  263. if (tt == BUG_TRAP_TYPE_WARN) {
  264. regs->iaoq[0] += 4;
  265. regs->iaoq[1] += 4;
  266. return; /* return to next instruction when WARN_ON(). */
  267. }
  268. die_if_kernel("Unknown kernel breakpoint", regs,
  269. (tt == BUG_TRAP_TYPE_NONE) ? 9 : 0);
  270. }
  271. if (unlikely(iir != GDB_BREAK_INSN))
  272. parisc_printk_ratelimited(0, regs,
  273. KERN_DEBUG "break %d,%d: pid=%d command='%s'\n",
  274. iir & 31, (iir>>13) & ((1<<13)-1),
  275. task_pid_nr(current), current->comm);
  276. /* send standard GDB signal */
  277. handle_gdb_break(regs, TRAP_BRKPT);
  278. }
  279. static void default_trap(int code, struct pt_regs *regs)
  280. {
  281. printk(KERN_ERR "Trap %d on CPU %d\n", code, smp_processor_id());
  282. show_regs(regs);
  283. }
  284. void (*cpu_lpmc) (int code, struct pt_regs *regs) __read_mostly = default_trap;
  285. void transfer_pim_to_trap_frame(struct pt_regs *regs)
  286. {
  287. register int i;
  288. extern unsigned int hpmc_pim_data[];
  289. struct pdc_hpmc_pim_11 *pim_narrow;
  290. struct pdc_hpmc_pim_20 *pim_wide;
  291. if (boot_cpu_data.cpu_type >= pcxu) {
  292. pim_wide = (struct pdc_hpmc_pim_20 *)hpmc_pim_data;
  293. /*
  294. * Note: The following code will probably generate a
  295. * bunch of truncation error warnings from the compiler.
  296. * Could be handled with an ifdef, but perhaps there
  297. * is a better way.
  298. */
  299. regs->gr[0] = pim_wide->cr[22];
  300. for (i = 1; i < 32; i++)
  301. regs->gr[i] = pim_wide->gr[i];
  302. for (i = 0; i < 32; i++)
  303. regs->fr[i] = pim_wide->fr[i];
  304. for (i = 0; i < 8; i++)
  305. regs->sr[i] = pim_wide->sr[i];
  306. regs->iasq[0] = pim_wide->cr[17];
  307. regs->iasq[1] = pim_wide->iasq_back;
  308. regs->iaoq[0] = pim_wide->cr[18];
  309. regs->iaoq[1] = pim_wide->iaoq_back;
  310. regs->sar = pim_wide->cr[11];
  311. regs->iir = pim_wide->cr[19];
  312. regs->isr = pim_wide->cr[20];
  313. regs->ior = pim_wide->cr[21];
  314. }
  315. else {
  316. pim_narrow = (struct pdc_hpmc_pim_11 *)hpmc_pim_data;
  317. regs->gr[0] = pim_narrow->cr[22];
  318. for (i = 1; i < 32; i++)
  319. regs->gr[i] = pim_narrow->gr[i];
  320. for (i = 0; i < 32; i++)
  321. regs->fr[i] = pim_narrow->fr[i];
  322. for (i = 0; i < 8; i++)
  323. regs->sr[i] = pim_narrow->sr[i];
  324. regs->iasq[0] = pim_narrow->cr[17];
  325. regs->iasq[1] = pim_narrow->iasq_back;
  326. regs->iaoq[0] = pim_narrow->cr[18];
  327. regs->iaoq[1] = pim_narrow->iaoq_back;
  328. regs->sar = pim_narrow->cr[11];
  329. regs->iir = pim_narrow->cr[19];
  330. regs->isr = pim_narrow->cr[20];
  331. regs->ior = pim_narrow->cr[21];
  332. }
  333. /*
  334. * The following fields only have meaning if we came through
  335. * another path. So just zero them here.
  336. */
  337. regs->ksp = 0;
  338. regs->kpc = 0;
  339. regs->orig_r28 = 0;
  340. }
  341. /*
  342. * This routine is called as a last resort when everything else
  343. * has gone clearly wrong. We get called for faults in kernel space,
  344. * and HPMC's.
  345. */
  346. void parisc_terminate(char *msg, struct pt_regs *regs, int code, unsigned long offset)
  347. {
  348. static DEFINE_SPINLOCK(terminate_lock);
  349. oops_in_progress = 1;
  350. set_eiem(0);
  351. local_irq_disable();
  352. spin_lock(&terminate_lock);
  353. /* unlock the pdc lock if necessary */
  354. pdc_emergency_unlock();
  355. /* restart pdc console if necessary */
  356. if (!console_drivers)
  357. pdc_console_restart();
  358. /* Not all paths will gutter the processor... */
  359. switch(code){
  360. case 1:
  361. transfer_pim_to_trap_frame(regs);
  362. break;
  363. default:
  364. /* Fall through */
  365. break;
  366. }
  367. {
  368. /* show_stack(NULL, (unsigned long *)regs->gr[30]); */
  369. struct unwind_frame_info info;
  370. unwind_frame_init(&info, current, regs);
  371. do_show_stack(&info);
  372. }
  373. printk("\n");
  374. printk(KERN_CRIT "%s: Code=%d regs=%p (Addr=" RFMT ")\n",
  375. msg, code, regs, offset);
  376. show_regs(regs);
  377. spin_unlock(&terminate_lock);
  378. /* put soft power button back under hardware control;
  379. * if the user had pressed it once at any time, the
  380. * system will shut down immediately right here. */
  381. pdc_soft_power_button(0);
  382. /* Call kernel panic() so reboot timeouts work properly
  383. * FIXME: This function should be on the list of
  384. * panic notifiers, and we should call panic
  385. * directly from the location that we wish.
  386. * e.g. We should not call panic from
  387. * parisc_terminate, but rather the oter way around.
  388. * This hack works, prints the panic message twice,
  389. * and it enables reboot timers!
  390. */
  391. panic(msg);
  392. }
  393. void notrace handle_interruption(int code, struct pt_regs *regs)
  394. {
  395. unsigned long fault_address = 0;
  396. unsigned long fault_space = 0;
  397. struct siginfo si;
  398. if (code == 1)
  399. pdc_console_restart(); /* switch back to pdc if HPMC */
  400. else
  401. local_irq_enable();
  402. /* Security check:
  403. * If the priority level is still user, and the
  404. * faulting space is not equal to the active space
  405. * then the user is attempting something in a space
  406. * that does not belong to them. Kill the process.
  407. *
  408. * This is normally the situation when the user
  409. * attempts to jump into the kernel space at the
  410. * wrong offset, be it at the gateway page or a
  411. * random location.
  412. *
  413. * We cannot normally signal the process because it
  414. * could *be* on the gateway page, and processes
  415. * executing on the gateway page can't have signals
  416. * delivered.
  417. *
  418. * We merely readjust the address into the users
  419. * space, at a destination address of zero, and
  420. * allow processing to continue.
  421. */
  422. if (((unsigned long)regs->iaoq[0] & 3) &&
  423. ((unsigned long)regs->iasq[0] != (unsigned long)regs->sr[7])) {
  424. /* Kill the user process later */
  425. regs->iaoq[0] = 0 | 3;
  426. regs->iaoq[1] = regs->iaoq[0] + 4;
  427. regs->iasq[0] = regs->iasq[1] = regs->sr[7];
  428. regs->gr[0] &= ~PSW_B;
  429. return;
  430. }
  431. #if 0
  432. printk(KERN_CRIT "Interruption # %d\n", code);
  433. #endif
  434. switch(code) {
  435. case 1:
  436. /* High-priority machine check (HPMC) */
  437. /* set up a new led state on systems shipped with a LED State panel */
  438. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_HPMC);
  439. parisc_terminate("High Priority Machine Check (HPMC)",
  440. regs, code, 0);
  441. /* NOT REACHED */
  442. case 2:
  443. /* Power failure interrupt */
  444. printk(KERN_CRIT "Power failure interrupt !\n");
  445. return;
  446. case 3:
  447. /* Recovery counter trap */
  448. regs->gr[0] &= ~PSW_R;
  449. if (user_space(regs))
  450. handle_gdb_break(regs, TRAP_TRACE);
  451. /* else this must be the start of a syscall - just let it run */
  452. return;
  453. case 5:
  454. /* Low-priority machine check */
  455. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_LPMC);
  456. flush_cache_all();
  457. flush_tlb_all();
  458. cpu_lpmc(5, regs);
  459. return;
  460. case 6:
  461. /* Instruction TLB miss fault/Instruction page fault */
  462. fault_address = regs->iaoq[0];
  463. fault_space = regs->iasq[0];
  464. break;
  465. case 8:
  466. /* Illegal instruction trap */
  467. die_if_kernel("Illegal instruction", regs, code);
  468. si.si_code = ILL_ILLOPC;
  469. goto give_sigill;
  470. case 9:
  471. /* Break instruction trap */
  472. handle_break(regs);
  473. return;
  474. case 10:
  475. /* Privileged operation trap */
  476. die_if_kernel("Privileged operation", regs, code);
  477. si.si_code = ILL_PRVOPC;
  478. goto give_sigill;
  479. case 11:
  480. /* Privileged register trap */
  481. if ((regs->iir & 0xffdfffe0) == 0x034008a0) {
  482. /* This is a MFCTL cr26/cr27 to gr instruction.
  483. * PCXS traps on this, so we need to emulate it.
  484. */
  485. if (regs->iir & 0x00200000)
  486. regs->gr[regs->iir & 0x1f] = mfctl(27);
  487. else
  488. regs->gr[regs->iir & 0x1f] = mfctl(26);
  489. regs->iaoq[0] = regs->iaoq[1];
  490. regs->iaoq[1] += 4;
  491. regs->iasq[0] = regs->iasq[1];
  492. return;
  493. }
  494. die_if_kernel("Privileged register usage", regs, code);
  495. si.si_code = ILL_PRVREG;
  496. give_sigill:
  497. si.si_signo = SIGILL;
  498. si.si_errno = 0;
  499. si.si_addr = (void __user *) regs->iaoq[0];
  500. force_sig_info(SIGILL, &si, current);
  501. return;
  502. case 12:
  503. /* Overflow Trap, let the userland signal handler do the cleanup */
  504. si.si_signo = SIGFPE;
  505. si.si_code = FPE_INTOVF;
  506. si.si_addr = (void __user *) regs->iaoq[0];
  507. force_sig_info(SIGFPE, &si, current);
  508. return;
  509. case 13:
  510. /* Conditional Trap
  511. The condition succeeds in an instruction which traps
  512. on condition */
  513. if(user_mode(regs)){
  514. si.si_signo = SIGFPE;
  515. /* Set to zero, and let the userspace app figure it out from
  516. the insn pointed to by si_addr */
  517. si.si_code = 0;
  518. si.si_addr = (void __user *) regs->iaoq[0];
  519. force_sig_info(SIGFPE, &si, current);
  520. return;
  521. }
  522. /* The kernel doesn't want to handle condition codes */
  523. break;
  524. case 14:
  525. /* Assist Exception Trap, i.e. floating point exception. */
  526. die_if_kernel("Floating point exception", regs, 0); /* quiet */
  527. __inc_irq_stat(irq_fpassist_count);
  528. handle_fpe(regs);
  529. return;
  530. case 15:
  531. /* Data TLB miss fault/Data page fault */
  532. /* Fall through */
  533. case 16:
  534. /* Non-access instruction TLB miss fault */
  535. /* The instruction TLB entry needed for the target address of the FIC
  536. is absent, and hardware can't find it, so we get to cleanup */
  537. /* Fall through */
  538. case 17:
  539. /* Non-access data TLB miss fault/Non-access data page fault */
  540. /* FIXME:
  541. Still need to add slow path emulation code here!
  542. If the insn used a non-shadow register, then the tlb
  543. handlers could not have their side-effect (e.g. probe
  544. writing to a target register) emulated since rfir would
  545. erase the changes to said register. Instead we have to
  546. setup everything, call this function we are in, and emulate
  547. by hand. Technically we need to emulate:
  548. fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw
  549. */
  550. fault_address = regs->ior;
  551. fault_space = regs->isr;
  552. break;
  553. case 18:
  554. /* PCXS only -- later cpu's split this into types 26,27 & 28 */
  555. /* Check for unaligned access */
  556. if (check_unaligned(regs)) {
  557. handle_unaligned(regs);
  558. return;
  559. }
  560. /* Fall Through */
  561. case 26:
  562. /* PCXL: Data memory access rights trap */
  563. fault_address = regs->ior;
  564. fault_space = regs->isr;
  565. break;
  566. case 19:
  567. /* Data memory break trap */
  568. regs->gr[0] |= PSW_X; /* So we can single-step over the trap */
  569. /* fall thru */
  570. case 21:
  571. /* Page reference trap */
  572. handle_gdb_break(regs, TRAP_HWBKPT);
  573. return;
  574. case 25:
  575. /* Taken branch trap */
  576. regs->gr[0] &= ~PSW_T;
  577. if (user_space(regs))
  578. handle_gdb_break(regs, TRAP_BRANCH);
  579. /* else this must be the start of a syscall - just let it
  580. * run.
  581. */
  582. return;
  583. case 7:
  584. /* Instruction access rights */
  585. /* PCXL: Instruction memory protection trap */
  586. /*
  587. * This could be caused by either: 1) a process attempting
  588. * to execute within a vma that does not have execute
  589. * permission, or 2) an access rights violation caused by a
  590. * flush only translation set up by ptep_get_and_clear().
  591. * So we check the vma permissions to differentiate the two.
  592. * If the vma indicates we have execute permission, then
  593. * the cause is the latter one. In this case, we need to
  594. * call do_page_fault() to fix the problem.
  595. */
  596. if (user_mode(regs)) {
  597. struct vm_area_struct *vma;
  598. down_read(&current->mm->mmap_sem);
  599. vma = find_vma(current->mm,regs->iaoq[0]);
  600. if (vma && (regs->iaoq[0] >= vma->vm_start)
  601. && (vma->vm_flags & VM_EXEC)) {
  602. fault_address = regs->iaoq[0];
  603. fault_space = regs->iasq[0];
  604. up_read(&current->mm->mmap_sem);
  605. break; /* call do_page_fault() */
  606. }
  607. up_read(&current->mm->mmap_sem);
  608. }
  609. /* Fall Through */
  610. case 27:
  611. /* Data memory protection ID trap */
  612. if (code == 27 && !user_mode(regs) &&
  613. fixup_exception(regs))
  614. return;
  615. die_if_kernel("Protection id trap", regs, code);
  616. si.si_code = SEGV_MAPERR;
  617. si.si_signo = SIGSEGV;
  618. si.si_errno = 0;
  619. if (code == 7)
  620. si.si_addr = (void __user *) regs->iaoq[0];
  621. else
  622. si.si_addr = (void __user *) regs->ior;
  623. force_sig_info(SIGSEGV, &si, current);
  624. return;
  625. case 28:
  626. /* Unaligned data reference trap */
  627. handle_unaligned(regs);
  628. return;
  629. default:
  630. if (user_mode(regs)) {
  631. parisc_printk_ratelimited(0, regs, KERN_DEBUG
  632. "handle_interruption() pid=%d command='%s'\n",
  633. task_pid_nr(current), current->comm);
  634. /* SIGBUS, for lack of a better one. */
  635. si.si_signo = SIGBUS;
  636. si.si_code = BUS_OBJERR;
  637. si.si_errno = 0;
  638. si.si_addr = (void __user *) regs->ior;
  639. force_sig_info(SIGBUS, &si, current);
  640. return;
  641. }
  642. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  643. parisc_terminate("Unexpected interruption", regs, code, 0);
  644. /* NOT REACHED */
  645. }
  646. if (user_mode(regs)) {
  647. if ((fault_space >> SPACEID_SHIFT) != (regs->sr[7] >> SPACEID_SHIFT)) {
  648. parisc_printk_ratelimited(0, regs, KERN_DEBUG
  649. "User fault %d on space 0x%08lx, pid=%d command='%s'\n",
  650. code, fault_space,
  651. task_pid_nr(current), current->comm);
  652. si.si_signo = SIGSEGV;
  653. si.si_errno = 0;
  654. si.si_code = SEGV_MAPERR;
  655. si.si_addr = (void __user *) regs->ior;
  656. force_sig_info(SIGSEGV, &si, current);
  657. return;
  658. }
  659. }
  660. else {
  661. /*
  662. * The kernel should never fault on its own address space,
  663. * unless pagefault_disable() was called before.
  664. */
  665. if (fault_space == 0 && !faulthandler_disabled())
  666. {
  667. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  668. parisc_terminate("Kernel Fault", regs, code, fault_address);
  669. }
  670. }
  671. do_page_fault(regs, code, fault_address);
  672. }
  673. int __init check_ivt(void *iva)
  674. {
  675. extern u32 os_hpmc_size;
  676. extern const u32 os_hpmc[];
  677. int i;
  678. u32 check = 0;
  679. u32 *ivap;
  680. u32 *hpmcp;
  681. u32 length;
  682. if (strcmp((char *)iva, "cows can fly"))
  683. return -1;
  684. ivap = (u32 *)iva;
  685. for (i = 0; i < 8; i++)
  686. *ivap++ = 0;
  687. /* Compute Checksum for HPMC handler */
  688. length = os_hpmc_size;
  689. ivap[7] = length;
  690. hpmcp = (u32 *)os_hpmc;
  691. for (i=0; i<length/4; i++)
  692. check += *hpmcp++;
  693. for (i=0; i<8; i++)
  694. check += ivap[i];
  695. ivap[5] = -check;
  696. return 0;
  697. }
  698. #ifndef CONFIG_64BIT
  699. extern const void fault_vector_11;
  700. #endif
  701. extern const void fault_vector_20;
  702. void __init trap_init(void)
  703. {
  704. void *iva;
  705. if (boot_cpu_data.cpu_type >= pcxu)
  706. iva = (void *) &fault_vector_20;
  707. else
  708. #ifdef CONFIG_64BIT
  709. panic("Can't boot 64-bit OS on PA1.1 processor!");
  710. #else
  711. iva = (void *) &fault_vector_11;
  712. #endif
  713. if (check_ivt(iva))
  714. panic("IVT invalid");
  715. }