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
40 /* ****************************************************************************
41 Function : ArchInit
42 Description : arch init function
43 Input : None
44 Output : None
45 Return : None
46 **************************************************************************** */
ArchInit(VOID)47 LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
48 {
49 HalHwiInit();
50 }
51
52 /* ****************************************************************************
53 Function : ArchSysExit
54 Description : Task exit function
55 Input : None
56 Output : None
57 Return : None
58 **************************************************************************** */
ArchSysExit(VOID)59 LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
60 {
61 (VOID)LOS_IntLock();
62 while (1) {
63 }
64 }
65
66 /* ****************************************************************************
67 Function : ArchTskStackInit
68 Description : Task stack initialization function
69 Input : taskID --- TaskID
70 stackSize --- Total size of the stack
71 topStack --- Top of task's stack
72 Output : None
73 Return : Context pointer
74 **************************************************************************** */
ArchTskStackInit(UINT32 taskID,UINT32 stackSize,VOID * topStack)75 LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
76 {
77 TaskContext *context = (TaskContext *)((UINTPTR)topStack + stackSize - sizeof(TaskContext));
78
79 #if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
80 (defined(__FPU_USED) && (__FPU_USED == 1U)))
81 context->S16 = 0xAA000010;
82 context->S17 = 0xAA000011;
83 context->S18 = 0xAA000012;
84 context->S19 = 0xAA000013;
85 context->S20 = 0xAA000014;
86 context->S21 = 0xAA000015;
87 context->S22 = 0xAA000016;
88 context->S23 = 0xAA000017;
89 context->S24 = 0xAA000018;
90 context->S25 = 0xAA000019;
91 context->S26 = 0xAA00001A;
92 context->S27 = 0xAA00001B;
93 context->S28 = 0xAA00001C;
94 context->S29 = 0xAA00001D;
95 context->S30 = 0xAA00001E;
96 context->S31 = 0xAA00001F;
97 context->S0 = 0xAA000000;
98 context->S1 = 0xAA000001;
99 context->S2 = 0xAA000002;
100 context->S3 = 0xAA000003;
101 context->S4 = 0xAA000004;
102 context->S5 = 0xAA000005;
103 context->S6 = 0xAA000006;
104 context->S7 = 0xAA000007;
105 context->S8 = 0xAA000008;
106 context->S9 = 0xAA000009;
107 context->S10 = 0xAA00000A;
108 context->S11 = 0xAA00000B;
109 context->S12 = 0xAA00000C;
110 context->S13 = 0xAA00000D;
111 context->S14 = 0xAA00000E;
112 context->S15 = 0xAA00000F;
113 context->FPSCR = 0x00000000;
114 context->NO_NAME = 0xAA000011;
115 #endif
116
117 context->uwR4 = 0x04040404L;
118 context->uwR5 = 0x05050505L;
119 context->uwR6 = 0x06060606L;
120 context->uwR7 = 0x07070707L;
121 context->uwR8 = 0x08080808L;
122 context->uwR9 = 0x09090909L;
123 context->uwR10 = 0x10101010L;
124 context->uwR11 = 0x11111111L;
125 context->uwPriMask = 0;
126 context->uwR0 = taskID;
127 context->uwR1 = 0x01010101L;
128 context->uwR2 = 0x02020202L;
129 context->uwR3 = 0x03030303L;
130 context->uwR12 = 0x12121212L;
131 context->uwLR = (UINT32)(UINTPTR)ArchSysExit;
132 context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
133 context->uwxPSR = 0x01000000L;
134
135 return (VOID *)context;
136 }
137
ArchSignalContextInit(VOID * stackPointer,VOID * stackTop,UINTPTR sigHandler,UINT32 param)138 VOID *ArchSignalContextInit(VOID *stackPointer, VOID *stackTop, UINTPTR sigHandler, UINT32 param)
139 {
140 UNUSED(stackTop);
141 TaskContext *context = (TaskContext *)((UINTPTR)stackPointer - sizeof(TaskContext));
142 (VOID)memset_s((VOID *)context, sizeof(TaskContext), 0, sizeof(TaskContext));
143
144 context->uwR0 = param;
145 context->uwPC = sigHandler;
146 context->uwxPSR = 0x01000000L; /* Thumb flag, always set 1 */
147
148 return (VOID *)context;
149 }
150
151 #if (LOSCFG_SECURE == 1)
HalUserTaskStackInit(TaskContext * context,UINTPTR taskEntry,UINTPTR stack)152 VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
153 {
154 context->uwR0 = stack;
155 context->uwPC = (UINT32)taskEntry;
156 context->uwxPSR = 0x01000000L; /* Thumb flag, always set 1 */
157 }
158 #endif
159
ArchStartSchedule(VOID)160 LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
161 {
162 (VOID)LOS_IntLock();
163 OsSchedStart();
164 HalStartToRun();
165 return LOS_OK; /* never return */
166 }
167
168