• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 .syntax unified
33 .arch armv7e-m
34 .thumb
35 .fpu fpv5-d16
36//;.arch_extension sec
37
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
44    .section .text
45    .thumb
46
47.macro SIGNAL_CONTEXT_RESTORE
48    push    {r12, lr}
49    blx     OsSignalTaskContextRestore
50    pop     {r12, lr}
51    cmp     r0, #0
52    mov     r1, r0
53    bne     SignalContextRestore
54.endm
55
56    .type HalStartToRun, %function
57    .global HalStartToRun
58HalStartToRun:
59    .fnstart
60    .cantunwind
61
62    ldr     r4, =OS_NVIC_SYSPRI2
63    ldr     r5, =OS_NVIC_PENDSV_PRI
64    str     r5, [r4]
65
66    mov     r0, #2
67    msr     CONTROL, r0
68
69    ldr     r1, =g_losTask
70    ldr     r0, [r1, #4]
71    ldr     r12, [r0]
72#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
73     (defined(__FPU_USED) && (__FPU_USED == 1U)))
74    add     r12, r12, #100
75
76    ldmfd   r12!, {r0-r7}
77    add     r12, r12, #72
78    msr     psp, r12
79    vpush   {S0}
80    vpop    {S0}
81#else
82    add     r12, r12, #36
83
84    ldmfd   r12!, {r0-r7}
85    msr     psp, r12
86#endif
87    mov     lr, r5
88    //MSR     xPSR, R7
89
90    cpsie   I
91    bx      r6
92
93    .fnend
94
95
96    .type ArchIntLock, %function
97    .global ArchIntLock
98ArchIntLock:
99    .fnstart
100    .cantunwind
101
102    MRS R0, PRIMASK
103    CPSID I
104    BX LR
105    .fnend
106
107    .type ArchIntUnLock, %function
108    .global ArchIntUnLock
109ArchIntUnLock:
110    .fnstart
111    .cantunwind
112
113    MRS R0, PRIMASK
114    CPSIE I
115    BX LR
116    .fnend
117
118    .type ArchIntRestore, %function
119    .global ArchIntRestore
120ArchIntRestore:
121    .fnstart
122    .cantunwind
123
124    MSR PRIMASK, R0
125    BX LR
126    .fnend
127
128    .type ArchTaskSchedule, %function
129    .global ArchTaskSchedule
130ArchTaskSchedule:
131    .fnstart
132    .cantunwind
133
134    ldr     r0, =OS_NVIC_INT_CTRL
135    ldr     r1, =OS_NVIC_PENDSVSET
136    str     r1, [r0]
137    dsb
138    isb
139    bx      lr
140    .fnend
141
142    .type HalPendSV, %function
143    .global HalPendSV
144HalPendSV:
145    .fnstart
146    .cantunwind
147
148    mrs     r12, PRIMASK
149    cpsid   I
150
151HalTaskSwitch:
152    SIGNAL_CONTEXT_RESTORE
153
154    push    {r12, lr}
155    blx     OsSchedTaskSwitch
156    pop     {r12, lr}
157    cmp     r0, #0
158    mov     r0, lr
159    bne     TaskContextSwitch
160    msr     PRIMASK, r12
161    bx      lr
162
163TaskContextSwitch:
164    mov     lr, r0
165    mrs     r0, psp
166
167    stmfd   r0!, {r4-r12}
168
169#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
170     (defined(__FPU_USED) && (__FPU_USED == 1U)))
171    vstmdb   r0!, {d8-d15}
172#endif
173    ldr     r5, =g_losTask
174    ldr     r6, [r5]
175    str     r0, [r6]
176
177    ldr     r0, [r5, #4]
178    str     r0, [r5]
179    ldr     r1, [r0]
180
181SignalContextRestore:
182#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
183     (defined(__FPU_USED) && (__FPU_USED == 1U)))
184    vldmia   r1!, {d8-d15}
185#endif
186    ldmfd   r1!, {r4-r12}
187    msr     psp,  r1
188
189    msr     PRIMASK, r12
190
191    bx      lr
192    .fnend
193