traps.c 48 KB

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