1/* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2022 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.syntax unified 32.arch armv7e-m 33.fpu fpv4-sp-d16 34.thumb 35 36.equ OS_FPU_CPACR, 0xE000ED88 37.equ OS_FPU_CPACR_ENABLE, 0x00F00000 38.equ OS_NVIC_INT_CTRL, 0xE000ED04 39.equ OS_NVIC_SYSPRI2, 0xE000ED20 40.equ OS_NVIC_PENDSV_PRI, 0xF0F00000 41.equ OS_NVIC_PENDSVSET, 0x10000000 42.equ OS_TASK_STATUS_RUNNING, 0x0010 43.equ OS_CONTROL_FPCA_ENABLE, 0x4 44.equ OS_CONTROL_KERNEL_MODE, 0x2 45#if (LOSCFG_SECURE == 1) 46.equ OS_CONTROL_USER_MODE, 0x3 47.equ OS_TASK_FLAG_USER_TASK, 0x0200 48#endif 49 50 .section .text 51 .thumb 52 53.macro SIGNAL_CONTEXT_RESTORE 54 push {r12, lr} 55 blx OsSignalTaskContextRestore 56 pop {r12, lr} 57 cmp r0, #0 58 mov r1, r0 59 bne SignalContextRestore 60.endm 61 62 .type HalStartToRun, %function 63 .global HalStartToRun 64HalStartToRun: 65 .fnstart 66 .cantunwind 67 68 ldr r4, =OS_NVIC_SYSPRI2 69 ldr r5, =OS_NVIC_PENDSV_PRI 70 str r5, [r4] 71 72 mov r0, #OS_CONTROL_KERNEL_MODE 73 msr CONTROL, r0 74 75 ldr r1, =g_losTask 76 ldr r0, [r1, #4] 77 ldr r12, [r0] 78 79 ldr.w r1, =OS_FPU_CPACR 80 ldr r1, [r1] 81 and r1, r1, #OS_FPU_CPACR_ENABLE 82 cmp r1, #OS_FPU_CPACR_ENABLE 83 bne __DisabledFPU 84 add r12, r12, #100 85 86 ldmfd r12!, {R0-R7} 87 add r12, r12, #72 88 msr psp, r12 89 vpush {s0} 90 vpop {s0} 91 mov lr, r5 92 cpsie i 93 bx r6 94 95__DisabledFPU: 96 add r12, r12, #36 97 98 ldmfd r12!, {r0-r7} 99 msr psp, r12 100 mov lr, r5 101 cpsie I 102 bx r6 103 104 .fnend 105 106 .type ArchIntLock, %function 107 .global ArchIntLock 108ArchIntLock: 109 .fnstart 110 .cantunwind 111 112 MRS R0, PRIMASK 113 CPSID I 114 BX LR 115 .fnend 116 117 .type ArchIntUnLock, %function 118 .global ArchIntUnLock 119ArchIntUnLock: 120 .fnstart 121 .cantunwind 122 123 MRS R0, PRIMASK 124 CPSIE I 125 BX LR 126 .fnend 127 128 .type ArchIntRestore, %function 129 .global ArchIntRestore 130ArchIntRestore: 131 .fnstart 132 .cantunwind 133 134 MSR PRIMASK, R0 135 BX LR 136 .fnend 137 138 .type ArchTaskSchedule, %function 139 .global ArchTaskSchedule 140ArchTaskSchedule: 141 .fnstart 142 .cantunwind 143 144 ldr r0, =OS_NVIC_INT_CTRL 145 ldr r1, =OS_NVIC_PENDSVSET 146 str r1, [r0] 147 bx lr 148 dsb 149 isb 150 .fnend 151 152 .type HalPendSV, %function 153 .global HalPendSV 154HalPendSV: 155 .fnstart 156 .cantunwind 157 158 mrs r12, PRIMASK 159 cpsid I 160 161HalTaskSwitch: 162 SIGNAL_CONTEXT_RESTORE 163 164 push {r12, lr} 165 blx OsSchedTaskSwitch 166 pop {r12, lr} 167 cmp r0, #0 168 mov r0, lr 169 bne TaskContextSwitch 170 msr PRIMASK, r12 171 bx lr 172 173TaskContextSwitch: 174 mov lr, r0 175 mrs r0, psp 176 177 stmfd r0!, {r4-r12} 178 ldr.w r3, =OS_FPU_CPACR 179 ldr r3, [r3] 180 and r3, r3, #OS_FPU_CPACR_ENABLE 181 cmp r3, #OS_FPU_CPACR_ENABLE 182 bne __DisabledFPU1 183 vstmdb r0!, {d8-d15} 184 185__DisabledFPU1: 186 ldr r5, =g_losTask 187 ldr r6, [r5] 188 str r0, [r6] 189 190 ldr r0, [r5, #4] 191 str r0, [r5] 192 ldr r1, [r0] 193 194SignalContextRestore: 195 ldr.w r3, =OS_FPU_CPACR 196 ldr r3, [r3] 197 and r3, r3, #OS_FPU_CPACR_ENABLE 198 cmp r3, #OS_FPU_CPACR_ENABLE 199 bne __DisabledFPU2 200 vldmia r1!, {d8-d15} 201 202__DisabledFPU2: 203#if (LOSCFG_SECURE == 1) 204 ldrh r7, [r0, #4] 205 tst r7, #OS_TASK_FLAG_USER_TASK 206 ite eq 207 moveq r3, #OS_CONTROL_KERNEL_MODE 208 movne r3, #OS_CONTROL_USER_MODE 209 msr CONTROL, r3 210#endif 211 ldmfd r1!, {r4-r12} 212 msr psp, r1 213 214 msr PRIMASK, r12 215 216 bx lr 217 .fnend 218