trace.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/module.h>
  16. #include <linux/kallsyms.h>
  17. #include <linux/err.h>
  18. #include <linux/fs.h>
  19. #include <linux/irq.h>
  20. #include <asm/dma.h>
  21. #include <asm/trace.h>
  22. #include <asm/fixed_code.h>
  23. #include <asm/traps.h>
  24. #include <asm/irq_handler.h>
  25. #include <asm/pda.h>
  26. void decode_address(char *buf, unsigned long address)
  27. {
  28. struct task_struct *p;
  29. struct mm_struct *mm;
  30. unsigned long offset;
  31. struct rb_node *n;
  32. #ifdef CONFIG_KALLSYMS
  33. unsigned long symsize;
  34. const char *symname;
  35. char *modname;
  36. char *delim = ":";
  37. char namebuf[128];
  38. #endif
  39. buf += sprintf(buf, "<0x%08lx> ", address);
  40. #ifdef CONFIG_KALLSYMS
  41. /* look up the address and see if we are in kernel space */
  42. symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
  43. if (symname) {
  44. /* yeah! kernel space! */
  45. if (!modname)
  46. modname = delim = "";
  47. sprintf(buf, "{ %s%s%s%s + 0x%lx }",
  48. delim, modname, delim, symname,
  49. (unsigned long)offset);
  50. return;
  51. }
  52. #endif
  53. if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
  54. /* Problem in fixed code section? */
  55. strcat(buf, "/* Maybe fixed code section */");
  56. return;
  57. } else if (address < CONFIG_BOOT_LOAD) {
  58. /* Problem somewhere before the kernel start address */
  59. strcat(buf, "/* Maybe null pointer? */");
  60. return;
  61. } else if (address >= COREMMR_BASE) {
  62. strcat(buf, "/* core mmrs */");
  63. return;
  64. } else if (address >= SYSMMR_BASE) {
  65. strcat(buf, "/* system mmrs */");
  66. return;
  67. } else if (address >= L1_ROM_START && address < L1_ROM_START + L1_ROM_LENGTH) {
  68. strcat(buf, "/* on-chip L1 ROM */");
  69. return;
  70. } else if (address >= L1_SCRATCH_START && address < L1_SCRATCH_START + L1_SCRATCH_LENGTH) {
  71. strcat(buf, "/* on-chip scratchpad */");
  72. return;
  73. } else if (address >= physical_mem_end && address < ASYNC_BANK0_BASE) {
  74. strcat(buf, "/* unconnected memory */");
  75. return;
  76. } else if (address >= ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE && address < BOOT_ROM_START) {
  77. strcat(buf, "/* reserved memory */");
  78. return;
  79. } else if (address >= L1_DATA_A_START && address < L1_DATA_A_START + L1_DATA_A_LENGTH) {
  80. strcat(buf, "/* on-chip Data Bank A */");
  81. return;
  82. } else if (address >= L1_DATA_B_START && address < L1_DATA_B_START + L1_DATA_B_LENGTH) {
  83. strcat(buf, "/* on-chip Data Bank B */");
  84. return;
  85. }
  86. /*
  87. * Don't walk any of the vmas if we are oopsing, it has been known
  88. * to cause problems - corrupt vmas (kernel crashes) cause double faults
  89. */
  90. if (oops_in_progress) {
  91. strcat(buf, "/* kernel dynamic memory (maybe user-space) */");
  92. return;
  93. }
  94. /* looks like we're off in user-land, so let's walk all the
  95. * mappings of all our processes and see if we can't be a whee
  96. * bit more specific
  97. */
  98. read_lock(&tasklist_lock);
  99. for_each_process(p) {
  100. struct task_struct *t;
  101. t = find_lock_task_mm(p);
  102. if (!t)
  103. continue;
  104. mm = t->mm;
  105. if (!down_read_trylock(&mm->mmap_sem))
  106. goto __continue;
  107. for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
  108. struct vm_area_struct *vma;
  109. vma = rb_entry(n, struct vm_area_struct, vm_rb);
  110. if (address >= vma->vm_start && address < vma->vm_end) {
  111. char _tmpbuf[256];
  112. char *name = t->comm;
  113. struct file *file = vma->vm_file;
  114. if (file) {
  115. char *d_name = file_path(file, _tmpbuf,
  116. sizeof(_tmpbuf));
  117. if (!IS_ERR(d_name))
  118. name = d_name;
  119. }
  120. /* FLAT does not have its text aligned to the start of
  121. * the map while FDPIC ELF does ...
  122. */
  123. /* before we can check flat/fdpic, we need to
  124. * make sure current is valid
  125. */
  126. if ((unsigned long)current >= FIXED_CODE_START &&
  127. !((unsigned long)current & 0x3)) {
  128. if (current->mm &&
  129. (address > current->mm->start_code) &&
  130. (address < current->mm->end_code))
  131. offset = address - current->mm->start_code;
  132. else
  133. offset = (address - vma->vm_start) +
  134. (vma->vm_pgoff << PAGE_SHIFT);
  135. sprintf(buf, "[ %s + 0x%lx ]", name, offset);
  136. } else
  137. sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
  138. name, vma->vm_start, vma->vm_end);
  139. up_read(&mm->mmap_sem);
  140. task_unlock(t);
  141. if (buf[0] == '\0')
  142. sprintf(buf, "[ %s ] dynamic memory", name);
  143. goto done;
  144. }
  145. }
  146. up_read(&mm->mmap_sem);
  147. __continue:
  148. task_unlock(t);
  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. read_unlock(&tasklist_lock);
  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. show_regs_print_info(KERN_NOTICE);
  744. if (CPUID != bfin_cpuid())
  745. pr_notice("Compiled for cpu family 0x%04x (Rev %d), "
  746. "but running on:0x%04x (Rev %d)\n",
  747. CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
  748. pr_notice("ADSP-%s-0.%d",
  749. CPU, bfin_compiled_revid());
  750. if (bfin_compiled_revid() != bfin_revid())
  751. pr_cont("(Detected 0.%d)", bfin_revid());
  752. pr_cont(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
  753. get_cclk()/1000000, get_sclk()/1000000,
  754. #ifdef CONFIG_MPU
  755. "mpu on"
  756. #else
  757. "mpu off"
  758. #endif
  759. );
  760. pr_notice("%s", linux_banner);
  761. pr_notice("\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
  762. pr_notice(" SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
  763. (long)fp->seqstat, fp->ipend, cpu_pda[raw_smp_processor_id()].ex_imask, fp->syscfg);
  764. if (fp->ipend & EVT_IRPTEN)
  765. pr_notice(" Global Interrupts Disabled (IPEND[4])\n");
  766. if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
  767. EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
  768. pr_notice(" Peripheral interrupts masked off\n");
  769. if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
  770. pr_notice(" Kernel interrupts masked off\n");
  771. if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
  772. pr_notice(" HWERRCAUSE: 0x%lx\n",
  773. (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
  774. #ifdef EBIU_ERRMST
  775. /* If the error was from the EBIU, print it out */
  776. if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
  777. pr_notice(" EBIU Error Reason : 0x%04x\n",
  778. bfin_read_EBIU_ERRMST());
  779. pr_notice(" EBIU Error Address : 0x%08x\n",
  780. bfin_read_EBIU_ERRADD());
  781. }
  782. #endif
  783. }
  784. pr_notice(" EXCAUSE : 0x%lx\n",
  785. fp->seqstat & SEQSTAT_EXCAUSE);
  786. for (i = 2; i <= 15 ; i++) {
  787. if (fp->ipend & (1 << i)) {
  788. if (i != 4) {
  789. decode_address(buf, bfin_read32(EVT0 + 4*i));
  790. pr_notice(" physical IVG%i asserted : %s\n", i, buf);
  791. } else
  792. pr_notice(" interrupts disabled\n");
  793. }
  794. }
  795. /* if no interrupts are going off, don't print this out */
  796. if (fp->ipend & ~0x3F) {
  797. for (i = 0; i < (NR_IRQS - 1); i++) {
  798. struct irq_desc *desc = irq_to_desc(i);
  799. if (!in_atomic)
  800. raw_spin_lock_irqsave(&desc->lock, flags);
  801. action = desc->action;
  802. if (!action)
  803. goto unlock;
  804. decode_address(buf, (unsigned int)action->handler);
  805. pr_notice(" logical irq %3d mapped : %s", i, buf);
  806. for (action = action->next; action; action = action->next) {
  807. decode_address(buf, (unsigned int)action->handler);
  808. pr_cont(", %s", buf);
  809. }
  810. pr_cont("\n");
  811. unlock:
  812. if (!in_atomic)
  813. raw_spin_unlock_irqrestore(&desc->lock, flags);
  814. }
  815. }
  816. decode_address(buf, fp->rete);
  817. pr_notice(" RETE: %s\n", buf);
  818. decode_address(buf, fp->retn);
  819. pr_notice(" RETN: %s\n", buf);
  820. decode_address(buf, fp->retx);
  821. pr_notice(" RETX: %s\n", buf);
  822. decode_address(buf, fp->rets);
  823. pr_notice(" RETS: %s\n", buf);
  824. decode_address(buf, fp->pc);
  825. pr_notice(" PC : %s\n", buf);
  826. if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
  827. (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
  828. decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
  829. pr_notice("DCPLB_FAULT_ADDR: %s\n", buf);
  830. decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
  831. pr_notice("ICPLB_FAULT_ADDR: %s\n", buf);
  832. }
  833. pr_notice("PROCESSOR STATE:\n");
  834. pr_notice(" R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  835. fp->r0, fp->r1, fp->r2, fp->r3);
  836. pr_notice(" R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  837. fp->r4, fp->r5, fp->r6, fp->r7);
  838. pr_notice(" P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
  839. fp->p0, fp->p1, fp->p2, fp->p3);
  840. pr_notice(" P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
  841. fp->p4, fp->p5, fp->fp, (long)fp);
  842. pr_notice(" LB0: %08lx LT0: %08lx LC0: %08lx\n",
  843. fp->lb0, fp->lt0, fp->lc0);
  844. pr_notice(" LB1: %08lx LT1: %08lx LC1: %08lx\n",
  845. fp->lb1, fp->lt1, fp->lc1);
  846. pr_notice(" B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
  847. fp->b0, fp->l0, fp->m0, fp->i0);
  848. pr_notice(" B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
  849. fp->b1, fp->l1, fp->m1, fp->i1);
  850. pr_notice(" B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
  851. fp->b2, fp->l2, fp->m2, fp->i2);
  852. pr_notice(" B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
  853. fp->b3, fp->l3, fp->m3, fp->i3);
  854. pr_notice("A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
  855. fp->a0w, fp->a0x, fp->a1w, fp->a1x);
  856. pr_notice("USP : %08lx ASTAT: %08lx\n",
  857. rdusp(), fp->astat);
  858. pr_notice("\n");
  859. }