traps.c 50 KB

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