1 1.10 rin /* $NetBSD: 4xx_trap_subr.S,v 1.10 2022/09/12 08:02:44 rin Exp $ */ 2 1.1 simonb 3 1.1 simonb /* 4 1.1 simonb * Copyright 2001 Wasabi Systems, Inc. 5 1.1 simonb * All rights reserved. 6 1.1 simonb * 7 1.1 simonb * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. 8 1.1 simonb * 9 1.1 simonb * Redistribution and use in source and binary forms, with or without 10 1.1 simonb * modification, are permitted provided that the following conditions 11 1.1 simonb * are met: 12 1.1 simonb * 1. Redistributions of source code must retain the above copyright 13 1.1 simonb * notice, this list of conditions and the following disclaimer. 14 1.1 simonb * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 simonb * notice, this list of conditions and the following disclaimer in the 16 1.1 simonb * documentation and/or other materials provided with the distribution. 17 1.1 simonb * 3. All advertising materials mentioning features or use of this software 18 1.1 simonb * must display the following acknowledgement: 19 1.1 simonb * This product includes software developed for the NetBSD Project by 20 1.1 simonb * Wasabi Systems, Inc. 21 1.1 simonb * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 1.1 simonb * or promote products derived from this software without specific prior 23 1.1 simonb * written permission. 24 1.1 simonb * 25 1.1 simonb * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 1.1 simonb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 1.1 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 1.1 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 1.1 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 1.1 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 1.1 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 1.1 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 1.1 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 1.1 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 1.1 simonb * POSSIBILITY OF SUCH DAMAGE. 36 1.1 simonb */ 37 1.1 simonb 38 1.2 simonb /* This file provides necessary handlers for 405GP CPU 39 1.9 rin * It should be included in locore.S after powerpc/ibm4xx/trap_subr.S 40 1.1 simonb */ 41 1.1 simonb 42 1.1 simonb .text 43 1.1 simonb .globl _C_LABEL(pitfitwdog),_C_LABEL(pitfitwdogsize) 44 1.1 simonb 45 1.1 simonb .align 4 46 1.1 simonb _C_LABEL(pitfitwdog): 47 1.1 simonb sync 48 1.1 simonb ba pitint 49 1.1 simonb .align 4 50 1.1 simonb sync 51 1.1 simonb ba fitint 52 1.1 simonb .align 4 53 1.1 simonb sync 54 1.1 simonb ba wdoghandler 55 1.1 simonb _C_LABEL(pitfitwdogsize) = .-_C_LABEL(pitfitwdog) 56 1.1 simonb 57 1.1 simonb pithandler: 58 1.8 rin IBM405_ERRATA77_SYNC 59 1.1 simonb rfi 60 1.1 simonb ba . /* Protect against prefetch */ 61 1.2 simonb 62 1.1 simonb wdoghandler: 63 1.8 rin IBM405_ERRATA77_SYNC 64 1.1 simonb rfi 65 1.1 simonb ba . /* Protect against prefetch */ 66 1.1 simonb 67 1.6 matt #define TLBSTK 0x1000 68 1.6 matt .lcomm tlbstack,TLBSTK,4 69 1.6 matt .type tlbstack,@object 70 1.1 simonb 71 1.6 matt .text 72 1.2 simonb /* If an unaligned excception (0x600) and DTLB miss exception (0x1100) 73 1.2 simonb occur at the same time, the interrupt vector offsets of the two 74 1.1 simonb exceptions are logically OR'ed together to produce 0x1700. 75 1.1 simonb See PPC405GP Rev D/E Errata item 51 */ 76 1.2 simonb 77 1.1 simonb .globl _C_LABEL(errata51handler),_C_LABEL(errata51size) 78 1.1 simonb _C_LABEL(errata51handler): 79 1.1 simonb ba 0x1100 80 1.2 simonb _C_LABEL(errata51size) = .-_C_LABEL(errata51handler) 81 1.1 simonb 82 1.1 simonb .globl _C_LABEL(tlbdmiss4xx),_C_LABEL(tlbdm4size) 83 1.1 simonb _C_LABEL(tlbdmiss4xx): 84 1.6 matt ACCESS_PROLOG(CI_TLBMISSSAVE) 85 1.1 simonb bla s4xx_miss 86 1.2 simonb _C_LABEL(tlbdm4size) = .-_C_LABEL(tlbdmiss4xx) 87 1.1 simonb 88 1.1 simonb .globl _C_LABEL(tlbimiss4xx),_C_LABEL(tlbim4size) 89 1.2 simonb _C_LABEL(tlbimiss4xx): 90 1.6 matt ACCESS_PROLOG(CI_TLBMISSSAVE) 91 1.1 simonb bla s4xx_miss 92 1.3 hannken _C_LABEL(tlbim4size) = .-_C_LABEL(tlbimiss4xx) 93 1.1 simonb 94 1.1 simonb s4xx_miss: 95 1.1 simonb .globl _C_LABEL(pmap_tlbmiss) 96 1.1 simonb 97 1.1 simonb /* If the kernel stack would fault, don't use it. */ 98 1.10 rin mfspr %r30,SPR_PID 99 1.4 eeh li %r31,KERNEL_PID 100 1.10 rin mtspr SPR_PID,%r31 101 1.4 eeh li %r31,-FRAMELEN 102 1.4 eeh tlbsx. %r31,%r31,%r1 103 1.10 rin mtspr SPR_PID,%r30 104 1.1 simonb beq 1f 105 1.1 simonb 106 1.2 simonb /* 107 1.6 matt * The kernel stack we want to switch to is not in the TLB. 108 1.1 simonb * To solve this problem, we will simulate a kernel 109 1.1 simonb * fault on the kernel stack and let the miss handler 110 1.1 simonb * bring it in, and return from the trap handler. The 111 1.1 simonb * processor will immediately take the original fault, 112 1.1 simonb * which we should be able to handle with the now-valid 113 1.1 simonb * kernel stack. 114 1.1 simonb */ 115 1.1 simonb 116 1.1 simonb /* Switch to tlbstack */ 117 1.4 eeh addi %r30,%r1,-FRAMELEN 118 1.6 matt lis %r1,tlbstack+TLBSTK-CALLFRAMELEN@ha 119 1.6 matt addi %r1,%r1,tlbstack+TLBSTK-CALLFRAMELEN@l 120 1.6 matt stw %r30,0(%r1) 121 1.2 simonb 122 1.6 matt FRAME_SETUP(CI_TLBMISSSAVE) 123 1.1 simonb 124 1.1 simonb /* Take an explicit fault at (kernelstack,pid) */ 125 1.7 kiyohara lwz %r3,FRAMELEN(%r1) 126 1.4 eeh li %r4,KERNEL_PID 127 1.1 simonb bl _C_LABEL(pmap_tlbmiss) 128 1.2 simonb /* 129 1.1 simonb * We can retry the old fault or switch stacks and 130 1.1 simonb * take it now. It's easier to retry. 131 1.1 simonb */ 132 1.4 eeh mr. %r3,%r3 133 1.6 matt beq trapexit 134 1.1 simonb 135 1.1 simonb /* kernel stack not in the pmap? we should panic */ 136 1.1 simonb trap 137 1.6 matt b trapagain 138 1.2 simonb 1: 139 1.6 matt FRAME_SETUP(CI_TLBMISSSAVE) 140 1.7 kiyohara li %r3,EXC_DTMISS 141 1.7 kiyohara lwz %r4,FRAME_EXC(%r1) 142 1.7 kiyohara cmpw %r3,%r4 143 1.6 matt lwz %r3,FRAME_DEAR(%r1) 144 1.7 kiyohara beq 2f 145 1.7 kiyohara lwz %r3,FRAME_SRR0(%r1) /* ITMISS case, TLB miss address in SRR0 */ 146 1.7 kiyohara 2: 147 1.6 matt lwz %r4,FRAME_PID(%r1) 148 1.1 simonb bl _C_LABEL(pmap_tlbmiss) 149 1.4 eeh mr. %r3,%r3 150 1.6 matt beq trapexit 151 1.1 simonb 152 1.1 simonb /* XXX DEBUG -- make sure we're not on tlbstack */ 153 1.6 matt lis %r3,tlbstack@ha 154 1.6 matt addi %r3,%r3,tlbstack@l 155 1.6 matt sub %r7,%r1,%r3 156 1.6 matt twllei %r7,TLBSTK 157 1.2 simonb 158 1.2 simonb /* PTE not found, time to cause a fault */ 159 1.6 matt b trapagain 160