traps.c 33 KB

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