trace.c 27 KB

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