⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 except.c

📁 《嵌入式固件开发》一书的源码
💻 C
字号:
/*  * except.c: * * This code handles exceptions that are caught by the exception * vectors installed by the monitor. These exception vectors look for * user-installed exception handlers and call them if found. Otherwise * they issue a software interrupt (trap, SWI) which engages the * monitor. In goes like this: * * by Nick Patavalis (npat@inaccessnetworks.com) * * General notice:  *   This code is part of a boot-monitor package *   developed as a generic base platform for embedded system designs. *   As such, it is likely to be distributed to various projects *   beyond the control of the original author.  Please notify the *   author of any enhancements made or bugs found so that all may *   benefit from the changes.  In addition, notification back to the *   author will allow the new user to pick up changes that may have *   been made by other users after this version of the code was *   distributed. * * Micromonitor Author: Ed Sutter *   email: esutter@lucent.com (home: lesutter@worldnet.att.net) *   phone: 908-582-2351 (home: 908-889-5161)  * * $Id: except.c,v 1.5 2001/05/25 03:48:35 npat Exp $  */#include "config.h"#include "cpu.h"#include "genlib.h"#include "cpuio.h"#include "monapp.h"#include "stddefs.h"#include "except.h"#include "SA-1100.h"/***********************************************************************/ulong   ExceptionAddr;/***********************************************************************/static isrp_t usr_handle_und_instr;static isrp_t usr_handle_abt_prefetch;static isrp_t usr_handle_abt_data;static isrp_t irqtbl[32];/***********************************************************************/isrp_tvecconnect (isrp_t f, int lev0, int lev1){    isrp_t of = 0;    switch (lev0) {    case VEC_L0_UND:        of = usr_handle_und_instr;        usr_handle_und_instr = f;        break;    case VEC_L0_ABP:        of = usr_handle_abt_prefetch;        usr_handle_abt_prefetch = f;        break;    case VEC_L0_ABD:        of = usr_handle_abt_data;        usr_handle_abt_data = f;        break;    case VEC_L0_IRQ:    case VEC_L0_FIQ:        if (lev1 < 0 || lev1 > 31)            break;        of = irqtbl[lev1];        irqtbl[lev1] = f;        break;    default:        break;    }    return of;}/***********************************************************************/void handle_software_interrupt (ulong swinum){    volatile int i;    switch (swinum) {    case SWINUM_SHOWREGS:        showregs();        break;    case SWINUM_EXCEPTION:        monrestart(EXCEPTION);        break;    case SWINUM_BREAKPOINT:        monrestart(BREAKPOINT);        break;    case SWINUM_APP_EXIT:        monreset(APP_EXIT);        break;    case SWINUM_MONREBOOT:    default:        printf("Unrecognized SWI. Rebooting!\n");        for(i=0; i<LoopsPerSecond; i++);        monreboot(INITIALIZE);        break;    }}/***********************************************************************/voidhandle_undefined_instruction (ulong addr){    if (usr_handle_und_instr) {        (*usr_handle_und_instr)(addr);    } else {        ExceptionAddr = addr;        SWI_EXCEPTION;    }}    /***********************************************************************/voidhandle_abort_prefetch (ulong addr){    if (usr_handle_abt_prefetch) {        (*usr_handle_abt_prefetch)(addr);    } else {        ExceptionAddr = addr;        SWI_EXCEPTION;    }}/***********************************************************************/voidhandle_abort_data (ulong addr){    if (usr_handle_abt_data) {        (*usr_handle_abt_data)(addr);    } else {        ExceptionAddr = addr;        SWI_EXCEPTION;    }}/***********************************************************************/voidhandle_irq (ulong addr){    int i, untrapped = 0;    for (i=0 ; i < 32; i++)        if ( (ICFP & (1L << i)) ) {            if (irqtbl[i])                (*irqtbl[i])(i);            else                untrapped = 1;        }    for (i=0 ; i < 32; i++)        if ( (ICIP & (1L << i)) ) {            if (irqtbl[i])                (*irqtbl[i])(i);            else                untrapped = 1;        }    if ( untrapped ) {        ExceptionAddr = addr;        SWI_EXCEPTION;    }}/***********************************************************************/voidvinit(void){    int i;    usr_handle_und_instr = 0;    usr_handle_abt_prefetch = 0;    usr_handle_abt_data = 0;    for ( i=0; i < sizeof(irqtbl) / sizeof(*irqtbl); i++ ) {        irqtbl[i] = 0;    }        return;}/***********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -