gonzui


Format: Advanced Search

tkernel_2/kernel/tkernel/src/misc_calls.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 T-Engine Forum at 2014/09/10.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      misc_calls.c (T-Kernel/OS)
   18:  *      Other System Calls
   19:  */
   20: 
   21: #include "kernel.h"
   22: #include "task.h"
   23: #include "check.h"
   24: #include <sys/rominfo.h>
   25: 
   26: IMPORT const T_RVER kernel_version;
   27: 
   28: /*
   29:  * Refer system state
   30:  */
   31: SYSCALL ER _tk_ref_sys( T_RSYS *pk_rsys )
   32: {
   33:         if ( in_indp() ) {
   34:                 pk_rsys->sysstat = TSS_INDP;
   35:         } else {
   36:                 if ( in_qtsk() ) {
   37:                         pk_rsys->sysstat = TSS_QTSK;
   38:                 } else {
   39:                         pk_rsys->sysstat = TSS_TSK;
   40:                 }
   41:                 if ( in_loc() ) {
   42:                         pk_rsys->sysstat |= TSS_DINT;
   43:                 }
   44:                 if ( in_ddsp() ) {
   45:                         pk_rsys->sysstat |= TSS_DDSP;
   46:                 }
   47:         }
   48:         pk_rsys->runtskid = ( ctxtsk != NULL )? ctxtsk->tskid: 0;
   49:         pk_rsys->schedtskid = ( schedtsk != NULL )? schedtsk->tskid: 0;
   50: 
   51:         return E_OK;
   52: }
   53: 
   54: /*
   55:  * Refer version information
   56:  *      If there is no kernel version information,
   57:  *      set 0 in each information. (Do NOT cause errors.)
   58:  */
   59: #define RVER_PRNO_SIZE  (4)              /* T_RVER.prno[4] */
   60: SYSCALL ER _tk_ref_ver( T_RVER *pk_rver )
   61: {
   62:         INT    info[RVER_PRNO_SIZE];      /* fit max number of T_RVER member */
   63:         INT    n;                 /* item number in SYSCONF */
   64: 
   65:         MEMCPY(pk_rver, &kernel_version, sizeof(T_RVER));
   66: 
   67:         if ( (n = _tk_get_cfn(SCTAG_MAKER, info, 1)) >= 1 ) {
   68:                 pk_rver->maker = (UH)info[0]; /* OS manufacturer */
   69:         }
   70:         if ( (n = _tk_get_cfn(SCTAG_PRODUCTID, info, 1)) >= 1) {
   71:                 pk_rver->prid = (UH)info[0];  /* OS identification number */
   72:         }
   73:         if ( (n = _tk_get_cfn(SCTAG_SPECVER, info, 1)) >= 1) {
   74:                 pk_rver->spver = (UH)info[0]; /* Specification version */
   75:         }
   76:         if ( (n = _tk_get_cfn(SCTAG_PRODUCTVER, info, 1)) >= 1) {
   77:                 pk_rver->prver = (UH)info[0]; /* OS product version */
   78:         }
   79:         if ( (n = _tk_get_cfn(SCTAG_PRODUCTNO, info, RVER_PRNO_SIZE)) >= 1) {
   80:                 if (n > RVER_PRNO_SIZE) {
   81:                         n = RVER_PRNO_SIZE;
   82:                 }
   83:                 while (--n >= 0) {
   84:                         pk_rver->prno[n] = (UH)info[n];
   85:                 }                     /* Product number */
   86:         }
   87: 
   88:         return E_OK;
   89: }
   90: 
   91: /*
   92:  * Number of times for disabling power-saving mode switch
   93:  *      If it is 0, the mode switch is enabled.
   94:  */
   95: EXPORT UINT     lowpow_discnt = 0;
   96: 
   97: #define LOWPOW_LIMIT    0x7fff             /* Maximum number for disabling */
   98: 
   99: /*
  100:  * Set Power-saving mode
  101:  */
  102: SYSCALL ER _tk_set_pow( UINT pwmode )
  103: {
  104: IMPORT  void     off_pow( void );    /* T-Kernel/SM */
  105:         ER     ercd = E_OK;
  106: 
  107:         CHECK_INTSK();
  108: 
  109:         BEGIN_CRITICAL_SECTION;
  110:         switch ( pwmode ) {
  111:           case TPW_DOSUSPEND:
  112:                 off_pow();
  113:                 break;
  114: 
  115:           case TPW_DISLOWPOW:
  116:                 if ( lowpow_discnt >= LOWPOW_LIMIT ) {
  117:                         ercd = E_QOVR;
  118:                 } else {
  119:                         lowpow_discnt++;
  120:                 }
  121:                 break;
  122:           case TPW_ENALOWPOW:
  123:                 if ( lowpow_discnt <= 0 ) {
  124:                         ercd = E_OBJ;
  125:                 } else {
  126:                         lowpow_discnt--;
  127:                 }
  128:                 break;
  129: 
  130:           default:
  131:                 ercd = E_PAR;
  132:         }
  133:         END_CRITICAL_SECTION;
  134: 
  135:         return ercd;
  136: }
  137: 
  138: /* ------------------------------------------------------------------------ */
  139: /*
  140:  *      Debugger support function
  141:  */
  142: #if USE_DBGSPT
  143: 
  144: /*
  145:  * Hook routine address
  146:  */
  147: EXPORT FP hook_enterfn;
  148: EXPORT FP hook_leavefn;
  149: EXPORT FP hook_execfn;
  150: EXPORT FP hook_stopfn;
  151: EXPORT FP hook_ienterfn;
  152: EXPORT FP hook_ileavefn;
  153: 
  154: #if TA_GP
  155: EXPORT void *hook_svc_gp;
  156: EXPORT void *hook_dsp_gp;
  157: EXPORT void *hook_int_gp;
  158: #endif
  159: 
  160: /*
  161:  * Hook enable/disable setting
  162:  */
  163: IMPORT void hook_svc( void );
  164: IMPORT void unhook_svc( void );
  165: IMPORT void hook_dsp( void );
  166: IMPORT void unhook_dsp( void );
  167: IMPORT void hook_int( void );
  168: IMPORT void unhook_int( void );
  169: 
  170: /*
  171:  * Set/Cancel system call/extended SVC hook routine
  172:  */
  173: SYSCALL ER _td_hok_svc P1( CONST TD_HSVC *hsvc )
  174: {
  175:         BEGIN_DISABLE_INTERRUPT;
  176:         if ( hsvc == NULL ) { /* Cancel system call hook routine */
  177:                 /* Cancel */
  178:                 unhook_svc();
  179:         } else {
  180:                 /* Set */
  181:                 hook_enterfn = hsvc->enter;
  182:                 hook_leavefn = hsvc->leave;
  183: #if TA_GP
  184:                 hook_svc_gp = gp;
  185: #endif
  186:                 hook_svc();
  187:         }
  188:         END_DISABLE_INTERRUPT;
  189: 
  190:         return E_OK;
  191: }
  192: 
  193: /*
  194:  * Set/Cancel dispatcher hook routine */
  195: SYSCALL ER _td_hok_dsp P1( CONST TD_HDSP *hdsp )
  196: {
  197:         BEGIN_DISABLE_INTERRUPT;
  198:         if ( hdsp == NULL ) { /* Cancel dispatcher hook routine */
  199:                 /* Cancel */
  200:                 unhook_dsp();
  201:         } else {
  202:                 /* Set */
  203:                 hook_execfn = hdsp->exec;
  204:                 hook_stopfn = hdsp->stop;
  205: #if TA_GP
  206:                 hook_dsp_gp = gp;
  207: #endif
  208:                 hook_dsp();
  209:         }
  210:         END_DISABLE_INTERRUPT;
  211: 
  212:         return E_OK;
  213: }
  214: 
  215: /*
  216:  * Set/Cancel EIT handler hook routine
  217:  */
  218: SYSCALL ER _td_hok_int P1( CONST TD_HINT *hint )
  219: {
  220:         BEGIN_DISABLE_INTERRUPT;
  221:         if ( hint == NULL ) { /* Cancel interrupt handler hook routine */
  222:                 /* Cancel */
  223:                 unhook_int();
  224:         } else {
  225:                 /* Set */
  226:                 hook_ienterfn = hint->enter;
  227:                 hook_ileavefn = hint->leave;
  228: #if TA_GP
  229:                 hook_int_gp = gp;
  230: #endif
  231:                 hook_int();
  232:         }
  233:         END_DISABLE_INTERRUPT;
  234: 
  235:         return E_OK;
  236: }
  237: 
  238: /*
  239:  * Refer system state
  240:  */
  241: SYSCALL ER _td_ref_sys( TD_RSYS *pk_rsys )
  242: {
  243:         if ( in_indp() ) {
  244:                 pk_rsys->sysstat = TSS_INDP;
  245:         } else {
  246:                 if ( in_qtsk() ) {
  247:                         pk_rsys->sysstat = TSS_QTSK;
  248:                 } else {
  249:                         pk_rsys->sysstat = TSS_TSK;
  250:                 }
  251:                 if ( in_loc() ) {
  252:                         pk_rsys->sysstat |= TSS_DINT;
  253:                 }
  254:                 if ( in_ddsp() ) {
  255:                         pk_rsys->sysstat |= TSS_DDSP;
  256:                 }
  257:         }
  258:         pk_rsys->runtskid = ( ctxtsk != NULL )? ctxtsk->tskid: 0;
  259:         pk_rsys->schedtskid = ( schedtsk != NULL )? schedtsk->tskid: 0;
  260: 
  261:         return E_OK;
  262: }
  263: 
  264: #endif /* USE_DBGSPT */