traps.c 47 KB

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