traps.c 20 KB

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