traps.c 39 KB

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