traps.c 35 KB

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