traps.c 40 KB

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