traps.c 47 KB

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