[6ef72c9] | 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 | .text
|
---|
| 30 |
|
---|
[4b2c872d] | 31 | .global context_save_arch
|
---|
| 32 | .global context_restore_arch
|
---|
[6ef72c9] | 33 |
|
---|
[4b2c872d] | 34 | context_save_arch:
|
---|
[ba1b7393] | 35 | alloc loc0 = ar.pfs, 1, 8, 0, 0
|
---|
[1eee8383] | 36 | mov loc1 = ar.unat ;;
|
---|
[32a89bf] | 37 | /* loc2 */
|
---|
| 38 | mov loc3 = ar.rsc
|
---|
[60049aa] | 39 |
|
---|
| 40 | .auto
|
---|
| 41 |
|
---|
| 42 | /*
|
---|
| 43 | * Flush dirty registers to backing store.
|
---|
| 44 | * After this ar.bsp and ar.bspstore are equal.
|
---|
| 45 | */
|
---|
| 46 | flushrs
|
---|
| 47 | mov loc4 = ar.bsp
|
---|
| 48 |
|
---|
| 49 | /*
|
---|
| 50 | * Put RSE to enforced lazy mode.
|
---|
| 51 | * So that ar.rnat can be read.
|
---|
| 52 | */
|
---|
[154049e] | 53 | and loc5 = ~3, loc3
|
---|
[60049aa] | 54 | mov ar.rsc = loc5
|
---|
[32a89bf] | 55 | mov loc5 = ar.rnat
|
---|
[60049aa] | 56 |
|
---|
| 57 | .explicit
|
---|
| 58 |
|
---|
[32a89bf] | 59 | mov loc6 = ar.lc
|
---|
[1eee8383] | 60 |
|
---|
[32a89bf] | 61 | /*
|
---|
| 62 | * Save application registers
|
---|
| 63 | */
|
---|
[1eee8383] | 64 | st8 [in0] = loc0, 8 ;; /* save ar.pfs */
|
---|
| 65 | st8 [in0] = loc1, 8 ;; /* save ar.unat (caller) */
|
---|
| 66 | mov loc2 = in0 ;;
|
---|
| 67 | add in0 = 8, in0 ;; /* skip ar.unat (callee) */
|
---|
[32a89bf] | 68 | st8 [in0] = loc3, 8 ;; /* save ar.rsc */
|
---|
| 69 | st8 [in0] = loc4, 8 ;; /* save ar.bsp */
|
---|
| 70 | st8 [in0] = loc5, 8 ;; /* save ar.rnat */
|
---|
| 71 | st8 [in0] = loc6, 8 ;; /* save ar.lc */
|
---|
[9db5b66] | 72 |
|
---|
[6b96ab44] | 73 | /*
|
---|
[1eee8383] | 74 | * Save general registers including NaT bits
|
---|
[6b96ab44] | 75 | */
|
---|
[1eee8383] | 76 | st8.spill [in0] = r1, 8 ;;
|
---|
| 77 | st8.spill [in0] = r4, 8 ;;
|
---|
| 78 | st8.spill [in0] = r5, 8 ;;
|
---|
| 79 | st8.spill [in0] = r6, 8 ;;
|
---|
| 80 | st8.spill [in0] = r7, 8 ;;
|
---|
| 81 | st8.spill [in0] = r12, 8 ;; /* save sp */
|
---|
| 82 | st8.spill [in0] = r13, 8 ;;
|
---|
| 83 |
|
---|
| 84 | mov loc3 = ar.unat ;;
|
---|
| 85 | st8 [loc2] = loc3 /* save ar.unat (callee) */
|
---|
[9db5b66] | 86 |
|
---|
[6b96ab44] | 87 | /*
|
---|
| 88 | * Save branch registers
|
---|
| 89 | */
|
---|
[1eee8383] | 90 | mov loc2 = b0 ;;
|
---|
| 91 | st8 [in0] = loc2, 8 /* save pc */
|
---|
| 92 | mov loc3 = b1 ;;
|
---|
[6b96ab44] | 93 | st8 [in0] = loc3, 8
|
---|
[1eee8383] | 94 | mov loc4 = b2 ;;
|
---|
[6b96ab44] | 95 | st8 [in0] = loc4, 8
|
---|
[1eee8383] | 96 | mov loc5 = b3 ;;
|
---|
[6b96ab44] | 97 | st8 [in0] = loc5, 8
|
---|
[1eee8383] | 98 | mov loc6 = b4 ;;
|
---|
[6b96ab44] | 99 | st8 [in0] = loc6, 8
|
---|
[1eee8383] | 100 | mov loc7 = b5 ;;
|
---|
[6b96ab44] | 101 | st8 [in0] = loc7, 8
|
---|
| 102 |
|
---|
| 103 | /*
|
---|
| 104 | * Save predicate registers
|
---|
| 105 | */
|
---|
[1eee8383] | 106 | mov loc2 = pr ;;
|
---|
| 107 | st8 [in0] = loc2, 8
|
---|
[9db5b66] | 108 |
|
---|
[1eee8383] | 109 | mov ar.unat = loc1
|
---|
[9db5b66] | 110 |
|
---|
| 111 | add r8 = r0, r0, 1 /* context_save returns 1 */
|
---|
[00a44bc] | 112 | br.ret.sptk.many b0
|
---|
[6ef72c9] | 113 |
|
---|
[4b2c872d] | 114 | context_restore_arch:
|
---|
[37e9dbd] | 115 | alloc loc0 = ar.pfs, 1, 9, 0, 0 ;;
|
---|
[9db5b66] | 116 |
|
---|
[32a89bf] | 117 | ld8 loc0 = [in0], 8 ;; /* load ar.pfs */
|
---|
| 118 | ld8 loc1 = [in0], 8 ;; /* load ar.unat (caller) */
|
---|
| 119 | ld8 loc2 = [in0], 8 ;; /* load ar.unat (callee) */
|
---|
| 120 | ld8 loc3 = [in0], 8 ;; /* load ar.rsc */
|
---|
| 121 | ld8 loc4 = [in0], 8 ;; /* load ar.bsp */
|
---|
| 122 | ld8 loc5 = [in0], 8 ;; /* load ar.rnat */
|
---|
| 123 | ld8 loc6 = [in0], 8 ;; /* load ar.lc */
|
---|
| 124 |
|
---|
[60049aa] | 125 | .auto
|
---|
| 126 |
|
---|
| 127 | /*
|
---|
| 128 | * Invalidate the ALAT
|
---|
| 129 | */
|
---|
| 130 | invala
|
---|
| 131 |
|
---|
[9db5b66] | 132 | /*
|
---|
[37e9dbd] | 133 | * Put RSE to enforced lazy mode.
|
---|
| 134 | * So that ar.bspstore and ar.rnat can be written.
|
---|
| 135 | */
|
---|
| 136 | movl loc8 = ~3
|
---|
| 137 | and loc8 = loc3, loc8
|
---|
| 138 | mov ar.rsc = loc8
|
---|
| 139 |
|
---|
| 140 | /*
|
---|
| 141 | * Flush dirty registers to backing store.
|
---|
| 142 | * We do this because we want the following move
|
---|
| 143 | * to ar.bspstore to assign the same value to ar.bsp.
|
---|
[9db5b66] | 144 | */
|
---|
[37e9dbd] | 145 | flushrs
|
---|
[60049aa] | 146 |
|
---|
[37e9dbd] | 147 | /*
|
---|
| 148 | * Restore application registers
|
---|
| 149 | */
|
---|
| 150 | mov ar.bspstore = loc4 /* rse.bspload = ar.bsp = ar.bspstore = loc4 */
|
---|
[60049aa] | 151 | mov ar.rnat = loc5
|
---|
| 152 | mov ar.pfs = loc0
|
---|
| 153 | mov ar.rsc = loc3
|
---|
| 154 |
|
---|
| 155 | .explicit
|
---|
| 156 |
|
---|
[1eee8383] | 157 | mov ar.unat = loc2 ;;
|
---|
[32a89bf] | 158 | mov ar.lc = loc6
|
---|
[1eee8383] | 159 |
|
---|
[6b96ab44] | 160 | /*
|
---|
[1eee8383] | 161 | * Restore general registers including NaT bits
|
---|
[6b96ab44] | 162 | */
|
---|
[1eee8383] | 163 | ld8.fill r1 = [in0], 8 ;;
|
---|
| 164 | ld8.fill r4 = [in0], 8 ;;
|
---|
| 165 | ld8.fill r5 = [in0], 8 ;;
|
---|
| 166 | ld8.fill r6 = [in0], 8 ;;
|
---|
| 167 | ld8.fill r7 = [in0], 8 ;;
|
---|
| 168 | ld8.fill r12 = [in0], 8 ;; /* restore sp */
|
---|
| 169 | ld8.fill r13 = [in0], 8 ;;
|
---|
[9db5b66] | 170 |
|
---|
[6b96ab44] | 171 | /*
|
---|
| 172 | * Restore branch registers
|
---|
| 173 | */
|
---|
[1eee8383] | 174 | ld8 loc2 = [in0], 8 ;; /* restore pc */
|
---|
| 175 | mov b0 = loc2
|
---|
[6b96ab44] | 176 | ld8 loc3 = [in0], 8 ;;
|
---|
[1eee8383] | 177 | mov b1 = loc3
|
---|
[6b96ab44] | 178 | ld8 loc4 = [in0], 8 ;;
|
---|
[1eee8383] | 179 | mov b2 = loc4
|
---|
[6b96ab44] | 180 | ld8 loc5 = [in0], 8 ;;
|
---|
[1eee8383] | 181 | mov b3 = loc5
|
---|
[6b96ab44] | 182 | ld8 loc6 = [in0], 8 ;;
|
---|
[1eee8383] | 183 | mov b4 = loc6
|
---|
[6b96ab44] | 184 | ld8 loc7 = [in0], 8 ;;
|
---|
[1eee8383] | 185 | mov b5 = loc7
|
---|
[6b96ab44] | 186 |
|
---|
[1eee8383] | 187 | /*
|
---|
| 188 | * Restore predicate registers
|
---|
| 189 | */
|
---|
| 190 | ld8 loc2 = [in0], 8 ;;
|
---|
| 191 | mov pr = loc2, ~0
|
---|
[9db5b66] | 192 |
|
---|
[1eee8383] | 193 | mov ar.unat = loc1
|
---|
[9db5b66] | 194 |
|
---|
| 195 | mov r8 = r0 /* context_restore returns 0 */
|
---|
[00a44bc] | 196 | br.ret.sptk.many b0
|
---|