2 # Copyright (c) 2005 Jakub Jermar
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
29 #include <arch/register.h>
33 /** Copy memory from/to userspace.
35 * This memcpy() has been taken from the assembler output of
36 * the generic _memcpy() and modified to have the failover part.
38 * @param in0 Destination address.
39 * @param in1 Source address.
40 * @param in2 Number of byte to copy.
43 .global memcpy_from_uspace
44 .global memcpy_to_uspace
45 .global memcpy_from_uspace_failover_address
46 .global memcpy_to_uspace_failover_address
50 alloc loc0 = ar.pfs, 3, 1, 0, 0
56 cmp.ne p6, p7 = r14, in1
57 (p7) br.cond.dpnt 3f ;;
59 cmp.ne p6, p7 = 0, in2
60 (p7) br.cond.dpnt 2f ;;
61 (p6) adds r14 = -1, in2
72 br.cloop.sptk.few 1b ;;
81 cmp.eq p6, p7 = r14, in0
84 cmp.ne p6, p7 = 0, r18
85 (p7) br.cond.dpnt 5f ;;
86 (p6) adds r14 = -1, r18
91 shladd r14 = r16, 3, r0
101 shladd r14 = r18, 3, r0
104 cmp.eq p6, p7 = 0, r15
108 (p6) br.cond.dpnt 2b ;;
117 br.cloop.sptk.few 6b ;;
123 memcpy_from_uspace_failover_address:
124 memcpy_to_uspace_failover_address:
125 mov r8 = r0 /* return 0 on failure */
140 br.call.sptk.many b0=printf
144 /** Switch to userspace - low level code.
146 * @param in0 Userspace entry point address.
147 * @param in1 Userspace stack pointer address.
148 * @param in2 Userspace register stack pointer address.
149 * @param in3 Userspace address of thread uspace_arg_t structure.
150 * @param in4 Value to be stored in IPSR.
151 * @param in5 Value to be stored in RSC.
153 .global switch_to_userspace
155 alloc loc0 = ar.pfs, 6, 3, 0, 0
156 rsm (PSR_IC_MASK | PSR_I_MASK) /* disable interruption collection and interrupts */
167 movl loc2 = PFM_MASK ;;
168 and loc1 = loc2, loc1 ;;
169 mov cr.ifs = loc1 ;; /* prevent decrementing BSP by rfi */
174 and loc1 = ~3, loc1 ;;
175 mov ar.rsc = loc1 ;; /* put RSE into enforced lazy mode */
179 mov ar.bspstore = in2 ;;