traps.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. /*
  2. * File: arch/blackfin/kernel/traps.c
  3. * Based on:
  4. * Author: Hamish Macdonald
  5. *
  6. * Created:
  7. * Description: uses S/W interrupt 15 for the system calls
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <linux/uaccess.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/module.h>
  32. #include <linux/kallsyms.h>
  33. #include <linux/fs.h>
  34. #include <linux/rbtree.h>
  35. #include <asm/traps.h>
  36. #include <asm/cacheflush.h>
  37. #include <asm/cplb.h>
  38. #include <asm/blackfin.h>
  39. #include <asm/irq_handler.h>
  40. #include <linux/irq.h>
  41. #include <asm/trace.h>
  42. #include <asm/fixed_code.h>
  43. #ifdef CONFIG_KGDB
  44. # include <linux/kgdb.h>
  45. # define CHK_DEBUGGER_TRAP() \
  46. do { \
  47. kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
  48. } while (0)
  49. # define CHK_DEBUGGER_TRAP_MAYBE() \
  50. do { \
  51. if (kgdb_connected) \
  52. CHK_DEBUGGER_TRAP(); \
  53. } while (0)
  54. #else
  55. # define CHK_DEBUGGER_TRAP() do { } while (0)
  56. # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
  57. #endif
  58. #ifdef CONFIG_DEBUG_VERBOSE
  59. #define verbose_printk(fmt, arg...) \
  60. printk(fmt, ##arg)
  61. #else
  62. #define verbose_printk(fmt, arg...) \
  63. ({ if (0) printk(fmt, ##arg); 0; })
  64. #endif
  65. /* Initiate the event table handler */
  66. void __init trap_init(void)
  67. {
  68. CSYNC();
  69. bfin_write_EVT3(trap);
  70. CSYNC();
  71. }
  72. static void decode_address(char *buf, unsigned long address)
  73. {
  74. #ifdef CONFIG_DEBUG_VERBOSE
  75. struct vm_list_struct *vml;
  76. struct task_struct *p;
  77. struct mm_struct *mm;
  78. unsigned long flags, offset;
  79. unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
  80. struct rb_node *n;
  81. #ifdef CONFIG_KALLSYMS
  82. unsigned long symsize;
  83. const char *symname;
  84. char *modname;
  85. char *delim = ":";
  86. char namebuf[128];
  87. /* look up the address and see if we are in kernel space */
  88. symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
  89. if (symname) {
  90. /* yeah! kernel space! */
  91. if (!modname)
  92. modname = delim = "";
  93. sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
  94. (void *)address, delim, modname, delim, symname,
  95. (unsigned long)offset);
  96. return;
  97. }
  98. #endif
  99. /* Problem in fixed code section? */
  100. if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
  101. sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
  102. return;
  103. }
  104. /* Problem somewhere before the kernel start address */
  105. if (address < CONFIG_BOOT_LOAD) {
  106. sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
  107. return;
  108. }
  109. /* looks like we're off in user-land, so let's walk all the
  110. * mappings of all our processes and see if we can't be a whee
  111. * bit more specific
  112. */
  113. write_lock_irqsave(&tasklist_lock, flags);
  114. for_each_process(p) {
  115. mm = (in_atomic ? p->mm : get_task_mm(p));
  116. if (!mm)
  117. continue;
  118. for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
  119. struct vm_area_struct *vma;
  120. vma = rb_entry(n, struct vm_area_struct, vm_rb);
  121. if (address >= vma->vm_start && address < vma->vm_end) {
  122. char _tmpbuf[256];
  123. char *name = p->comm;
  124. struct file *file = vma->vm_file;
  125. if (file) {
  126. char *d_name = d_path(&file->f_path, _tmpbuf,
  127. sizeof(_tmpbuf));
  128. if (!IS_ERR(d_name))
  129. name = d_name;
  130. }
  131. /* FLAT does not have its text aligned to the start of
  132. * the map while FDPIC ELF does ...
  133. */
  134. /* before we can check flat/fdpic, we need to
  135. * make sure current is valid
  136. */
  137. if ((unsigned long)current >= FIXED_CODE_START &&
  138. !((unsigned long)current & 0x3)) {
  139. if (current->mm &&
  140. (address > current->mm->start_code) &&
  141. (address < current->mm->end_code))
  142. offset = address - current->mm->start_code;
  143. else
  144. offset = (address - vma->vm_start) +
  145. (vma->vm_pgoff << PAGE_SHIFT);
  146. sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
  147. (void *)address, name, offset);
  148. } else
  149. sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
  150. (void *)address, name,
  151. vma->vm_start, vma->vm_end);
  152. if (!in_atomic)
  153. mmput(mm);
  154. if (!strlen(buf))
  155. sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
  156. goto done;
  157. }
  158. }
  159. if (!in_atomic)
  160. mmput(mm);
  161. }
  162. /* we were unable to find this address anywhere */
  163. sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
  164. done:
  165. write_unlock_irqrestore(&tasklist_lock, flags);
  166. #else
  167. sprintf(buf, " ");
  168. #endif
  169. }
  170. asmlinkage void double_fault_c(struct pt_regs *fp)
  171. {
  172. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  173. int j;
  174. trace_buffer_save(j);
  175. #endif
  176. console_verbose();
  177. oops_in_progress = 1;
  178. #ifdef CONFIG_DEBUG_VERBOSE
  179. printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
  180. #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
  181. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
  182. unsigned int cpu = smp_processor_id();
  183. char buf[150];
  184. decode_address(buf, cpu_pda[cpu].retx);
  185. printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
  186. (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
  187. decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
  188. printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
  189. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  190. printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
  191. decode_address(buf, fp->retx);
  192. printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
  193. } else
  194. #endif
  195. {
  196. dump_bfin_process(fp);
  197. dump_bfin_mem(fp);
  198. show_regs(fp);
  199. dump_bfin_trace_buffer();
  200. }
  201. #endif
  202. panic("Double Fault - unrecoverable event");
  203. }
  204. asmlinkage void trap_c(struct pt_regs *fp)
  205. {
  206. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  207. int j;
  208. #endif
  209. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  210. unsigned int cpu = smp_processor_id();
  211. #endif
  212. int sig = 0;
  213. siginfo_t info;
  214. unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
  215. trace_buffer_save(j);
  216. /* Important - be very careful dereferncing pointers - will lead to
  217. * double faults if the stack has become corrupt
  218. */
  219. /* If the fault was caused by a kernel thread, or interrupt handler
  220. * we will kernel panic, so the system reboots.
  221. * If KGDB is enabled, don't set this for kernel breakpoints
  222. */
  223. /* TODO: check to see if we are in some sort of deferred HWERR
  224. * that we should be able to recover from, not kernel panic
  225. */
  226. if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
  227. #ifdef CONFIG_KGDB
  228. && (trapnr != VEC_EXCPT02)
  229. #endif
  230. ){
  231. console_verbose();
  232. oops_in_progress = 1;
  233. } else if (current) {
  234. if (current->mm == NULL) {
  235. console_verbose();
  236. oops_in_progress = 1;
  237. }
  238. }
  239. /* trap_c() will be called for exceptions. During exceptions
  240. * processing, the pc value should be set with retx value.
  241. * With this change we can cleanup some code in signal.c- TODO
  242. */
  243. fp->orig_pc = fp->retx;
  244. /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
  245. trapnr, fp->ipend, fp->pc, fp->retx); */
  246. /* send the appropriate signal to the user program */
  247. switch (trapnr) {
  248. /* This table works in conjuction with the one in ./mach-common/entry.S
  249. * Some exceptions are handled there (in assembly, in exception space)
  250. * Some are handled here, (in C, in interrupt space)
  251. * Some, like CPLB, are handled in both, where the normal path is
  252. * handled in assembly/exception space, and the error path is handled
  253. * here
  254. */
  255. /* 0x00 - Linux Syscall, getting here is an error */
  256. /* 0x01 - userspace gdb breakpoint, handled here */
  257. case VEC_EXCPT01:
  258. info.si_code = TRAP_ILLTRAP;
  259. sig = SIGTRAP;
  260. CHK_DEBUGGER_TRAP_MAYBE();
  261. /* Check if this is a breakpoint in kernel space */
  262. if (fp->ipend & 0xffc0)
  263. return;
  264. else
  265. break;
  266. /* 0x03 - User Defined, userspace stack overflow */
  267. case VEC_EXCPT03:
  268. info.si_code = SEGV_STACKFLOW;
  269. sig = SIGSEGV;
  270. verbose_printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
  271. CHK_DEBUGGER_TRAP_MAYBE();
  272. break;
  273. /* 0x02 - KGDB initial connection and break signal trap */
  274. case VEC_EXCPT02:
  275. #ifdef CONFIG_KGDB
  276. info.si_code = TRAP_ILLTRAP;
  277. sig = SIGTRAP;
  278. CHK_DEBUGGER_TRAP();
  279. return;
  280. #endif
  281. /* 0x04 - User Defined */
  282. /* 0x05 - User Defined */
  283. /* 0x06 - User Defined */
  284. /* 0x07 - User Defined */
  285. /* 0x08 - User Defined */
  286. /* 0x09 - User Defined */
  287. /* 0x0A - User Defined */
  288. /* 0x0B - User Defined */
  289. /* 0x0C - User Defined */
  290. /* 0x0D - User Defined */
  291. /* 0x0E - User Defined */
  292. /* 0x0F - User Defined */
  293. /* If we got here, it is most likely that someone was trying to use a
  294. * custom exception handler, and it is not actually installed properly
  295. */
  296. case VEC_EXCPT04 ... VEC_EXCPT15:
  297. info.si_code = ILL_ILLPARAOP;
  298. sig = SIGILL;
  299. verbose_printk(KERN_NOTICE EXC_0x04(KERN_NOTICE));
  300. CHK_DEBUGGER_TRAP_MAYBE();
  301. break;
  302. /* 0x10 HW Single step, handled here */
  303. case VEC_STEP:
  304. info.si_code = TRAP_STEP;
  305. sig = SIGTRAP;
  306. CHK_DEBUGGER_TRAP_MAYBE();
  307. /* Check if this is a single step in kernel space */
  308. if (fp->ipend & 0xffc0)
  309. return;
  310. else
  311. break;
  312. /* 0x11 - Trace Buffer Full, handled here */
  313. case VEC_OVFLOW:
  314. info.si_code = TRAP_TRACEFLOW;
  315. sig = SIGTRAP;
  316. verbose_printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
  317. CHK_DEBUGGER_TRAP_MAYBE();
  318. break;
  319. /* 0x12 - Reserved, Caught by default */
  320. /* 0x13 - Reserved, Caught by default */
  321. /* 0x14 - Reserved, Caught by default */
  322. /* 0x15 - Reserved, Caught by default */
  323. /* 0x16 - Reserved, Caught by default */
  324. /* 0x17 - Reserved, Caught by default */
  325. /* 0x18 - Reserved, Caught by default */
  326. /* 0x19 - Reserved, Caught by default */
  327. /* 0x1A - Reserved, Caught by default */
  328. /* 0x1B - Reserved, Caught by default */
  329. /* 0x1C - Reserved, Caught by default */
  330. /* 0x1D - Reserved, Caught by default */
  331. /* 0x1E - Reserved, Caught by default */
  332. /* 0x1F - Reserved, Caught by default */
  333. /* 0x20 - Reserved, Caught by default */
  334. /* 0x21 - Undefined Instruction, handled here */
  335. case VEC_UNDEF_I:
  336. info.si_code = ILL_ILLOPC;
  337. sig = SIGILL;
  338. verbose_printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
  339. CHK_DEBUGGER_TRAP_MAYBE();
  340. break;
  341. /* 0x22 - Illegal Instruction Combination, handled here */
  342. case VEC_ILGAL_I:
  343. info.si_code = ILL_ILLPARAOP;
  344. sig = SIGILL;
  345. verbose_printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
  346. CHK_DEBUGGER_TRAP_MAYBE();
  347. break;
  348. /* 0x23 - Data CPLB protection violation, handled here */
  349. case VEC_CPLB_VL:
  350. info.si_code = ILL_CPLB_VI;
  351. sig = SIGBUS;
  352. verbose_printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
  353. CHK_DEBUGGER_TRAP_MAYBE();
  354. break;
  355. /* 0x24 - Data access misaligned, handled here */
  356. case VEC_MISALI_D:
  357. info.si_code = BUS_ADRALN;
  358. sig = SIGBUS;
  359. verbose_printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
  360. CHK_DEBUGGER_TRAP_MAYBE();
  361. break;
  362. /* 0x25 - Unrecoverable Event, handled here */
  363. case VEC_UNCOV:
  364. info.si_code = ILL_ILLEXCPT;
  365. sig = SIGILL;
  366. verbose_printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
  367. CHK_DEBUGGER_TRAP_MAYBE();
  368. break;
  369. /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
  370. error case is handled here */
  371. case VEC_CPLB_M:
  372. info.si_code = BUS_ADRALN;
  373. sig = SIGBUS;
  374. verbose_printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
  375. break;
  376. /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
  377. case VEC_CPLB_MHIT:
  378. info.si_code = ILL_CPLB_MULHIT;
  379. sig = SIGSEGV;
  380. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  381. if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
  382. verbose_printk(KERN_NOTICE "NULL pointer access\n");
  383. else
  384. #endif
  385. verbose_printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
  386. CHK_DEBUGGER_TRAP_MAYBE();
  387. break;
  388. /* 0x28 - Emulation Watchpoint, handled here */
  389. case VEC_WATCH:
  390. info.si_code = TRAP_WATCHPT;
  391. sig = SIGTRAP;
  392. pr_debug(EXC_0x28(KERN_DEBUG));
  393. CHK_DEBUGGER_TRAP_MAYBE();
  394. /* Check if this is a watchpoint in kernel space */
  395. if (fp->ipend & 0xffc0)
  396. return;
  397. else
  398. break;
  399. #ifdef CONFIG_BF535
  400. /* 0x29 - Instruction fetch access error (535 only) */
  401. case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
  402. info.si_code = BUS_OPFETCH;
  403. sig = SIGBUS;
  404. verbose_printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
  405. CHK_DEBUGGER_TRAP_MAYBE();
  406. break;
  407. #else
  408. /* 0x29 - Reserved, Caught by default */
  409. #endif
  410. /* 0x2A - Instruction fetch misaligned, handled here */
  411. case VEC_MISALI_I:
  412. info.si_code = BUS_ADRALN;
  413. sig = SIGBUS;
  414. verbose_printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
  415. CHK_DEBUGGER_TRAP_MAYBE();
  416. break;
  417. /* 0x2B - Instruction CPLB protection violation, handled here */
  418. case VEC_CPLB_I_VL:
  419. info.si_code = ILL_CPLB_VI;
  420. sig = SIGBUS;
  421. verbose_printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
  422. CHK_DEBUGGER_TRAP_MAYBE();
  423. break;
  424. /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
  425. case VEC_CPLB_I_M:
  426. info.si_code = ILL_CPLB_MISS;
  427. sig = SIGBUS;
  428. verbose_printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
  429. break;
  430. /* 0x2D - Instruction CPLB Multiple Hits, handled here */
  431. case VEC_CPLB_I_MHIT:
  432. info.si_code = ILL_CPLB_MULHIT;
  433. sig = SIGSEGV;
  434. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  435. if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
  436. verbose_printk(KERN_NOTICE "Jump to NULL address\n");
  437. else
  438. #endif
  439. verbose_printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
  440. CHK_DEBUGGER_TRAP_MAYBE();
  441. break;
  442. /* 0x2E - Illegal use of Supervisor Resource, handled here */
  443. case VEC_ILL_RES:
  444. info.si_code = ILL_PRVOPC;
  445. sig = SIGILL;
  446. verbose_printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
  447. CHK_DEBUGGER_TRAP_MAYBE();
  448. break;
  449. /* 0x2F - Reserved, Caught by default */
  450. /* 0x30 - Reserved, Caught by default */
  451. /* 0x31 - Reserved, Caught by default */
  452. /* 0x32 - Reserved, Caught by default */
  453. /* 0x33 - Reserved, Caught by default */
  454. /* 0x34 - Reserved, Caught by default */
  455. /* 0x35 - Reserved, Caught by default */
  456. /* 0x36 - Reserved, Caught by default */
  457. /* 0x37 - Reserved, Caught by default */
  458. /* 0x38 - Reserved, Caught by default */
  459. /* 0x39 - Reserved, Caught by default */
  460. /* 0x3A - Reserved, Caught by default */
  461. /* 0x3B - Reserved, Caught by default */
  462. /* 0x3C - Reserved, Caught by default */
  463. /* 0x3D - Reserved, Caught by default */
  464. /* 0x3E - Reserved, Caught by default */
  465. /* 0x3F - Reserved, Caught by default */
  466. case VEC_HWERR:
  467. info.si_code = BUS_ADRALN;
  468. sig = SIGBUS;
  469. switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
  470. /* System MMR Error */
  471. case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
  472. info.si_code = BUS_ADRALN;
  473. sig = SIGBUS;
  474. verbose_printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
  475. break;
  476. /* External Memory Addressing Error */
  477. case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
  478. info.si_code = BUS_ADRERR;
  479. sig = SIGBUS;
  480. verbose_printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
  481. break;
  482. /* Performance Monitor Overflow */
  483. case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
  484. verbose_printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
  485. break;
  486. /* RAISE 5 instruction */
  487. case (SEQSTAT_HWERRCAUSE_RAISE_5):
  488. printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
  489. break;
  490. default: /* Reserved */
  491. printk(KERN_NOTICE HWC_default(KERN_NOTICE));
  492. break;
  493. }
  494. CHK_DEBUGGER_TRAP_MAYBE();
  495. break;
  496. /*
  497. * We should be handling all known exception types above,
  498. * if we get here we hit a reserved one, so panic
  499. */
  500. default:
  501. oops_in_progress = 1;
  502. info.si_code = ILL_ILLPARAOP;
  503. sig = SIGILL;
  504. verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
  505. (fp->seqstat & SEQSTAT_EXCAUSE));
  506. CHK_DEBUGGER_TRAP_MAYBE();
  507. break;
  508. }
  509. BUG_ON(sig == 0);
  510. if (sig != SIGTRAP) {
  511. dump_bfin_process(fp);
  512. dump_bfin_mem(fp);
  513. show_regs(fp);
  514. /* Print out the trace buffer if it makes sense */
  515. #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
  516. if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
  517. verbose_printk(KERN_NOTICE "No trace since you do not have "
  518. "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
  519. KERN_NOTICE "\n");
  520. else
  521. #endif
  522. dump_bfin_trace_buffer();
  523. if (oops_in_progress) {
  524. /* Dump the current kernel stack */
  525. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
  526. show_stack(current, NULL);
  527. print_modules();
  528. #ifndef CONFIG_ACCESS_CHECK
  529. verbose_printk(KERN_EMERG "Please turn on "
  530. "CONFIG_ACCESS_CHECK\n");
  531. #endif
  532. panic("Kernel exception");
  533. } else {
  534. #ifdef CONFIG_DEBUG_VERBOSE
  535. unsigned long *stack;
  536. /* Dump the user space stack */
  537. stack = (unsigned long *)rdusp();
  538. verbose_printk(KERN_NOTICE "Userspace Stack\n");
  539. show_stack(NULL, stack);
  540. #endif
  541. }
  542. }
  543. #ifdef CONFIG_IPIPE
  544. if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
  545. #endif
  546. {
  547. info.si_signo = sig;
  548. info.si_errno = 0;
  549. info.si_addr = (void __user *)fp->pc;
  550. force_sig_info(sig, &info, current);
  551. }
  552. if (ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8))
  553. fp->pc = SAFE_USER_INSTRUCTION;
  554. trace_buffer_restore(j);
  555. return;
  556. }
  557. /* Typical exception handling routines */
  558. #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
  559. /*
  560. * Similar to get_user, do some address checking, then dereference
  561. * Return true on sucess, false on bad address
  562. */
  563. static bool get_instruction(unsigned short *val, unsigned short *address)
  564. {
  565. unsigned long addr;
  566. addr = (unsigned long)address;
  567. /* Check for odd addresses */
  568. if (addr & 0x1)
  569. return false;
  570. /* Check that things do not wrap around */
  571. if (addr > (addr + 2))
  572. return false;
  573. /*
  574. * Since we are in exception context, we need to do a little address checking
  575. * We need to make sure we are only accessing valid memory, and
  576. * we don't read something in the async space that can hang forever
  577. */
  578. if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
  579. #if L2_LENGTH != 0
  580. (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
  581. #endif
  582. (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
  583. #if L1_DATA_A_LENGTH != 0
  584. (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
  585. #endif
  586. #if L1_DATA_B_LENGTH != 0
  587. (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
  588. #endif
  589. (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
  590. (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
  591. addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
  592. (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
  593. addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
  594. (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
  595. addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
  596. (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
  597. addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
  598. *val = *address;
  599. return true;
  600. }
  601. #if L1_CODE_LENGTH != 0
  602. if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
  603. isram_memcpy(val, address, 2);
  604. return true;
  605. }
  606. #endif
  607. return false;
  608. }
  609. /*
  610. * decode the instruction if we are printing out the trace, as it
  611. * makes things easier to follow, without running it through objdump
  612. * These are the normal instructions which cause change of flow, which
  613. * would be at the source of the trace buffer
  614. */
  615. #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
  616. static void decode_instruction(unsigned short *address)
  617. {
  618. unsigned short opcode;
  619. if (get_instruction(&opcode, address)) {
  620. if (opcode == 0x0010)
  621. verbose_printk("RTS");
  622. else if (opcode == 0x0011)
  623. verbose_printk("RTI");
  624. else if (opcode == 0x0012)
  625. verbose_printk("RTX");
  626. else if (opcode == 0x0013)
  627. verbose_printk("RTN");
  628. else if (opcode == 0x0014)
  629. verbose_printk("RTE");
  630. else if (opcode == 0x0025)
  631. verbose_printk("EMUEXCPT");
  632. else if (opcode == 0x0040 && opcode <= 0x0047)
  633. verbose_printk("STI R%i", opcode & 7);
  634. else if (opcode >= 0x0050 && opcode <= 0x0057)
  635. verbose_printk("JUMP (P%i)", opcode & 7);
  636. else if (opcode >= 0x0060 && opcode <= 0x0067)
  637. verbose_printk("CALL (P%i)", opcode & 7);
  638. else if (opcode >= 0x0070 && opcode <= 0x0077)
  639. verbose_printk("CALL (PC+P%i)", opcode & 7);
  640. else if (opcode >= 0x0080 && opcode <= 0x0087)
  641. verbose_printk("JUMP (PC+P%i)", opcode & 7);
  642. else if (opcode >= 0x0090 && opcode <= 0x009F)
  643. verbose_printk("RAISE 0x%x", opcode & 0xF);
  644. else if (opcode >= 0x00A0 && opcode <= 0x00AF)
  645. verbose_printk("EXCPT 0x%x", opcode & 0xF);
  646. else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
  647. verbose_printk("IF !CC JUMP");
  648. else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
  649. verbose_printk("IF CC JUMP");
  650. else if (opcode >= 0x2000 && opcode <= 0x2fff)
  651. verbose_printk("JUMP.S");
  652. else if (opcode >= 0xe080 && opcode <= 0xe0ff)
  653. verbose_printk("LSETUP");
  654. else if (opcode >= 0xe200 && opcode <= 0xe2ff)
  655. verbose_printk("JUMP.L");
  656. else if (opcode >= 0xe300 && opcode <= 0xe3ff)
  657. verbose_printk("CALL pcrel");
  658. else
  659. verbose_printk("0x%04x", opcode);
  660. }
  661. }
  662. #endif
  663. void dump_bfin_trace_buffer(void)
  664. {
  665. #ifdef CONFIG_DEBUG_VERBOSE
  666. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  667. int tflags, i = 0;
  668. char buf[150];
  669. unsigned short *addr;
  670. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  671. int j, index;
  672. #endif
  673. trace_buffer_save(tflags);
  674. printk(KERN_NOTICE "Hardware Trace:\n");
  675. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  676. printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
  677. #endif
  678. if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
  679. for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
  680. decode_address(buf, (unsigned long)bfin_read_TBUF());
  681. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  682. addr = (unsigned short *)bfin_read_TBUF();
  683. decode_address(buf, (unsigned long)addr);
  684. printk(KERN_NOTICE " Source : %s ", buf);
  685. decode_instruction(addr);
  686. printk("\n");
  687. }
  688. }
  689. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  690. if (trace_buff_offset)
  691. index = trace_buff_offset / 4;
  692. else
  693. index = EXPAND_LEN;
  694. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  695. while (j) {
  696. decode_address(buf, software_trace_buff[index]);
  697. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  698. index -= 1;
  699. if (index < 0 )
  700. index = EXPAND_LEN;
  701. decode_address(buf, software_trace_buff[index]);
  702. printk(KERN_NOTICE " Source : %s ", buf);
  703. decode_instruction((unsigned short *)software_trace_buff[index]);
  704. printk("\n");
  705. index -= 1;
  706. if (index < 0)
  707. index = EXPAND_LEN;
  708. j--;
  709. i++;
  710. }
  711. #endif
  712. trace_buffer_restore(tflags);
  713. #endif
  714. #endif
  715. }
  716. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  717. /*
  718. * Checks to see if the address pointed to is either a
  719. * 16-bit CALL instruction, or a 32-bit CALL instruction
  720. */
  721. static bool is_bfin_call(unsigned short *addr)
  722. {
  723. unsigned short opcode = 0, *ins_addr;
  724. ins_addr = (unsigned short *)addr;
  725. if (!get_instruction(&opcode, ins_addr))
  726. return false;
  727. if ((opcode >= 0x0060 && opcode <= 0x0067) ||
  728. (opcode >= 0x0070 && opcode <= 0x0077))
  729. return true;
  730. ins_addr--;
  731. if (!get_instruction(&opcode, ins_addr))
  732. return false;
  733. if (opcode >= 0xE300 && opcode <= 0xE3FF)
  734. return true;
  735. return false;
  736. }
  737. void show_stack(struct task_struct *task, unsigned long *stack)
  738. {
  739. #ifdef CONFIG_PRINTK
  740. unsigned int *addr, *endstack, *fp = 0, *frame;
  741. unsigned short *ins_addr;
  742. char buf[150];
  743. unsigned int i, j, ret_addr, frame_no = 0;
  744. /*
  745. * If we have been passed a specific stack, use that one otherwise
  746. * if we have been passed a task structure, use that, otherwise
  747. * use the stack of where the variable "stack" exists
  748. */
  749. if (stack == NULL) {
  750. if (task) {
  751. /* We know this is a kernel stack, so this is the start/end */
  752. stack = (unsigned long *)task->thread.ksp;
  753. endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
  754. } else {
  755. /* print out the existing stack info */
  756. stack = (unsigned long *)&stack;
  757. endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
  758. }
  759. } else
  760. endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
  761. printk(KERN_NOTICE "Stack info:\n");
  762. decode_address(buf, (unsigned int)stack);
  763. printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
  764. if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
  765. printk(KERN_NOTICE "Invalid stack pointer\n");
  766. return;
  767. }
  768. /* First thing is to look for a frame pointer */
  769. for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
  770. if (*addr & 0x1)
  771. continue;
  772. ins_addr = (unsigned short *)*addr;
  773. ins_addr--;
  774. if (is_bfin_call(ins_addr))
  775. fp = addr - 1;
  776. if (fp) {
  777. /* Let's check to see if it is a frame pointer */
  778. while (fp >= (addr - 1) && fp < endstack
  779. && fp && ((unsigned int) fp & 0x3) == 0)
  780. fp = (unsigned int *)*fp;
  781. if (fp == 0 || fp == endstack) {
  782. fp = addr - 1;
  783. break;
  784. }
  785. fp = 0;
  786. }
  787. }
  788. if (fp) {
  789. frame = fp;
  790. printk(KERN_NOTICE " FP: (0x%p)\n", fp);
  791. } else
  792. frame = 0;
  793. /*
  794. * Now that we think we know where things are, we
  795. * walk the stack again, this time printing things out
  796. * incase there is no frame pointer, we still look for
  797. * valid return addresses
  798. */
  799. /* First time print out data, next time, print out symbols */
  800. for (j = 0; j <= 1; j++) {
  801. if (j)
  802. printk(KERN_NOTICE "Return addresses in stack:\n");
  803. else
  804. printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
  805. fp = frame;
  806. frame_no = 0;
  807. for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
  808. addr <= endstack; addr++, i++) {
  809. ret_addr = 0;
  810. if (!j && i % 8 == 0)
  811. printk("\n" KERN_NOTICE "%p:",addr);
  812. /* if it is an odd address, or zero, just skip it */
  813. if (*addr & 0x1 || !*addr)
  814. goto print;
  815. ins_addr = (unsigned short *)*addr;
  816. /* Go back one instruction, and see if it is a CALL */
  817. ins_addr--;
  818. ret_addr = is_bfin_call(ins_addr);
  819. print:
  820. if (!j && stack == (unsigned long *)addr)
  821. printk("[%08x]", *addr);
  822. else if (ret_addr)
  823. if (j) {
  824. decode_address(buf, (unsigned int)*addr);
  825. if (frame == addr) {
  826. printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
  827. continue;
  828. }
  829. printk(KERN_NOTICE " address : %s\n", buf);
  830. } else
  831. printk("<%08x>", *addr);
  832. else if (fp == addr) {
  833. if (j)
  834. frame = addr+1;
  835. else
  836. printk("(%08x)", *addr);
  837. fp = (unsigned int *)*addr;
  838. frame_no++;
  839. } else if (!j)
  840. printk(" %08x ", *addr);
  841. }
  842. if (!j)
  843. printk("\n");
  844. }
  845. #endif
  846. }
  847. void dump_stack(void)
  848. {
  849. unsigned long stack;
  850. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  851. int tflags;
  852. #endif
  853. trace_buffer_save(tflags);
  854. dump_bfin_trace_buffer();
  855. show_stack(current, &stack);
  856. trace_buffer_restore(tflags);
  857. }
  858. EXPORT_SYMBOL(dump_stack);
  859. void dump_bfin_process(struct pt_regs *fp)
  860. {
  861. #ifdef CONFIG_DEBUG_VERBOSE
  862. /* We should be able to look at fp->ipend, but we don't push it on the
  863. * stack all the time, so do this until we fix that */
  864. unsigned int context = bfin_read_IPEND();
  865. if (oops_in_progress)
  866. verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
  867. if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
  868. verbose_printk(KERN_NOTICE "HW Error context\n");
  869. else if (context & 0x0020)
  870. verbose_printk(KERN_NOTICE "Deferred Exception context\n");
  871. else if (context & 0x3FC0)
  872. verbose_printk(KERN_NOTICE "Interrupt context\n");
  873. else if (context & 0x4000)
  874. verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
  875. else if (context & 0x8000)
  876. verbose_printk(KERN_NOTICE "Kernel process context\n");
  877. /* Because we are crashing, and pointers could be bad, we check things
  878. * pretty closely before we use them
  879. */
  880. if ((unsigned long)current >= FIXED_CODE_START &&
  881. !((unsigned long)current & 0x3) && current->pid) {
  882. verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
  883. if (current->comm >= (char *)FIXED_CODE_START)
  884. verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
  885. current->comm, current->pid);
  886. else
  887. verbose_printk(KERN_NOTICE "COMM= invalid\n");
  888. printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
  889. if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
  890. verbose_printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
  891. KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
  892. KERN_NOTICE "\n",
  893. (void *)current->mm->start_code,
  894. (void *)current->mm->end_code,
  895. (void *)current->mm->start_data,
  896. (void *)current->mm->end_data,
  897. (void *)current->mm->end_data,
  898. (void *)current->mm->brk,
  899. (void *)current->mm->start_stack);
  900. else
  901. verbose_printk(KERN_NOTICE "invalid mm\n");
  902. } else
  903. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE
  904. "No Valid process in current context\n");
  905. #endif
  906. }
  907. void dump_bfin_mem(struct pt_regs *fp)
  908. {
  909. #ifdef CONFIG_DEBUG_VERBOSE
  910. unsigned short *addr, *erraddr, val = 0, err = 0;
  911. char sti = 0, buf[6];
  912. erraddr = (void *)fp->pc;
  913. verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
  914. for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
  915. addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
  916. addr++) {
  917. if (!((unsigned long)addr & 0xF))
  918. verbose_printk("\n" KERN_NOTICE "0x%p: ", addr);
  919. if (!get_instruction(&val, addr)) {
  920. val = 0;
  921. sprintf(buf, "????");
  922. } else
  923. sprintf(buf, "%04x", val);
  924. if (addr == erraddr) {
  925. verbose_printk("[%s]", buf);
  926. err = val;
  927. } else
  928. verbose_printk(" %s ", buf);
  929. /* Do any previous instructions turn on interrupts? */
  930. if (addr <= erraddr && /* in the past */
  931. ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
  932. val == 0x017b)) /* [SP++] = RETI */
  933. sti = 1;
  934. }
  935. verbose_printk("\n");
  936. /* Hardware error interrupts can be deferred */
  937. if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
  938. oops_in_progress)){
  939. verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
  940. #ifndef CONFIG_DEBUG_HWERR
  941. verbose_printk(KERN_NOTICE "The remaining message may be meaningless\n"
  942. KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
  943. " better idea where it came from\n");
  944. #else
  945. /* If we are handling only one peripheral interrupt
  946. * and current mm and pid are valid, and the last error
  947. * was in that user space process's text area
  948. * print it out - because that is where the problem exists
  949. */
  950. if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
  951. (current->pid && current->mm)) {
  952. /* And the last RETI points to the current userspace context */
  953. if ((fp + 1)->pc >= current->mm->start_code &&
  954. (fp + 1)->pc <= current->mm->end_code) {
  955. verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
  956. verbose_printk(KERN_NOTICE "-------------------------------------------\n");
  957. show_regs(fp + 1);
  958. verbose_printk(KERN_NOTICE "-------------------------------------------\n");
  959. }
  960. }
  961. #endif
  962. }
  963. #endif
  964. }
  965. void show_regs(struct pt_regs *fp)
  966. {
  967. #ifdef CONFIG_DEBUG_VERBOSE
  968. char buf [150];
  969. struct irqaction *action;
  970. unsigned int i;
  971. unsigned long flags = 0;
  972. unsigned int cpu = smp_processor_id();
  973. unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
  974. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
  975. verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
  976. (long)fp->seqstat, fp->ipend, fp->syscfg);
  977. if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
  978. verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
  979. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  980. #ifdef EBIU_ERRMST
  981. /* If the error was from the EBIU, print it out */
  982. if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
  983. verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
  984. bfin_read_EBIU_ERRMST());
  985. verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
  986. bfin_read_EBIU_ERRADD());
  987. }
  988. #endif
  989. }
  990. verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
  991. fp->seqstat & SEQSTAT_EXCAUSE);
  992. for (i = 2; i <= 15 ; i++) {
  993. if (fp->ipend & (1 << i)) {
  994. if (i != 4) {
  995. decode_address(buf, bfin_read32(EVT0 + 4*i));
  996. verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
  997. } else
  998. verbose_printk(KERN_NOTICE " interrupts disabled\n");
  999. }
  1000. }
  1001. /* if no interrupts are going off, don't print this out */
  1002. if (fp->ipend & ~0x3F) {
  1003. for (i = 0; i < (NR_IRQS - 1); i++) {
  1004. if (!in_atomic)
  1005. spin_lock_irqsave(&irq_desc[i].lock, flags);
  1006. action = irq_desc[i].action;
  1007. if (!action)
  1008. goto unlock;
  1009. decode_address(buf, (unsigned int)action->handler);
  1010. verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
  1011. for (action = action->next; action; action = action->next) {
  1012. decode_address(buf, (unsigned int)action->handler);
  1013. verbose_printk(", %s", buf);
  1014. }
  1015. verbose_printk("\n");
  1016. unlock:
  1017. if (!in_atomic)
  1018. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  1019. }
  1020. }
  1021. decode_address(buf, fp->rete);
  1022. verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
  1023. decode_address(buf, fp->retn);
  1024. verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
  1025. decode_address(buf, fp->retx);
  1026. verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
  1027. decode_address(buf, fp->rets);
  1028. verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
  1029. decode_address(buf, fp->pc);
  1030. verbose_printk(KERN_NOTICE " PC : %s\n", buf);
  1031. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  1032. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  1033. decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
  1034. verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
  1035. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  1036. verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
  1037. }
  1038. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
  1039. verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  1040. fp->r0, fp->r1, fp->r2, fp->r3);
  1041. verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  1042. fp->r4, fp->r5, fp->r6, fp->r7);
  1043. verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  1044. fp->p0, fp->p1, fp->p2, fp->p3);
  1045. verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  1046. fp->p4, fp->p5, fp->fp, (long)fp);
  1047. verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
  1048. fp->lb0, fp->lt0, fp->lc0);
  1049. verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
  1050. fp->lb1, fp->lt1, fp->lc1);
  1051. verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  1052. fp->b0, fp->l0, fp->m0, fp->i0);
  1053. verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  1054. fp->b1, fp->l1, fp->m1, fp->i1);
  1055. verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  1056. fp->b2, fp->l2, fp->m2, fp->i2);
  1057. verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  1058. fp->b3, fp->l3, fp->m3, fp->i3);
  1059. verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  1060. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  1061. verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
  1062. rdusp(), fp->astat);
  1063. verbose_printk(KERN_NOTICE "\n");
  1064. #endif
  1065. }
  1066. #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
  1067. asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
  1068. #endif
  1069. static DEFINE_SPINLOCK(bfin_spinlock_lock);
  1070. asmlinkage int sys_bfin_spinlock(int *p)
  1071. {
  1072. int ret, tmp = 0;
  1073. spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
  1074. ret = get_user(tmp, p);
  1075. if (likely(ret == 0)) {
  1076. if (unlikely(tmp))
  1077. ret = 1;
  1078. else
  1079. put_user(1, p);
  1080. }
  1081. spin_unlock(&bfin_spinlock_lock);
  1082. return ret;
  1083. }
  1084. int bfin_request_exception(unsigned int exception, void (*handler)(void))
  1085. {
  1086. void (*curr_handler)(void);
  1087. if (exception > 0x3F)
  1088. return -EINVAL;
  1089. curr_handler = ex_table[exception];
  1090. if (curr_handler != ex_replaceable)
  1091. return -EBUSY;
  1092. ex_table[exception] = handler;
  1093. return 0;
  1094. }
  1095. EXPORT_SYMBOL(bfin_request_exception);
  1096. int bfin_free_exception(unsigned int exception, void (*handler)(void))
  1097. {
  1098. void (*curr_handler)(void);
  1099. if (exception > 0x3F)
  1100. return -EINVAL;
  1101. curr_handler = ex_table[exception];
  1102. if (curr_handler != handler)
  1103. return -EBUSY;
  1104. ex_table[exception] = ex_replaceable;
  1105. return 0;
  1106. }
  1107. EXPORT_SYMBOL(bfin_free_exception);
  1108. void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
  1109. {
  1110. switch (cplb_panic) {
  1111. case CPLB_NO_UNLOCKED:
  1112. printk(KERN_EMERG "All CPLBs are locked\n");
  1113. break;
  1114. case CPLB_PROT_VIOL:
  1115. return;
  1116. case CPLB_NO_ADDR_MATCH:
  1117. return;
  1118. case CPLB_UNKNOWN_ERR:
  1119. printk(KERN_EMERG "Unknown CPLB Exception\n");
  1120. break;
  1121. }
  1122. oops_in_progress = 1;
  1123. dump_bfin_process(fp);
  1124. dump_bfin_mem(fp);
  1125. show_regs(fp);
  1126. dump_stack();
  1127. panic("Unrecoverable event");
  1128. }