traps.c 49 KB

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