traps.c 38 KB

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