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_interrupt.h"
33 #include <stdarg.h>
34 #include "securec.h"
35 #include "los_context.h"
36 #include "los_arch_context.h"
37 #include "los_arch_interrupt.h"
38 #include "los_debug.h"
39 #include "los_hook.h"
40 #include "los_task.h"
41 #include "los_sched.h"
42 #include "los_memory.h"
43 #include "los_membox.h"
44
45 #define INT_OFFSET 6
46 #define PRI_OFF_PER_INT 8
47 #define PRI_PER_REG 4
48 #define PRI_OFF_IN_REG 6
49 #define PRI_BITS 2
50 #define PRI_HI 0
51 #define PRI_LOW 7
52 #define MASK_8_BITS 0xFF
53 #define MASK_32_BITS 0xFFFFFFFF
54 #define BYTES_OF_128_INT 4
55 #define TIM_INT_NUM 1
56
57 #define OS_USER_HWI_MIN 0
58 #define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1)
59 #define HWI_ALIGNSIZE 0x400
60
61 UINT32 g_intCount = 0;
62 CHAR g_trapStackBase[OS_TRAP_STACK_SIZE];
63
64 VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE;
65
HwiNumValid(UINT32 num)66 UINT32 HwiNumValid(UINT32 num)
67 {
68 return ((num) >= OS_USER_HWI_MIN) && ((num) <= OS_USER_HWI_MAX);
69 }
70
HalGetPsr(VOID)71 UINT32 HalGetPsr(VOID)
72 {
73 UINT32 intSave;
74 __asm__ volatile("mfcr %0, psr" : "=r" (intSave) : : "memory");
75 return intSave;
76 }
77
HalSetVbr(UINT32 intSave)78 UINT32 HalSetVbr(UINT32 intSave)
79 {
80 __asm__ volatile("mtcr %0, vbr" : : "r"(intSave) : "memory");
81 return intSave;
82 }
83
ArchIntLock(VOID)84 UINT32 ArchIntLock(VOID)
85 {
86 UINT32 intSave;
87 __asm__ __volatile__(
88 "mfcr %0, psr \n"
89 "psrclr ie"
90 : "=r"(intSave)
91 :
92 : "memory");
93 return intSave;
94 }
95
ArchIntUnLock(VOID)96 UINT32 ArchIntUnLock(VOID)
97 {
98 UINT32 intSave;
99 __asm__ __volatile__(
100 "mfcr %0, psr \n"
101 "psrset ie"
102 : "=r"(intSave)
103 :
104 : "memory");
105 return intSave;
106 }
107
ArchIntRestore(UINT32 intSave)108 VOID ArchIntRestore(UINT32 intSave)
109 {
110 __asm__ __volatile__("mtcr %0, psr" : : "r"(intSave));
111 }
112
ArchIntLocked(VOID)113 UINT32 ArchIntLocked(VOID)
114 {
115 UINT32 intSave;
116 __asm__ volatile("mfcr %0, psr" : "=r" (intSave) : : "memory");
117 return !(intSave & (1 << INT_OFFSET));
118 }
119
HwiUnmask(HWI_HANDLE_T hwiNum)120 STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
121 {
122 UINT32 intSave;
123
124 if (!HwiNumValid(hwiNum)) {
125 return LOS_ERRNO_HWI_NUM_INVALID;
126 }
127
128 intSave = LOS_IntLock();
129 VIC_REG->ISER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
130 VIC_REG->ISSR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
131 LOS_IntRestore(intSave);
132
133 return LOS_OK;
134 }
135
HwiSetPriority(HWI_HANDLE_T hwiNum,UINT8 priority)136 STATIC UINT32 HwiSetPriority(HWI_HANDLE_T hwiNum, UINT8 priority)
137 {
138 UINT32 intSave;
139
140 if (!HwiNumValid(hwiNum)) {
141 return LOS_ERRNO_HWI_NUM_INVALID;
142 }
143
144 if (!HWI_PRI_VALID(priority)) {
145 return OS_ERRNO_HWI_PRIO_INVALID;
146 }
147
148 intSave = LOS_IntLock();
149 VIC_REG->IPR[hwiNum / PRI_PER_REG] |= (((priority << PRI_OFF_IN_REG) << (hwiNum % PRI_PER_REG)) * PRI_OFF_PER_INT);
150 LOS_IntRestore(intSave);
151
152 return LOS_OK;
153 }
154
HwiMask(HWI_HANDLE_T hwiNum)155 STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum)
156 {
157 UINT32 intSave;
158
159 if (!HwiNumValid(hwiNum)) {
160 return LOS_ERRNO_HWI_NUM_INVALID;
161 }
162
163 intSave = LOS_IntLock();
164 VIC_REG->ICER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
165 LOS_IntRestore(intSave);
166
167 return LOS_OK;
168 }
169
HwiPending(HWI_HANDLE_T hwiNum)170 STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum)
171 {
172 UINT32 intSave;
173
174 if (!HwiNumValid(hwiNum)) {
175 return LOS_ERRNO_HWI_NUM_INVALID;
176 }
177
178 intSave = LOS_IntLock();
179 VIC_REG->ISPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
180 LOS_IntRestore(intSave);
181
182 return LOS_OK;
183 }
184
HwiClear(HWI_HANDLE_T hwiNum)185 STATIC UINT32 HwiClear(HWI_HANDLE_T hwiNum)
186 {
187 if (!HwiNumValid(hwiNum)) {
188 return LOS_ERRNO_HWI_NUM_INVALID;
189 }
190
191 VIC_REG->ICPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
192
193 return LOS_OK;
194 }
195
196 /* *
197 * @ingroup los_hwi
198 * Hardware interrupt form mapping handling function array.
199 */
200 STATIC HWI_PROC_FUNC __attribute__((aligned(HWI_ALIGNSIZE))) g_hwiForm[OS_VECTOR_CNT] = {0};
201
202 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
203
204 typedef struct {
205 HWI_PROC_FUNC pfnHandler;
206 VOID *pParm;
207 } HWI_HANDLER_FUNC;
208
209 /* *
210 * @ingroup los_hwi
211 * Hardware interrupt handler form mapping handling function array.
212 */
213 STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
214
215 /* *
216 * @ingroup los_hwi
217 * Set interrupt vector table.
218 */
OsSetVector(UINT32 num,HWI_PROC_FUNC vector,VOID * arg)219 VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
220 {
221 if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
222 g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)IrqEntry;
223 g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
224 g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
225 HwiUnmask(num);
226 }
227 }
228
229 #else
230 /* *
231 * @ingroup los_hwi
232 * Hardware interrupt handler form mapping handling function array.
233 */
234 STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0};
235
236 /* *
237 * @ingroup los_hwi
238 * Set interrupt vector table.
239 */
OsSetVector(UINT32 num,HWI_PROC_FUNC vector)240 VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
241 {
242 if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
243 g_hwiForm[num + OS_SYS_VECTOR_CNT] = IrqEntry;
244 g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
245 HwiUnmask(num);
246 }
247 }
248 #endif
249
250 /* ****************************************************************************
251 Function : HwiNumGet
252 Description : Get an interrupt number
253 Input : None
254 Output : None
255 Return : Interrupt Indexes number
256 **************************************************************************** */
HwiNumGet(VOID)257 STATIC UINT32 HwiNumGet(VOID)
258 {
259 return (HalGetPsr() >> PSR_VEC_OFFSET) & MASK_8_BITS;
260 }
261
262 HwiControllerOps g_archHwiOps = {
263 .triggerIrq = HwiPending,
264 .enableIrq = HwiUnmask,
265 .disableIrq = HwiMask,
266 .setIrqPriority = HwiSetPriority,
267 .getCurIrqNum = HwiNumGet,
268 .clearIrq = HwiClear,
269 };
270
ArchIsIntActive(VOID)271 inline UINT32 ArchIsIntActive(VOID)
272 {
273 return (g_intCount > 0);
274 }
275
276 /* ****************************************************************************
277 Function : HalHwiDefaultHandler
278 Description : default handler of the hardware interrupt
279 Input : None
280 Output : None
281 Return : None
282 **************************************************************************** */
HalHwiDefaultHandler(VOID)283 LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
284 {
285 PRINT_ERR("%s irqnum:%x\n", __FUNCTION__, HwiNumGet());
286 while (1) {}
287 }
288
HalPreInterruptHandler(UINT32 arg)289 WEAK VOID HalPreInterruptHandler(UINT32 arg)
290 {
291 (VOID)arg;
292 return;
293 }
294
HalAftInterruptHandler(UINT32 arg)295 WEAK VOID HalAftInterruptHandler(UINT32 arg)
296 {
297 (VOID)arg;
298 return;
299 }
300
301 /* ****************************************************************************
302 Function : HalInterrupt
303 Description : Hardware interrupt entry function
304 Input : None
305 Output : None
306 Return : None
307 **************************************************************************** */
HalInterrupt(VOID)308 LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
309 {
310 UINT32 hwiIndex;
311 UINT32 intSave;
312
313 intSave = LOS_IntLock();
314 g_intCount++;
315 LOS_IntRestore(intSave);
316
317 hwiIndex = HwiNumGet();
318 OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
319
320 HalPreInterruptHandler(hwiIndex);
321 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
322 if (g_hwiHandlerForm[hwiIndex].pfnHandler != 0) {
323 g_hwiHandlerForm[hwiIndex].pfnHandler((VOID *)g_hwiHandlerForm[hwiIndex].pParm);
324 }
325 #else
326 if (g_hwiHandlerForm[hwiIndex] != 0) {
327 g_hwiHandlerForm[hwiIndex]();
328 }
329 #endif
330
331 HalAftInterruptHandler(hwiIndex);
332
333 OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
334
335 intSave = LOS_IntLock();
336 g_intCount--;
337 HalIrqEndCheckNeedSched();
338 LOS_IntRestore(intSave);
339 }
340
341 /* ****************************************************************************
342 Function : ArchHwiCreate
343 Description : create hardware interrupt
344 Input : hwiNum --- hwi num to create
345 hwiPrio --- priority of the hwi
346 hwiMode --- unused
347 hwiHandler --- hwi handler
348 irqParam --- param of the hwi handler
349 Output : None
350 Return : LOS_OK on success or error code on failure
351 **************************************************************************** */
ArchHwiCreate(HWI_HANDLE_T hwiNum,HWI_PRIOR_T hwiPrio,HWI_MODE_T hwiMode,HWI_PROC_FUNC hwiHandler,HwiIrqParam * irqParam)352 LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
353 HWI_PRIOR_T hwiPrio,
354 HWI_MODE_T hwiMode,
355 HWI_PROC_FUNC hwiHandler,
356 HwiIrqParam *irqParam)
357 {
358 (VOID)hwiMode;
359 UINT32 intSave;
360
361 if (hwiHandler == NULL) {
362 return OS_ERRNO_HWI_PROC_FUNC_NULL;
363 }
364 if (hwiNum >= OS_HWI_MAX_NUM) {
365 return OS_ERRNO_HWI_NUM_INVALID;
366 }
367 if (g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] != 0) {
368 return OS_ERRNO_HWI_ALREADY_CREATED;
369 }
370 if (g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] != 0) {
371 return OS_ERRNO_HWI_ALREADY_CREATED;
372 }
373 if (hwiPrio > OS_HWI_PRIO_LOWEST) {
374 return OS_ERRNO_HWI_PRIO_INVALID;
375 }
376 intSave = LOS_IntLock();
377 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
378 if (irqParam != NULL) {
379 OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
380 } else {
381 OsSetVector(hwiNum, hwiHandler, NULL);
382 }
383 #else
384 (VOID)irqParam;
385 OsSetVector(hwiNum, hwiHandler);
386 #endif
387 HwiUnmask(hwiNum);
388 (VOID)HwiSetPriority(hwiNum, (UINT8)hwiPrio);
389 LOS_IntRestore(intSave);
390
391 return LOS_OK;
392 }
393
394 /* ****************************************************************************
395 Function : ArchHwiDelete
396 Description : Delete hardware interrupt
397 Input : hwiNum --- hwi num to delete
398 irqParam --- param of the hwi handler
399 Output : None
400 Return : LOS_OK on success or error code on failure
401 **************************************************************************** */
ArchHwiDelete(HWI_HANDLE_T hwiNum,HwiIrqParam * irqParam)402 LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
403 {
404 (VOID)irqParam;
405 UINT32 intSave;
406
407 if (hwiNum >= OS_HWI_MAX_NUM) {
408 return OS_ERRNO_HWI_NUM_INVALID;
409 }
410 HwiMask(hwiNum);
411 intSave = LOS_IntLock();
412 g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] = 0;
413 LOS_IntRestore(intSave);
414
415 return LOS_OK;
416 }
417
418 ExcInfo g_excInfo = {0};
419
420 #if (LOSCFG_KERNEL_PRINTF != 0)
OsExcTypeInfo(const ExcInfo * excInfo)421 STATIC VOID OsExcTypeInfo(const ExcInfo *excInfo)
422 {
423 CHAR *phaseStr[] = {"exc in init", "exc in task", "exc in hwi"};
424
425 PRINTK("Type = %d\n", excInfo->type);
426 PRINTK("ThrdPid = %d\n", excInfo->thrdPid);
427 PRINTK("Phase = %s\n", phaseStr[excInfo->phase]);
428 PRINTK("FaultAddr = 0x%x\n", excInfo->faultAddr);
429 }
430
OsExcCurTaskInfo(const ExcInfo * excInfo)431 STATIC VOID OsExcCurTaskInfo(const ExcInfo *excInfo)
432 {
433 PRINTK("Current task info:\n");
434 if (excInfo->phase == OS_EXC_IN_TASK) {
435 LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
436 PRINTK("Task name = %s\n", taskCB->taskName);
437 PRINTK("Task ID = %d\n", taskCB->taskID);
438 PRINTK("Task SP = 0x%x\n", (UINTPTR)taskCB->stackPointer);
439 PRINTK("Task ST = 0x%x\n", taskCB->topOfStack);
440 PRINTK("Task SS = 0x%x\n", taskCB->stackSize);
441 } else if (excInfo->phase == OS_EXC_IN_HWI) {
442 PRINTK("Exception occur in interrupt phase!\n");
443 } else {
444 PRINTK("Exception occur in system init phase!\n");
445 }
446 }
447
OsExcRegInfo(const ExcInfo * excInfo)448 STATIC VOID OsExcRegInfo(const ExcInfo *excInfo)
449 {
450 EXC_CONTEXT_S *excContext = excInfo->context;
451 PRINTK("Exception reg dump:\n");
452 PRINTK("R0 = 0x%x\n"
453 "R1 = 0x%x\n"
454 "R2 = 0x%x\n"
455 "R3 = 0x%x\n"
456 "R4 = 0x%x\n"
457 "R5 = 0x%x\n"
458 "R6 = 0x%x\n"
459 "R7 = 0x%x\n"
460 "R8 = 0x%x\n"
461 "R9 = 0x%x\n"
462 "R10 = 0x%x\n"
463 "R11 = 0x%x\n"
464 "R12 = 0x%x\n"
465 "R13 = 0x%x\n"
466 "R14 = 0x%x\n"
467 "R15 = 0x%x\n"
468 "EPSR = 0x%x\n"
469 "EPC = 0x%x\n",
470 excContext->R0, excContext->R1, excContext->R2, excContext->R3, excContext->R4, excContext->R5,
471 excContext->R6, excContext->R7, excContext->R8, excContext->R9, excContext->R10, excContext->R11,
472 excContext->R12, excContext->R13, excContext->R14, excContext->R15, excContext->EPSR,
473 excContext->EPC);
474 }
475
476 #if (LOSCFG_KERNEL_BACKTRACE == 1)
OsExcBackTraceInfo(const ExcInfo * excInfo)477 STATIC VOID OsExcBackTraceInfo(const ExcInfo *excInfo)
478 {
479 UINTPTR LR[LOSCFG_BACKTRACE_DEPTH] = {0};
480 UINT32 index;
481
482 OsBackTraceHookCall(LR, LOSCFG_BACKTRACE_DEPTH, 0, excInfo->context->R14);
483
484 PRINTK("----- backtrace start -----\n");
485 for (index = 0; index < LOSCFG_BACKTRACE_DEPTH; index++) {
486 if (LR[index] == 0) {
487 break;
488 }
489 PRINTK("backtrace %d -- lr = 0x%x\n", index, LR[index]);
490 }
491 PRINTK("----- backtrace end -----\n");
492 }
493 #endif
494
OsExcMemPoolCheckInfo(VOID)495 STATIC VOID OsExcMemPoolCheckInfo(VOID)
496 {
497 PRINTK("\r\nmemory pools check:\n");
498 #if (LOSCFG_PLATFORM_EXC == 1)
499 MemInfoCB memExcInfo[OS_SYS_MEM_NUM];
500 UINT32 errCnt;
501 UINT32 i;
502
503 (VOID)memset_s(memExcInfo, sizeof(memExcInfo), 0, sizeof(memExcInfo));
504
505 errCnt = OsMemExcInfoGet(OS_SYS_MEM_NUM, memExcInfo);
506 if (errCnt < OS_SYS_MEM_NUM) {
507 errCnt += OsMemboxExcInfoGet(OS_SYS_MEM_NUM - errCnt, memExcInfo + errCnt);
508 }
509
510 if (errCnt == 0) {
511 PRINTK("all memory pool check passed!\n");
512 return;
513 }
514
515 for (i = 0; i < errCnt; i++) {
516 PRINTK("pool num = %d\n", i);
517 PRINTK("pool type = %d\n", memExcInfo[i].type);
518 PRINTK("pool addr = 0x%x\n", memExcInfo[i].startAddr);
519 PRINTK("pool size = 0x%x\n", memExcInfo[i].size);
520 PRINTK("pool free = 0x%x\n", memExcInfo[i].free);
521 PRINTK("pool blkNum = %d\n", memExcInfo[i].blockSize);
522 PRINTK("pool error node addr = 0x%x\n", memExcInfo[i].errorAddr);
523 PRINTK("pool error node len = 0x%x\n", memExcInfo[i].errorLen);
524 PRINTK("pool error node owner = %d\n", memExcInfo[i].errorOwner);
525 }
526 #endif
527 UINT32 ret = LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR);
528 if (ret == LOS_OK) {
529 PRINTK("system heap memcheck over, all passed!\n");
530 }
531
532 PRINTK("memory pool check end!\n");
533 }
534 #endif
535
OsExcInfoDisplay(const ExcInfo * excInfo)536 STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo)
537 {
538 #if (LOSCFG_KERNEL_PRINTF != 0)
539 PRINTK("*************Exception Information**************\n");
540 OsExcTypeInfo(excInfo);
541 OsExcCurTaskInfo(excInfo);
542 OsExcRegInfo(excInfo);
543 #if (LOSCFG_KERNEL_BACKTRACE == 1)
544 OsExcBackTraceInfo(excInfo);
545 #endif
546 OsGetAllTskInfo();
547 OsExcMemPoolCheckInfo();
548 #endif
549 }
550
HalExcHandleEntry(EXC_CONTEXT_S * excBufAddr,UINT32 faultAddr)551 LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 faultAddr)
552 {
553 UINT16 tmpFlag = ((excBufAddr->EPSR >> PSR_VEC_OFFSET) & MASK_8_BITS);
554 g_excInfo.nestCnt++;
555 UINT32 excType = (HalGetPsr() >> PSR_VEC_OFFSET) & MASK_8_BITS;
556 g_excInfo.type = excType;
557
558 g_excInfo.faultAddr = faultAddr;
559
560 if (g_losTask.runTask != NULL) {
561 if (tmpFlag > 0) {
562 g_excInfo.phase = OS_EXC_IN_HWI;
563 g_excInfo.thrdPid = tmpFlag;
564 } else {
565 g_excInfo.phase = OS_EXC_IN_TASK;
566 g_excInfo.thrdPid = g_losTask.runTask->taskID;
567 }
568 } else {
569 g_excInfo.phase = OS_EXC_IN_INIT;
570 g_excInfo.thrdPid = OS_NULL_INT;
571 }
572 g_excInfo.context = excBufAddr;
573
574 OsDoExcHook(EXC_INTERRUPT);
575 OsExcInfoDisplay(&g_excInfo);
576 ArchSysExit();
577 }
578
579 /* stack protector */
580 WEAK UINT32 __stack_chk_guard = 0xd00a0dff;
581
__stack_chk_fail(VOID)582 WEAK VOID __stack_chk_fail(VOID)
583 {
584 /* __builtin_return_address is a builtin function, building in gcc */
585 LOS_Panic("stack-protector: Kernel stack is corrupted in: %x\n",
586 __builtin_return_address(0));
587 }
588
589 /* ****************************************************************************
590 Function : HalHwiInit
591 Description : initialization of the hardware interrupt
592 Input : None
593 Output : None
594 Return : None
595 **************************************************************************** */
HalHwiInit(VOID)596 LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
597 {
598 UINT32 i;
599
600 for (i = 1; i < OS_SYS_VECTOR_CNT; i++) {
601 g_hwiForm[i] = (HWI_PROC_FUNC)HandleEntry;
602 }
603
604 for (i = OS_SYS_VECTOR_CNT; i < (LOSCFG_PLATFORM_HWI_LIMIT + OS_SYS_VECTOR_CNT); i++) {
605 g_hwiForm[i] = (HWI_PROC_FUNC)IrqEntry;
606 }
607
608 HalSetVbr((UINT32)&g_hwiForm);
609 for (int i = 0; i < BYTES_OF_128_INT; i++) {
610 VIC_REG->IABR[i] = 0x0;
611 VIC_REG->ICPR[i] = MASK_32_BITS;
612 }
613 return;
614 }
615
616