2 * TLB exception handling code for R2000/R3000.
4 * Copyright (C) 1994, 1995, 1996 by Ralf Baechle and Andreas Busse
6 * Multi-CPU abstraction reworking:
7 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
9 * Further modifications to make this work:
10 * Copyright (c) 1998 Harald Koerfgen
11 * Copyright (c) 1998, 1999 Gleb Raiko & Vladimir Roganov
12 * Copyright (c) 2001 Ralf Baechle
13 * Copyright (c) 2001 MIPS Technologies, Inc.
15 #include <linux/init.h>
17 #include <asm/cachectl.h>
18 #include <asm/fpregdef.h>
19 #include <asm/mipsregs.h>
21 #include <asm/pgtable-bits.h>
22 #include <asm/regdef.h>
23 #include <asm/stackframe.h>
25 #define TLB_OPTIMIZE /* If you are paranoid, disable this. */
27 /* ABUSE of CPP macros 101. */
29 /* After this macro runs, the pte faulted on is
30 * in register PTE, a ptr into the table in which
31 * the pte belongs is in PTR.
33 #define LOAD_PTE(pte, ptr) \
34 mfc0 pte, CP0_BADVADDR; \
35 lw ptr, pgd_current; \
39 mfc0 pte, CP0_CONTEXT; \
41 andi pte, pte, 0xffc; \
46 /* This places the even/odd pte pair in the page
47 * table at PTR into ENTRYLO0 and ENTRYLO1 using
48 * TMP as a scratch register.
50 #define PTE_RELOAD(ptr) \
53 mtc0 ptr, CP0_ENTRYLO0; \
56 #define DO_FAULT(write) \
60 mfc0 a2, CP0_BADVADDR; \
66 j ret_from_exception; \
71 /* Check is PTE is present, if not then jump to LABEL.
72 * PTR points to the page table where this PTE is located,
73 * when the macro is done executing PTE will be restored
74 * with it's original value.
76 #define PTE_PRESENT(pte, ptr, label) \
77 andi pte, pte, (_PAGE_PRESENT | _PAGE_READ); \
78 xori pte, pte, (_PAGE_PRESENT | _PAGE_READ); \
85 /* Make PTE valid, store result in PTR. */
86 #define PTE_MAKEVALID(pte, ptr) \
87 ori pte, pte, (_PAGE_VALID | _PAGE_ACCESSED); \
90 /* Check if PTE can be written to, if not branch to LABEL.
91 * Regardless restore PTE with value from PTR when done.
93 #define PTE_WRITABLE(pte, ptr, label) \
94 andi pte, pte, (_PAGE_PRESENT | _PAGE_WRITE); \
95 xori pte, pte, (_PAGE_PRESENT | _PAGE_WRITE); \
103 /* Make PTE writable, update software status bits as well,
106 #define PTE_MAKEWRITE(pte, ptr) \
107 ori pte, pte, (_PAGE_ACCESSED | _PAGE_MODIFIED | \
108 _PAGE_VALID | _PAGE_DIRTY); \
112 * The index register may have the probe fail bit set,
113 * because we would trap on access kseg2, i.e. without refill.
115 #define TLB_WRITE(reg) \
116 mfc0 reg, CP0_INDEX; \
135 NESTED(handle_tlbl, PT_SIZE, sp)
139 /* Test present bit in entry. */
142 PTE_PRESENT(k0, k1, nopage_tlbl)
143 PTE_MAKEVALID(k0, k1)
153 NESTED(handle_tlbs, PT_SIZE, sp)
158 tlbp # find faulting entry
159 PTE_WRITABLE(k0, k1, nopage_tlbs)
160 PTE_MAKEWRITE(k0, k1)
171 NESTED(handle_mod, PT_SIZE, sp)
175 tlbp # find faulting entry
176 andi k0, k0, _PAGE_WRITE
183 /* Present and writable bits set, set accessed and dirty bits. */
184 PTE_MAKEWRITE(k0, k1)
186 /* Now reload the entry into the tlb. */