traps.c 19 KB

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