• 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 #include "los_interrupt.h"
32 #include <stdarg.h>
33 #include "securec.h"
34 #include "los_context.h"
35 #include "los_arch_interrupt.h"
36 #include "los_debug.h"
37 #include "los_hook.h"
38 #include "los_task.h"
39 #include "los_sched.h"
40 #include "los_memory.h"
41 #include "los_membox.h"
42 
43 UINT32 g_intCount = 0;
44 
45 #ifdef __ICCARM__
46 #pragma location = ".data.vector"
47 #elif defined(__CC_ARM) || defined(__GNUC__)
48 #pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
49 LITE_OS_SEC_VEC
50 #endif
51 /* *
52  * @ingroup los_hwi
53  * Hardware interrupt form mapping handling function array.
54  */
55 STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
56 
57 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
58 
59 typedef struct {
60     HWI_PROC_FUNC pfnHandler;
61     VOID *pParm;
62 } HWI_HANDLER_FUNC;
63 
64 /* *
65  * @ingroup los_hwi
66  * Hardware interrupt handler form mapping handling function array.
67  */
68 STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
69 
70 /* *
71  * @ingroup los_hwi
72  * Set interrupt vector table.
73  */
OsSetVector(UINT32 num,HWI_PROC_FUNC vector,VOID * arg)74 VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
75 {
76     if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
77         g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt;
78         g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
79         g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
80     }
81 }
82 
83 #else
84 /* *
85  * @ingroup los_hwi
86  * hardware interrupt handler form mapping handling function array.
87  */
88 STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0};
89 
90 /* *
91  * @ingroup los_hwi
92  * Set interrupt vector table.
93  */
OsSetVector(UINT32 num,HWI_PROC_FUNC vector)94 VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
95 {
96     if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
97         g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt;
98         g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
99     }
100 }
101 #endif
102 
SysTick_Handler(VOID)103 WEAK VOID SysTick_Handler(VOID)
104 {
105     return;
106 }
107 
108 /* ****************************************************************************
109  Function    : HwiNumGet
110  Description : Get an interrupt number
111  Input       : None
112  Output      : None
113  Return      : Interrupt Indexes number
114  **************************************************************************** */
HwiNumGet(VOID)115 STATIC UINT32 HwiNumGet(VOID)
116 {
117     return __get_IPSR();
118 }
119 
HwiUnmask(HWI_HANDLE_T hwiNum)120 STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
121 {
122     if (hwiNum >= OS_HWI_MAX_NUM) {
123         return OS_ERRNO_HWI_NUM_INVALID;
124     }
125 
126     NVIC_EnableIRQ((IRQn_Type)hwiNum);
127 
128     return LOS_OK;
129 }
130 
HwiMask(HWI_HANDLE_T hwiNum)131 STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum)
132 {
133     if (hwiNum >= OS_HWI_MAX_NUM) {
134         return OS_ERRNO_HWI_NUM_INVALID;
135     }
136 
137     NVIC_DisableIRQ((IRQn_Type)hwiNum);
138 
139     return LOS_OK;
140 }
141 
HwiSetPriority(HWI_HANDLE_T hwiNum,UINT8 priority)142 STATIC UINT32 HwiSetPriority(HWI_HANDLE_T hwiNum, UINT8 priority)
143 {
144     if (hwiNum >= OS_HWI_MAX_NUM) {
145         return OS_ERRNO_HWI_NUM_INVALID;
146     }
147 
148     if (priority > OS_HWI_PRIO_LOWEST) {
149         return OS_ERRNO_HWI_PRIO_INVALID;
150     }
151 
152     NVIC_SetPriority((IRQn_Type)hwiNum, priority);
153 
154     return LOS_OK;
155 }
156 
HwiPending(HWI_HANDLE_T hwiNum)157 STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum)
158 {
159     if (hwiNum >= OS_HWI_MAX_NUM) {
160         return OS_ERRNO_HWI_NUM_INVALID;
161     }
162 
163     NVIC_SetPendingIRQ((IRQn_Type)hwiNum);
164 
165     return LOS_OK;
166 }
167 
HwiClear(HWI_HANDLE_T hwiNum)168 STATIC UINT32 HwiClear(HWI_HANDLE_T hwiNum)
169 {
170     if (hwiNum >= OS_HWI_MAX_NUM) {
171         return OS_ERRNO_HWI_NUM_INVALID;
172     }
173 
174     NVIC_ClearPendingIRQ((IRQn_Type)hwiNum);
175 
176     return LOS_OK;
177 }
178 
179 HwiControllerOps g_archHwiOps = {
180     .enableIrq      = HwiUnmask,
181     .disableIrq     = HwiMask,
182     .setIrqPriority = HwiSetPriority,
183     .getCurIrqNum   = HwiNumGet,
184     .triggerIrq     = HwiPending,
185     .clearIrq       = HwiClear,
186 };
187 
ArchIsIntActive(VOID)188 inline UINT32 ArchIsIntActive(VOID)
189 {
190     return (g_intCount > 0);
191 }
192 /* ****************************************************************************
193  Function    : HalHwiDefaultHandler
194  Description : default handler of the hardware interrupt
195  Input       : None
196  Output      : None
197  Return      : None
198  **************************************************************************** */
HalHwiDefaultHandler(VOID)199 LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
200 {
201     PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
202     while (1) {}
203 }
204 
HalPreInterruptHandler(UINT32 arg)205 WEAK VOID HalPreInterruptHandler(UINT32 arg)
206 {
207     (VOID)arg;
208     return;
209 }
210 
HalAftInterruptHandler(UINT32 arg)211 WEAK VOID HalAftInterruptHandler(UINT32 arg)
212 {
213     (VOID)arg;
214     return;
215 }
216 
217 /* ****************************************************************************
218  Function    : HalInterrupt
219  Description : Hardware interrupt entry function
220  Input       : None
221  Output      : None
222  Return      : None
223  **************************************************************************** */
HalInterrupt(VOID)224 LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
225 {
226     UINT32 hwiIndex;
227     UINT32 intSave;
228 
229 #if (LOSCFG_KERNEL_RUNSTOP == 1)
230     SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk);
231 #endif
232 
233     intSave = LOS_IntLock();
234     g_intCount++;
235     LOS_IntRestore(intSave);
236 
237     hwiIndex = HwiNumGet();
238 
239     OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
240 
241     HalPreInterruptHandler(hwiIndex);
242 
243 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
244     if (g_hwiHandlerForm[hwiIndex].pfnHandler != 0) {
245         g_hwiHandlerForm[hwiIndex].pfnHandler((VOID *)g_hwiHandlerForm[hwiIndex].pParm);
246     }
247 #else
248     if (g_hwiHandlerForm[hwiIndex] != 0) {
249         g_hwiHandlerForm[hwiIndex]();
250     }
251 #endif
252 
253     HalAftInterruptHandler(hwiIndex);
254 
255     OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
256 
257     intSave = LOS_IntLock();
258     g_intCount--;
259     LOS_IntRestore(intSave);
260 }
261 
262 /* ****************************************************************************
263  Function    : ArchHwiCreate
264  Description : create hardware interrupt
265  Input       : hwiNum   --- hwi num to create
266                hwiPrio  --- priority of the hwi
267                hwiMode  --- unused
268                hwiHandler --- hwi handler
269                irqParam --- param of the hwi handler
270  Output      : None
271  Return      : LOS_OK on success or error code on failure
272  **************************************************************************** */
ArchHwiCreate(HWI_HANDLE_T hwiNum,HWI_PRIOR_T hwiPrio,HWI_MODE_T hwiMode,HWI_PROC_FUNC hwiHandler,HwiIrqParam * irqParam)273 LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
274                                            HWI_PRIOR_T hwiPrio,
275                                            HWI_MODE_T hwiMode,
276                                            HWI_PROC_FUNC hwiHandler,
277                                            HwiIrqParam *irqParam)
278 {
279     (VOID)hwiMode;
280     UINT32 intSave;
281 
282     if (hwiHandler == NULL) {
283         return OS_ERRNO_HWI_PROC_FUNC_NULL;
284     }
285 
286     if (hwiNum >= OS_HWI_MAX_NUM) {
287         return OS_ERRNO_HWI_NUM_INVALID;
288     }
289 
290     if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
291         return OS_ERRNO_HWI_ALREADY_CREATED;
292     }
293 
294     if (hwiPrio > OS_HWI_PRIO_LOWEST) {
295         return OS_ERRNO_HWI_PRIO_INVALID;
296     }
297 
298     intSave = LOS_IntLock();
299 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
300     if (irqParam != NULL) {
301         OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
302     } else {
303         OsSetVector(hwiNum, hwiHandler, NULL);
304     }
305 #else
306     (VOID)irqParam;
307     OsSetVector(hwiNum, hwiHandler);
308 #endif
309     HwiUnmask((IRQn_Type)hwiNum);
310     HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
311 
312     LOS_IntRestore(intSave);
313 
314     return LOS_OK;
315 }
316 
317 /* ****************************************************************************
318  Function    : ArchHwiDelete
319  Description : Delete hardware interrupt
320  Input       : hwiNum   --- hwi num to delete
321                irqParam --- param of the hwi handler
322  Output      : None
323  Return      : LOS_OK on success or error code on failure
324  **************************************************************************** */
ArchHwiDelete(HWI_HANDLE_T hwiNum,HwiIrqParam * irqParam)325 LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
326 {
327     (VOID)irqParam;
328     UINT32 intSave;
329 
330     if (hwiNum >= OS_HWI_MAX_NUM) {
331         return OS_ERRNO_HWI_NUM_INVALID;
332     }
333 
334     HwiMask((IRQn_Type)hwiNum);
335 
336     intSave = LOS_IntLock();
337 
338     g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
339 
340     LOS_IntRestore(intSave);
341 
342     return LOS_OK;
343 }
344 
345 #define FAULT_STATUS_REG_BIT            32
346 #define USGFAULT                        (1 << 18)
347 #define BUSFAULT                        (1 << 17)
348 #define MEMFAULT                        (1 << 16)
349 #define DIV0FAULT                       (1 << 4)
350 #define UNALIGNFAULT                    (1 << 3)
351 #define HARDFAULT_IRQN                  (-13)
352 
353 ExcInfo g_excInfo = {0};
354 
355 UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = {
356     0, 0, 0, 0, 0, 0, OS_EXC_UF_DIVBYZERO, OS_EXC_UF_UNALIGNED,
357     0, 0, 0, 0, OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
358     0, 0, 0, OS_EXC_BF_STKERR, OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
359     0, 0, 0, OS_EXC_MF_MSTKERR, OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL
360 };
361 
362 #if (LOSCFG_KERNEL_PRINTF != 0)
OsExcNvicDump(VOID)363 STATIC VOID OsExcNvicDump(VOID)
364 {
365 #define OS_NR_NVIC_EXC_DUMP_TYPES   7
366     UINT32 *base = NULL;
367     UINT32 len, i, j;
368     UINT32 rgNvicBases[OS_NR_NVIC_EXC_DUMP_TYPES] = {
369         OS_NVIC_SETENA_BASE, OS_NVIC_SETPEND_BASE, OS_NVIC_INT_ACT_BASE,
370         OS_NVIC_PRI_BASE, OS_NVIC_EXCPRI_BASE, OS_NVIC_SHCSR, OS_NVIC_INT_CTRL
371     };
372     UINT32 rgNvicLens[OS_NR_NVIC_EXC_DUMP_TYPES] = {
373         OS_NVIC_INT_ENABLE_SIZE, OS_NVIC_INT_PEND_SIZE, OS_NVIC_INT_ACT_SIZE,
374         OS_NVIC_INT_PRI_SIZE, OS_NVIC_EXCPRI_SIZE, OS_NVIC_SHCSR_SIZE,
375         OS_NVIC_INT_CTRL_SIZE
376     };
377     CHAR strRgEnable[] = "enable";
378     CHAR strRgPending[] = "pending";
379     CHAR strRgActive[] = "active";
380     CHAR strRgPriority[] = "priority";
381     CHAR strRgException[] = "exception";
382     CHAR strRgShcsr[] = "shcsr";
383     CHAR strRgIntCtrl[] = "control";
384     CHAR *strRgs[] = {
385         strRgEnable, strRgPending, strRgActive, strRgPriority,
386         strRgException, strRgShcsr, strRgIntCtrl
387     };
388 
389     PRINTK("\r\nOS exception NVIC dump:\n");
390     for (i = 0; i < OS_NR_NVIC_EXC_DUMP_TYPES; i++) {
391         base = (UINT32 *)rgNvicBases[i];
392         len = rgNvicLens[i];
393         PRINTK("interrupt %s register, base address: %p, size: 0x%x\n", strRgs[i], base, len);
394         len = (len >> 2); /* 2: Gets the next register offset */
395         for (j = 0; j < len; j++) {
396             PRINTK("0x%x ", *(base + j));
397             if ((j != 0) && ((j % 16) == 0)) { /* 16: print wrap line */
398                 PRINTK("\n");
399             }
400         }
401         PRINTK("\n");
402     }
403 }
404 
OsExcTypeInfo(const ExcInfo * excInfo)405 STATIC VOID OsExcTypeInfo(const ExcInfo *excInfo)
406 {
407     CHAR *phaseStr[] = {"exc in init", "exc in task", "exc in hwi"};
408 
409     PRINTK("Type      = %d\n", excInfo->type);
410     PRINTK("ThrdPid   = %d\n", excInfo->thrdPid);
411     PRINTK("Phase     = %s\n", phaseStr[excInfo->phase]);
412     PRINTK("FaultAddr = 0x%x\n", excInfo->faultAddr);
413 }
414 
OsExcCurTaskInfo(const ExcInfo * excInfo)415 STATIC VOID OsExcCurTaskInfo(const ExcInfo *excInfo)
416 {
417     PRINTK("Current task info:\n");
418     if (excInfo->phase == OS_EXC_IN_TASK) {
419         LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
420         PRINTK("Task name = %s\n", taskCB->taskName);
421         PRINTK("Task ID   = %d\n", taskCB->taskID);
422         PRINTK("Task SP   = %p\n", taskCB->stackPointer);
423         PRINTK("Task ST   = 0x%x\n", taskCB->topOfStack);
424         PRINTK("Task SS   = 0x%x\n", taskCB->stackSize);
425     } else if (excInfo->phase == OS_EXC_IN_HWI) {
426         PRINTK("Exception occur in interrupt phase!\n");
427     } else {
428         PRINTK("Exception occur in system init phase!\n");
429     }
430 }
431 
OsExcRegInfo(const ExcInfo * excInfo)432 STATIC VOID OsExcRegInfo(const ExcInfo *excInfo)
433 {
434     PRINTK("Exception reg dump:\n");
435     PRINTK("PC        = 0x%x\n", excInfo->context->uwPC);
436     PRINTK("LR        = 0x%x\n", excInfo->context->uwLR);
437     PRINTK("SP        = 0x%x\n", excInfo->context->uwSP);
438     PRINTK("R0        = 0x%x\n", excInfo->context->uwR0);
439     PRINTK("R1        = 0x%x\n", excInfo->context->uwR1);
440     PRINTK("R2        = 0x%x\n", excInfo->context->uwR2);
441     PRINTK("R3        = 0x%x\n", excInfo->context->uwR3);
442     PRINTK("R4        = 0x%x\n", excInfo->context->uwR4);
443     PRINTK("R5        = 0x%x\n", excInfo->context->uwR5);
444     PRINTK("R6        = 0x%x\n", excInfo->context->uwR6);
445     PRINTK("R7        = 0x%x\n", excInfo->context->uwR7);
446     PRINTK("R8        = 0x%x\n", excInfo->context->uwR8);
447     PRINTK("R9        = 0x%x\n", excInfo->context->uwR9);
448     PRINTK("R10       = 0x%x\n", excInfo->context->uwR10);
449     PRINTK("R11       = 0x%x\n", excInfo->context->uwR11);
450     PRINTK("R12       = 0x%x\n", excInfo->context->uwR12);
451     PRINTK("PriMask   = 0x%x\n", excInfo->context->uwPriMask);
452     PRINTK("xPSR      = 0x%x\n", excInfo->context->uwxPSR);
453 }
454 
455 #if (LOSCFG_KERNEL_BACKTRACE == 1)
OsExcBackTraceInfo(const ExcInfo * excInfo)456 STATIC VOID OsExcBackTraceInfo(const ExcInfo *excInfo)
457 {
458     UINTPTR LR[LOSCFG_BACKTRACE_DEPTH] = {0};
459     UINT32 index;
460 
461     OsBackTraceHookCall(LR, LOSCFG_BACKTRACE_DEPTH, 0, excInfo->context->uwSP);
462 
463     PRINTK("----- backtrace start -----\n");
464     for (index = 0; index < LOSCFG_BACKTRACE_DEPTH; index++) {
465         if (LR[index] == 0) {
466             break;
467         }
468         PRINTK("backtrace %d -- lr = 0x%x\n", index, LR[index]);
469     }
470     PRINTK("----- backtrace end -----\n");
471 }
472 #endif
473 
OsExcMemPoolCheckInfo(VOID)474 STATIC VOID OsExcMemPoolCheckInfo(VOID)
475 {
476     PRINTK("\r\nmemory pools check:\n");
477 #if (LOSCFG_PLATFORM_EXC == 1)
478     MemInfoCB memExcInfo[OS_SYS_MEM_NUM];
479     UINT32 errCnt;
480     UINT32 i;
481 
482     (VOID)memset_s(memExcInfo, sizeof(memExcInfo), 0, sizeof(memExcInfo));
483 
484     errCnt = OsMemExcInfoGet(OS_SYS_MEM_NUM, memExcInfo);
485     if (errCnt < OS_SYS_MEM_NUM) {
486         errCnt += OsMemboxExcInfoGet(OS_SYS_MEM_NUM - errCnt, memExcInfo + errCnt);
487     }
488 
489     if (errCnt == 0) {
490         PRINTK("all memory pool check passed!\n");
491         return;
492     }
493 
494     for (i = 0; i < errCnt; i++) {
495         PRINTK("pool num    = %d\n", i);
496         PRINTK("pool type   = %d\n", memExcInfo[i].type);
497         PRINTK("pool addr   = 0x%x\n", memExcInfo[i].startAddr);
498         PRINTK("pool size   = 0x%x\n", memExcInfo[i].size);
499         PRINTK("pool free   = 0x%x\n", memExcInfo[i].free);
500         PRINTK("pool blkNum = %d\n", memExcInfo[i].blockSize);
501         PRINTK("pool error node addr  = 0x%x\n", memExcInfo[i].errorAddr);
502         PRINTK("pool error node len   = 0x%x\n", memExcInfo[i].errorLen);
503         PRINTK("pool error node owner = %d\n", memExcInfo[i].errorOwner);
504     }
505 #endif
506     UINT32 ret = LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR);
507     if (ret == LOS_OK) {
508         PRINTK("system heap memcheck over, all passed!\n");
509     }
510 
511     PRINTK("memory pool check end!\n");
512 }
513 #endif
514 
OsExcInfoDisplay(const ExcInfo * excInfo)515 STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo)
516 {
517 #if (LOSCFG_KERNEL_PRINTF != 0)
518     PRINTK("*************Exception Information**************\n");
519     OsExcTypeInfo(excInfo);
520     OsExcCurTaskInfo(excInfo);
521     OsExcRegInfo(excInfo);
522 #if (LOSCFG_KERNEL_BACKTRACE == 1)
523     OsExcBackTraceInfo(excInfo);
524 #endif
525     OsGetAllTskInfo();
526     OsExcNvicDump();
527     OsExcMemPoolCheckInfo();
528 #endif
529 }
530 
HalExcHandleEntry(UINT32 excType,UINT32 faultAddr,UINT32 pid,EXC_CONTEXT_S * excBufAddr)531 LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr)
532 {
533     UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */
534     g_intCount++;
535     g_excInfo.nestCnt++;
536 
537     g_excInfo.type = excType & OS_NULL_SHORT;
538 
539     if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
540         g_excInfo.faultAddr = faultAddr;
541     } else {
542         g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
543     }
544     if (g_losTask.runTask != NULL) {
545         if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
546             g_excInfo.phase = OS_EXC_IN_HWI;
547             g_excInfo.thrdPid = pid;
548         } else {
549             g_excInfo.phase = OS_EXC_IN_TASK;
550             g_excInfo.thrdPid = g_losTask.runTask->taskID;
551         }
552     } else {
553         g_excInfo.phase = OS_EXC_IN_INIT;
554         g_excInfo.thrdPid = OS_NULL_INT;
555     }
556     if (excType & OS_EXC_FLAG_NO_FLOAT) {
557         g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
558     } else {
559         g_excInfo.context = excBufAddr;
560     }
561 
562     OsDoExcHook(EXC_INTERRUPT);
563     OsExcInfoDisplay(&g_excInfo);
564     ArchSysExit();
565 }
566 
567 /* ****************************************************************************
568  Function    : HalHwiInit
569  Description : initialization of the hardware interrupt
570  Input       : None
571  Output      : None
572  Return      : None
573  **************************************************************************** */
HalHwiInit(VOID)574 LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
575 {
576 #if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
577     UINT32 index;
578     g_hwiForm[0] = 0;             /* [0] Top of Stack */
579     g_hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
580     for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
581         g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
582     }
583     /* Exception handler register */
584     g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT]   = (HWI_PROC_FUNC)HalExcNMI;
585     g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT]        = (HWI_PROC_FUNC)HalExcHardFault;
586     g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
587     g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT]         = (HWI_PROC_FUNC)HalExcBusFault;
588     g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT]       = (HWI_PROC_FUNC)HalExcUsageFault;
589     g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT]           = (HWI_PROC_FUNC)HalExcSvcCall;
590     g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT]           = (HWI_PROC_FUNC)HalPendSV;
591     g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT]          = (HWI_PROC_FUNC)SysTick_Handler;
592 
593     /* Interrupt vector table location */
594     SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
595 #endif
596 #if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
597     NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
598 #endif
599 
600     /* Enable USGFAULT, BUSFAULT, MEMFAULT */
601     *(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
602 
603     /* Enable DIV 0 and unaligned exception */
604 #ifdef LOSCFG_ARCH_UNALIGNED_EXC
605     *(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
606 #else
607     *(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT);
608 #endif
609 
610     return;
611 }
612 
613