1 ; WARNING : The refill handler has been modified, see below !!!
4 * Copyright (C) 2003 Axis Communications AB
6 * Authors: Mikael Starvik (starvik@axis.com)
8 * Code for the fault low-level handling routines.
13 #include <asm/pgtable.h>
15 ; Save all register. Must save in same order as struct pt_regs.
37 ; Bus fault handler. Extracts relevant information and calls mm subsystem
38 ; to handle the fault.
39 .macro MMU_BUS_FAULT_HANDLER handler, mmu, we, ex
43 move \mmu, $srs ; Select MMU support register bank
44 move.d $sp, $r11 ; regs
45 moveq 1, $r12 ; protection fault
46 moveq \we, $r13 ; write exception?
47 orq \ex << 1, $r13 ; execute?
48 move $s3, $r10 ; rw_mm_cause
49 and.d ~8191, $r10 ; Get faulting page start address
57 ; Refill handler. Three cases may occur:
58 ; 1. PMD and PTE exists in mm subsystem but not in TLB
59 ; 2. PMD exists but not PTE
60 ; 3. PMD doesn't exist
61 ; The code below handles case 1 and calls the mm subsystem for case 2 and 3.
62 ; Do not touch this code without very good reasons and extensive testing.
63 ; Note that the code is optimized to minimize stalls (makes the code harder
67 ; Modified by Mikael Asker 060725: added a workaround for strange TLB
68 ; behavior. If the same PTE is present in more than one set, the TLB
69 ; doesn't recognize it and we get stuck in a loop of refill exceptions.
70 ; The workaround detects such loops and exits them by flushing
71 ; the TLB contents. The problem and workaround were verified
72 ; in VCS by Mikael Starvik.
74 ; Each page is 8 KB. Each PMD holds 8192/4 PTEs (each PTE is 4 bytes) so each
75 ; PMD holds 16 MB of virtual memory.
76 ; Bits 0-12 : Offset within a page
77 ; Bits 13-23 : PTE offset within a PMD
78 ; Bits 24-31 : PMD offset within the PGD
80 .macro MMU_REFILL_HANDLER handler, mmu
82 1: .dword 0 ; refill_count
83 ; == 0 <=> last_refill_cause is invalid
84 2: .dword 0 ; last_refill_cause
89 ; (The pipeline stalls for one cycle; $sp used as address in the next cycle.)
92 move \mmu, $srs ; Select MMU support register bank
95 move.d 1b, $acr ; Point to refill_count
98 test.d [$acr] ; refill_count == 0 ?
99 beq 5f ; yes, last_refill_cause is invalid
102 ; last_refill_cause is valid, investigate cause
103 addq 4, $r1 ; Point to last_refill_cause
104 move $s3, $r0 ; Get rw_mm_cause
105 move.d [$r1], $r2 ; Get last_refill_cause
106 cmp.d $r0, $r2 ; rw_mm_cause == last_refill_cause ?
107 beq 6f ; yes, increment count
110 ; rw_mm_cause != last_refill_cause
111 move.d $r2, [$acr] ; refill_count = 1
112 move.d $r0, [$r1] ; last_refill_cause = rw_mm_cause
114 3: ; Probably not in a loop, continue normal processing
118 move.d per_cpu__current_pgd, $acr ; PGD
121 lsrq 24, $r0 ; Get PMD index into PGD (bit 24-31)
122 move.d [$acr], $acr ; PGD for the current process
123 addi $r0.d, $acr, $acr
124 move $s3, $r0 ; rw_mm_cause
125 move.d [$acr], $acr ; Get PMD
129 and.w PAGE_MASK, $acr ; Remove PMD flags
130 and.d 0x7ff, $r0 ; Get PTE index into PMD (bit 13-23)
131 addi $r0.d, $acr, $acr
132 move.d [$acr], $acr ; Get PTE
134 movem [$sp], $r2 ; Restore r0-r2 in delay slot
145 5: ; last_refill_cause is invalid
147 addq 4, $r1 ; Point to last_refill_cause
148 move.d $r2, [$acr] ; refill_count = 1
149 move $s3, $r0 ; Get rw_mm_cause
150 ba 3b ; Continue normal processing
151 move.d $r0,[$r1] ; last_refill_cause = rw_mm_cause
153 6: ; rw_mm_cause == last_refill_cause
154 move.d [$acr], $r2 ; Get refill_count
155 cmpq 4, $r2 ; refill_count > 4 ?
157 addq 1, $r2 ; refill_count++
158 ba 3b ; Continue normal processing
161 7: ; refill_count > 4, error
162 move.d $acr, $r0 ; Save pointer to refill_count
163 clear.d [$r0] ; refill_count = 0
165 ;; rewind the short stack
166 movem [$sp], $r2 ; Restore r0-r2
171 ;; Keep it simple (slow), save all the regs.
175 ba ret_from_intr ; Return
178 8: ; PMD missing, let the mm subsystem fix it up.
179 movem [$sp], $r2 ; Restore r0-r2
180 9: ; PTE missing, let the mm subsystem fix it up.
187 move.d $sp, $r11 ; regs
188 clear.d $r12 ; Not a protection fault
189 move.w PAGE_MASK, $acr
190 move $s3, $r10 ; rw_mm_cause
191 btstq 9, $r10 ; Check if write access
193 and.w PAGE_MASK, $r10 ; Get VPN (virtual address)
201 ; This is the MMU bus fault handlers.
203 MMU_REFILL_HANDLER i_mmu_refill, 1
204 MMU_BUS_FAULT_HANDLER i_mmu_invalid, 1, 0, 0
205 MMU_BUS_FAULT_HANDLER i_mmu_access, 1, 0, 0
206 MMU_BUS_FAULT_HANDLER i_mmu_execute, 1, 0, 1
207 MMU_REFILL_HANDLER d_mmu_refill, 2
208 MMU_BUS_FAULT_HANDLER d_mmu_invalid, 2, 0, 0
209 MMU_BUS_FAULT_HANDLER d_mmu_access, 2, 0, 0
210 MMU_BUS_FAULT_HANDLER d_mmu_write, 2, 1, 0