/*1* arch/score/mm/tlbex.S2*3* Score Processor version.4*5* Copyright (C) 2009 Sunplus Core Technology Co., Ltd.6* Lennox Wu <[email protected]>7* Chen Liqin <[email protected]>8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, see the file COPYING, or write21* to the Free Software Foundation, Inc.,22* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA23*/2425#include <asm/asmmacro.h>26#include <asm/pgtable-bits.h>27#include <asm/scoreregs.h>2829/*30* After this macro runs, the pte faulted on is31* in register PTE, a ptr into the table in which32* the pte belongs is in PTR.33*/34.macro load_pte, pte, ptr35la \ptr, pgd_current36lw \ptr, [\ptr, 0]37mfcr \pte, cr638srli \pte, \pte, 2239slli \pte, \pte, 240add \ptr, \ptr, \pte41lw \ptr, [\ptr, 0]42mfcr \pte, cr643srli \pte, \pte, 1044andi \pte, 0xffc45add \ptr, \ptr, \pte46lw \pte, [\ptr, 0]47.endm4849.macro pte_reload, ptr50lw \ptr, [\ptr, 0]51mtcr \ptr, cr1252nop53nop54nop55nop56nop57.endm5859.macro do_fault, write60SAVE_ALL61mfcr r6, cr662mv r4, r063ldi r5, \write64la r8, do_page_fault65brl r866j ret_from_exception67.endm6869.macro pte_writable, pte, ptr, label70andi \pte, 0x28071cmpi.c \pte, 0x28072bne \label73lw \pte, [\ptr, 0] /*reload PTE*/74.endm7576/*77* Make PTE writable, update software status bits as well,78* then store at PTR.79*/80.macro pte_makewrite, pte, ptr81ori \pte, 0x42682sw \pte, [\ptr, 0]83.endm8485.text86ENTRY(score7_FTLB_refill_Handler)87la r31, pgd_current /* get pgd pointer */88lw r31, [r31, 0] /* get the address of PGD */89mfcr r30, cr690srli r30, r30, 22 /* PGDIR_SHIFT = 22*/91slli r30, r30, 292add r31, r31, r3093lw r31, [r31, 0] /* get the address of the start address of PTE table */9495mfcr r30, cr996andi r30, 0xfff /* equivalent to get PET index and right shift 2 bits */97add r31, r31, r3098lw r30, [r31, 0] /* load pte entry */99mtcr r30, cr12100nop101nop102nop103nop104nop105mtrtlb106nop107nop108nop109nop110nop111rte /* 6 cycles to make sure tlb entry works */112113ENTRY(score7_KSEG_refill_Handler)114la r31, pgd_current /* get pgd pointer */115lw r31, [r31, 0] /* get the address of PGD */116mfcr r30, cr6117srli r30, r30, 22 /* PGDIR_SHIFT = 22 */118slli r30, r30, 2119add r31, r31, r30120lw r31, [r31, 0] /* get the address of the start address of PTE table */121122mfcr r30, cr6 /* get Bad VPN */123srli r30, r30, 10124andi r30, 0xffc /* PTE VPN mask (bit 11~2) */125126add r31, r31, r30127lw r30, [r31, 0] /* load pte entry */128mtcr r30, cr12129nop130nop131nop132nop133nop134mtrtlb135nop136nop137nop138nop139nop140rte /* 6 cycles to make sure tlb entry works */141142nopage_tlbl:143do_fault 0 /* Read */144145ENTRY(handle_tlb_refill)146load_pte r30, r31147pte_writable r30, r31, handle_tlb_refill_nopage148pte_makewrite r30, r31 /* Access|Modify|Dirty|Valid */149pte_reload r31150mtrtlb151nop152nop153nop154nop155nop156rte157handle_tlb_refill_nopage:158do_fault 0 /* Read */159160ENTRY(handle_tlb_invaild)161load_pte r30, r31162stlb /* find faulting entry */163pte_writable r30, r31, handle_tlb_invaild_nopage164pte_makewrite r30, r31 /* Access|Modify|Dirty|Valid */165pte_reload r31166mtptlb167nop168nop169nop170nop171nop172rte173handle_tlb_invaild_nopage:174do_fault 0 /* Read */175176ENTRY(handle_mod)177load_pte r30, r31178stlb /* find faulting entry */179andi r30, _PAGE_WRITE /* Writable? */180cmpz.c r30181beq nowrite_mod182lw r30, [r31, 0] /* reload into r30 */183184/* Present and writable bits set, set accessed and dirty bits. */185pte_makewrite r30, r31186187/* Now reload the entry into the tlb. */188pte_reload r31189mtptlb190nop191nop192nop193nop194nop195rte196197nowrite_mod:198do_fault 1 /* Write */199200201