traps.c 21 KB

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