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#include "los_arch_macro.h" 34 35.section .text 36.literal_position 37.align 4 38.type HalTaskContextSwitch, %function 39.global HalTaskContextSwitch 40HalTaskContextSwitch: 41 42 entry sp, 16 43 addi a2, sp, -CONTEXT_SIZE 44 PUSH_ALL_REG a2 45 call0 SaveRetAddr 46 beqi a3, 1, .switchdone 47 movi a4, g_losTask 48 l32i a5, a4, 0 /* get run task */ 49 s32i a2, a5, 0 /* store sp */ 50 l32i a5, a4, 4 /* get new task */ 51 s32i a5, a4, 0 /* run task = new task */ 52 l32i a4, a5, 0 /* get new sp */ 53 rsr a5, PS 54 movi a3, ~(WOE_ENABLE | LEVEL_MASK) 55 and a2, a5, a3 56 addi a2, a2, 3 57 wsr a2, PS 58 rsync 59 call0 SpillWindow 60 mov a2, a4 61 POP_ALL_REG a2 EPC5 EPS5 62 rfi 5 63 64.switchdone: 65 retw 66 67.type HakSpillWindow, %function 68.global HakSpillWindow 69HakSpillWindow: 70 71 entry sp, 32 72 73 addi a2, sp, -CONTEXT_SIZE 74 PUSH_ALL_REG a2 75 76 rsr a5, PS 77 movi a3, ~(WOE_ENABLE | LEVEL_MASK) /* disable woe and int */ 78 and a3, a5, a3 79 addi a3, a3, LEVEL3 80 wsr a3, PS 81 rsync 82 83 mov a4, a2 84 call0 SpillWindow 85 86 l32i a5, a4, CONTEXT_OFF_PS /* restroe PS */ 87 wsr a5, PS 88 rsync 89 l32i a0, a4, CONTEXT_OFF_A0 90 l32i a1, a4, CONTEXT_OFF_A1 91 92 retw 93 94.type OsStartToRun, %function 95.global OsStartToRun 96OsStartToRun: 97 98 movi a2, g_losTask 99 l32i a3, a2, 4 /* get new task */ 100 l32i sp, a3, 0 /* get sp */ 101 102 rsr a4, PS 103 movi a3, ~(WOE_ENABLE | LEVEL_MASK) 104 and a2, a4, a3 105 addi a2, a2, LEVEL3 106 wsr a2, PS 107 rsync 108 109 mov a5, a1 110 l32i a1, a1, CONTEXT_OFF_A1 111 call0 SpillWindow 112 113 mov a2, a5 114 POP_ALL_REG a2 EPC5 EPS5 115 rfi 5 116 117.global SaveRetAddr 118.type SaveRetAddr, @function 119.literal_position 120.align 4 121 122SaveRetAddr: 123 124 movi a3, 1 125 s32i a3, a2, CONTEXT_OFF_A3 126 s32i a0, a2, CONTEXT_OFF_PC /* save pc */ 127 movi a3, 0 128 ret 129