traps.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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/config.h>
  12. #include <linux/sched.h>
  13. #include <linux/kernel.h>
  14. #include <linux/string.h>
  15. #include <linux/errno.h>
  16. #include <linux/ptrace.h>
  17. #include <linux/timer.h>
  18. #include <linux/mm.h>
  19. #include <linux/module.h>
  20. #include <linux/smp.h>
  21. #include <linux/smp_lock.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/init.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/console.h>
  26. #include <linux/kallsyms.h>
  27. #include <asm/assembly.h>
  28. #include <asm/system.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/io.h>
  31. #include <asm/irq.h>
  32. #include <asm/traps.h>
  33. #include <asm/unaligned.h>
  34. #include <asm/atomic.h>
  35. #include <asm/smp.h>
  36. #include <asm/pdc.h>
  37. #include <asm/pdc_chassis.h>
  38. #include <asm/unwind.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. int printbinary(char *buf, unsigned long x, int nbits)
  46. {
  47. unsigned long mask = 1UL << (nbits - 1);
  48. while (mask != 0) {
  49. *buf++ = (mask & x ? '1' : '0');
  50. mask >>= 1;
  51. }
  52. *buf = '\0';
  53. return nbits;
  54. }
  55. #ifdef __LP64__
  56. #define RFMT "%016lx"
  57. #else
  58. #define RFMT "%08lx"
  59. #endif
  60. void show_regs(struct pt_regs *regs)
  61. {
  62. int i;
  63. char buf[128], *p;
  64. char *level;
  65. unsigned long cr30;
  66. unsigned long cr31;
  67. /* carlos says that gcc understands better memory in a struct,
  68. * and it makes our life easier with fpregs -- T-Bone */
  69. struct { u32 sw[2]; } s;
  70. level = user_mode(regs) ? KERN_DEBUG : KERN_CRIT;
  71. printk("%s\n", level); /* don't want to have that pretty register dump messed up */
  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. int j;
  77. p = buf;
  78. p += sprintf(p, "%sr%02d-%02d ", level, i, i + 3);
  79. for (j = 0; j < 4; j++) {
  80. p += sprintf(p, " " RFMT, (i+j) == 0 ? 0 : regs->gr[i + j]);
  81. }
  82. printk("%s\n", buf);
  83. }
  84. for (i = 0; i < 8; i += 4) {
  85. int j;
  86. p = buf;
  87. p += sprintf(p, "%ssr%d-%d ", level, i, i + 3);
  88. for (j = 0; j < 4; j++) {
  89. p += sprintf(p, " " RFMT, regs->sr[i + j]);
  90. }
  91. printk("%s\n", buf);
  92. }
  93. /* FR are 64bit everywhere. Need to use asm to get the content
  94. * of fpsr/fper1, and we assume that we won't have a FP Identify
  95. * in our way, otherwise we're screwed.
  96. * The fldd is used to restore the T-bit if there was one, as the
  97. * store clears it anyway.
  98. * BTW, PA2.0 book says "thou shall not use fstw on FPSR/FPERs". */
  99. __asm__ (
  100. "fstd %%fr0,0(%1) \n\t"
  101. "fldd 0(%1),%%fr0 \n\t"
  102. : "=m" (s) : "r" (&s) : "%r0"
  103. );
  104. printk("%s\n", level);
  105. printk("%s VZOUICununcqcqcqcqcqcrmunTDVZOUI\n", level);
  106. printbinary(buf, s.sw[0], 32);
  107. printk("%sFPSR: %s\n", level, buf);
  108. printk("%sFPER1: %08x\n", level, s.sw[1]);
  109. /* here we'll print fr0 again, tho it'll be meaningless */
  110. for (i = 0; i < 32; i += 4) {
  111. int j;
  112. p = buf;
  113. p += sprintf(p, "%sfr%02d-%02d ", level, i, i + 3);
  114. for (j = 0; j < 4; j++)
  115. p += sprintf(p, " %016llx", (i+j) == 0 ? 0 : regs->fr[i+j]);
  116. printk("%s\n", buf);
  117. }
  118. cr30 = mfctl(30);
  119. cr31 = mfctl(31);
  120. printk("%s\n", level);
  121. printk("%sIASQ: " RFMT " " RFMT " IAOQ: " RFMT " " RFMT "\n",
  122. level, regs->iasq[0], regs->iasq[1], regs->iaoq[0], regs->iaoq[1]);
  123. printk("%s IIR: %08lx ISR: " RFMT " IOR: " RFMT "\n",
  124. level, regs->iir, regs->isr, regs->ior);
  125. printk("%s CPU: %8d CR30: " RFMT " CR31: " RFMT "\n",
  126. level, current_thread_info()->cpu, cr30, cr31);
  127. printk("%s ORIG_R28: " RFMT "\n", level, regs->orig_r28);
  128. printk(level);
  129. print_symbol(" IAOQ[0]: %s\n", regs->iaoq[0]);
  130. printk(level);
  131. print_symbol(" IAOQ[1]: %s\n", regs->iaoq[1]);
  132. printk(level);
  133. print_symbol(" RP(r2): %s\n", regs->gr[2]);
  134. }
  135. void dump_stack(void)
  136. {
  137. show_stack(NULL, NULL);
  138. }
  139. EXPORT_SYMBOL(dump_stack);
  140. static void do_show_stack(struct unwind_frame_info *info)
  141. {
  142. int i = 1;
  143. printk("Backtrace:\n");
  144. while (i <= 16) {
  145. if (unwind_once(info) < 0 || info->ip == 0)
  146. break;
  147. if (__kernel_text_address(info->ip)) {
  148. printk(" [<" RFMT ">] ", info->ip);
  149. #ifdef CONFIG_KALLSYMS
  150. print_symbol("%s\n", info->ip);
  151. #else
  152. if ((i & 0x03) == 0)
  153. printk("\n");
  154. #endif
  155. i++;
  156. }
  157. }
  158. printk("\n");
  159. }
  160. void show_stack(struct task_struct *task, unsigned long *s)
  161. {
  162. struct unwind_frame_info info;
  163. if (!task) {
  164. unsigned long sp;
  165. struct pt_regs *r;
  166. HERE:
  167. asm volatile ("copy %%r30, %0" : "=r"(sp));
  168. r = (struct pt_regs *)kmalloc(sizeof(struct pt_regs), GFP_KERNEL);
  169. if (!r)
  170. return;
  171. memset(r, 0, sizeof(struct pt_regs));
  172. r->iaoq[0] = (unsigned long)&&HERE;
  173. r->gr[2] = (unsigned long)__builtin_return_address(0);
  174. r->gr[30] = sp;
  175. unwind_frame_init(&info, current, r);
  176. kfree(r);
  177. } else {
  178. unwind_frame_init_from_blocked_task(&info, task);
  179. }
  180. do_show_stack(&info);
  181. }
  182. void die_if_kernel(char *str, struct pt_regs *regs, long err)
  183. {
  184. if (user_mode(regs)) {
  185. if (err == 0)
  186. return; /* STFU */
  187. printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
  188. current->comm, current->pid, str, err, regs->iaoq[0]);
  189. #ifdef PRINT_USER_FAULTS
  190. /* XXX for debugging only */
  191. show_regs(regs);
  192. #endif
  193. return;
  194. }
  195. oops_in_progress = 1;
  196. /* Amuse the user in a SPARC fashion */
  197. printk(
  198. " _______________________________ \n"
  199. " < Your System ate a SPARC! Gah! >\n"
  200. " ------------------------------- \n"
  201. " \\ ^__^\n"
  202. " \\ (xx)\\_______\n"
  203. " (__)\\ )\\/\\\n"
  204. " U ||----w |\n"
  205. " || ||\n");
  206. /* unlock the pdc lock if necessary */
  207. pdc_emergency_unlock();
  208. /* maybe the kernel hasn't booted very far yet and hasn't been able
  209. * to initialize the serial or STI console. In that case we should
  210. * re-enable the pdc console, so that the user will be able to
  211. * identify the problem. */
  212. if (!console_drivers)
  213. pdc_console_restart();
  214. printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
  215. current->comm, current->pid, str, err);
  216. show_regs(regs);
  217. /* Wot's wrong wif bein' racy? */
  218. if (current->thread.flags & PARISC_KERNEL_DEATH) {
  219. printk(KERN_CRIT "%s() recursion detected.\n", __FUNCTION__);
  220. local_irq_enable();
  221. while (1);
  222. }
  223. current->thread.flags |= PARISC_KERNEL_DEATH;
  224. do_exit(SIGSEGV);
  225. }
  226. int syscall_ipi(int (*syscall) (struct pt_regs *), struct pt_regs *regs)
  227. {
  228. return syscall(regs);
  229. }
  230. /* gdb uses break 4,8 */
  231. #define GDB_BREAK_INSN 0x10004
  232. void handle_gdb_break(struct pt_regs *regs, int wot)
  233. {
  234. struct siginfo si;
  235. si.si_code = wot;
  236. si.si_addr = (void __user *) (regs->iaoq[0] & ~3);
  237. si.si_signo = SIGTRAP;
  238. si.si_errno = 0;
  239. force_sig_info(SIGTRAP, &si, current);
  240. }
  241. void handle_break(unsigned iir, struct pt_regs *regs)
  242. {
  243. struct siginfo si;
  244. switch(iir) {
  245. case 0x00:
  246. #ifdef PRINT_USER_FAULTS
  247. printk(KERN_DEBUG "break 0,0: pid=%d command='%s'\n",
  248. current->pid, current->comm);
  249. #endif
  250. die_if_kernel("Breakpoint", regs, 0);
  251. #ifdef PRINT_USER_FAULTS
  252. show_regs(regs);
  253. #endif
  254. si.si_code = TRAP_BRKPT;
  255. si.si_addr = (void __user *) (regs->iaoq[0] & ~3);
  256. si.si_signo = SIGTRAP;
  257. force_sig_info(SIGTRAP, &si, current);
  258. break;
  259. case GDB_BREAK_INSN:
  260. die_if_kernel("Breakpoint", regs, 0);
  261. handle_gdb_break(regs, TRAP_BRKPT);
  262. break;
  263. default:
  264. #ifdef PRINT_USER_FAULTS
  265. printk(KERN_DEBUG "break %#08x: pid=%d command='%s'\n",
  266. iir, current->pid, current->comm);
  267. show_regs(regs);
  268. #endif
  269. si.si_signo = SIGTRAP;
  270. si.si_code = TRAP_BRKPT;
  271. si.si_addr = (void __user *) (regs->iaoq[0] & ~3);
  272. force_sig_info(SIGTRAP, &si, current);
  273. return;
  274. }
  275. }
  276. int handle_toc(void)
  277. {
  278. printk(KERN_CRIT "TOC call.\n");
  279. return 0;
  280. }
  281. static void default_trap(int code, struct pt_regs *regs)
  282. {
  283. printk(KERN_ERR "Trap %d on CPU %d\n", code, smp_processor_id());
  284. show_regs(regs);
  285. }
  286. void (*cpu_lpmc) (int code, struct pt_regs *regs) = default_trap;
  287. void transfer_pim_to_trap_frame(struct pt_regs *regs)
  288. {
  289. register int i;
  290. extern unsigned int hpmc_pim_data[];
  291. struct pdc_hpmc_pim_11 *pim_narrow;
  292. struct pdc_hpmc_pim_20 *pim_wide;
  293. if (boot_cpu_data.cpu_type >= pcxu) {
  294. pim_wide = (struct pdc_hpmc_pim_20 *)hpmc_pim_data;
  295. /*
  296. * Note: The following code will probably generate a
  297. * bunch of truncation error warnings from the compiler.
  298. * Could be handled with an ifdef, but perhaps there
  299. * is a better way.
  300. */
  301. regs->gr[0] = pim_wide->cr[22];
  302. for (i = 1; i < 32; i++)
  303. regs->gr[i] = pim_wide->gr[i];
  304. for (i = 0; i < 32; i++)
  305. regs->fr[i] = pim_wide->fr[i];
  306. for (i = 0; i < 8; i++)
  307. regs->sr[i] = pim_wide->sr[i];
  308. regs->iasq[0] = pim_wide->cr[17];
  309. regs->iasq[1] = pim_wide->iasq_back;
  310. regs->iaoq[0] = pim_wide->cr[18];
  311. regs->iaoq[1] = pim_wide->iaoq_back;
  312. regs->sar = pim_wide->cr[11];
  313. regs->iir = pim_wide->cr[19];
  314. regs->isr = pim_wide->cr[20];
  315. regs->ior = pim_wide->cr[21];
  316. }
  317. else {
  318. pim_narrow = (struct pdc_hpmc_pim_11 *)hpmc_pim_data;
  319. regs->gr[0] = pim_narrow->cr[22];
  320. for (i = 1; i < 32; i++)
  321. regs->gr[i] = pim_narrow->gr[i];
  322. for (i = 0; i < 32; i++)
  323. regs->fr[i] = pim_narrow->fr[i];
  324. for (i = 0; i < 8; i++)
  325. regs->sr[i] = pim_narrow->sr[i];
  326. regs->iasq[0] = pim_narrow->cr[17];
  327. regs->iasq[1] = pim_narrow->iasq_back;
  328. regs->iaoq[0] = pim_narrow->cr[18];
  329. regs->iaoq[1] = pim_narrow->iaoq_back;
  330. regs->sar = pim_narrow->cr[11];
  331. regs->iir = pim_narrow->cr[19];
  332. regs->isr = pim_narrow->cr[20];
  333. regs->ior = pim_narrow->cr[21];
  334. }
  335. /*
  336. * The following fields only have meaning if we came through
  337. * another path. So just zero them here.
  338. */
  339. regs->ksp = 0;
  340. regs->kpc = 0;
  341. regs->orig_r28 = 0;
  342. }
  343. /*
  344. * This routine is called as a last resort when everything else
  345. * has gone clearly wrong. We get called for faults in kernel space,
  346. * and HPMC's.
  347. */
  348. void parisc_terminate(char *msg, struct pt_regs *regs, int code, unsigned long offset)
  349. {
  350. static DEFINE_SPINLOCK(terminate_lock);
  351. oops_in_progress = 1;
  352. set_eiem(0);
  353. local_irq_disable();
  354. spin_lock(&terminate_lock);
  355. /* unlock the pdc lock if necessary */
  356. pdc_emergency_unlock();
  357. /* restart pdc console if necessary */
  358. if (!console_drivers)
  359. pdc_console_restart();
  360. /* Not all paths will gutter the processor... */
  361. switch(code){
  362. case 1:
  363. transfer_pim_to_trap_frame(regs);
  364. break;
  365. default:
  366. /* Fall through */
  367. break;
  368. }
  369. {
  370. /* show_stack(NULL, (unsigned long *)regs->gr[30]); */
  371. struct unwind_frame_info info;
  372. unwind_frame_init(&info, current, regs);
  373. do_show_stack(&info);
  374. }
  375. printk("\n");
  376. printk(KERN_CRIT "%s: Code=%d regs=%p (Addr=" RFMT ")\n",
  377. msg, code, regs, offset);
  378. show_regs(regs);
  379. spin_unlock(&terminate_lock);
  380. /* put soft power button back under hardware control;
  381. * if the user had pressed it once at any time, the
  382. * system will shut down immediately right here. */
  383. pdc_soft_power_button(0);
  384. /* Call kernel panic() so reboot timeouts work properly
  385. * FIXME: This function should be on the list of
  386. * panic notifiers, and we should call panic
  387. * directly from the location that we wish.
  388. * e.g. We should not call panic from
  389. * parisc_terminate, but rather the oter way around.
  390. * This hack works, prints the panic message twice,
  391. * and it enables reboot timers!
  392. */
  393. panic(msg);
  394. }
  395. void handle_interruption(int code, struct pt_regs *regs)
  396. {
  397. unsigned long fault_address = 0;
  398. unsigned long fault_space = 0;
  399. struct siginfo si;
  400. if (code == 1)
  401. pdc_console_restart(); /* switch back to pdc if HPMC */
  402. else
  403. local_irq_enable();
  404. /* Security check:
  405. * If the priority level is still user, and the
  406. * faulting space is not equal to the active space
  407. * then the user is attempting something in a space
  408. * that does not belong to them. Kill the process.
  409. *
  410. * This is normally the situation when the user
  411. * attempts to jump into the kernel space at the
  412. * wrong offset, be it at the gateway page or a
  413. * random location.
  414. *
  415. * We cannot normally signal the process because it
  416. * could *be* on the gateway page, and processes
  417. * executing on the gateway page can't have signals
  418. * delivered.
  419. *
  420. * We merely readjust the address into the users
  421. * space, at a destination address of zero, and
  422. * allow processing to continue.
  423. */
  424. if (((unsigned long)regs->iaoq[0] & 3) &&
  425. ((unsigned long)regs->iasq[0] != (unsigned long)regs->sr[7])) {
  426. /* Kill the user process later */
  427. regs->iaoq[0] = 0 | 3;
  428. regs->iaoq[1] = regs->iaoq[0] + 4;
  429. regs->iasq[0] = regs->iasq[0] = regs->sr[7];
  430. regs->gr[0] &= ~PSW_B;
  431. return;
  432. }
  433. #if 0
  434. printk(KERN_CRIT "Interruption # %d\n", code);
  435. #endif
  436. switch(code) {
  437. case 1:
  438. /* High-priority machine check (HPMC) */
  439. /* set up a new led state on systems shipped with a LED State panel */
  440. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_HPMC);
  441. parisc_terminate("High Priority Machine Check (HPMC)",
  442. regs, code, 0);
  443. /* NOT REACHED */
  444. case 2:
  445. /* Power failure interrupt */
  446. printk(KERN_CRIT "Power failure interrupt !\n");
  447. return;
  448. case 3:
  449. /* Recovery counter trap */
  450. regs->gr[0] &= ~PSW_R;
  451. if (user_space(regs))
  452. handle_gdb_break(regs, TRAP_TRACE);
  453. /* else this must be the start of a syscall - just let it run */
  454. return;
  455. case 5:
  456. /* Low-priority machine check */
  457. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_LPMC);
  458. flush_all_caches();
  459. cpu_lpmc(5, regs);
  460. return;
  461. case 6:
  462. /* Instruction TLB miss fault/Instruction page fault */
  463. fault_address = regs->iaoq[0];
  464. fault_space = regs->iasq[0];
  465. break;
  466. case 8:
  467. /* Illegal instruction trap */
  468. die_if_kernel("Illegal instruction", regs, code);
  469. si.si_code = ILL_ILLOPC;
  470. goto give_sigill;
  471. case 9:
  472. /* Break instruction trap */
  473. handle_break(regs->iir,regs);
  474. return;
  475. case 10:
  476. /* Privileged operation trap */
  477. die_if_kernel("Privileged operation", regs, code);
  478. si.si_code = ILL_PRVOPC;
  479. goto give_sigill;
  480. case 11:
  481. /* Privileged register trap */
  482. if ((regs->iir & 0xffdfffe0) == 0x034008a0) {
  483. /* This is a MFCTL cr26/cr27 to gr instruction.
  484. * PCXS traps on this, so we need to emulate it.
  485. */
  486. if (regs->iir & 0x00200000)
  487. regs->gr[regs->iir & 0x1f] = mfctl(27);
  488. else
  489. regs->gr[regs->iir & 0x1f] = mfctl(26);
  490. regs->iaoq[0] = regs->iaoq[1];
  491. regs->iaoq[1] += 4;
  492. regs->iasq[0] = regs->iasq[1];
  493. return;
  494. }
  495. die_if_kernel("Privileged register usage", regs, code);
  496. si.si_code = ILL_PRVREG;
  497. give_sigill:
  498. si.si_signo = SIGILL;
  499. si.si_errno = 0;
  500. si.si_addr = (void __user *) regs->iaoq[0];
  501. force_sig_info(SIGILL, &si, current);
  502. return;
  503. case 12:
  504. /* Overflow Trap, let the userland signal handler do the cleanup */
  505. si.si_signo = SIGFPE;
  506. si.si_code = FPE_INTOVF;
  507. si.si_addr = (void __user *) regs->iaoq[0];
  508. force_sig_info(SIGFPE, &si, current);
  509. return;
  510. case 13:
  511. /* Conditional Trap
  512. The condition succees in an instruction which traps
  513. on condition */
  514. if(user_mode(regs)){
  515. si.si_signo = SIGFPE;
  516. /* Set to zero, and let the userspace app figure it out from
  517. the insn pointed to by si_addr */
  518. si.si_code = 0;
  519. si.si_addr = (void __user *) regs->iaoq[0];
  520. force_sig_info(SIGFPE, &si, current);
  521. return;
  522. }
  523. /* The kernel doesn't want to handle condition codes */
  524. break;
  525. case 14:
  526. /* Assist Exception Trap, i.e. floating point exception. */
  527. die_if_kernel("Floating point exception", regs, 0); /* quiet */
  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. die_if_kernel("Protection id trap", regs, code);
  613. si.si_code = SEGV_MAPERR;
  614. si.si_signo = SIGSEGV;
  615. si.si_errno = 0;
  616. if (code == 7)
  617. si.si_addr = (void __user *) regs->iaoq[0];
  618. else
  619. si.si_addr = (void __user *) regs->ior;
  620. force_sig_info(SIGSEGV, &si, current);
  621. return;
  622. case 28:
  623. /* Unaligned data reference trap */
  624. handle_unaligned(regs);
  625. return;
  626. default:
  627. if (user_mode(regs)) {
  628. #ifdef PRINT_USER_FAULTS
  629. printk(KERN_DEBUG "\nhandle_interruption() pid=%d command='%s'\n",
  630. current->pid, current->comm);
  631. show_regs(regs);
  632. #endif
  633. /* SIGBUS, for lack of a better one. */
  634. si.si_signo = SIGBUS;
  635. si.si_code = BUS_OBJERR;
  636. si.si_errno = 0;
  637. si.si_addr = (void __user *) regs->ior;
  638. force_sig_info(SIGBUS, &si, current);
  639. return;
  640. }
  641. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  642. parisc_terminate("Unexpected interruption", regs, code, 0);
  643. /* NOT REACHED */
  644. }
  645. if (user_mode(regs)) {
  646. if ((fault_space >> SPACEID_SHIFT) != (regs->sr[7] >> SPACEID_SHIFT)) {
  647. #ifdef PRINT_USER_FAULTS
  648. if (fault_space == 0)
  649. printk(KERN_DEBUG "User Fault on Kernel Space ");
  650. else
  651. printk(KERN_DEBUG "User Fault (long pointer) (fault %d) ",
  652. code);
  653. printk("pid=%d command='%s'\n", current->pid, current->comm);
  654. show_regs(regs);
  655. #endif
  656. si.si_signo = SIGSEGV;
  657. si.si_errno = 0;
  658. si.si_code = SEGV_MAPERR;
  659. si.si_addr = (void __user *) regs->ior;
  660. force_sig_info(SIGSEGV, &si, current);
  661. return;
  662. }
  663. }
  664. else {
  665. /*
  666. * The kernel should never fault on its own address space.
  667. */
  668. if (fault_space == 0)
  669. {
  670. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  671. parisc_terminate("Kernel Fault", regs, code, fault_address);
  672. }
  673. }
  674. do_page_fault(regs, code, fault_address);
  675. }
  676. int __init check_ivt(void *iva)
  677. {
  678. int i;
  679. u32 check = 0;
  680. u32 *ivap;
  681. u32 *hpmcp;
  682. u32 length;
  683. extern void os_hpmc(void);
  684. extern void os_hpmc_end(void);
  685. if (strcmp((char *)iva, "cows can fly"))
  686. return -1;
  687. ivap = (u32 *)iva;
  688. for (i = 0; i < 8; i++)
  689. *ivap++ = 0;
  690. /* Compute Checksum for HPMC handler */
  691. length = (u32)((unsigned long)os_hpmc_end - (unsigned long)os_hpmc);
  692. ivap[7] = length;
  693. hpmcp = (u32 *)os_hpmc;
  694. for (i=0; i<length/4; i++)
  695. check += *hpmcp++;
  696. for (i=0; i<8; i++)
  697. check += ivap[i];
  698. ivap[5] = -check;
  699. return 0;
  700. }
  701. #ifndef __LP64__
  702. extern const void fault_vector_11;
  703. #endif
  704. extern const void fault_vector_20;
  705. void __init trap_init(void)
  706. {
  707. void *iva;
  708. if (boot_cpu_data.cpu_type >= pcxu)
  709. iva = (void *) &fault_vector_20;
  710. else
  711. #ifdef __LP64__
  712. panic("Can't boot 64-bit OS on PA1.1 processor!");
  713. #else
  714. iva = (void *) &fault_vector_11;
  715. #endif
  716. if (check_ivt(iva))
  717. panic("IVT invalid");
  718. }