4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <sys/types.h>
31 #include <sys/thread.h>
37 #include <sys/machasi.h>
38 #include <sys/asm_linkage.h>
39 #include <zuluvm_offsets.h>
40 #include <sys/zulu_hat.h>
41 #include <sys/zuluvm.h>
44 * function to look up ttes in zulu_hat TSB.
46 * zulu_hat_tsb_lookup_tl1 is called from the zuluvm dmv interrupt handler
47 * so we can only use the global registers.
49 * zulu_hat_tsb_lookup_tl0 is called from TL=0
55 zulu_hat_tsb_lookup_tl1
(caddr_t vaddr
)
62 zulu_hat_tsb_lookup_tl0
(struct zulu_hat
*zhat
, caddr_t vaddr
)
71 * %g3 - return address
72 * Must preserve %g7 for caller
76 * %g2 - zuluvm error code if %g1 is null
78 ENTRY_NP
(zulu_hat_tsb_lookup_tl1
)
79 set ZULU_CTX_MASK
, %g4
82 ! we
're at trap level 1, (TL=1)
83 ! if the context is already locked by another
84 ! thread, punt to the TL=0 code
85 ! it's
not safe to spinloop now.
90 mov
%g5
, %g2
! remember ctx
* 8
96 bne,a,pn
%icc
, ctx_busy
97 mov ZULUVM_CTX_LOCKED
, %g2
99 ! now do
a compare
and swap
and make sure it
's still not locked
101 casxa [%g6]ASI_N, %g4, %g5
103 bne,a,pn %icc, ctx_busy
104 mov ZULUVM_CTX_LOCKED, %g2
106 brz,a,pn %g4, zulu_hat_tsb_exit
109 ! we have the lock now proceed
111 ! set lsb of g3 to indicate that we need to unlock the context
113 ba,pt %xcc, zulu_hat_tsb_lookup
123 * zulu_hat_tsb_lookup_tl0 jumps here
126 * %g3 return address | unlock flag (bit zero)
127 * %g4 has the zulu hat ptr (locked)
133 add %g1, ZULU_HAT_TSB_SZ, %g5
134 lduh [%g5], %g5 ! tsb size
137 srlx %g2, 22, %g4 ! 4m page hash
138 and %g5, %g4, %g4 ! hash index
140 add %g1, ZULU_HAT_TSB, %g5
142 add %g5, %g4, %g4 ! ptr to struct zulu_tte
143 ldx [%g4], %g5 ! get the tag
145 set (0x1ff << 13), %g6
149 bne,pn %xcc, zulu_hat_tsb_try_512k
152 ldx [%g4 + 8], %g4 ! flags and pfn
153 brgez,pn %g4, zulu_hat_tsb_try_512k ! check if entry is valid
157 srlx %g5, 61, %g5 ! tte size
159 be,pn %xcc, zulu_hat_tsb_found
162 zulu_hat_tsb_try_512k:
163 add %g1, ZULU_HAT_TSB_SZ, %g5
164 lduh [%g5], %g5 ! tsb size
167 srlx %g2, 19, %g4 ! 4m page hash
168 and %g5, %g4, %g4 ! hash index
170 add %g1, ZULU_HAT_TSB, %g5
172 add %g5, %g4, %g4 ! ptr to struct zulu_tte
173 ldx [%g4], %g5 ! get the tag
175 set (0x3f << 13), %g6
179 bne,pn %xcc, zulu_hat_tsb_try_64k
182 ldx [%g4 + 8], %g4 ! flags and pfn
183 brgez,pn %g4, zulu_hat_tsb_try_64k ! check if entry is valid
187 srlx %g5, 61, %g5 ! tte size
188 cmp %g5, ZULU_TTE512K
189 be,pn %xcc, zulu_hat_tsb_found
192 zulu_hat_tsb_try_64k:
193 add %g1, ZULU_HAT_TSB_SZ, %g5
194 lduh [%g5], %g5 ! tsb size
197 srlx %g2, 16, %g4 ! 4m page hash
198 and %g5, %g4, %g4 ! hash index
200 add %g1, ZULU_HAT_TSB, %g5
202 add %g5, %g4, %g4 ! ptr to struct zulu_tte
203 ldx [%g4], %g5 ! get the tag
209 bne,pn %xcc, zulu_hat_tsb_try_8k
212 ldx [%g4 + 8], %g4 ! flags and pfn
213 brgez,pn %g4, zulu_hat_tsb_try_8k ! check if entry is valid
217 srlx %g5, 61, %g5 ! tte size
219 be,pn %xcc, zulu_hat_tsb_found
223 add %g1, ZULU_HAT_TSB_SZ, %g5
224 lduh [%g5], %g5 ! tsb size
227 srlx %g2, 13, %g4 ! calc hash
228 and %g5, %g4, %g4 ! hash index
230 add %g1, ZULU_HAT_TSB, %g5
231 ldx [%g5], %g5 ! tsb ptr
232 add %g5, %g4, %g4 ! ptr to struct tte
233 ldx [%g4], %g5 ! get the tag
235 bne,pn %xcc, zulu_hat_tsb_exit
238 ldx [%g4 + 8], %g4 ! flags and pfn
239 brgez,pn %g4, zulu_hat_tsb_exit ! check if entry is valid
243 srlx %g5, 61, %g5 ! tte size
244 brnz,pn %g5, zulu_hat_tsb_exit
248 ! expect the tte size in %g5
259 ! now fall through to exit
262 ! if bit zero of %g3 is set, we're at TL
=1 and need to unlock
265 be,pn
%xcc
, after_unlock
268 ! clear the context unlock flag
271 set ZULU_CTX_MASK
, %g6
272 and %g2
, %g6
, %g6
! ctx num
275 set zulu_ctx_tab
, %g5
276 add %g6
, %g5
, %g5
! %g5
= &zulu_ctx_tab
[ctx_num
]
283 ! set the status code to ZULUVM_NO_TTE in case we are running at TL
=1
284 ! and no tte was found.
286 ! note
: caller doesn
't examine %g2 unless flags and pfn are null
288 mov ZULUVM_NO_TTE, %g2
293 SET_SIZE(zulu_hat_tsb_lookup_tl1)
296 * %o0 - zulu hat ptr (already locked)
299 ENTRY_NP(zulu_hat_tsb_lookup_tl0)
302 set zulu_hat_tsb_lookup, %g3
304 ! note bit zero of g3 is zero which tells zulu_hat_tsb_lookup
305 ! to not unlock tsb before returning
312 SET_SIZE(zulu_hat_tsb_lookup_tl0)