• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: 错误处理函数文件
14  */
15 #include "prt_sys_external.h"
16 #include "prt_task_external.h"
17 #include "prt_err_internal.h"
18 
19 OS_SEC_L4_BSS U32 g_normalErrorNo;
20 OS_SEC_L4_BSS U32 g_fatalErrorNo;
21 
22 /*
23  * 描述:设置致命错误码
24  */
OsFatalErrSet(U32 faltError)25 OS_SEC_ALW_INLINE INLINE void OsFatalErrSet(U32 faltError)
26 {
27     g_fatalErrorNo = faltError;
28 }
29 
OsErrRecordInCda(U32 errorNo)30 OS_SEC_L4_TEXT void OsErrRecordInCda(U32 errorNo)
31 {
32     g_normalErrorNo = errorNo;
33 }
34 
OsErrRecord(U32 errorNo)35 OS_SEC_ALW_INLINE INLINE void OsErrRecord(U32 errorNo)
36 {
37     enum SysThreadType curThreadType;
38     uintptr_t interruptSave;
39 
40     struct TagTskCb *taskCb = NULL;
41 
42     interruptSave = OsIntLock();
43     curThreadType = OsCurThreadType();
44     if (curThreadType == SYS_TASK) {
45         taskCb = GET_TCB_HANDLE(RUNNING_TASK->taskPid);
46         taskCb->lastErr = errorNo;
47     }
48 
49     OsIntRestore(interruptSave);
50 }
51 
OsErrHandle(const char * fileName,U32 lineNo,U32 errorNo,U32 paraLen,void * para)52 OS_SEC_L4_TEXT void OsErrHandle(const char *fileName, U32 lineNo, U32 errorNo, U32 paraLen, void *para)
53 {
54     OS_ERR_CALL_USR_HOOK(fileName, lineNo, errorNo, paraLen, para);
55 
56     /* 表示用户调用,回调用户钩子后返回 */
57     if (lineNo != OS_ERR_MAGIC_WORD) {
58         return;
59     }
60 
61     OsErrRecord(errorNo);
62 
63     /* 致命错误流程:记录trace、触发异常,高8bit为03的时候为致命错误 */
64     if ((errorNo & OS_ERROR_TYPE_MASK) == ERRTYPE_FATAL) {
65         OsFatalErrSet(errorNo);
66         /* 调用ill指令触发异常 */
67         OsAsmIll();
68     }
69 }
70 
71 /*
72  * 描述:错误处理函数
73  */
PRT_ErrHandle(const char * fileName,U32 lineNo,U32 errorNo,U32 paraLen,void * para)74 OS_SEC_L4_TEXT U32 PRT_ErrHandle(const char *fileName, U32 lineNo, U32 errorNo, U32 paraLen, void *para)
75 {
76     OsErrHandle(fileName, lineNo, errorNo, paraLen, para);
77 
78     return OS_OK;
79 }
80