trace.c 27 KB

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