trace.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. /* provide some functions which dump the trace buffer, in a nice way for people
  2. * to read it, and understand what is going on
  3. *
  4. * Copyright 2004-2010 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/hardirq.h>
  10. #include <linux/thread_info.h>
  11. #include <linux/mm.h>
  12. #include <linux/uaccess.h>
  13. #include <linux/module.h>
  14. #include <linux/kallsyms.h>
  15. #include <linux/err.h>
  16. #include <linux/fs.h>
  17. #include <asm/dma.h>
  18. #include <asm/trace.h>
  19. #include <asm/fixed_code.h>
  20. #include <asm/traps.h>
  21. #include <asm/irq_handler.h>
  22. void decode_address(char *buf, unsigned long address)
  23. {
  24. struct task_struct *p;
  25. struct mm_struct *mm;
  26. unsigned long flags, offset;
  27. unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
  28. struct rb_node *n;
  29. #ifdef CONFIG_KALLSYMS
  30. unsigned long symsize;
  31. const char *symname;
  32. char *modname;
  33. char *delim = ":";
  34. char namebuf[128];
  35. #endif
  36. buf += sprintf(buf, "<0x%08lx> ", address);
  37. #ifdef CONFIG_KALLSYMS
  38. /* look up the address and see if we are in kernel space */
  39. symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
  40. if (symname) {
  41. /* yeah! kernel space! */
  42. if (!modname)
  43. modname = delim = "";
  44. sprintf(buf, "{ %s%s%s%s + 0x%lx }",
  45. delim, modname, delim, symname,
  46. (unsigned long)offset);
  47. return;
  48. }
  49. #endif
  50. if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
  51. /* Problem in fixed code section? */
  52. strcat(buf, "/* Maybe fixed code section */");
  53. return;
  54. } else if (address < CONFIG_BOOT_LOAD) {
  55. /* Problem somewhere before the kernel start address */
  56. strcat(buf, "/* Maybe null pointer? */");
  57. return;
  58. } else if (address >= COREMMR_BASE) {
  59. strcat(buf, "/* core mmrs */");
  60. return;
  61. } else if (address >= SYSMMR_BASE) {
  62. strcat(buf, "/* system mmrs */");
  63. return;
  64. } else if (address >= L1_ROM_START && address < L1_ROM_START + L1_ROM_LENGTH) {
  65. strcat(buf, "/* on-chip L1 ROM */");
  66. return;
  67. } else if (address >= L1_SCRATCH_START && address < L1_SCRATCH_START + L1_SCRATCH_LENGTH) {
  68. strcat(buf, "/* on-chip scratchpad */");
  69. return;
  70. } else if (address >= physical_mem_end && address < ASYNC_BANK0_BASE) {
  71. strcat(buf, "/* unconnected memory */");
  72. return;
  73. } else if (address >= ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE && address < BOOT_ROM_START) {
  74. strcat(buf, "/* reserved memory */");
  75. return;
  76. } else if (address >= L1_DATA_A_START && address < L1_DATA_A_START + L1_DATA_A_LENGTH) {
  77. strcat(buf, "/* on-chip Data Bank A */");
  78. return;
  79. } else if (address >= L1_DATA_B_START && address < L1_DATA_B_START + L1_DATA_B_LENGTH) {
  80. strcat(buf, "/* on-chip Data Bank B */");
  81. return;
  82. }
  83. /*
  84. * Don't walk any of the vmas if we are oopsing, it has been known
  85. * to cause problems - corrupt vmas (kernel crashes) cause double faults
  86. */
  87. if (oops_in_progress) {
  88. strcat(buf, "/* kernel dynamic memory (maybe user-space) */");
  89. return;
  90. }
  91. /* looks like we're off in user-land, so let's walk all the
  92. * mappings of all our processes and see if we can't be a whee
  93. * bit more specific
  94. */
  95. write_lock_irqsave(&tasklist_lock, flags);
  96. for_each_process(p) {
  97. mm = (in_atomic ? p->mm : get_task_mm(p));
  98. if (!mm)
  99. continue;
  100. if (!down_read_trylock(&mm->mmap_sem)) {
  101. if (!in_atomic)
  102. mmput(mm);
  103. continue;
  104. }
  105. for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
  106. struct vm_area_struct *vma;
  107. vma = rb_entry(n, struct vm_area_struct, vm_rb);
  108. if (address >= vma->vm_start && address < vma->vm_end) {
  109. char _tmpbuf[256];
  110. char *name = p->comm;
  111. struct file *file = vma->vm_file;
  112. if (file) {
  113. char *d_name = d_path(&file->f_path, _tmpbuf,
  114. sizeof(_tmpbuf));
  115. if (!IS_ERR(d_name))
  116. name = d_name;
  117. }
  118. /* FLAT does not have its text aligned to the start of
  119. * the map while FDPIC ELF does ...
  120. */
  121. /* before we can check flat/fdpic, we need to
  122. * make sure current is valid
  123. */
  124. if ((unsigned long)current >= FIXED_CODE_START &&
  125. !((unsigned long)current & 0x3)) {
  126. if (current->mm &&
  127. (address > current->mm->start_code) &&
  128. (address < current->mm->end_code))
  129. offset = address - current->mm->start_code;
  130. else
  131. offset = (address - vma->vm_start) +
  132. (vma->vm_pgoff << PAGE_SHIFT);
  133. sprintf(buf, "[ %s + 0x%lx ]", name, offset);
  134. } else
  135. sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
  136. name, vma->vm_start, vma->vm_end);
  137. up_read(&mm->mmap_sem);
  138. if (!in_atomic)
  139. mmput(mm);
  140. if (buf[0] == '\0')
  141. sprintf(buf, "[ %s ] dynamic memory", name);
  142. goto done;
  143. }
  144. }
  145. up_read(&mm->mmap_sem);
  146. if (!in_atomic)
  147. mmput(mm);
  148. }
  149. /*
  150. * we were unable to find this address anywhere,
  151. * or some MMs were skipped because they were in use.
  152. */
  153. sprintf(buf, "/* kernel dynamic memory */");
  154. done:
  155. write_unlock_irqrestore(&tasklist_lock, flags);
  156. }
  157. #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
  158. /*
  159. * Similar to get_user, do some address checking, then dereference
  160. * Return true on success, false on bad address
  161. */
  162. bool get_mem16(unsigned short *val, unsigned short *address)
  163. {
  164. unsigned long addr = (unsigned long)address;
  165. /* Check for odd addresses */
  166. if (addr & 0x1)
  167. return false;
  168. switch (bfin_mem_access_type(addr, 2)) {
  169. case BFIN_MEM_ACCESS_CORE:
  170. case BFIN_MEM_ACCESS_CORE_ONLY:
  171. *val = *address;
  172. return true;
  173. case BFIN_MEM_ACCESS_DMA:
  174. dma_memcpy(val, address, 2);
  175. return true;
  176. case BFIN_MEM_ACCESS_ITEST:
  177. isram_memcpy(val, address, 2);
  178. return true;
  179. default: /* invalid access */
  180. return false;
  181. }
  182. }
  183. bool get_instruction(unsigned int *val, unsigned short *address)
  184. {
  185. unsigned long addr = (unsigned long)address;
  186. unsigned short opcode0, opcode1;
  187. /* Check for odd addresses */
  188. if (addr & 0x1)
  189. return false;
  190. /* MMR region will never have instructions */
  191. if (addr >= SYSMMR_BASE)
  192. return false;
  193. /* Scratchpad will never have instructions */
  194. if (addr >= L1_SCRATCH_START && addr < L1_SCRATCH_START + L1_SCRATCH_LENGTH)
  195. return false;
  196. /* Data banks will never have instructions */
  197. if (addr >= BOOT_ROM_START + BOOT_ROM_LENGTH && addr < L1_CODE_START)
  198. return false;
  199. if (!get_mem16(&opcode0, address))
  200. return false;
  201. /* was this a 32-bit instruction? If so, get the next 16 bits */
  202. if ((opcode0 & 0xc000) == 0xc000) {
  203. if (!get_mem16(&opcode1, address + 1))
  204. return false;
  205. *val = (opcode0 << 16) + opcode1;
  206. } else
  207. *val = opcode0;
  208. return true;
  209. }
  210. #if defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
  211. /*
  212. * decode the instruction if we are printing out the trace, as it
  213. * makes things easier to follow, without running it through objdump
  214. * Decode the change of flow, and the common load/store instructions
  215. * which are the main cause for faults, and discontinuities in the trace
  216. * buffer.
  217. */
  218. #define ProgCtrl_opcode 0x0000
  219. #define ProgCtrl_poprnd_bits 0
  220. #define ProgCtrl_poprnd_mask 0xf
  221. #define ProgCtrl_prgfunc_bits 4
  222. #define ProgCtrl_prgfunc_mask 0xf
  223. #define ProgCtrl_code_bits 8
  224. #define ProgCtrl_code_mask 0xff
  225. static void decode_ProgCtrl_0(unsigned int opcode)
  226. {
  227. int poprnd = ((opcode >> ProgCtrl_poprnd_bits) & ProgCtrl_poprnd_mask);
  228. int prgfunc = ((opcode >> ProgCtrl_prgfunc_bits) & ProgCtrl_prgfunc_mask);
  229. if (prgfunc == 0 && poprnd == 0)
  230. pr_cont("NOP");
  231. else if (prgfunc == 1 && poprnd == 0)
  232. pr_cont("RTS");
  233. else if (prgfunc == 1 && poprnd == 1)
  234. pr_cont("RTI");
  235. else if (prgfunc == 1 && poprnd == 2)
  236. pr_cont("RTX");
  237. else if (prgfunc == 1 && poprnd == 3)
  238. pr_cont("RTN");
  239. else if (prgfunc == 1 && poprnd == 4)
  240. pr_cont("RTE");
  241. else if (prgfunc == 2 && poprnd == 0)
  242. pr_cont("IDLE");
  243. else if (prgfunc == 2 && poprnd == 3)
  244. pr_cont("CSYNC");
  245. else if (prgfunc == 2 && poprnd == 4)
  246. pr_cont("SSYNC");
  247. else if (prgfunc == 2 && poprnd == 5)
  248. pr_cont("EMUEXCPT");
  249. else if (prgfunc == 3)
  250. pr_cont("CLI R%i", poprnd);
  251. else if (prgfunc == 4)
  252. pr_cont("STI R%i", poprnd);
  253. else if (prgfunc == 5)
  254. pr_cont("JUMP (P%i)", poprnd);
  255. else if (prgfunc == 6)
  256. pr_cont("CALL (P%i)", poprnd);
  257. else if (prgfunc == 7)
  258. pr_cont("CALL (PC + P%i)", poprnd);
  259. else if (prgfunc == 8)
  260. pr_cont("JUMP (PC + P%i", poprnd);
  261. else if (prgfunc == 9)
  262. pr_cont("RAISE %i", poprnd);
  263. else if (prgfunc == 10)
  264. pr_cont("EXCPT %i", poprnd);
  265. else
  266. pr_cont("0x%04x", opcode);
  267. }
  268. #define BRCC_opcode 0x1000
  269. #define BRCC_offset_bits 0
  270. #define BRCC_offset_mask 0x3ff
  271. #define BRCC_B_bits 10
  272. #define BRCC_B_mask 0x1
  273. #define BRCC_T_bits 11
  274. #define BRCC_T_mask 0x1
  275. #define BRCC_code_bits 12
  276. #define BRCC_code_mask 0xf
  277. static void decode_BRCC_0(unsigned int opcode)
  278. {
  279. int B = ((opcode >> BRCC_B_bits) & BRCC_B_mask);
  280. int T = ((opcode >> BRCC_T_bits) & BRCC_T_mask);
  281. pr_cont("IF %sCC JUMP pcrel %s", T ? "" : "!", B ? "(BP)" : "");
  282. }
  283. #define CALLa_opcode 0xe2000000
  284. #define CALLa_addr_bits 0
  285. #define CALLa_addr_mask 0xffffff
  286. #define CALLa_S_bits 24
  287. #define CALLa_S_mask 0x1
  288. #define CALLa_code_bits 25
  289. #define CALLa_code_mask 0x7f
  290. static void decode_CALLa_0(unsigned int opcode)
  291. {
  292. int S = ((opcode >> (CALLa_S_bits - 16)) & CALLa_S_mask);
  293. if (S)
  294. pr_cont("CALL pcrel");
  295. else
  296. pr_cont("JUMP.L");
  297. }
  298. #define LoopSetup_opcode 0xe0800000
  299. #define LoopSetup_eoffset_bits 0
  300. #define LoopSetup_eoffset_mask 0x3ff
  301. #define LoopSetup_dontcare_bits 10
  302. #define LoopSetup_dontcare_mask 0x3
  303. #define LoopSetup_reg_bits 12
  304. #define LoopSetup_reg_mask 0xf
  305. #define LoopSetup_soffset_bits 16
  306. #define LoopSetup_soffset_mask 0xf
  307. #define LoopSetup_c_bits 20
  308. #define LoopSetup_c_mask 0x1
  309. #define LoopSetup_rop_bits 21
  310. #define LoopSetup_rop_mask 0x3
  311. #define LoopSetup_code_bits 23
  312. #define LoopSetup_code_mask 0x1ff
  313. static void decode_LoopSetup_0(unsigned int opcode)
  314. {
  315. int c = ((opcode >> LoopSetup_c_bits) & LoopSetup_c_mask);
  316. int reg = ((opcode >> LoopSetup_reg_bits) & LoopSetup_reg_mask);
  317. int rop = ((opcode >> LoopSetup_rop_bits) & LoopSetup_rop_mask);
  318. pr_cont("LSETUP <> LC%i", c);
  319. if ((rop & 1) == 1)
  320. pr_cont("= P%i", reg);
  321. if ((rop & 2) == 2)
  322. pr_cont(" >> 0x1");
  323. }
  324. #define DspLDST_opcode 0x9c00
  325. #define DspLDST_reg_bits 0
  326. #define DspLDST_reg_mask 0x7
  327. #define DspLDST_i_bits 3
  328. #define DspLDST_i_mask 0x3
  329. #define DspLDST_m_bits 5
  330. #define DspLDST_m_mask 0x3
  331. #define DspLDST_aop_bits 7
  332. #define DspLDST_aop_mask 0x3
  333. #define DspLDST_W_bits 9
  334. #define DspLDST_W_mask 0x1
  335. #define DspLDST_code_bits 10
  336. #define DspLDST_code_mask 0x3f
  337. static void decode_dspLDST_0(unsigned int opcode)
  338. {
  339. int i = ((opcode >> DspLDST_i_bits) & DspLDST_i_mask);
  340. int m = ((opcode >> DspLDST_m_bits) & DspLDST_m_mask);
  341. int W = ((opcode >> DspLDST_W_bits) & DspLDST_W_mask);
  342. int aop = ((opcode >> DspLDST_aop_bits) & DspLDST_aop_mask);
  343. int reg = ((opcode >> DspLDST_reg_bits) & DspLDST_reg_mask);
  344. if (W == 0) {
  345. pr_cont("R%i", reg);
  346. switch (m) {
  347. case 0:
  348. pr_cont(" = ");
  349. break;
  350. case 1:
  351. pr_cont(".L = ");
  352. break;
  353. case 2:
  354. pr_cont(".W = ");
  355. break;
  356. }
  357. }
  358. pr_cont("[ I%i", i);
  359. switch (aop) {
  360. case 0:
  361. pr_cont("++ ]");
  362. break;
  363. case 1:
  364. pr_cont("-- ]");
  365. break;
  366. }
  367. if (W == 1) {
  368. pr_cont(" = R%i", reg);
  369. switch (m) {
  370. case 1:
  371. pr_cont(".L = ");
  372. break;
  373. case 2:
  374. pr_cont(".W = ");
  375. break;
  376. }
  377. }
  378. }
  379. #define LDST_opcode 0x9000
  380. #define LDST_reg_bits 0
  381. #define LDST_reg_mask 0x7
  382. #define LDST_ptr_bits 3
  383. #define LDST_ptr_mask 0x7
  384. #define LDST_Z_bits 6
  385. #define LDST_Z_mask 0x1
  386. #define LDST_aop_bits 7
  387. #define LDST_aop_mask 0x3
  388. #define LDST_W_bits 9
  389. #define LDST_W_mask 0x1
  390. #define LDST_sz_bits 10
  391. #define LDST_sz_mask 0x3
  392. #define LDST_code_bits 12
  393. #define LDST_code_mask 0xf
  394. static void decode_LDST_0(unsigned int opcode)
  395. {
  396. int Z = ((opcode >> LDST_Z_bits) & LDST_Z_mask);
  397. int W = ((opcode >> LDST_W_bits) & LDST_W_mask);
  398. int sz = ((opcode >> LDST_sz_bits) & LDST_sz_mask);
  399. int aop = ((opcode >> LDST_aop_bits) & LDST_aop_mask);
  400. int reg = ((opcode >> LDST_reg_bits) & LDST_reg_mask);
  401. int ptr = ((opcode >> LDST_ptr_bits) & LDST_ptr_mask);
  402. if (W == 0)
  403. pr_cont("%s%i = ", (sz == 0 && Z == 1) ? "P" : "R", reg);
  404. switch (sz) {
  405. case 1:
  406. pr_cont("W");
  407. break;
  408. case 2:
  409. pr_cont("B");
  410. break;
  411. }
  412. pr_cont("[P%i", ptr);
  413. switch (aop) {
  414. case 0:
  415. pr_cont("++");
  416. break;
  417. case 1:
  418. pr_cont("--");
  419. break;
  420. }
  421. pr_cont("]");
  422. if (W == 1)
  423. pr_cont(" = %s%i ", (sz == 0 && Z == 1) ? "P" : "R", reg);
  424. if (sz) {
  425. if (Z)
  426. pr_cont(" (X)");
  427. else
  428. pr_cont(" (Z)");
  429. }
  430. }
  431. #define LDSTii_opcode 0xa000
  432. #define LDSTii_reg_bit 0
  433. #define LDSTii_reg_mask 0x7
  434. #define LDSTii_ptr_bit 3
  435. #define LDSTii_ptr_mask 0x7
  436. #define LDSTii_offset_bit 6
  437. #define LDSTii_offset_mask 0xf
  438. #define LDSTii_op_bit 10
  439. #define LDSTii_op_mask 0x3
  440. #define LDSTii_W_bit 12
  441. #define LDSTii_W_mask 0x1
  442. #define LDSTii_code_bit 13
  443. #define LDSTii_code_mask 0x7
  444. static void decode_LDSTii_0(unsigned int opcode)
  445. {
  446. int reg = ((opcode >> LDSTii_reg_bit) & LDSTii_reg_mask);
  447. int ptr = ((opcode >> LDSTii_ptr_bit) & LDSTii_ptr_mask);
  448. int offset = ((opcode >> LDSTii_offset_bit) & LDSTii_offset_mask);
  449. int op = ((opcode >> LDSTii_op_bit) & LDSTii_op_mask);
  450. int W = ((opcode >> LDSTii_W_bit) & LDSTii_W_mask);
  451. if (W == 0) {
  452. pr_cont("%s%i = %s[P%i + %i]", op == 3 ? "R" : "P", reg,
  453. op == 1 || op == 2 ? "" : "W", ptr, offset);
  454. if (op == 2)
  455. pr_cont("(Z)");
  456. if (op == 3)
  457. pr_cont("(X)");
  458. } else {
  459. pr_cont("%s[P%i + %i] = %s%i", op == 0 ? "" : "W", ptr,
  460. offset, op == 3 ? "P" : "R", reg);
  461. }
  462. }
  463. #define LDSTidxI_opcode 0xe4000000
  464. #define LDSTidxI_offset_bits 0
  465. #define LDSTidxI_offset_mask 0xffff
  466. #define LDSTidxI_reg_bits 16
  467. #define LDSTidxI_reg_mask 0x7
  468. #define LDSTidxI_ptr_bits 19
  469. #define LDSTidxI_ptr_mask 0x7
  470. #define LDSTidxI_sz_bits 22
  471. #define LDSTidxI_sz_mask 0x3
  472. #define LDSTidxI_Z_bits 24
  473. #define LDSTidxI_Z_mask 0x1
  474. #define LDSTidxI_W_bits 25
  475. #define LDSTidxI_W_mask 0x1
  476. #define LDSTidxI_code_bits 26
  477. #define LDSTidxI_code_mask 0x3f
  478. static void decode_LDSTidxI_0(unsigned int opcode)
  479. {
  480. int Z = ((opcode >> LDSTidxI_Z_bits) & LDSTidxI_Z_mask);
  481. int W = ((opcode >> LDSTidxI_W_bits) & LDSTidxI_W_mask);
  482. int sz = ((opcode >> LDSTidxI_sz_bits) & LDSTidxI_sz_mask);
  483. int reg = ((opcode >> LDSTidxI_reg_bits) & LDSTidxI_reg_mask);
  484. int ptr = ((opcode >> LDSTidxI_ptr_bits) & LDSTidxI_ptr_mask);
  485. int offset = ((opcode >> LDSTidxI_offset_bits) & LDSTidxI_offset_mask);
  486. if (W == 0)
  487. pr_cont("%s%i = ", sz == 0 && Z == 1 ? "P" : "R", reg);
  488. if (sz == 1)
  489. pr_cont("W");
  490. if (sz == 2)
  491. pr_cont("B");
  492. pr_cont("[P%i + %s0x%x]", ptr, offset & 0x20 ? "-" : "",
  493. (offset & 0x1f) << 2);
  494. if (W == 0 && sz != 0) {
  495. if (Z)
  496. pr_cont("(X)");
  497. else
  498. pr_cont("(Z)");
  499. }
  500. if (W == 1)
  501. pr_cont("= %s%i", (sz == 0 && Z == 1) ? "P" : "R", reg);
  502. }
  503. static void decode_opcode(unsigned int opcode)
  504. {
  505. #ifdef CONFIG_BUG
  506. if (opcode == BFIN_BUG_OPCODE)
  507. pr_cont("BUG");
  508. else
  509. #endif
  510. if ((opcode & 0xffffff00) == ProgCtrl_opcode)
  511. decode_ProgCtrl_0(opcode);
  512. else if ((opcode & 0xfffff000) == BRCC_opcode)
  513. decode_BRCC_0(opcode);
  514. else if ((opcode & 0xfffff000) == 0x2000)
  515. pr_cont("JUMP.S");
  516. else if ((opcode & 0xfe000000) == CALLa_opcode)
  517. decode_CALLa_0(opcode);
  518. else if ((opcode & 0xff8000C0) == LoopSetup_opcode)
  519. decode_LoopSetup_0(opcode);
  520. else if ((opcode & 0xfffffc00) == DspLDST_opcode)
  521. decode_dspLDST_0(opcode);
  522. else if ((opcode & 0xfffff000) == LDST_opcode)
  523. decode_LDST_0(opcode);
  524. else if ((opcode & 0xffffe000) == LDSTii_opcode)
  525. decode_LDSTii_0(opcode);
  526. else if ((opcode & 0xfc000000) == LDSTidxI_opcode)
  527. decode_LDSTidxI_0(opcode);
  528. else if (opcode & 0xffff0000)
  529. pr_cont("0x%08x", opcode);
  530. else
  531. pr_cont("0x%04x", opcode);
  532. }
  533. #define BIT_MULTI_INS 0x08000000
  534. static void decode_instruction(unsigned short *address)
  535. {
  536. unsigned int opcode;
  537. if (!get_instruction(&opcode, address))
  538. return;
  539. decode_opcode(opcode);
  540. /* If things are a 32-bit instruction, it has the possibility of being
  541. * a multi-issue instruction (a 32-bit, and 2 16 bit instrucitions)
  542. * This test collidates with the unlink instruction, so disallow that
  543. */
  544. if ((opcode & 0xc0000000) == 0xc0000000 &&
  545. (opcode & BIT_MULTI_INS) &&
  546. (opcode & 0xe8000000) != 0xe8000000) {
  547. pr_cont(" || ");
  548. if (!get_instruction(&opcode, address + 2))
  549. return;
  550. decode_opcode(opcode);
  551. pr_cont(" || ");
  552. if (!get_instruction(&opcode, address + 3))
  553. return;
  554. decode_opcode(opcode);
  555. }
  556. }
  557. #endif
  558. void dump_bfin_trace_buffer(void)
  559. {
  560. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  561. int tflags, i = 0, fault = 0;
  562. char buf[150];
  563. unsigned short *addr;
  564. unsigned int cpu = raw_smp_processor_id();
  565. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  566. int j, index;
  567. #endif
  568. trace_buffer_save(tflags);
  569. pr_notice("Hardware Trace:\n");
  570. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  571. pr_notice("WARNING: Expanded trace turned on - can not trace exceptions\n");
  572. #endif
  573. if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
  574. for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
  575. addr = (unsigned short *)bfin_read_TBUF();
  576. decode_address(buf, (unsigned long)addr);
  577. pr_notice("%4i Target : %s\n", i, buf);
  578. /* Normally, the faulting instruction doesn't go into
  579. * the trace buffer, (since it doesn't commit), so
  580. * we print out the fault address here
  581. */
  582. if (!fault && addr == (unsigned short *)trap &&
  583. (cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE) > VEC_EXCPT15) {
  584. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  585. pr_notice(" FAULT : %s ", buf);
  586. decode_instruction((unsigned short *)cpu_pda[cpu].icplb_fault_addr);
  587. pr_cont("\n");
  588. fault = 1;
  589. }
  590. addr = (unsigned short *)bfin_read_TBUF();
  591. decode_address(buf, (unsigned long)addr);
  592. pr_notice(" Source : %s ", buf);
  593. decode_instruction(addr);
  594. pr_cont("\n");
  595. }
  596. }
  597. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  598. if (trace_buff_offset)
  599. index = trace_buff_offset / 4;
  600. else
  601. index = EXPAND_LEN;
  602. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  603. while (j) {
  604. decode_address(buf, software_trace_buff[index]);
  605. pr_notice("%4i Target : %s\n", i, buf);
  606. index -= 1;
  607. if (index < 0)
  608. index = EXPAND_LEN;
  609. decode_address(buf, software_trace_buff[index]);
  610. pr_notice(" Source : %s ", buf);
  611. decode_instruction((unsigned short *)software_trace_buff[index]);
  612. pr_cont("\n");
  613. index -= 1;
  614. if (index < 0)
  615. index = EXPAND_LEN;
  616. j--;
  617. i++;
  618. }
  619. #endif
  620. trace_buffer_restore(tflags);
  621. #endif
  622. }
  623. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  624. void dump_bfin_process(struct pt_regs *fp)
  625. {
  626. /* We should be able to look at fp->ipend, but we don't push it on the
  627. * stack all the time, so do this until we fix that */
  628. unsigned int context = bfin_read_IPEND();
  629. if (oops_in_progress)
  630. pr_emerg("Kernel OOPS in progress\n");
  631. if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
  632. pr_notice("HW Error context\n");
  633. else if (context & 0x0020)
  634. pr_notice("Deferred Exception context\n");
  635. else if (context & 0x3FC0)
  636. pr_notice("Interrupt context\n");
  637. else if (context & 0x4000)
  638. pr_notice("Deferred Interrupt context\n");
  639. else if (context & 0x8000)
  640. pr_notice("Kernel process context\n");
  641. /* Because we are crashing, and pointers could be bad, we check things
  642. * pretty closely before we use them
  643. */
  644. if ((unsigned long)current >= FIXED_CODE_START &&
  645. !((unsigned long)current & 0x3) && current->pid) {
  646. pr_notice("CURRENT PROCESS:\n");
  647. if (current->comm >= (char *)FIXED_CODE_START)
  648. pr_notice("COMM=%s PID=%d",
  649. current->comm, current->pid);
  650. else
  651. pr_notice("COMM= invalid");
  652. pr_cont(" CPU=%d\n", current_thread_info()->cpu);
  653. if (!((unsigned long)current->mm & 0x3) &&
  654. (unsigned long)current->mm >= FIXED_CODE_START) {
  655. pr_notice("TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n",
  656. (void *)current->mm->start_code,
  657. (void *)current->mm->end_code,
  658. (void *)current->mm->start_data,
  659. (void *)current->mm->end_data);
  660. pr_notice(" BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
  661. (void *)current->mm->end_data,
  662. (void *)current->mm->brk,
  663. (void *)current->mm->start_stack);
  664. } else
  665. pr_notice("invalid mm\n");
  666. } else
  667. pr_notice("No Valid process in current context\n");
  668. }
  669. void dump_bfin_mem(struct pt_regs *fp)
  670. {
  671. unsigned short *addr, *erraddr, val = 0, err = 0;
  672. char sti = 0, buf[6];
  673. erraddr = (void *)fp->pc;
  674. pr_notice("return address: [0x%p]; contents of:", erraddr);
  675. for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
  676. addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
  677. addr++) {
  678. if (!((unsigned long)addr & 0xF))
  679. pr_notice("0x%p: ", addr);
  680. if (!get_mem16(&val, addr)) {
  681. val = 0;
  682. sprintf(buf, "????");
  683. } else
  684. sprintf(buf, "%04x", val);
  685. if (addr == erraddr) {
  686. pr_cont("[%s]", buf);
  687. err = val;
  688. } else
  689. pr_cont(" %s ", buf);
  690. /* Do any previous instructions turn on interrupts? */
  691. if (addr <= erraddr && /* in the past */
  692. ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
  693. val == 0x017b)) /* [SP++] = RETI */
  694. sti = 1;
  695. }
  696. pr_cont("\n");
  697. /* Hardware error interrupts can be deferred */
  698. if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
  699. oops_in_progress)){
  700. pr_notice("Looks like this was a deferred error - sorry\n");
  701. #ifndef CONFIG_DEBUG_HWERR
  702. pr_notice("The remaining message may be meaningless\n");
  703. pr_notice("You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
  704. #else
  705. /* If we are handling only one peripheral interrupt
  706. * and current mm and pid are valid, and the last error
  707. * was in that user space process's text area
  708. * print it out - because that is where the problem exists
  709. */
  710. if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
  711. (current->pid && current->mm)) {
  712. /* And the last RETI points to the current userspace context */
  713. if ((fp + 1)->pc >= current->mm->start_code &&
  714. (fp + 1)->pc <= current->mm->end_code) {
  715. pr_notice("It might be better to look around here :\n");
  716. pr_notice("-------------------------------------------\n");
  717. show_regs(fp + 1);
  718. pr_notice("-------------------------------------------\n");
  719. }
  720. }
  721. #endif
  722. }
  723. }
  724. void show_regs(struct pt_regs *fp)
  725. {
  726. char buf[150];
  727. struct irqaction *action;
  728. unsigned int i;
  729. unsigned long flags = 0;
  730. unsigned int cpu = raw_smp_processor_id();
  731. unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
  732. pr_notice("\n");
  733. if (CPUID != bfin_cpuid())
  734. pr_notice("Compiled for cpu family 0x%04x (Rev %d), "
  735. "but running on:0x%04x (Rev %d)\n",
  736. CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
  737. pr_notice("ADSP-%s-0.%d",
  738. CPU, bfin_compiled_revid());
  739. if (bfin_compiled_revid() != bfin_revid())
  740. pr_cont("(Detected 0.%d)", bfin_revid());
  741. pr_cont(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
  742. get_cclk()/1000000, get_sclk()/1000000,
  743. #ifdef CONFIG_MPU
  744. "mpu on"
  745. #else
  746. "mpu off"
  747. #endif
  748. );
  749. pr_notice("%s", linux_banner);
  750. pr_notice("\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
  751. pr_notice(" SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
  752. (long)fp->seqstat, fp->ipend, cpu_pda[raw_smp_processor_id()].ex_imask, fp->syscfg);
  753. if (fp->ipend & EVT_IRPTEN)
  754. pr_notice(" Global Interrupts Disabled (IPEND[4])\n");
  755. if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
  756. EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
  757. pr_notice(" Peripheral interrupts masked off\n");
  758. if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
  759. pr_notice(" Kernel interrupts masked off\n");
  760. if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
  761. pr_notice(" HWERRCAUSE: 0x%lx\n",
  762. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  763. #ifdef EBIU_ERRMST
  764. /* If the error was from the EBIU, print it out */
  765. if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
  766. pr_notice(" EBIU Error Reason : 0x%04x\n",
  767. bfin_read_EBIU_ERRMST());
  768. pr_notice(" EBIU Error Address : 0x%08x\n",
  769. bfin_read_EBIU_ERRADD());
  770. }
  771. #endif
  772. }
  773. pr_notice(" EXCAUSE : 0x%lx\n",
  774. fp->seqstat & SEQSTAT_EXCAUSE);
  775. for (i = 2; i <= 15 ; i++) {
  776. if (fp->ipend & (1 << i)) {
  777. if (i != 4) {
  778. decode_address(buf, bfin_read32(EVT0 + 4*i));
  779. pr_notice(" physical IVG%i asserted : %s\n", i, buf);
  780. } else
  781. pr_notice(" interrupts disabled\n");
  782. }
  783. }
  784. /* if no interrupts are going off, don't print this out */
  785. if (fp->ipend & ~0x3F) {
  786. for (i = 0; i < (NR_IRQS - 1); i++) {
  787. if (!in_atomic)
  788. raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
  789. action = irq_desc[i].action;
  790. if (!action)
  791. goto unlock;
  792. decode_address(buf, (unsigned int)action->handler);
  793. pr_notice(" logical irq %3d mapped : %s", i, buf);
  794. for (action = action->next; action; action = action->next) {
  795. decode_address(buf, (unsigned int)action->handler);
  796. pr_cont(", %s", buf);
  797. }
  798. pr_cont("\n");
  799. unlock:
  800. if (!in_atomic)
  801. raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  802. }
  803. }
  804. decode_address(buf, fp->rete);
  805. pr_notice(" RETE: %s\n", buf);
  806. decode_address(buf, fp->retn);
  807. pr_notice(" RETN: %s\n", buf);
  808. decode_address(buf, fp->retx);
  809. pr_notice(" RETX: %s\n", buf);
  810. decode_address(buf, fp->rets);
  811. pr_notice(" RETS: %s\n", buf);
  812. decode_address(buf, fp->pc);
  813. pr_notice(" PC : %s\n", buf);
  814. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  815. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  816. decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
  817. pr_notice("DCPLB_FAULT_ADDR: %s\n", buf);
  818. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  819. pr_notice("ICPLB_FAULT_ADDR: %s\n", buf);
  820. }
  821. pr_notice("PROCESSOR STATE:\n");
  822. pr_notice(" R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  823. fp->r0, fp->r1, fp->r2, fp->r3);
  824. pr_notice(" R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  825. fp->r4, fp->r5, fp->r6, fp->r7);
  826. pr_notice(" P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  827. fp->p0, fp->p1, fp->p2, fp->p3);
  828. pr_notice(" P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  829. fp->p4, fp->p5, fp->fp, (long)fp);
  830. pr_notice(" LB0: %08lx LT0: %08lx LC0: %08lx\n",
  831. fp->lb0, fp->lt0, fp->lc0);
  832. pr_notice(" LB1: %08lx LT1: %08lx LC1: %08lx\n",
  833. fp->lb1, fp->lt1, fp->lc1);
  834. pr_notice(" B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  835. fp->b0, fp->l0, fp->m0, fp->i0);
  836. pr_notice(" B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  837. fp->b1, fp->l1, fp->m1, fp->i1);
  838. pr_notice(" B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  839. fp->b2, fp->l2, fp->m2, fp->i2);
  840. pr_notice(" B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  841. fp->b3, fp->l3, fp->m3, fp->i3);
  842. pr_notice("A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  843. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  844. pr_notice("USP : %08lx ASTAT: %08lx\n",
  845. rdusp(), fp->astat);
  846. pr_notice("\n");
  847. }