• 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        PRESERVE8
33
34        EXPORT  ArchIntLock
35        EXPORT  ArchIntUnLock
36        EXPORT  ArchIntRestore
37        EXPORT  HalStartToRun
38        EXPORT  ArchTaskSchedule
39        EXPORT  HalPendSV
40        IMPORT  OsSchedTaskSwitch
41        IMPORT  g_losTask
42
43OS_NVIC_INT_CTRL            EQU     0xE000ED04
44OS_NVIC_SYSPRI2             EQU     0xE000ED20
45OS_NVIC_PENDSV_PRI          EQU     0xF0F00000
46OS_NVIC_PENDSVSET           EQU     0x10000000
47OS_TASK_STATUS_RUNNING      EQU     0x0010
48
49    AREA  |.text|, CODE, READONLY
50    THUMB
51    REQUIRE8
52
53HalStartToRun
54    LDR     R4, =OS_NVIC_SYSPRI2
55    LDR     R5, =OS_NVIC_PENDSV_PRI
56    STR     R5, [R4]
57
58    MOV     R0, #2
59    MSR     CONTROL, R0
60
61    LDR     R1, =g_losTask
62    LDR     R0, [R1, #4]
63    LDR     R12, [R0]
64    ;ADD     R12, R12, #100
65    ADD     R12, R12, #36
66
67    LDMFD   R12!, {R0-R7}
68    ;ADD     R12, R12, #72
69    MSR     PSP, R12
70    ;VPUSH   S0;
71    ;VPOP    S0;
72
73    MOV     LR, R5
74   ;MSR     xPSR, R7
75
76    CPSIE   I
77    BX      R6
78
79
80ArchIntLock
81    MRS     R0, PRIMASK
82    CPSID   I
83    BX      LR
84
85ArchIntUnLock
86    MRS     R0, PRIMASK
87    CPSIE   I
88    BX      LR
89
90ArchIntRestore
91    MSR     PRIMASK, R0
92    BX      LR
93
94ArchTaskSchedule
95    LDR     R0, =OS_NVIC_INT_CTRL
96    LDR     R1, =OS_NVIC_PENDSVSET
97    STR     R1, [R0]
98    DSB
99    ISB
100    BX      LR
101
102HalPendSV
103    MRS     R12, PRIMASK
104    CPSID   I
105
106HalTaskSwitch
107    PUSH    {R12, LR}
108    BL      OsSchedTaskSwitch
109    POP     {R12, LR}
110    CMP     R0, #0
111    MOV     R0, LR
112    BNE     TaskContextSwitch
113    MSR     PRIMASK, R12
114    BX      LR
115
116TaskContextSwitch
117    MOV     LR, R0
118    MRS     R0, PSP
119
120    STMFD   R0!, {R4-R12}
121    ;VSTMDB  R0!, {D8-D15}
122
123    LDR     R5, =g_losTask
124    LDR     R6, [R5]
125    STR     R0, [R6]
126
127    LDR     R0, [R5, #4]
128    STR     R0, [R5]
129
130    LDR     R1,   [R0]
131    ;VLDMIA  R1!, {D8-D15}
132    LDMFD   R1!, {R4-R12}
133    MSR     PSP,  R1
134
135    MSR     PRIMASK, R12
136    BX      LR
137
138    END
139