traps.c 21 KB

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