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 #include "los_context.h"
33 #include "securec.h"
34 #include "los_arch_context.h"
35 #include "los_arch_interrupt.h"
36 #include "los_task.h"
37 #include "los_sched.h"
38 #include "los_interrupt.h"
39 #include "los_debug.h"
40
41 #ifndef CPU_CK804
42 STATIC UINT32 g_sysNeedSched = FALSE;
43 #endif
44
45 /* ****************************************************************************
46 Function : ArchInit
47 Description : arch init function
48 Input : None
49 Output : None
50 Return : None
51 **************************************************************************** */
ArchInit(VOID)52 LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
53 {
54 HalHwiInit();
55 }
56
57 /* ****************************************************************************
58 Function : ArchSysExit
59 Description : Task exit function
60 Input : None
61 Output : None
62 Return : None
63 **************************************************************************** */
ArchSysExit(VOID)64 LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
65 {
66 (VOID)LOS_IntLock();
67 while (1) {
68 }
69 }
70
71 /* ****************************************************************************
72 Function : ArchTskStackInit
73 Description : Task stack initialization function
74 Input : taskID --- TaskID
75 stackSize --- Total size of the stack
76 topStack --- Top of task's stack
77 Output : None
78 Return : Context pointer
79 **************************************************************************** */
ArchTskStackInit(UINT32 taskID,UINT32 stackSize,VOID * topStack)80 LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
81 {
82 TaskContext *context = (TaskContext *)((UINTPTR)topStack + stackSize - sizeof(TaskContext));
83
84 context->R0 = taskID;
85 context->R1 = 0x01010101L;
86 context->R2 = 0x02020202L;
87 context->R3 = 0x03030303L;
88 context->R4 = 0x04040404L;
89 context->R5 = 0x05050505L;
90 context->R6 = 0x06060606L;
91 context->R7 = 0x07070707L;
92 context->R8 = 0x08080808L;
93 context->R9 = 0x09090909L;
94 context->R10 = 0x10101010L;
95 context->R11 = 0x11111111L;
96 context->R12 = 0x12121212L;
97 context->R13 = 0x13131313L;
98 #ifdef CPU_CK804
99 context->R15 = (UINT32)ArchSysExit;
100 context->R16 = 0x16161616L;
101 context->R17 = 0x17171717L;
102 context->R18 = 0x18181818L;
103 context->R19 = 0x19191919L;
104 context->R20 = 0x20202020L;
105 context->R21 = 0x21212121L;
106 context->R22 = 0x22222222L;
107 context->R23 = 0x23232323L;
108 context->R24 = 0x24242424L;
109 context->R25 = 0x25252525L;
110 context->R26 = 0x26262626L;
111 context->R27 = 0x27272727L;
112 context->R28 = 0x28282828L;
113 context->R29 = 0x29292929L;
114 context->R30 = 0x30303030L;
115 context->R31 = 0x31313131L;
116 context->EPSR = 0x80000340L;
117 #else
118 context->R15 = (UINT32)ArchSysExit;
119 context->EPSR = 0xe0000144L;
120 #endif
121 context->EPC = (UINT32)OsTaskEntry;
122 return (VOID *)context;
123 }
124
ArchStartSchedule(VOID)125 LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
126 {
127 (VOID)LOS_IntLock();
128 OsSchedStart();
129 HalStartToRun();
130 return LOS_OK; /* never return */
131 }
132
133 #ifndef CPU_CK804
HalIrqEndCheckNeedSched(VOID)134 VOID HalIrqEndCheckNeedSched(VOID)
135 {
136 if (g_sysNeedSched && g_taskScheduled && LOS_CHECK_SCHEDULE) {
137 ArchTaskSchedule();
138 }
139 }
140
ArchTaskSchedule(VOID)141 VOID ArchTaskSchedule(VOID)
142 {
143 UINT32 intSave;
144
145 if (OS_INT_ACTIVE) {
146 g_sysNeedSched = TRUE;
147 return;
148 }
149
150 intSave = LOS_IntLock();
151 g_sysNeedSched = FALSE;
152 BOOL isSwitch = OsSchedTaskSwitch();
153 if (isSwitch) {
154 HalTaskContextSwitch();
155 }
156 LOS_IntRestore(intSave);
157 return;
158 }
159 #else
ArchTaskSchedule(VOID)160 VOID ArchTaskSchedule(VOID)
161 {
162 HalTaskContextSwitch();
163 }
164 #endif
165
166