traps.c 53 KB

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