• 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 #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 /* ****************************************************************************
42  Function    : ArchInit
43  Description : arch init function
44  Input       : None
45  Output      : None
46  Return      : None
47  **************************************************************************** */
ArchInit(VOID)48 LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
49 {
50     HalHwiInit();
51 }
52 
53 /* ****************************************************************************
54  Function    : ArchSysExit
55  Description : Task exit function
56  Input       : None
57  Output      : None
58  Return      : None
59  **************************************************************************** */
ArchSysExit(VOID)60 LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
61 {
62     (VOID)LOS_IntLock();
63     while (1) {
64     }
65 }
66 
67 /* ****************************************************************************
68  Function    : ArchTskStackInit
69  Description : Task stack initialization function
70  Input       : taskID     --- TaskID
71                stackSize  --- Total size of the stack
72                topStack    --- Top of task's stack
73  Output      : None
74  Return      : Context pointer
75  **************************************************************************** */
ArchTskStackInit(UINT32 taskID,UINT32 stackSize,VOID * topStack)76 LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
77 {
78     TaskContext *context = (TaskContext *)((UINTPTR)topStack + stackSize - sizeof(TaskContext));
79     LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
80 
81     context->r0 = taskID;
82     context->r1 = 0x01010101L;
83     context->r2 = 0x02020202L;
84     context->r3 = 0x03030303L;
85     context->r4 = 0x04040404L;
86     context->r5 = 0x05050505L;
87     context->r6 = 0x06060606L;
88     context->r7 = 0x07070707L;
89     context->r8 = 0x08080808L;
90     context->r9 = 0x09090909L;
91     context->r10 = 0x10101010L;
92     context->r11 = 0x11111111L;
93     context->r12 = 0x12121212L;
94     context->sp = (UINTPTR)topStack + stackSize;
95     context->lr = (UINTPTR)ArchSysExit;
96 
97     if ((UINTPTR)taskCB->taskEntry & 0x01) {
98         context->pc = (UINTPTR)OsTaskEntryThumb;
99         context->spsr = PSR_MODE_SYS_THUMB; /* thumb mode */
100     } else {
101         context->pc = (UINTPTR)OsTaskEntryArm;
102         context->spsr = PSR_MODE_SYS_ARM;   /* arm mode */
103     }
104 
105     return (VOID *)context;
106 }
107 
ArchStartSchedule(VOID)108 LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
109 {
110     (VOID)LOS_IntLock();
111     OsSchedStart();
112     HalStartToRun();
113 
114     return LOS_OK; /* never return */
115 }
116 
ArchTaskSchedule(VOID)117 LITE_OS_SEC_TEXT_INIT VOID ArchTaskSchedule(VOID)
118 {
119     __asm__ __volatile__("swi 0");
120 }
121 
dmb(VOID)122 LITE_OS_SEC_TEXT_INIT VOID dmb(VOID)
123 {
124     __asm__ __volatile__("" : : : "memory");
125 }
126 
dsb(VOID)127 LITE_OS_SEC_TEXT_INIT VOID dsb(VOID)
128 {
129     __asm__ __volatile__("mcr p15, 0, %0, c7, c10, 4" : : "r"(0) : "memory");
130 }
131 
isb(VOID)132 LITE_OS_SEC_TEXT_INIT VOID isb(VOID)
133 {
134     __asm__ __volatile__("" : : : "memory");
135 }
136 
wfi(VOID)137 LITE_OS_SEC_TEXT_INIT VOID wfi(VOID)
138 {
139     __asm__ __volatile__("mcr p15, 0, %0, c7, c0, 4" : : "r"(0) : "memory");
140 }
141 
142