traps.c 48 KB

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