traps.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  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. #ifdef CONFIG_MATH_EMULATION
  907. static int emulate_math(struct pt_regs *regs)
  908. {
  909. int ret;
  910. extern int do_mathemu(struct pt_regs *regs);
  911. ret = do_mathemu(regs);
  912. if (ret >= 0)
  913. PPC_WARN_EMULATED(math, regs);
  914. switch (ret) {
  915. case 0:
  916. emulate_single_step(regs);
  917. return 0;
  918. case 1: {
  919. int code = 0;
  920. code = __parse_fpscr(current->thread.fpscr.val);
  921. _exception(SIGFPE, regs, code, regs->nip);
  922. return 0;
  923. }
  924. case -EFAULT:
  925. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  926. return 0;
  927. }
  928. return -1;
  929. }
  930. #else
  931. static inline int emulate_math(struct pt_regs *regs) { return -1; }
  932. #endif
  933. void __kprobes program_check_exception(struct pt_regs *regs)
  934. {
  935. enum ctx_state prev_state = exception_enter();
  936. unsigned int reason = get_reason(regs);
  937. /* We can now get here via a FP Unavailable exception if the core
  938. * has no FPU, in that case the reason flags will be 0 */
  939. if (reason & REASON_FP) {
  940. /* IEEE FP exception */
  941. parse_fpe(regs);
  942. goto bail;
  943. }
  944. if (reason & REASON_TRAP) {
  945. /* Debugger is first in line to stop recursive faults in
  946. * rcu_lock, notify_die, or atomic_notifier_call_chain */
  947. if (debugger_bpt(regs))
  948. goto bail;
  949. /* trap exception */
  950. if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
  951. == NOTIFY_STOP)
  952. goto bail;
  953. if (!(regs->msr & MSR_PR) && /* not user-mode */
  954. report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
  955. regs->nip += 4;
  956. goto bail;
  957. }
  958. _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
  959. goto bail;
  960. }
  961. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  962. if (reason & REASON_TM) {
  963. /* This is a TM "Bad Thing Exception" program check.
  964. * This occurs when:
  965. * - An rfid/hrfid/mtmsrd attempts to cause an illegal
  966. * transition in TM states.
  967. * - A trechkpt is attempted when transactional.
  968. * - A treclaim is attempted when non transactional.
  969. * - A tend is illegally attempted.
  970. * - writing a TM SPR when transactional.
  971. */
  972. if (!user_mode(regs) &&
  973. report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
  974. regs->nip += 4;
  975. goto bail;
  976. }
  977. /* If usermode caused this, it's done something illegal and
  978. * gets a SIGILL slap on the wrist. We call it an illegal
  979. * operand to distinguish from the instruction just being bad
  980. * (e.g. executing a 'tend' on a CPU without TM!); it's an
  981. * illegal /placement/ of a valid instruction.
  982. */
  983. if (user_mode(regs)) {
  984. _exception(SIGILL, regs, ILL_ILLOPN, regs->nip);
  985. goto bail;
  986. } else {
  987. printk(KERN_EMERG "Unexpected TM Bad Thing exception "
  988. "at %lx (msr 0x%x)\n", regs->nip, reason);
  989. die("Unrecoverable exception", regs, SIGABRT);
  990. }
  991. }
  992. #endif
  993. /* We restore the interrupt state now */
  994. if (!arch_irq_disabled_regs(regs))
  995. local_irq_enable();
  996. /* (reason & REASON_ILLEGAL) would be the obvious thing here,
  997. * but there seems to be a hardware bug on the 405GP (RevD)
  998. * that means ESR is sometimes set incorrectly - either to
  999. * ESR_DST (!?) or 0. In the process of chasing this with the
  1000. * hardware people - not sure if it can happen on any illegal
  1001. * instruction or only on FP instructions, whether there is a
  1002. * pattern to occurrences etc. -dgibson 31/Mar/2003
  1003. */
  1004. if (!emulate_math(regs))
  1005. goto bail;
  1006. /* Try to emulate it if we should. */
  1007. if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
  1008. switch (emulate_instruction(regs)) {
  1009. case 0:
  1010. regs->nip += 4;
  1011. emulate_single_step(regs);
  1012. goto bail;
  1013. case -EFAULT:
  1014. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  1015. goto bail;
  1016. }
  1017. }
  1018. if (reason & REASON_PRIVILEGED)
  1019. _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
  1020. else
  1021. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1022. bail:
  1023. exception_exit(prev_state);
  1024. }
  1025. /*
  1026. * This occurs when running in hypervisor mode on POWER6 or later
  1027. * and an illegal instruction is encountered.
  1028. */
  1029. void __kprobes emulation_assist_interrupt(struct pt_regs *regs)
  1030. {
  1031. regs->msr |= REASON_ILLEGAL;
  1032. program_check_exception(regs);
  1033. }
  1034. void alignment_exception(struct pt_regs *regs)
  1035. {
  1036. enum ctx_state prev_state = exception_enter();
  1037. int sig, code, fixed = 0;
  1038. /* We restore the interrupt state now */
  1039. if (!arch_irq_disabled_regs(regs))
  1040. local_irq_enable();
  1041. if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT))
  1042. goto bail;
  1043. /* we don't implement logging of alignment exceptions */
  1044. if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS))
  1045. fixed = fix_alignment(regs);
  1046. if (fixed == 1) {
  1047. regs->nip += 4; /* skip over emulated instruction */
  1048. emulate_single_step(regs);
  1049. goto bail;
  1050. }
  1051. /* Operand address was bad */
  1052. if (fixed == -EFAULT) {
  1053. sig = SIGSEGV;
  1054. code = SEGV_ACCERR;
  1055. } else {
  1056. sig = SIGBUS;
  1057. code = BUS_ADRALN;
  1058. }
  1059. if (user_mode(regs))
  1060. _exception(sig, regs, code, regs->dar);
  1061. else
  1062. bad_page_fault(regs, regs->dar, sig);
  1063. bail:
  1064. exception_exit(prev_state);
  1065. }
  1066. void StackOverflow(struct pt_regs *regs)
  1067. {
  1068. printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
  1069. current, regs->gpr[1]);
  1070. debugger(regs);
  1071. show_regs(regs);
  1072. panic("kernel stack overflow");
  1073. }
  1074. void nonrecoverable_exception(struct pt_regs *regs)
  1075. {
  1076. printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
  1077. regs->nip, regs->msr);
  1078. debugger(regs);
  1079. die("nonrecoverable exception", regs, SIGKILL);
  1080. }
  1081. void trace_syscall(struct pt_regs *regs)
  1082. {
  1083. printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
  1084. current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
  1085. regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
  1086. }
  1087. void kernel_fp_unavailable_exception(struct pt_regs *regs)
  1088. {
  1089. enum ctx_state prev_state = exception_enter();
  1090. printk(KERN_EMERG "Unrecoverable FP Unavailable Exception "
  1091. "%lx at %lx\n", regs->trap, regs->nip);
  1092. die("Unrecoverable FP Unavailable Exception", regs, SIGABRT);
  1093. exception_exit(prev_state);
  1094. }
  1095. void altivec_unavailable_exception(struct pt_regs *regs)
  1096. {
  1097. enum ctx_state prev_state = exception_enter();
  1098. if (user_mode(regs)) {
  1099. /* A user program has executed an altivec instruction,
  1100. but this kernel doesn't support altivec. */
  1101. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1102. goto bail;
  1103. }
  1104. printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception "
  1105. "%lx at %lx\n", regs->trap, regs->nip);
  1106. die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT);
  1107. bail:
  1108. exception_exit(prev_state);
  1109. }
  1110. void vsx_unavailable_exception(struct pt_regs *regs)
  1111. {
  1112. if (user_mode(regs)) {
  1113. /* A user program has executed an vsx instruction,
  1114. but this kernel doesn't support vsx. */
  1115. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1116. return;
  1117. }
  1118. printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception "
  1119. "%lx at %lx\n", regs->trap, regs->nip);
  1120. die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT);
  1121. }
  1122. void facility_unavailable_exception(struct pt_regs *regs)
  1123. {
  1124. static char *facility_strings[] = {
  1125. "FPU",
  1126. "VMX/VSX",
  1127. "DSCR",
  1128. "PMU SPRs",
  1129. "BHRB",
  1130. "TM",
  1131. "AT",
  1132. "EBB",
  1133. "TAR",
  1134. };
  1135. char *facility, *prefix;
  1136. u64 value;
  1137. if (regs->trap == 0xf60) {
  1138. value = mfspr(SPRN_FSCR);
  1139. prefix = "";
  1140. } else {
  1141. value = mfspr(SPRN_HFSCR);
  1142. prefix = "Hypervisor ";
  1143. }
  1144. value = value >> 56;
  1145. /* We restore the interrupt state now */
  1146. if (!arch_irq_disabled_regs(regs))
  1147. local_irq_enable();
  1148. if (value < ARRAY_SIZE(facility_strings))
  1149. facility = facility_strings[value];
  1150. else
  1151. facility = "unknown";
  1152. pr_err("%sFacility '%s' unavailable, exception at 0x%lx, MSR=%lx\n",
  1153. prefix, facility, regs->nip, regs->msr);
  1154. if (user_mode(regs)) {
  1155. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1156. return;
  1157. }
  1158. die("Unexpected facility unavailable exception", regs, SIGABRT);
  1159. }
  1160. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1161. extern void do_load_up_fpu(struct pt_regs *regs);
  1162. void fp_unavailable_tm(struct pt_regs *regs)
  1163. {
  1164. /* Note: This does not handle any kind of FP laziness. */
  1165. TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n",
  1166. regs->nip, regs->msr);
  1167. tm_enable();
  1168. /* We can only have got here if the task started using FP after
  1169. * beginning the transaction. So, the transactional regs are just a
  1170. * copy of the checkpointed ones. But, we still need to recheckpoint
  1171. * as we're enabling FP for the process; it will return, abort the
  1172. * transaction, and probably retry but now with FP enabled. So the
  1173. * checkpointed FP registers need to be loaded.
  1174. */
  1175. tm_reclaim(&current->thread, current->thread.regs->msr,
  1176. TM_CAUSE_FAC_UNAV);
  1177. /* Reclaim didn't save out any FPRs to transact_fprs. */
  1178. /* Enable FP for the task: */
  1179. regs->msr |= (MSR_FP | current->thread.fpexc_mode);
  1180. /* This loads and recheckpoints the FP registers from
  1181. * thread.fpr[]. They will remain in registers after the
  1182. * checkpoint so we don't need to reload them after.
  1183. */
  1184. tm_recheckpoint(&current->thread, regs->msr);
  1185. }
  1186. #ifdef CONFIG_ALTIVEC
  1187. extern void do_load_up_altivec(struct pt_regs *regs);
  1188. void altivec_unavailable_tm(struct pt_regs *regs)
  1189. {
  1190. /* See the comments in fp_unavailable_tm(). This function operates
  1191. * the same way.
  1192. */
  1193. TM_DEBUG("Vector Unavailable trap whilst transactional at 0x%lx,"
  1194. "MSR=%lx\n",
  1195. regs->nip, regs->msr);
  1196. tm_enable();
  1197. tm_reclaim(&current->thread, current->thread.regs->msr,
  1198. TM_CAUSE_FAC_UNAV);
  1199. regs->msr |= MSR_VEC;
  1200. tm_recheckpoint(&current->thread, regs->msr);
  1201. current->thread.used_vr = 1;
  1202. }
  1203. #endif
  1204. #ifdef CONFIG_VSX
  1205. void vsx_unavailable_tm(struct pt_regs *regs)
  1206. {
  1207. /* See the comments in fp_unavailable_tm(). This works similarly,
  1208. * though we're loading both FP and VEC registers in here.
  1209. *
  1210. * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC
  1211. * regs. Either way, set MSR_VSX.
  1212. */
  1213. TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx,"
  1214. "MSR=%lx\n",
  1215. regs->nip, regs->msr);
  1216. tm_enable();
  1217. /* This reclaims FP and/or VR regs if they're already enabled */
  1218. tm_reclaim(&current->thread, current->thread.regs->msr,
  1219. TM_CAUSE_FAC_UNAV);
  1220. regs->msr |= MSR_VEC | MSR_FP | current->thread.fpexc_mode |
  1221. MSR_VSX;
  1222. /* This loads & recheckpoints FP and VRs. */
  1223. tm_recheckpoint(&current->thread, regs->msr);
  1224. current->thread.used_vsr = 1;
  1225. }
  1226. #endif
  1227. #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
  1228. void performance_monitor_exception(struct pt_regs *regs)
  1229. {
  1230. __get_cpu_var(irq_stat).pmu_irqs++;
  1231. perf_irq(regs);
  1232. }
  1233. #ifdef CONFIG_8xx
  1234. void SoftwareEmulation(struct pt_regs *regs)
  1235. {
  1236. CHECK_FULL_REGS(regs);
  1237. if (!user_mode(regs)) {
  1238. debugger(regs);
  1239. die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
  1240. }
  1241. if (!emulate_math(regs))
  1242. return;
  1243. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1244. }
  1245. #endif /* CONFIG_8xx */
  1246. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1247. static void handle_debug(struct pt_regs *regs, unsigned long debug_status)
  1248. {
  1249. int changed = 0;
  1250. /*
  1251. * Determine the cause of the debug event, clear the
  1252. * event flags and send a trap to the handler. Torez
  1253. */
  1254. if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) {
  1255. dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  1256. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1257. current->thread.dbcr2 &= ~DBCR2_DAC12MODE;
  1258. #endif
  1259. do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT,
  1260. 5);
  1261. changed |= 0x01;
  1262. } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) {
  1263. dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W);
  1264. do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT,
  1265. 6);
  1266. changed |= 0x01;
  1267. } else if (debug_status & DBSR_IAC1) {
  1268. current->thread.dbcr0 &= ~DBCR0_IAC1;
  1269. dbcr_iac_range(current) &= ~DBCR_IAC12MODE;
  1270. do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT,
  1271. 1);
  1272. changed |= 0x01;
  1273. } else if (debug_status & DBSR_IAC2) {
  1274. current->thread.dbcr0 &= ~DBCR0_IAC2;
  1275. do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT,
  1276. 2);
  1277. changed |= 0x01;
  1278. } else if (debug_status & DBSR_IAC3) {
  1279. current->thread.dbcr0 &= ~DBCR0_IAC3;
  1280. dbcr_iac_range(current) &= ~DBCR_IAC34MODE;
  1281. do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT,
  1282. 3);
  1283. changed |= 0x01;
  1284. } else if (debug_status & DBSR_IAC4) {
  1285. current->thread.dbcr0 &= ~DBCR0_IAC4;
  1286. do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT,
  1287. 4);
  1288. changed |= 0x01;
  1289. }
  1290. /*
  1291. * At the point this routine was called, the MSR(DE) was turned off.
  1292. * Check all other debug flags and see if that bit needs to be turned
  1293. * back on or not.
  1294. */
  1295. if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0, current->thread.dbcr1))
  1296. regs->msr |= MSR_DE;
  1297. else
  1298. /* Make sure the IDM flag is off */
  1299. current->thread.dbcr0 &= ~DBCR0_IDM;
  1300. if (changed & 0x01)
  1301. mtspr(SPRN_DBCR0, current->thread.dbcr0);
  1302. }
  1303. void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)
  1304. {
  1305. current->thread.dbsr = debug_status;
  1306. /* Hack alert: On BookE, Branch Taken stops on the branch itself, while
  1307. * on server, it stops on the target of the branch. In order to simulate
  1308. * the server behaviour, we thus restart right away with a single step
  1309. * instead of stopping here when hitting a BT
  1310. */
  1311. if (debug_status & DBSR_BT) {
  1312. regs->msr &= ~MSR_DE;
  1313. /* Disable BT */
  1314. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT);
  1315. /* Clear the BT event */
  1316. mtspr(SPRN_DBSR, DBSR_BT);
  1317. /* Do the single step trick only when coming from userspace */
  1318. if (user_mode(regs)) {
  1319. current->thread.dbcr0 &= ~DBCR0_BT;
  1320. current->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC;
  1321. regs->msr |= MSR_DE;
  1322. return;
  1323. }
  1324. if (notify_die(DIE_SSTEP, "block_step", regs, 5,
  1325. 5, SIGTRAP) == NOTIFY_STOP) {
  1326. return;
  1327. }
  1328. if (debugger_sstep(regs))
  1329. return;
  1330. } else if (debug_status & DBSR_IC) { /* Instruction complete */
  1331. regs->msr &= ~MSR_DE;
  1332. /* Disable instruction completion */
  1333. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);
  1334. /* Clear the instruction completion event */
  1335. mtspr(SPRN_DBSR, DBSR_IC);
  1336. if (notify_die(DIE_SSTEP, "single_step", regs, 5,
  1337. 5, SIGTRAP) == NOTIFY_STOP) {
  1338. return;
  1339. }
  1340. if (debugger_sstep(regs))
  1341. return;
  1342. if (user_mode(regs)) {
  1343. current->thread.dbcr0 &= ~DBCR0_IC;
  1344. if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0,
  1345. current->thread.dbcr1))
  1346. regs->msr |= MSR_DE;
  1347. else
  1348. /* Make sure the IDM bit is off */
  1349. current->thread.dbcr0 &= ~DBCR0_IDM;
  1350. }
  1351. _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
  1352. } else
  1353. handle_debug(regs, debug_status);
  1354. }
  1355. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  1356. #if !defined(CONFIG_TAU_INT)
  1357. void TAUException(struct pt_regs *regs)
  1358. {
  1359. printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
  1360. regs->nip, regs->msr, regs->trap, print_tainted());
  1361. }
  1362. #endif /* CONFIG_INT_TAU */
  1363. #ifdef CONFIG_ALTIVEC
  1364. void altivec_assist_exception(struct pt_regs *regs)
  1365. {
  1366. int err;
  1367. if (!user_mode(regs)) {
  1368. printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
  1369. " at %lx\n", regs->nip);
  1370. die("Kernel VMX/Altivec assist exception", regs, SIGILL);
  1371. }
  1372. flush_altivec_to_thread(current);
  1373. PPC_WARN_EMULATED(altivec, regs);
  1374. err = emulate_altivec(regs);
  1375. if (err == 0) {
  1376. regs->nip += 4; /* skip emulated instruction */
  1377. emulate_single_step(regs);
  1378. return;
  1379. }
  1380. if (err == -EFAULT) {
  1381. /* got an error reading the instruction */
  1382. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1383. } else {
  1384. /* didn't recognize the instruction */
  1385. /* XXX quick hack for now: set the non-Java bit in the VSCR */
  1386. printk_ratelimited(KERN_ERR "Unrecognized altivec instruction "
  1387. "in %s at %lx\n", current->comm, regs->nip);
  1388. current->thread.vscr.u[3] |= 0x10000;
  1389. }
  1390. }
  1391. #endif /* CONFIG_ALTIVEC */
  1392. #ifdef CONFIG_VSX
  1393. void vsx_assist_exception(struct pt_regs *regs)
  1394. {
  1395. if (!user_mode(regs)) {
  1396. printk(KERN_EMERG "VSX assist exception in kernel mode"
  1397. " at %lx\n", regs->nip);
  1398. die("Kernel VSX assist exception", regs, SIGILL);
  1399. }
  1400. flush_vsx_to_thread(current);
  1401. printk(KERN_INFO "VSX assist not supported at %lx\n", regs->nip);
  1402. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1403. }
  1404. #endif /* CONFIG_VSX */
  1405. #ifdef CONFIG_FSL_BOOKE
  1406. void CacheLockingException(struct pt_regs *regs, unsigned long address,
  1407. unsigned long error_code)
  1408. {
  1409. /* We treat cache locking instructions from the user
  1410. * as priv ops, in the future we could try to do
  1411. * something smarter
  1412. */
  1413. if (error_code & (ESR_DLK|ESR_ILK))
  1414. _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
  1415. return;
  1416. }
  1417. #endif /* CONFIG_FSL_BOOKE */
  1418. #ifdef CONFIG_SPE
  1419. void SPEFloatingPointException(struct pt_regs *regs)
  1420. {
  1421. extern int do_spe_mathemu(struct pt_regs *regs);
  1422. unsigned long spefscr;
  1423. int fpexc_mode;
  1424. int code = 0;
  1425. int err;
  1426. flush_spe_to_thread(current);
  1427. spefscr = current->thread.spefscr;
  1428. fpexc_mode = current->thread.fpexc_mode;
  1429. if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
  1430. code = FPE_FLTOVF;
  1431. }
  1432. else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
  1433. code = FPE_FLTUND;
  1434. }
  1435. else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
  1436. code = FPE_FLTDIV;
  1437. else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
  1438. code = FPE_FLTINV;
  1439. }
  1440. else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
  1441. code = FPE_FLTRES;
  1442. err = do_spe_mathemu(regs);
  1443. if (err == 0) {
  1444. regs->nip += 4; /* skip emulated instruction */
  1445. emulate_single_step(regs);
  1446. return;
  1447. }
  1448. if (err == -EFAULT) {
  1449. /* got an error reading the instruction */
  1450. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1451. } else if (err == -EINVAL) {
  1452. /* didn't recognize the instruction */
  1453. printk(KERN_ERR "unrecognized spe instruction "
  1454. "in %s at %lx\n", current->comm, regs->nip);
  1455. } else {
  1456. _exception(SIGFPE, regs, code, regs->nip);
  1457. }
  1458. return;
  1459. }
  1460. void SPEFloatingPointRoundException(struct pt_regs *regs)
  1461. {
  1462. extern int speround_handler(struct pt_regs *regs);
  1463. int err;
  1464. preempt_disable();
  1465. if (regs->msr & MSR_SPE)
  1466. giveup_spe(current);
  1467. preempt_enable();
  1468. regs->nip -= 4;
  1469. err = speround_handler(regs);
  1470. if (err == 0) {
  1471. regs->nip += 4; /* skip emulated instruction */
  1472. emulate_single_step(regs);
  1473. return;
  1474. }
  1475. if (err == -EFAULT) {
  1476. /* got an error reading the instruction */
  1477. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1478. } else if (err == -EINVAL) {
  1479. /* didn't recognize the instruction */
  1480. printk(KERN_ERR "unrecognized spe instruction "
  1481. "in %s at %lx\n", current->comm, regs->nip);
  1482. } else {
  1483. _exception(SIGFPE, regs, 0, regs->nip);
  1484. return;
  1485. }
  1486. }
  1487. #endif
  1488. /*
  1489. * We enter here if we get an unrecoverable exception, that is, one
  1490. * that happened at a point where the RI (recoverable interrupt) bit
  1491. * in the MSR is 0. This indicates that SRR0/1 are live, and that
  1492. * we therefore lost state by taking this exception.
  1493. */
  1494. void unrecoverable_exception(struct pt_regs *regs)
  1495. {
  1496. printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
  1497. regs->trap, regs->nip);
  1498. die("Unrecoverable exception", regs, SIGABRT);
  1499. }
  1500. #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x)
  1501. /*
  1502. * Default handler for a Watchdog exception,
  1503. * spins until a reboot occurs
  1504. */
  1505. void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
  1506. {
  1507. /* Generic WatchdogHandler, implement your own */
  1508. mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
  1509. return;
  1510. }
  1511. void WatchdogException(struct pt_regs *regs)
  1512. {
  1513. printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
  1514. WatchdogHandler(regs);
  1515. }
  1516. #endif
  1517. /*
  1518. * We enter here if we discover during exception entry that we are
  1519. * running in supervisor mode with a userspace value in the stack pointer.
  1520. */
  1521. void kernel_bad_stack(struct pt_regs *regs)
  1522. {
  1523. printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
  1524. regs->gpr[1], regs->nip);
  1525. die("Bad kernel stack pointer", regs, SIGABRT);
  1526. }
  1527. void __init trap_init(void)
  1528. {
  1529. }
  1530. #ifdef CONFIG_PPC_EMULATED_STATS
  1531. #define WARN_EMULATED_SETUP(type) .type = { .name = #type }
  1532. struct ppc_emulated ppc_emulated = {
  1533. #ifdef CONFIG_ALTIVEC
  1534. WARN_EMULATED_SETUP(altivec),
  1535. #endif
  1536. WARN_EMULATED_SETUP(dcba),
  1537. WARN_EMULATED_SETUP(dcbz),
  1538. WARN_EMULATED_SETUP(fp_pair),
  1539. WARN_EMULATED_SETUP(isel),
  1540. WARN_EMULATED_SETUP(mcrxr),
  1541. WARN_EMULATED_SETUP(mfpvr),
  1542. WARN_EMULATED_SETUP(multiple),
  1543. WARN_EMULATED_SETUP(popcntb),
  1544. WARN_EMULATED_SETUP(spe),
  1545. WARN_EMULATED_SETUP(string),
  1546. WARN_EMULATED_SETUP(unaligned),
  1547. #ifdef CONFIG_MATH_EMULATION
  1548. WARN_EMULATED_SETUP(math),
  1549. #endif
  1550. #ifdef CONFIG_VSX
  1551. WARN_EMULATED_SETUP(vsx),
  1552. #endif
  1553. #ifdef CONFIG_PPC64
  1554. WARN_EMULATED_SETUP(mfdscr),
  1555. WARN_EMULATED_SETUP(mtdscr),
  1556. #endif
  1557. };
  1558. u32 ppc_warn_emulated;
  1559. void ppc_warn_emulated_print(const char *type)
  1560. {
  1561. pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm,
  1562. type);
  1563. }
  1564. static int __init ppc_warn_emulated_init(void)
  1565. {
  1566. struct dentry *dir, *d;
  1567. unsigned int i;
  1568. struct ppc_emulated_entry *entries = (void *)&ppc_emulated;
  1569. if (!powerpc_debugfs_root)
  1570. return -ENODEV;
  1571. dir = debugfs_create_dir("emulated_instructions",
  1572. powerpc_debugfs_root);
  1573. if (!dir)
  1574. return -ENOMEM;
  1575. d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir,
  1576. &ppc_warn_emulated);
  1577. if (!d)
  1578. goto fail;
  1579. for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) {
  1580. d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir,
  1581. (u32 *)&entries[i].val.counter);
  1582. if (!d)
  1583. goto fail;
  1584. }
  1585. return 0;
  1586. fail:
  1587. debugfs_remove_recursive(dir);
  1588. return -ENOMEM;
  1589. }
  1590. device_initcall(ppc_warn_emulated_init);
  1591. #endif /* CONFIG_PPC_EMULATED_STATS */