2 * Dump R4x00 TLB for debugging purposes.
4 * Copyright (C) 1994, 1995 by Waldorf Electronics, written by Ralf Baechle.
5 * Copyright (C) 1999 by Silicon Graphics, Inc.
7 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/string.h>
12 #include <asm/bootinfo.h>
13 #include <asm/cachectl.h>
15 #include <asm/mipsregs.h>
17 #include <asm/pgtable.h>
19 static inline const char *msk2str(unsigned int mask
)
30 #ifndef CONFIG_CPU_VR41XX
48 __asm__ __volatile__( \
49 ".set\tnoreorder\n\t" \
50 "nop;nop;nop;nop;nop;nop;nop\n\t" \
53 void dump_tlb(int first
, int last
)
55 unsigned int pagemask
, c0
, c1
, asid
;
56 unsigned long long entrylo0
, entrylo1
;
57 unsigned long entryhi
;
60 asid
= read_c0_entryhi() & 0xff;
63 for (i
= first
; i
<= last
; i
++) {
68 pagemask
= read_c0_pagemask();
69 entryhi
= read_c0_entryhi();
70 entrylo0
= read_c0_entrylo0();
71 entrylo1
= read_c0_entrylo1();
73 /* Unused entries have a virtual address in KSEG0. */
74 if ((entryhi
& 0xf0000000) != 0x80000000
75 && (entryhi
& 0xff) == asid
) {
77 * Only print entries in use
79 printk("Index: %2d pgmask=%s ", i
, msk2str(pagemask
));
81 c0
= (entrylo0
>> 3) & 7;
82 c1
= (entrylo1
>> 3) & 7;
84 printk("va=%08lx asid=%02lx\n",
85 (entryhi
& 0xffffe000), (entryhi
& 0xff));
86 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
87 (entrylo0
<< 6) & PAGE_MASK
, c0
,
88 (entrylo0
& 4) ? 1 : 0,
89 (entrylo0
& 2) ? 1 : 0, (entrylo0
& 1));
90 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
91 (entrylo1
<< 6) & PAGE_MASK
, c1
,
92 (entrylo1
& 4) ? 1 : 0,
93 (entrylo1
& 2) ? 1 : 0, (entrylo1
& 1));
98 write_c0_entryhi(asid
);
101 void dump_tlb_all(void)
103 dump_tlb(0, current_cpu_data
.tlbsize
- 1);
106 void dump_tlb_wired(void)
110 wired
= read_c0_wired();
111 printk("Wired: %d", wired
);
112 dump_tlb(0, read_c0_wired());
115 void dump_tlb_addr(unsigned long addr
)
117 unsigned int flags
, oldpid
;
120 local_irq_save(flags
);
121 oldpid
= read_c0_entryhi() & 0xff;
123 write_c0_entryhi((addr
& PAGE_MASK
) | oldpid
);
127 index
= read_c0_index();
128 write_c0_entryhi(oldpid
);
129 local_irq_restore(flags
);
132 printk("No entry for address 0x%08lx in TLB\n", addr
);
136 printk("Entry %d maps address 0x%08lx\n", index
, addr
);
137 dump_tlb(index
, index
);
140 void dump_tlb_nonwired(void)
142 dump_tlb(read_c0_wired(), current_cpu_data
.tlbsize
- 1);
145 void dump_list_process(struct task_struct
*t
, void *address
)
147 pgd_t
*page_dir
, *pgd
;
151 unsigned long addr
, val
;
153 addr
= (unsigned long) address
;
155 printk("Addr == %08lx\n", addr
);
156 printk("task == %8p\n", t
);
157 printk("task->mm == %8p\n", t
->mm
);
158 //printk("tasks->mm.pgd == %08x\n", (unsigned int) t->mm->pgd);
161 page_dir
= pgd_offset_k(0);
162 pgd
= pgd_offset_k(addr
);
164 page_dir
= pgd_offset(t
->mm
, 0);
165 pgd
= pgd_offset(t
->mm
, addr
);
167 printk("Current thread has no mm\n");
170 printk("page_dir == %08x\n", (unsigned int) page_dir
);
171 printk("pgd == %08x, ", (unsigned int) pgd
);
172 pud
= pud_offset(pgd
, addr
);
173 printk("pud == %08x, ", (unsigned int) pud
);
175 pmd
= pmd_offset(pud
, addr
);
176 printk("pmd == %08x, ", (unsigned int) pmd
);
178 pte
= pte_offset(pmd
, addr
);
179 printk("pte == %08x, ", (unsigned int) pte
);
182 #ifdef CONFIG_64BIT_PHYS_ADDR
183 printk("page == %08Lx\n", pte_val(page
));
185 printk("page == %08lx\n", pte_val(page
));
189 if (val
& _PAGE_PRESENT
)
191 if (val
& _PAGE_READ
)
193 if (val
& _PAGE_WRITE
)
195 if (val
& _PAGE_ACCESSED
)
197 if (val
& _PAGE_MODIFIED
)
199 if (val
& _PAGE_R4KBUG
)
201 if (val
& _PAGE_GLOBAL
)
203 if (val
& _PAGE_VALID
)
208 void dump_list_current(void *address
)
210 dump_list_process(current
, address
);
213 unsigned int vtop(void *address
)
219 unsigned int addr
, paddr
;
221 addr
= (unsigned long) address
;
222 pgd
= pgd_offset(current
->mm
, addr
);
223 pud
= pud_offset(pgd
, addr
);
224 pmd
= pmd_offset(pud
, addr
);
225 pte
= pte_offset(pmd
, addr
);
226 paddr
= (KSEG1
| (unsigned int) pte_val(*pte
)) & PAGE_MASK
;
227 paddr
|= (addr
& ~PAGE_MASK
);
232 void dump16(unsigned long *p
)
236 for (i
= 0; i
< 8; i
++) {
237 printk("*%08lx == %08lx, ", (unsigned long) p
, *p
);
239 printk("*%08lx == %08lx\n", (unsigned long) p
, *p
);