traps.c 38 KB

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