traps.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. /*
  2. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Modified by Cort Dougan (cort@cs.nmt.edu)
  10. * and Paul Mackerras (paulus@samba.org)
  11. */
  12. /*
  13. * This file handles the architecture-dependent parts of hardware exceptions
  14. */
  15. #include <linux/errno.h>
  16. #include <linux/sched.h>
  17. #include <linux/kernel.h>
  18. #include <linux/mm.h>
  19. #include <linux/stddef.h>
  20. #include <linux/unistd.h>
  21. #include <linux/ptrace.h>
  22. #include <linux/slab.h>
  23. #include <linux/user.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/prctl.h>
  28. #include <linux/delay.h>
  29. #include <linux/kprobes.h>
  30. #include <linux/kexec.h>
  31. #include <linux/backlight.h>
  32. #include <linux/bug.h>
  33. #include <linux/kdebug.h>
  34. #include <linux/debugfs.h>
  35. #include <asm/emulated_ops.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/uaccess.h>
  38. #include <asm/system.h>
  39. #include <asm/io.h>
  40. #include <asm/machdep.h>
  41. #include <asm/rtas.h>
  42. #include <asm/pmc.h>
  43. #ifdef CONFIG_PPC32
  44. #include <asm/reg.h>
  45. #endif
  46. #ifdef CONFIG_PMAC_BACKLIGHT
  47. #include <asm/backlight.h>
  48. #endif
  49. #ifdef CONFIG_PPC64
  50. #include <asm/firmware.h>
  51. #include <asm/processor.h>
  52. #endif
  53. #include <asm/kexec.h>
  54. #include <asm/ppc-opcode.h>
  55. #ifdef CONFIG_FSL_BOOKE
  56. #include <asm/dbell.h>
  57. #endif
  58. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  59. int (*__debugger)(struct pt_regs *regs);
  60. int (*__debugger_ipi)(struct pt_regs *regs);
  61. int (*__debugger_bpt)(struct pt_regs *regs);
  62. int (*__debugger_sstep)(struct pt_regs *regs);
  63. int (*__debugger_iabr_match)(struct pt_regs *regs);
  64. int (*__debugger_dabr_match)(struct pt_regs *regs);
  65. int (*__debugger_fault_handler)(struct pt_regs *regs);
  66. EXPORT_SYMBOL(__debugger);
  67. EXPORT_SYMBOL(__debugger_ipi);
  68. EXPORT_SYMBOL(__debugger_bpt);
  69. EXPORT_SYMBOL(__debugger_sstep);
  70. EXPORT_SYMBOL(__debugger_iabr_match);
  71. EXPORT_SYMBOL(__debugger_dabr_match);
  72. EXPORT_SYMBOL(__debugger_fault_handler);
  73. #endif
  74. /*
  75. * Trap & Exception support
  76. */
  77. #ifdef CONFIG_PMAC_BACKLIGHT
  78. static void pmac_backlight_unblank(void)
  79. {
  80. mutex_lock(&pmac_backlight_mutex);
  81. if (pmac_backlight) {
  82. struct backlight_properties *props;
  83. props = &pmac_backlight->props;
  84. props->brightness = props->max_brightness;
  85. props->power = FB_BLANK_UNBLANK;
  86. backlight_update_status(pmac_backlight);
  87. }
  88. mutex_unlock(&pmac_backlight_mutex);
  89. }
  90. #else
  91. static inline void pmac_backlight_unblank(void) { }
  92. #endif
  93. int die(const char *str, struct pt_regs *regs, long err)
  94. {
  95. static struct {
  96. spinlock_t lock;
  97. u32 lock_owner;
  98. int lock_owner_depth;
  99. } die = {
  100. .lock = __SPIN_LOCK_UNLOCKED(die.lock),
  101. .lock_owner = -1,
  102. .lock_owner_depth = 0
  103. };
  104. static int die_counter;
  105. unsigned long flags;
  106. if (debugger(regs))
  107. return 1;
  108. oops_enter();
  109. if (die.lock_owner != raw_smp_processor_id()) {
  110. console_verbose();
  111. spin_lock_irqsave(&die.lock, flags);
  112. die.lock_owner = smp_processor_id();
  113. die.lock_owner_depth = 0;
  114. bust_spinlocks(1);
  115. if (machine_is(powermac))
  116. pmac_backlight_unblank();
  117. } else {
  118. local_save_flags(flags);
  119. }
  120. if (++die.lock_owner_depth < 3) {
  121. printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
  122. #ifdef CONFIG_PREEMPT
  123. printk("PREEMPT ");
  124. #endif
  125. #ifdef CONFIG_SMP
  126. printk("SMP NR_CPUS=%d ", NR_CPUS);
  127. #endif
  128. #ifdef CONFIG_DEBUG_PAGEALLOC
  129. printk("DEBUG_PAGEALLOC ");
  130. #endif
  131. #ifdef CONFIG_NUMA
  132. printk("NUMA ");
  133. #endif
  134. printk("%s\n", ppc_md.name ? ppc_md.name : "");
  135. print_modules();
  136. show_regs(regs);
  137. } else {
  138. printk("Recursive die() failure, output suppressed\n");
  139. }
  140. bust_spinlocks(0);
  141. die.lock_owner = -1;
  142. add_taint(TAINT_DIE);
  143. spin_unlock_irqrestore(&die.lock, flags);
  144. if (kexec_should_crash(current) ||
  145. kexec_sr_activated(smp_processor_id()))
  146. crash_kexec(regs);
  147. crash_kexec_secondary(regs);
  148. if (in_interrupt())
  149. panic("Fatal exception in interrupt");
  150. if (panic_on_oops)
  151. panic("Fatal exception");
  152. oops_exit();
  153. do_exit(err);
  154. return 0;
  155. }
  156. void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
  157. {
  158. siginfo_t info;
  159. const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \
  160. "at %08lx nip %08lx lr %08lx code %x\n";
  161. const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \
  162. "at %016lx nip %016lx lr %016lx code %x\n";
  163. if (!user_mode(regs)) {
  164. if (die("Exception in kernel mode", regs, signr))
  165. return;
  166. } else if (show_unhandled_signals &&
  167. unhandled_signal(current, signr) &&
  168. printk_ratelimit()) {
  169. printk(regs->msr & MSR_SF ? fmt64 : fmt32,
  170. current->comm, current->pid, signr,
  171. addr, regs->nip, regs->link, code);
  172. }
  173. memset(&info, 0, sizeof(info));
  174. info.si_signo = signr;
  175. info.si_code = code;
  176. info.si_addr = (void __user *) addr;
  177. force_sig_info(signr, &info, current);
  178. /*
  179. * Init gets no signals that it doesn't have a handler for.
  180. * That's all very well, but if it has caused a synchronous
  181. * exception and we ignore the resulting signal, it will just
  182. * generate the same exception over and over again and we get
  183. * nowhere. Better to kill it and let the kernel panic.
  184. */
  185. if (is_global_init(current)) {
  186. __sighandler_t handler;
  187. spin_lock_irq(&current->sighand->siglock);
  188. handler = current->sighand->action[signr-1].sa.sa_handler;
  189. spin_unlock_irq(&current->sighand->siglock);
  190. if (handler == SIG_DFL) {
  191. /* init has generated a synchronous exception
  192. and it doesn't have a handler for the signal */
  193. printk(KERN_CRIT "init has generated signal %d "
  194. "but has no handler for it\n", signr);
  195. do_exit(signr);
  196. }
  197. }
  198. }
  199. #ifdef CONFIG_PPC64
  200. void system_reset_exception(struct pt_regs *regs)
  201. {
  202. /* See if any machine dependent calls */
  203. if (ppc_md.system_reset_exception) {
  204. if (ppc_md.system_reset_exception(regs))
  205. return;
  206. }
  207. #ifdef CONFIG_KEXEC
  208. cpu_set(smp_processor_id(), cpus_in_sr);
  209. #endif
  210. die("System Reset", regs, SIGABRT);
  211. /*
  212. * Some CPUs when released from the debugger will execute this path.
  213. * These CPUs entered the debugger via a soft-reset. If the CPU was
  214. * hung before entering the debugger it will return to the hung
  215. * state when exiting this function. This causes a problem in
  216. * kdump since the hung CPU(s) will not respond to the IPI sent
  217. * from kdump. To prevent the problem we call crash_kexec_secondary()
  218. * here. If a kdump had not been initiated or we exit the debugger
  219. * with the "exit and recover" command (x) crash_kexec_secondary()
  220. * will return after 5ms and the CPU returns to its previous state.
  221. */
  222. crash_kexec_secondary(regs);
  223. /* Must die if the interrupt is not recoverable */
  224. if (!(regs->msr & MSR_RI))
  225. panic("Unrecoverable System Reset");
  226. /* What should we do here? We could issue a shutdown or hard reset. */
  227. }
  228. #endif
  229. /*
  230. * I/O accesses can cause machine checks on powermacs.
  231. * Check if the NIP corresponds to the address of a sync
  232. * instruction for which there is an entry in the exception
  233. * table.
  234. * Note that the 601 only takes a machine check on TEA
  235. * (transfer error ack) signal assertion, and does not
  236. * set any of the top 16 bits of SRR1.
  237. * -- paulus.
  238. */
  239. static inline int check_io_access(struct pt_regs *regs)
  240. {
  241. #ifdef CONFIG_PPC32
  242. unsigned long msr = regs->msr;
  243. const struct exception_table_entry *entry;
  244. unsigned int *nip = (unsigned int *)regs->nip;
  245. if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
  246. && (entry = search_exception_tables(regs->nip)) != NULL) {
  247. /*
  248. * Check that it's a sync instruction, or somewhere
  249. * in the twi; isync; nop sequence that inb/inw/inl uses.
  250. * As the address is in the exception table
  251. * we should be able to read the instr there.
  252. * For the debug message, we look at the preceding
  253. * load or store.
  254. */
  255. if (*nip == 0x60000000) /* nop */
  256. nip -= 2;
  257. else if (*nip == 0x4c00012c) /* isync */
  258. --nip;
  259. if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {
  260. /* sync or twi */
  261. unsigned int rb;
  262. --nip;
  263. rb = (*nip >> 11) & 0x1f;
  264. printk(KERN_DEBUG "%s bad port %lx at %p\n",
  265. (*nip & 0x100)? "OUT to": "IN from",
  266. regs->gpr[rb] - _IO_BASE, nip);
  267. regs->msr |= MSR_RI;
  268. regs->nip = entry->fixup;
  269. return 1;
  270. }
  271. }
  272. #endif /* CONFIG_PPC32 */
  273. return 0;
  274. }
  275. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  276. /* On 4xx, the reason for the machine check or program exception
  277. is in the ESR. */
  278. #define get_reason(regs) ((regs)->dsisr)
  279. #ifndef CONFIG_FSL_BOOKE
  280. #define get_mc_reason(regs) ((regs)->dsisr)
  281. #else
  282. #define get_mc_reason(regs) (mfspr(SPRN_MCSR) & MCSR_MASK)
  283. #endif
  284. #define REASON_FP ESR_FP
  285. #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
  286. #define REASON_PRIVILEGED ESR_PPR
  287. #define REASON_TRAP ESR_PTR
  288. /* single-step stuff */
  289. #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC)
  290. #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
  291. #else
  292. /* On non-4xx, the reason for the machine check or program
  293. exception is in the MSR. */
  294. #define get_reason(regs) ((regs)->msr)
  295. #define get_mc_reason(regs) ((regs)->msr)
  296. #define REASON_FP 0x100000
  297. #define REASON_ILLEGAL 0x80000
  298. #define REASON_PRIVILEGED 0x40000
  299. #define REASON_TRAP 0x20000
  300. #define single_stepping(regs) ((regs)->msr & MSR_SE)
  301. #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
  302. #endif
  303. #if defined(CONFIG_4xx)
  304. int machine_check_4xx(struct pt_regs *regs)
  305. {
  306. unsigned long reason = get_mc_reason(regs);
  307. if (reason & ESR_IMCP) {
  308. printk("Instruction");
  309. mtspr(SPRN_ESR, reason & ~ESR_IMCP);
  310. } else
  311. printk("Data");
  312. printk(" machine check in kernel mode.\n");
  313. return 0;
  314. }
  315. int machine_check_440A(struct pt_regs *regs)
  316. {
  317. unsigned long reason = get_mc_reason(regs);
  318. printk("Machine check in kernel mode.\n");
  319. if (reason & ESR_IMCP){
  320. printk("Instruction Synchronous Machine Check exception\n");
  321. mtspr(SPRN_ESR, reason & ~ESR_IMCP);
  322. }
  323. else {
  324. u32 mcsr = mfspr(SPRN_MCSR);
  325. if (mcsr & MCSR_IB)
  326. printk("Instruction Read PLB Error\n");
  327. if (mcsr & MCSR_DRB)
  328. printk("Data Read PLB Error\n");
  329. if (mcsr & MCSR_DWB)
  330. printk("Data Write PLB Error\n");
  331. if (mcsr & MCSR_TLBP)
  332. printk("TLB Parity Error\n");
  333. if (mcsr & MCSR_ICP){
  334. flush_instruction_cache();
  335. printk("I-Cache Parity Error\n");
  336. }
  337. if (mcsr & MCSR_DCSP)
  338. printk("D-Cache Search Parity Error\n");
  339. if (mcsr & MCSR_DCFP)
  340. printk("D-Cache Flush Parity Error\n");
  341. if (mcsr & MCSR_IMPE)
  342. printk("Machine Check exception is imprecise\n");
  343. /* Clear MCSR */
  344. mtspr(SPRN_MCSR, mcsr);
  345. }
  346. return 0;
  347. }
  348. #elif defined(CONFIG_E500)
  349. int machine_check_e500(struct pt_regs *regs)
  350. {
  351. unsigned long reason = get_mc_reason(regs);
  352. printk("Machine check in kernel mode.\n");
  353. printk("Caused by (from MCSR=%lx): ", reason);
  354. if (reason & MCSR_MCP)
  355. printk("Machine Check Signal\n");
  356. if (reason & MCSR_ICPERR)
  357. printk("Instruction Cache Parity Error\n");
  358. if (reason & MCSR_DCP_PERR)
  359. printk("Data Cache Push Parity Error\n");
  360. if (reason & MCSR_DCPERR)
  361. printk("Data Cache Parity Error\n");
  362. if (reason & MCSR_BUS_IAERR)
  363. printk("Bus - Instruction Address Error\n");
  364. if (reason & MCSR_BUS_RAERR)
  365. printk("Bus - Read Address Error\n");
  366. if (reason & MCSR_BUS_WAERR)
  367. printk("Bus - Write Address Error\n");
  368. if (reason & MCSR_BUS_IBERR)
  369. printk("Bus - Instruction Data Error\n");
  370. if (reason & MCSR_BUS_RBERR)
  371. printk("Bus - Read Data Bus Error\n");
  372. if (reason & MCSR_BUS_WBERR)
  373. printk("Bus - Read Data Bus Error\n");
  374. if (reason & MCSR_BUS_IPERR)
  375. printk("Bus - Instruction Parity Error\n");
  376. if (reason & MCSR_BUS_RPERR)
  377. printk("Bus - Read Parity Error\n");
  378. return 0;
  379. }
  380. #elif defined(CONFIG_E200)
  381. int machine_check_e200(struct pt_regs *regs)
  382. {
  383. unsigned long reason = get_mc_reason(regs);
  384. printk("Machine check in kernel mode.\n");
  385. printk("Caused by (from MCSR=%lx): ", reason);
  386. if (reason & MCSR_MCP)
  387. printk("Machine Check Signal\n");
  388. if (reason & MCSR_CP_PERR)
  389. printk("Cache Push Parity Error\n");
  390. if (reason & MCSR_CPERR)
  391. printk("Cache Parity Error\n");
  392. if (reason & MCSR_EXCP_ERR)
  393. printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
  394. if (reason & MCSR_BUS_IRERR)
  395. printk("Bus - Read Bus Error on instruction fetch\n");
  396. if (reason & MCSR_BUS_DRERR)
  397. printk("Bus - Read Bus Error on data load\n");
  398. if (reason & MCSR_BUS_WRERR)
  399. printk("Bus - Write Bus Error on buffered store or cache line push\n");
  400. return 0;
  401. }
  402. #else
  403. int machine_check_generic(struct pt_regs *regs)
  404. {
  405. unsigned long reason = get_mc_reason(regs);
  406. printk("Machine check in kernel mode.\n");
  407. printk("Caused by (from SRR1=%lx): ", reason);
  408. switch (reason & 0x601F0000) {
  409. case 0x80000:
  410. printk("Machine check signal\n");
  411. break;
  412. case 0: /* for 601 */
  413. case 0x40000:
  414. case 0x140000: /* 7450 MSS error and TEA */
  415. printk("Transfer error ack signal\n");
  416. break;
  417. case 0x20000:
  418. printk("Data parity error signal\n");
  419. break;
  420. case 0x10000:
  421. printk("Address parity error signal\n");
  422. break;
  423. case 0x20000000:
  424. printk("L1 Data Cache error\n");
  425. break;
  426. case 0x40000000:
  427. printk("L1 Instruction Cache error\n");
  428. break;
  429. case 0x00100000:
  430. printk("L2 data cache parity error\n");
  431. break;
  432. default:
  433. printk("Unknown values in msr\n");
  434. }
  435. return 0;
  436. }
  437. #endif /* everything else */
  438. void machine_check_exception(struct pt_regs *regs)
  439. {
  440. int recover = 0;
  441. /* See if any machine dependent calls. In theory, we would want
  442. * to call the CPU first, and call the ppc_md. one if the CPU
  443. * one returns a positive number. However there is existing code
  444. * that assumes the board gets a first chance, so let's keep it
  445. * that way for now and fix things later. --BenH.
  446. */
  447. if (ppc_md.machine_check_exception)
  448. recover = ppc_md.machine_check_exception(regs);
  449. else if (cur_cpu_spec->machine_check)
  450. recover = cur_cpu_spec->machine_check(regs);
  451. if (recover > 0)
  452. return;
  453. if (user_mode(regs)) {
  454. regs->msr |= MSR_RI;
  455. _exception(SIGBUS, regs, BUS_ADRERR, regs->nip);
  456. return;
  457. }
  458. #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
  459. /* the qspan pci read routines can cause machine checks -- Cort
  460. *
  461. * yuck !!! that totally needs to go away ! There are better ways
  462. * to deal with that than having a wart in the mcheck handler.
  463. * -- BenH
  464. */
  465. bad_page_fault(regs, regs->dar, SIGBUS);
  466. return;
  467. #endif
  468. if (debugger_fault_handler(regs)) {
  469. regs->msr |= MSR_RI;
  470. return;
  471. }
  472. if (check_io_access(regs))
  473. return;
  474. if (debugger_fault_handler(regs))
  475. return;
  476. die("Machine check", regs, SIGBUS);
  477. /* Must die if the interrupt is not recoverable */
  478. if (!(regs->msr & MSR_RI))
  479. panic("Unrecoverable Machine check");
  480. }
  481. void SMIException(struct pt_regs *regs)
  482. {
  483. die("System Management Interrupt", regs, SIGABRT);
  484. }
  485. void unknown_exception(struct pt_regs *regs)
  486. {
  487. printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  488. regs->nip, regs->msr, regs->trap);
  489. _exception(SIGTRAP, regs, 0, 0);
  490. }
  491. void instruction_breakpoint_exception(struct pt_regs *regs)
  492. {
  493. if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5,
  494. 5, SIGTRAP) == NOTIFY_STOP)
  495. return;
  496. if (debugger_iabr_match(regs))
  497. return;
  498. _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
  499. }
  500. void RunModeException(struct pt_regs *regs)
  501. {
  502. _exception(SIGTRAP, regs, 0, 0);
  503. }
  504. void __kprobes single_step_exception(struct pt_regs *regs)
  505. {
  506. regs->msr &= ~(MSR_SE | MSR_BE); /* Turn off 'trace' bits */
  507. if (notify_die(DIE_SSTEP, "single_step", regs, 5,
  508. 5, SIGTRAP) == NOTIFY_STOP)
  509. return;
  510. if (debugger_sstep(regs))
  511. return;
  512. _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
  513. }
  514. /*
  515. * After we have successfully emulated an instruction, we have to
  516. * check if the instruction was being single-stepped, and if so,
  517. * pretend we got a single-step exception. This was pointed out
  518. * by Kumar Gala. -- paulus
  519. */
  520. static void emulate_single_step(struct pt_regs *regs)
  521. {
  522. if (single_stepping(regs)) {
  523. clear_single_step(regs);
  524. _exception(SIGTRAP, regs, TRAP_TRACE, 0);
  525. }
  526. }
  527. static inline int __parse_fpscr(unsigned long fpscr)
  528. {
  529. int ret = 0;
  530. /* Invalid operation */
  531. if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
  532. ret = FPE_FLTINV;
  533. /* Overflow */
  534. else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX))
  535. ret = FPE_FLTOVF;
  536. /* Underflow */
  537. else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX))
  538. ret = FPE_FLTUND;
  539. /* Divide by zero */
  540. else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX))
  541. ret = FPE_FLTDIV;
  542. /* Inexact result */
  543. else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX))
  544. ret = FPE_FLTRES;
  545. return ret;
  546. }
  547. static void parse_fpe(struct pt_regs *regs)
  548. {
  549. int code = 0;
  550. flush_fp_to_thread(current);
  551. code = __parse_fpscr(current->thread.fpscr.val);
  552. _exception(SIGFPE, regs, code, regs->nip);
  553. }
  554. /*
  555. * Illegal instruction emulation support. Originally written to
  556. * provide the PVR to user applications using the mfspr rd, PVR.
  557. * Return non-zero if we can't emulate, or -EFAULT if the associated
  558. * memory access caused an access fault. Return zero on success.
  559. *
  560. * There are a couple of ways to do this, either "decode" the instruction
  561. * or directly match lots of bits. In this case, matching lots of
  562. * bits is faster and easier.
  563. *
  564. */
  565. static int emulate_string_inst(struct pt_regs *regs, u32 instword)
  566. {
  567. u8 rT = (instword >> 21) & 0x1f;
  568. u8 rA = (instword >> 16) & 0x1f;
  569. u8 NB_RB = (instword >> 11) & 0x1f;
  570. u32 num_bytes;
  571. unsigned long EA;
  572. int pos = 0;
  573. /* Early out if we are an invalid form of lswx */
  574. if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX)
  575. if ((rT == rA) || (rT == NB_RB))
  576. return -EINVAL;
  577. EA = (rA == 0) ? 0 : regs->gpr[rA];
  578. switch (instword & PPC_INST_STRING_MASK) {
  579. case PPC_INST_LSWX:
  580. case PPC_INST_STSWX:
  581. EA += NB_RB;
  582. num_bytes = regs->xer & 0x7f;
  583. break;
  584. case PPC_INST_LSWI:
  585. case PPC_INST_STSWI:
  586. num_bytes = (NB_RB == 0) ? 32 : NB_RB;
  587. break;
  588. default:
  589. return -EINVAL;
  590. }
  591. while (num_bytes != 0)
  592. {
  593. u8 val;
  594. u32 shift = 8 * (3 - (pos & 0x3));
  595. switch ((instword & PPC_INST_STRING_MASK)) {
  596. case PPC_INST_LSWX:
  597. case PPC_INST_LSWI:
  598. if (get_user(val, (u8 __user *)EA))
  599. return -EFAULT;
  600. /* first time updating this reg,
  601. * zero it out */
  602. if (pos == 0)
  603. regs->gpr[rT] = 0;
  604. regs->gpr[rT] |= val << shift;
  605. break;
  606. case PPC_INST_STSWI:
  607. case PPC_INST_STSWX:
  608. val = regs->gpr[rT] >> shift;
  609. if (put_user(val, (u8 __user *)EA))
  610. return -EFAULT;
  611. break;
  612. }
  613. /* move EA to next address */
  614. EA += 1;
  615. num_bytes--;
  616. /* manage our position within the register */
  617. if (++pos == 4) {
  618. pos = 0;
  619. if (++rT == 32)
  620. rT = 0;
  621. }
  622. }
  623. return 0;
  624. }
  625. static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword)
  626. {
  627. u32 ra,rs;
  628. unsigned long tmp;
  629. ra = (instword >> 16) & 0x1f;
  630. rs = (instword >> 21) & 0x1f;
  631. tmp = regs->gpr[rs];
  632. tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL);
  633. tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL);
  634. tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
  635. regs->gpr[ra] = tmp;
  636. return 0;
  637. }
  638. static int emulate_isel(struct pt_regs *regs, u32 instword)
  639. {
  640. u8 rT = (instword >> 21) & 0x1f;
  641. u8 rA = (instword >> 16) & 0x1f;
  642. u8 rB = (instword >> 11) & 0x1f;
  643. u8 BC = (instword >> 6) & 0x1f;
  644. u8 bit;
  645. unsigned long tmp;
  646. tmp = (rA == 0) ? 0 : regs->gpr[rA];
  647. bit = (regs->ccr >> (31 - BC)) & 0x1;
  648. regs->gpr[rT] = bit ? tmp : regs->gpr[rB];
  649. return 0;
  650. }
  651. static int emulate_instruction(struct pt_regs *regs)
  652. {
  653. u32 instword;
  654. u32 rd;
  655. if (!user_mode(regs) || (regs->msr & MSR_LE))
  656. return -EINVAL;
  657. CHECK_FULL_REGS(regs);
  658. if (get_user(instword, (u32 __user *)(regs->nip)))
  659. return -EFAULT;
  660. /* Emulate the mfspr rD, PVR. */
  661. if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) {
  662. PPC_WARN_EMULATED(mfpvr);
  663. rd = (instword >> 21) & 0x1f;
  664. regs->gpr[rd] = mfspr(SPRN_PVR);
  665. return 0;
  666. }
  667. /* Emulating the dcba insn is just a no-op. */
  668. if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) {
  669. PPC_WARN_EMULATED(dcba);
  670. return 0;
  671. }
  672. /* Emulate the mcrxr insn. */
  673. if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) {
  674. int shift = (instword >> 21) & 0x1c;
  675. unsigned long msk = 0xf0000000UL >> shift;
  676. PPC_WARN_EMULATED(mcrxr);
  677. regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
  678. regs->xer &= ~0xf0000000UL;
  679. return 0;
  680. }
  681. /* Emulate load/store string insn. */
  682. if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) {
  683. PPC_WARN_EMULATED(string);
  684. return emulate_string_inst(regs, instword);
  685. }
  686. /* Emulate the popcntb (Population Count Bytes) instruction. */
  687. if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) {
  688. PPC_WARN_EMULATED(popcntb);
  689. return emulate_popcntb_inst(regs, instword);
  690. }
  691. /* Emulate isel (Integer Select) instruction */
  692. if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) {
  693. PPC_WARN_EMULATED(isel);
  694. return emulate_isel(regs, instword);
  695. }
  696. return -EINVAL;
  697. }
  698. int is_valid_bugaddr(unsigned long addr)
  699. {
  700. return is_kernel_addr(addr);
  701. }
  702. void __kprobes program_check_exception(struct pt_regs *regs)
  703. {
  704. unsigned int reason = get_reason(regs);
  705. extern int do_mathemu(struct pt_regs *regs);
  706. /* We can now get here via a FP Unavailable exception if the core
  707. * has no FPU, in that case the reason flags will be 0 */
  708. if (reason & REASON_FP) {
  709. /* IEEE FP exception */
  710. parse_fpe(regs);
  711. return;
  712. }
  713. if (reason & REASON_TRAP) {
  714. /* trap exception */
  715. if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
  716. == NOTIFY_STOP)
  717. return;
  718. if (debugger_bpt(regs))
  719. return;
  720. if (!(regs->msr & MSR_PR) && /* not user-mode */
  721. report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
  722. regs->nip += 4;
  723. return;
  724. }
  725. _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
  726. return;
  727. }
  728. local_irq_enable();
  729. #ifdef CONFIG_MATH_EMULATION
  730. /* (reason & REASON_ILLEGAL) would be the obvious thing here,
  731. * but there seems to be a hardware bug on the 405GP (RevD)
  732. * that means ESR is sometimes set incorrectly - either to
  733. * ESR_DST (!?) or 0. In the process of chasing this with the
  734. * hardware people - not sure if it can happen on any illegal
  735. * instruction or only on FP instructions, whether there is a
  736. * pattern to occurences etc. -dgibson 31/Mar/2003 */
  737. switch (do_mathemu(regs)) {
  738. case 0:
  739. emulate_single_step(regs);
  740. return;
  741. case 1: {
  742. int code = 0;
  743. code = __parse_fpscr(current->thread.fpscr.val);
  744. _exception(SIGFPE, regs, code, regs->nip);
  745. return;
  746. }
  747. case -EFAULT:
  748. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  749. return;
  750. }
  751. /* fall through on any other errors */
  752. #endif /* CONFIG_MATH_EMULATION */
  753. /* Try to emulate it if we should. */
  754. if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
  755. switch (emulate_instruction(regs)) {
  756. case 0:
  757. regs->nip += 4;
  758. emulate_single_step(regs);
  759. return;
  760. case -EFAULT:
  761. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  762. return;
  763. }
  764. }
  765. if (reason & REASON_PRIVILEGED)
  766. _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
  767. else
  768. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  769. }
  770. void alignment_exception(struct pt_regs *regs)
  771. {
  772. int sig, code, fixed = 0;
  773. /* we don't implement logging of alignment exceptions */
  774. if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS))
  775. fixed = fix_alignment(regs);
  776. if (fixed == 1) {
  777. regs->nip += 4; /* skip over emulated instruction */
  778. emulate_single_step(regs);
  779. return;
  780. }
  781. /* Operand address was bad */
  782. if (fixed == -EFAULT) {
  783. sig = SIGSEGV;
  784. code = SEGV_ACCERR;
  785. } else {
  786. sig = SIGBUS;
  787. code = BUS_ADRALN;
  788. }
  789. if (user_mode(regs))
  790. _exception(sig, regs, code, regs->dar);
  791. else
  792. bad_page_fault(regs, regs->dar, sig);
  793. }
  794. void StackOverflow(struct pt_regs *regs)
  795. {
  796. printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
  797. current, regs->gpr[1]);
  798. debugger(regs);
  799. show_regs(regs);
  800. panic("kernel stack overflow");
  801. }
  802. void nonrecoverable_exception(struct pt_regs *regs)
  803. {
  804. printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
  805. regs->nip, regs->msr);
  806. debugger(regs);
  807. die("nonrecoverable exception", regs, SIGKILL);
  808. }
  809. void trace_syscall(struct pt_regs *regs)
  810. {
  811. printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
  812. current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
  813. regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
  814. }
  815. void kernel_fp_unavailable_exception(struct pt_regs *regs)
  816. {
  817. printk(KERN_EMERG "Unrecoverable FP Unavailable Exception "
  818. "%lx at %lx\n", regs->trap, regs->nip);
  819. die("Unrecoverable FP Unavailable Exception", regs, SIGABRT);
  820. }
  821. void altivec_unavailable_exception(struct pt_regs *regs)
  822. {
  823. if (user_mode(regs)) {
  824. /* A user program has executed an altivec instruction,
  825. but this kernel doesn't support altivec. */
  826. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  827. return;
  828. }
  829. printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception "
  830. "%lx at %lx\n", regs->trap, regs->nip);
  831. die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT);
  832. }
  833. void vsx_unavailable_exception(struct pt_regs *regs)
  834. {
  835. if (user_mode(regs)) {
  836. /* A user program has executed an vsx instruction,
  837. but this kernel doesn't support vsx. */
  838. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  839. return;
  840. }
  841. printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception "
  842. "%lx at %lx\n", regs->trap, regs->nip);
  843. die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT);
  844. }
  845. void performance_monitor_exception(struct pt_regs *regs)
  846. {
  847. perf_irq(regs);
  848. }
  849. #ifdef CONFIG_8xx
  850. void SoftwareEmulation(struct pt_regs *regs)
  851. {
  852. extern int do_mathemu(struct pt_regs *);
  853. extern int Soft_emulate_8xx(struct pt_regs *);
  854. #if defined(CONFIG_MATH_EMULATION) || defined(CONFIG_8XX_MINIMAL_FPEMU)
  855. int errcode;
  856. #endif
  857. CHECK_FULL_REGS(regs);
  858. if (!user_mode(regs)) {
  859. debugger(regs);
  860. die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
  861. }
  862. #ifdef CONFIG_MATH_EMULATION
  863. errcode = do_mathemu(regs);
  864. if (errcode >= 0)
  865. PPC_WARN_EMULATED(math);
  866. switch (errcode) {
  867. case 0:
  868. emulate_single_step(regs);
  869. return;
  870. case 1: {
  871. int code = 0;
  872. code = __parse_fpscr(current->thread.fpscr.val);
  873. _exception(SIGFPE, regs, code, regs->nip);
  874. return;
  875. }
  876. case -EFAULT:
  877. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  878. return;
  879. default:
  880. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  881. return;
  882. }
  883. #elif defined(CONFIG_8XX_MINIMAL_FPEMU)
  884. errcode = Soft_emulate_8xx(regs);
  885. if (errcode >= 0)
  886. PPC_WARN_EMULATED(8xx);
  887. switch (errcode) {
  888. case 0:
  889. emulate_single_step(regs);
  890. return;
  891. case 1:
  892. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  893. return;
  894. case -EFAULT:
  895. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  896. return;
  897. }
  898. #else
  899. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  900. #endif
  901. }
  902. #endif /* CONFIG_8xx */
  903. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  904. void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)
  905. {
  906. if (debug_status & DBSR_IC) { /* instruction completion */
  907. regs->msr &= ~MSR_DE;
  908. /* Disable instruction completion */
  909. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);
  910. /* Clear the instruction completion event */
  911. mtspr(SPRN_DBSR, DBSR_IC);
  912. if (notify_die(DIE_SSTEP, "single_step", regs, 5,
  913. 5, SIGTRAP) == NOTIFY_STOP) {
  914. return;
  915. }
  916. if (debugger_sstep(regs))
  917. return;
  918. if (user_mode(regs)) {
  919. current->thread.dbcr0 &= ~DBCR0_IC;
  920. }
  921. _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
  922. } else if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) {
  923. regs->msr &= ~MSR_DE;
  924. if (user_mode(regs)) {
  925. current->thread.dbcr0 &= ~(DBSR_DAC1R | DBSR_DAC1W |
  926. DBCR0_IDM);
  927. } else {
  928. /* Disable DAC interupts */
  929. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~(DBSR_DAC1R |
  930. DBSR_DAC1W | DBCR0_IDM));
  931. /* Clear the DAC event */
  932. mtspr(SPRN_DBSR, (DBSR_DAC1R | DBSR_DAC1W));
  933. }
  934. /* Setup and send the trap to the handler */
  935. do_dabr(regs, mfspr(SPRN_DAC1), debug_status);
  936. }
  937. }
  938. #endif /* CONFIG_4xx || CONFIG_BOOKE */
  939. #if !defined(CONFIG_TAU_INT)
  940. void TAUException(struct pt_regs *regs)
  941. {
  942. printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
  943. regs->nip, regs->msr, regs->trap, print_tainted());
  944. }
  945. #endif /* CONFIG_INT_TAU */
  946. #ifdef CONFIG_ALTIVEC
  947. void altivec_assist_exception(struct pt_regs *regs)
  948. {
  949. int err;
  950. if (!user_mode(regs)) {
  951. printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
  952. " at %lx\n", regs->nip);
  953. die("Kernel VMX/Altivec assist exception", regs, SIGILL);
  954. }
  955. flush_altivec_to_thread(current);
  956. PPC_WARN_EMULATED(altivec);
  957. err = emulate_altivec(regs);
  958. if (err == 0) {
  959. regs->nip += 4; /* skip emulated instruction */
  960. emulate_single_step(regs);
  961. return;
  962. }
  963. if (err == -EFAULT) {
  964. /* got an error reading the instruction */
  965. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  966. } else {
  967. /* didn't recognize the instruction */
  968. /* XXX quick hack for now: set the non-Java bit in the VSCR */
  969. if (printk_ratelimit())
  970. printk(KERN_ERR "Unrecognized altivec instruction "
  971. "in %s at %lx\n", current->comm, regs->nip);
  972. current->thread.vscr.u[3] |= 0x10000;
  973. }
  974. }
  975. #endif /* CONFIG_ALTIVEC */
  976. #ifdef CONFIG_VSX
  977. void vsx_assist_exception(struct pt_regs *regs)
  978. {
  979. if (!user_mode(regs)) {
  980. printk(KERN_EMERG "VSX assist exception in kernel mode"
  981. " at %lx\n", regs->nip);
  982. die("Kernel VSX assist exception", regs, SIGILL);
  983. }
  984. flush_vsx_to_thread(current);
  985. printk(KERN_INFO "VSX assist not supported at %lx\n", regs->nip);
  986. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  987. }
  988. #endif /* CONFIG_VSX */
  989. #ifdef CONFIG_FSL_BOOKE
  990. void doorbell_exception(struct pt_regs *regs)
  991. {
  992. #ifdef CONFIG_SMP
  993. int cpu = smp_processor_id();
  994. int msg;
  995. if (num_online_cpus() < 2)
  996. return;
  997. for (msg = 0; msg < 4; msg++)
  998. if (test_and_clear_bit(msg, &dbell_smp_message[cpu]))
  999. smp_message_recv(msg);
  1000. #else
  1001. printk(KERN_WARNING "Received doorbell on non-smp system\n");
  1002. #endif
  1003. }
  1004. void CacheLockingException(struct pt_regs *regs, unsigned long address,
  1005. unsigned long error_code)
  1006. {
  1007. /* We treat cache locking instructions from the user
  1008. * as priv ops, in the future we could try to do
  1009. * something smarter
  1010. */
  1011. if (error_code & (ESR_DLK|ESR_ILK))
  1012. _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
  1013. return;
  1014. }
  1015. #endif /* CONFIG_FSL_BOOKE */
  1016. #ifdef CONFIG_SPE
  1017. void SPEFloatingPointException(struct pt_regs *regs)
  1018. {
  1019. extern int do_spe_mathemu(struct pt_regs *regs);
  1020. unsigned long spefscr;
  1021. int fpexc_mode;
  1022. int code = 0;
  1023. int err;
  1024. preempt_disable();
  1025. if (regs->msr & MSR_SPE)
  1026. giveup_spe(current);
  1027. preempt_enable();
  1028. spefscr = current->thread.spefscr;
  1029. fpexc_mode = current->thread.fpexc_mode;
  1030. if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
  1031. code = FPE_FLTOVF;
  1032. }
  1033. else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
  1034. code = FPE_FLTUND;
  1035. }
  1036. else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
  1037. code = FPE_FLTDIV;
  1038. else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
  1039. code = FPE_FLTINV;
  1040. }
  1041. else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
  1042. code = FPE_FLTRES;
  1043. err = do_spe_mathemu(regs);
  1044. if (err == 0) {
  1045. regs->nip += 4; /* skip emulated instruction */
  1046. emulate_single_step(regs);
  1047. return;
  1048. }
  1049. if (err == -EFAULT) {
  1050. /* got an error reading the instruction */
  1051. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1052. } else if (err == -EINVAL) {
  1053. /* didn't recognize the instruction */
  1054. printk(KERN_ERR "unrecognized spe instruction "
  1055. "in %s at %lx\n", current->comm, regs->nip);
  1056. } else {
  1057. _exception(SIGFPE, regs, code, regs->nip);
  1058. }
  1059. return;
  1060. }
  1061. void SPEFloatingPointRoundException(struct pt_regs *regs)
  1062. {
  1063. extern int speround_handler(struct pt_regs *regs);
  1064. int err;
  1065. preempt_disable();
  1066. if (regs->msr & MSR_SPE)
  1067. giveup_spe(current);
  1068. preempt_enable();
  1069. regs->nip -= 4;
  1070. err = speround_handler(regs);
  1071. if (err == 0) {
  1072. regs->nip += 4; /* skip emulated instruction */
  1073. emulate_single_step(regs);
  1074. return;
  1075. }
  1076. if (err == -EFAULT) {
  1077. /* got an error reading the instruction */
  1078. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1079. } else if (err == -EINVAL) {
  1080. /* didn't recognize the instruction */
  1081. printk(KERN_ERR "unrecognized spe instruction "
  1082. "in %s at %lx\n", current->comm, regs->nip);
  1083. } else {
  1084. _exception(SIGFPE, regs, 0, regs->nip);
  1085. return;
  1086. }
  1087. }
  1088. #endif
  1089. /*
  1090. * We enter here if we get an unrecoverable exception, that is, one
  1091. * that happened at a point where the RI (recoverable interrupt) bit
  1092. * in the MSR is 0. This indicates that SRR0/1 are live, and that
  1093. * we therefore lost state by taking this exception.
  1094. */
  1095. void unrecoverable_exception(struct pt_regs *regs)
  1096. {
  1097. printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
  1098. regs->trap, regs->nip);
  1099. die("Unrecoverable exception", regs, SIGABRT);
  1100. }
  1101. #ifdef CONFIG_BOOKE_WDT
  1102. /*
  1103. * Default handler for a Watchdog exception,
  1104. * spins until a reboot occurs
  1105. */
  1106. void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
  1107. {
  1108. /* Generic WatchdogHandler, implement your own */
  1109. mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
  1110. return;
  1111. }
  1112. void WatchdogException(struct pt_regs *regs)
  1113. {
  1114. printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
  1115. WatchdogHandler(regs);
  1116. }
  1117. #endif
  1118. /*
  1119. * We enter here if we discover during exception entry that we are
  1120. * running in supervisor mode with a userspace value in the stack pointer.
  1121. */
  1122. void kernel_bad_stack(struct pt_regs *regs)
  1123. {
  1124. printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
  1125. regs->gpr[1], regs->nip);
  1126. die("Bad kernel stack pointer", regs, SIGABRT);
  1127. }
  1128. void __init trap_init(void)
  1129. {
  1130. }
  1131. #ifdef CONFIG_PPC_EMULATED_STATS
  1132. #define WARN_EMULATED_SETUP(type) .type = { .name = #type }
  1133. struct ppc_emulated ppc_emulated = {
  1134. #ifdef CONFIG_ALTIVEC
  1135. WARN_EMULATED_SETUP(altivec),
  1136. #endif
  1137. WARN_EMULATED_SETUP(dcba),
  1138. WARN_EMULATED_SETUP(dcbz),
  1139. WARN_EMULATED_SETUP(fp_pair),
  1140. WARN_EMULATED_SETUP(isel),
  1141. WARN_EMULATED_SETUP(mcrxr),
  1142. WARN_EMULATED_SETUP(mfpvr),
  1143. WARN_EMULATED_SETUP(multiple),
  1144. WARN_EMULATED_SETUP(popcntb),
  1145. WARN_EMULATED_SETUP(spe),
  1146. WARN_EMULATED_SETUP(string),
  1147. WARN_EMULATED_SETUP(unaligned),
  1148. #ifdef CONFIG_MATH_EMULATION
  1149. WARN_EMULATED_SETUP(math),
  1150. #elif defined(CONFIG_8XX_MINIMAL_FPEMU)
  1151. WARN_EMULATED_SETUP(8xx),
  1152. #endif
  1153. #ifdef CONFIG_VSX
  1154. WARN_EMULATED_SETUP(vsx),
  1155. #endif
  1156. };
  1157. u32 ppc_warn_emulated;
  1158. void ppc_warn_emulated_print(const char *type)
  1159. {
  1160. if (printk_ratelimit())
  1161. pr_warning("%s used emulated %s instruction\n", current->comm,
  1162. type);
  1163. }
  1164. static int __init ppc_warn_emulated_init(void)
  1165. {
  1166. struct dentry *dir, *d;
  1167. unsigned int i;
  1168. struct ppc_emulated_entry *entries = (void *)&ppc_emulated;
  1169. if (!powerpc_debugfs_root)
  1170. return -ENODEV;
  1171. dir = debugfs_create_dir("emulated_instructions",
  1172. powerpc_debugfs_root);
  1173. if (!dir)
  1174. return -ENOMEM;
  1175. d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir,
  1176. &ppc_warn_emulated);
  1177. if (!d)
  1178. goto fail;
  1179. for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) {
  1180. d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir,
  1181. (u32 *)&entries[i].val.counter);
  1182. if (!d)
  1183. goto fail;
  1184. }
  1185. return 0;
  1186. fail:
  1187. debugfs_remove_recursive(dir);
  1188. return -ENOMEM;
  1189. }
  1190. device_initcall(ppc_warn_emulated_init);
  1191. #endif /* CONFIG_PPC_EMULATED_STATS */