traps.c 40 KB

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