Пример #1
0
/*
 *  ======== Exception_excHandler ========
 */
Void Exception_excHandler(UInt *excStack, UInt pc)
{
    Exception_ExcContext excContext, *excContextp;
    SizeT stackSize = 0;
    UInt8 *stack = NULL;
    UInt coreId = 0;

#if (ti_sysbios_BIOS_smpEnabled__D)
    coreId = Core_getId();
#endif

#if defined(ti_sysbios_family_arm_a8_intcps_Hwi_enableAsidTagging__D) && \
    (ti_sysbios_family_arm_a8_intcps_Hwi_enableAsidTagging__D)
    Mmu_switchContext(0, Mmu_getMmuTableAddr());
#elif defined(ti_sysbios_family_arm_gic_Hwi_enableAsidTagging__D) && \
    (ti_sysbios_family_arm_gic_Hwi_enableAsidTagging__D)
    Mmu_switchContext(0, Mmu_getFirstLevelTableAddr());
#endif

    Exception_module->excActive[coreId] = TRUE;

    if (Exception_module->excContext[coreId] == NULL) {
        Exception_module->excContext[coreId] = &excContext;
        excContextp = &excContext;
    }
    else {
        excContextp = Exception_module->excContext[coreId];
    }

    /* copy registers from stack to excContext */
    excContextp->r0  = (Ptr)excStack[8];        /* r0 */
    excContextp->r1  = (Ptr)excStack[9];        /* r1 */
    excContextp->r2  = (Ptr)excStack[10];       /* r2 */
    excContextp->r3  = (Ptr)excStack[11];       /* r3 */
    excContextp->r4  = (Ptr)excStack[12];       /* r4 */
    excContextp->r5  = (Ptr)excStack[13];       /* r5 */
    excContextp->r6  = (Ptr)excStack[14];       /* r6 */
    excContextp->r7  = (Ptr)excStack[15];       /* r7 */
    excContextp->r8  = (Ptr)excStack[16];       /* r8 */
    excContextp->r9  = (Ptr)excStack[17];       /* r9 */
    excContextp->r10 = (Ptr)excStack[18];       /* r10 */
    excContextp->r11 = (Ptr)excStack[19];       /* r11 */
    excContextp->r12 = (Ptr)excStack[20];       /* r12 */
    excContextp->ifar = (Ptr)excStack[4];       /* IFAR */
    excContextp->dfar = (Ptr)excStack[5];       /* DFAR */
    excContextp->ifsr = (Ptr)excStack[6];       /* IFSR */
    excContextp->dfsr = (Ptr)excStack[7];       /* DFSR */
    excContextp->sp  = (Ptr)excStack[1];        /* sp */
    excContextp->lr  = (Ptr)excStack[2];        /* lr */
    excContextp->pc  = (Ptr)pc;                 /* pc */
    excContextp->psr = (Ptr)excStack[0];        /* psr */

    excContextp->type = (Exception_Type)(excStack[3] &0x1f);    /* psr */

    excContextp->threadType = BIOS_getThreadType();

    switch (excContextp->threadType) {
        case BIOS_ThreadType_Task: {
            if (BIOS_taskEnabled == TRUE) {
                excContextp->threadHandle = (Ptr)Task_self();
                stack = (UInt8 *)(Task_self())->stack;
                stackSize = (Task_self())->stackSize;
            }
            break;
        }
        case BIOS_ThreadType_Swi: {
            if (BIOS_swiEnabled == TRUE) {
                excContextp->threadHandle = (Ptr)Swi_self();
                stack = STACK_BASE;
                stackSize = (SizeT)(&__STACK_SIZE);
            }
            break;
        }
        case BIOS_ThreadType_Hwi: {
                excContextp->threadHandle = NULL;
                stack = STACK_BASE;
                stackSize = (SizeT)(&__STACK_SIZE);
            break;
        }
        case BIOS_ThreadType_Main: {
                excContextp->threadHandle = NULL;
                stack = STACK_BASE;
                stackSize = (SizeT)(&__STACK_SIZE);
            break;
        }
    }

    excContextp->threadStackSize = stackSize;
    excContextp->threadStack = (Ptr)stack;

    /* copy thread's stack contents if user has provided a buffer */
    if (Exception_module->excStackBuffers[coreId] != NULL) {
        UInt8 *from, *to;
        from = stack;
        to = (UInt8 *)Exception_module->excStackBuffers[coreId];
        while (stackSize--) {
            *to++ = *from++;
        }
    }

    /* Force MAIN threadtype So we can safely call System_printf */

    BIOS_setThreadType(BIOS_ThreadType_Main);

    if (Exception_enableDecode == TRUE) {
        Exception_excDumpContext(pc);
    }

    /* Call user's exception hook */
    if (Exception_excHookFuncs[coreId] != NULL) {
        Exception_excHookFuncs[coreId](excContextp);
    }

    /* raise a corresponding Error */
    switch(excContextp->type) {

        case Exception_Type_Supervisor:
            Error_raise(0, Exception_E_swi, pc, excStack[2]);
            break;

        case Exception_Type_PreAbort:
            Error_raise(0, Exception_E_prefetchAbort, pc, excStack[2]);
            break;

        case Exception_Type_DataAbort:
            Error_raise(0, Exception_E_dataAbort, pc, excStack[2]);
            break;

        case Exception_Type_UndefInst:
            Error_raise(0, Exception_E_undefinedInstruction, pc, excStack[2]);
            break;
    }
}
Пример #2
0
/*
 *  ======== Exception_excHandler ========
 */
Void Exception_excHandler(UInt *excStack, UInt pc)
{
    Exception_ExcContext excContext, *excContextp;
    SizeT stackSize = 0;
    UInt8 *stack = NULL;

    Exception_module->excActive = TRUE;

    if (Exception_module->excContext == NULL) {
        Exception_module->excContext = &excContext;
        excContextp = &excContext;
    }
    else {
        excContextp = Exception_module->excContext;
    }

    /* copy registers from stack to excContext */
    excContextp->r0  = (Ptr)excStack[4];        /* r0 */
    excContextp->r1  = (Ptr)excStack[5];        /* r1 */
    excContextp->r2  = (Ptr)excStack[6];        /* r2 */
    excContextp->r3  = (Ptr)excStack[7];        /* r3 */
    excContextp->r4  = (Ptr)excStack[8];        /* r4 */
    excContextp->r5  = (Ptr)excStack[9];        /* r5 */
    excContextp->r6  = (Ptr)excStack[10];       /* r6 */
    excContextp->r7  = (Ptr)excStack[11];       /* r7 */
    excContextp->r8  = (Ptr)excStack[12];       /* r8 */
    excContextp->r9  = (Ptr)excStack[13];       /* r9 */
    excContextp->r10 = (Ptr)excStack[14];       /* r10 */
    excContextp->r11 = (Ptr)excStack[15];       /* r11 */
    excContextp->r12 = (Ptr)excStack[16];       /* r12 */
    excContextp->sp  = (Ptr)excStack[1];        /* sp */
    excContextp->lr  = (Ptr)excStack[2];        /* lr */
    excContextp->pc  = (Ptr)pc;         /* pc */
    excContextp->psr = (Ptr)excStack[0];        /* psr */

    excContextp->type = (Exception_Type)(excStack[3] &0x1f);    /* psr */

    excContextp->threadType = BIOS_getThreadType();

    switch (excContextp->threadType) {
    case BIOS_ThreadType_Task: {
        if (BIOS_taskEnabled == TRUE) {
            excContextp->threadHandle = (Ptr)Task_self();
            stack = (UInt8 *)(Task_self())->stack;
            stackSize = (Task_self())->stackSize;
        }
        break;
    }
    case BIOS_ThreadType_Swi: {
        if (BIOS_swiEnabled == TRUE) {
            excContextp->threadHandle = (Ptr)Swi_self();
            stack = STACK_BASE;
            stackSize = (SizeT)(&__STACK_SIZE);
        }
        break;
    }
    case BIOS_ThreadType_Hwi: {
        excContextp->threadHandle = NULL;
        stack = STACK_BASE;
        stackSize = (SizeT)(&__STACK_SIZE);
        break;
    }
    case BIOS_ThreadType_Main: {
        excContextp->threadHandle = NULL;
        stack = STACK_BASE;
        stackSize = (SizeT)(&__STACK_SIZE);
        break;
    }
    }

    excContextp->threadStackSize = stackSize;
    excContextp->threadStack = (Ptr)stack;

    /* copy thread's stack contents if user has provided a buffer */
    if (Exception_module->excStackBuffer != NULL) {
        UInt8 *from, *to;
        from = stack;
        to = (UInt8 *)Exception_module->excStackBuffer;
        while (stackSize--) {
            *to++ = *from++;
        }
    }

    /* Force MAIN threadtype So we can safely call System_printf */

    BIOS_setThreadType(BIOS_ThreadType_Main);

    if (Exception_enableDecode == TRUE) {
        Exception_excDumpContext(pc);
    }

    /* Call user's exception hook */
    if (Exception_excHookFunc != NULL) {
        Exception_excHookFunc(excContextp);
    }

    /* raise a corresponding Error */
    switch(excContextp->type) {

    case Exception_Type_Supervisor:
        Error_raise(0, Exception_E_swi, pc, excStack[2]);
        break;

    case Exception_Type_PreAbort:
        Error_raise(0, Exception_E_prefetchAbort, pc, excStack[2]);
        break;

    case Exception_Type_DataAbort:
        Error_raise(0, Exception_E_dataAbort, pc, excStack[2]);
        break;

    case Exception_Type_UndefInst:
        Error_raise(0, Exception_E_undefinedInstruction, pc, excStack[2]);
        break;
    }
}