traps.c 37 KB

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