traps.c 37 KB

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