gonzui


Format: Advanced Search

tkernel_2/monitor/cmdsvc/src/svc.cbare sourcepermlink (0.04 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:  *      svc.c
   17:  *
   18:  *       service call
   19:  */
   20: 
   21: #include "cmdsvc.h"
   22: #include <sys/rominfo.h>
   23: 
   24: /*
   25:  * submodule extended SVC function
   26:  *       fno     function code
   27:  *       p1-p3 parameter(s)
   28:  *       er      returns error code
   29:  *       return value      if the function is handled, returns TRUE.
   30:  *                         if not, returns FALSE
   31:  */
   32: typedef BOOL (*ESVCFUNC)( W fno, W p1, W p2, W p3, W *er );
   33: 
   34: /*
   35:  * use weak attribute to call only the linked submodule.
   36:  * `weak' is a gcc-specific function and so other methods (using "#if" for example) need to be employed with other compilers.
   37:  *
   38:  */
   39: #ifdef __GNUC__
   40: #define WEAK    __attribute__ ((weak))
   41: #else
   42: #define WEAK
   43: #endif
   44: 
   45: /*
   46:  * submodule
   47:  */
   48: IMPORT BOOL memDiskSVC( W fno, W p1, W p2, W p3, W *er )        WEAK;
   49: IMPORT BOOL pciSVC( W fno, W p1, W p2, W p3, W *er )            WEAK;
   50: IMPORT BOOL usbSVC( W fno, W p1, W p2, W p3, W *er )            WEAK;
   51: IMPORT BOOL sysExtSVC( W fno, W p1, W p2, W p3, W *er )         WEAK;
   52: 
   53: /*
   54:  * calling submodule extended SVC function
   55:  */
   56: LOCAL BOOL callSubModuleSVC( ESVCFUNC func, W fno, W p1, W p2, W p3, W *er )
   57: {
   58:         if ( func == NULL ) return FALSE;
   59: 
   60:         return (*func)(fno, p1, p2, p3, er);
   61: }
   62: 
   63: #define CALL_ESVC(func)         callSubModuleSVC(func, fno, p1, p2, p3, &er)
   64: 
   65: /*
   66:  * extended service call processing
   67:  */
   68: LOCAL W procExtSVC( W fno, W p1, W p2, W p3 )
   69: {
   70:         W      er;
   71: 
   72:         switch ( fno ) {
   73:           case TMEF_PORTBPS:   /* debug port speed (bps) */
   74:                 er = ConPortBps;
   75:                 break;
   76: 
   77:           case TMEF_DIPSW:     /* DIPSW status */
   78:                 er = getDipSw();
   79:                 break;
   80: 
   81:           case TMEF_WROM:      /* Flash ROM write */
   82:                 er = writeFrom(p1, p2, p3, 0);
   83:                 break;
   84: 
   85:           default:
   86:                 CALL_ESVC(sysExtSVC) ||
   87:                 CALL_ESVC(usbSVC) ||
   88:                 CALL_ESVC(pciSVC) ||
   89:                 CALL_ESVC(memDiskSVC) ||
   90:                 (er = E_PAR);
   91:         }
   92: 
   93:         return er;
   94: }
   95: 
   96: /* ------------------------------------------------------------------------ */
   97: 
   98: /*
   99:  * service call
  100:  */
  101: EXPORT W procSVC( W fno, W p1, W p2, W p3, W p4 )
  102: {
  103:         W      er = E_OK;
  104:         W      n;
  105: 
  106:         switch ( fno ) {
  107:           case TM_MONITOR:     /* void tm_monitor( void ) */
  108:                 procCommand(NULL, 0);
  109:                 break;
  110: 
  111:           case TM_GETCHAR:     /* INT      tm_getchar( INT wait ) */
  112:                 er = getChar(p1);
  113:                 break;
  114: 
  115:           case TM_PUTCHAR:     /* INT      tm_putchar( INT c ) */
  116:                 er = putChar(p1);
  117:                 break;
  118: 
  119:           case TM_GETLINE:     /* INT      tm_getline( UB *buff ) */
  120:                 er = getString(wrkBuf);
  121:                 if ( er < 0 ) break;
  122:                 n = er + 1;
  123:                 if ( writeMem(p1, wrkBuf, n, 1) != n ) er = E_MACV;
  124:                 break;
  125: 
  126:           case TM_PUTSTRING:   /* INT    tm_putstring( const UB *buff ) */
  127:                 n = readMemStr(p1, wrkBuf, WRKBUF_SZ);
  128:                 if ( n < 0 ) { er = E_MACV; break; }
  129:                 er = putString(wrkBuf);
  130:                 break;
  131: 
  132:           case TM_COMMAND:     /* INT      tm_command( const UB *buff ) */
  133:                 n = readMemStr(p1, lineBuf, L_LINE);
  134:                 if ( n < 0 ) { er = E_MACV; break; }
  135:                 procCommand(( n == 0 )? NULL: lineBuf, 1);
  136:                 break;
  137: 
  138:           case TM_READDISK:
  139:           case TM_WRITEDISK:
  140:           case TM_INFODISK:
  141:                 /* INT tm_readdisk( const UB *dev, INT sec, INT nsec, void *addr )
  142:                  * INT tm_writedisk( const UB *dev, INT sec, INT nsec, void *addr )
  143:                  * INT tm_infodisk( const UB *dev, INT *blksz, INT *nblks )
  144:                  */
  145:                 n = readMemStr(p1, lineBuf, L_LINE);
  146:                 if ( n < 0 ) { er = E_MACV; break; }
  147: 
  148:                 if ( fno == TM_INFODISK ) {
  149:                         er = infoDisk(lineBuf, (UW*)p2, (UW*)p3);
  150:                 } else {
  151:                         n = ( fno == TM_READDISK )? 0: 1;
  152:                         er = rwDisk(lineBuf, p2, p3, (void*)p4, n);
  153:                 }
  154:                 break;
  155: 
  156:           case TM_EXIT:                /* void tm_exit( INT mode ) */
  157:                 sysExit(p1); /* do not return */
  158:                 break;
  159: 
  160:           case TM_EXTSVC:
  161:                 /* INT        tm_extsvc( INT fno, INT par1, INT par2, INT par3 ) */
  162:                 er = procExtSVC(p1, p2, p3, p4);
  163:                 break;
  164: 
  165:           default:
  166:                 er = E_PAR;
  167:         }
  168: 
  169:         return er;
  170: }