traps.c 21 KB

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