dbg.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*--------------------------------------------------------------------------
  2. --
  3. -- Identity : Linux50 Debug Funcions
  4. --
  5. -- File : arch/sh/lib64/dbg.c
  6. --
  7. -- Copyright 2000, 2001 STMicroelectronics Limited.
  8. -- Copyright 2004 Richard Curnow (evt_debug etc)
  9. --
  10. --------------------------------------------------------------------------*/
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm.h>
  15. #include <linux/fs.h>
  16. #include <asm/mmu_context.h>
  17. typedef u64 regType_t;
  18. static regType_t getConfigReg(u64 id)
  19. {
  20. register u64 reg __asm__("r2");
  21. asm volatile ("getcfg %1, 0, %0":"=r" (reg):"r"(id));
  22. return (reg);
  23. }
  24. /* ======================================================================= */
  25. static char *szTab[] = { "4k", "64k", "1M", "512M" };
  26. static char *protTab[] = { "----",
  27. "---R",
  28. "--X-",
  29. "--XR",
  30. "-W--",
  31. "-W-R",
  32. "-WX-",
  33. "-WXR",
  34. "U---",
  35. "U--R",
  36. "U-X-",
  37. "U-XR",
  38. "UW--",
  39. "UW-R",
  40. "UWX-",
  41. "UWXR"
  42. };
  43. #define ITLB_BASE 0x00000000
  44. #define DTLB_BASE 0x00800000
  45. #define MAX_TLBs 64
  46. /* PTE High */
  47. #define GET_VALID(pte) ((pte) & 0x1)
  48. #define GET_SHARED(pte) ((pte) & 0x2)
  49. #define GET_ASID(pte) ((pte >> 2) & 0x0ff)
  50. #define GET_EPN(pte) ((pte) & 0xfffff000)
  51. /* PTE Low */
  52. #define GET_CBEHAVIOR(pte) ((pte) & 0x3)
  53. #define GET_PAGE_SIZE(pte) szTab[((pte >> 3) & 0x3)]
  54. #define GET_PROTECTION(pte) protTab[((pte >> 6) & 0xf)]
  55. #define GET_PPN(pte) ((pte) & 0xfffff000)
  56. #define PAGE_1K_MASK 0x00000000
  57. #define PAGE_4K_MASK 0x00000010
  58. #define PAGE_64K_MASK 0x00000080
  59. #define MMU_PAGESIZE_MASK (PAGE_64K_MASK | PAGE_4K_MASK)
  60. #define PAGE_1MB_MASK MMU_PAGESIZE_MASK
  61. #define PAGE_1K (1024)
  62. #define PAGE_4K (1024 * 4)
  63. #define PAGE_64K (1024 * 64)
  64. #define PAGE_1MB (1024 * 1024)
  65. #define HOW_TO_READ_TLB_CONTENT \
  66. "[ ID] PPN EPN ASID Share CB P.Size PROT.\n"
  67. void print_single_tlb(unsigned long tlb, int single_print)
  68. {
  69. regType_t pteH;
  70. regType_t pteL;
  71. unsigned int valid, shared, asid, epn, cb, ppn;
  72. char *pSize;
  73. char *pProt;
  74. /*
  75. ** in case of single print <single_print> is true, this implies:
  76. ** 1) print the TLB in any case also if NOT VALID
  77. ** 2) print out the header
  78. */
  79. pteH = getConfigReg(tlb);
  80. valid = GET_VALID(pteH);
  81. if (single_print)
  82. printk(HOW_TO_READ_TLB_CONTENT);
  83. else if (!valid)
  84. return;
  85. pteL = getConfigReg(tlb + 1);
  86. shared = GET_SHARED(pteH);
  87. asid = GET_ASID(pteH);
  88. epn = GET_EPN(pteH);
  89. cb = GET_CBEHAVIOR(pteL);
  90. pSize = GET_PAGE_SIZE(pteL);
  91. pProt = GET_PROTECTION(pteL);
  92. ppn = GET_PPN(pteL);
  93. printk("[%c%2ld] 0x%08x 0x%08x %03d %02x %02x %4s %s\n",
  94. ((valid) ? ' ' : 'u'), ((tlb & 0x0ffff) / TLB_STEP),
  95. ppn, epn, asid, shared, cb, pSize, pProt);
  96. }
  97. void print_dtlb(void)
  98. {
  99. int count;
  100. unsigned long tlb;
  101. printk(" ================= SH-5 D-TLBs Status ===================\n");
  102. printk(HOW_TO_READ_TLB_CONTENT);
  103. tlb = DTLB_BASE;
  104. for (count = 0; count < MAX_TLBs; count++, tlb += TLB_STEP)
  105. print_single_tlb(tlb, 0);
  106. printk
  107. (" =============================================================\n");
  108. }
  109. void print_itlb(void)
  110. {
  111. int count;
  112. unsigned long tlb;
  113. printk(" ================= SH-5 I-TLBs Status ===================\n");
  114. printk(HOW_TO_READ_TLB_CONTENT);
  115. tlb = ITLB_BASE;
  116. for (count = 0; count < MAX_TLBs; count++, tlb += TLB_STEP)
  117. print_single_tlb(tlb, 0);
  118. printk
  119. (" =============================================================\n");
  120. }
  121. void show_excp_regs(char *from, int trapnr, int signr, struct pt_regs *regs)
  122. {
  123. unsigned long long ah, al, bh, bl, ch, cl;
  124. printk("\n");
  125. printk("EXCEPTION - %s: task %d; Linux trap # %d; signal = %d\n",
  126. ((from) ? from : "???"), current->pid, trapnr, signr);
  127. asm volatile ("getcon " __EXPEVT ", %0":"=r"(ah));
  128. asm volatile ("getcon " __EXPEVT ", %0":"=r"(al));
  129. ah = (ah) >> 32;
  130. al = (al) & 0xffffffff;
  131. asm volatile ("getcon " __KCR1 ", %0":"=r"(bh));
  132. asm volatile ("getcon " __KCR1 ", %0":"=r"(bl));
  133. bh = (bh) >> 32;
  134. bl = (bl) & 0xffffffff;
  135. asm volatile ("getcon " __INTEVT ", %0":"=r"(ch));
  136. asm volatile ("getcon " __INTEVT ", %0":"=r"(cl));
  137. ch = (ch) >> 32;
  138. cl = (cl) & 0xffffffff;
  139. printk("EXPE: %08Lx%08Lx KCR1: %08Lx%08Lx INTE: %08Lx%08Lx\n",
  140. ah, al, bh, bl, ch, cl);
  141. asm volatile ("getcon " __PEXPEVT ", %0":"=r"(ah));
  142. asm volatile ("getcon " __PEXPEVT ", %0":"=r"(al));
  143. ah = (ah) >> 32;
  144. al = (al) & 0xffffffff;
  145. asm volatile ("getcon " __PSPC ", %0":"=r"(bh));
  146. asm volatile ("getcon " __PSPC ", %0":"=r"(bl));
  147. bh = (bh) >> 32;
  148. bl = (bl) & 0xffffffff;
  149. asm volatile ("getcon " __PSSR ", %0":"=r"(ch));
  150. asm volatile ("getcon " __PSSR ", %0":"=r"(cl));
  151. ch = (ch) >> 32;
  152. cl = (cl) & 0xffffffff;
  153. printk("PEXP: %08Lx%08Lx PSPC: %08Lx%08Lx PSSR: %08Lx%08Lx\n",
  154. ah, al, bh, bl, ch, cl);
  155. ah = (regs->pc) >> 32;
  156. al = (regs->pc) & 0xffffffff;
  157. bh = (regs->regs[18]) >> 32;
  158. bl = (regs->regs[18]) & 0xffffffff;
  159. ch = (regs->regs[15]) >> 32;
  160. cl = (regs->regs[15]) & 0xffffffff;
  161. printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n",
  162. ah, al, bh, bl, ch, cl);
  163. ah = (regs->sr) >> 32;
  164. al = (regs->sr) & 0xffffffff;
  165. asm volatile ("getcon " __TEA ", %0":"=r"(bh));
  166. asm volatile ("getcon " __TEA ", %0":"=r"(bl));
  167. bh = (bh) >> 32;
  168. bl = (bl) & 0xffffffff;
  169. asm volatile ("getcon " __KCR0 ", %0":"=r"(ch));
  170. asm volatile ("getcon " __KCR0 ", %0":"=r"(cl));
  171. ch = (ch) >> 32;
  172. cl = (cl) & 0xffffffff;
  173. printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
  174. ah, al, bh, bl, ch, cl);
  175. ah = (regs->regs[0]) >> 32;
  176. al = (regs->regs[0]) & 0xffffffff;
  177. bh = (regs->regs[1]) >> 32;
  178. bl = (regs->regs[1]) & 0xffffffff;
  179. ch = (regs->regs[2]) >> 32;
  180. cl = (regs->regs[2]) & 0xffffffff;
  181. printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n",
  182. ah, al, bh, bl, ch, cl);
  183. ah = (regs->regs[3]) >> 32;
  184. al = (regs->regs[3]) & 0xffffffff;
  185. bh = (regs->regs[4]) >> 32;
  186. bl = (regs->regs[4]) & 0xffffffff;
  187. ch = (regs->regs[5]) >> 32;
  188. cl = (regs->regs[5]) & 0xffffffff;
  189. printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n",
  190. ah, al, bh, bl, ch, cl);
  191. ah = (regs->regs[6]) >> 32;
  192. al = (regs->regs[6]) & 0xffffffff;
  193. bh = (regs->regs[7]) >> 32;
  194. bl = (regs->regs[7]) & 0xffffffff;
  195. ch = (regs->regs[8]) >> 32;
  196. cl = (regs->regs[8]) & 0xffffffff;
  197. printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n",
  198. ah, al, bh, bl, ch, cl);
  199. ah = (regs->regs[9]) >> 32;
  200. al = (regs->regs[9]) & 0xffffffff;
  201. bh = (regs->regs[10]) >> 32;
  202. bl = (regs->regs[10]) & 0xffffffff;
  203. ch = (regs->regs[11]) >> 32;
  204. cl = (regs->regs[11]) & 0xffffffff;
  205. printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
  206. ah, al, bh, bl, ch, cl);
  207. printk("....\n");
  208. ah = (regs->tregs[0]) >> 32;
  209. al = (regs->tregs[0]) & 0xffffffff;
  210. bh = (regs->tregs[1]) >> 32;
  211. bl = (regs->tregs[1]) & 0xffffffff;
  212. ch = (regs->tregs[2]) >> 32;
  213. cl = (regs->tregs[2]) & 0xffffffff;
  214. printk("T0 : %08Lx%08Lx T1 : %08Lx%08Lx T2 : %08Lx%08Lx\n",
  215. ah, al, bh, bl, ch, cl);
  216. printk("....\n");
  217. print_dtlb();
  218. print_itlb();
  219. }