• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2013-2020, 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#define OS_TASK_STATUS_RUNNING    0x0010
33#define VIC_TSPDR                 0XE000EC08
34
35#ifdef CPU_CK804
36.section .text
37.align  2
38.type HalStartToRun, %function
39.global HalStartToRun
40HalStartToRun:
41    lrw    r1, g_losTask
42    lrw    r2, g_losTask + 4
43
44    ldw    r0, (r2)
45
46    st.w   r0, (r1)
47    st.w   r0, (r2)
48
49    ldw    sp, (r0)
50
51    ldw    r0, (sp, 128)
52    mtcr   r0, epc
53    ldw    r0, (sp, 124)
54    mtcr   r0, epsr
55    ldw    r15, (sp, 56)
56    ldm    r0-r13, (sp)
57    addi     sp, 60
58    ldm      r16-r31, (sp)
59    addi     sp, 72
60
61    rte
62
63.align  2
64.type HalTaskContextSwitch, %function
65.global HalTaskContextSwitch
66HalTaskContextSwitch:
67    lrw    r0, VIC_TSPDR
68    bgeni  r1, 0
69    stw    r1, (r0)
70    nop
71    nop
72    nop
73    rts
74
75.align  2
76.type tspend_handler, %function
77.global tspend_handler
78tspend_handler:
79
80    subi   sp, 132
81    stm    r0-r13, (sp)
82    stw    r15, (sp, 56)
83    addi     r0, sp, 60
84    stm      r16-r31, (r0)
85    mfcr     r1, epsr
86    stw    r1, (sp, 124)
87    mfcr     r1, epc
88    stw    r1, (sp, 128)
89
90    jbsr    OsSchedTaskSwitch
91    bez     r0, ret_con
92
93    lrw    r2, g_losTask
94    ldw    r0, (r2)
95    stw    sp, (r0)
96
97    lrw    r3, g_losTask + 4
98    ldw    r0, (r3)
99    stw    r0, (r2)
100
101    ldw    sp, (r0)
102
103 ret_con:
104    ldw    r0, (sp, 128)
105    mtcr   r0, epc
106    ldw    r0, (sp, 124)
107    mtcr   r0, epsr
108    ldw    r15, (sp, 56)
109    ldm    r0-r13, (sp)
110    addi     sp, 60
111    ldm      r16-r31, (sp)
112
113    addi   sp, 72
114
115    rte
116
117#else
118.section .text
119.align  2
120.type HalStartToRun, %function
121.global HalStartToRun
122HalStartToRun:
123    lrw    r1, g_losTask
124    lrw    r2, g_losTask + 4
125
126    ldw    r0, (r2)
127
128    st.w   r0, (r1)
129    st.w   r0, (r2)
130
131    ldw    sp, (r0)
132
133    ldw    r0, (sp, 64)
134    mtcr   r0, epc
135    ldw    r0, (sp, 60)
136    mtcr   r0, epsr
137    ldw    r15, (sp, 56)
138    ldm    r0-r13, (sp)
139
140    rte
141
142.align  2
143.type HalTaskContextSwitch, %function
144.global HalTaskContextSwitch
145HalTaskContextSwitch:
146
147    subi   sp, 68
148    stm    r0-r13, (sp)
149    stw    r15, (sp, 56)
150    mfcr   r1, psr
151    stw    r1, (sp, 60)
152    stw    r15, (sp, 64)
153    lrw    r2, g_losTask
154    ldw    r0, (r2)
155    stw    sp, (r0)
156
157    lrw    r3, g_losTask + 4
158    ldw    r0, (r3)
159    stw    r0, (r2)
160
161    ldw    sp, (r0)
162    ldw    r0, (sp, 64)
163    mtcr   r0, epc
164    ldw    r0, (sp, 60)
165    mtcr   r0, epsr
166    ldw    r15, (sp, 56)
167    ldm    r0-r13, (sp)
168
169    addi   sp, 68
170
171    rte
172
173#endif
174