1 | /*
|
---|
2 | * SPDX-FileCopyrightText: 2008 Pavel Rimsky
|
---|
3 | *
|
---|
4 | * SPDX-License-Identifier: BSD-3-Clause
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <abi/asmtool.h>
|
---|
8 | #include <arch/mm/mmu.h>
|
---|
9 | #include <arch/regdef.h>
|
---|
10 | #include <arch/stack.h>
|
---|
11 |
|
---|
12 | .text
|
---|
13 |
|
---|
14 | /** Switch to userspace.
|
---|
15 | *
|
---|
16 | * %o0 Userspace entry address.
|
---|
17 | * %o1 Userspace stack pointer address.
|
---|
18 | * %o2 Userspace address of uarg structure.
|
---|
19 | */
|
---|
20 | FUNCTION_BEGIN(switch_to_userspace)
|
---|
21 | save %o1, -(STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp
|
---|
22 | flushw
|
---|
23 | wrpr %g0, 0, %cleanwin ! avoid information leak
|
---|
24 |
|
---|
25 | mov %i2, %o0 ! uarg
|
---|
26 | xor %o1, %o1, %o1 ! %o1 is defined to hold pcb_ptr
|
---|
27 | ! set it to 0
|
---|
28 | clr %i2
|
---|
29 | clr %i3
|
---|
30 | clr %i4
|
---|
31 | clr %i5
|
---|
32 | clr %i6
|
---|
33 | wrpr %g0, 1, %tl ! enforce mapping via nucleus
|
---|
34 |
|
---|
35 | rdpr %cwp, %g1
|
---|
36 | wrpr %g1, TSTATE_IE_BIT, %tstate
|
---|
37 | wrpr %i0, 0, %tnpc
|
---|
38 |
|
---|
39 | /*
|
---|
40 | * Set primary context according to secondary context.
|
---|
41 | * Secondary context has been already installed by
|
---|
42 | * higher-level functions.
|
---|
43 | */
|
---|
44 | wr %g0, ASI_SECONDARY_CONTEXT_REG, %asi
|
---|
45 | ldxa [VA_SECONDARY_CONTEXT_REG] %asi, %g1
|
---|
46 | wr %g0, ASI_PRIMARY_CONTEXT_REG, %asi
|
---|
47 | stxa %g1, [VA_PRIMARY_CONTEXT_REG] %asi
|
---|
48 | flush %i7
|
---|
49 |
|
---|
50 | /*
|
---|
51 | * Spills and fills will be handled by the userspace handlers.
|
---|
52 | */
|
---|
53 | wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(1), %wstate
|
---|
54 | done ! jump to userspace
|
---|
55 | FUNCTION_END(switch_to_userspace)
|
---|