traps.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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. case VEC_HWERR:
  407. info.si_code = BUS_ADRALN;
  408. sig = SIGBUS;
  409. switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
  410. /* System MMR Error */
  411. case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
  412. info.si_code = BUS_ADRALN;
  413. sig = SIGBUS;
  414. printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
  415. break;
  416. /* External Memory Addressing Error */
  417. case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
  418. info.si_code = BUS_ADRERR;
  419. sig = SIGBUS;
  420. printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
  421. break;
  422. /* Performance Monitor Overflow */
  423. case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
  424. printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
  425. break;
  426. /* RAISE 5 instruction */
  427. case (SEQSTAT_HWERRCAUSE_RAISE_5):
  428. printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
  429. break;
  430. default: /* Reserved */
  431. printk(KERN_NOTICE HWC_default(KERN_NOTICE));
  432. break;
  433. }
  434. CHK_DEBUGGER_TRAP();
  435. break;
  436. default:
  437. info.si_code = TRAP_ILLTRAP;
  438. sig = SIGTRAP;
  439. printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
  440. (fp->seqstat & SEQSTAT_EXCAUSE));
  441. CHK_DEBUGGER_TRAP();
  442. break;
  443. }
  444. BUG_ON(sig == 0);
  445. if (sig != SIGTRAP) {
  446. unsigned long stack;
  447. dump_bfin_process(fp);
  448. /* Is it an interrupt, or an exception? */
  449. if (trapnr == VEC_HWERR)
  450. dump_bfin_mem((void *)fp->pc);
  451. else
  452. dump_bfin_mem((void *)fp->retx);
  453. show_regs(fp);
  454. /* Print out the trace buffer if it makes sense */
  455. #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
  456. if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
  457. printk(KERN_NOTICE "No trace since you do not have "
  458. "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
  459. KERN_NOTICE "\n");
  460. else
  461. #endif
  462. dump_bfin_trace_buffer();
  463. show_stack(current, &stack);
  464. if (oops_in_progress) {
  465. #ifndef CONFIG_ACCESS_CHECK
  466. printk(KERN_EMERG "Please turn on "
  467. "CONFIG_ACCESS_CHECK\n");
  468. #endif
  469. panic("Kernel exception");
  470. }
  471. }
  472. info.si_signo = sig;
  473. info.si_errno = 0;
  474. info.si_addr = (void *)fp->pc;
  475. force_sig_info(sig, &info, current);
  476. /* Ensure that bad return addresses don't end up in an infinite
  477. * loop, due to speculative loads/reads. This needs to be done after
  478. * the signal has been sent.
  479. */
  480. if (trapnr == VEC_CPLB_I_M && sig != SIGTRAP)
  481. fp->pc = SAFE_USER_INSTRUCTION;
  482. trace_buffer_restore(j);
  483. return;
  484. }
  485. /* Typical exception handling routines */
  486. #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
  487. void dump_bfin_trace_buffer(void)
  488. {
  489. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  490. int tflags, i = 0;
  491. char buf[150];
  492. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  493. int j, index;
  494. #endif
  495. trace_buffer_save(tflags);
  496. printk(KERN_NOTICE "Hardware Trace:\n");
  497. if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
  498. for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
  499. decode_address(buf, (unsigned long)bfin_read_TBUF());
  500. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  501. decode_address(buf, (unsigned long)bfin_read_TBUF());
  502. printk(KERN_NOTICE " Source : %s\n", buf);
  503. }
  504. }
  505. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  506. if (trace_buff_offset)
  507. index = trace_buff_offset/4 - 1;
  508. else
  509. index = EXPAND_LEN;
  510. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  511. while (j) {
  512. decode_address(buf, software_trace_buff[index]);
  513. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  514. index -= 1;
  515. if (index < 0 )
  516. index = EXPAND_LEN;
  517. decode_address(buf, software_trace_buff[index]);
  518. printk(KERN_NOTICE " Source : %s\n", buf);
  519. index -= 1;
  520. if (index < 0)
  521. index = EXPAND_LEN;
  522. j--;
  523. i++;
  524. }
  525. #endif
  526. trace_buffer_restore(tflags);
  527. #endif
  528. }
  529. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  530. static void show_trace(struct task_struct *tsk, unsigned long *sp)
  531. {
  532. unsigned long addr;
  533. printk(KERN_NOTICE "\n" KERN_NOTICE "Call Trace:\n");
  534. while (!kstack_end(sp)) {
  535. addr = *sp++;
  536. /*
  537. * If the address is either in the text segment of the
  538. * kernel, or in the region which contains vmalloc'ed
  539. * memory, it *may* be the address of a calling
  540. * routine; if so, print it so that someone tracing
  541. * down the cause of the crash will be able to figure
  542. * out the call path that was taken.
  543. */
  544. if (kernel_text_address(addr))
  545. print_ip_sym(addr);
  546. }
  547. printk(KERN_NOTICE "\n");
  548. }
  549. void show_stack(struct task_struct *task, unsigned long *stack)
  550. {
  551. unsigned long *endstack, addr;
  552. int i;
  553. /* Cannot call dump_bfin_trace_buffer() here as show_stack() is
  554. * called externally in some places in the kernel.
  555. */
  556. if (!stack) {
  557. if (task)
  558. stack = (unsigned long *)task->thread.ksp;
  559. else
  560. stack = (unsigned long *)&stack;
  561. }
  562. addr = (unsigned long)stack;
  563. endstack = (unsigned long *)PAGE_ALIGN(addr);
  564. printk(KERN_NOTICE "Stack from %08lx:", (unsigned long)stack);
  565. for (i = 0; i < kstack_depth_to_print; i++) {
  566. if (stack + 1 > endstack)
  567. break;
  568. if (i % 8 == 0)
  569. printk("\n" KERN_NOTICE " ");
  570. printk(" %08lx", *stack++);
  571. }
  572. printk("\n");
  573. show_trace(task, stack);
  574. }
  575. void dump_stack(void)
  576. {
  577. unsigned long stack;
  578. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  579. int tflags;
  580. #endif
  581. trace_buffer_save(tflags);
  582. dump_bfin_trace_buffer();
  583. show_stack(current, &stack);
  584. trace_buffer_restore(tflags);
  585. }
  586. EXPORT_SYMBOL(dump_stack);
  587. void dump_bfin_process(struct pt_regs *fp)
  588. {
  589. /* We should be able to look at fp->ipend, but we don't push it on the
  590. * stack all the time, so do this until we fix that */
  591. unsigned int context = bfin_read_IPEND();
  592. if (oops_in_progress)
  593. printk(KERN_EMERG "Kernel OOPS in progress\n");
  594. if (context & 0x0020)
  595. printk(KERN_NOTICE "Deferred excecption or HW Error context\n");
  596. else if (context & 0x3FC0)
  597. printk(KERN_NOTICE "Interrupt context\n");
  598. else if (context & 0x4000)
  599. printk(KERN_NOTICE "Deferred Interrupt context\n");
  600. else if (context & 0x8000)
  601. printk(KERN_NOTICE "Kernel process context\n");
  602. if (current->pid && current->mm) {
  603. printk(KERN_NOTICE "CURRENT PROCESS:\n");
  604. printk(KERN_NOTICE "COMM=%s PID=%d\n",
  605. current->comm, current->pid);
  606. printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
  607. KERN_NOTICE "BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
  608. KERN_NOTICE "\n",
  609. (void *)current->mm->start_code,
  610. (void *)current->mm->end_code,
  611. (void *)current->mm->start_data,
  612. (void *)current->mm->end_data,
  613. (void *)current->mm->end_data,
  614. (void *)current->mm->brk,
  615. (void *)current->mm->start_stack);
  616. } else
  617. printk(KERN_NOTICE "\n" KERN_NOTICE
  618. "No Valid process in current context\n");
  619. }
  620. void dump_bfin_mem(void *retaddr)
  621. {
  622. if (retaddr >= (void *)FIXED_CODE_START && retaddr < (void *)physical_mem_end
  623. #if L1_CODE_LENGTH != 0
  624. /* FIXME: Copy the code out of L1 Instruction SRAM through dma
  625. memcpy. */
  626. && !(retaddr >= (void *)L1_CODE_START
  627. && retaddr < (void *)(L1_CODE_START + L1_CODE_LENGTH))
  628. #endif
  629. ) {
  630. int i = ((unsigned int)retaddr & 0xFFFFFFF0) - 32;
  631. unsigned short x = 0;
  632. printk(KERN_NOTICE "return address: [0x%p]; contents of:", retaddr);
  633. for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) {
  634. if (!(i & 0xF))
  635. printk("\n" KERN_NOTICE "0x%08x: ", i);
  636. if (get_user(x, (unsigned short *)i))
  637. break;
  638. #ifndef CONFIG_DEBUG_HWERR
  639. /* If one of the last few instructions was a STI
  640. * it is likely that the error occured awhile ago
  641. * and we just noticed. This only happens in kernel
  642. * context, which should mean an oops is happening
  643. */
  644. if (oops_in_progress && x >= 0x0040 && x <= 0x0047 && i <= 0)
  645. printk(KERN_EMERG "\n"
  646. KERN_EMERG "WARNING : You should reconfigure"
  647. " the kernel to turn on\n"
  648. KERN_EMERG " 'Hardware error interrupt debugging'\n"
  649. KERN_EMERG " The rest of this error is meanless\n");
  650. #endif
  651. if (i == (unsigned int)retaddr)
  652. printk("[%04x]", x);
  653. else
  654. printk(" %04x ", x);
  655. }
  656. printk("\n");
  657. } else
  658. printk("\n" KERN_NOTICE
  659. "Cannot look at the [PC] <%p> for it is"
  660. " in unreadable memory - sorry\n", retaddr);
  661. }
  662. void show_regs(struct pt_regs *fp)
  663. {
  664. char buf [150];
  665. printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\n");
  666. printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
  667. (long)fp->seqstat, fp->ipend, fp->syscfg);
  668. printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
  669. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  670. printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
  671. fp->seqstat & SEQSTAT_EXCAUSE);
  672. decode_address(buf, fp->rete);
  673. printk(KERN_NOTICE " RETE: %s\n", buf);
  674. decode_address(buf, fp->retn);
  675. printk(KERN_NOTICE " RETN: %s\n", buf);
  676. decode_address(buf, fp->retx);
  677. printk(KERN_NOTICE " RETX: %s\n", buf);
  678. decode_address(buf, fp->rets);
  679. printk(KERN_NOTICE " RETS: %s\n", buf);
  680. decode_address(buf, fp->pc);
  681. printk(KERN_NOTICE " PC : %s\n", buf);
  682. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  683. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  684. decode_address(buf, bfin_read_DCPLB_FAULT_ADDR());
  685. printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
  686. decode_address(buf, bfin_read_ICPLB_FAULT_ADDR());
  687. printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
  688. }
  689. printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
  690. printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  691. fp->r0, fp->r1, fp->r2, fp->r3);
  692. printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  693. fp->r4, fp->r5, fp->r6, fp->r7);
  694. printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  695. fp->p0, fp->p1, fp->p2, fp->p3);
  696. printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  697. fp->p4, fp->p5, fp->fp, (long)fp);
  698. printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
  699. fp->lb0, fp->lt0, fp->lc0);
  700. printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
  701. fp->lb1, fp->lt1, fp->lc1);
  702. printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  703. fp->b0, fp->l0, fp->m0, fp->i0);
  704. printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  705. fp->b1, fp->l1, fp->m1, fp->i1);
  706. printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  707. fp->b2, fp->l2, fp->m2, fp->i2);
  708. printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  709. fp->b3, fp->l3, fp->m3, fp->i3);
  710. printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  711. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  712. printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
  713. rdusp(), fp->astat);
  714. printk(KERN_NOTICE "\n");
  715. }
  716. #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
  717. asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
  718. #endif
  719. asmlinkage int sys_bfin_spinlock(int *spinlock)
  720. {
  721. int ret = 0;
  722. int tmp = 0;
  723. local_irq_disable();
  724. ret = get_user(tmp, spinlock);
  725. if (ret == 0) {
  726. if (tmp)
  727. ret = 1;
  728. tmp = 1;
  729. put_user(tmp, spinlock);
  730. }
  731. local_irq_enable();
  732. return ret;
  733. }
  734. int bfin_request_exception(unsigned int exception, void (*handler)(void))
  735. {
  736. void (*curr_handler)(void);
  737. if (exception > 0x3F)
  738. return -EINVAL;
  739. curr_handler = ex_table[exception];
  740. if (curr_handler != ex_replaceable)
  741. return -EBUSY;
  742. ex_table[exception] = handler;
  743. return 0;
  744. }
  745. EXPORT_SYMBOL(bfin_request_exception);
  746. int bfin_free_exception(unsigned int exception, void (*handler)(void))
  747. {
  748. void (*curr_handler)(void);
  749. if (exception > 0x3F)
  750. return -EINVAL;
  751. curr_handler = ex_table[exception];
  752. if (curr_handler != handler)
  753. return -EBUSY;
  754. ex_table[exception] = ex_replaceable;
  755. return 0;
  756. }
  757. EXPORT_SYMBOL(bfin_free_exception);
  758. void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
  759. {
  760. switch (cplb_panic) {
  761. case CPLB_NO_UNLOCKED:
  762. printk(KERN_EMERG "All CPLBs are locked\n");
  763. break;
  764. case CPLB_PROT_VIOL:
  765. return;
  766. case CPLB_NO_ADDR_MATCH:
  767. return;
  768. case CPLB_UNKNOWN_ERR:
  769. printk(KERN_EMERG "Unknown CPLB Exception\n");
  770. break;
  771. }
  772. oops_in_progress = 1;
  773. printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", (void *)bfin_read_DCPLB_FAULT_ADDR());
  774. printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", (void *)bfin_read_ICPLB_FAULT_ADDR());
  775. dump_bfin_process(fp);
  776. dump_bfin_mem((void *)fp->retx);
  777. show_regs(fp);
  778. dump_stack();
  779. panic("Unrecoverable event\n");
  780. }