traps.c 36 KB

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