2
# Copyright (c) 2005 Jakub Jermar
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
9
# - Redistributions of source code must retain the above copyright
10
# notice, this list of conditions and the following disclaimer.
11
# - Redistributions in binary form must reproduce the above copyright
12
# notice, this list of conditions and the following disclaimer in the
13
# documentation and/or other materials provided with the distribution.
14
# - The name of the author may not be used to endorse or promote products
15
# derived from this software without specific prior written permission.
17
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
#include <arch/arch.h>
30
#include <arch/stack.h>
31
#include <arch/regdef.h>
32
#include <arch/mm/mmu.h>
36
.register %g2, #scratch
37
.register %g3, #scratch
40
* This is the assembly language version of our _memcpy() generated by gcc.
44
mov %o0, %o3 ! save dst
62
jmp %o7 + 8 ! exit point
96
jmp %o7 + 8 ! exit point
100
* Almost the same as memcpy() except the loads are from userspace.
102
.global memcpy_from_uspace
104
mov %o0, %o3 ! save dst
115
lduba [%g3 + %o1] ASI_AIUS, %g1
122
jmp %o7 + 8 ! exit point
135
ldxa [%o1 + %g2] ASI_AIUS, %g1
149
lduba [%g2 + %g4] ASI_AIUS, %g1
156
jmp %o7 + 8 ! exit point
160
* Almost the same as memcpy() except the stores are to userspace.
162
.global memcpy_to_uspace
164
mov %o0, %o3 ! save dst
175
ldub [%g3 + %o1], %g1
178
stba %g1, [%g3 + %o0] ASI_AIUS
182
jmp %o7 + 8 ! exit point
199
stxa %g1, [%o0 + %g2] ASI_AIUS
209
ldub [%g2 + %g4], %g1
210
stba %g1, [%g2 + %o0] ASI_AIUS
216
jmp %o7 + 8 ! exit point
219
.global memcpy_from_uspace_failover_address
220
.global memcpy_to_uspace_failover_address
221
memcpy_from_uspace_failover_address:
222
memcpy_to_uspace_failover_address:
223
jmp %o7 + 8 ! exit point
224
mov %g0, %o0 ! return 0 on failure
237
.macro WRITE_ALTERNATE_REGISTER reg, bit
238
rdpr %pstate, %g1 ! save PSTATE.PEF
239
wrpr %g0, (\bit | PSTATE_PRIV_BIT), %pstate
241
wrpr %g0, PSTATE_PRIV_BIT, %pstate
243
wrpr %g1, 0, %pstate ! restore PSTATE.PEF
246
.macro READ_ALTERNATE_REGISTER reg, bit
247
rdpr %pstate, %g1 ! save PSTATE.PEF
248
wrpr %g0, (\bit | PSTATE_PRIV_BIT), %pstate
250
wrpr %g0, PSTATE_PRIV_BIT, %pstate
252
wrpr %g1, 0, %pstate ! restore PSTATE.PEF
255
.global write_to_ag_g6
257
WRITE_ALTERNATE_REGISTER %g6, PSTATE_AG_BIT
259
.global write_to_ag_g7
261
WRITE_ALTERNATE_REGISTER %g7, PSTATE_AG_BIT
263
.global write_to_ig_g6
265
WRITE_ALTERNATE_REGISTER %g6, PSTATE_IG_BIT
267
.global read_from_ag_g7
269
READ_ALTERNATE_REGISTER %g7, PSTATE_AG_BIT
272
/** Switch to userspace.
274
* %o0 Userspace entry address.
275
* %o1 Userspace stack pointer address.
276
* %o2 Userspace address of uarg structure.
278
.global switch_to_userspace
280
save %o1, -(STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp
282
wrpr %g0, 0, %cleanwin ! avoid information leak
285
xor %o1, %o1, %o1 ! %o1 is defined to hold pcb_ptr
294
wrpr %g0, 1, %tl ! enforce mapping via nucleus
297
wrpr %g1, TSTATE_IE_BIT, %tstate
301
* Set primary context according to secondary context.
302
* Secondary context has been already installed by
303
* higher-level functions.
305
wr %g0, ASI_DMMU, %asi
306
ldxa [VA_SECONDARY_CONTEXT_REG] %asi, %g1
307
stxa %g1, [VA_PRIMARY_CONTEXT_REG] %asi
311
* Spills and fills will be handled by the userspace handlers.
313
wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(1), %wstate
315
done ! jump to userspace