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