traps.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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_DEBUG_VERBOSE
  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. char *d_name = d_path(&file->f_path, _tmpbuf,
  134. sizeof(_tmpbuf));
  135. if (!IS_ERR(d_name))
  136. name = d_name;
  137. }
  138. /* FLAT does not have its text aligned to the start of
  139. * the map while FDPIC ELF does ...
  140. */
  141. /* before we can check flat/fdpic, we need to
  142. * make sure current is valid
  143. */
  144. if ((unsigned long)current >= FIXED_CODE_START &&
  145. !((unsigned long)current & 0x3)) {
  146. if (current->mm &&
  147. (address > current->mm->start_code) &&
  148. (address < current->mm->end_code))
  149. offset = address - current->mm->start_code;
  150. else
  151. offset = (address - vma->vm_start) +
  152. (vma->vm_pgoff << PAGE_SHIFT);
  153. sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
  154. (void *)address, name, offset);
  155. } else
  156. sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
  157. (void *)address, name,
  158. vma->vm_start, vma->vm_end);
  159. if (!in_atomic)
  160. mmput(mm);
  161. if (!strlen(buf))
  162. sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
  163. goto done;
  164. }
  165. vml = vml->next;
  166. }
  167. if (!in_atomic)
  168. mmput(mm);
  169. }
  170. /* we were unable to find this address anywhere */
  171. sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
  172. done:
  173. write_unlock_irqrestore(&tasklist_lock, flags);
  174. #else
  175. sprintf(buf, " ");
  176. #endif
  177. }
  178. asmlinkage void double_fault_c(struct pt_regs *fp)
  179. {
  180. console_verbose();
  181. oops_in_progress = 1;
  182. #ifdef CONFIG_DEBUG_VERBOSE
  183. printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
  184. #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
  185. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
  186. char buf[150];
  187. decode_address(buf, saved_retx);
  188. printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
  189. (int)saved_seqstat & SEQSTAT_EXCAUSE, buf);
  190. decode_address(buf, saved_dcplb_fault_addr);
  191. printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
  192. decode_address(buf, saved_icplb_fault_addr);
  193. printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
  194. decode_address(buf, fp->retx);
  195. printk(KERN_NOTICE "The instruction at %s caused a double exception\n",
  196. buf);
  197. } else
  198. #endif
  199. {
  200. dump_bfin_process(fp);
  201. dump_bfin_mem(fp);
  202. show_regs(fp);
  203. }
  204. #endif
  205. panic("Double Fault - unrecoverable event\n");
  206. }
  207. asmlinkage void trap_c(struct pt_regs *fp)
  208. {
  209. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  210. int j;
  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 (saved_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 (saved_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. info.si_signo = sig;
  544. info.si_errno = 0;
  545. info.si_addr = (void __user *)fp->pc;
  546. force_sig_info(sig, &info, current);
  547. trace_buffer_restore(j);
  548. return;
  549. }
  550. /* Typical exception handling routines */
  551. #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
  552. /*
  553. * Similar to get_user, do some address checking, then dereference
  554. * Return true on sucess, false on bad address
  555. */
  556. static bool get_instruction(unsigned short *val, unsigned short *address)
  557. {
  558. unsigned long addr;
  559. addr = (unsigned long)address;
  560. /* Check for odd addresses */
  561. if (addr & 0x1)
  562. return false;
  563. /* Check that things do not wrap around */
  564. if (addr > (addr + 2))
  565. return false;
  566. /*
  567. * Since we are in exception context, we need to do a little address checking
  568. * We need to make sure we are only accessing valid memory, and
  569. * we don't read something in the async space that can hang forever
  570. */
  571. if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
  572. #if L2_LENGTH != 0
  573. (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
  574. #endif
  575. (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
  576. #if L1_DATA_A_LENGTH != 0
  577. (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
  578. #endif
  579. #if L1_DATA_B_LENGTH != 0
  580. (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
  581. #endif
  582. (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
  583. (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
  584. addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
  585. (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
  586. addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
  587. (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
  588. addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
  589. (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
  590. addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
  591. *val = *address;
  592. return true;
  593. }
  594. #if L1_CODE_LENGTH != 0
  595. if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
  596. isram_memcpy(val, address, 2);
  597. return true;
  598. }
  599. #endif
  600. return false;
  601. }
  602. /*
  603. * decode the instruction if we are printing out the trace, as it
  604. * makes things easier to follow, without running it through objdump
  605. * These are the normal instructions which cause change of flow, which
  606. * would be at the source of the trace buffer
  607. */
  608. #ifdef CONFIG_DEBUG_VERBOSE
  609. static void decode_instruction(unsigned short *address)
  610. {
  611. unsigned short opcode;
  612. if (get_instruction(&opcode, address)) {
  613. if (opcode == 0x0010)
  614. verbose_printk("RTS");
  615. else if (opcode == 0x0011)
  616. verbose_printk("RTI");
  617. else if (opcode == 0x0012)
  618. verbose_printk("RTX");
  619. else if (opcode >= 0x0050 && opcode <= 0x0057)
  620. verbose_printk("JUMP (P%i)", opcode & 7);
  621. else if (opcode >= 0x0060 && opcode <= 0x0067)
  622. verbose_printk("CALL (P%i)", opcode & 7);
  623. else if (opcode >= 0x0070 && opcode <= 0x0077)
  624. verbose_printk("CALL (PC+P%i)", opcode & 7);
  625. else if (opcode >= 0x0080 && opcode <= 0x0087)
  626. verbose_printk("JUMP (PC+P%i)", opcode & 7);
  627. else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
  628. verbose_printk("IF !CC JUMP");
  629. else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
  630. verbose_printk("IF CC JUMP");
  631. else if (opcode >= 0x2000 && opcode <= 0x2fff)
  632. verbose_printk("JUMP.S");
  633. else if (opcode >= 0xe080 && opcode <= 0xe0ff)
  634. verbose_printk("LSETUP");
  635. else if (opcode >= 0xe200 && opcode <= 0xe2ff)
  636. verbose_printk("JUMP.L");
  637. else if (opcode >= 0xe300 && opcode <= 0xe3ff)
  638. verbose_printk("CALL pcrel");
  639. else
  640. verbose_printk("0x%04x", opcode);
  641. }
  642. }
  643. #endif
  644. void dump_bfin_trace_buffer(void)
  645. {
  646. #ifdef CONFIG_DEBUG_VERBOSE
  647. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  648. int tflags, i = 0;
  649. char buf[150];
  650. unsigned short *addr;
  651. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  652. int j, index;
  653. #endif
  654. trace_buffer_save(tflags);
  655. printk(KERN_NOTICE "Hardware Trace:\n");
  656. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  657. printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
  658. #endif
  659. if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
  660. for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
  661. decode_address(buf, (unsigned long)bfin_read_TBUF());
  662. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  663. addr = (unsigned short *)bfin_read_TBUF();
  664. decode_address(buf, (unsigned long)addr);
  665. printk(KERN_NOTICE " Source : %s ", buf);
  666. decode_instruction(addr);
  667. printk("\n");
  668. }
  669. }
  670. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  671. if (trace_buff_offset)
  672. index = trace_buff_offset / 4;
  673. else
  674. index = EXPAND_LEN;
  675. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  676. while (j) {
  677. decode_address(buf, software_trace_buff[index]);
  678. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  679. index -= 1;
  680. if (index < 0 )
  681. index = EXPAND_LEN;
  682. decode_address(buf, software_trace_buff[index]);
  683. printk(KERN_NOTICE " Source : %s ", buf);
  684. decode_instruction((unsigned short *)software_trace_buff[index]);
  685. printk("\n");
  686. index -= 1;
  687. if (index < 0)
  688. index = EXPAND_LEN;
  689. j--;
  690. i++;
  691. }
  692. #endif
  693. trace_buffer_restore(tflags);
  694. #endif
  695. #endif
  696. }
  697. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  698. /*
  699. * Checks to see if the address pointed to is either a
  700. * 16-bit CALL instruction, or a 32-bit CALL instruction
  701. */
  702. static bool is_bfin_call(unsigned short *addr)
  703. {
  704. unsigned short opcode = 0, *ins_addr;
  705. ins_addr = (unsigned short *)addr;
  706. if (!get_instruction(&opcode, ins_addr))
  707. return false;
  708. if ((opcode >= 0x0060 && opcode <= 0x0067) ||
  709. (opcode >= 0x0070 && opcode <= 0x0077))
  710. return true;
  711. ins_addr--;
  712. if (!get_instruction(&opcode, ins_addr))
  713. return false;
  714. if (opcode >= 0xE300 && opcode <= 0xE3FF)
  715. return true;
  716. return false;
  717. }
  718. void show_stack(struct task_struct *task, unsigned long *stack)
  719. {
  720. #ifdef CONFIG_PRINTK
  721. unsigned int *addr, *endstack, *fp = 0, *frame;
  722. unsigned short *ins_addr;
  723. char buf[150];
  724. unsigned int i, j, ret_addr, frame_no = 0;
  725. /*
  726. * If we have been passed a specific stack, use that one otherwise
  727. * if we have been passed a task structure, use that, otherwise
  728. * use the stack of where the variable "stack" exists
  729. */
  730. if (stack == NULL) {
  731. if (task) {
  732. /* We know this is a kernel stack, so this is the start/end */
  733. stack = (unsigned long *)task->thread.ksp;
  734. endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
  735. } else {
  736. /* print out the existing stack info */
  737. stack = (unsigned long *)&stack;
  738. endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
  739. }
  740. } else
  741. endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
  742. printk(KERN_NOTICE "Stack info:\n");
  743. decode_address(buf, (unsigned int)stack);
  744. printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
  745. addr = (unsigned int *)((unsigned int)stack & ~0x3F);
  746. /* First thing is to look for a frame pointer */
  747. for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
  748. addr < endstack; addr++, i++) {
  749. if (*addr & 0x1)
  750. continue;
  751. ins_addr = (unsigned short *)*addr;
  752. ins_addr--;
  753. if (is_bfin_call(ins_addr))
  754. fp = addr - 1;
  755. if (fp) {
  756. /* Let's check to see if it is a frame pointer */
  757. while (fp >= (addr - 1) && fp < endstack && fp)
  758. fp = (unsigned int *)*fp;
  759. if (fp == 0 || fp == endstack) {
  760. fp = addr - 1;
  761. break;
  762. }
  763. fp = 0;
  764. }
  765. }
  766. if (fp) {
  767. frame = fp;
  768. printk(" FP: (0x%p)\n", fp);
  769. } else
  770. frame = 0;
  771. /*
  772. * Now that we think we know where things are, we
  773. * walk the stack again, this time printing things out
  774. * incase there is no frame pointer, we still look for
  775. * valid return addresses
  776. */
  777. /* First time print out data, next time, print out symbols */
  778. for (j = 0; j <= 1; j++) {
  779. if (j)
  780. printk(KERN_NOTICE "Return addresses in stack:\n");
  781. else
  782. printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
  783. fp = frame;
  784. frame_no = 0;
  785. for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
  786. addr <= endstack; addr++, i++) {
  787. ret_addr = 0;
  788. if (!j && i % 8 == 0)
  789. printk("\n" KERN_NOTICE "%p:",addr);
  790. /* if it is an odd address, or zero, just skip it */
  791. if (*addr & 0x1 || !*addr)
  792. goto print;
  793. ins_addr = (unsigned short *)*addr;
  794. /* Go back one instruction, and see if it is a CALL */
  795. ins_addr--;
  796. ret_addr = is_bfin_call(ins_addr);
  797. print:
  798. if (!j && stack == (unsigned long *)addr)
  799. printk("[%08x]", *addr);
  800. else if (ret_addr)
  801. if (j) {
  802. decode_address(buf, (unsigned int)*addr);
  803. if (frame == addr) {
  804. printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
  805. continue;
  806. }
  807. printk(KERN_NOTICE " address : %s\n", buf);
  808. } else
  809. printk("<%08x>", *addr);
  810. else if (fp == addr) {
  811. if (j)
  812. frame = addr+1;
  813. else
  814. printk("(%08x)", *addr);
  815. fp = (unsigned int *)*addr;
  816. frame_no++;
  817. } else if (!j)
  818. printk(" %08x ", *addr);
  819. }
  820. if (!j)
  821. printk("\n");
  822. }
  823. #endif
  824. }
  825. void dump_stack(void)
  826. {
  827. unsigned long stack;
  828. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  829. int tflags;
  830. #endif
  831. trace_buffer_save(tflags);
  832. dump_bfin_trace_buffer();
  833. show_stack(current, &stack);
  834. trace_buffer_restore(tflags);
  835. }
  836. EXPORT_SYMBOL(dump_stack);
  837. void dump_bfin_process(struct pt_regs *fp)
  838. {
  839. #ifdef CONFIG_DEBUG_VERBOSE
  840. /* We should be able to look at fp->ipend, but we don't push it on the
  841. * stack all the time, so do this until we fix that */
  842. unsigned int context = bfin_read_IPEND();
  843. if (oops_in_progress)
  844. verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
  845. if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
  846. verbose_printk(KERN_NOTICE "HW Error context\n");
  847. else if (context & 0x0020)
  848. verbose_printk(KERN_NOTICE "Deferred Exception context\n");
  849. else if (context & 0x3FC0)
  850. verbose_printk(KERN_NOTICE "Interrupt context\n");
  851. else if (context & 0x4000)
  852. verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
  853. else if (context & 0x8000)
  854. verbose_printk(KERN_NOTICE "Kernel process context\n");
  855. /* Because we are crashing, and pointers could be bad, we check things
  856. * pretty closely before we use them
  857. */
  858. if ((unsigned long)current >= FIXED_CODE_START &&
  859. !((unsigned long)current & 0x3) && current->pid) {
  860. verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
  861. if (current->comm >= (char *)FIXED_CODE_START)
  862. verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
  863. current->comm, current->pid);
  864. else
  865. verbose_printk(KERN_NOTICE "COMM= invalid\n");
  866. if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
  867. verbose_printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
  868. KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
  869. KERN_NOTICE "\n",
  870. (void *)current->mm->start_code,
  871. (void *)current->mm->end_code,
  872. (void *)current->mm->start_data,
  873. (void *)current->mm->end_data,
  874. (void *)current->mm->end_data,
  875. (void *)current->mm->brk,
  876. (void *)current->mm->start_stack);
  877. else
  878. verbose_printk(KERN_NOTICE "invalid mm\n");
  879. } else
  880. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE
  881. "No Valid process in current context\n");
  882. #endif
  883. }
  884. void dump_bfin_mem(struct pt_regs *fp)
  885. {
  886. #ifdef CONFIG_DEBUG_VERBOSE
  887. unsigned short *addr, *erraddr, val = 0, err = 0;
  888. char sti = 0, buf[6];
  889. erraddr = (void *)fp->pc;
  890. verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
  891. for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
  892. addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
  893. addr++) {
  894. if (!((unsigned long)addr & 0xF))
  895. verbose_printk("\n" KERN_NOTICE "0x%p: ", addr);
  896. if (!get_instruction(&val, addr)) {
  897. val = 0;
  898. sprintf(buf, "????");
  899. } else
  900. sprintf(buf, "%04x", val);
  901. if (addr == erraddr) {
  902. verbose_printk("[%s]", buf);
  903. err = val;
  904. } else
  905. verbose_printk(" %s ", buf);
  906. /* Do any previous instructions turn on interrupts? */
  907. if (addr <= erraddr && /* in the past */
  908. ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
  909. val == 0x017b)) /* [SP++] = RETI */
  910. sti = 1;
  911. }
  912. verbose_printk("\n");
  913. /* Hardware error interrupts can be deferred */
  914. if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
  915. oops_in_progress)){
  916. verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
  917. #ifndef CONFIG_DEBUG_HWERR
  918. verbose_printk(KERN_NOTICE "The remaining message may be meaningless\n"
  919. KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
  920. " better idea where it came from\n");
  921. #else
  922. /* If we are handling only one peripheral interrupt
  923. * and current mm and pid are valid, and the last error
  924. * was in that user space process's text area
  925. * print it out - because that is where the problem exists
  926. */
  927. if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
  928. (current->pid && current->mm)) {
  929. /* And the last RETI points to the current userspace context */
  930. if ((fp + 1)->pc >= current->mm->start_code &&
  931. (fp + 1)->pc <= current->mm->end_code) {
  932. verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
  933. verbose_printk(KERN_NOTICE "-------------------------------------------\n");
  934. show_regs(fp + 1);
  935. verbose_printk(KERN_NOTICE "-------------------------------------------\n");
  936. }
  937. }
  938. #endif
  939. }
  940. #endif
  941. }
  942. void show_regs(struct pt_regs *fp)
  943. {
  944. #ifdef CONFIG_DEBUG_VERBOSE
  945. char buf [150];
  946. struct irqaction *action;
  947. unsigned int i;
  948. unsigned long flags;
  949. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
  950. verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
  951. (long)fp->seqstat, fp->ipend, fp->syscfg);
  952. if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
  953. verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
  954. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  955. #ifdef EBIU_ERRMST
  956. /* If the error was from the EBIU, print it out */
  957. if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
  958. verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
  959. bfin_read_EBIU_ERRMST());
  960. verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
  961. bfin_read_EBIU_ERRADD());
  962. }
  963. #endif
  964. }
  965. verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
  966. fp->seqstat & SEQSTAT_EXCAUSE);
  967. for (i = 6; i <= 15 ; i++) {
  968. if (fp->ipend & (1 << i)) {
  969. decode_address(buf, bfin_read32(EVT0 + 4*i));
  970. verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
  971. }
  972. }
  973. /* if no interrupts are going off, don't print this out */
  974. if (fp->ipend & ~0x3F) {
  975. for (i = 0; i < (NR_IRQS - 1); i++) {
  976. spin_lock_irqsave(&irq_desc[i].lock, flags);
  977. action = irq_desc[i].action;
  978. if (!action)
  979. goto unlock;
  980. decode_address(buf, (unsigned int)action->handler);
  981. verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
  982. for (action = action->next; action; action = action->next) {
  983. decode_address(buf, (unsigned int)action->handler);
  984. verbose_printk(", %s", buf);
  985. }
  986. verbose_printk("\n");
  987. unlock:
  988. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  989. }
  990. }
  991. decode_address(buf, fp->rete);
  992. verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
  993. decode_address(buf, fp->retn);
  994. verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
  995. decode_address(buf, fp->retx);
  996. verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
  997. decode_address(buf, fp->rets);
  998. verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
  999. decode_address(buf, fp->pc);
  1000. verbose_printk(KERN_NOTICE " PC : %s\n", buf);
  1001. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  1002. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  1003. decode_address(buf, saved_dcplb_fault_addr);
  1004. verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
  1005. decode_address(buf, saved_icplb_fault_addr);
  1006. verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
  1007. }
  1008. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
  1009. verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  1010. fp->r0, fp->r1, fp->r2, fp->r3);
  1011. verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  1012. fp->r4, fp->r5, fp->r6, fp->r7);
  1013. verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  1014. fp->p0, fp->p1, fp->p2, fp->p3);
  1015. verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  1016. fp->p4, fp->p5, fp->fp, (long)fp);
  1017. verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
  1018. fp->lb0, fp->lt0, fp->lc0);
  1019. verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
  1020. fp->lb1, fp->lt1, fp->lc1);
  1021. verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  1022. fp->b0, fp->l0, fp->m0, fp->i0);
  1023. verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  1024. fp->b1, fp->l1, fp->m1, fp->i1);
  1025. verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  1026. fp->b2, fp->l2, fp->m2, fp->i2);
  1027. verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  1028. fp->b3, fp->l3, fp->m3, fp->i3);
  1029. verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  1030. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  1031. verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
  1032. rdusp(), fp->astat);
  1033. verbose_printk(KERN_NOTICE "\n");
  1034. #endif
  1035. }
  1036. #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
  1037. asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
  1038. #endif
  1039. asmlinkage int sys_bfin_spinlock(int *spinlock)
  1040. {
  1041. int ret = 0;
  1042. int tmp = 0;
  1043. local_irq_disable();
  1044. ret = get_user(tmp, spinlock);
  1045. if (ret == 0) {
  1046. if (tmp)
  1047. ret = 1;
  1048. tmp = 1;
  1049. put_user(tmp, spinlock);
  1050. }
  1051. local_irq_enable();
  1052. return ret;
  1053. }
  1054. int bfin_request_exception(unsigned int exception, void (*handler)(void))
  1055. {
  1056. void (*curr_handler)(void);
  1057. if (exception > 0x3F)
  1058. return -EINVAL;
  1059. curr_handler = ex_table[exception];
  1060. if (curr_handler != ex_replaceable)
  1061. return -EBUSY;
  1062. ex_table[exception] = handler;
  1063. return 0;
  1064. }
  1065. EXPORT_SYMBOL(bfin_request_exception);
  1066. int bfin_free_exception(unsigned int exception, void (*handler)(void))
  1067. {
  1068. void (*curr_handler)(void);
  1069. if (exception > 0x3F)
  1070. return -EINVAL;
  1071. curr_handler = ex_table[exception];
  1072. if (curr_handler != handler)
  1073. return -EBUSY;
  1074. ex_table[exception] = ex_replaceable;
  1075. return 0;
  1076. }
  1077. EXPORT_SYMBOL(bfin_free_exception);
  1078. void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
  1079. {
  1080. switch (cplb_panic) {
  1081. case CPLB_NO_UNLOCKED:
  1082. printk(KERN_EMERG "All CPLBs are locked\n");
  1083. break;
  1084. case CPLB_PROT_VIOL:
  1085. return;
  1086. case CPLB_NO_ADDR_MATCH:
  1087. return;
  1088. case CPLB_UNKNOWN_ERR:
  1089. printk(KERN_EMERG "Unknown CPLB Exception\n");
  1090. break;
  1091. }
  1092. oops_in_progress = 1;
  1093. dump_bfin_process(fp);
  1094. dump_bfin_mem(fp);
  1095. show_regs(fp);
  1096. dump_stack();
  1097. panic("Unrecoverable event\n");
  1098. }