traps.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. /*
  2. * File: arch/blackfin/kernel/traps.c
  3. * Based on:
  4. * Author: Hamish Macdonald
  5. *
  6. * Created:
  7. * Description: uses S/W interrupt 15 for the system calls
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <linux/uaccess.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/module.h>
  32. #include <linux/kallsyms.h>
  33. #include <linux/fs.h>
  34. #include <asm/traps.h>
  35. #include <asm/cacheflush.h>
  36. #include <asm/blackfin.h>
  37. #include <asm/irq_handler.h>
  38. #include <linux/irq.h>
  39. #include <asm/trace.h>
  40. #include <asm/fixed_code.h>
  41. #ifdef CONFIG_KGDB
  42. # include <linux/debugger.h>
  43. # include <linux/kgdb.h>
  44. # define CHK_DEBUGGER_TRAP() \
  45. do { \
  46. CHK_DEBUGGER(trapnr, sig, info.si_code, fp, ); \
  47. } while (0)
  48. # define CHK_DEBUGGER_TRAP_MAYBE() \
  49. do { \
  50. if (kgdb_connected) \
  51. CHK_DEBUGGER_TRAP(); \
  52. } while (0)
  53. #else
  54. # define CHK_DEBUGGER_TRAP() do { } while (0)
  55. # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
  56. #endif
  57. /* Initiate the event table handler */
  58. void __init trap_init(void)
  59. {
  60. CSYNC();
  61. bfin_write_EVT3(trap);
  62. CSYNC();
  63. }
  64. int kstack_depth_to_print = 48;
  65. static void decode_address(char *buf, unsigned long address)
  66. {
  67. struct vm_list_struct *vml;
  68. struct task_struct *p;
  69. struct mm_struct *mm;
  70. unsigned long flags, offset;
  71. unsigned int in_exception = bfin_read_IPEND() & 0x10;
  72. #ifdef CONFIG_KALLSYMS
  73. unsigned long symsize;
  74. const char *symname;
  75. char *modname;
  76. char *delim = ":";
  77. char namebuf[128];
  78. /* look up the address and see if we are in kernel space */
  79. symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
  80. if (symname) {
  81. /* yeah! kernel space! */
  82. if (!modname)
  83. modname = delim = "";
  84. sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
  85. (void *)address, delim, modname, delim, symname,
  86. (unsigned long)offset);
  87. return;
  88. }
  89. #endif
  90. /* Problem in fixed code section? */
  91. if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
  92. sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
  93. return;
  94. }
  95. /* Problem somewhere before the kernel start address */
  96. if (address < CONFIG_BOOT_LOAD) {
  97. sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
  98. return;
  99. }
  100. /* looks like we're off in user-land, so let's walk all the
  101. * mappings of all our processes and see if we can't be a whee
  102. * bit more specific
  103. */
  104. write_lock_irqsave(&tasklist_lock, flags);
  105. for_each_process(p) {
  106. mm = (in_exception ? p->mm : get_task_mm(p));
  107. if (!mm)
  108. continue;
  109. vml = mm->context.vmlist;
  110. while (vml) {
  111. struct vm_area_struct *vma = vml->vma;
  112. if (address >= vma->vm_start && address < vma->vm_end) {
  113. char *name = p->comm;
  114. struct file *file = vma->vm_file;
  115. if (file) {
  116. char _tmpbuf[256];
  117. name = d_path(file->f_dentry,
  118. file->f_vfsmnt,
  119. _tmpbuf,
  120. sizeof(_tmpbuf));
  121. }
  122. /* FLAT does not have its text aligned to the start of
  123. * the map while FDPIC ELF does ...
  124. */
  125. if (current->mm &&
  126. (address > current->mm->start_code) &&
  127. (address < current->mm->end_code))
  128. offset = address - current->mm->start_code;
  129. else
  130. offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
  131. sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
  132. (void *)address, name, offset);
  133. if (!in_exception)
  134. mmput(mm);
  135. goto done;
  136. }
  137. vml = vml->next;
  138. }
  139. if (!in_exception)
  140. mmput(mm);
  141. }
  142. /* we were unable to find this address anywhere */
  143. sprintf(buf, "<0x%p> /* unknown address */", (void *)address);
  144. done:
  145. write_unlock_irqrestore(&tasklist_lock, flags);
  146. }
  147. asmlinkage void double_fault_c(struct pt_regs *fp)
  148. {
  149. console_verbose();
  150. oops_in_progress = 1;
  151. printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
  152. dump_bfin_process(fp);
  153. dump_bfin_mem((void *)fp->retx);
  154. show_regs(fp);
  155. panic("Double Fault - unrecoverable event\n");
  156. }
  157. asmlinkage void trap_c(struct pt_regs *fp)
  158. {
  159. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  160. int j;
  161. #endif
  162. int sig = 0;
  163. siginfo_t info;
  164. unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
  165. trace_buffer_save(j);
  166. /* Important - be very careful dereferncing pointers - will lead to
  167. * double faults if the stack has become corrupt
  168. */
  169. /* If the fault was caused by a kernel thread, or interrupt handler
  170. * we will kernel panic, so the system reboots.
  171. * If KGDB is enabled, don't set this for kernel breakpoints
  172. */
  173. if ((bfin_read_IPEND() & 0xFFC0)
  174. #ifdef CONFIG_KGDB
  175. && trapnr != VEC_EXCPT02
  176. #endif
  177. ){
  178. console_verbose();
  179. oops_in_progress = 1;
  180. } else if (current) {
  181. if (current->mm == NULL) {
  182. console_verbose();
  183. oops_in_progress = 1;
  184. }
  185. }
  186. /* trap_c() will be called for exceptions. During exceptions
  187. * processing, the pc value should be set with retx value.
  188. * With this change we can cleanup some code in signal.c- TODO
  189. */
  190. fp->orig_pc = fp->retx;
  191. /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
  192. trapnr, fp->ipend, fp->pc, fp->retx); */
  193. /* send the appropriate signal to the user program */
  194. switch (trapnr) {
  195. /* This table works in conjuction with the one in ./mach-common/entry.S
  196. * Some exceptions are handled there (in assembly, in exception space)
  197. * Some are handled here, (in C, in interrupt space)
  198. * Some, like CPLB, are handled in both, where the normal path is
  199. * handled in assembly/exception space, and the error path is handled
  200. * here
  201. */
  202. /* 0x00 - Linux Syscall, getting here is an error */
  203. /* 0x01 - userspace gdb breakpoint, handled here */
  204. case VEC_EXCPT01:
  205. info.si_code = TRAP_ILLTRAP;
  206. sig = SIGTRAP;
  207. CHK_DEBUGGER_TRAP_MAYBE();
  208. /* Check if this is a breakpoint in kernel space */
  209. if (fp->ipend & 0xffc0)
  210. return;
  211. else
  212. break;
  213. #ifdef CONFIG_KGDB
  214. case VEC_EXCPT02 : /* gdb connection */
  215. info.si_code = TRAP_ILLTRAP;
  216. sig = SIGTRAP;
  217. CHK_DEBUGGER_TRAP();
  218. return;
  219. #else
  220. /* 0x02 - User Defined, Caught by default */
  221. #endif
  222. /* 0x03 - User Defined, userspace stack overflow */
  223. case VEC_EXCPT03:
  224. info.si_code = SEGV_STACKFLOW;
  225. sig = SIGSEGV;
  226. printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
  227. CHK_DEBUGGER_TRAP();
  228. break;
  229. /* 0x04 - User Defined, Caught by default */
  230. /* 0x05 - User Defined, Caught by default */
  231. /* 0x06 - User Defined, Caught by default */
  232. /* 0x07 - User Defined, Caught by default */
  233. /* 0x08 - User Defined, Caught by default */
  234. /* 0x09 - User Defined, Caught by default */
  235. /* 0x0A - User Defined, Caught by default */
  236. /* 0x0B - User Defined, Caught by default */
  237. /* 0x0C - User Defined, Caught by default */
  238. /* 0x0D - User Defined, Caught by default */
  239. /* 0x0E - User Defined, Caught by default */
  240. /* 0x0F - User Defined, Caught by default */
  241. /* 0x10 HW Single step, handled here */
  242. case VEC_STEP:
  243. info.si_code = TRAP_STEP;
  244. sig = SIGTRAP;
  245. CHK_DEBUGGER_TRAP_MAYBE();
  246. /* Check if this is a single step in kernel space */
  247. if (fp->ipend & 0xffc0)
  248. return;
  249. else
  250. break;
  251. /* 0x11 - Trace Buffer Full, handled here */
  252. case VEC_OVFLOW:
  253. info.si_code = TRAP_TRACEFLOW;
  254. sig = SIGTRAP;
  255. printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
  256. CHK_DEBUGGER_TRAP();
  257. break;
  258. /* 0x12 - Reserved, Caught by default */
  259. /* 0x13 - Reserved, Caught by default */
  260. /* 0x14 - Reserved, Caught by default */
  261. /* 0x15 - Reserved, Caught by default */
  262. /* 0x16 - Reserved, Caught by default */
  263. /* 0x17 - Reserved, Caught by default */
  264. /* 0x18 - Reserved, Caught by default */
  265. /* 0x19 - Reserved, Caught by default */
  266. /* 0x1A - Reserved, Caught by default */
  267. /* 0x1B - Reserved, Caught by default */
  268. /* 0x1C - Reserved, Caught by default */
  269. /* 0x1D - Reserved, Caught by default */
  270. /* 0x1E - Reserved, Caught by default */
  271. /* 0x1F - Reserved, Caught by default */
  272. /* 0x20 - Reserved, Caught by default */
  273. /* 0x21 - Undefined Instruction, handled here */
  274. case VEC_UNDEF_I:
  275. info.si_code = ILL_ILLOPC;
  276. sig = SIGILL;
  277. printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
  278. CHK_DEBUGGER_TRAP();
  279. break;
  280. /* 0x22 - Illegal Instruction Combination, handled here */
  281. case VEC_ILGAL_I:
  282. info.si_code = ILL_ILLPARAOP;
  283. sig = SIGILL;
  284. printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
  285. CHK_DEBUGGER_TRAP();
  286. break;
  287. /* 0x23 - Data CPLB protection violation, handled here */
  288. case VEC_CPLB_VL:
  289. info.si_code = ILL_CPLB_VI;
  290. sig = SIGBUS;
  291. printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
  292. CHK_DEBUGGER_TRAP();
  293. break;
  294. /* 0x24 - Data access misaligned, handled here */
  295. case VEC_MISALI_D:
  296. info.si_code = BUS_ADRALN;
  297. sig = SIGBUS;
  298. printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
  299. CHK_DEBUGGER_TRAP();
  300. break;
  301. /* 0x25 - Unrecoverable Event, handled here */
  302. case VEC_UNCOV:
  303. info.si_code = ILL_ILLEXCPT;
  304. sig = SIGILL;
  305. printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
  306. CHK_DEBUGGER_TRAP();
  307. break;
  308. /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
  309. error case is handled here */
  310. case VEC_CPLB_M:
  311. info.si_code = BUS_ADRALN;
  312. sig = SIGBUS;
  313. printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
  314. CHK_DEBUGGER_TRAP();
  315. break;
  316. /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
  317. case VEC_CPLB_MHIT:
  318. info.si_code = ILL_CPLB_MULHIT;
  319. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  320. sig = SIGSEGV;
  321. printk(KERN_NOTICE "NULL pointer access (probably)\n");
  322. #else
  323. sig = SIGILL;
  324. printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
  325. #endif
  326. CHK_DEBUGGER_TRAP();
  327. break;
  328. /* 0x28 - Emulation Watchpoint, handled here */
  329. case VEC_WATCH:
  330. info.si_code = TRAP_WATCHPT;
  331. sig = SIGTRAP;
  332. pr_debug(EXC_0x28(KERN_DEBUG));
  333. CHK_DEBUGGER_TRAP_MAYBE();
  334. /* Check if this is a watchpoint in kernel space */
  335. if (fp->ipend & 0xffc0)
  336. return;
  337. else
  338. break;
  339. #ifdef CONFIG_BF535
  340. /* 0x29 - Instruction fetch access error (535 only) */
  341. case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
  342. info.si_code = BUS_OPFETCH;
  343. sig = SIGBUS;
  344. printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
  345. CHK_DEBUGGER_TRAP();
  346. break;
  347. #else
  348. /* 0x29 - Reserved, Caught by default */
  349. #endif
  350. /* 0x2A - Instruction fetch misaligned, handled here */
  351. case VEC_MISALI_I:
  352. info.si_code = BUS_ADRALN;
  353. sig = SIGBUS;
  354. printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
  355. CHK_DEBUGGER_TRAP();
  356. break;
  357. /* 0x2B - Instruction CPLB protection violation, handled here */
  358. case VEC_CPLB_I_VL:
  359. info.si_code = ILL_CPLB_VI;
  360. sig = SIGBUS;
  361. printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
  362. CHK_DEBUGGER_TRAP();
  363. break;
  364. /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
  365. case VEC_CPLB_I_M:
  366. info.si_code = ILL_CPLB_MISS;
  367. sig = SIGBUS;
  368. printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
  369. CHK_DEBUGGER_TRAP();
  370. break;
  371. /* 0x2D - Instruction CPLB Multiple Hits, handled here */
  372. case VEC_CPLB_I_MHIT:
  373. info.si_code = ILL_CPLB_MULHIT;
  374. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  375. sig = SIGSEGV;
  376. printk(KERN_NOTICE "Jump to address 0 - 0x0fff\n");
  377. #else
  378. sig = SIGILL;
  379. printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
  380. #endif
  381. CHK_DEBUGGER_TRAP();
  382. break;
  383. /* 0x2E - Illegal use of Supervisor Resource, handled here */
  384. case VEC_ILL_RES:
  385. info.si_code = ILL_PRVOPC;
  386. sig = SIGILL;
  387. printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
  388. CHK_DEBUGGER_TRAP();
  389. break;
  390. /* 0x2F - Reserved, Caught by default */
  391. /* 0x30 - Reserved, Caught by default */
  392. /* 0x31 - Reserved, Caught by default */
  393. /* 0x32 - Reserved, Caught by default */
  394. /* 0x33 - Reserved, Caught by default */
  395. /* 0x34 - Reserved, Caught by default */
  396. /* 0x35 - Reserved, Caught by default */
  397. /* 0x36 - Reserved, Caught by default */
  398. /* 0x37 - Reserved, Caught by default */
  399. /* 0x38 - Reserved, Caught by default */
  400. /* 0x39 - Reserved, Caught by default */
  401. /* 0x3A - Reserved, Caught by default */
  402. /* 0x3B - Reserved, Caught by default */
  403. /* 0x3C - Reserved, Caught by default */
  404. /* 0x3D - Reserved, Caught by default */
  405. /* 0x3E - Reserved, Caught by default */
  406. /* 0x3F - Reserved, Caught by default */
  407. case VEC_HWERR:
  408. info.si_code = BUS_ADRALN;
  409. sig = SIGBUS;
  410. switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
  411. /* System MMR Error */
  412. case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
  413. info.si_code = BUS_ADRALN;
  414. sig = SIGBUS;
  415. printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
  416. break;
  417. /* External Memory Addressing Error */
  418. case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
  419. info.si_code = BUS_ADRERR;
  420. sig = SIGBUS;
  421. printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
  422. break;
  423. /* Performance Monitor Overflow */
  424. case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
  425. printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
  426. break;
  427. /* RAISE 5 instruction */
  428. case (SEQSTAT_HWERRCAUSE_RAISE_5):
  429. printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
  430. break;
  431. default: /* Reserved */
  432. printk(KERN_NOTICE HWC_default(KERN_NOTICE));
  433. break;
  434. }
  435. CHK_DEBUGGER_TRAP();
  436. break;
  437. default:
  438. info.si_code = TRAP_ILLTRAP;
  439. sig = SIGTRAP;
  440. printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
  441. (fp->seqstat & SEQSTAT_EXCAUSE));
  442. CHK_DEBUGGER_TRAP();
  443. break;
  444. }
  445. BUG_ON(sig == 0);
  446. if (sig != SIGTRAP) {
  447. unsigned long stack;
  448. dump_bfin_process(fp);
  449. /* Is it an interrupt, or an exception? */
  450. if (trapnr == VEC_HWERR)
  451. dump_bfin_mem((void *)fp->pc);
  452. else
  453. dump_bfin_mem((void *)fp->retx);
  454. show_regs(fp);
  455. /* Print out the trace buffer if it makes sense */
  456. #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
  457. if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
  458. printk(KERN_NOTICE "No trace since you do not have "
  459. "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
  460. KERN_NOTICE "\n");
  461. else
  462. #endif
  463. dump_bfin_trace_buffer();
  464. show_stack(current, &stack);
  465. if (oops_in_progress) {
  466. #ifndef CONFIG_ACCESS_CHECK
  467. printk(KERN_EMERG "Please turn on "
  468. "CONFIG_ACCESS_CHECK\n");
  469. #endif
  470. panic("Kernel exception");
  471. }
  472. }
  473. info.si_signo = sig;
  474. info.si_errno = 0;
  475. info.si_addr = (void *)fp->pc;
  476. force_sig_info(sig, &info, current);
  477. trace_buffer_restore(j);
  478. return;
  479. }
  480. /* Typical exception handling routines */
  481. #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
  482. void dump_bfin_trace_buffer(void)
  483. {
  484. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  485. int tflags, i = 0;
  486. char buf[150];
  487. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  488. int j, index;
  489. #endif
  490. trace_buffer_save(tflags);
  491. printk(KERN_NOTICE "Hardware Trace:\n");
  492. if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
  493. for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
  494. decode_address(buf, (unsigned long)bfin_read_TBUF());
  495. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  496. decode_address(buf, (unsigned long)bfin_read_TBUF());
  497. printk(KERN_NOTICE " Source : %s\n", buf);
  498. }
  499. }
  500. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  501. if (trace_buff_offset)
  502. index = trace_buff_offset/4 - 1;
  503. else
  504. index = EXPAND_LEN;
  505. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  506. while (j) {
  507. decode_address(buf, software_trace_buff[index]);
  508. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  509. index -= 1;
  510. if (index < 0 )
  511. index = EXPAND_LEN;
  512. decode_address(buf, software_trace_buff[index]);
  513. printk(KERN_NOTICE " Source : %s\n", buf);
  514. index -= 1;
  515. if (index < 0)
  516. index = EXPAND_LEN;
  517. j--;
  518. i++;
  519. }
  520. #endif
  521. trace_buffer_restore(tflags);
  522. #endif
  523. }
  524. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  525. static void show_trace(struct task_struct *tsk, unsigned long *sp)
  526. {
  527. unsigned long addr;
  528. printk(KERN_NOTICE "\n" KERN_NOTICE "Call Trace:\n");
  529. while (!kstack_end(sp)) {
  530. addr = *sp++;
  531. /*
  532. * If the address is either in the text segment of the
  533. * kernel, or in the region which contains vmalloc'ed
  534. * memory, it *may* be the address of a calling
  535. * routine; if so, print it so that someone tracing
  536. * down the cause of the crash will be able to figure
  537. * out the call path that was taken.
  538. */
  539. if (kernel_text_address(addr))
  540. print_ip_sym(addr);
  541. }
  542. printk(KERN_NOTICE "\n");
  543. }
  544. void show_stack(struct task_struct *task, unsigned long *stack)
  545. {
  546. unsigned long *endstack, addr;
  547. int i;
  548. /* Cannot call dump_bfin_trace_buffer() here as show_stack() is
  549. * called externally in some places in the kernel.
  550. */
  551. if (!stack) {
  552. if (task)
  553. stack = (unsigned long *)task->thread.ksp;
  554. else
  555. stack = (unsigned long *)&stack;
  556. }
  557. addr = (unsigned long)stack;
  558. endstack = (unsigned long *)PAGE_ALIGN(addr);
  559. printk(KERN_NOTICE "Stack from %08lx:", (unsigned long)stack);
  560. for (i = 0; i < kstack_depth_to_print; i++) {
  561. if (stack + 1 > endstack)
  562. break;
  563. if (i % 8 == 0)
  564. printk("\n" KERN_NOTICE " ");
  565. printk(" %08lx", *stack++);
  566. }
  567. printk("\n");
  568. show_trace(task, stack);
  569. }
  570. void dump_stack(void)
  571. {
  572. unsigned long stack;
  573. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  574. int tflags;
  575. #endif
  576. trace_buffer_save(tflags);
  577. dump_bfin_trace_buffer();
  578. show_stack(current, &stack);
  579. trace_buffer_restore(tflags);
  580. }
  581. EXPORT_SYMBOL(dump_stack);
  582. void dump_bfin_process(struct pt_regs *fp)
  583. {
  584. /* We should be able to look at fp->ipend, but we don't push it on the
  585. * stack all the time, so do this until we fix that */
  586. unsigned int context = bfin_read_IPEND();
  587. if (oops_in_progress)
  588. printk(KERN_EMERG "Kernel OOPS in progress\n");
  589. if (context & 0x0020)
  590. printk(KERN_NOTICE "Deferred excecption or HW Error context\n");
  591. else if (context & 0x3FC0)
  592. printk(KERN_NOTICE "Interrupt context\n");
  593. else if (context & 0x4000)
  594. printk(KERN_NOTICE "Deferred Interrupt context\n");
  595. else if (context & 0x8000)
  596. printk(KERN_NOTICE "Kernel process context\n");
  597. if (current->pid && current->mm) {
  598. printk(KERN_NOTICE "CURRENT PROCESS:\n");
  599. printk(KERN_NOTICE "COMM=%s PID=%d\n",
  600. current->comm, current->pid);
  601. printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
  602. KERN_NOTICE "BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
  603. KERN_NOTICE "\n",
  604. (void *)current->mm->start_code,
  605. (void *)current->mm->end_code,
  606. (void *)current->mm->start_data,
  607. (void *)current->mm->end_data,
  608. (void *)current->mm->end_data,
  609. (void *)current->mm->brk,
  610. (void *)current->mm->start_stack);
  611. } else
  612. printk(KERN_NOTICE "\n" KERN_NOTICE
  613. "No Valid process in current context\n");
  614. }
  615. void dump_bfin_mem(void *retaddr)
  616. {
  617. if (retaddr >= (void *)FIXED_CODE_START && retaddr < (void *)physical_mem_end
  618. #if L1_CODE_LENGTH != 0
  619. /* FIXME: Copy the code out of L1 Instruction SRAM through dma
  620. memcpy. */
  621. && !(retaddr >= (void *)L1_CODE_START
  622. && retaddr < (void *)(L1_CODE_START + L1_CODE_LENGTH))
  623. #endif
  624. ) {
  625. int i = ((unsigned int)retaddr & 0xFFFFFFF0) - 32;
  626. unsigned short x = 0;
  627. printk(KERN_NOTICE "return address: [0x%p]; contents of:", retaddr);
  628. for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) {
  629. if (!(i & 0xF))
  630. printk("\n" KERN_NOTICE "0x%08x: ", i);
  631. if (get_user(x, (unsigned short *)i))
  632. break;
  633. #ifndef CONFIG_DEBUG_HWERR
  634. /* If one of the last few instructions was a STI
  635. * it is likely that the error occured awhile ago
  636. * and we just noticed. This only happens in kernel
  637. * context, which should mean an oops is happening
  638. */
  639. if (oops_in_progress && x >= 0x0040 && x <= 0x0047 && i <= 0)
  640. printk(KERN_EMERG "\n"
  641. KERN_EMERG "WARNING : You should reconfigure"
  642. " the kernel to turn on\n"
  643. KERN_EMERG " 'Hardware error interrupt debugging'\n"
  644. KERN_EMERG " The rest of this error is meanless\n");
  645. #endif
  646. if (i == (unsigned int)retaddr)
  647. printk("[%04x]", x);
  648. else
  649. printk(" %04x ", x);
  650. }
  651. printk("\n");
  652. } else
  653. printk("\n" KERN_NOTICE
  654. "Cannot look at the [PC] <%p> for it is"
  655. " in unreadable memory - sorry\n", retaddr);
  656. }
  657. void show_regs(struct pt_regs *fp)
  658. {
  659. char buf [150];
  660. struct irqaction *action;
  661. unsigned int i;
  662. unsigned long flags;
  663. printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\n");
  664. printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
  665. (long)fp->seqstat, fp->ipend, fp->syscfg);
  666. printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
  667. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  668. printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
  669. fp->seqstat & SEQSTAT_EXCAUSE);
  670. for (i = 6; i <= 15 ; i++) {
  671. if (fp->ipend & (1 << i)) {
  672. decode_address(buf, bfin_read32(EVT0 + 4*i));
  673. printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
  674. }
  675. }
  676. /* if no interrupts are going off, don't print this out */
  677. if (fp->ipend & ~0x3F) {
  678. for (i = 0; i < (NR_IRQS - 1); i++) {
  679. spin_lock_irqsave(&irq_desc[i].lock, flags);
  680. action = irq_desc[i].action;
  681. if (!action)
  682. goto unlock;
  683. decode_address(buf, (unsigned int)action->handler);
  684. printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
  685. for (action = action->next; action; action = action->next) {
  686. decode_address(buf, (unsigned int)action->handler);
  687. printk(", %s", buf);
  688. }
  689. printk("\n");
  690. unlock:
  691. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  692. }
  693. }
  694. decode_address(buf, fp->rete);
  695. printk(KERN_NOTICE " RETE: %s\n", buf);
  696. decode_address(buf, fp->retn);
  697. printk(KERN_NOTICE " RETN: %s\n", buf);
  698. decode_address(buf, fp->retx);
  699. printk(KERN_NOTICE " RETX: %s\n", buf);
  700. decode_address(buf, fp->rets);
  701. printk(KERN_NOTICE " RETS: %s\n", buf);
  702. decode_address(buf, fp->pc);
  703. printk(KERN_NOTICE " PC : %s\n", buf);
  704. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  705. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  706. decode_address(buf, bfin_read_DCPLB_FAULT_ADDR());
  707. printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
  708. decode_address(buf, bfin_read_ICPLB_FAULT_ADDR());
  709. printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
  710. }
  711. printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
  712. printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  713. fp->r0, fp->r1, fp->r2, fp->r3);
  714. printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  715. fp->r4, fp->r5, fp->r6, fp->r7);
  716. printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  717. fp->p0, fp->p1, fp->p2, fp->p3);
  718. printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  719. fp->p4, fp->p5, fp->fp, (long)fp);
  720. printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
  721. fp->lb0, fp->lt0, fp->lc0);
  722. printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
  723. fp->lb1, fp->lt1, fp->lc1);
  724. printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  725. fp->b0, fp->l0, fp->m0, fp->i0);
  726. printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  727. fp->b1, fp->l1, fp->m1, fp->i1);
  728. printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  729. fp->b2, fp->l2, fp->m2, fp->i2);
  730. printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  731. fp->b3, fp->l3, fp->m3, fp->i3);
  732. printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  733. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  734. printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
  735. rdusp(), fp->astat);
  736. printk(KERN_NOTICE "\n");
  737. }
  738. #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
  739. asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
  740. #endif
  741. asmlinkage int sys_bfin_spinlock(int *spinlock)
  742. {
  743. int ret = 0;
  744. int tmp = 0;
  745. local_irq_disable();
  746. ret = get_user(tmp, spinlock);
  747. if (ret == 0) {
  748. if (tmp)
  749. ret = 1;
  750. tmp = 1;
  751. put_user(tmp, spinlock);
  752. }
  753. local_irq_enable();
  754. return ret;
  755. }
  756. int bfin_request_exception(unsigned int exception, void (*handler)(void))
  757. {
  758. void (*curr_handler)(void);
  759. if (exception > 0x3F)
  760. return -EINVAL;
  761. curr_handler = ex_table[exception];
  762. if (curr_handler != ex_replaceable)
  763. return -EBUSY;
  764. ex_table[exception] = handler;
  765. return 0;
  766. }
  767. EXPORT_SYMBOL(bfin_request_exception);
  768. int bfin_free_exception(unsigned int exception, void (*handler)(void))
  769. {
  770. void (*curr_handler)(void);
  771. if (exception > 0x3F)
  772. return -EINVAL;
  773. curr_handler = ex_table[exception];
  774. if (curr_handler != handler)
  775. return -EBUSY;
  776. ex_table[exception] = ex_replaceable;
  777. return 0;
  778. }
  779. EXPORT_SYMBOL(bfin_free_exception);
  780. void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
  781. {
  782. switch (cplb_panic) {
  783. case CPLB_NO_UNLOCKED:
  784. printk(KERN_EMERG "All CPLBs are locked\n");
  785. break;
  786. case CPLB_PROT_VIOL:
  787. return;
  788. case CPLB_NO_ADDR_MATCH:
  789. return;
  790. case CPLB_UNKNOWN_ERR:
  791. printk(KERN_EMERG "Unknown CPLB Exception\n");
  792. break;
  793. }
  794. oops_in_progress = 1;
  795. printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", (void *)bfin_read_DCPLB_FAULT_ADDR());
  796. printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", (void *)bfin_read_ICPLB_FAULT_ADDR());
  797. dump_bfin_process(fp);
  798. dump_bfin_mem((void *)fp->retx);
  799. show_regs(fp);
  800. dump_stack();
  801. panic("Unrecoverable event\n");
  802. }