traps.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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/cplb.h>
  37. #include <asm/blackfin.h>
  38. #include <asm/irq_handler.h>
  39. #include <linux/irq.h>
  40. #include <asm/trace.h>
  41. #include <asm/fixed_code.h>
  42. #include <asm/dma.h>
  43. #ifdef CONFIG_KGDB
  44. # include <linux/kgdb.h>
  45. # define CHK_DEBUGGER_TRAP() \
  46. do { \
  47. kgdb_handle_exception(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. /*
  66. * Used to save the RETX, SEQSTAT, I/D CPLB FAULT ADDR
  67. * values across the transition from exception to IRQ5.
  68. * We put these in L1, so they are going to be in a valid
  69. * location during exception context
  70. */
  71. __attribute__((l1_data))
  72. unsigned long saved_retx, saved_seqstat,
  73. saved_icplb_fault_addr, saved_dcplb_fault_addr;
  74. static void decode_address(char *buf, unsigned long address)
  75. {
  76. struct vm_list_struct *vml;
  77. struct task_struct *p;
  78. struct mm_struct *mm;
  79. unsigned long flags, offset;
  80. unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
  81. #ifdef CONFIG_KALLSYMS
  82. unsigned long symsize;
  83. const char *symname;
  84. char *modname;
  85. char *delim = ":";
  86. char namebuf[128];
  87. /* look up the address and see if we are in kernel space */
  88. symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
  89. if (symname) {
  90. /* yeah! kernel space! */
  91. if (!modname)
  92. modname = delim = "";
  93. sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
  94. (void *)address, delim, modname, delim, symname,
  95. (unsigned long)offset);
  96. return;
  97. }
  98. #endif
  99. /* Problem in fixed code section? */
  100. if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
  101. sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
  102. return;
  103. }
  104. /* Problem somewhere before the kernel start address */
  105. if (address < CONFIG_BOOT_LOAD) {
  106. sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
  107. return;
  108. }
  109. /* looks like we're off in user-land, so let's walk all the
  110. * mappings of all our processes and see if we can't be a whee
  111. * bit more specific
  112. */
  113. write_lock_irqsave(&tasklist_lock, flags);
  114. for_each_process(p) {
  115. mm = (in_atomic ? p->mm : get_task_mm(p));
  116. if (!mm)
  117. continue;
  118. vml = mm->context.vmlist;
  119. while (vml) {
  120. struct vm_area_struct *vma = vml->vma;
  121. if (address >= vma->vm_start && address < vma->vm_end) {
  122. char _tmpbuf[256];
  123. char *name = p->comm;
  124. struct file *file = vma->vm_file;
  125. if (file)
  126. name = d_path(&file->f_path, _tmpbuf,
  127. sizeof(_tmpbuf));
  128. /* FLAT does not have its text aligned to the start of
  129. * the map while FDPIC ELF does ...
  130. */
  131. /* before we can check flat/fdpic, we need to
  132. * make sure current is valid
  133. */
  134. if ((unsigned long)current >= FIXED_CODE_START &&
  135. !((unsigned long)current & 0x3)) {
  136. if (current->mm &&
  137. (address > current->mm->start_code) &&
  138. (address < current->mm->end_code))
  139. offset = address - current->mm->start_code;
  140. else
  141. offset = (address - vma->vm_start) +
  142. (vma->vm_pgoff << PAGE_SHIFT);
  143. sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
  144. (void *)address, name, offset);
  145. } else
  146. sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
  147. (void *)address, name,
  148. vma->vm_start, vma->vm_end);
  149. if (!in_atomic)
  150. mmput(mm);
  151. if (!strlen(buf))
  152. sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
  153. goto done;
  154. }
  155. vml = vml->next;
  156. }
  157. if (!in_atomic)
  158. mmput(mm);
  159. }
  160. /* we were unable to find this address anywhere */
  161. sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
  162. done:
  163. write_unlock_irqrestore(&tasklist_lock, flags);
  164. }
  165. asmlinkage void double_fault_c(struct pt_regs *fp)
  166. {
  167. console_verbose();
  168. oops_in_progress = 1;
  169. printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
  170. #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
  171. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
  172. char buf[150];
  173. decode_address(buf, saved_retx);
  174. printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
  175. (int)saved_seqstat & SEQSTAT_EXCAUSE, buf);
  176. decode_address(buf, saved_dcplb_fault_addr);
  177. printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
  178. decode_address(buf, saved_icplb_fault_addr);
  179. printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
  180. decode_address(buf, fp->retx);
  181. printk(KERN_NOTICE "The instruction at %s caused a double exception\n",
  182. buf);
  183. } else
  184. #endif
  185. {
  186. dump_bfin_process(fp);
  187. dump_bfin_mem(fp);
  188. show_regs(fp);
  189. }
  190. panic("Double Fault - unrecoverable event\n");
  191. }
  192. asmlinkage void trap_c(struct pt_regs *fp)
  193. {
  194. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  195. int j;
  196. #endif
  197. int sig = 0;
  198. siginfo_t info;
  199. unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
  200. trace_buffer_save(j);
  201. /* Important - be very careful dereferncing pointers - will lead to
  202. * double faults if the stack has become corrupt
  203. */
  204. /* If the fault was caused by a kernel thread, or interrupt handler
  205. * we will kernel panic, so the system reboots.
  206. * If KGDB is enabled, don't set this for kernel breakpoints
  207. */
  208. /* TODO: check to see if we are in some sort of deferred HWERR
  209. * that we should be able to recover from, not kernel panic
  210. */
  211. if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
  212. #ifdef CONFIG_KGDB
  213. && (trapnr != VEC_EXCPT02)
  214. #endif
  215. ){
  216. console_verbose();
  217. oops_in_progress = 1;
  218. } else if (current) {
  219. if (current->mm == NULL) {
  220. console_verbose();
  221. oops_in_progress = 1;
  222. }
  223. }
  224. /* trap_c() will be called for exceptions. During exceptions
  225. * processing, the pc value should be set with retx value.
  226. * With this change we can cleanup some code in signal.c- TODO
  227. */
  228. fp->orig_pc = fp->retx;
  229. /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
  230. trapnr, fp->ipend, fp->pc, fp->retx); */
  231. /* send the appropriate signal to the user program */
  232. switch (trapnr) {
  233. /* This table works in conjuction with the one in ./mach-common/entry.S
  234. * Some exceptions are handled there (in assembly, in exception space)
  235. * Some are handled here, (in C, in interrupt space)
  236. * Some, like CPLB, are handled in both, where the normal path is
  237. * handled in assembly/exception space, and the error path is handled
  238. * here
  239. */
  240. /* 0x00 - Linux Syscall, getting here is an error */
  241. /* 0x01 - userspace gdb breakpoint, handled here */
  242. case VEC_EXCPT01:
  243. info.si_code = TRAP_ILLTRAP;
  244. sig = SIGTRAP;
  245. CHK_DEBUGGER_TRAP_MAYBE();
  246. /* Check if this is a breakpoint in kernel space */
  247. if (fp->ipend & 0xffc0)
  248. return;
  249. else
  250. break;
  251. #ifdef CONFIG_KGDB
  252. case VEC_EXCPT02 : /* gdb connection */
  253. info.si_code = TRAP_ILLTRAP;
  254. sig = SIGTRAP;
  255. CHK_DEBUGGER_TRAP();
  256. return;
  257. #else
  258. /* 0x02 - User Defined, Caught by default */
  259. #endif
  260. /* 0x03 - User Defined, userspace stack overflow */
  261. case VEC_EXCPT03:
  262. info.si_code = SEGV_STACKFLOW;
  263. sig = SIGSEGV;
  264. printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
  265. CHK_DEBUGGER_TRAP_MAYBE();
  266. break;
  267. /* 0x04 - User Defined, Caught by default */
  268. /* 0x05 - User Defined, Caught by default */
  269. /* 0x06 - User Defined, Caught by default */
  270. /* 0x07 - User Defined, Caught by default */
  271. /* 0x08 - User Defined, Caught by default */
  272. /* 0x09 - User Defined, Caught by default */
  273. /* 0x0A - User Defined, Caught by default */
  274. /* 0x0B - User Defined, Caught by default */
  275. /* 0x0C - User Defined, Caught by default */
  276. /* 0x0D - User Defined, Caught by default */
  277. /* 0x0E - User Defined, Caught by default */
  278. /* 0x0F - User Defined, Caught by default */
  279. /* 0x10 HW Single step, handled here */
  280. case VEC_STEP:
  281. info.si_code = TRAP_STEP;
  282. sig = SIGTRAP;
  283. CHK_DEBUGGER_TRAP_MAYBE();
  284. /* Check if this is a single step in kernel space */
  285. if (fp->ipend & 0xffc0)
  286. return;
  287. else
  288. break;
  289. /* 0x11 - Trace Buffer Full, handled here */
  290. case VEC_OVFLOW:
  291. info.si_code = TRAP_TRACEFLOW;
  292. sig = SIGTRAP;
  293. printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
  294. CHK_DEBUGGER_TRAP_MAYBE();
  295. break;
  296. /* 0x12 - Reserved, Caught by default */
  297. /* 0x13 - Reserved, Caught by default */
  298. /* 0x14 - Reserved, Caught by default */
  299. /* 0x15 - Reserved, Caught by default */
  300. /* 0x16 - Reserved, Caught by default */
  301. /* 0x17 - Reserved, Caught by default */
  302. /* 0x18 - Reserved, Caught by default */
  303. /* 0x19 - Reserved, Caught by default */
  304. /* 0x1A - Reserved, Caught by default */
  305. /* 0x1B - Reserved, Caught by default */
  306. /* 0x1C - Reserved, Caught by default */
  307. /* 0x1D - Reserved, Caught by default */
  308. /* 0x1E - Reserved, Caught by default */
  309. /* 0x1F - Reserved, Caught by default */
  310. /* 0x20 - Reserved, Caught by default */
  311. /* 0x21 - Undefined Instruction, handled here */
  312. case VEC_UNDEF_I:
  313. info.si_code = ILL_ILLOPC;
  314. sig = SIGILL;
  315. printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
  316. CHK_DEBUGGER_TRAP_MAYBE();
  317. break;
  318. /* 0x22 - Illegal Instruction Combination, handled here */
  319. case VEC_ILGAL_I:
  320. info.si_code = ILL_ILLPARAOP;
  321. sig = SIGILL;
  322. printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
  323. CHK_DEBUGGER_TRAP_MAYBE();
  324. break;
  325. /* 0x23 - Data CPLB protection violation, handled here */
  326. case VEC_CPLB_VL:
  327. info.si_code = ILL_CPLB_VI;
  328. sig = SIGBUS;
  329. printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
  330. CHK_DEBUGGER_TRAP_MAYBE();
  331. break;
  332. /* 0x24 - Data access misaligned, handled here */
  333. case VEC_MISALI_D:
  334. info.si_code = BUS_ADRALN;
  335. sig = SIGBUS;
  336. printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
  337. CHK_DEBUGGER_TRAP_MAYBE();
  338. break;
  339. /* 0x25 - Unrecoverable Event, handled here */
  340. case VEC_UNCOV:
  341. info.si_code = ILL_ILLEXCPT;
  342. sig = SIGILL;
  343. printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
  344. CHK_DEBUGGER_TRAP_MAYBE();
  345. break;
  346. /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
  347. error case is handled here */
  348. case VEC_CPLB_M:
  349. info.si_code = BUS_ADRALN;
  350. sig = SIGBUS;
  351. printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
  352. break;
  353. /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
  354. case VEC_CPLB_MHIT:
  355. info.si_code = ILL_CPLB_MULHIT;
  356. sig = SIGSEGV;
  357. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  358. if (saved_dcplb_fault_addr < FIXED_CODE_START)
  359. printk(KERN_NOTICE "NULL pointer access\n");
  360. else
  361. #endif
  362. printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
  363. CHK_DEBUGGER_TRAP_MAYBE();
  364. break;
  365. /* 0x28 - Emulation Watchpoint, handled here */
  366. case VEC_WATCH:
  367. info.si_code = TRAP_WATCHPT;
  368. sig = SIGTRAP;
  369. pr_debug(EXC_0x28(KERN_DEBUG));
  370. CHK_DEBUGGER_TRAP_MAYBE();
  371. /* Check if this is a watchpoint in kernel space */
  372. if (fp->ipend & 0xffc0)
  373. return;
  374. else
  375. break;
  376. #ifdef CONFIG_BF535
  377. /* 0x29 - Instruction fetch access error (535 only) */
  378. case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
  379. info.si_code = BUS_OPFETCH;
  380. sig = SIGBUS;
  381. printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
  382. CHK_DEBUGGER_TRAP_MAYBE();
  383. break;
  384. #else
  385. /* 0x29 - Reserved, Caught by default */
  386. #endif
  387. /* 0x2A - Instruction fetch misaligned, handled here */
  388. case VEC_MISALI_I:
  389. info.si_code = BUS_ADRALN;
  390. sig = SIGBUS;
  391. printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
  392. CHK_DEBUGGER_TRAP_MAYBE();
  393. break;
  394. /* 0x2B - Instruction CPLB protection violation, handled here */
  395. case VEC_CPLB_I_VL:
  396. info.si_code = ILL_CPLB_VI;
  397. sig = SIGBUS;
  398. printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
  399. CHK_DEBUGGER_TRAP_MAYBE();
  400. break;
  401. /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
  402. case VEC_CPLB_I_M:
  403. info.si_code = ILL_CPLB_MISS;
  404. sig = SIGBUS;
  405. printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
  406. break;
  407. /* 0x2D - Instruction CPLB Multiple Hits, handled here */
  408. case VEC_CPLB_I_MHIT:
  409. info.si_code = ILL_CPLB_MULHIT;
  410. sig = SIGSEGV;
  411. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  412. if (saved_icplb_fault_addr < FIXED_CODE_START)
  413. printk(KERN_NOTICE "Jump to NULL address\n");
  414. else
  415. #endif
  416. printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
  417. CHK_DEBUGGER_TRAP_MAYBE();
  418. break;
  419. /* 0x2E - Illegal use of Supervisor Resource, handled here */
  420. case VEC_ILL_RES:
  421. info.si_code = ILL_PRVOPC;
  422. sig = SIGILL;
  423. printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
  424. CHK_DEBUGGER_TRAP_MAYBE();
  425. break;
  426. /* 0x2F - Reserved, Caught by default */
  427. /* 0x30 - Reserved, Caught by default */
  428. /* 0x31 - Reserved, Caught by default */
  429. /* 0x32 - Reserved, Caught by default */
  430. /* 0x33 - Reserved, Caught by default */
  431. /* 0x34 - Reserved, Caught by default */
  432. /* 0x35 - Reserved, Caught by default */
  433. /* 0x36 - Reserved, Caught by default */
  434. /* 0x37 - Reserved, Caught by default */
  435. /* 0x38 - Reserved, Caught by default */
  436. /* 0x39 - Reserved, Caught by default */
  437. /* 0x3A - Reserved, Caught by default */
  438. /* 0x3B - Reserved, Caught by default */
  439. /* 0x3C - Reserved, Caught by default */
  440. /* 0x3D - Reserved, Caught by default */
  441. /* 0x3E - Reserved, Caught by default */
  442. /* 0x3F - Reserved, Caught by default */
  443. case VEC_HWERR:
  444. info.si_code = BUS_ADRALN;
  445. sig = SIGBUS;
  446. switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
  447. /* System MMR Error */
  448. case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
  449. info.si_code = BUS_ADRALN;
  450. sig = SIGBUS;
  451. printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
  452. break;
  453. /* External Memory Addressing Error */
  454. case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
  455. info.si_code = BUS_ADRERR;
  456. sig = SIGBUS;
  457. printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
  458. break;
  459. /* Performance Monitor Overflow */
  460. case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
  461. printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
  462. break;
  463. /* RAISE 5 instruction */
  464. case (SEQSTAT_HWERRCAUSE_RAISE_5):
  465. printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
  466. break;
  467. default: /* Reserved */
  468. printk(KERN_NOTICE HWC_default(KERN_NOTICE));
  469. break;
  470. }
  471. CHK_DEBUGGER_TRAP_MAYBE();
  472. break;
  473. default:
  474. info.si_code = TRAP_ILLTRAP;
  475. sig = SIGTRAP;
  476. printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
  477. (fp->seqstat & SEQSTAT_EXCAUSE));
  478. CHK_DEBUGGER_TRAP_MAYBE();
  479. break;
  480. }
  481. BUG_ON(sig == 0);
  482. if (sig != SIGTRAP) {
  483. unsigned long *stack;
  484. dump_bfin_process(fp);
  485. dump_bfin_mem(fp);
  486. show_regs(fp);
  487. /* Print out the trace buffer if it makes sense */
  488. #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
  489. if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
  490. printk(KERN_NOTICE "No trace since you do not have "
  491. "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
  492. KERN_NOTICE "\n");
  493. else
  494. #endif
  495. dump_bfin_trace_buffer();
  496. if (oops_in_progress) {
  497. /* Dump the current kernel stack */
  498. printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
  499. show_stack(current, NULL);
  500. print_modules();
  501. #ifndef CONFIG_ACCESS_CHECK
  502. printk(KERN_EMERG "Please turn on "
  503. "CONFIG_ACCESS_CHECK\n");
  504. #endif
  505. panic("Kernel exception");
  506. } else {
  507. /* Dump the user space stack */
  508. stack = (unsigned long *)rdusp();
  509. printk(KERN_NOTICE "Userspace Stack\n");
  510. show_stack(NULL, stack);
  511. }
  512. }
  513. info.si_signo = sig;
  514. info.si_errno = 0;
  515. info.si_addr = (void __user *)fp->pc;
  516. force_sig_info(sig, &info, current);
  517. trace_buffer_restore(j);
  518. return;
  519. }
  520. /* Typical exception handling routines */
  521. #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
  522. /*
  523. * Similar to get_user, do some address checking, then dereference
  524. * Return true on sucess, false on bad address
  525. */
  526. bool get_instruction(unsigned short *val, unsigned short *address)
  527. {
  528. unsigned long addr;
  529. addr = (unsigned long)address;
  530. /* Check for odd addresses */
  531. if (addr & 0x1)
  532. return false;
  533. /* Check that things do not wrap around */
  534. if (addr > (addr + 2))
  535. return false;
  536. /*
  537. * Since we are in exception context, we need to do a little address checking
  538. * We need to make sure we are only accessing valid memory, and
  539. * we don't read something in the async space that can hang forever
  540. */
  541. if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
  542. #if L2_LENGTH != 0
  543. (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
  544. #endif
  545. (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
  546. #if L1_DATA_A_LENGTH != 0
  547. (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
  548. #endif
  549. #if L1_DATA_B_LENGTH != 0
  550. (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
  551. #endif
  552. (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
  553. (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
  554. addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
  555. (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
  556. addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
  557. (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
  558. addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
  559. (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
  560. addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
  561. *val = *address;
  562. return true;
  563. }
  564. #if L1_CODE_LENGTH != 0
  565. if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
  566. dma_memcpy(val, address, 2);
  567. return true;
  568. }
  569. #endif
  570. return false;
  571. }
  572. /*
  573. * decode the instruction if we are printing out the trace, as it
  574. * makes things easier to follow, without running it through objdump
  575. * These are the normal instructions which cause change of flow, which
  576. * would be at the source of the trace buffer
  577. */
  578. void decode_instruction(unsigned short *address)
  579. {
  580. unsigned short opcode;
  581. if (get_instruction(&opcode, address)) {
  582. if (opcode == 0x0010)
  583. printk("RTS");
  584. else if (opcode == 0x0011)
  585. printk("RTI");
  586. else if (opcode == 0x0012)
  587. printk("RTX");
  588. else if (opcode >= 0x0050 && opcode <= 0x0057)
  589. printk("JUMP (P%i)", opcode & 7);
  590. else if (opcode >= 0x0060 && opcode <= 0x0067)
  591. printk("CALL (P%i)", opcode & 7);
  592. else if (opcode >= 0x0070 && opcode <= 0x0077)
  593. printk("CALL (PC+P%i)", opcode & 7);
  594. else if (opcode >= 0x0080 && opcode <= 0x0087)
  595. printk("JUMP (PC+P%i)", opcode & 7);
  596. else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
  597. printk("IF !CC JUMP");
  598. else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
  599. printk("IF CC JUMP");
  600. else if (opcode >= 0x2000 && opcode <= 0x2fff)
  601. printk("JUMP.S");
  602. else if (opcode >= 0xe080 && opcode <= 0xe0ff)
  603. printk("LSETUP");
  604. else if (opcode >= 0xe200 && opcode <= 0xe2ff)
  605. printk("JUMP.L");
  606. else if (opcode >= 0xe300 && opcode <= 0xe3ff)
  607. printk("CALL pcrel");
  608. else
  609. printk("0x%04x", opcode);
  610. }
  611. }
  612. void dump_bfin_trace_buffer(void)
  613. {
  614. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  615. int tflags, i = 0;
  616. char buf[150];
  617. unsigned short *addr;
  618. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  619. int j, index;
  620. #endif
  621. trace_buffer_save(tflags);
  622. printk(KERN_NOTICE "Hardware Trace:\n");
  623. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  624. printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
  625. #endif
  626. if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
  627. for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
  628. decode_address(buf, (unsigned long)bfin_read_TBUF());
  629. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  630. addr = (unsigned short *)bfin_read_TBUF();
  631. decode_address(buf, (unsigned long)addr);
  632. printk(KERN_NOTICE " Source : %s ", buf);
  633. decode_instruction(addr);
  634. printk("\n");
  635. }
  636. }
  637. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  638. if (trace_buff_offset)
  639. index = trace_buff_offset / 4;
  640. else
  641. index = EXPAND_LEN;
  642. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  643. while (j) {
  644. decode_address(buf, software_trace_buff[index]);
  645. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  646. index -= 1;
  647. if (index < 0 )
  648. index = EXPAND_LEN;
  649. decode_address(buf, software_trace_buff[index]);
  650. printk(KERN_NOTICE " Source : %s ", buf);
  651. decode_instruction((unsigned short *)software_trace_buff[index]);
  652. printk("\n");
  653. index -= 1;
  654. if (index < 0)
  655. index = EXPAND_LEN;
  656. j--;
  657. i++;
  658. }
  659. #endif
  660. trace_buffer_restore(tflags);
  661. #endif
  662. }
  663. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  664. /*
  665. * Checks to see if the address pointed to is either a
  666. * 16-bit CALL instruction, or a 32-bit CALL instruction
  667. */
  668. bool is_bfin_call(unsigned short *addr)
  669. {
  670. unsigned short opcode = 0, *ins_addr;
  671. ins_addr = (unsigned short *)addr;
  672. if (!get_instruction(&opcode, ins_addr))
  673. return false;
  674. if ((opcode >= 0x0060 && opcode <= 0x0067) ||
  675. (opcode >= 0x0070 && opcode <= 0x0077))
  676. return true;
  677. ins_addr--;
  678. if (!get_instruction(&opcode, ins_addr))
  679. return false;
  680. if (opcode >= 0xE300 && opcode <= 0xE3FF)
  681. return true;
  682. return false;
  683. }
  684. void show_stack(struct task_struct *task, unsigned long *stack)
  685. {
  686. unsigned int *addr, *endstack, *fp = 0, *frame;
  687. unsigned short *ins_addr;
  688. char buf[150];
  689. unsigned int i, j, ret_addr, frame_no = 0;
  690. /*
  691. * If we have been passed a specific stack, use that one otherwise
  692. * if we have been passed a task structure, use that, otherwise
  693. * use the stack of where the variable "stack" exists
  694. */
  695. if (stack == NULL) {
  696. if (task) {
  697. /* We know this is a kernel stack, so this is the start/end */
  698. stack = (unsigned long *)task->thread.ksp;
  699. endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
  700. } else {
  701. /* print out the existing stack info */
  702. stack = (unsigned long *)&stack;
  703. endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
  704. }
  705. } else
  706. endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
  707. decode_address(buf, (unsigned int)stack);
  708. printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
  709. addr = (unsigned int *)((unsigned int)stack & ~0x3F);
  710. /* First thing is to look for a frame pointer */
  711. for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
  712. addr < endstack; addr++, i++) {
  713. if (*addr & 0x1)
  714. continue;
  715. ins_addr = (unsigned short *)*addr;
  716. ins_addr--;
  717. if (is_bfin_call(ins_addr))
  718. fp = addr - 1;
  719. if (fp) {
  720. /* Let's check to see if it is a frame pointer */
  721. while (fp >= (addr - 1) && fp < endstack && fp)
  722. fp = (unsigned int *)*fp;
  723. if (fp == 0 || fp == endstack) {
  724. fp = addr - 1;
  725. break;
  726. }
  727. fp = 0;
  728. }
  729. }
  730. if (fp) {
  731. frame = fp;
  732. printk(" FP: (0x%p)\n", fp);
  733. } else
  734. frame = 0;
  735. /*
  736. * Now that we think we know where things are, we
  737. * walk the stack again, this time printing things out
  738. * incase there is no frame pointer, we still look for
  739. * valid return addresses
  740. */
  741. /* First time print out data, next time, print out symbols */
  742. for (j = 0; j <= 1; j++) {
  743. if (j)
  744. printk(KERN_NOTICE "Return addresses in stack:\n");
  745. else
  746. printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
  747. fp = frame;
  748. frame_no = 0;
  749. for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
  750. addr <= endstack; addr++, i++) {
  751. ret_addr = 0;
  752. if (!j && i % 8 == 0)
  753. printk("\n" KERN_NOTICE "%p:",addr);
  754. /* if it is an odd address, or zero, just skip it */
  755. if (*addr & 0x1 || !*addr)
  756. goto print;
  757. ins_addr = (unsigned short *)*addr;
  758. /* Go back one instruction, and see if it is a CALL */
  759. ins_addr--;
  760. ret_addr = is_bfin_call(ins_addr);
  761. print:
  762. if (!j && stack == (unsigned long *)addr)
  763. printk("[%08x]", *addr);
  764. else if (ret_addr)
  765. if (j) {
  766. decode_address(buf, (unsigned int)*addr);
  767. if (frame == addr) {
  768. printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
  769. continue;
  770. }
  771. printk(KERN_NOTICE " address : %s\n", buf);
  772. } else
  773. printk("<%08x>", *addr);
  774. else if (fp == addr) {
  775. if (j)
  776. frame = addr+1;
  777. else
  778. printk("(%08x)", *addr);
  779. fp = (unsigned int *)*addr;
  780. frame_no++;
  781. } else if (!j)
  782. printk(" %08x ", *addr);
  783. }
  784. if (!j)
  785. printk("\n");
  786. }
  787. }
  788. void dump_stack(void)
  789. {
  790. unsigned long stack;
  791. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  792. int tflags;
  793. #endif
  794. trace_buffer_save(tflags);
  795. dump_bfin_trace_buffer();
  796. show_stack(current, &stack);
  797. trace_buffer_restore(tflags);
  798. }
  799. EXPORT_SYMBOL(dump_stack);
  800. void dump_bfin_process(struct pt_regs *fp)
  801. {
  802. /* We should be able to look at fp->ipend, but we don't push it on the
  803. * stack all the time, so do this until we fix that */
  804. unsigned int context = bfin_read_IPEND();
  805. if (oops_in_progress)
  806. printk(KERN_EMERG "Kernel OOPS in progress\n");
  807. if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
  808. printk(KERN_NOTICE "HW Error context\n");
  809. else if (context & 0x0020)
  810. printk(KERN_NOTICE "Deferred Exception context\n");
  811. else if (context & 0x3FC0)
  812. printk(KERN_NOTICE "Interrupt context\n");
  813. else if (context & 0x4000)
  814. printk(KERN_NOTICE "Deferred Interrupt context\n");
  815. else if (context & 0x8000)
  816. printk(KERN_NOTICE "Kernel process context\n");
  817. /* Because we are crashing, and pointers could be bad, we check things
  818. * pretty closely before we use them
  819. */
  820. if ((unsigned long)current >= FIXED_CODE_START &&
  821. !((unsigned long)current & 0x3) && current->pid) {
  822. printk(KERN_NOTICE "CURRENT PROCESS:\n");
  823. if (current->comm >= (char *)FIXED_CODE_START)
  824. printk(KERN_NOTICE "COMM=%s PID=%d\n",
  825. current->comm, current->pid);
  826. else
  827. printk(KERN_NOTICE "COMM= invalid\n");
  828. if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
  829. printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
  830. KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
  831. KERN_NOTICE "\n",
  832. (void *)current->mm->start_code,
  833. (void *)current->mm->end_code,
  834. (void *)current->mm->start_data,
  835. (void *)current->mm->end_data,
  836. (void *)current->mm->end_data,
  837. (void *)current->mm->brk,
  838. (void *)current->mm->start_stack);
  839. else
  840. printk(KERN_NOTICE "invalid mm\n");
  841. } else
  842. printk(KERN_NOTICE "\n" KERN_NOTICE
  843. "No Valid process in current context\n");
  844. }
  845. void dump_bfin_mem(struct pt_regs *fp)
  846. {
  847. unsigned short *addr, *erraddr, val = 0, err = 0;
  848. char sti = 0, buf[6];
  849. erraddr = (void *)fp->pc;
  850. printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
  851. for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
  852. addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
  853. addr++) {
  854. if (!((unsigned long)addr & 0xF))
  855. printk("\n" KERN_NOTICE "0x%p: ", addr);
  856. if (get_instruction(&val, addr)) {
  857. val = 0;
  858. sprintf(buf, "????");
  859. } else
  860. sprintf(buf, "%04x", val);
  861. if (addr == erraddr) {
  862. printk("[%s]", buf);
  863. err = val;
  864. } else
  865. printk(" %s ", buf);
  866. /* Do any previous instructions turn on interrupts? */
  867. if (addr <= erraddr && /* in the past */
  868. ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
  869. val == 0x017b)) /* [SP++] = RETI */
  870. sti = 1;
  871. }
  872. printk("\n");
  873. /* Hardware error interrupts can be deferred */
  874. if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
  875. oops_in_progress)){
  876. printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
  877. #ifndef CONFIG_DEBUG_HWERR
  878. printk(KERN_NOTICE "The remaining message may be meaningless\n"
  879. KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
  880. " better idea where it came from\n");
  881. #else
  882. /* If we are handling only one peripheral interrupt
  883. * and current mm and pid are valid, and the last error
  884. * was in that user space process's text area
  885. * print it out - because that is where the problem exists
  886. */
  887. if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
  888. (current->pid && current->mm)) {
  889. /* And the last RETI points to the current userspace context */
  890. if ((fp + 1)->pc >= current->mm->start_code &&
  891. (fp + 1)->pc <= current->mm->end_code) {
  892. printk(KERN_NOTICE "It might be better to look around here : \n");
  893. printk(KERN_NOTICE "-------------------------------------------\n");
  894. show_regs(fp + 1);
  895. printk(KERN_NOTICE "-------------------------------------------\n");
  896. }
  897. }
  898. #endif
  899. }
  900. }
  901. void show_regs(struct pt_regs *fp)
  902. {
  903. char buf [150];
  904. struct irqaction *action;
  905. unsigned int i;
  906. unsigned long flags;
  907. printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
  908. printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
  909. (long)fp->seqstat, fp->ipend, fp->syscfg);
  910. printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
  911. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  912. printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
  913. fp->seqstat & SEQSTAT_EXCAUSE);
  914. for (i = 6; i <= 15 ; i++) {
  915. if (fp->ipend & (1 << i)) {
  916. decode_address(buf, bfin_read32(EVT0 + 4*i));
  917. printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
  918. }
  919. }
  920. /* if no interrupts are going off, don't print this out */
  921. if (fp->ipend & ~0x3F) {
  922. for (i = 0; i < (NR_IRQS - 1); i++) {
  923. spin_lock_irqsave(&irq_desc[i].lock, flags);
  924. action = irq_desc[i].action;
  925. if (!action)
  926. goto unlock;
  927. decode_address(buf, (unsigned int)action->handler);
  928. printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
  929. for (action = action->next; action; action = action->next) {
  930. decode_address(buf, (unsigned int)action->handler);
  931. printk(", %s", buf);
  932. }
  933. printk("\n");
  934. unlock:
  935. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  936. }
  937. }
  938. decode_address(buf, fp->rete);
  939. printk(KERN_NOTICE " RETE: %s\n", buf);
  940. decode_address(buf, fp->retn);
  941. printk(KERN_NOTICE " RETN: %s\n", buf);
  942. decode_address(buf, fp->retx);
  943. printk(KERN_NOTICE " RETX: %s\n", buf);
  944. decode_address(buf, fp->rets);
  945. printk(KERN_NOTICE " RETS: %s\n", buf);
  946. decode_address(buf, fp->pc);
  947. printk(KERN_NOTICE " PC : %s\n", buf);
  948. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  949. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  950. decode_address(buf, saved_dcplb_fault_addr);
  951. printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
  952. decode_address(buf, saved_icplb_fault_addr);
  953. printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
  954. }
  955. printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
  956. printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  957. fp->r0, fp->r1, fp->r2, fp->r3);
  958. printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  959. fp->r4, fp->r5, fp->r6, fp->r7);
  960. printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  961. fp->p0, fp->p1, fp->p2, fp->p3);
  962. printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  963. fp->p4, fp->p5, fp->fp, (long)fp);
  964. printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
  965. fp->lb0, fp->lt0, fp->lc0);
  966. printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
  967. fp->lb1, fp->lt1, fp->lc1);
  968. printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  969. fp->b0, fp->l0, fp->m0, fp->i0);
  970. printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  971. fp->b1, fp->l1, fp->m1, fp->i1);
  972. printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  973. fp->b2, fp->l2, fp->m2, fp->i2);
  974. printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  975. fp->b3, fp->l3, fp->m3, fp->i3);
  976. printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  977. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  978. printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
  979. rdusp(), fp->astat);
  980. printk(KERN_NOTICE "\n");
  981. }
  982. #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
  983. asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
  984. #endif
  985. asmlinkage int sys_bfin_spinlock(int *spinlock)
  986. {
  987. int ret = 0;
  988. int tmp = 0;
  989. local_irq_disable();
  990. ret = get_user(tmp, spinlock);
  991. if (ret == 0) {
  992. if (tmp)
  993. ret = 1;
  994. tmp = 1;
  995. put_user(tmp, spinlock);
  996. }
  997. local_irq_enable();
  998. return ret;
  999. }
  1000. int bfin_request_exception(unsigned int exception, void (*handler)(void))
  1001. {
  1002. void (*curr_handler)(void);
  1003. if (exception > 0x3F)
  1004. return -EINVAL;
  1005. curr_handler = ex_table[exception];
  1006. if (curr_handler != ex_replaceable)
  1007. return -EBUSY;
  1008. ex_table[exception] = handler;
  1009. return 0;
  1010. }
  1011. EXPORT_SYMBOL(bfin_request_exception);
  1012. int bfin_free_exception(unsigned int exception, void (*handler)(void))
  1013. {
  1014. void (*curr_handler)(void);
  1015. if (exception > 0x3F)
  1016. return -EINVAL;
  1017. curr_handler = ex_table[exception];
  1018. if (curr_handler != handler)
  1019. return -EBUSY;
  1020. ex_table[exception] = ex_replaceable;
  1021. return 0;
  1022. }
  1023. EXPORT_SYMBOL(bfin_free_exception);
  1024. void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
  1025. {
  1026. switch (cplb_panic) {
  1027. case CPLB_NO_UNLOCKED:
  1028. printk(KERN_EMERG "All CPLBs are locked\n");
  1029. break;
  1030. case CPLB_PROT_VIOL:
  1031. return;
  1032. case CPLB_NO_ADDR_MATCH:
  1033. return;
  1034. case CPLB_UNKNOWN_ERR:
  1035. printk(KERN_EMERG "Unknown CPLB Exception\n");
  1036. break;
  1037. }
  1038. oops_in_progress = 1;
  1039. dump_bfin_process(fp);
  1040. dump_bfin_mem(fp);
  1041. show_regs(fp);
  1042. dump_stack();
  1043. panic("Unrecoverable event\n");
  1044. }