traps.c 20 KB

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