traps.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  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 <linux/rbtree.h>
  35. #include <asm/traps.h>
  36. #include <asm/cacheflush.h>
  37. #include <asm/cplb.h>
  38. #include <asm/blackfin.h>
  39. #include <asm/irq_handler.h>
  40. #include <linux/irq.h>
  41. #include <asm/trace.h>
  42. #include <asm/fixed_code.h>
  43. #ifdef CONFIG_KGDB
  44. # include <linux/kgdb.h>
  45. # define CHK_DEBUGGER_TRAP() \
  46. do { \
  47. kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
  48. } while (0)
  49. # define CHK_DEBUGGER_TRAP_MAYBE() \
  50. do { \
  51. if (kgdb_connected) \
  52. CHK_DEBUGGER_TRAP(); \
  53. } while (0)
  54. #else
  55. # define CHK_DEBUGGER_TRAP() do { } while (0)
  56. # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
  57. #endif
  58. #ifdef CONFIG_DEBUG_VERBOSE
  59. #define verbose_printk(fmt, arg...) \
  60. printk(fmt, ##arg)
  61. #else
  62. #define verbose_printk(fmt, arg...) \
  63. ({ if (0) printk(fmt, ##arg); 0; })
  64. #endif
  65. #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
  66. u32 last_seqstat;
  67. #ifdef CONFIG_DEBUG_MMRS_MODULE
  68. EXPORT_SYMBOL(last_seqstat);
  69. #endif
  70. #endif
  71. /* Initiate the event table handler */
  72. void __init trap_init(void)
  73. {
  74. CSYNC();
  75. bfin_write_EVT3(trap);
  76. CSYNC();
  77. }
  78. static void decode_address(char *buf, unsigned long address)
  79. {
  80. #ifdef CONFIG_DEBUG_VERBOSE
  81. struct task_struct *p;
  82. struct mm_struct *mm;
  83. unsigned long flags, offset;
  84. unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
  85. struct rb_node *n;
  86. #ifdef CONFIG_KALLSYMS
  87. unsigned long symsize;
  88. const char *symname;
  89. char *modname;
  90. char *delim = ":";
  91. char namebuf[128];
  92. /* look up the address and see if we are in kernel space */
  93. symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
  94. if (symname) {
  95. /* yeah! kernel space! */
  96. if (!modname)
  97. modname = delim = "";
  98. sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
  99. (void *)address, delim, modname, delim, symname,
  100. (unsigned long)offset);
  101. return;
  102. }
  103. #endif
  104. /* Problem in fixed code section? */
  105. if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
  106. sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
  107. return;
  108. }
  109. /* Problem somewhere before the kernel start address */
  110. if (address < CONFIG_BOOT_LOAD) {
  111. sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
  112. return;
  113. }
  114. /* looks like we're off in user-land, so let's walk all the
  115. * mappings of all our processes and see if we can't be a whee
  116. * bit more specific
  117. */
  118. write_lock_irqsave(&tasklist_lock, flags);
  119. for_each_process(p) {
  120. mm = (in_atomic ? p->mm : get_task_mm(p));
  121. if (!mm)
  122. continue;
  123. for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
  124. struct vm_area_struct *vma;
  125. vma = rb_entry(n, struct vm_area_struct, vm_rb);
  126. if (address >= vma->vm_start && address < vma->vm_end) {
  127. char _tmpbuf[256];
  128. char *name = p->comm;
  129. struct file *file = vma->vm_file;
  130. if (file) {
  131. char *d_name = d_path(&file->f_path, _tmpbuf,
  132. sizeof(_tmpbuf));
  133. if (!IS_ERR(d_name))
  134. name = d_name;
  135. }
  136. /* FLAT does not have its text aligned to the start of
  137. * the map while FDPIC ELF does ...
  138. */
  139. /* before we can check flat/fdpic, we need to
  140. * make sure current is valid
  141. */
  142. if ((unsigned long)current >= FIXED_CODE_START &&
  143. !((unsigned long)current & 0x3)) {
  144. if (current->mm &&
  145. (address > current->mm->start_code) &&
  146. (address < current->mm->end_code))
  147. offset = address - current->mm->start_code;
  148. else
  149. offset = (address - vma->vm_start) +
  150. (vma->vm_pgoff << PAGE_SHIFT);
  151. sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
  152. (void *)address, name, offset);
  153. } else
  154. sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
  155. (void *)address, name,
  156. vma->vm_start, vma->vm_end);
  157. if (!in_atomic)
  158. mmput(mm);
  159. if (!strlen(buf))
  160. sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
  161. goto done;
  162. }
  163. }
  164. if (!in_atomic)
  165. mmput(mm);
  166. }
  167. /* we were unable to find this address anywhere */
  168. sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
  169. done:
  170. write_unlock_irqrestore(&tasklist_lock, flags);
  171. #else
  172. sprintf(buf, " ");
  173. #endif
  174. }
  175. asmlinkage void double_fault_c(struct pt_regs *fp)
  176. {
  177. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  178. int j;
  179. trace_buffer_save(j);
  180. #endif
  181. console_verbose();
  182. oops_in_progress = 1;
  183. #ifdef CONFIG_DEBUG_VERBOSE
  184. printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
  185. #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
  186. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
  187. unsigned int cpu = smp_processor_id();
  188. char buf[150];
  189. decode_address(buf, cpu_pda[cpu].retx);
  190. printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
  191. (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
  192. decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
  193. printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
  194. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  195. printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
  196. decode_address(buf, fp->retx);
  197. printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
  198. } else
  199. #endif
  200. {
  201. dump_bfin_process(fp);
  202. dump_bfin_mem(fp);
  203. show_regs(fp);
  204. dump_bfin_trace_buffer();
  205. }
  206. #endif
  207. panic("Double Fault - unrecoverable event");
  208. }
  209. asmlinkage void trap_c(struct pt_regs *fp)
  210. {
  211. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  212. int j;
  213. #endif
  214. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  215. unsigned int cpu = smp_processor_id();
  216. #endif
  217. int sig = 0;
  218. siginfo_t info;
  219. unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
  220. trace_buffer_save(j);
  221. #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
  222. last_seqstat = (u32)fp->seqstat;
  223. #endif
  224. /* Important - be very careful dereferncing pointers - will lead to
  225. * double faults if the stack has become corrupt
  226. */
  227. /* If the fault was caused by a kernel thread, or interrupt handler
  228. * we will kernel panic, so the system reboots.
  229. * If KGDB is enabled, don't set this for kernel breakpoints
  230. */
  231. /* TODO: check to see if we are in some sort of deferred HWERR
  232. * that we should be able to recover from, not kernel panic
  233. */
  234. if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
  235. #ifdef CONFIG_KGDB
  236. && (trapnr != VEC_EXCPT02)
  237. #endif
  238. ){
  239. console_verbose();
  240. oops_in_progress = 1;
  241. } else if (current) {
  242. if (current->mm == NULL) {
  243. console_verbose();
  244. oops_in_progress = 1;
  245. }
  246. }
  247. /* trap_c() will be called for exceptions. During exceptions
  248. * processing, the pc value should be set with retx value.
  249. * With this change we can cleanup some code in signal.c- TODO
  250. */
  251. fp->orig_pc = fp->retx;
  252. /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
  253. trapnr, fp->ipend, fp->pc, fp->retx); */
  254. /* send the appropriate signal to the user program */
  255. switch (trapnr) {
  256. /* This table works in conjuction with the one in ./mach-common/entry.S
  257. * Some exceptions are handled there (in assembly, in exception space)
  258. * Some are handled here, (in C, in interrupt space)
  259. * Some, like CPLB, are handled in both, where the normal path is
  260. * handled in assembly/exception space, and the error path is handled
  261. * here
  262. */
  263. /* 0x00 - Linux Syscall, getting here is an error */
  264. /* 0x01 - userspace gdb breakpoint, handled here */
  265. case VEC_EXCPT01:
  266. info.si_code = TRAP_ILLTRAP;
  267. sig = SIGTRAP;
  268. CHK_DEBUGGER_TRAP_MAYBE();
  269. /* Check if this is a breakpoint in kernel space */
  270. if (fp->ipend & 0xffc0)
  271. return;
  272. else
  273. break;
  274. /* 0x03 - User Defined, userspace stack overflow */
  275. case VEC_EXCPT03:
  276. info.si_code = SEGV_STACKFLOW;
  277. sig = SIGSEGV;
  278. verbose_printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
  279. CHK_DEBUGGER_TRAP_MAYBE();
  280. break;
  281. /* 0x02 - KGDB initial connection and break signal trap */
  282. case VEC_EXCPT02:
  283. #ifdef CONFIG_KGDB
  284. info.si_code = TRAP_ILLTRAP;
  285. sig = SIGTRAP;
  286. CHK_DEBUGGER_TRAP();
  287. return;
  288. #endif
  289. /* 0x04 - User Defined */
  290. /* 0x05 - User Defined */
  291. /* 0x06 - User Defined */
  292. /* 0x07 - User Defined */
  293. /* 0x08 - User Defined */
  294. /* 0x09 - User Defined */
  295. /* 0x0A - User Defined */
  296. /* 0x0B - User Defined */
  297. /* 0x0C - User Defined */
  298. /* 0x0D - User Defined */
  299. /* 0x0E - User Defined */
  300. /* 0x0F - User Defined */
  301. /* If we got here, it is most likely that someone was trying to use a
  302. * custom exception handler, and it is not actually installed properly
  303. */
  304. case VEC_EXCPT04 ... VEC_EXCPT15:
  305. info.si_code = ILL_ILLPARAOP;
  306. sig = SIGILL;
  307. verbose_printk(KERN_NOTICE EXC_0x04(KERN_NOTICE));
  308. CHK_DEBUGGER_TRAP_MAYBE();
  309. break;
  310. /* 0x10 HW Single step, handled here */
  311. case VEC_STEP:
  312. info.si_code = TRAP_STEP;
  313. sig = SIGTRAP;
  314. CHK_DEBUGGER_TRAP_MAYBE();
  315. /* Check if this is a single step in kernel space */
  316. if (fp->ipend & 0xffc0)
  317. return;
  318. else
  319. break;
  320. /* 0x11 - Trace Buffer Full, handled here */
  321. case VEC_OVFLOW:
  322. info.si_code = TRAP_TRACEFLOW;
  323. sig = SIGTRAP;
  324. verbose_printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
  325. CHK_DEBUGGER_TRAP_MAYBE();
  326. break;
  327. /* 0x12 - Reserved, Caught by default */
  328. /* 0x13 - Reserved, Caught by default */
  329. /* 0x14 - Reserved, Caught by default */
  330. /* 0x15 - Reserved, Caught by default */
  331. /* 0x16 - Reserved, Caught by default */
  332. /* 0x17 - Reserved, Caught by default */
  333. /* 0x18 - Reserved, Caught by default */
  334. /* 0x19 - Reserved, Caught by default */
  335. /* 0x1A - Reserved, Caught by default */
  336. /* 0x1B - Reserved, Caught by default */
  337. /* 0x1C - Reserved, Caught by default */
  338. /* 0x1D - Reserved, Caught by default */
  339. /* 0x1E - Reserved, Caught by default */
  340. /* 0x1F - Reserved, Caught by default */
  341. /* 0x20 - Reserved, Caught by default */
  342. /* 0x21 - Undefined Instruction, handled here */
  343. case VEC_UNDEF_I:
  344. info.si_code = ILL_ILLOPC;
  345. sig = SIGILL;
  346. verbose_printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
  347. CHK_DEBUGGER_TRAP_MAYBE();
  348. break;
  349. /* 0x22 - Illegal Instruction Combination, handled here */
  350. case VEC_ILGAL_I:
  351. info.si_code = ILL_ILLPARAOP;
  352. sig = SIGILL;
  353. verbose_printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
  354. CHK_DEBUGGER_TRAP_MAYBE();
  355. break;
  356. /* 0x23 - Data CPLB protection violation, handled here */
  357. case VEC_CPLB_VL:
  358. info.si_code = ILL_CPLB_VI;
  359. sig = SIGBUS;
  360. verbose_printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
  361. CHK_DEBUGGER_TRAP_MAYBE();
  362. break;
  363. /* 0x24 - Data access misaligned, handled here */
  364. case VEC_MISALI_D:
  365. info.si_code = BUS_ADRALN;
  366. sig = SIGBUS;
  367. verbose_printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
  368. CHK_DEBUGGER_TRAP_MAYBE();
  369. break;
  370. /* 0x25 - Unrecoverable Event, handled here */
  371. case VEC_UNCOV:
  372. info.si_code = ILL_ILLEXCPT;
  373. sig = SIGILL;
  374. verbose_printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
  375. CHK_DEBUGGER_TRAP_MAYBE();
  376. break;
  377. /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
  378. error case is handled here */
  379. case VEC_CPLB_M:
  380. info.si_code = BUS_ADRALN;
  381. sig = SIGBUS;
  382. verbose_printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
  383. break;
  384. /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
  385. case VEC_CPLB_MHIT:
  386. info.si_code = ILL_CPLB_MULHIT;
  387. sig = SIGSEGV;
  388. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  389. if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
  390. verbose_printk(KERN_NOTICE "NULL pointer access\n");
  391. else
  392. #endif
  393. verbose_printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
  394. CHK_DEBUGGER_TRAP_MAYBE();
  395. break;
  396. /* 0x28 - Emulation Watchpoint, handled here */
  397. case VEC_WATCH:
  398. info.si_code = TRAP_WATCHPT;
  399. sig = SIGTRAP;
  400. pr_debug(EXC_0x28(KERN_DEBUG));
  401. CHK_DEBUGGER_TRAP_MAYBE();
  402. /* Check if this is a watchpoint in kernel space */
  403. if (fp->ipend & 0xffc0)
  404. return;
  405. else
  406. break;
  407. #ifdef CONFIG_BF535
  408. /* 0x29 - Instruction fetch access error (535 only) */
  409. case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
  410. info.si_code = BUS_OPFETCH;
  411. sig = SIGBUS;
  412. verbose_printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
  413. CHK_DEBUGGER_TRAP_MAYBE();
  414. break;
  415. #else
  416. /* 0x29 - Reserved, Caught by default */
  417. #endif
  418. /* 0x2A - Instruction fetch misaligned, handled here */
  419. case VEC_MISALI_I:
  420. info.si_code = BUS_ADRALN;
  421. sig = SIGBUS;
  422. verbose_printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
  423. CHK_DEBUGGER_TRAP_MAYBE();
  424. break;
  425. /* 0x2B - Instruction CPLB protection violation, handled here */
  426. case VEC_CPLB_I_VL:
  427. info.si_code = ILL_CPLB_VI;
  428. sig = SIGBUS;
  429. verbose_printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
  430. CHK_DEBUGGER_TRAP_MAYBE();
  431. break;
  432. /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
  433. case VEC_CPLB_I_M:
  434. info.si_code = ILL_CPLB_MISS;
  435. sig = SIGBUS;
  436. verbose_printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
  437. break;
  438. /* 0x2D - Instruction CPLB Multiple Hits, handled here */
  439. case VEC_CPLB_I_MHIT:
  440. info.si_code = ILL_CPLB_MULHIT;
  441. sig = SIGSEGV;
  442. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  443. if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
  444. verbose_printk(KERN_NOTICE "Jump to NULL address\n");
  445. else
  446. #endif
  447. verbose_printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
  448. CHK_DEBUGGER_TRAP_MAYBE();
  449. break;
  450. /* 0x2E - Illegal use of Supervisor Resource, handled here */
  451. case VEC_ILL_RES:
  452. info.si_code = ILL_PRVOPC;
  453. sig = SIGILL;
  454. verbose_printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
  455. CHK_DEBUGGER_TRAP_MAYBE();
  456. break;
  457. /* 0x2F - Reserved, Caught by default */
  458. /* 0x30 - Reserved, Caught by default */
  459. /* 0x31 - Reserved, Caught by default */
  460. /* 0x32 - Reserved, Caught by default */
  461. /* 0x33 - Reserved, Caught by default */
  462. /* 0x34 - Reserved, Caught by default */
  463. /* 0x35 - Reserved, Caught by default */
  464. /* 0x36 - Reserved, Caught by default */
  465. /* 0x37 - Reserved, Caught by default */
  466. /* 0x38 - Reserved, Caught by default */
  467. /* 0x39 - Reserved, Caught by default */
  468. /* 0x3A - Reserved, Caught by default */
  469. /* 0x3B - Reserved, Caught by default */
  470. /* 0x3C - Reserved, Caught by default */
  471. /* 0x3D - Reserved, Caught by default */
  472. /* 0x3E - Reserved, Caught by default */
  473. /* 0x3F - Reserved, Caught by default */
  474. case VEC_HWERR:
  475. info.si_code = BUS_ADRALN;
  476. sig = SIGBUS;
  477. switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
  478. /* System MMR Error */
  479. case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
  480. info.si_code = BUS_ADRALN;
  481. sig = SIGBUS;
  482. verbose_printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
  483. break;
  484. /* External Memory Addressing Error */
  485. case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
  486. info.si_code = BUS_ADRERR;
  487. sig = SIGBUS;
  488. verbose_printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
  489. break;
  490. /* Performance Monitor Overflow */
  491. case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
  492. verbose_printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
  493. break;
  494. /* RAISE 5 instruction */
  495. case (SEQSTAT_HWERRCAUSE_RAISE_5):
  496. printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
  497. break;
  498. default: /* Reserved */
  499. printk(KERN_NOTICE HWC_default(KERN_NOTICE));
  500. break;
  501. }
  502. CHK_DEBUGGER_TRAP_MAYBE();
  503. break;
  504. /*
  505. * We should be handling all known exception types above,
  506. * if we get here we hit a reserved one, so panic
  507. */
  508. default:
  509. oops_in_progress = 1;
  510. info.si_code = ILL_ILLPARAOP;
  511. sig = SIGILL;
  512. verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
  513. (fp->seqstat & SEQSTAT_EXCAUSE));
  514. CHK_DEBUGGER_TRAP_MAYBE();
  515. break;
  516. }
  517. BUG_ON(sig == 0);
  518. if (sig != SIGTRAP) {
  519. dump_bfin_process(fp);
  520. dump_bfin_mem(fp);
  521. show_regs(fp);
  522. /* Print out the trace buffer if it makes sense */
  523. #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
  524. if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
  525. verbose_printk(KERN_NOTICE "No trace since you do not have "
  526. "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
  527. KERN_NOTICE "\n");
  528. else
  529. #endif
  530. dump_bfin_trace_buffer();
  531. if (oops_in_progress) {
  532. /* Dump the current kernel stack */
  533. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
  534. show_stack(current, NULL);
  535. print_modules();
  536. #ifndef CONFIG_ACCESS_CHECK
  537. verbose_printk(KERN_EMERG "Please turn on "
  538. "CONFIG_ACCESS_CHECK\n");
  539. #endif
  540. panic("Kernel exception");
  541. } else {
  542. #ifdef CONFIG_DEBUG_VERBOSE
  543. unsigned long *stack;
  544. /* Dump the user space stack */
  545. stack = (unsigned long *)rdusp();
  546. verbose_printk(KERN_NOTICE "Userspace Stack\n");
  547. show_stack(NULL, stack);
  548. #endif
  549. }
  550. }
  551. #ifdef CONFIG_IPIPE
  552. if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
  553. #endif
  554. {
  555. info.si_signo = sig;
  556. info.si_errno = 0;
  557. info.si_addr = (void __user *)fp->pc;
  558. force_sig_info(sig, &info, current);
  559. }
  560. if (ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8))
  561. fp->pc = SAFE_USER_INSTRUCTION;
  562. trace_buffer_restore(j);
  563. return;
  564. }
  565. /* Typical exception handling routines */
  566. #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
  567. /*
  568. * Similar to get_user, do some address checking, then dereference
  569. * Return true on sucess, false on bad address
  570. */
  571. static bool get_instruction(unsigned short *val, unsigned short *address)
  572. {
  573. unsigned long addr;
  574. addr = (unsigned long)address;
  575. /* Check for odd addresses */
  576. if (addr & 0x1)
  577. return false;
  578. /* Check that things do not wrap around */
  579. if (addr > (addr + 2))
  580. return false;
  581. /*
  582. * Since we are in exception context, we need to do a little address checking
  583. * We need to make sure we are only accessing valid memory, and
  584. * we don't read something in the async space that can hang forever
  585. */
  586. if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
  587. #if L2_LENGTH != 0
  588. (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
  589. #endif
  590. (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
  591. #if L1_DATA_A_LENGTH != 0
  592. (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
  593. #endif
  594. #if L1_DATA_B_LENGTH != 0
  595. (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
  596. #endif
  597. (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
  598. (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
  599. addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
  600. (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
  601. addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
  602. (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
  603. addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
  604. (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
  605. addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
  606. *val = *address;
  607. return true;
  608. }
  609. #if L1_CODE_LENGTH != 0
  610. if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
  611. isram_memcpy(val, address, 2);
  612. return true;
  613. }
  614. #endif
  615. return false;
  616. }
  617. /*
  618. * decode the instruction if we are printing out the trace, as it
  619. * makes things easier to follow, without running it through objdump
  620. * These are the normal instructions which cause change of flow, which
  621. * would be at the source of the trace buffer
  622. */
  623. #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
  624. static void decode_instruction(unsigned short *address)
  625. {
  626. unsigned short opcode;
  627. if (get_instruction(&opcode, address)) {
  628. if (opcode == 0x0010)
  629. verbose_printk("RTS");
  630. else if (opcode == 0x0011)
  631. verbose_printk("RTI");
  632. else if (opcode == 0x0012)
  633. verbose_printk("RTX");
  634. else if (opcode == 0x0013)
  635. verbose_printk("RTN");
  636. else if (opcode == 0x0014)
  637. verbose_printk("RTE");
  638. else if (opcode == 0x0025)
  639. verbose_printk("EMUEXCPT");
  640. else if (opcode == 0x0040 && opcode <= 0x0047)
  641. verbose_printk("STI R%i", opcode & 7);
  642. else if (opcode >= 0x0050 && opcode <= 0x0057)
  643. verbose_printk("JUMP (P%i)", opcode & 7);
  644. else if (opcode >= 0x0060 && opcode <= 0x0067)
  645. verbose_printk("CALL (P%i)", opcode & 7);
  646. else if (opcode >= 0x0070 && opcode <= 0x0077)
  647. verbose_printk("CALL (PC+P%i)", opcode & 7);
  648. else if (opcode >= 0x0080 && opcode <= 0x0087)
  649. verbose_printk("JUMP (PC+P%i)", opcode & 7);
  650. else if (opcode >= 0x0090 && opcode <= 0x009F)
  651. verbose_printk("RAISE 0x%x", opcode & 0xF);
  652. else if (opcode >= 0x00A0 && opcode <= 0x00AF)
  653. verbose_printk("EXCPT 0x%x", opcode & 0xF);
  654. else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
  655. verbose_printk("IF !CC JUMP");
  656. else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
  657. verbose_printk("IF CC JUMP");
  658. else if (opcode >= 0x2000 && opcode <= 0x2fff)
  659. verbose_printk("JUMP.S");
  660. else if (opcode >= 0xe080 && opcode <= 0xe0ff)
  661. verbose_printk("LSETUP");
  662. else if (opcode >= 0xe200 && opcode <= 0xe2ff)
  663. verbose_printk("JUMP.L");
  664. else if (opcode >= 0xe300 && opcode <= 0xe3ff)
  665. verbose_printk("CALL pcrel");
  666. else
  667. verbose_printk("0x%04x", opcode);
  668. }
  669. }
  670. #endif
  671. void dump_bfin_trace_buffer(void)
  672. {
  673. #ifdef CONFIG_DEBUG_VERBOSE
  674. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  675. int tflags, i = 0;
  676. char buf[150];
  677. unsigned short *addr;
  678. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  679. int j, index;
  680. #endif
  681. trace_buffer_save(tflags);
  682. printk(KERN_NOTICE "Hardware Trace:\n");
  683. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  684. printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
  685. #endif
  686. if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
  687. for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
  688. decode_address(buf, (unsigned long)bfin_read_TBUF());
  689. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  690. addr = (unsigned short *)bfin_read_TBUF();
  691. decode_address(buf, (unsigned long)addr);
  692. printk(KERN_NOTICE " Source : %s ", buf);
  693. decode_instruction(addr);
  694. printk("\n");
  695. }
  696. }
  697. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  698. if (trace_buff_offset)
  699. index = trace_buff_offset / 4;
  700. else
  701. index = EXPAND_LEN;
  702. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  703. while (j) {
  704. decode_address(buf, software_trace_buff[index]);
  705. printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
  706. index -= 1;
  707. if (index < 0 )
  708. index = EXPAND_LEN;
  709. decode_address(buf, software_trace_buff[index]);
  710. printk(KERN_NOTICE " Source : %s ", buf);
  711. decode_instruction((unsigned short *)software_trace_buff[index]);
  712. printk("\n");
  713. index -= 1;
  714. if (index < 0)
  715. index = EXPAND_LEN;
  716. j--;
  717. i++;
  718. }
  719. #endif
  720. trace_buffer_restore(tflags);
  721. #endif
  722. #endif
  723. }
  724. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  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("\n" 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 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
  899. KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
  900. KERN_NOTICE "\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 "\n" 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("\n" 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 "The remaining message may be meaningless\n"
  950. KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
  951. " 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 "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
  1001. verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
  1002. (long)fp->seqstat, fp->ipend, fp->syscfg);
  1003. if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
  1004. verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
  1005. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  1006. #ifdef EBIU_ERRMST
  1007. /* If the error was from the EBIU, print it out */
  1008. if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
  1009. verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
  1010. bfin_read_EBIU_ERRMST());
  1011. verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
  1012. bfin_read_EBIU_ERRADD());
  1013. }
  1014. #endif
  1015. }
  1016. verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
  1017. fp->seqstat & SEQSTAT_EXCAUSE);
  1018. for (i = 2; i <= 15 ; i++) {
  1019. if (fp->ipend & (1 << i)) {
  1020. if (i != 4) {
  1021. decode_address(buf, bfin_read32(EVT0 + 4*i));
  1022. verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
  1023. } else
  1024. verbose_printk(KERN_NOTICE " interrupts disabled\n");
  1025. }
  1026. }
  1027. /* if no interrupts are going off, don't print this out */
  1028. if (fp->ipend & ~0x3F) {
  1029. for (i = 0; i < (NR_IRQS - 1); i++) {
  1030. if (!in_atomic)
  1031. spin_lock_irqsave(&irq_desc[i].lock, flags);
  1032. action = irq_desc[i].action;
  1033. if (!action)
  1034. goto unlock;
  1035. decode_address(buf, (unsigned int)action->handler);
  1036. verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
  1037. for (action = action->next; action; action = action->next) {
  1038. decode_address(buf, (unsigned int)action->handler);
  1039. verbose_printk(", %s", buf);
  1040. }
  1041. verbose_printk("\n");
  1042. unlock:
  1043. if (!in_atomic)
  1044. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  1045. }
  1046. }
  1047. decode_address(buf, fp->rete);
  1048. verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
  1049. decode_address(buf, fp->retn);
  1050. verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
  1051. decode_address(buf, fp->retx);
  1052. verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
  1053. decode_address(buf, fp->rets);
  1054. verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
  1055. decode_address(buf, fp->pc);
  1056. verbose_printk(KERN_NOTICE " PC : %s\n", buf);
  1057. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  1058. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  1059. decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
  1060. verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
  1061. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  1062. verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
  1063. }
  1064. verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
  1065. verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  1066. fp->r0, fp->r1, fp->r2, fp->r3);
  1067. verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  1068. fp->r4, fp->r5, fp->r6, fp->r7);
  1069. verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  1070. fp->p0, fp->p1, fp->p2, fp->p3);
  1071. verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  1072. fp->p4, fp->p5, fp->fp, (long)fp);
  1073. verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
  1074. fp->lb0, fp->lt0, fp->lc0);
  1075. verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
  1076. fp->lb1, fp->lt1, fp->lc1);
  1077. verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  1078. fp->b0, fp->l0, fp->m0, fp->i0);
  1079. verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  1080. fp->b1, fp->l1, fp->m1, fp->i1);
  1081. verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  1082. fp->b2, fp->l2, fp->m2, fp->i2);
  1083. verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  1084. fp->b3, fp->l3, fp->m3, fp->i3);
  1085. verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  1086. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  1087. verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
  1088. rdusp(), fp->astat);
  1089. verbose_printk(KERN_NOTICE "\n");
  1090. #endif
  1091. }
  1092. #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
  1093. asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
  1094. #endif
  1095. static DEFINE_SPINLOCK(bfin_spinlock_lock);
  1096. asmlinkage int sys_bfin_spinlock(int *p)
  1097. {
  1098. int ret, tmp = 0;
  1099. spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
  1100. ret = get_user(tmp, p);
  1101. if (likely(ret == 0)) {
  1102. if (unlikely(tmp))
  1103. ret = 1;
  1104. else
  1105. put_user(1, p);
  1106. }
  1107. spin_unlock(&bfin_spinlock_lock);
  1108. return ret;
  1109. }
  1110. int bfin_request_exception(unsigned int exception, void (*handler)(void))
  1111. {
  1112. void (*curr_handler)(void);
  1113. if (exception > 0x3F)
  1114. return -EINVAL;
  1115. curr_handler = ex_table[exception];
  1116. if (curr_handler != ex_replaceable)
  1117. return -EBUSY;
  1118. ex_table[exception] = handler;
  1119. return 0;
  1120. }
  1121. EXPORT_SYMBOL(bfin_request_exception);
  1122. int bfin_free_exception(unsigned int exception, void (*handler)(void))
  1123. {
  1124. void (*curr_handler)(void);
  1125. if (exception > 0x3F)
  1126. return -EINVAL;
  1127. curr_handler = ex_table[exception];
  1128. if (curr_handler != handler)
  1129. return -EBUSY;
  1130. ex_table[exception] = ex_replaceable;
  1131. return 0;
  1132. }
  1133. EXPORT_SYMBOL(bfin_free_exception);
  1134. void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
  1135. {
  1136. switch (cplb_panic) {
  1137. case CPLB_NO_UNLOCKED:
  1138. printk(KERN_EMERG "All CPLBs are locked\n");
  1139. break;
  1140. case CPLB_PROT_VIOL:
  1141. return;
  1142. case CPLB_NO_ADDR_MATCH:
  1143. return;
  1144. case CPLB_UNKNOWN_ERR:
  1145. printk(KERN_EMERG "Unknown CPLB Exception\n");
  1146. break;
  1147. }
  1148. oops_in_progress = 1;
  1149. dump_bfin_process(fp);
  1150. dump_bfin_mem(fp);
  1151. show_regs(fp);
  1152. dump_stack();
  1153. panic("Unrecoverable event");
  1154. }