[18baf9c0] | 1 | #
|
---|
| 2 | # Copyright (c) 2005 Jakub Jermar
|
---|
| 3 | # All rights reserved.
|
---|
| 4 | #
|
---|
| 5 | # Redistribution and use in source and binary forms, with or without
|
---|
| 6 | # modification, are permitted provided that the following conditions
|
---|
| 7 | # are met:
|
---|
| 8 | #
|
---|
| 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.
|
---|
| 16 | #
|
---|
| 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.
|
---|
| 27 | #
|
---|
| 28 |
|
---|
[a52e2f4] | 29 | #include <abi/asmtool.h>
|
---|
[18baf9c0] | 30 | #include <arch/arch.h>
|
---|
| 31 | #include <arch/stack.h>
|
---|
| 32 | #include <arch/regdef.h>
|
---|
| 33 | #include <arch/mm/mmu.h>
|
---|
| 34 |
|
---|
| 35 | .text
|
---|
| 36 |
|
---|
| 37 | .register %g2, #scratch
|
---|
| 38 | .register %g3, #scratch
|
---|
| 39 |
|
---|
| 40 | .macro WRITE_ALTERNATE_REGISTER reg, bit
|
---|
| 41 | rdpr %pstate, %g1 ! save PSTATE.PEF
|
---|
| 42 | wrpr %g0, (\bit | PSTATE_PRIV_BIT), %pstate
|
---|
| 43 | mov %o0, \reg
|
---|
| 44 | wrpr %g0, PSTATE_PRIV_BIT, %pstate
|
---|
| 45 | retl
|
---|
| 46 | wrpr %g1, 0, %pstate ! restore PSTATE.PEF
|
---|
| 47 | .endm
|
---|
| 48 |
|
---|
| 49 | .macro READ_ALTERNATE_REGISTER reg, bit
|
---|
| 50 | rdpr %pstate, %g1 ! save PSTATE.PEF
|
---|
| 51 | wrpr %g0, (\bit | PSTATE_PRIV_BIT), %pstate
|
---|
| 52 | mov \reg, %o0
|
---|
| 53 | wrpr %g0, PSTATE_PRIV_BIT, %pstate
|
---|
| 54 | retl
|
---|
| 55 | wrpr %g1, 0, %pstate ! restore PSTATE.PEF
|
---|
| 56 | .endm
|
---|
| 57 |
|
---|
[a52e2f4] | 58 | FUNCTION_BEGIN(write_to_ag_g6)
|
---|
[18baf9c0] | 59 | WRITE_ALTERNATE_REGISTER %g6, PSTATE_AG_BIT
|
---|
[a52e2f4] | 60 | FUNCTION_END(write_to_ag_g6)
|
---|
[18baf9c0] | 61 |
|
---|
[a52e2f4] | 62 | FUNCTION_BEGIN(write_to_ag_g7)
|
---|
[18baf9c0] | 63 | WRITE_ALTERNATE_REGISTER %g7, PSTATE_AG_BIT
|
---|
[a52e2f4] | 64 | FUNCTION_END(write_to_ag_g7)
|
---|
[18baf9c0] | 65 |
|
---|
[a52e2f4] | 66 | FUNCTION_BEGIN(write_to_ig_g6)
|
---|
[18baf9c0] | 67 | WRITE_ALTERNATE_REGISTER %g6, PSTATE_IG_BIT
|
---|
[a52e2f4] | 68 | FUNCTION_END(write_to_ig_g6)
|
---|
[18baf9c0] | 69 |
|
---|
[a52e2f4] | 70 | FUNCTION_BEGIN(read_from_ag_g6)
|
---|
[2ee907e] | 71 | READ_ALTERNATE_REGISTER %g6, PSTATE_AG_BIT
|
---|
[a52e2f4] | 72 | FUNCTION_END(read_from_ag_g6)
|
---|
[2ee907e] | 73 |
|
---|
[a52e2f4] | 74 | FUNCTION_BEGIN(read_from_ag_g7)
|
---|
[18baf9c0] | 75 | READ_ALTERNATE_REGISTER %g7, PSTATE_AG_BIT
|
---|
[a52e2f4] | 76 | FUNCTION_END(read_from_ag_g7)
|
---|
[18baf9c0] | 77 |
|
---|
| 78 | /** Switch to userspace.
|
---|
| 79 | *
|
---|
| 80 | * %o0 Userspace entry address.
|
---|
| 81 | * %o1 Userspace stack pointer address.
|
---|
| 82 | * %o2 Userspace address of uarg structure.
|
---|
| 83 | */
|
---|
[a52e2f4] | 84 | FUNCTION_BEGIN(switch_to_userspace)
|
---|
[3fcea34] | 85 | save %o1, 0, %sp
|
---|
[18baf9c0] | 86 | flushw
|
---|
| 87 | wrpr %g0, 0, %cleanwin ! avoid information leak
|
---|
| 88 |
|
---|
| 89 | mov %i2, %o0 ! uarg
|
---|
| 90 | xor %o1, %o1, %o1 ! %o1 is defined to hold pcb_ptr
|
---|
| 91 | ! set it to 0
|
---|
| 92 |
|
---|
| 93 | clr %i2
|
---|
| 94 | clr %i3
|
---|
| 95 | clr %i4
|
---|
| 96 | clr %i5
|
---|
| 97 | clr %i6
|
---|
| 98 |
|
---|
| 99 | wrpr %g0, 1, %tl ! enforce mapping via nucleus
|
---|
| 100 |
|
---|
| 101 | rdpr %cwp, %g1
|
---|
| 102 | wrpr %g1, TSTATE_IE_BIT, %tstate
|
---|
| 103 | wrpr %i0, 0, %tnpc
|
---|
[a35b458] | 104 |
|
---|
[18baf9c0] | 105 | /*
|
---|
| 106 | * Set primary context according to secondary context.
|
---|
| 107 | * Secondary context has been already installed by
|
---|
| 108 | * higher-level functions.
|
---|
| 109 | */
|
---|
| 110 | wr %g0, ASI_DMMU, %asi
|
---|
| 111 | ldxa [VA_SECONDARY_CONTEXT_REG] %asi, %g1
|
---|
| 112 | stxa %g1, [VA_PRIMARY_CONTEXT_REG] %asi
|
---|
| 113 | flush %i7
|
---|
| 114 |
|
---|
| 115 | /*
|
---|
| 116 | * Spills and fills will be handled by the userspace handlers.
|
---|
| 117 | */
|
---|
| 118 | wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(1), %wstate
|
---|
[a35b458] | 119 |
|
---|
[18baf9c0] | 120 | done ! jump to userspace
|
---|
[a52e2f4] | 121 | FUNCTION_END(switch_to_userspace)
|
---|
[18baf9c0] | 122 |
|
---|