1/* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include "los_arch_regs.h" 33 34.text 35.align 4 36.literal_position 37.global SpillWindow 38SpillWindow: 39 40 rsr a2, WINDOWBASE /* read windowbase reg */ 41 42 movi a3, WINDOWSTARTBITS 43 sub a3, a3, a2 /* get the num of high bits */ 44 addi a3, a3, -1 45 46 ssl a3 /* set left shift bit */ 47 rsr a3, WINDOWSTART /* read windowstart reg */ 48 sll a3, a3 49 movi a2, WINDOWSTARTMASK 50 and a3, a3, a2 51 52 beqi a3, 0, .Linvalidwindowstart /* if a3 == 0 goto Linvalidwindowstart */ 53 54 rsr a2, WINDOWBASE /* read windowbase reg */ 55 56 addi a2, a2, 1 57 ssr a2 58 rsr a2, WINDOWSTART 59 srl a2, a2 60 or a2, a2, a3 61 movi a3, 0 62 63.bitclear0: 64 bbsi.l a2, 0, .bitcleardone 65 srli a2, a2, 1 66 addi a3, a3, 1 67 j .bitclear0 68 69.bitcleardone: 70 srli a2, a2, 1 /* drop the first bit */ 71 72 wsr a2, WINDOWSTART 73 rsr a2, WINDOWBASE 74 75 add a2, a2, a3 76 wsr a2, WINDOWBASE 77 rsync 78 79 rsr a2, WINDOWSTART 80 81.Lspillstart: 82 beqi a2, 0, .Ldone 83 bbsi.l a2, 0, .Lspill4 84 bbsi.l a2, 1, .Lspill8 85 bbsi.l a2, 2, .Lspill12 86 j .Linvalidwindow 87 88.Lspill4: 89 s32e a4, a9, -16 90 s32e a5, a9, -12 91 s32e a6, a9, -8 92 s32e a7, a9, -4 93 94 srli a6, a2, 1 95 rotw 1 96 j .Lspillstart 97 98.Lspill8: 99 s32e a4, a13, -16 100 s32e a5, a13, -12 101 s32e a6, a13, -8 102 s32e a7, a13, -4 103 104 l32i a3, a5, -12 /* call[i - 1]'s sp */ 105 addi a3, a3, -16 /* base area */ 106 107 s32e a8, a3, -16 108 s32e a9, a3, -12 109 s32e a10, a3, -8 110 s32e a11, a3, -4 111 112 srli a10, a2, 2 113 rotw 2 114 j .Lspillstart 115 116.Lspill12: 117 rotw 1 118 s32e a0, a13, -16 119 s32e a1, a13, -12 120 s32e a2, a13, -8 121 s32e a3, a13, -4 122 123 l32i a3, a1, -12 /* call[i - 1]'s sp */ 124 addi a3, a3, -16 /* base area */ 125 126 s32e a4, a3, -32 127 s32e a5, a3, -28 128 s32e a6, a3, -24 129 s32e a7, a3, -20 130 s32e a8, a3, -16 131 s32e a9, a3, -12 132 s32e a10, a3, -8 133 s32e a11, a3, -4 134 135 rotw -1 136 srli a14, a2, 3 137 rotw 3 138 j .Lspillstart 139 140.Ldone: 141 rotw 1 142 rsr a2, WINDOWBASE 143 ssl a2 144 movi a2, 1 145 sll a2, a2 146 wsr a2, WINDOWSTART 147 rsync 148 movi a2, 0 149 ret 150 151.Linvalidwindowstart: 152 movi a2, 1 153 ret 154 155.Linvalidwindow: 156 movi a3, 1 157 slli a2, a2, 1 158 or a2, a2, a3 159 rsr a3, WINDOWBASE 160 161.RestoreWindowBase: 162 bbsi.l a2, WINDOWSTARTBITS - 1, .RestoreWindow 163 slli a2, a2, 1 164 addi a3, a3, -1 165 j .RestoreWindowBase 166 167.RestoreWindow: 168 extui a3, a3, 0, WINDOWSTARTBITS /* the original bit */ 169 170 addi a3, a3, 1 171 ssl a3 172 sll a3, a2 173 slli a2, a2, 32 - WINDOWSTARTBITS 174 srl a2, a2 175 176 or a2, a2, a3 177 extui a2, a2, 0, WINDOWSTARTBITS 178 wsr a2, WINDOWSTART 179 180 movi a3, 31 181 rsr a2, SAR 182 sub a2, a3, a2 183 wsr a2, WINDOWBASE 184 rsync 185 186 movi a2, 2 187 ret 188