traps.c 40 KB

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