1 /*
2 * Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2022 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_arch_context.h"
33 #include "los_arch_interrupt.h"
34 #include "los_arch_timer.h"
35 #include "los_task.h"
36 #include "los_sched.h"
37 #include "los_memory.h"
38 #include "soc_common.h"
39 #include "securec.h"
40
41
42 extern LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID);
43 extern LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID);
44
__wrap_ArchTskStackInit(UINT32 taskID,UINT32 stackSize,VOID * topStack)45 LITE_OS_SEC_TEXT_INIT VOID *__wrap_ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
46 {
47 TaskContext *context = (TaskContext *)((UINTPTR)topStack + stackSize - sizeof(TaskContext));
48 UINT32 *bottom;
49 bottom = (UINT32 *)context - (FPU_CONTEXT_SIZE); // reserve the space for FPU regs. REGBYTES = sizeof(UINT32);
50 memset_s(bottom, (FPU_CONTEXT_SIZE * sizeof(UINT32)), 0, (FPU_CONTEXT_SIZE * sizeof(UINT32)));
51
52 context->mstatus = READ_CSR(mstatus);
53 context->mstatus |= RISCV_MSTATUS_MPP | RISCV_MSTATUS_MPIE;
54
55 context->mepc = (UINT32)(UINTPTR)OsTaskEntry;
56 context->tp = TP_INIT_VALUE;
57 context->sp = SP_INIT_VALUE;
58 context->s11 = S11_INIT_VALUE;
59 context->s10 = S10_INIT_VALUE;
60 context->s9 = S9_INIT_VALUE;
61 context->s8 = S8_INIT_VALUE;
62 context->s7 = S7_INIT_VALUE;
63 context->s6 = S6_INIT_VALUE;
64 context->s5 = S5_INIT_VALUE;
65 context->s4 = S4_INIT_VALUE;
66 context->s3 = S3_INIT_VALUE;
67 context->s2 = S2_INIT_VALUE;
68 context->s1 = S1_INIT_VALUE;
69 context->s0 = FP_INIT_VALUE;
70 context->t6 = T6_INIT_VALUE;
71 context->t5 = T5_INIT_VALUE;
72 context->t4 = T4_INIT_VALUE;
73 context->t3 = T3_INIT_VALUE;
74 context->a7 = A7_INIT_VALUE;
75 context->a6 = A6_INIT_VALUE;
76 context->a5 = A5_INIT_VALUE;
77 context->a4 = A4_INIT_VALUE;
78 context->a3 = A3_INIT_VALUE;
79 context->a2 = A2_INIT_VALUE;
80 context->a1 = A1_INIT_VALUE;
81 context->a0 = taskID;
82 context->t2 = T2_INIT_VALUE;
83 context->t1 = T1_INIT_VALUE;
84 context->t0 = T0_INIT_VALUE;
85 context->ra = (UINT32)(UINTPTR)ArchSysExit;
86 return (VOID *)bottom;
87 }
88
89