traps.c 36 KB

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