gonzui


Format: Advanced Search

tkernel_2/monitor/hwdepend/tef_em1d/src/eitproc.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: 
   15: /*
   16:  *      eitproc.c
   17:  *
   18:  *       EIT processing
   19:  */
   20: 
   21: #include "sysdepend.h"
   22: #include <tk/sysdef.h>
   23: 
   24: /*
   25:  * vector information
   26:  */
   27: typedef struct vecinfo  VECINFO;
   28: struct vecinfo {
   29:         UW     vec;                        /* initial vector numer */
   30:         B      *msg;                         /* message */
   31: 
   32:         /* processing function
   33:          *           return value  1 : adjust PC by decrementing it by one instruction worth
   34:          *                         0 : PC needs no adjustment
   35:          */
   36:         W (*func)( const VECINFO*, UW vec, UW pc, UW cpsr );
   37: };
   38: 
   39: /* display message */
   40: LOCAL W vf_msg( const VECINFO *vi, UW vec, UW pc, UW cpsr )
   41: {
   42:         B      *msg = vi->msg;
   43:         B      opt;
   44: 
   45:         if ( msg == NULL ) return 0;
   46: 
   47:         /* if the first byte of the message is not a letter, treat it as option.
   48:          *       opt = 0 - 037 (the code prior to ' ' )
   49:          *       \020    PC is adjusted to the previous instruction's address
   50:          */
   51:         opt = 0;
   52:         if ( *msg < ' ' ) opt = *msg++;
   53: 
   54:         DSP_F5(S,"Exception ", D,vec, S," (", S,msg, CH,')');
   55: 
   56:         return ( opt & 020 )? 1: 0;
   57: }
   58: 
   59: /* undefined instruction */
   60: LOCAL W vf_undef( const VECINFO *vi, UW vec, UW pc, UW cpsr )
   61: {
   62:         if (cpsr & PSR_T) {
   63:                 DSP_F3(S,vi->msg, CH,' ', 04X,*((UH*)(pc - 2)));
   64:         } else {
   65:                 DSP_F3(S,vi->msg, CH,' ', 08X,*((UW*)(pc - 4)));
   66:         }
   67:         return 1;
   68: }
   69: 
   70: /* data abort */
   71: LOCAL W vf_dabort( const VECINFO *vi, UW vec, UW pc, UW cpsr )
   72: {
   73:         DSP_F1(S,vi->msg);
   74:         DSP_F4(S," ADDR: ", 08X,getCP15(6, 0), S," STAT: ", 08X,getCP15(5, 0));
   75:         return 0;
   76: }
   77: 
   78: /*
   79:  * vector information table
   80:  *       this has to be filled in the ascending order of the vector number
   81:  */
   82: LOCAL const VECINFO VecInfoTable[] = {
   83:   { 0,            "\020" "Undefined SWI",       vf_msg                },
   84:   { EIT_UNDEF,    "Undefined Instruction",      vf_undef     },
   85:   { EIT_IABORT,   "Prefetch Abort",             vf_msg             },
   86:   { EIT_DABORT,   "Data Abort",                 vf_dabort     },
   87:   { EIT_DABORT+1, "\020" "Undefined SWI",       vf_msg                },
   88: 
   89:   { EIT_FIQ,               "Undefined FIQ",             vf_msg  },
   90:   { EIT_IRQ(0),            "Undefined IRQ",             vf_msg  },
   91:   { EIT_GPIO(0),           "Undefined GPIO-INT",        vf_msg  },
   92:   { EIT_GPIO(127)+1,"\020" "Undefined SWI",             vf_msg  },
   93: 
   94:   { N_INTVEC, NULL, vf_msg }    /* terminating mark (the last vector number + 1) */
   95: };
   96: #define N_VECINFO       ( sizeof(VecInfoTable) / sizeof(VECINFO) )
   97: 
   98: /*
   99:  * EIT processing
  100:  *       *  return value   0 : monitor should keep on running
  101:  *                         1 : return from the interrupt handler
  102:  */
  103: EXPORT W procEIT( UW vec )
  104: {
  105:         const VECINFO  *vp;
  106:         UW     pc, cpsr;
  107:         W      i;
  108: 
  109:         pc = getCurPCX();
  110:         cpsr = getCurCPSR();
  111: 
  112:         /* machine-dependent interrupt processing */
  113:         i = procHwInt(vec);
  114:         if ( i == 2 ) return 1; /* exit from the interrupt handler immediately */
  115: 
  116:         if ( i == 0 ) {
  117:                 /* other EIT processing */
  118:                 for ( i = 1; i < N_VECINFO; ++i ) {
  119:                         if ( vec < VecInfoTable[i].vec ) break;
  120:                 }
  121:                 vp = &VecInfoTable[i-1];
  122:                 i = (*vp->func)(vp, vec, pc, cpsr);
  123:                 if ( i > 0 ) {
  124:                         /* PC is adjusted to the previous instruction's address */
  125:                         pc -= ( (cpsr & PSR_T) != 0 )? 2: 4;
  126:                 }
  127:         }
  128: 
  129:         DSP_F5(S,"\nPC: ", 08X,pc, S," CPSR: ", 08X,cpsr, CH,'\n');
  130: 
  131:         return 0;
  132: }