traps.c 26 KB

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