traps.c 40 KB

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