diff options
Diffstat (limited to 'arch/mips/lib-32/r3k_dump_tlb.c')
-rw-r--r-- | arch/mips/lib-32/r3k_dump_tlb.c | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/arch/mips/lib-32/r3k_dump_tlb.c b/arch/mips/lib-32/r3k_dump_tlb.c new file mode 100644 index 000000000000..a878224004e5 --- /dev/null +++ b/arch/mips/lib-32/r3k_dump_tlb.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Dump R3000 TLB for debugging purposes. | ||
3 | * | ||
4 | * Copyright (C) 1994, 1995 by Waldorf Electronics, written by Ralf Baechle. | ||
5 | * Copyright (C) 1999 by Silicon Graphics, Inc. | ||
6 | * Copyright (C) 1999 by Harald Koerfgen | ||
7 | */ | ||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/mm.h> | ||
10 | #include <linux/sched.h> | ||
11 | #include <linux/string.h> | ||
12 | |||
13 | #include <asm/bootinfo.h> | ||
14 | #include <asm/cachectl.h> | ||
15 | #include <asm/cpu.h> | ||
16 | #include <asm/mipsregs.h> | ||
17 | #include <asm/page.h> | ||
18 | #include <asm/pgtable.h> | ||
19 | |||
20 | extern int r3k_have_wired_reg; /* defined in tlb-r3k.c */ | ||
21 | |||
22 | void dump_tlb(int first, int last) | ||
23 | { | ||
24 | int i; | ||
25 | unsigned int asid; | ||
26 | unsigned long entryhi, entrylo0; | ||
27 | |||
28 | asid = read_c0_entryhi() & 0xfc0; | ||
29 | |||
30 | for (i = first; i <= last; i++) { | ||
31 | write_c0_index(i<<8); | ||
32 | __asm__ __volatile__( | ||
33 | ".set\tnoreorder\n\t" | ||
34 | "tlbr\n\t" | ||
35 | "nop\n\t" | ||
36 | ".set\treorder"); | ||
37 | entryhi = read_c0_entryhi(); | ||
38 | entrylo0 = read_c0_entrylo0(); | ||
39 | |||
40 | /* Unused entries have a virtual address of KSEG0. */ | ||
41 | if ((entryhi & 0xffffe000) != 0x80000000 | ||
42 | && (entryhi & 0xfc0) == asid) { | ||
43 | /* | ||
44 | * Only print entries in use | ||
45 | */ | ||
46 | printk("Index: %2d ", i); | ||
47 | |||
48 | printk("va=%08lx asid=%08lx" | ||
49 | " [pa=%06lx n=%d d=%d v=%d g=%d]", | ||
50 | (entryhi & 0xffffe000), | ||
51 | entryhi & 0xfc0, | ||
52 | entrylo0 & PAGE_MASK, | ||
53 | (entrylo0 & (1 << 11)) ? 1 : 0, | ||
54 | (entrylo0 & (1 << 10)) ? 1 : 0, | ||
55 | (entrylo0 & (1 << 9)) ? 1 : 0, | ||
56 | (entrylo0 & (1 << 8)) ? 1 : 0); | ||
57 | } | ||
58 | } | ||
59 | printk("\n"); | ||
60 | |||
61 | write_c0_entryhi(asid); | ||
62 | } | ||
63 | |||
64 | void dump_tlb_all(void) | ||
65 | { | ||
66 | dump_tlb(0, current_cpu_data.tlbsize - 1); | ||
67 | } | ||
68 | |||
69 | void dump_tlb_wired(void) | ||
70 | { | ||
71 | int wired = r3k_have_wired_reg ? read_c0_wired() : 8; | ||
72 | |||
73 | printk("Wired: %d", wired); | ||
74 | dump_tlb(0, wired - 1); | ||
75 | } | ||
76 | |||
77 | void dump_tlb_addr(unsigned long addr) | ||
78 | { | ||
79 | unsigned long flags, oldpid; | ||
80 | int index; | ||
81 | |||
82 | local_irq_save(flags); | ||
83 | oldpid = read_c0_entryhi() & 0xff; | ||
84 | write_c0_entryhi((addr & PAGE_MASK) | oldpid); | ||
85 | tlb_probe(); | ||
86 | index = read_c0_index(); | ||
87 | write_c0_entryhi(oldpid); | ||
88 | local_irq_restore(flags); | ||
89 | |||
90 | if (index < 0) { | ||
91 | printk("No entry for address 0x%08lx in TLB\n", addr); | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | printk("Entry %d maps address 0x%08lx\n", index, addr); | ||
96 | dump_tlb(index, index); | ||
97 | } | ||
98 | |||
99 | void dump_tlb_nonwired(void) | ||
100 | { | ||
101 | int wired = r3k_have_wired_reg ? read_c0_wired() : 8; | ||
102 | dump_tlb(wired, current_cpu_data.tlbsize - 1); | ||
103 | } | ||
104 | |||
105 | void dump_list_process(struct task_struct *t, void *address) | ||
106 | { | ||
107 | pgd_t *page_dir, *pgd; | ||
108 | pmd_t *pmd; | ||
109 | pte_t *pte, page; | ||
110 | unsigned int addr; | ||
111 | unsigned long val; | ||
112 | |||
113 | addr = (unsigned int) address; | ||
114 | |||
115 | printk("Addr == %08x\n", addr); | ||
116 | printk("tasks->mm.pgd == %08x\n", (unsigned int) t->mm->pgd); | ||
117 | |||
118 | page_dir = pgd_offset(t->mm, 0); | ||
119 | printk("page_dir == %08x\n", (unsigned int) page_dir); | ||
120 | |||
121 | pgd = pgd_offset(t->mm, addr); | ||
122 | printk("pgd == %08x, ", (unsigned int) pgd); | ||
123 | |||
124 | pmd = pmd_offset(pgd, addr); | ||
125 | printk("pmd == %08x, ", (unsigned int) pmd); | ||
126 | |||
127 | pte = pte_offset(pmd, addr); | ||
128 | printk("pte == %08x, ", (unsigned int) pte); | ||
129 | |||
130 | page = *pte; | ||
131 | printk("page == %08x\n", (unsigned int) pte_val(page)); | ||
132 | |||
133 | val = pte_val(page); | ||
134 | if (val & _PAGE_PRESENT) printk("present "); | ||
135 | if (val & _PAGE_READ) printk("read "); | ||
136 | if (val & _PAGE_WRITE) printk("write "); | ||
137 | if (val & _PAGE_ACCESSED) printk("accessed "); | ||
138 | if (val & _PAGE_MODIFIED) printk("modified "); | ||
139 | if (val & _PAGE_GLOBAL) printk("global "); | ||
140 | if (val & _PAGE_VALID) printk("valid "); | ||
141 | printk("\n"); | ||
142 | } | ||
143 | |||
144 | void dump_list_current(void *address) | ||
145 | { | ||
146 | dump_list_process(current, address); | ||
147 | } | ||
148 | |||
149 | unsigned int vtop(void *address) | ||
150 | { | ||
151 | pgd_t *pgd; | ||
152 | pmd_t *pmd; | ||
153 | pte_t *pte; | ||
154 | unsigned int addr, paddr; | ||
155 | |||
156 | addr = (unsigned long) address; | ||
157 | pgd = pgd_offset(current->mm, addr); | ||
158 | pmd = pmd_offset(pgd, addr); | ||
159 | pte = pte_offset(pmd, addr); | ||
160 | paddr = (KSEG1 | (unsigned int) pte_val(*pte)) & PAGE_MASK; | ||
161 | paddr |= (addr & ~PAGE_MASK); | ||
162 | |||
163 | return paddr; | ||
164 | } | ||
165 | |||
166 | void dump16(unsigned long *p) | ||
167 | { | ||
168 | int i; | ||
169 | |||
170 | for (i = 0; i < 8; i++) { | ||
171 | printk("*%08lx == %08lx, ", (unsigned long)p, *p); | ||
172 | p++; | ||
173 | printk("*%08lx == %08lx\n", (unsigned long)p, *p); | ||
174 | p++; | ||
175 | } | ||
176 | } | ||