4xx_trap_subr.S revision 1.7 1 1.7 kiyohara /* $NetBSD: 4xx_trap_subr.S,v 1.7 2011/05/19 07:51:50 kiyohara 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.1 simonb * It should be included in locore.S after powerpc/powerpc/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.1 simonb rfi
59 1.1 simonb ba . /* Protect against prefetch */
60 1.2 simonb
61 1.1 simonb wdoghandler:
62 1.1 simonb rfi
63 1.1 simonb ba . /* Protect against prefetch */
64 1.1 simonb
65 1.6 matt #define TLBSTK 0x1000
66 1.6 matt .lcomm tlbstack,TLBSTK,4
67 1.6 matt .type tlbstack,@object
68 1.1 simonb
69 1.6 matt .text
70 1.2 simonb /* If an unaligned excception (0x600) and DTLB miss exception (0x1100)
71 1.2 simonb occur at the same time, the interrupt vector offsets of the two
72 1.1 simonb exceptions are logically OR'ed together to produce 0x1700.
73 1.1 simonb See PPC405GP Rev D/E Errata item 51 */
74 1.2 simonb
75 1.1 simonb .globl _C_LABEL(errata51handler),_C_LABEL(errata51size)
76 1.1 simonb _C_LABEL(errata51handler):
77 1.1 simonb ba 0x1100
78 1.2 simonb _C_LABEL(errata51size) = .-_C_LABEL(errata51handler)
79 1.1 simonb
80 1.1 simonb .globl _C_LABEL(tlbdmiss4xx),_C_LABEL(tlbdm4size)
81 1.1 simonb _C_LABEL(tlbdmiss4xx):
82 1.6 matt ACCESS_PROLOG(CI_TLBMISSSAVE)
83 1.1 simonb bla s4xx_miss
84 1.2 simonb _C_LABEL(tlbdm4size) = .-_C_LABEL(tlbdmiss4xx)
85 1.1 simonb
86 1.1 simonb .globl _C_LABEL(tlbimiss4xx),_C_LABEL(tlbim4size)
87 1.2 simonb _C_LABEL(tlbimiss4xx):
88 1.6 matt ACCESS_PROLOG(CI_TLBMISSSAVE)
89 1.1 simonb bla s4xx_miss
90 1.3 hannken _C_LABEL(tlbim4size) = .-_C_LABEL(tlbimiss4xx)
91 1.1 simonb
92 1.1 simonb s4xx_miss:
93 1.1 simonb .globl _C_LABEL(pmap_tlbmiss)
94 1.1 simonb
95 1.1 simonb /* If the kernel stack would fault, don't use it. */
96 1.4 eeh mfpid %r30
97 1.4 eeh li %r31,KERNEL_PID
98 1.4 eeh mtpid %r31
99 1.4 eeh li %r31,-FRAMELEN
100 1.4 eeh tlbsx. %r31,%r31,%r1
101 1.4 eeh mtpid %r30
102 1.1 simonb beq 1f
103 1.1 simonb
104 1.2 simonb /*
105 1.6 matt * The kernel stack we want to switch to is not in the TLB.
106 1.1 simonb * To solve this problem, we will simulate a kernel
107 1.1 simonb * fault on the kernel stack and let the miss handler
108 1.1 simonb * bring it in, and return from the trap handler. The
109 1.1 simonb * processor will immediately take the original fault,
110 1.1 simonb * which we should be able to handle with the now-valid
111 1.1 simonb * kernel stack.
112 1.1 simonb */
113 1.1 simonb
114 1.1 simonb /* Switch to tlbstack */
115 1.4 eeh addi %r30,%r1,-FRAMELEN
116 1.6 matt lis %r1,tlbstack+TLBSTK-CALLFRAMELEN@ha
117 1.6 matt addi %r1,%r1,tlbstack+TLBSTK-CALLFRAMELEN@l
118 1.6 matt stw %r30,0(%r1)
119 1.2 simonb
120 1.6 matt FRAME_SETUP(CI_TLBMISSSAVE)
121 1.1 simonb
122 1.1 simonb /* Take an explicit fault at (kernelstack,pid) */
123 1.7 kiyohara lwz %r3,FRAMELEN(%r1)
124 1.4 eeh li %r4,KERNEL_PID
125 1.1 simonb bl _C_LABEL(pmap_tlbmiss)
126 1.2 simonb /*
127 1.1 simonb * We can retry the old fault or switch stacks and
128 1.1 simonb * take it now. It's easier to retry.
129 1.1 simonb */
130 1.4 eeh mr. %r3,%r3
131 1.6 matt beq trapexit
132 1.1 simonb
133 1.1 simonb /* kernel stack not in the pmap? we should panic */
134 1.1 simonb trap
135 1.6 matt b trapagain
136 1.2 simonb 1:
137 1.6 matt FRAME_SETUP(CI_TLBMISSSAVE)
138 1.7 kiyohara li %r3,EXC_DTMISS
139 1.7 kiyohara lwz %r4,FRAME_EXC(%r1)
140 1.7 kiyohara cmpw %r3,%r4
141 1.6 matt lwz %r3,FRAME_DEAR(%r1)
142 1.7 kiyohara beq 2f
143 1.7 kiyohara lwz %r3,FRAME_SRR0(%r1) /* ITMISS case, TLB miss address in SRR0 */
144 1.7 kiyohara 2:
145 1.6 matt lwz %r4,FRAME_PID(%r1)
146 1.1 simonb bl _C_LABEL(pmap_tlbmiss)
147 1.4 eeh mr. %r3,%r3
148 1.6 matt beq trapexit
149 1.1 simonb
150 1.1 simonb /* XXX DEBUG -- make sure we're not on tlbstack */
151 1.6 matt lis %r3,tlbstack@ha
152 1.6 matt addi %r3,%r3,tlbstack@l
153 1.6 matt sub %r7,%r1,%r3
154 1.6 matt twllei %r7,TLBSTK
155 1.2 simonb
156 1.2 simonb /* PTE not found, time to cause a fault */
157 1.6 matt b trapagain
158