trace.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  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 *)evt_ivhw)) {
  583. addr = (unsigned short *)bfin_read_TBUF();
  584. decode_address(buf, (unsigned long)addr);
  585. pr_notice(" FAULT : %s ", buf);
  586. decode_instruction(addr);
  587. pr_cont("\n");
  588. fault = 1;
  589. continue;
  590. }
  591. if (!fault && addr == (unsigned short *)trap &&
  592. (cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE) > VEC_EXCPT15) {
  593. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  594. pr_notice(" FAULT : %s ", buf);
  595. decode_instruction((unsigned short *)cpu_pda[cpu].icplb_fault_addr);
  596. pr_cont("\n");
  597. fault = 1;
  598. }
  599. addr = (unsigned short *)bfin_read_TBUF();
  600. decode_address(buf, (unsigned long)addr);
  601. pr_notice(" Source : %s ", buf);
  602. decode_instruction(addr);
  603. pr_cont("\n");
  604. }
  605. }
  606. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
  607. if (trace_buff_offset)
  608. index = trace_buff_offset / 4;
  609. else
  610. index = EXPAND_LEN;
  611. j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
  612. while (j) {
  613. decode_address(buf, software_trace_buff[index]);
  614. pr_notice("%4i Target : %s\n", i, buf);
  615. index -= 1;
  616. if (index < 0)
  617. index = EXPAND_LEN;
  618. decode_address(buf, software_trace_buff[index]);
  619. pr_notice(" Source : %s ", buf);
  620. decode_instruction((unsigned short *)software_trace_buff[index]);
  621. pr_cont("\n");
  622. index -= 1;
  623. if (index < 0)
  624. index = EXPAND_LEN;
  625. j--;
  626. i++;
  627. }
  628. #endif
  629. trace_buffer_restore(tflags);
  630. #endif
  631. }
  632. EXPORT_SYMBOL(dump_bfin_trace_buffer);
  633. void dump_bfin_process(struct pt_regs *fp)
  634. {
  635. /* We should be able to look at fp->ipend, but we don't push it on the
  636. * stack all the time, so do this until we fix that */
  637. unsigned int context = bfin_read_IPEND();
  638. if (oops_in_progress)
  639. pr_emerg("Kernel OOPS in progress\n");
  640. if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
  641. pr_notice("HW Error context\n");
  642. else if (context & 0x0020)
  643. pr_notice("Deferred Exception context\n");
  644. else if (context & 0x3FC0)
  645. pr_notice("Interrupt context\n");
  646. else if (context & 0x4000)
  647. pr_notice("Deferred Interrupt context\n");
  648. else if (context & 0x8000)
  649. pr_notice("Kernel process context\n");
  650. /* Because we are crashing, and pointers could be bad, we check things
  651. * pretty closely before we use them
  652. */
  653. if ((unsigned long)current >= FIXED_CODE_START &&
  654. !((unsigned long)current & 0x3) && current->pid) {
  655. pr_notice("CURRENT PROCESS:\n");
  656. if (current->comm >= (char *)FIXED_CODE_START)
  657. pr_notice("COMM=%s PID=%d",
  658. current->comm, current->pid);
  659. else
  660. pr_notice("COMM= invalid");
  661. pr_cont(" CPU=%d\n", current_thread_info()->cpu);
  662. if (!((unsigned long)current->mm & 0x3) &&
  663. (unsigned long)current->mm >= FIXED_CODE_START) {
  664. pr_notice("TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n",
  665. (void *)current->mm->start_code,
  666. (void *)current->mm->end_code,
  667. (void *)current->mm->start_data,
  668. (void *)current->mm->end_data);
  669. pr_notice(" BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
  670. (void *)current->mm->end_data,
  671. (void *)current->mm->brk,
  672. (void *)current->mm->start_stack);
  673. } else
  674. pr_notice("invalid mm\n");
  675. } else
  676. pr_notice("No Valid process in current context\n");
  677. }
  678. void dump_bfin_mem(struct pt_regs *fp)
  679. {
  680. unsigned short *addr, *erraddr, val = 0, err = 0;
  681. char sti = 0, buf[6];
  682. erraddr = (void *)fp->pc;
  683. pr_notice("return address: [0x%p]; contents of:", erraddr);
  684. for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
  685. addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
  686. addr++) {
  687. if (!((unsigned long)addr & 0xF))
  688. pr_notice("0x%p: ", addr);
  689. if (!get_mem16(&val, addr)) {
  690. val = 0;
  691. sprintf(buf, "????");
  692. } else
  693. sprintf(buf, "%04x", val);
  694. if (addr == erraddr) {
  695. pr_cont("[%s]", buf);
  696. err = val;
  697. } else
  698. pr_cont(" %s ", buf);
  699. /* Do any previous instructions turn on interrupts? */
  700. if (addr <= erraddr && /* in the past */
  701. ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
  702. val == 0x017b)) /* [SP++] = RETI */
  703. sti = 1;
  704. }
  705. pr_cont("\n");
  706. /* Hardware error interrupts can be deferred */
  707. if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
  708. oops_in_progress)){
  709. pr_notice("Looks like this was a deferred error - sorry\n");
  710. #ifndef CONFIG_DEBUG_HWERR
  711. pr_notice("The remaining message may be meaningless\n");
  712. pr_notice("You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
  713. #else
  714. /* If we are handling only one peripheral interrupt
  715. * and current mm and pid are valid, and the last error
  716. * was in that user space process's text area
  717. * print it out - because that is where the problem exists
  718. */
  719. if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
  720. (current->pid && current->mm)) {
  721. /* And the last RETI points to the current userspace context */
  722. if ((fp + 1)->pc >= current->mm->start_code &&
  723. (fp + 1)->pc <= current->mm->end_code) {
  724. pr_notice("It might be better to look around here :\n");
  725. pr_notice("-------------------------------------------\n");
  726. show_regs(fp + 1);
  727. pr_notice("-------------------------------------------\n");
  728. }
  729. }
  730. #endif
  731. }
  732. }
  733. void show_regs(struct pt_regs *fp)
  734. {
  735. char buf[150];
  736. struct irqaction *action;
  737. unsigned int i;
  738. unsigned long flags = 0;
  739. unsigned int cpu = raw_smp_processor_id();
  740. unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
  741. pr_notice("\n");
  742. if (CPUID != bfin_cpuid())
  743. pr_notice("Compiled for cpu family 0x%04x (Rev %d), "
  744. "but running on:0x%04x (Rev %d)\n",
  745. CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
  746. pr_notice("ADSP-%s-0.%d",
  747. CPU, bfin_compiled_revid());
  748. if (bfin_compiled_revid() != bfin_revid())
  749. pr_cont("(Detected 0.%d)", bfin_revid());
  750. pr_cont(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
  751. get_cclk()/1000000, get_sclk()/1000000,
  752. #ifdef CONFIG_MPU
  753. "mpu on"
  754. #else
  755. "mpu off"
  756. #endif
  757. );
  758. pr_notice("%s", linux_banner);
  759. pr_notice("\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
  760. pr_notice(" SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
  761. (long)fp->seqstat, fp->ipend, cpu_pda[raw_smp_processor_id()].ex_imask, fp->syscfg);
  762. if (fp->ipend & EVT_IRPTEN)
  763. pr_notice(" Global Interrupts Disabled (IPEND[4])\n");
  764. if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
  765. EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
  766. pr_notice(" Peripheral interrupts masked off\n");
  767. if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
  768. pr_notice(" Kernel interrupts masked off\n");
  769. if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
  770. pr_notice(" HWERRCAUSE: 0x%lx\n",
  771. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  772. #ifdef EBIU_ERRMST
  773. /* If the error was from the EBIU, print it out */
  774. if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
  775. pr_notice(" EBIU Error Reason : 0x%04x\n",
  776. bfin_read_EBIU_ERRMST());
  777. pr_notice(" EBIU Error Address : 0x%08x\n",
  778. bfin_read_EBIU_ERRADD());
  779. }
  780. #endif
  781. }
  782. pr_notice(" EXCAUSE : 0x%lx\n",
  783. fp->seqstat & SEQSTAT_EXCAUSE);
  784. for (i = 2; i <= 15 ; i++) {
  785. if (fp->ipend & (1 << i)) {
  786. if (i != 4) {
  787. decode_address(buf, bfin_read32(EVT0 + 4*i));
  788. pr_notice(" physical IVG%i asserted : %s\n", i, buf);
  789. } else
  790. pr_notice(" interrupts disabled\n");
  791. }
  792. }
  793. /* if no interrupts are going off, don't print this out */
  794. if (fp->ipend & ~0x3F) {
  795. for (i = 0; i < (NR_IRQS - 1); i++) {
  796. if (!in_atomic)
  797. raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
  798. action = irq_desc[i].action;
  799. if (!action)
  800. goto unlock;
  801. decode_address(buf, (unsigned int)action->handler);
  802. pr_notice(" logical irq %3d mapped : %s", i, buf);
  803. for (action = action->next; action; action = action->next) {
  804. decode_address(buf, (unsigned int)action->handler);
  805. pr_cont(", %s", buf);
  806. }
  807. pr_cont("\n");
  808. unlock:
  809. if (!in_atomic)
  810. raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  811. }
  812. }
  813. decode_address(buf, fp->rete);
  814. pr_notice(" RETE: %s\n", buf);
  815. decode_address(buf, fp->retn);
  816. pr_notice(" RETN: %s\n", buf);
  817. decode_address(buf, fp->retx);
  818. pr_notice(" RETX: %s\n", buf);
  819. decode_address(buf, fp->rets);
  820. pr_notice(" RETS: %s\n", buf);
  821. decode_address(buf, fp->pc);
  822. pr_notice(" PC : %s\n", buf);
  823. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  824. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  825. decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
  826. pr_notice("DCPLB_FAULT_ADDR: %s\n", buf);
  827. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  828. pr_notice("ICPLB_FAULT_ADDR: %s\n", buf);
  829. }
  830. pr_notice("PROCESSOR STATE:\n");
  831. pr_notice(" R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  832. fp->r0, fp->r1, fp->r2, fp->r3);
  833. pr_notice(" R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  834. fp->r4, fp->r5, fp->r6, fp->r7);
  835. pr_notice(" P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  836. fp->p0, fp->p1, fp->p2, fp->p3);
  837. pr_notice(" P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  838. fp->p4, fp->p5, fp->fp, (long)fp);
  839. pr_notice(" LB0: %08lx LT0: %08lx LC0: %08lx\n",
  840. fp->lb0, fp->lt0, fp->lc0);
  841. pr_notice(" LB1: %08lx LT1: %08lx LC1: %08lx\n",
  842. fp->lb1, fp->lt1, fp->lc1);
  843. pr_notice(" B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  844. fp->b0, fp->l0, fp->m0, fp->i0);
  845. pr_notice(" B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  846. fp->b1, fp->l1, fp->m1, fp->i1);
  847. pr_notice(" B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  848. fp->b2, fp->l2, fp->m2, fp->i2);
  849. pr_notice(" B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  850. fp->b3, fp->l3, fp->m3, fp->i3);
  851. pr_notice("A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  852. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  853. pr_notice("USP : %08lx ASTAT: %08lx\n",
  854. rdusp(), fp->astat);
  855. pr_notice("\n");
  856. }