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