1 /* $Id: r2300_misc.S,v 1.3 1999/05/01 22:40:36 ralf Exp $
2 * r2300_misc.S: Misc. exception handling code for R3000/R2000.
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 Gleb Raiko & Vladimir Roganov
14 #include <asm/current.h>
15 #include <asm/bootinfo.h>
16 #include <asm/cachectl.h>
17 #include <asm/fpregdef.h>
18 #include <asm/mipsconfig.h>
19 #include <asm/mipsregs.h>
21 #include <asm/pgtable.h>
22 #include <asm/processor.h>
23 #include <asm/regdef.h>
24 #include <asm/segment.h>
25 #include <asm/stackframe.h>
31 #undef NOTLB_OPTIMIZE /* If you are paranoid, define this. */
33 /* ABUSE of CPP macros 101. */
35 /* After this macro runs, the pte faulted on is
36 * in register PTE, a ptr into the table in which
37 * the pte belongs is in PTR.
39 #define LOAD_PTE(pte, ptr) \
40 mfc0 pte, CP0_BADVADDR; \
43 lw ptr, THREAD_PGDIR(ptr); \
46 mfc0 pte, CP0_CONTEXT; \
48 andi pte, pte, 0xffc; \
53 /* This places the even/odd pte pair in the page
54 * table at PTR into ENTRYLO0 and ENTRYLO1 using
55 * TMP as a scratch register.
57 #define PTE_RELOAD(ptr) \
60 mtc0 ptr, CP0_ENTRYLO0; \
63 #define DO_FAULT(write) \
67 mfc0 a2, CP0_BADVADDR; \
73 j ret_from_sys_call; \
78 /* Check is PTE is present, if not then jump to LABEL.
79 * PTR points to the page table where this PTE is located,
80 * when the macro is done executing PTE will be restored
81 * with it's original value.
83 #define PTE_PRESENT(pte, ptr, label) \
84 andi pte, pte, (_PAGE_PRESENT | _PAGE_READ); \
85 xori pte, pte, (_PAGE_PRESENT | _PAGE_READ); \
92 /* Make PTE valid, store result in PTR. */
93 #define PTE_MAKEVALID(pte, ptr) \
94 ori pte, pte, (_PAGE_VALID | _PAGE_ACCESSED); \
97 /* Check if PTE can be written to, if not branch to LABEL.
98 * Regardless restore PTE with value from PTR when done.
100 #define PTE_WRITABLE(pte, ptr, label) \
101 andi pte, pte, (_PAGE_PRESENT | _PAGE_WRITE); \
102 xori pte, pte, (_PAGE_PRESENT | _PAGE_WRITE); \
110 /* Make PTE writable, update software status bits as well,
113 #define PTE_MAKEWRITE(pte, ptr) \
114 ori pte, pte, (_PAGE_ACCESSED | _PAGE_MODIFIED | \
115 _PAGE_VALID | _PAGE_DIRTY); \
121 NESTED(r2300_handle_tlbl, PT_SIZE, sp)
124 #ifndef NOTLB_OPTIMIZE
125 /* Test present bit in entry. */
129 PTE_PRESENT(k0, k1, nopage_tlbl)
130 PTE_MAKEVALID(k0, k1)
142 END(r2300_handle_tlbl)
144 NESTED(r2300_handle_tlbs, PT_SIZE, sp)
147 #ifndef NOTLB_OPTIMIZE
149 tlbp # find faulting entry
151 PTE_WRITABLE(k0, k1, nopage_tlbs)
152 PTE_MAKEWRITE(k0, k1)
164 END(r2300_handle_tlbs)
167 NESTED(r2300_handle_mod, PT_SIZE, sp)
169 #ifndef NOTLB_OPTIMIZE
171 tlbp # find faulting entry
172 andi k0, k0, _PAGE_WRITE
179 /* Present and writable bits set, set accessed and dirty bits. */
180 PTE_MAKEWRITE(k0, k1)
182 /* Now reload the entry into the tlb. */
195 END(r2300_handle_mod)