traps.c 36 KB

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