traps.c 23 KB

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