• 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    .equ    OS_PSR_THUMB,       0x20
33    .equ    OS_PSR_INT_DIS,     0xC0
34    .equ    OS_PSR_FIQ_DIS,     0x40
35    .equ    OS_PSR_IRQ_DIS,     0x80
36    .equ    OS_PSR_MODE_MASK,   0x1F
37    .equ    OS_PSR_MODE_USR,    0x10
38    .equ    OS_PSR_MODE_FIQ,    0x11
39    .equ    OS_PSR_MODE_IRQ,    0x12
40    .equ    OS_PSR_MODE_SVC,    0x13
41    .equ    OS_PSR_MODE_ABT,    0x17
42    .equ    OS_PSR_MODE_UND,    0x1B
43    .equ    OS_PSR_MODE_SYS,    0x1F
44
45    .global HalStartToRun
46    .global OsTaskEntryArm
47    .global OsTaskEntryThumb
48    .global HalExceptSwiHdl
49    .global HalExceptFiqHdl
50    .global HalExceptIrqHdl
51
52    .extern OsTaskEntry
53    .extern OsSchedTaskSwitch
54    .extern HalInterrupt
55    .extern g_losTask
56
57    .code 32
58    .text
59
60.macro SAVE_CONTEXT
61    STMFD   SP!, {R0}
62
63    MRS     R0, SPSR
64    AND     R0, R0, #OS_PSR_MODE_SYS
65    CMP     R0, #OS_PSR_MODE_SYS
66    BNE     1f
67
68    STMFD   SP!, {SP}^
69    LDMFD   SP!, {R0}
70
71    STMFD   R0!, {LR}
72    MOV     LR, R0
73    LDMFD   SP!, {R0}
74
75    STMFD   LR, {R0-R14}^
76
77    SUB     LR, LR, #60
78    MRS     R0, SPSR
79    STMFD   LR!, {R0}
80
81    LDR     R1, =g_losTask
82    LDR     R1, [R1]
83    STR     LR, [R1]
84    B       2f
85
861:
87    LDMFD   SP!, {R0}
88    STMFD   SP!, {R0-R12, LR}
89    MRS     R0, SPSR
90    STMFD   SP!, {R0}
91
922:
93.endm
94
95.macro RETSORE_CONTEXT
96    MRS     R0, SPSR
97    AND     R0, R0, #OS_PSR_MODE_SYS
98    CMP     R0, #OS_PSR_MODE_SYS
99    BNE     3f
100
101    LDR     R1, =g_losTask
102    LDR     R1, [R1]
103    LDR     LR, [R1]
104
105    LDMFD   LR!, {R0}
106    MSR     SPSR_cxsf, R0
107    LDMFD   LR, {R0-R14}^
108    ADD     LR, LR, #60
109    LDMFD   LR!, {PC}^
1103:
111    LDMFD   SP!, {R0}
112    MSR     SPSR_cxsf, R0
113    LDMFD   SP!, {R0-R12, LR}
114    MOVS    PC, LR
115.endm
116
117.macro TASK_SWITCH
118    MRS     R0, CPSR
119    ORR     R0, R0, #OS_PSR_INT_DIS
120    MSR     CPSR, R0
121    BLX     OsSchedTaskSwitch
122    CMP     R0, #0
123    BEQ     4f
124
125    LDR     R0, =g_losTask
126    LDR     R1, [R0, #4]
127    STR     R1, [R0]
128
1294:
130.endm
131
132HalStartToRun:
133    LDR     R1, =g_losTask
134    LDR     R0, [R1, #4]
135    LDR     LR, [R0]
136
137    LDMFD   LR!, {R0}
138    MSR     SPSR_cxsf, R0
139
140    LDMFD   LR, {R0-R14}^
141    ADD     LR, LR, #60
142    LDMFD   LR!, {PC}^
143
144HalExceptSwiHdl:
145    SAVE_CONTEXT
146
147    TASK_SWITCH
148
149    RETSORE_CONTEXT
150
151HalExceptFiqHdl:
152    SUB     LR, LR, #4
153    SAVE_CONTEXT
154
155    BLX     HalInterrupt
156
157    RETSORE_CONTEXT
158
159HalExceptIrqHdl:
160    SUB     LR, LR, #4
161
162    SAVE_CONTEXT
163
164    BLX     HalInterrupt
165
166    RETSORE_CONTEXT
167
168OsTaskEntryArm:
169    STMFD   SP!, {LR}
170    BL      OsTaskEntry
171    LDMFD   SP!, {LR}
172    BX      LR
173
174    .code 16
175    .text
176OsTaskEntryThumb:
177    PUSH    {LR}
178    BL      OsTaskEntry
179    POP     {R0}
180    MOV     LR, R0
181    BX      LR
182
183