traps.c 26 KB

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