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/config.h>
8 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/string.h>
13 #include <asm/bootinfo.h>
14 #include <asm/cachectl.h>
16 #include <asm/mipsregs.h>
18 #include <asm/pgtable.h>
20 static inline const char *msk2str(unsigned int mask)
31 #ifndef CONFIG_CPU_VR41XX
49 __asm__ __volatile__( \
50 ".set\tnoreorder\n\t" \
51 "nop;nop;nop;nop;nop;nop;nop\n\t" \
54 void dump_tlb(int first, int last)
56 unsigned int pagemask, c0, c1, asid;
57 unsigned long long entrylo0, entrylo1;
58 unsigned long entryhi;
61 asid = read_c0_entryhi() & 0xff;
64 for (i = first; i <= last; i++) {
69 pagemask = read_c0_pagemask();
70 entryhi = read_c0_entryhi();
71 entrylo0 = read_c0_entrylo0();
72 entrylo1 = read_c0_entrylo1();
74 /* Unused entries have a virtual address in KSEG0. */
75 if ((entryhi & 0xf0000000) != 0x80000000
76 && (entryhi & 0xff) == asid) {
78 * Only print entries in use
80 printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
82 c0 = (entrylo0 >> 3) & 7;
83 c1 = (entrylo1 >> 3) & 7;
85 printk("va=%08lx asid=%02lx\n",
86 (entryhi & 0xffffe000), (entryhi & 0xff));
87 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
88 (entrylo0 << 6) & PAGE_MASK, c0,
89 (entrylo0 & 4) ? 1 : 0,
90 (entrylo0 & 2) ? 1 : 0, (entrylo0 & 1));
91 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
92 (entrylo1 << 6) & PAGE_MASK, c1,
93 (entrylo1 & 4) ? 1 : 0,
94 (entrylo1 & 2) ? 1 : 0, (entrylo1 & 1));
99 write_c0_entryhi(asid);
102 void dump_tlb_all(void)
104 dump_tlb(0, current_cpu_data.tlbsize - 1);
107 void dump_tlb_wired(void)
111 wired = read_c0_wired();
112 printk("Wired: %d", wired);
113 dump_tlb(0, read_c0_wired());
116 void dump_tlb_addr(unsigned long addr)
118 unsigned int flags, oldpid;
121 local_irq_save(flags);
122 oldpid = read_c0_entryhi() & 0xff;
124 write_c0_entryhi((addr & PAGE_MASK) | oldpid);
128 index = read_c0_index();
129 write_c0_entryhi(oldpid);
130 local_irq_restore(flags);
133 printk("No entry for address 0x%08lx in TLB\n", addr);
137 printk("Entry %d maps address 0x%08lx\n", index, addr);
138 dump_tlb(index, index);
141 void dump_tlb_nonwired(void)
143 dump_tlb(read_c0_wired(), current_cpu_data.tlbsize - 1);
146 void dump_list_process(struct task_struct *t, void *address)
148 pgd_t *page_dir, *pgd;
152 unsigned long addr, val;
154 addr = (unsigned long) address;
156 printk("Addr == %08lx\n", addr);
157 printk("task == %8p\n", t);
158 printk("task->mm == %8p\n", t->mm);
159 //printk("tasks->mm.pgd == %08x\n", (unsigned int) t->mm->pgd);
162 page_dir = pgd_offset_k(0);
163 pgd = pgd_offset_k(addr);
165 page_dir = pgd_offset(t->mm, 0);
166 pgd = pgd_offset(t->mm, addr);
168 printk("Current thread has no mm\n");
171 printk("page_dir == %08x\n", (unsigned int) page_dir);
172 printk("pgd == %08x, ", (unsigned int) pgd);
173 pud = pud_offset(pgd, addr);
174 printk("pud == %08x, ", (unsigned int) pud);
176 pmd = pmd_offset(pud, addr);
177 printk("pmd == %08x, ", (unsigned int) pmd);
179 pte = pte_offset(pmd, addr);
180 printk("pte == %08x, ", (unsigned int) pte);
183 #ifdef CONFIG_64BIT_PHYS_ADDR
184 printk("page == %08Lx\n", pte_val(page));
186 printk("page == %08lx\n", pte_val(page));
190 if (val & _PAGE_PRESENT)
192 if (val & _PAGE_READ)
194 if (val & _PAGE_WRITE)
196 if (val & _PAGE_ACCESSED)
198 if (val & _PAGE_MODIFIED)
200 if (val & _PAGE_R4KBUG)
202 if (val & _PAGE_GLOBAL)
204 if (val & _PAGE_VALID)
209 void dump_list_current(void *address)
211 dump_list_process(current, address);
214 unsigned int vtop(void *address)
220 unsigned int addr, paddr;
222 addr = (unsigned long) address;
223 pgd = pgd_offset(current->mm, addr);
224 pud = pud_offset(pgd, addr);
225 pmd = pmd_offset(pud, addr);
226 pte = pte_offset(pmd, addr);
227 paddr = (KSEG1 | (unsigned int) pte_val(*pte)) & PAGE_MASK;
228 paddr |= (addr & ~PAGE_MASK);
233 void dump16(unsigned long *p)
237 for (i = 0; i < 8; i++) {
238 printk("*%08lx == %08lx, ", (unsigned long) p, *p);
240 printk("*%08lx == %08lx\n", (unsigned long) p, *p);