HelenOS sources
#
#
#
# - Redistributions of source code must retain the above copyright
# - Redistributions in binary form must reproduce the above copyright
# - The name of the author may not be used to endorse or promote products
#
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
#
#include <abi/asmtool.h>
#include <arch/arch.h>
#include <arch/stack.h>
#include <arch/regdef.h>
#include <arch/mm/mmu.h>
.text
.register %g2, #scratch
.register %g3, #scratch
.macro WRITE_ALTERNATE_REGISTER reg, bit
rdpr %pstate, %g1 ! save PSTATE.PEF
wrpr %g0, (\bit | PSTATE_PRIV_BIT), %pstate
mov %o0, \reg
wrpr %g0, PSTATE_PRIV_BIT, %pstate
retl
wrpr %g1, 0, %pstate ! restore PSTATE.PEF
.endm
.macro READ_ALTERNATE_REGISTER reg, bit
rdpr %pstate, %g1 ! save PSTATE.PEF
wrpr %g0, (\bit | PSTATE_PRIV_BIT), %pstate
mov \reg, %o0
wrpr %g0, PSTATE_PRIV_BIT, %pstate
retl
wrpr %g1, 0, %pstate ! restore PSTATE.PEF
.endm
FUNCTION_BEGIN(write_to_ag_g6)
WRITE_ALTERNATE_REGISTER %g6, PSTATE_AG_BIT
FUNCTION_END(write_to_ag_g6)
FUNCTION_BEGIN(write_to_ag_g7)
WRITE_ALTERNATE_REGISTER %g7, PSTATE_AG_BIT
FUNCTION_END(write_to_ag_g7)
FUNCTION_BEGIN(write_to_ig_g6)
WRITE_ALTERNATE_REGISTER %g6, PSTATE_IG_BIT
FUNCTION_END(write_to_ig_g6)
FUNCTION_BEGIN(read_from_ag_g6)
READ_ALTERNATE_REGISTER %g6, PSTATE_AG_BIT
FUNCTION_END(read_from_ag_g6)
FUNCTION_BEGIN(read_from_ag_g7)
READ_ALTERNATE_REGISTER %g7, PSTATE_AG_BIT
FUNCTION_END(read_from_ag_g7)
FUNCTION_BEGIN(switch_to_userspace)
save %o1, 0, %sp
flushw
wrpr %g0, 0, %cleanwin ! avoid information leak
mov %i2, %o0 ! uarg
xor %o1, %o1, %o1 ! %o1 is defined to hold pcb_ptr
! set it to 0
clr %i2
clr %i3
clr %i4
clr %i5
clr %i6
wrpr %g0, 1, %tl ! enforce mapping via nucleus
rdpr %cwp, %g1
wrpr %g1, TSTATE_IE_BIT, %tstate
wrpr %i0, 0, %tnpc
wr %g0, ASI_DMMU, %asi
ldxa [VA_SECONDARY_CONTEXT_REG] %asi, %g1
stxa %g1, [VA_PRIMARY_CONTEXT_REG] %asi
flush %i7
wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(1), %wstate
done ! jump to userspace
FUNCTION_END(switch_to_userspace)
HelenOS homepage, sources at GitHub