traps.c 33 KB

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