1 /* SPDX-License-Identifier: GPL-2.0 */
3 * linux/arch/m32r/mm/mmu.S
5 * Copyright (C) 2001 by Hiroyuki Kondo
8 #include <linux/linkage.h>
9 #include <asm/assembler.h>
15 #include <asm/mmu_context.h>
17 #include <asm/pgtable.h>
21 * TLB Miss Exception handler
25 .global tlb_entry_i_dat
26 .global tlb_entry_d_dat
28 SWITCH_TO_KERNEL_STACK
30 #if defined(CONFIG_ISA_M32R2)
36 seth r3, #high(MMU_REG_BASE)
37 ld r1, @(MESTS_offset, r3) ; r1: status (MESTS reg.)
38 ld r0, @(MDEVP_offset, r3) ; r0: PFN + ASID (MDEVP reg.)
39 st r1, @(MESTS_offset, r3) ; clear status (MESTS reg.)
40 and3 r1, r1, #(MESTS_IT)
41 bnez r1, 1f ; instruction TLB miss?
45 ;; r0: PFN + ASID (MDEVP reg.)
49 ;; r1: TLB entry base address
50 ;; r2: &tlb_entry_{i|d}_dat
54 seth r2, #high(tlb_entry_d_dat)
55 or3 r2, r2, #low(tlb_entry_d_dat)
56 #else /* CONFIG_SMP */
58 seth r2, #high(tlb_entry_d_dat)
59 or3 r2, r2, #low(tlb_entry_d_dat)
61 ld r1, @(16, r1) ; current_thread_info->cpu
64 #endif /* !CONFIG_SMP */
65 seth r1, #high(DTLB_BASE)
66 or3 r1, r1, #low(DTLB_BASE)
72 ;; instrucntion TLB miss
74 ;; r0: MDEVP reg. (included ASID)
78 ;; r1: TLB entry base address
79 ;; r2: &tlb_entry_{i|d}_dat
82 and3 r0, r0, #(MMU_CONTEXT_ASID_MASK)
85 or r0, r1 ; r0: PFN + ASID
87 seth r2, #high(tlb_entry_i_dat)
88 or3 r2, r2, #low(tlb_entry_i_dat)
89 #else /* CONFIG_SMP */
91 seth r2, #high(tlb_entry_i_dat)
92 or3 r2, r2, #low(tlb_entry_i_dat)
94 ld r1, @(16, r1) ; current_thread_info->cpu
97 #endif /* !CONFIG_SMP */
98 seth r1, #high(ITLB_BASE)
99 or3 r1, r1, #low(ITLB_BASE)
106 ;; r1: TLB entry base address
107 ;; r2: &tlb_entry_{i|d}_dat
111 ;; r1: TLB entry address
113 #ifdef CONFIG_ISA_DUAL_ISSUE
114 ld r3, @r2 || srli r1, #3
120 ; tlb_entry_{d|i}_dat++;
122 and3 r3, r3, #(NR_TLB_ENTRIES - 1)
123 #ifdef CONFIG_ISA_DUAL_ISSUE
124 st r3, @r2 || slli r1, #3
133 ;; r1: TLB entry address
137 ;; r1: TLB entry address
140 ; pgd = *(unsigned long *)MPTB;
141 ld24 r2, #(-MPTB - 1)
143 #ifdef CONFIG_ISA_DUAL_ISSUE
144 not r2, r2 || slli r3, #2 ; r3: pgd offset
149 ld r2, @r2 ; r2: pgd base addr (MPTB reg.)
150 or r3, r2 ; r3: pmd addr
152 ; pmd = pmd_offset(pgd, address);
153 ld r3, @r3 ; r3: pmd data
154 beqz r3, 3f ; pmd_none(*pmd) ?
157 add3 r2, r2, #-355 ; _KERNPG_TABLE(=0x163)
158 bnez r2, 3f ; pmd_bad(*pmd) ?
161 ; pte = pte_offset(pmd, address);
162 and r2, r3 ; r2: pte base addr
164 and3 r3, r3, #0xffc ; r3: pte offset
167 or r3, r2 ; r3: pte addr
169 ; pte_data = (unsigned long)pte_val(*pte);
170 ld r2, @r3 ; r2: pte data
171 and3 r3, r2, #2 ; _PAGE_PRESENT(=2) check
179 ;; r1: TLB entry address
182 st r0, @r1 ; set_tlb_tag(entry++, address);
183 st r2, @+r1 ; set_tlb_data(entry, pte_data);
198 ;; r1: TLB entry address
202 ;; r1: TLB entry address
205 #ifdef CONFIG_ISA_DUAL_ISSUE
208 ldi r2, #2 ; r2: pte_data = 0 | _PAGE_PRESENT(=2)
212 #elif defined (CONFIG_ISA_M32R)
221 seth r3, #high(MMU_REG_BASE)
222 ld r0, @(MDEVA_offset,r3) ; r0: address (MDEVA reg.)
223 mvfc r2, bpc ; r2: bpc
224 ld r1, @(MESTS_offset,r3) ; r1: status (MESTS reg.)
225 st r1, @(MESTS_offset,r3) ; clear status (MESTS reg.)
226 and3 r1, r1, #(MESTS_IT)
227 beqz r1, 1f ; data TLB miss?
229 ;; instrucntion TLB miss
230 mv r0, r2 ; address = bpc;
231 ; entry = (unsigned long *)ITLB_BASE+tlb_entry_i*2;
232 seth r3, #shigh(tlb_entry_i_dat)
233 ld r4, @(low(tlb_entry_i_dat),r3)
235 seth r1, #high(ITLB_BASE)
236 or3 r1, r1, #low(ITLB_BASE)
237 add r2, r1 ; r2: entry
238 addi r4, #1 ; tlb_entry_i++;
239 and3 r4, r4, #(NR_TLB_ENTRIES-1)
240 st r4, @(low(tlb_entry_i_dat),r3)
245 ; entry = (unsigned long *)DTLB_BASE+tlb_entry_d*2;
246 seth r3, #shigh(tlb_entry_d_dat)
247 ld r4, @(low(tlb_entry_d_dat),r3)
249 seth r1, #high(DTLB_BASE)
250 or3 r1, r1, #low(DTLB_BASE)
251 add r2, r1 ; r2: entry
252 addi r4, #1 ; tlb_entry_d++;
253 and3 r4, r4, #(NR_TLB_ENTRIES-1)
254 st r4, @(low(tlb_entry_d_dat),r3)
258 ; r0: address, r2: entry
260 ; pgd = *(unsigned long *)MPTB;
267 ; pmd = pmd_offset(pgd, address);
269 beqz r1, 3f ; pmd_none(*pmd) ?
272 ldi r4, #0x163 ; _KERNPG_TABLE(=0x163)
273 bne r1, r4, 3f ; pmd_bad(*pmd) ?
277 ; pte = pte_offset(pmd, address);
286 ; pte_data = (unsigned long)pte_val(*pte);
287 ld r1, @r4 ; r1: pte_data
288 and3 r3, r1, #2 ; _PAGE_PRESENT(=2) check
293 ; r0: address, r1: pte_data, r2: entry
296 ldi r3, #-4096 ; set_tlb_tag(entry++, address);
298 seth r4, #shigh(MASID)
299 ld r4, @(low(MASID),r4) ; r4: MASID
300 and3 r4, r4, #(MMU_CONTEXT_ASID_MASK)
303 st r1, @(4,r2) ; set_tlb_data(entry, pte_data);
315 ldi r1, #2 ; r1: pte_data = 0 | _PAGE_PRESENT(=2)
319 #error unknown isa configuration
324 seth r0, #high(MMU_REG_BASE) ; Set MMU_REG_BASE higher
325 or3 r0, r0, #low(MMU_REG_BASE) ; Set MMU_REG_BASE lower
327 st r1, @(MPSZ_offset,r0) ; Set MPSZ Reg(Page size 4KB:0 16KB:1 64KB:2)
329 st r1, @(MASID_offset,r0) ; Set ASID Zero
332 seth r0, #high(ITLB_BASE) ; Set ITLB_BASE higher
333 or3 r0, r0, #low(ITLB_BASE) ; Set ITLB_BASE lower
334 seth r1, #high(DTLB_BASE) ; Set DTLB_BASE higher
335 or3 r1, r1, #low(DTLB_BASE) ; Set DTLB_BASE lower
337 ldi r3, #NR_TLB_ENTRIES
341 st r2, @+r0 ; VPA <- 0
342 st r2, @+r0 ; PPA <- 0
343 st r2, @+r1 ; VPA <- 0
344 st r2, @+r1 ; PPA <- 0
350 ENTRY(m32r_itlb_entrys)
351 ENTRY(m32r_otlb_entrys)
353 #endif /* CONFIG_MMU */