traps.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  1. /*
  2. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  3. * Copyright 2007-2010 Freescale Semiconductor, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. *
  10. * Modified by Cort Dougan (cort@cs.nmt.edu)
  11. * and Paul Mackerras (paulus@samba.org)
  12. */
  13. /*
  14. * This file handles the architecture-dependent parts of hardware exceptions
  15. */
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/stddef.h>
  21. #include <linux/unistd.h>
  22. #include <linux/ptrace.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 <linux/ratelimit.h>
  36. #include <linux/context_tracking.h>
  37. #include <asm/emulated_ops.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/io.h>
  41. #include <asm/machdep.h>
  42. #include <asm/rtas.h>
  43. #include <asm/pmc.h>
  44. #ifdef CONFIG_PPC32
  45. #include <asm/reg.h>
  46. #endif
  47. #ifdef CONFIG_PMAC_BACKLIGHT
  48. #include <asm/backlight.h>
  49. #endif
  50. #ifdef CONFIG_PPC64
  51. #include <asm/firmware.h>
  52. #include <asm/processor.h>
  53. #include <asm/tm.h>
  54. #endif
  55. #include <asm/kexec.h>
  56. #include <asm/ppc-opcode.h>
  57. #include <asm/rio.h>
  58. #include <asm/fadump.h>
  59. #include <asm/switch_to.h>
  60. #include <asm/tm.h>
  61. #include <asm/debug.h>
  62. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  63. int (*__debugger)(struct pt_regs *regs) __read_mostly;
  64. int (*__debugger_ipi)(struct pt_regs *regs) __read_mostly;
  65. int (*__debugger_bpt)(struct pt_regs *regs) __read_mostly;
  66. int (*__debugger_sstep)(struct pt_regs *regs) __read_mostly;
  67. int (*__debugger_iabr_match)(struct pt_regs *regs) __read_mostly;
  68. int (*__debugger_break_match)(struct pt_regs *regs) __read_mostly;
  69. int (*__debugger_fault_handler)(struct pt_regs *regs) __read_mostly;
  70. EXPORT_SYMBOL(__debugger);
  71. EXPORT_SYMBOL(__debugger_ipi);
  72. EXPORT_SYMBOL(__debugger_bpt);
  73. EXPORT_SYMBOL(__debugger_sstep);
  74. EXPORT_SYMBOL(__debugger_iabr_match);
  75. EXPORT_SYMBOL(__debugger_break_match);
  76. EXPORT_SYMBOL(__debugger_fault_handler);
  77. #endif
  78. /* Transactional Memory trap debug */
  79. #ifdef TM_DEBUG_SW
  80. #define TM_DEBUG(x...) printk(KERN_INFO x)
  81. #else
  82. #define TM_DEBUG(x...) do { } while(0)
  83. #endif
  84. /*
  85. * Trap & Exception support
  86. */
  87. #ifdef CONFIG_PMAC_BACKLIGHT
  88. static void pmac_backlight_unblank(void)
  89. {
  90. mutex_lock(&pmac_backlight_mutex);
  91. if (pmac_backlight) {
  92. struct backlight_properties *props;
  93. props = &pmac_backlight->props;
  94. props->brightness = props->max_brightness;
  95. props->power = FB_BLANK_UNBLANK;
  96. backlight_update_status(pmac_backlight);
  97. }
  98. mutex_unlock(&pmac_backlight_mutex);
  99. }
  100. #else
  101. static inline void pmac_backlight_unblank(void) { }
  102. #endif
  103. static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
  104. static int die_owner = -1;
  105. static unsigned int die_nest_count;
  106. static int die_counter;
  107. static unsigned __kprobes long oops_begin(struct pt_regs *regs)
  108. {
  109. int cpu;
  110. unsigned long flags;
  111. if (debugger(regs))
  112. return 1;
  113. oops_enter();
  114. /* racy, but better than risking deadlock. */
  115. raw_local_irq_save(flags);
  116. cpu = smp_processor_id();
  117. if (!arch_spin_trylock(&die_lock)) {
  118. if (cpu == die_owner)
  119. /* nested oops. should stop eventually */;
  120. else
  121. arch_spin_lock(&die_lock);
  122. }
  123. die_nest_count++;
  124. die_owner = cpu;
  125. console_verbose();
  126. bust_spinlocks(1);
  127. if (machine_is(powermac))
  128. pmac_backlight_unblank();
  129. return flags;
  130. }
  131. static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
  132. int signr)
  133. {
  134. bust_spinlocks(0);
  135. die_owner = -1;
  136. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  137. die_nest_count--;
  138. oops_exit();
  139. printk("\n");
  140. if (!die_nest_count)
  141. /* Nest count reaches zero, release the lock. */
  142. arch_spin_unlock(&die_lock);
  143. raw_local_irq_restore(flags);
  144. crash_fadump(regs, "die oops");
  145. /*
  146. * A system reset (0x100) is a request to dump, so we always send
  147. * it through the crashdump code.
  148. */
  149. if (kexec_should_crash(current) || (TRAP(regs) == 0x100)) {
  150. crash_kexec(regs);
  151. /*
  152. * We aren't the primary crash CPU. We need to send it
  153. * to a holding pattern to avoid it ending up in the panic
  154. * code.
  155. */
  156. crash_kexec_secondary(regs);
  157. }
  158. if (!signr)
  159. return;
  160. /*
  161. * While our oops output is serialised by a spinlock, output
  162. * from panic() called below can race and corrupt it. If we
  163. * know we are going to panic, delay for 1 second so we have a
  164. * chance to get clean backtraces from all CPUs that are oopsing.
  165. */
  166. if (in_interrupt() || panic_on_oops || !current->pid ||
  167. is_global_init(current)) {
  168. mdelay(MSEC_PER_SEC);
  169. }
  170. if (in_interrupt())
  171. panic("Fatal exception in interrupt");
  172. if (panic_on_oops)
  173. panic("Fatal exception");
  174. do_exit(signr);
  175. }
  176. static int __kprobes __die(const char *str, struct pt_regs *regs, long err)
  177. {
  178. printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
  179. #ifdef CONFIG_PREEMPT
  180. printk("PREEMPT ");
  181. #endif
  182. #ifdef CONFIG_SMP
  183. printk("SMP NR_CPUS=%d ", NR_CPUS);
  184. #endif
  185. #ifdef CONFIG_DEBUG_PAGEALLOC
  186. printk("DEBUG_PAGEALLOC ");
  187. #endif
  188. #ifdef CONFIG_NUMA
  189. printk("NUMA ");
  190. #endif
  191. printk("%s\n", ppc_md.name ? ppc_md.name : "");
  192. if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP)
  193. return 1;
  194. print_modules();
  195. show_regs(regs);
  196. return 0;
  197. }
  198. void die(const char *str, struct pt_regs *regs, long err)
  199. {
  200. unsigned long flags = oops_begin(regs);
  201. if (__die(str, regs, err))
  202. err = 0;
  203. oops_end(flags, regs, err);
  204. }
  205. void user_single_step_siginfo(struct task_struct *tsk,
  206. struct pt_regs *regs, siginfo_t *info)
  207. {
  208. memset(info, 0, sizeof(*info));
  209. info->si_signo = SIGTRAP;
  210. info->si_code = TRAP_TRACE;
  211. info->si_addr = (void __user *)regs->nip;
  212. }
  213. void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
  214. {
  215. siginfo_t info;
  216. const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \
  217. "at %08lx nip %08lx lr %08lx code %x\n";
  218. const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \
  219. "at %016lx nip %016lx lr %016lx code %x\n";
  220. if (!user_mode(regs)) {
  221. die("Exception in kernel mode", regs, signr);
  222. return;
  223. }
  224. if (show_unhandled_signals && unhandled_signal(current, signr)) {
  225. printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32,
  226. current->comm, current->pid, signr,
  227. addr, regs->nip, regs->link, code);
  228. }
  229. if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs))
  230. local_irq_enable();
  231. current->thread.trap_nr = code;
  232. memset(&info, 0, sizeof(info));
  233. info.si_signo = signr;
  234. info.si_code = code;
  235. info.si_addr = (void __user *) addr;
  236. force_sig_info(signr, &info, current);
  237. }
  238. #ifdef CONFIG_PPC64
  239. void system_reset_exception(struct pt_regs *regs)
  240. {
  241. /* See if any machine dependent calls */
  242. if (ppc_md.system_reset_exception) {
  243. if (ppc_md.system_reset_exception(regs))
  244. return;
  245. }
  246. die("System Reset", regs, SIGABRT);
  247. /* Must die if the interrupt is not recoverable */
  248. if (!(regs->msr & MSR_RI))
  249. panic("Unrecoverable System Reset");
  250. /* What should we do here? We could issue a shutdown or hard reset. */
  251. }
  252. #endif
  253. /*
  254. * I/O accesses can cause machine checks on powermacs.
  255. * Check if the NIP corresponds to the address of a sync
  256. * instruction for which there is an entry in the exception
  257. * table.
  258. * Note that the 601 only takes a machine check on TEA
  259. * (transfer error ack) signal assertion, and does not
  260. * set any of the top 16 bits of SRR1.
  261. * -- paulus.
  262. */
  263. static inline int check_io_access(struct pt_regs *regs)
  264. {
  265. #ifdef CONFIG_PPC32
  266. unsigned long msr = regs->msr;
  267. const struct exception_table_entry *entry;
  268. unsigned int *nip = (unsigned int *)regs->nip;
  269. if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
  270. && (entry = search_exception_tables(regs->nip)) != NULL) {
  271. /*
  272. * Check that it's a sync instruction, or somewhere
  273. * in the twi; isync; nop sequence that inb/inw/inl uses.
  274. * As the address is in the exception table
  275. * we should be able to read the instr there.
  276. * For the debug message, we look at the preceding
  277. * load or store.
  278. */
  279. if (*nip == 0x60000000) /* nop */
  280. nip -= 2;
  281. else if (*nip == 0x4c00012c) /* isync */
  282. --nip;
  283. if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {
  284. /* sync or twi */
  285. unsigned int rb;
  286. --nip;
  287. rb = (*nip >> 11) & 0x1f;
  288. printk(KERN_DEBUG "%s bad port %lx at %p\n",
  289. (*nip & 0x100)? "OUT to": "IN from",
  290. regs->gpr[rb] - _IO_BASE, nip);
  291. regs->msr |= MSR_RI;
  292. regs->nip = entry->fixup;
  293. return 1;
  294. }
  295. }
  296. #endif /* CONFIG_PPC32 */
  297. return 0;
  298. }
  299. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  300. /* On 4xx, the reason for the machine check or program exception
  301. is in the ESR. */
  302. #define get_reason(regs) ((regs)->dsisr)
  303. #ifndef CONFIG_FSL_BOOKE
  304. #define get_mc_reason(regs) ((regs)->dsisr)
  305. #else
  306. #define get_mc_reason(regs) (mfspr(SPRN_MCSR))
  307. #endif
  308. #define REASON_FP ESR_FP
  309. #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
  310. #define REASON_PRIVILEGED ESR_PPR
  311. #define REASON_TRAP ESR_PTR
  312. /* single-step stuff */
  313. #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC)
  314. #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
  315. #else
  316. /* On non-4xx, the reason for the machine check or program
  317. exception is in the MSR. */
  318. #define get_reason(regs) ((regs)->msr)
  319. #define get_mc_reason(regs) ((regs)->msr)
  320. #define REASON_TM 0x200000
  321. #define REASON_FP 0x100000
  322. #define REASON_ILLEGAL 0x80000
  323. #define REASON_PRIVILEGED 0x40000
  324. #define REASON_TRAP 0x20000
  325. #define single_stepping(regs) ((regs)->msr & MSR_SE)
  326. #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
  327. #endif
  328. #if defined(CONFIG_4xx)
  329. int machine_check_4xx(struct pt_regs *regs)
  330. {
  331. unsigned long reason = get_mc_reason(regs);
  332. if (reason & ESR_IMCP) {
  333. printk("Instruction");
  334. mtspr(SPRN_ESR, reason & ~ESR_IMCP);
  335. } else
  336. printk("Data");
  337. printk(" machine check in kernel mode.\n");
  338. return 0;
  339. }
  340. int machine_check_440A(struct pt_regs *regs)
  341. {
  342. unsigned long reason = get_mc_reason(regs);
  343. printk("Machine check in kernel mode.\n");
  344. if (reason & ESR_IMCP){
  345. printk("Instruction Synchronous Machine Check exception\n");
  346. mtspr(SPRN_ESR, reason & ~ESR_IMCP);
  347. }
  348. else {
  349. u32 mcsr = mfspr(SPRN_MCSR);
  350. if (mcsr & MCSR_IB)
  351. printk("Instruction Read PLB Error\n");
  352. if (mcsr & MCSR_DRB)
  353. printk("Data Read PLB Error\n");
  354. if (mcsr & MCSR_DWB)
  355. printk("Data Write PLB Error\n");
  356. if (mcsr & MCSR_TLBP)
  357. printk("TLB Parity Error\n");
  358. if (mcsr & MCSR_ICP){
  359. flush_instruction_cache();
  360. printk("I-Cache Parity Error\n");
  361. }
  362. if (mcsr & MCSR_DCSP)
  363. printk("D-Cache Search Parity Error\n");
  364. if (mcsr & MCSR_DCFP)
  365. printk("D-Cache Flush Parity Error\n");
  366. if (mcsr & MCSR_IMPE)
  367. printk("Machine Check exception is imprecise\n");
  368. /* Clear MCSR */
  369. mtspr(SPRN_MCSR, mcsr);
  370. }
  371. return 0;
  372. }
  373. int machine_check_47x(struct pt_regs *regs)
  374. {
  375. unsigned long reason = get_mc_reason(regs);
  376. u32 mcsr;
  377. printk(KERN_ERR "Machine check in kernel mode.\n");
  378. if (reason & ESR_IMCP) {
  379. printk(KERN_ERR
  380. "Instruction Synchronous Machine Check exception\n");
  381. mtspr(SPRN_ESR, reason & ~ESR_IMCP);
  382. return 0;
  383. }
  384. mcsr = mfspr(SPRN_MCSR);
  385. if (mcsr & MCSR_IB)
  386. printk(KERN_ERR "Instruction Read PLB Error\n");
  387. if (mcsr & MCSR_DRB)
  388. printk(KERN_ERR "Data Read PLB Error\n");
  389. if (mcsr & MCSR_DWB)
  390. printk(KERN_ERR "Data Write PLB Error\n");
  391. if (mcsr & MCSR_TLBP)
  392. printk(KERN_ERR "TLB Parity Error\n");
  393. if (mcsr & MCSR_ICP) {
  394. flush_instruction_cache();
  395. printk(KERN_ERR "I-Cache Parity Error\n");
  396. }
  397. if (mcsr & MCSR_DCSP)
  398. printk(KERN_ERR "D-Cache Search Parity Error\n");
  399. if (mcsr & PPC47x_MCSR_GPR)
  400. printk(KERN_ERR "GPR Parity Error\n");
  401. if (mcsr & PPC47x_MCSR_FPR)
  402. printk(KERN_ERR "FPR Parity Error\n");
  403. if (mcsr & PPC47x_MCSR_IPR)
  404. printk(KERN_ERR "Machine Check exception is imprecise\n");
  405. /* Clear MCSR */
  406. mtspr(SPRN_MCSR, mcsr);
  407. return 0;
  408. }
  409. #elif defined(CONFIG_E500)
  410. int machine_check_e500mc(struct pt_regs *regs)
  411. {
  412. unsigned long mcsr = mfspr(SPRN_MCSR);
  413. unsigned long reason = mcsr;
  414. int recoverable = 1;
  415. if (reason & MCSR_LD) {
  416. recoverable = fsl_rio_mcheck_exception(regs);
  417. if (recoverable == 1)
  418. goto silent_out;
  419. }
  420. printk("Machine check in kernel mode.\n");
  421. printk("Caused by (from MCSR=%lx): ", reason);
  422. if (reason & MCSR_MCP)
  423. printk("Machine Check Signal\n");
  424. if (reason & MCSR_ICPERR) {
  425. printk("Instruction Cache Parity Error\n");
  426. /*
  427. * This is recoverable by invalidating the i-cache.
  428. */
  429. mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI);
  430. while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI)
  431. ;
  432. /*
  433. * This will generally be accompanied by an instruction
  434. * fetch error report -- only treat MCSR_IF as fatal
  435. * if it wasn't due to an L1 parity error.
  436. */
  437. reason &= ~MCSR_IF;
  438. }
  439. if (reason & MCSR_DCPERR_MC) {
  440. printk("Data Cache Parity Error\n");
  441. /*
  442. * In write shadow mode we auto-recover from the error, but it
  443. * may still get logged and cause a machine check. We should
  444. * only treat the non-write shadow case as non-recoverable.
  445. */
  446. if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS))
  447. recoverable = 0;
  448. }
  449. if (reason & MCSR_L2MMU_MHIT) {
  450. printk("Hit on multiple TLB entries\n");
  451. recoverable = 0;
  452. }
  453. if (reason & MCSR_NMI)
  454. printk("Non-maskable interrupt\n");
  455. if (reason & MCSR_IF) {
  456. printk("Instruction Fetch Error Report\n");
  457. recoverable = 0;
  458. }
  459. if (reason & MCSR_LD) {
  460. printk("Load Error Report\n");
  461. recoverable = 0;
  462. }
  463. if (reason & MCSR_ST) {
  464. printk("Store Error Report\n");
  465. recoverable = 0;
  466. }
  467. if (reason & MCSR_LDG) {
  468. printk("Guarded Load Error Report\n");
  469. recoverable = 0;
  470. }
  471. if (reason & MCSR_TLBSYNC)
  472. printk("Simultaneous tlbsync operations\n");
  473. if (reason & MCSR_BSL2_ERR) {
  474. printk("Level 2 Cache Error\n");
  475. recoverable = 0;
  476. }
  477. if (reason & MCSR_MAV) {
  478. u64 addr;
  479. addr = mfspr(SPRN_MCAR);
  480. addr |= (u64)mfspr(SPRN_MCARU) << 32;
  481. printk("Machine Check %s Address: %#llx\n",
  482. reason & MCSR_MEA ? "Effective" : "Physical", addr);
  483. }
  484. silent_out:
  485. mtspr(SPRN_MCSR, mcsr);
  486. return mfspr(SPRN_MCSR) == 0 && recoverable;
  487. }
  488. int machine_check_e500(struct pt_regs *regs)
  489. {
  490. unsigned long reason = get_mc_reason(regs);
  491. if (reason & MCSR_BUS_RBERR) {
  492. if (fsl_rio_mcheck_exception(regs))
  493. return 1;
  494. }
  495. printk("Machine check in kernel mode.\n");
  496. printk("Caused by (from MCSR=%lx): ", reason);
  497. if (reason & MCSR_MCP)
  498. printk("Machine Check Signal\n");
  499. if (reason & MCSR_ICPERR)
  500. printk("Instruction Cache Parity Error\n");
  501. if (reason & MCSR_DCP_PERR)
  502. printk("Data Cache Push Parity Error\n");
  503. if (reason & MCSR_DCPERR)
  504. printk("Data Cache Parity Error\n");
  505. if (reason & MCSR_BUS_IAERR)
  506. printk("Bus - Instruction Address Error\n");
  507. if (reason & MCSR_BUS_RAERR)
  508. printk("Bus - Read Address Error\n");
  509. if (reason & MCSR_BUS_WAERR)
  510. printk("Bus - Write Address Error\n");
  511. if (reason & MCSR_BUS_IBERR)
  512. printk("Bus - Instruction Data Error\n");
  513. if (reason & MCSR_BUS_RBERR)
  514. printk("Bus - Read Data Bus Error\n");
  515. if (reason & MCSR_BUS_WBERR)
  516. printk("Bus - Read Data Bus Error\n");
  517. if (reason & MCSR_BUS_IPERR)
  518. printk("Bus - Instruction Parity Error\n");
  519. if (reason & MCSR_BUS_RPERR)
  520. printk("Bus - Read Parity Error\n");
  521. return 0;
  522. }
  523. int machine_check_generic(struct pt_regs *regs)
  524. {
  525. return 0;
  526. }
  527. #elif defined(CONFIG_E200)
  528. int machine_check_e200(struct pt_regs *regs)
  529. {
  530. unsigned long reason = get_mc_reason(regs);
  531. printk("Machine check in kernel mode.\n");
  532. printk("Caused by (from MCSR=%lx): ", reason);
  533. if (reason & MCSR_MCP)
  534. printk("Machine Check Signal\n");
  535. if (reason & MCSR_CP_PERR)
  536. printk("Cache Push Parity Error\n");
  537. if (reason & MCSR_CPERR)
  538. printk("Cache Parity Error\n");
  539. if (reason & MCSR_EXCP_ERR)
  540. printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
  541. if (reason & MCSR_BUS_IRERR)
  542. printk("Bus - Read Bus Error on instruction fetch\n");
  543. if (reason & MCSR_BUS_DRERR)
  544. printk("Bus - Read Bus Error on data load\n");
  545. if (reason & MCSR_BUS_WRERR)
  546. printk("Bus - Write Bus Error on buffered store or cache line push\n");
  547. return 0;
  548. }
  549. #else
  550. int machine_check_generic(struct pt_regs *regs)
  551. {
  552. unsigned long reason = get_mc_reason(regs);
  553. printk("Machine check in kernel mode.\n");
  554. printk("Caused by (from SRR1=%lx): ", reason);
  555. switch (reason & 0x601F0000) {
  556. case 0x80000:
  557. printk("Machine check signal\n");
  558. break;
  559. case 0: /* for 601 */
  560. case 0x40000:
  561. case 0x140000: /* 7450 MSS error and TEA */
  562. printk("Transfer error ack signal\n");
  563. break;
  564. case 0x20000:
  565. printk("Data parity error signal\n");
  566. break;
  567. case 0x10000:
  568. printk("Address parity error signal\n");
  569. break;
  570. case 0x20000000:
  571. printk("L1 Data Cache error\n");
  572. break;
  573. case 0x40000000:
  574. printk("L1 Instruction Cache error\n");
  575. break;
  576. case 0x00100000:
  577. printk("L2 data cache parity error\n");
  578. break;
  579. default:
  580. printk("Unknown values in msr\n");
  581. }
  582. return 0;
  583. }
  584. #endif /* everything else */
  585. void machine_check_exception(struct pt_regs *regs)
  586. {
  587. enum ctx_state prev_state = exception_enter();
  588. int recover = 0;
  589. __get_cpu_var(irq_stat).mce_exceptions++;
  590. /* See if any machine dependent calls. In theory, we would want
  591. * to call the CPU first, and call the ppc_md. one if the CPU
  592. * one returns a positive number. However there is existing code
  593. * that assumes the board gets a first chance, so let's keep it
  594. * that way for now and fix things later. --BenH.
  595. */
  596. if (ppc_md.machine_check_exception)
  597. recover = ppc_md.machine_check_exception(regs);
  598. else if (cur_cpu_spec->machine_check)
  599. recover = cur_cpu_spec->machine_check(regs);
  600. if (recover > 0)
  601. goto bail;
  602. #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
  603. /* the qspan pci read routines can cause machine checks -- Cort
  604. *
  605. * yuck !!! that totally needs to go away ! There are better ways
  606. * to deal with that than having a wart in the mcheck handler.
  607. * -- BenH
  608. */
  609. bad_page_fault(regs, regs->dar, SIGBUS);
  610. goto bail;
  611. #endif
  612. if (debugger_fault_handler(regs))
  613. goto bail;
  614. if (check_io_access(regs))
  615. goto bail;
  616. die("Machine check", regs, SIGBUS);
  617. /* Must die if the interrupt is not recoverable */
  618. if (!(regs->msr & MSR_RI))
  619. panic("Unrecoverable Machine check");
  620. bail:
  621. exception_exit(prev_state);
  622. }
  623. void SMIException(struct pt_regs *regs)
  624. {
  625. die("System Management Interrupt", regs, SIGABRT);
  626. }
  627. void unknown_exception(struct pt_regs *regs)
  628. {
  629. enum ctx_state prev_state = exception_enter();
  630. printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  631. regs->nip, regs->msr, regs->trap);
  632. _exception(SIGTRAP, regs, 0, 0);
  633. exception_exit(prev_state);
  634. }
  635. void instruction_breakpoint_exception(struct pt_regs *regs)
  636. {
  637. enum ctx_state prev_state = exception_enter();
  638. if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5,
  639. 5, SIGTRAP) == NOTIFY_STOP)
  640. goto bail;
  641. if (debugger_iabr_match(regs))
  642. goto bail;
  643. _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
  644. bail:
  645. exception_exit(prev_state);
  646. }
  647. void RunModeException(struct pt_regs *regs)
  648. {
  649. _exception(SIGTRAP, regs, 0, 0);
  650. }
  651. void __kprobes single_step_exception(struct pt_regs *regs)
  652. {
  653. enum ctx_state prev_state = exception_enter();
  654. clear_single_step(regs);
  655. if (notify_die(DIE_SSTEP, "single_step", regs, 5,
  656. 5, SIGTRAP) == NOTIFY_STOP)
  657. goto bail;
  658. if (debugger_sstep(regs))
  659. goto bail;
  660. _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
  661. bail:
  662. exception_exit(prev_state);
  663. }
  664. /*
  665. * After we have successfully emulated an instruction, we have to
  666. * check if the instruction was being single-stepped, and if so,
  667. * pretend we got a single-step exception. This was pointed out
  668. * by Kumar Gala. -- paulus
  669. */
  670. static void emulate_single_step(struct pt_regs *regs)
  671. {
  672. if (single_stepping(regs))
  673. single_step_exception(regs);
  674. }
  675. static inline int __parse_fpscr(unsigned long fpscr)
  676. {
  677. int ret = 0;
  678. /* Invalid operation */
  679. if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
  680. ret = FPE_FLTINV;
  681. /* Overflow */
  682. else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX))
  683. ret = FPE_FLTOVF;
  684. /* Underflow */
  685. else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX))
  686. ret = FPE_FLTUND;
  687. /* Divide by zero */
  688. else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX))
  689. ret = FPE_FLTDIV;
  690. /* Inexact result */
  691. else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX))
  692. ret = FPE_FLTRES;
  693. return ret;
  694. }
  695. static void parse_fpe(struct pt_regs *regs)
  696. {
  697. int code = 0;
  698. flush_fp_to_thread(current);
  699. code = __parse_fpscr(current->thread.fpscr.val);
  700. _exception(SIGFPE, regs, code, regs->nip);
  701. }
  702. /*
  703. * Illegal instruction emulation support. Originally written to
  704. * provide the PVR to user applications using the mfspr rd, PVR.
  705. * Return non-zero if we can't emulate, or -EFAULT if the associated
  706. * memory access caused an access fault. Return zero on success.
  707. *
  708. * There are a couple of ways to do this, either "decode" the instruction
  709. * or directly match lots of bits. In this case, matching lots of
  710. * bits is faster and easier.
  711. *
  712. */
  713. static int emulate_string_inst(struct pt_regs *regs, u32 instword)
  714. {
  715. u8 rT = (instword >> 21) & 0x1f;
  716. u8 rA = (instword >> 16) & 0x1f;
  717. u8 NB_RB = (instword >> 11) & 0x1f;
  718. u32 num_bytes;
  719. unsigned long EA;
  720. int pos = 0;
  721. /* Early out if we are an invalid form of lswx */
  722. if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX)
  723. if ((rT == rA) || (rT == NB_RB))
  724. return -EINVAL;
  725. EA = (rA == 0) ? 0 : regs->gpr[rA];
  726. switch (instword & PPC_INST_STRING_MASK) {
  727. case PPC_INST_LSWX:
  728. case PPC_INST_STSWX:
  729. EA += NB_RB;
  730. num_bytes = regs->xer & 0x7f;
  731. break;
  732. case PPC_INST_LSWI:
  733. case PPC_INST_STSWI:
  734. num_bytes = (NB_RB == 0) ? 32 : NB_RB;
  735. break;
  736. default:
  737. return -EINVAL;
  738. }
  739. while (num_bytes != 0)
  740. {
  741. u8 val;
  742. u32 shift = 8 * (3 - (pos & 0x3));
  743. /* if process is 32-bit, clear upper 32 bits of EA */
  744. if ((regs->msr & MSR_64BIT) == 0)
  745. EA &= 0xFFFFFFFF;
  746. switch ((instword & PPC_INST_STRING_MASK)) {
  747. case PPC_INST_LSWX:
  748. case PPC_INST_LSWI:
  749. if (get_user(val, (u8 __user *)EA))
  750. return -EFAULT;
  751. /* first time updating this reg,
  752. * zero it out */
  753. if (pos == 0)
  754. regs->gpr[rT] = 0;
  755. regs->gpr[rT] |= val << shift;
  756. break;
  757. case PPC_INST_STSWI:
  758. case PPC_INST_STSWX:
  759. val = regs->gpr[rT] >> shift;
  760. if (put_user(val, (u8 __user *)EA))
  761. return -EFAULT;
  762. break;
  763. }
  764. /* move EA to next address */
  765. EA += 1;
  766. num_bytes--;
  767. /* manage our position within the register */
  768. if (++pos == 4) {
  769. pos = 0;
  770. if (++rT == 32)
  771. rT = 0;
  772. }
  773. }
  774. return 0;
  775. }
  776. static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword)
  777. {
  778. u32 ra,rs;
  779. unsigned long tmp;
  780. ra = (instword >> 16) & 0x1f;
  781. rs = (instword >> 21) & 0x1f;
  782. tmp = regs->gpr[rs];
  783. tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL);
  784. tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL);
  785. tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
  786. regs->gpr[ra] = tmp;
  787. return 0;
  788. }
  789. static int emulate_isel(struct pt_regs *regs, u32 instword)
  790. {
  791. u8 rT = (instword >> 21) & 0x1f;
  792. u8 rA = (instword >> 16) & 0x1f;
  793. u8 rB = (instword >> 11) & 0x1f;
  794. u8 BC = (instword >> 6) & 0x1f;
  795. u8 bit;
  796. unsigned long tmp;
  797. tmp = (rA == 0) ? 0 : regs->gpr[rA];
  798. bit = (regs->ccr >> (31 - BC)) & 0x1;
  799. regs->gpr[rT] = bit ? tmp : regs->gpr[rB];
  800. return 0;
  801. }
  802. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  803. static inline bool tm_abort_check(struct pt_regs *regs, int cause)
  804. {
  805. /* If we're emulating a load/store in an active transaction, we cannot
  806. * emulate it as the kernel operates in transaction suspended context.
  807. * We need to abort the transaction. This creates a persistent TM
  808. * abort so tell the user what caused it with a new code.
  809. */
  810. if (MSR_TM_TRANSACTIONAL(regs->msr)) {
  811. tm_enable();
  812. tm_abort(cause);
  813. return true;
  814. }
  815. return false;
  816. }
  817. #else
  818. static inline bool tm_abort_check(struct pt_regs *regs, int reason)
  819. {
  820. return false;
  821. }
  822. #endif
  823. static int emulate_instruction(struct pt_regs *regs)
  824. {
  825. u32 instword;
  826. u32 rd;
  827. if (!user_mode(regs) || (regs->msr & MSR_LE))
  828. return -EINVAL;
  829. CHECK_FULL_REGS(regs);
  830. if (get_user(instword, (u32 __user *)(regs->nip)))
  831. return -EFAULT;
  832. /* Emulate the mfspr rD, PVR. */
  833. if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) {
  834. PPC_WARN_EMULATED(mfpvr, regs);
  835. rd = (instword >> 21) & 0x1f;
  836. regs->gpr[rd] = mfspr(SPRN_PVR);
  837. return 0;
  838. }
  839. /* Emulating the dcba insn is just a no-op. */
  840. if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) {
  841. PPC_WARN_EMULATED(dcba, regs);
  842. return 0;
  843. }
  844. /* Emulate the mcrxr insn. */
  845. if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) {
  846. int shift = (instword >> 21) & 0x1c;
  847. unsigned long msk = 0xf0000000UL >> shift;
  848. PPC_WARN_EMULATED(mcrxr, regs);
  849. regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
  850. regs->xer &= ~0xf0000000UL;
  851. return 0;
  852. }
  853. /* Emulate load/store string insn. */
  854. if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) {
  855. if (tm_abort_check(regs,
  856. TM_CAUSE_EMULATE | TM_CAUSE_PERSISTENT))
  857. return -EINVAL;
  858. PPC_WARN_EMULATED(string, regs);
  859. return emulate_string_inst(regs, instword);
  860. }
  861. /* Emulate the popcntb (Population Count Bytes) instruction. */
  862. if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) {
  863. PPC_WARN_EMULATED(popcntb, regs);
  864. return emulate_popcntb_inst(regs, instword);
  865. }
  866. /* Emulate isel (Integer Select) instruction */
  867. if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) {
  868. PPC_WARN_EMULATED(isel, regs);
  869. return emulate_isel(regs, instword);
  870. }
  871. #ifdef CONFIG_PPC64
  872. /* Emulate the mfspr rD, DSCR. */
  873. if ((((instword & PPC_INST_MFSPR_DSCR_USER_MASK) ==
  874. PPC_INST_MFSPR_DSCR_USER) ||
  875. ((instword & PPC_INST_MFSPR_DSCR_MASK) ==
  876. PPC_INST_MFSPR_DSCR)) &&
  877. cpu_has_feature(CPU_FTR_DSCR)) {
  878. PPC_WARN_EMULATED(mfdscr, regs);
  879. rd = (instword >> 21) & 0x1f;
  880. regs->gpr[rd] = mfspr(SPRN_DSCR);
  881. return 0;
  882. }
  883. /* Emulate the mtspr DSCR, rD. */
  884. if ((((instword & PPC_INST_MTSPR_DSCR_USER_MASK) ==
  885. PPC_INST_MTSPR_DSCR_USER) ||
  886. ((instword & PPC_INST_MTSPR_DSCR_MASK) ==
  887. PPC_INST_MTSPR_DSCR)) &&
  888. cpu_has_feature(CPU_FTR_DSCR)) {
  889. PPC_WARN_EMULATED(mtdscr, regs);
  890. rd = (instword >> 21) & 0x1f;
  891. current->thread.dscr = regs->gpr[rd];
  892. current->thread.dscr_inherit = 1;
  893. mtspr(SPRN_DSCR, current->thread.dscr);
  894. return 0;
  895. }
  896. #endif
  897. return -EINVAL;
  898. }
  899. int is_valid_bugaddr(unsigned long addr)
  900. {
  901. return is_kernel_addr(addr);
  902. }
  903. void __kprobes program_check_exception(struct pt_regs *regs)
  904. {
  905. enum ctx_state prev_state = exception_enter();
  906. unsigned int reason = get_reason(regs);
  907. extern int do_mathemu(struct pt_regs *regs);
  908. /* We can now get here via a FP Unavailable exception if the core
  909. * has no FPU, in that case the reason flags will be 0 */
  910. if (reason & REASON_FP) {
  911. /* IEEE FP exception */
  912. parse_fpe(regs);
  913. goto bail;
  914. }
  915. if (reason & REASON_TRAP) {
  916. /* Debugger is first in line to stop recursive faults in
  917. * rcu_lock, notify_die, or atomic_notifier_call_chain */
  918. if (debugger_bpt(regs))
  919. goto bail;
  920. /* trap exception */
  921. if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
  922. == NOTIFY_STOP)
  923. goto bail;
  924. if (!(regs->msr & MSR_PR) && /* not user-mode */
  925. report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
  926. regs->nip += 4;
  927. goto bail;
  928. }
  929. _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
  930. goto bail;
  931. }
  932. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  933. if (reason & REASON_TM) {
  934. /* This is a TM "Bad Thing Exception" program check.
  935. * This occurs when:
  936. * - An rfid/hrfid/mtmsrd attempts to cause an illegal
  937. * transition in TM states.
  938. * - A trechkpt is attempted when transactional.
  939. * - A treclaim is attempted when non transactional.
  940. * - A tend is illegally attempted.
  941. * - writing a TM SPR when transactional.
  942. */
  943. if (!user_mode(regs) &&
  944. report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
  945. regs->nip += 4;
  946. goto bail;
  947. }
  948. /* If usermode caused this, it's done something illegal and
  949. * gets a SIGILL slap on the wrist. We call it an illegal
  950. * operand to distinguish from the instruction just being bad
  951. * (e.g. executing a 'tend' on a CPU without TM!); it's an
  952. * illegal /placement/ of a valid instruction.
  953. */
  954. if (user_mode(regs)) {
  955. _exception(SIGILL, regs, ILL_ILLOPN, regs->nip);
  956. goto bail;
  957. } else {
  958. printk(KERN_EMERG "Unexpected TM Bad Thing exception "
  959. "at %lx (msr 0x%x)\n", regs->nip, reason);
  960. die("Unrecoverable exception", regs, SIGABRT);
  961. }
  962. }
  963. #endif
  964. /* We restore the interrupt state now */
  965. if (!arch_irq_disabled_regs(regs))
  966. local_irq_enable();
  967. #ifdef CONFIG_MATH_EMULATION
  968. /* (reason & REASON_ILLEGAL) would be the obvious thing here,
  969. * but there seems to be a hardware bug on the 405GP (RevD)
  970. * that means ESR is sometimes set incorrectly - either to
  971. * ESR_DST (!?) or 0. In the process of chasing this with the
  972. * hardware people - not sure if it can happen on any illegal
  973. * instruction or only on FP instructions, whether there is a
  974. * pattern to occurrences etc. -dgibson 31/Mar/2003
  975. */
  976. /*
  977. * If we support a HW FPU, we need to ensure the FP state
  978. * if flushed into the thread_struct before attempting
  979. * emulation
  980. */
  981. #ifdef CONFIG_PPC_FPU
  982. flush_fp_to_thread(current);
  983. #endif
  984. switch (do_mathemu(regs)) {
  985. case 0:
  986. emulate_single_step(regs);
  987. goto bail;
  988. case 1: {
  989. int code = 0;
  990. code = __parse_fpscr(current->thread.fpscr.val);
  991. _exception(SIGFPE, regs, code, regs->nip);
  992. goto bail;
  993. }
  994. case -EFAULT:
  995. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  996. goto bail;
  997. }
  998. /* fall through on any other errors */
  999. #endif /* CONFIG_MATH_EMULATION */
  1000. /* Try to emulate it if we should. */
  1001. if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
  1002. switch (emulate_instruction(regs)) {
  1003. case 0:
  1004. regs->nip += 4;
  1005. emulate_single_step(regs);
  1006. goto bail;
  1007. case -EFAULT:
  1008. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  1009. goto bail;
  1010. }
  1011. }
  1012. if (reason & REASON_PRIVILEGED)
  1013. _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
  1014. else
  1015. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1016. bail:
  1017. exception_exit(prev_state);
  1018. }
  1019. /*
  1020. * This occurs when running in hypervisor mode on POWER6 or later
  1021. * and an illegal instruction is encountered.
  1022. */
  1023. void __kprobes emulation_assist_interrupt(struct pt_regs *regs)
  1024. {
  1025. regs->msr |= REASON_ILLEGAL;
  1026. program_check_exception(regs);
  1027. }
  1028. void alignment_exception(struct pt_regs *regs)
  1029. {
  1030. enum ctx_state prev_state = exception_enter();
  1031. int sig, code, fixed = 0;
  1032. /* We restore the interrupt state now */
  1033. if (!arch_irq_disabled_regs(regs))
  1034. local_irq_enable();
  1035. if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT))
  1036. goto bail;
  1037. /* we don't implement logging of alignment exceptions */
  1038. if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS))
  1039. fixed = fix_alignment(regs);
  1040. if (fixed == 1) {
  1041. regs->nip += 4; /* skip over emulated instruction */
  1042. emulate_single_step(regs);
  1043. goto bail;
  1044. }
  1045. /* Operand address was bad */
  1046. if (fixed == -EFAULT) {
  1047. sig = SIGSEGV;
  1048. code = SEGV_ACCERR;
  1049. } else {
  1050. sig = SIGBUS;
  1051. code = BUS_ADRALN;
  1052. }
  1053. if (user_mode(regs))
  1054. _exception(sig, regs, code, regs->dar);
  1055. else
  1056. bad_page_fault(regs, regs->dar, sig);
  1057. bail:
  1058. exception_exit(prev_state);
  1059. }
  1060. void StackOverflow(struct pt_regs *regs)
  1061. {
  1062. printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
  1063. current, regs->gpr[1]);
  1064. debugger(regs);
  1065. show_regs(regs);
  1066. panic("kernel stack overflow");
  1067. }
  1068. void nonrecoverable_exception(struct pt_regs *regs)
  1069. {
  1070. printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
  1071. regs->nip, regs->msr);
  1072. debugger(regs);
  1073. die("nonrecoverable exception", regs, SIGKILL);
  1074. }
  1075. void trace_syscall(struct pt_regs *regs)
  1076. {
  1077. printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
  1078. current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
  1079. regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
  1080. }
  1081. void kernel_fp_unavailable_exception(struct pt_regs *regs)
  1082. {
  1083. enum ctx_state prev_state = exception_enter();
  1084. printk(KERN_EMERG "Unrecoverable FP Unavailable Exception "
  1085. "%lx at %lx\n", regs->trap, regs->nip);
  1086. die("Unrecoverable FP Unavailable Exception", regs, SIGABRT);
  1087. exception_exit(prev_state);
  1088. }
  1089. void altivec_unavailable_exception(struct pt_regs *regs)
  1090. {
  1091. enum ctx_state prev_state = exception_enter();
  1092. if (user_mode(regs)) {
  1093. /* A user program has executed an altivec instruction,
  1094. but this kernel doesn't support altivec. */
  1095. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1096. goto bail;
  1097. }
  1098. printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception "
  1099. "%lx at %lx\n", regs->trap, regs->nip);
  1100. die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT);
  1101. bail:
  1102. exception_exit(prev_state);
  1103. }
  1104. void vsx_unavailable_exception(struct pt_regs *regs)
  1105. {
  1106. if (user_mode(regs)) {
  1107. /* A user program has executed an vsx instruction,
  1108. but this kernel doesn't support vsx. */
  1109. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1110. return;
  1111. }
  1112. printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception "
  1113. "%lx at %lx\n", regs->trap, regs->nip);
  1114. die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT);
  1115. }
  1116. void facility_unavailable_exception(struct pt_regs *regs)
  1117. {
  1118. static char *facility_strings[] = {
  1119. "FPU",
  1120. "VMX/VSX",
  1121. "DSCR",
  1122. "PMU SPRs",
  1123. "BHRB",
  1124. "TM",
  1125. "AT",
  1126. "EBB",
  1127. "TAR",
  1128. };
  1129. char *facility, *prefix;
  1130. u64 value;
  1131. if (regs->trap == 0xf60) {
  1132. value = mfspr(SPRN_FSCR);
  1133. prefix = "";
  1134. } else {
  1135. value = mfspr(SPRN_HFSCR);
  1136. prefix = "Hypervisor ";
  1137. }
  1138. value = value >> 56;
  1139. /* We restore the interrupt state now */
  1140. if (!arch_irq_disabled_regs(regs))
  1141. local_irq_enable();
  1142. if (value < ARRAY_SIZE(facility_strings))
  1143. facility = facility_strings[value];
  1144. else
  1145. facility = "unknown";
  1146. pr_err("%sFacility '%s' unavailable, exception at 0x%lx, MSR=%lx\n",
  1147. prefix, facility, regs->nip, regs->msr);
  1148. if (user_mode(regs)) {
  1149. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1150. return;
  1151. }
  1152. die("Unexpected facility unavailable exception", regs, SIGABRT);
  1153. }
  1154. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1155. extern void do_load_up_fpu(struct pt_regs *regs);
  1156. void fp_unavailable_tm(struct pt_regs *regs)
  1157. {
  1158. /* Note: This does not handle any kind of FP laziness. */
  1159. TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n",
  1160. regs->nip, regs->msr);
  1161. tm_enable();
  1162. /* We can only have got here if the task started using FP after
  1163. * beginning the transaction. So, the transactional regs are just a
  1164. * copy of the checkpointed ones. But, we still need to recheckpoint
  1165. * as we're enabling FP for the process; it will return, abort the
  1166. * transaction, and probably retry but now with FP enabled. So the
  1167. * checkpointed FP registers need to be loaded.
  1168. */
  1169. tm_reclaim(&current->thread, current->thread.regs->msr,
  1170. TM_CAUSE_FAC_UNAV);
  1171. /* Reclaim didn't save out any FPRs to transact_fprs. */
  1172. /* Enable FP for the task: */
  1173. regs->msr |= (MSR_FP | current->thread.fpexc_mode);
  1174. /* This loads and recheckpoints the FP registers from
  1175. * thread.fpr[]. They will remain in registers after the
  1176. * checkpoint so we don't need to reload them after.
  1177. */
  1178. tm_recheckpoint(&current->thread, regs->msr);
  1179. }
  1180. #ifdef CONFIG_ALTIVEC
  1181. extern void do_load_up_altivec(struct pt_regs *regs);
  1182. void altivec_unavailable_tm(struct pt_regs *regs)
  1183. {
  1184. /* See the comments in fp_unavailable_tm(). This function operates
  1185. * the same way.
  1186. */
  1187. TM_DEBUG("Vector Unavailable trap whilst transactional at 0x%lx,"
  1188. "MSR=%lx\n",
  1189. regs->nip, regs->msr);
  1190. tm_enable();
  1191. tm_reclaim(&current->thread, current->thread.regs->msr,
  1192. TM_CAUSE_FAC_UNAV);
  1193. regs->msr |= MSR_VEC;
  1194. tm_recheckpoint(&current->thread, regs->msr);
  1195. current->thread.used_vr = 1;
  1196. }
  1197. #endif
  1198. #ifdef CONFIG_VSX
  1199. void vsx_unavailable_tm(struct pt_regs *regs)
  1200. {
  1201. /* See the comments in fp_unavailable_tm(). This works similarly,
  1202. * though we're loading both FP and VEC registers in here.
  1203. *
  1204. * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC
  1205. * regs. Either way, set MSR_VSX.
  1206. */
  1207. TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx,"
  1208. "MSR=%lx\n",
  1209. regs->nip, regs->msr);
  1210. tm_enable();
  1211. /* This reclaims FP and/or VR regs if they're already enabled */
  1212. tm_reclaim(&current->thread, current->thread.regs->msr,
  1213. TM_CAUSE_FAC_UNAV);
  1214. regs->msr |= MSR_VEC | MSR_FP | current->thread.fpexc_mode |
  1215. MSR_VSX;
  1216. /* This loads & recheckpoints FP and VRs. */
  1217. tm_recheckpoint(&current->thread, regs->msr);
  1218. current->thread.used_vsr = 1;
  1219. }
  1220. #endif
  1221. #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
  1222. void performance_monitor_exception(struct pt_regs *regs)
  1223. {
  1224. __get_cpu_var(irq_stat).pmu_irqs++;
  1225. perf_irq(regs);
  1226. }
  1227. #ifdef CONFIG_8xx
  1228. void SoftwareEmulation(struct pt_regs *regs)
  1229. {
  1230. extern int do_mathemu(struct pt_regs *);
  1231. #if defined(CONFIG_MATH_EMULATION)
  1232. int errcode;
  1233. #endif
  1234. CHECK_FULL_REGS(regs);
  1235. if (!user_mode(regs)) {
  1236. debugger(regs);
  1237. die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
  1238. }
  1239. #ifdef CONFIG_MATH_EMULATION
  1240. errcode = do_mathemu(regs);
  1241. if (errcode >= 0)
  1242. PPC_WARN_EMULATED(math, regs);
  1243. switch (errcode) {
  1244. case 0:
  1245. emulate_single_step(regs);
  1246. return;
  1247. case 1: {
  1248. int code = 0;
  1249. code = __parse_fpscr(current->thread.fpscr.val);
  1250. _exception(SIGFPE, regs, code, regs->nip);
  1251. return;
  1252. }
  1253. case -EFAULT:
  1254. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  1255. return;
  1256. default:
  1257. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1258. return;
  1259. }
  1260. #else
  1261. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1262. #endif
  1263. }
  1264. #endif /* CONFIG_8xx */
  1265. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1266. static void handle_debug(struct pt_regs *regs, unsigned long debug_status)
  1267. {
  1268. int changed = 0;
  1269. /*
  1270. * Determine the cause of the debug event, clear the
  1271. * event flags and send a trap to the handler. Torez
  1272. */
  1273. if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) {
  1274. dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  1275. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1276. current->thread.dbcr2 &= ~DBCR2_DAC12MODE;
  1277. #endif
  1278. do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT,
  1279. 5);
  1280. changed |= 0x01;
  1281. } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) {
  1282. dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W);
  1283. do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT,
  1284. 6);
  1285. changed |= 0x01;
  1286. } else if (debug_status & DBSR_IAC1) {
  1287. current->thread.dbcr0 &= ~DBCR0_IAC1;
  1288. dbcr_iac_range(current) &= ~DBCR_IAC12MODE;
  1289. do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT,
  1290. 1);
  1291. changed |= 0x01;
  1292. } else if (debug_status & DBSR_IAC2) {
  1293. current->thread.dbcr0 &= ~DBCR0_IAC2;
  1294. do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT,
  1295. 2);
  1296. changed |= 0x01;
  1297. } else if (debug_status & DBSR_IAC3) {
  1298. current->thread.dbcr0 &= ~DBCR0_IAC3;
  1299. dbcr_iac_range(current) &= ~DBCR_IAC34MODE;
  1300. do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT,
  1301. 3);
  1302. changed |= 0x01;
  1303. } else if (debug_status & DBSR_IAC4) {
  1304. current->thread.dbcr0 &= ~DBCR0_IAC4;
  1305. do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT,
  1306. 4);
  1307. changed |= 0x01;
  1308. }
  1309. /*
  1310. * At the point this routine was called, the MSR(DE) was turned off.
  1311. * Check all other debug flags and see if that bit needs to be turned
  1312. * back on or not.
  1313. */
  1314. if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0, current->thread.dbcr1))
  1315. regs->msr |= MSR_DE;
  1316. else
  1317. /* Make sure the IDM flag is off */
  1318. current->thread.dbcr0 &= ~DBCR0_IDM;
  1319. if (changed & 0x01)
  1320. mtspr(SPRN_DBCR0, current->thread.dbcr0);
  1321. }
  1322. void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)
  1323. {
  1324. current->thread.dbsr = debug_status;
  1325. /* Hack alert: On BookE, Branch Taken stops on the branch itself, while
  1326. * on server, it stops on the target of the branch. In order to simulate
  1327. * the server behaviour, we thus restart right away with a single step
  1328. * instead of stopping here when hitting a BT
  1329. */
  1330. if (debug_status & DBSR_BT) {
  1331. regs->msr &= ~MSR_DE;
  1332. /* Disable BT */
  1333. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT);
  1334. /* Clear the BT event */
  1335. mtspr(SPRN_DBSR, DBSR_BT);
  1336. /* Do the single step trick only when coming from userspace */
  1337. if (user_mode(regs)) {
  1338. current->thread.dbcr0 &= ~DBCR0_BT;
  1339. current->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC;
  1340. regs->msr |= MSR_DE;
  1341. return;
  1342. }
  1343. if (notify_die(DIE_SSTEP, "block_step", regs, 5,
  1344. 5, SIGTRAP) == NOTIFY_STOP) {
  1345. return;
  1346. }
  1347. if (debugger_sstep(regs))
  1348. return;
  1349. } else if (debug_status & DBSR_IC) { /* Instruction complete */
  1350. regs->msr &= ~MSR_DE;
  1351. /* Disable instruction completion */
  1352. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);
  1353. /* Clear the instruction completion event */
  1354. mtspr(SPRN_DBSR, DBSR_IC);
  1355. if (notify_die(DIE_SSTEP, "single_step", regs, 5,
  1356. 5, SIGTRAP) == NOTIFY_STOP) {
  1357. return;
  1358. }
  1359. if (debugger_sstep(regs))
  1360. return;
  1361. if (user_mode(regs)) {
  1362. current->thread.dbcr0 &= ~DBCR0_IC;
  1363. if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0,
  1364. current->thread.dbcr1))
  1365. regs->msr |= MSR_DE;
  1366. else
  1367. /* Make sure the IDM bit is off */
  1368. current->thread.dbcr0 &= ~DBCR0_IDM;
  1369. }
  1370. _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
  1371. } else
  1372. handle_debug(regs, debug_status);
  1373. }
  1374. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  1375. #if !defined(CONFIG_TAU_INT)
  1376. void TAUException(struct pt_regs *regs)
  1377. {
  1378. printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
  1379. regs->nip, regs->msr, regs->trap, print_tainted());
  1380. }
  1381. #endif /* CONFIG_INT_TAU */
  1382. #ifdef CONFIG_ALTIVEC
  1383. void altivec_assist_exception(struct pt_regs *regs)
  1384. {
  1385. int err;
  1386. if (!user_mode(regs)) {
  1387. printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
  1388. " at %lx\n", regs->nip);
  1389. die("Kernel VMX/Altivec assist exception", regs, SIGILL);
  1390. }
  1391. flush_altivec_to_thread(current);
  1392. PPC_WARN_EMULATED(altivec, regs);
  1393. err = emulate_altivec(regs);
  1394. if (err == 0) {
  1395. regs->nip += 4; /* skip emulated instruction */
  1396. emulate_single_step(regs);
  1397. return;
  1398. }
  1399. if (err == -EFAULT) {
  1400. /* got an error reading the instruction */
  1401. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1402. } else {
  1403. /* didn't recognize the instruction */
  1404. /* XXX quick hack for now: set the non-Java bit in the VSCR */
  1405. printk_ratelimited(KERN_ERR "Unrecognized altivec instruction "
  1406. "in %s at %lx\n", current->comm, regs->nip);
  1407. current->thread.vscr.u[3] |= 0x10000;
  1408. }
  1409. }
  1410. #endif /* CONFIG_ALTIVEC */
  1411. #ifdef CONFIG_VSX
  1412. void vsx_assist_exception(struct pt_regs *regs)
  1413. {
  1414. if (!user_mode(regs)) {
  1415. printk(KERN_EMERG "VSX assist exception in kernel mode"
  1416. " at %lx\n", regs->nip);
  1417. die("Kernel VSX assist exception", regs, SIGILL);
  1418. }
  1419. flush_vsx_to_thread(current);
  1420. printk(KERN_INFO "VSX assist not supported at %lx\n", regs->nip);
  1421. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1422. }
  1423. #endif /* CONFIG_VSX */
  1424. #ifdef CONFIG_FSL_BOOKE
  1425. void CacheLockingException(struct pt_regs *regs, unsigned long address,
  1426. unsigned long error_code)
  1427. {
  1428. /* We treat cache locking instructions from the user
  1429. * as priv ops, in the future we could try to do
  1430. * something smarter
  1431. */
  1432. if (error_code & (ESR_DLK|ESR_ILK))
  1433. _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
  1434. return;
  1435. }
  1436. #endif /* CONFIG_FSL_BOOKE */
  1437. #ifdef CONFIG_SPE
  1438. void SPEFloatingPointException(struct pt_regs *regs)
  1439. {
  1440. extern int do_spe_mathemu(struct pt_regs *regs);
  1441. unsigned long spefscr;
  1442. int fpexc_mode;
  1443. int code = 0;
  1444. int err;
  1445. flush_spe_to_thread(current);
  1446. spefscr = current->thread.spefscr;
  1447. fpexc_mode = current->thread.fpexc_mode;
  1448. if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
  1449. code = FPE_FLTOVF;
  1450. }
  1451. else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
  1452. code = FPE_FLTUND;
  1453. }
  1454. else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
  1455. code = FPE_FLTDIV;
  1456. else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
  1457. code = FPE_FLTINV;
  1458. }
  1459. else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
  1460. code = FPE_FLTRES;
  1461. err = do_spe_mathemu(regs);
  1462. if (err == 0) {
  1463. regs->nip += 4; /* skip emulated instruction */
  1464. emulate_single_step(regs);
  1465. return;
  1466. }
  1467. if (err == -EFAULT) {
  1468. /* got an error reading the instruction */
  1469. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1470. } else if (err == -EINVAL) {
  1471. /* didn't recognize the instruction */
  1472. printk(KERN_ERR "unrecognized spe instruction "
  1473. "in %s at %lx\n", current->comm, regs->nip);
  1474. } else {
  1475. _exception(SIGFPE, regs, code, regs->nip);
  1476. }
  1477. return;
  1478. }
  1479. void SPEFloatingPointRoundException(struct pt_regs *regs)
  1480. {
  1481. extern int speround_handler(struct pt_regs *regs);
  1482. int err;
  1483. preempt_disable();
  1484. if (regs->msr & MSR_SPE)
  1485. giveup_spe(current);
  1486. preempt_enable();
  1487. regs->nip -= 4;
  1488. err = speround_handler(regs);
  1489. if (err == 0) {
  1490. regs->nip += 4; /* skip emulated instruction */
  1491. emulate_single_step(regs);
  1492. return;
  1493. }
  1494. if (err == -EFAULT) {
  1495. /* got an error reading the instruction */
  1496. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1497. } else if (err == -EINVAL) {
  1498. /* didn't recognize the instruction */
  1499. printk(KERN_ERR "unrecognized spe instruction "
  1500. "in %s at %lx\n", current->comm, regs->nip);
  1501. } else {
  1502. _exception(SIGFPE, regs, 0, regs->nip);
  1503. return;
  1504. }
  1505. }
  1506. #endif
  1507. /*
  1508. * We enter here if we get an unrecoverable exception, that is, one
  1509. * that happened at a point where the RI (recoverable interrupt) bit
  1510. * in the MSR is 0. This indicates that SRR0/1 are live, and that
  1511. * we therefore lost state by taking this exception.
  1512. */
  1513. void unrecoverable_exception(struct pt_regs *regs)
  1514. {
  1515. printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
  1516. regs->trap, regs->nip);
  1517. die("Unrecoverable exception", regs, SIGABRT);
  1518. }
  1519. #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x)
  1520. /*
  1521. * Default handler for a Watchdog exception,
  1522. * spins until a reboot occurs
  1523. */
  1524. void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
  1525. {
  1526. /* Generic WatchdogHandler, implement your own */
  1527. mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
  1528. return;
  1529. }
  1530. void WatchdogException(struct pt_regs *regs)
  1531. {
  1532. printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
  1533. WatchdogHandler(regs);
  1534. }
  1535. #endif
  1536. /*
  1537. * We enter here if we discover during exception entry that we are
  1538. * running in supervisor mode with a userspace value in the stack pointer.
  1539. */
  1540. void kernel_bad_stack(struct pt_regs *regs)
  1541. {
  1542. printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
  1543. regs->gpr[1], regs->nip);
  1544. die("Bad kernel stack pointer", regs, SIGABRT);
  1545. }
  1546. void __init trap_init(void)
  1547. {
  1548. }
  1549. #ifdef CONFIG_PPC_EMULATED_STATS
  1550. #define WARN_EMULATED_SETUP(type) .type = { .name = #type }
  1551. struct ppc_emulated ppc_emulated = {
  1552. #ifdef CONFIG_ALTIVEC
  1553. WARN_EMULATED_SETUP(altivec),
  1554. #endif
  1555. WARN_EMULATED_SETUP(dcba),
  1556. WARN_EMULATED_SETUP(dcbz),
  1557. WARN_EMULATED_SETUP(fp_pair),
  1558. WARN_EMULATED_SETUP(isel),
  1559. WARN_EMULATED_SETUP(mcrxr),
  1560. WARN_EMULATED_SETUP(mfpvr),
  1561. WARN_EMULATED_SETUP(multiple),
  1562. WARN_EMULATED_SETUP(popcntb),
  1563. WARN_EMULATED_SETUP(spe),
  1564. WARN_EMULATED_SETUP(string),
  1565. WARN_EMULATED_SETUP(unaligned),
  1566. #ifdef CONFIG_MATH_EMULATION
  1567. WARN_EMULATED_SETUP(math),
  1568. #endif
  1569. #ifdef CONFIG_VSX
  1570. WARN_EMULATED_SETUP(vsx),
  1571. #endif
  1572. #ifdef CONFIG_PPC64
  1573. WARN_EMULATED_SETUP(mfdscr),
  1574. WARN_EMULATED_SETUP(mtdscr),
  1575. #endif
  1576. };
  1577. u32 ppc_warn_emulated;
  1578. void ppc_warn_emulated_print(const char *type)
  1579. {
  1580. pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm,
  1581. type);
  1582. }
  1583. static int __init ppc_warn_emulated_init(void)
  1584. {
  1585. struct dentry *dir, *d;
  1586. unsigned int i;
  1587. struct ppc_emulated_entry *entries = (void *)&ppc_emulated;
  1588. if (!powerpc_debugfs_root)
  1589. return -ENODEV;
  1590. dir = debugfs_create_dir("emulated_instructions",
  1591. powerpc_debugfs_root);
  1592. if (!dir)
  1593. return -ENOMEM;
  1594. d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir,
  1595. &ppc_warn_emulated);
  1596. if (!d)
  1597. goto fail;
  1598. for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) {
  1599. d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir,
  1600. (u32 *)&entries[i].val.counter);
  1601. if (!d)
  1602. goto fail;
  1603. }
  1604. return 0;
  1605. fail:
  1606. debugfs_remove_recursive(dir);
  1607. return -ENOMEM;
  1608. }
  1609. device_initcall(ppc_warn_emulated_init);
  1610. #endif /* CONFIG_PPC_EMULATED_STATS */