• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2  * Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved.
3  * Description : Exception HeadFile
4  * Author: Huawei LiteOS Team
5  * Create : 2022-12-20
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted provided that the following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  * conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14  * to endorse or promote products derived from this software without specific prior written
15  * permission.
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * --------------------------------------------------------------------------- */
28 
29 #ifndef _ARCH_EXCEPTION_H
30 #define _ARCH_EXCEPTION_H
31 
32 #include "arch/cpu.h"
33 
34 #ifndef __ASSEMBLER__
35 #include "los_typedef.h"
36 #include "arch/task.h"
37 #endif
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42 
43 /* Initial bit32 stack value. */
44 #define OS_STACK_INIT            0xCACACACA
45 /* Bit32 stack top magic number. */
46 #define OS_STACK_MAGIC_WORD      0xCCCCCCCC
47 
48 #define OS_EXC_STAGE_INIT_VALUE 0xFFFFFFFF
49 #define OS_EXC_STAGE_INIT       0
50 #define OS_EXC_STAGE_TASK       1
51 #define OS_EXC_STAGE_IRQ        2
52 #define OS_EXC_STAGE_EXC        3
53 
54 #ifndef __ASSEMBLER__
55 
56 extern UINTPTR __startup_stack_top;
57 extern UINTPTR __exc_stack_top;
58 extern UINTPTR __irq_stack_top;
59 extern UINTPTR __nmi_stack_top;
60 
61 typedef struct {
62     UINT32      ccause;
63     UINT32      mcause;
64     UINT32      mtval;
65     UINT32      gp;
66     TaskContext taskContext;
67 } ExcContext;
68 
69 typedef struct {
70     UINT16 phase;           /**< Exception occurrence phase: 0 indicates that the exception occurs during
71                              *   initialization, 1 indicates that the exception occurs during task, 2
72                              *   indicates that the exception occurs during interrupt, and 3 indicates that
73                              *   the exception occurs during exception.
74                              */
75     UINT16 type;            /**< Type of exception, refer to no. 1-19 listed above for exceptions */
76     UINT32 faultAddr;       /**< A precise address access error indicates the error access address where
77                              *   the exception occurred.
78                              */
79     UINT32 thrdPid;         /**< An exception occurs in the interrupt, indicating the interrupt number. An
80                              *   exception occurs in the task, indicating the task id, or 0xffffffff if it
81                              *   occurs during initialization
82                              */
83     UINT16 nestCnt;         /**< The number of nested exceptions, currently only support the first time the
84                              *   exception into the implementation of the registered hook function
85                              */
86     UINT16 reserved;        /**< Reserved */
87     ExcContext *context; /**< The hardware context at which an exception to an automatic stack floating point
88                              *   register occurs
89                              */
90 } ExcInfo;
91 
92 #define ArchGetFp() ({ \
93     UINTPTR _fpSave; \
94     __asm__ __volatile__("mv %0, s0" : "=r"(_fpSave)); \
95     _fpSave; \
96 })
97 
ArchHaltCpu(VOID)98 STATIC INLINE VOID ArchHaltCpu(VOID)
99 {
100     __asm__ __volatile__("ecall");
101 }
102 
103 extern VOID ArchBackTraceWithSp(const VOID *stackPointer);
104 extern VOID ArchBackTrace(VOID);
105 extern UINT32 ArchExcInit(VOID);
106 extern UINT32 ArchBackTraceGet(UINTPTR fp, UINTPTR *callChain, UINT32 maxDepth, UINT32 ignrDepth);
107 
108 typedef VOID (*EXC_PROC_FUNC)(UINT32, const ExcContext *);
109 extern UINT32 ArchSetExcHook(EXC_PROC_FUNC excHook);
110 extern UINT32 ArchSetExcUserHook(EXC_PROC_FUNC excHook);
111 typedef VOID (*NMI_PROC_FUNC)(const ExcContext *);
112 extern UINT32 ArchSetNMIHook(NMI_PROC_FUNC nmiHook);
113 #define LOS_ExcRegHook ArchSetExcHook
114 extern EXC_PROC_FUNC ArchGetExcHook(VOID);
115 extern NMI_PROC_FUNC ArchGetNMIHook(VOID);
116 #endif /* __ASSEMBLER__ */
117 
118 #ifdef __cplusplus
119 }
120 #endif /* __cplusplus */
121 
122 #endif /* _ARCH_EXCEPTION_H */
123