traps.c 22 KB

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