traps.c 35 KB

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