traps.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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 "\n" 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. if (strerror)
  532. verbose_printk(strerror);
  533. }
  534. if (sig != SIGTRAP) {
  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"
  543. KERN_NOTICE "\n");
  544. else
  545. #endif
  546. dump_bfin_trace_buffer();
  547. if (oops_in_progress) {
  548. /* Dump the current kernel stack */
  549. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
  550. show_stack(current, NULL);
  551. print_modules();
  552. #ifndef CONFIG_ACCESS_CHECK
  553. verbose_printk(KERN_EMERG "Please turn on "
  554. "CONFIG_ACCESS_CHECK\n");
  555. #endif
  556. panic("Kernel exception");
  557. } else {
  558. #ifdef CONFIG_DEBUG_VERBOSE
  559. unsigned long *stack;
  560. /* Dump the user space stack */
  561. stack = (unsigned long *)rdusp();
  562. verbose_printk(KERN_NOTICE "Userspace Stack\n");
  563. show_stack(NULL, stack);
  564. #endif
  565. }
  566. }
  567. #ifdef CONFIG_IPIPE
  568. if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
  569. #endif
  570. {
  571. info.si_signo = sig;
  572. info.si_errno = 0;
  573. info.si_addr = (void __user *)fp->pc;
  574. force_sig_info(sig, &info, current);
  575. }
  576. if (ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8))
  577. fp->pc = SAFE_USER_INSTRUCTION;
  578. traps_done:
  579. trace_buffer_restore(j);
  580. }
  581. /* Typical exception handling routines */
  582. #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
  583. /*
  584. * Similar to get_user, do some address checking, then dereference
  585. * Return true on sucess, false on bad address
  586. */
  587. static bool get_instruction(unsigned short *val, unsigned short *address)
  588. {
  589. unsigned long addr = (unsigned long)address;
  590. /* Check for odd addresses */
  591. if (addr & 0x1)
  592. return false;
  593. /* MMR region will never have instructions */
  594. if (addr >= SYSMMR_BASE)
  595. return false;
  596. switch (bfin_mem_access_type(addr, 2)) {
  597. case BFIN_MEM_ACCESS_CORE:
  598. case BFIN_MEM_ACCESS_CORE_ONLY:
  599. *val = *address;
  600. return true;
  601. case BFIN_MEM_ACCESS_DMA:
  602. dma_memcpy(val, address, 2);
  603. return true;
  604. case BFIN_MEM_ACCESS_ITEST:
  605. isram_memcpy(val, address, 2);
  606. return true;
  607. default: /* invalid access */
  608. return false;
  609. }
  610. }
  611. /*
  612. * decode the instruction if we are printing out the trace, as it
  613. * makes things easier to follow, without running it through objdump
  614. * These are the normal instructions which cause change of flow, which
  615. * would be at the source of the trace buffer
  616. */
  617. #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
  618. static void decode_instruction(unsigned short *address)
  619. {
  620. unsigned short opcode;
  621. if (get_instruction(&opcode, address)) {
  622. if (opcode == 0x0010)
  623. verbose_printk("RTS");
  624. else if (opcode == 0x0011)
  625. verbose_printk("RTI");
  626. else if (opcode == 0x0012)
  627. verbose_printk("RTX");
  628. else if (opcode == 0x0013)
  629. verbose_printk("RTN");
  630. else if (opcode == 0x0014)
  631. verbose_printk("RTE");
  632. else if (opcode == 0x0025)
  633. verbose_printk("EMUEXCPT");
  634. else if (opcode == 0x0040 && opcode <= 0x0047)
  635. verbose_printk("STI R%i", opcode & 7);
  636. else if (opcode >= 0x0050 && opcode <= 0x0057)
  637. verbose_printk("JUMP (P%i)", opcode & 7);
  638. else if (opcode >= 0x0060 && opcode <= 0x0067)
  639. verbose_printk("CALL (P%i)", opcode & 7);
  640. else if (opcode >= 0x0070 && opcode <= 0x0077)
  641. verbose_printk("CALL (PC+P%i)", opcode & 7);
  642. else if (opcode >= 0x0080 && opcode <= 0x0087)
  643. verbose_printk("JUMP (PC+P%i)", opcode & 7);
  644. else if (opcode >= 0x0090 && opcode <= 0x009F)
  645. verbose_printk("RAISE 0x%x", opcode & 0xF);
  646. else if (opcode >= 0x00A0 && opcode <= 0x00AF)
  647. verbose_printk("EXCPT 0x%x", opcode & 0xF);
  648. else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
  649. verbose_printk("IF !CC JUMP");
  650. else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
  651. verbose_printk("IF CC JUMP");
  652. else if (opcode >= 0x2000 && opcode <= 0x2fff)
  653. verbose_printk("JUMP.S");
  654. else if (opcode >= 0xe080 && opcode <= 0xe0ff)
  655. verbose_printk("LSETUP");
  656. else if (opcode >= 0xe200 && opcode <= 0xe2ff)
  657. verbose_printk("JUMP.L");
  658. else if (opcode >= 0xe300 && opcode <= 0xe3ff)
  659. verbose_printk("CALL pcrel");
  660. else
  661. verbose_printk("0x%04x", opcode);
  662. }
  663. }
  664. #endif
  665. void dump_bfin_trace_buffer(void)
  666. {
  667. #ifdef CONFIG_DEBUG_VERBOSE
  668. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  669. int tflags, i = 0;
  670. char buf[150];
  671. unsigned short *addr;
  672. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  673. int j, index;
  674. #endif
  675. trace_buffer_save(tflags);
  676. printk(KERN_NOTICE "Hardware Trace:\n");
  677. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  678. printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
  679. #endif
  680. if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
  681. for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
  682. decode_address(buf, (unsigned long)bfin_read_TBUF());
  683. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  684. addr = (unsigned short *)bfin_read_TBUF();
  685. decode_address(buf, (unsigned long)addr);
  686. printk(KERN_NOTICE " Source : %s ", buf);
  687. decode_instruction(addr);
  688. printk("\n");
  689. }
  690. }
  691. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  692. if (trace_buff_offset)
  693. index = trace_buff_offset / 4;
  694. else
  695. index = EXPAND_LEN;
  696. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  697. while (j) {
  698. decode_address(buf, software_trace_buff[index]);
  699. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  700. index -= 1;
  701. if (index < 0 )
  702. index = EXPAND_LEN;
  703. decode_address(buf, software_trace_buff[index]);
  704. printk(KERN_NOTICE " Source : %s ", buf);
  705. decode_instruction((unsigned short *)software_trace_buff[index]);
  706. printk("\n");
  707. index -= 1;
  708. if (index < 0)
  709. index = EXPAND_LEN;
  710. j--;
  711. i++;
  712. }
  713. #endif
  714. trace_buffer_restore(tflags);
  715. #endif
  716. #endif
  717. }
  718. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  719. #ifdef CONFIG_BUG
  720. int is_valid_bugaddr(unsigned long addr)
  721. {
  722. unsigned short opcode;
  723. if (!get_instruction(&opcode, (unsigned short *)addr))
  724. return 0;
  725. return opcode == BFIN_BUG_OPCODE;
  726. }
  727. #endif
  728. /*
  729. * Checks to see if the address pointed to is either a
  730. * 16-bit CALL instruction, or a 32-bit CALL instruction
  731. */
  732. static bool is_bfin_call(unsigned short *addr)
  733. {
  734. unsigned short opcode = 0, *ins_addr;
  735. ins_addr = (unsigned short *)addr;
  736. if (!get_instruction(&opcode, ins_addr))
  737. return false;
  738. if ((opcode >= 0x0060 && opcode <= 0x0067) ||
  739. (opcode >= 0x0070 && opcode <= 0x0077))
  740. return true;
  741. ins_addr--;
  742. if (!get_instruction(&opcode, ins_addr))
  743. return false;
  744. if (opcode >= 0xE300 && opcode <= 0xE3FF)
  745. return true;
  746. return false;
  747. }
  748. void show_stack(struct task_struct *task, unsigned long *stack)
  749. {
  750. #ifdef CONFIG_PRINTK
  751. unsigned int *addr, *endstack, *fp = 0, *frame;
  752. unsigned short *ins_addr;
  753. char buf[150];
  754. unsigned int i, j, ret_addr, frame_no = 0;
  755. /*
  756. * If we have been passed a specific stack, use that one otherwise
  757. * if we have been passed a task structure, use that, otherwise
  758. * use the stack of where the variable "stack" exists
  759. */
  760. if (stack == NULL) {
  761. if (task) {
  762. /* We know this is a kernel stack, so this is the start/end */
  763. stack = (unsigned long *)task->thread.ksp;
  764. endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
  765. } else {
  766. /* print out the existing stack info */
  767. stack = (unsigned long *)&stack;
  768. endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
  769. }
  770. } else
  771. endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
  772. printk(KERN_NOTICE "Stack info:\n");
  773. decode_address(buf, (unsigned int)stack);
  774. printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
  775. if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
  776. printk(KERN_NOTICE "Invalid stack pointer\n");
  777. return;
  778. }
  779. /* First thing is to look for a frame pointer */
  780. for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
  781. if (*addr & 0x1)
  782. continue;
  783. ins_addr = (unsigned short *)*addr;
  784. ins_addr--;
  785. if (is_bfin_call(ins_addr))
  786. fp = addr - 1;
  787. if (fp) {
  788. /* Let's check to see if it is a frame pointer */
  789. while (fp >= (addr - 1) && fp < endstack
  790. && fp && ((unsigned int) fp & 0x3) == 0)
  791. fp = (unsigned int *)*fp;
  792. if (fp == 0 || fp == endstack) {
  793. fp = addr - 1;
  794. break;
  795. }
  796. fp = 0;
  797. }
  798. }
  799. if (fp) {
  800. frame = fp;
  801. printk(KERN_NOTICE " FP: (0x%p)\n", fp);
  802. } else
  803. frame = 0;
  804. /*
  805. * Now that we think we know where things are, we
  806. * walk the stack again, this time printing things out
  807. * incase there is no frame pointer, we still look for
  808. * valid return addresses
  809. */
  810. /* First time print out data, next time, print out symbols */
  811. for (j = 0; j <= 1; j++) {
  812. if (j)
  813. printk(KERN_NOTICE "Return addresses in stack:\n");
  814. else
  815. printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
  816. fp = frame;
  817. frame_no = 0;
  818. for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
  819. addr <= endstack; addr++, i++) {
  820. ret_addr = 0;
  821. if (!j && i % 8 == 0)
  822. printk("\n" KERN_NOTICE "%p:",addr);
  823. /* if it is an odd address, or zero, just skip it */
  824. if (*addr & 0x1 || !*addr)
  825. goto print;
  826. ins_addr = (unsigned short *)*addr;
  827. /* Go back one instruction, and see if it is a CALL */
  828. ins_addr--;
  829. ret_addr = is_bfin_call(ins_addr);
  830. print:
  831. if (!j && stack == (unsigned long *)addr)
  832. printk("[%08x]", *addr);
  833. else if (ret_addr)
  834. if (j) {
  835. decode_address(buf, (unsigned int)*addr);
  836. if (frame == addr) {
  837. printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
  838. continue;
  839. }
  840. printk(KERN_NOTICE " address : %s\n", buf);
  841. } else
  842. printk("<%08x>", *addr);
  843. else if (fp == addr) {
  844. if (j)
  845. frame = addr+1;
  846. else
  847. printk("(%08x)", *addr);
  848. fp = (unsigned int *)*addr;
  849. frame_no++;
  850. } else if (!j)
  851. printk(" %08x ", *addr);
  852. }
  853. if (!j)
  854. printk("\n");
  855. }
  856. #endif
  857. }
  858. void dump_stack(void)
  859. {
  860. unsigned long stack;
  861. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  862. int tflags;
  863. #endif
  864. trace_buffer_save(tflags);
  865. dump_bfin_trace_buffer();
  866. show_stack(current, &stack);
  867. trace_buffer_restore(tflags);
  868. }
  869. EXPORT_SYMBOL(dump_stack);
  870. void dump_bfin_process(struct pt_regs *fp)
  871. {
  872. #ifdef CONFIG_DEBUG_VERBOSE
  873. /* We should be able to look at fp->ipend, but we don't push it on the
  874. * stack all the time, so do this until we fix that */
  875. unsigned int context = bfin_read_IPEND();
  876. if (oops_in_progress)
  877. verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
  878. if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
  879. verbose_printk(KERN_NOTICE "HW Error context\n");
  880. else if (context & 0x0020)
  881. verbose_printk(KERN_NOTICE "Deferred Exception context\n");
  882. else if (context & 0x3FC0)
  883. verbose_printk(KERN_NOTICE "Interrupt context\n");
  884. else if (context & 0x4000)
  885. verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
  886. else if (context & 0x8000)
  887. verbose_printk(KERN_NOTICE "Kernel process context\n");
  888. /* Because we are crashing, and pointers could be bad, we check things
  889. * pretty closely before we use them
  890. */
  891. if ((unsigned long)current >= FIXED_CODE_START &&
  892. !((unsigned long)current & 0x3) && current->pid) {
  893. verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
  894. if (current->comm >= (char *)FIXED_CODE_START)
  895. verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
  896. current->comm, current->pid);
  897. else
  898. verbose_printk(KERN_NOTICE "COMM= invalid\n");
  899. printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
  900. if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
  901. verbose_printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
  902. KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
  903. KERN_NOTICE "\n",
  904. (void *)current->mm->start_code,
  905. (void *)current->mm->end_code,
  906. (void *)current->mm->start_data,
  907. (void *)current->mm->end_data,
  908. (void *)current->mm->end_data,
  909. (void *)current->mm->brk,
  910. (void *)current->mm->start_stack);
  911. else
  912. verbose_printk(KERN_NOTICE "invalid mm\n");
  913. } else
  914. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE
  915. "No Valid process in current context\n");
  916. #endif
  917. }
  918. void dump_bfin_mem(struct pt_regs *fp)
  919. {
  920. #ifdef CONFIG_DEBUG_VERBOSE
  921. unsigned short *addr, *erraddr, val = 0, err = 0;
  922. char sti = 0, buf[6];
  923. erraddr = (void *)fp->pc;
  924. verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
  925. for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
  926. addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
  927. addr++) {
  928. if (!((unsigned long)addr & 0xF))
  929. verbose_printk("\n" KERN_NOTICE "0x%p: ", addr);
  930. if (!get_instruction(&val, addr)) {
  931. val = 0;
  932. sprintf(buf, "????");
  933. } else
  934. sprintf(buf, "%04x", val);
  935. if (addr == erraddr) {
  936. verbose_printk("[%s]", buf);
  937. err = val;
  938. } else
  939. verbose_printk(" %s ", buf);
  940. /* Do any previous instructions turn on interrupts? */
  941. if (addr <= erraddr && /* in the past */
  942. ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
  943. val == 0x017b)) /* [SP++] = RETI */
  944. sti = 1;
  945. }
  946. verbose_printk("\n");
  947. /* Hardware error interrupts can be deferred */
  948. if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
  949. oops_in_progress)){
  950. verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
  951. #ifndef CONFIG_DEBUG_HWERR
  952. verbose_printk(KERN_NOTICE "The remaining message may be meaningless\n"
  953. KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
  954. " better idea where it came from\n");
  955. #else
  956. /* If we are handling only one peripheral interrupt
  957. * and current mm and pid are valid, and the last error
  958. * was in that user space process's text area
  959. * print it out - because that is where the problem exists
  960. */
  961. if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
  962. (current->pid && current->mm)) {
  963. /* And the last RETI points to the current userspace context */
  964. if ((fp + 1)->pc >= current->mm->start_code &&
  965. (fp + 1)->pc <= current->mm->end_code) {
  966. verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
  967. verbose_printk(KERN_NOTICE "-------------------------------------------\n");
  968. show_regs(fp + 1);
  969. verbose_printk(KERN_NOTICE "-------------------------------------------\n");
  970. }
  971. }
  972. #endif
  973. }
  974. #endif
  975. }
  976. void show_regs(struct pt_regs *fp)
  977. {
  978. #ifdef CONFIG_DEBUG_VERBOSE
  979. char buf [150];
  980. struct irqaction *action;
  981. unsigned int i;
  982. unsigned long flags = 0;
  983. unsigned int cpu = smp_processor_id();
  984. unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
  985. verbose_printk(KERN_NOTICE "\n");
  986. if (CPUID != bfin_cpuid())
  987. verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
  988. "but running on:0x%04x (Rev %d)\n",
  989. CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
  990. verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
  991. CPU, bfin_compiled_revid());
  992. if (bfin_compiled_revid() != bfin_revid())
  993. verbose_printk("(Detected 0.%d)", bfin_revid());
  994. verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
  995. get_cclk()/1000000, get_sclk()/1000000,
  996. #ifdef CONFIG_MPU
  997. "mpu on"
  998. #else
  999. "mpu off"
  1000. #endif
  1001. );
  1002. verbose_printk(KERN_NOTICE "%s", linux_banner);
  1003. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
  1004. verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
  1005. (long)fp->seqstat, fp->ipend, fp->syscfg);
  1006. if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
  1007. verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
  1008. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  1009. #ifdef EBIU_ERRMST
  1010. /* If the error was from the EBIU, print it out */
  1011. if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
  1012. verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
  1013. bfin_read_EBIU_ERRMST());
  1014. verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
  1015. bfin_read_EBIU_ERRADD());
  1016. }
  1017. #endif
  1018. }
  1019. verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
  1020. fp->seqstat & SEQSTAT_EXCAUSE);
  1021. for (i = 2; i <= 15 ; i++) {
  1022. if (fp->ipend & (1 << i)) {
  1023. if (i != 4) {
  1024. decode_address(buf, bfin_read32(EVT0 + 4*i));
  1025. verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
  1026. } else
  1027. verbose_printk(KERN_NOTICE " interrupts disabled\n");
  1028. }
  1029. }
  1030. /* if no interrupts are going off, don't print this out */
  1031. if (fp->ipend & ~0x3F) {
  1032. for (i = 0; i < (NR_IRQS - 1); i++) {
  1033. if (!in_atomic)
  1034. spin_lock_irqsave(&irq_desc[i].lock, flags);
  1035. action = irq_desc[i].action;
  1036. if (!action)
  1037. goto unlock;
  1038. decode_address(buf, (unsigned int)action->handler);
  1039. verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
  1040. for (action = action->next; action; action = action->next) {
  1041. decode_address(buf, (unsigned int)action->handler);
  1042. verbose_printk(", %s", buf);
  1043. }
  1044. verbose_printk("\n");
  1045. unlock:
  1046. if (!in_atomic)
  1047. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  1048. }
  1049. }
  1050. decode_address(buf, fp->rete);
  1051. verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
  1052. decode_address(buf, fp->retn);
  1053. verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
  1054. decode_address(buf, fp->retx);
  1055. verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
  1056. decode_address(buf, fp->rets);
  1057. verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
  1058. decode_address(buf, fp->pc);
  1059. verbose_printk(KERN_NOTICE " PC : %s\n", buf);
  1060. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  1061. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  1062. decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
  1063. verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
  1064. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  1065. verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
  1066. }
  1067. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
  1068. verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  1069. fp->r0, fp->r1, fp->r2, fp->r3);
  1070. verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  1071. fp->r4, fp->r5, fp->r6, fp->r7);
  1072. verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  1073. fp->p0, fp->p1, fp->p2, fp->p3);
  1074. verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  1075. fp->p4, fp->p5, fp->fp, (long)fp);
  1076. verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
  1077. fp->lb0, fp->lt0, fp->lc0);
  1078. verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
  1079. fp->lb1, fp->lt1, fp->lc1);
  1080. verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  1081. fp->b0, fp->l0, fp->m0, fp->i0);
  1082. verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  1083. fp->b1, fp->l1, fp->m1, fp->i1);
  1084. verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  1085. fp->b2, fp->l2, fp->m2, fp->i2);
  1086. verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  1087. fp->b3, fp->l3, fp->m3, fp->i3);
  1088. verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  1089. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  1090. verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
  1091. rdusp(), fp->astat);
  1092. verbose_printk(KERN_NOTICE "\n");
  1093. #endif
  1094. }
  1095. #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
  1096. asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
  1097. #endif
  1098. static DEFINE_SPINLOCK(bfin_spinlock_lock);
  1099. asmlinkage int sys_bfin_spinlock(int *p)
  1100. {
  1101. int ret, tmp = 0;
  1102. spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
  1103. ret = get_user(tmp, p);
  1104. if (likely(ret == 0)) {
  1105. if (unlikely(tmp))
  1106. ret = 1;
  1107. else
  1108. put_user(1, p);
  1109. }
  1110. spin_unlock(&bfin_spinlock_lock);
  1111. return ret;
  1112. }
  1113. int bfin_request_exception(unsigned int exception, void (*handler)(void))
  1114. {
  1115. void (*curr_handler)(void);
  1116. if (exception > 0x3F)
  1117. return -EINVAL;
  1118. curr_handler = ex_table[exception];
  1119. if (curr_handler != ex_replaceable)
  1120. return -EBUSY;
  1121. ex_table[exception] = handler;
  1122. return 0;
  1123. }
  1124. EXPORT_SYMBOL(bfin_request_exception);
  1125. int bfin_free_exception(unsigned int exception, void (*handler)(void))
  1126. {
  1127. void (*curr_handler)(void);
  1128. if (exception > 0x3F)
  1129. return -EINVAL;
  1130. curr_handler = ex_table[exception];
  1131. if (curr_handler != handler)
  1132. return -EBUSY;
  1133. ex_table[exception] = ex_replaceable;
  1134. return 0;
  1135. }
  1136. EXPORT_SYMBOL(bfin_free_exception);
  1137. void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
  1138. {
  1139. switch (cplb_panic) {
  1140. case CPLB_NO_UNLOCKED:
  1141. printk(KERN_EMERG "All CPLBs are locked\n");
  1142. break;
  1143. case CPLB_PROT_VIOL:
  1144. return;
  1145. case CPLB_NO_ADDR_MATCH:
  1146. return;
  1147. case CPLB_UNKNOWN_ERR:
  1148. printk(KERN_EMERG "Unknown CPLB Exception\n");
  1149. break;
  1150. }
  1151. oops_in_progress = 1;
  1152. dump_bfin_process(fp);
  1153. dump_bfin_mem(fp);
  1154. show_regs(fp);
  1155. dump_stack();
  1156. panic("Unrecoverable event");
  1157. }