[54171e8] | 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 | */
|
---|
[9db5b66] | 28 |
|
---|
[27f67f5] | 29 | #include <abi/asmtool.h>
|
---|
[b994a60] | 30 | #include <arch/register.h>
|
---|
| 31 |
|
---|
[9db5b66] | 32 | .text
|
---|
| 33 |
|
---|
[e3c762cd] | 34 | /** Copy memory from/to userspace.
|
---|
[ffdfcf0] | 35 | *
|
---|
| 36 | * This memcpy() has been taken from the assembler output of
|
---|
[cb4f078] | 37 | * a plain C implementation of memcpy() modified to have the
|
---|
| 38 | * failover part.
|
---|
[e3c762cd] | 39 | *
|
---|
| 40 | * @param in0 Destination address.
|
---|
| 41 | * @param in1 Source address.
|
---|
| 42 | * @param in2 Number of byte to copy.
|
---|
[54171e8] | 43 | *
|
---|
[e3c762cd] | 44 | */
|
---|
[27f67f5] | 45 | FUNCTION_BEGIN(memcpy_from_uspace)
|
---|
| 46 | FUNCTION_BEGIN(memcpy_to_uspace)
|
---|
[ffdfcf0] | 47 | alloc loc0 = ar.pfs, 3, 1, 0, 0
|
---|
[a35b458] | 48 |
|
---|
[e269c53] | 49 | adds r14 = 7, in1
|
---|
| 50 | mov r2 = ar.lc
|
---|
[c640876] | 51 | mov r8 = in0 ;;
|
---|
[e269c53] | 52 | and r14 = -8, r14 ;;
|
---|
| 53 | cmp.ne p6, p7 = r14, in1
|
---|
[54171e8] | 54 | (p7) br.cond.dpnt 3f ;;
|
---|
[a35b458] | 55 |
|
---|
[54171e8] | 56 | 0:
|
---|
[a35b458] | 57 |
|
---|
[54171e8] | 58 | cmp.ne p6, p7 = 0, in2
|
---|
| 59 | (p7) br.cond.dpnt 2f ;;
|
---|
| 60 | (p6) adds r14 = -1, in2
|
---|
| 61 | (p6) mov r16 = r0
|
---|
| 62 | (p6) mov r17 = r0 ;;
|
---|
| 63 | (p6) mov ar.lc = r14
|
---|
[a35b458] | 64 |
|
---|
[54171e8] | 65 | 1:
|
---|
[a35b458] | 66 |
|
---|
[1b20da0] | 67 | add r14 = r16, in1
|
---|
[54171e8] | 68 | add r15 = r16, in0
|
---|
| 69 | adds r17 = 1, r17 ;;
|
---|
| 70 | ld1 r14 = [r14]
|
---|
| 71 | mov r16 = r17 ;;
|
---|
| 72 | st1 [r15] = r14
|
---|
| 73 | br.cloop.sptk.few 1b ;;
|
---|
[a35b458] | 74 |
|
---|
[54171e8] | 75 | 2:
|
---|
[a35b458] | 76 |
|
---|
[54171e8] | 77 | mov ar.lc = r2
|
---|
| 78 | mov ar.pfs = loc0
|
---|
| 79 | br.ret.sptk.many rp
|
---|
[a35b458] | 80 |
|
---|
[54171e8] | 81 | 3:
|
---|
[a35b458] | 82 |
|
---|
[54171e8] | 83 | adds r14 = 7, in0 ;;
|
---|
| 84 | and r14 = -8, r14 ;;
|
---|
| 85 | cmp.eq p6, p7 = r14, in0
|
---|
| 86 | (p7) br.cond.dptk 0b
|
---|
| 87 | shr.u r18 = in2, 3 ;;
|
---|
| 88 | cmp.ne p6, p7 = 0, r18
|
---|
| 89 | (p7) br.cond.dpnt 5f ;;
|
---|
| 90 | (p6) adds r14 = -1, r18
|
---|
| 91 | (p6) mov r16 = r0
|
---|
| 92 | (p6) mov r17 = r0 ;;
|
---|
| 93 | (p6) mov ar.lc = r14
|
---|
[a35b458] | 94 |
|
---|
[54171e8] | 95 | 4:
|
---|
[a35b458] | 96 |
|
---|
[54171e8] | 97 | shladd r14 = r16, 3, r0
|
---|
| 98 | adds r16 = 1, r17 ;;
|
---|
| 99 | add r15 = in1, r14
|
---|
| 100 | add r14 = in0, r14
|
---|
| 101 | mov r17 = r16 ;;
|
---|
| 102 | ld8 r15 = [r15] ;;
|
---|
| 103 | st8 [r14] = r15
|
---|
| 104 | br.cloop.sptk.few 4b
|
---|
[a35b458] | 105 |
|
---|
[54171e8] | 106 | 5:
|
---|
[a35b458] | 107 |
|
---|
[54171e8] | 108 | and r15 = 7, in2
|
---|
| 109 | shladd r14 = r18, 3, r0
|
---|
| 110 | mov r16 = r0
|
---|
| 111 | mov r18 = r0 ;;
|
---|
| 112 | cmp.eq p6, p7 = 0, r15
|
---|
| 113 | add in0 = r14, in0
|
---|
| 114 | adds r15 = -1, r15
|
---|
[1b20da0] | 115 | add r17 = r14, in1
|
---|
[54171e8] | 116 | (p6) br.cond.dpnt 2b ;;
|
---|
| 117 | mov ar.lc = r15
|
---|
[a35b458] | 118 |
|
---|
[54171e8] | 119 | 6:
|
---|
[a35b458] | 120 |
|
---|
[54171e8] | 121 | add r14 = r16, r17
|
---|
| 122 | add r15 = r16, in0
|
---|
| 123 | adds r16 = 1, r18 ;;
|
---|
| 124 | ld1 r14 = [r14]
|
---|
| 125 | mov r18 = r16 ;;
|
---|
| 126 | st1 [r15] = r14
|
---|
| 127 | br.cloop.sptk.few 6b ;;
|
---|
| 128 | mov ar.lc = r2
|
---|
| 129 | mov ar.pfs = loc0
|
---|
| 130 | br.ret.sptk.many rp
|
---|
[27f67f5] | 131 | FUNCTION_END(memcpy_from_uspace)
|
---|
| 132 | FUNCTION_END(memcpy_to_uspace)
|
---|
[54171e8] | 133 |
|
---|
[27f67f5] | 134 | SYMBOL(memcpy_from_uspace_failover_address)
|
---|
| 135 | SYMBOL(memcpy_to_uspace_failover_address)
|
---|
[54171e8] | 136 | /* Return 0 on failure */
|
---|
| 137 | mov r8 = r0
|
---|
[ffdfcf0] | 138 | mov ar.pfs = loc0
|
---|
| 139 | br.ret.sptk.many rp
|
---|
[2b50d7c] | 140 |
|
---|
[27f67f5] | 141 | FUNCTION_BEGIN(cpu_halt)
|
---|
[2b50d7c] | 142 | br cpu_halt
|
---|
[27f67f5] | 143 | FUNCTION_END(cpu_halt)
|
---|
[b994a60] | 144 |
|
---|
| 145 | /** Switch to userspace - low level code.
|
---|
| 146 | *
|
---|
| 147 | * @param in0 Userspace entry point address.
|
---|
| 148 | * @param in1 Userspace stack pointer address.
|
---|
| 149 | * @param in2 Userspace register stack pointer address.
|
---|
[0f250f9] | 150 | * @param in3 Userspace address of thread uspace_arg_t structure.
|
---|
| 151 | * @param in4 Value to be stored in IPSR.
|
---|
| 152 | * @param in5 Value to be stored in RSC.
|
---|
[54171e8] | 153 | *
|
---|
[b994a60] | 154 | */
|
---|
[27f67f5] | 155 | FUNCTION_BEGIN(switch_to_userspace)
|
---|
[0f250f9] | 156 | alloc loc0 = ar.pfs, 6, 3, 0, 0
|
---|
[a35b458] | 157 |
|
---|
[54171e8] | 158 | /* Disable interruption collection and interrupts */
|
---|
| 159 | rsm (PSR_IC_MASK | PSR_I_MASK)
|
---|
[b994a60] | 160 | srlz.d ;;
|
---|
| 161 | srlz.i ;;
|
---|
[a35b458] | 162 |
|
---|
[0f250f9] | 163 | mov cr.ipsr = in4
|
---|
[b994a60] | 164 | mov cr.iip = in0
|
---|
| 165 | mov r12 = in1
|
---|
[a35b458] | 166 |
|
---|
[b994a60] | 167 | xor r1 = r1, r1
|
---|
[a35b458] | 168 |
|
---|
[c98e6ee] | 169 | /* r2 is defined to hold pcb_ptr - set it to 0 */
|
---|
| 170 | xor r2 = r2, r2
|
---|
[a35b458] | 171 |
|
---|
[b994a60] | 172 | mov loc1 = cr.ifs
|
---|
| 173 | movl loc2 = PFM_MASK ;;
|
---|
| 174 | and loc1 = loc2, loc1 ;;
|
---|
[54171e8] | 175 | mov cr.ifs = loc1 ;; /* prevent decrementing BSP by rfi */
|
---|
[a35b458] | 176 |
|
---|
[b994a60] | 177 | invala
|
---|
[a35b458] | 178 |
|
---|
[b994a60] | 179 | mov loc1 = ar.rsc ;;
|
---|
[54171e8] | 180 | and loc1 = ~3, loc1 ;;
|
---|
| 181 | mov ar.rsc = loc1 ;; /* put RSE into enforced lazy mode */
|
---|
[a35b458] | 182 |
|
---|
[b994a60] | 183 | flushrs ;;
|
---|
[a35b458] | 184 |
|
---|
[b994a60] | 185 | mov ar.bspstore = in2 ;;
|
---|
[0f250f9] | 186 | mov ar.rsc = in5 ;;
|
---|
[a35b458] | 187 |
|
---|
[0f250f9] | 188 | mov r8 = in3
|
---|
[a35b458] | 189 |
|
---|
[b994a60] | 190 | rfi ;;
|
---|
[27f67f5] | 191 | FUNCTION_END(switch_to_userspace)
|
---|
[da52547] | 192 |
|
---|
[28a5ebd] | 193 | FUNCTION_BEGIN(early_putuchar)
|
---|
[da52547] | 194 | br.ret.sptk.many b0
|
---|
[28a5ebd] | 195 | FUNCTION_END(early_putuchar)
|
---|