gonzui


Format: Advanced Search

mtkernel_3/kernel/tkernel/cpuctl.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.03
    4:  *
    5:  *    Copyright (C) 2006-2021 by Ken Sakamura.
    6:  *    This software is distributed under the T-License 2.2.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by TRON Forum(http://www.tron.org) at 2021/03/31.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: /*
   15:  *      cpuctl.c
   16:  *      CPU Control
   17:  */
   18: 
   19: #include "kernel.h"
   20: #include "task.h"
   21: #include "check.h"
   22: 
   23: 
   24: #ifdef USE_FUNC_TK_DIS_DSP
   25: /* ------------------------------------------------------------------------ */
   26: /*
   27:  * Dispatch disable
   28:  */
   29: SYSCALL ER tk_dis_dsp( void )
   30: {
   31:         CHECK_CTX(!in_loc());
   32: 
   33:         knl_dispatch_disabled = DDS_DISABLE;
   34: 
   35:         return E_OK;
   36: }
   37: #endif /* USE_FUNC_TK_DIS_DSP */
   38: 
   39: 
   40: /* ------------------------------------------------------------------------ */
   41: /*
   42:  * Dispatch enable
   43:  */
   44: #ifdef USE_FUNC_TK_ENA_DSP
   45: SYSCALL ER tk_ena_dsp( void )
   46: {
   47:         CHECK_CTX(!in_loc());
   48: 
   49:         knl_dispatch_disabled = DDS_ENABLE;
   50:         if ( knl_ctxtsk != knl_schedtsk ) {
   51:                 knl_dispatch();
   52:         }
   53: 
   54:         return E_OK;
   55: }
   56: #endif /* USE_FUNC_TK_ENA_DSP */
   57: 
   58: #if TK_SUPPORT_REGOPS
   59: #ifdef USE_FUNC_TK_SET_REG
   60: /* ------------------------------------------------------------------------ */
   61: /*
   62:  * Set task register contents
   63:  */
   64: SYSCALL ER tk_set_reg( ID tskid,
   65:                 CONST T_REGS *pk_regs, CONST T_EIT *pk_eit, CONST T_CREGS *pk_cregs )
   66: {
   67:         TCB            *tcb;
   68:         ER             ercd = E_OK;
   69: 
   70:         CHECK_INTSK();
   71:         CHECK_TSKID(tskid);
   72:         CHECK_NONSELF(tskid);
   73: 
   74:         tcb = get_tcb(tskid);
   75: 
   76:         BEGIN_CRITICAL_SECTION;
   77:         if ( tcb->state == TS_NONEXIST ) {
   78:                 ercd = E_NOEXS;
   79:         } else {
   80:                 knl_set_reg(tcb, pk_regs, pk_eit, pk_cregs);
   81:         }
   82:         END_CRITICAL_SECTION;
   83: 
   84:         return ercd;
   85: }
   86: #endif /* USE_FUNC_TK_SET_REG */
   87: 
   88: #ifdef USE_FUNC_TK_GET_REG
   89: /* ------------------------------------------------------------------------ */
   90: /*
   91:  * Get task register contents
   92:  */
   93: SYSCALL ER tk_get_reg( ID tskid, T_REGS *pk_regs, T_EIT *pk_eit, T_CREGS *pk_cregs )
   94: {
   95:         TCB            *tcb;
   96:         ER             ercd = E_OK;
   97: 
   98:         CHECK_INTSK();
   99:         CHECK_TSKID(tskid);
  100:         CHECK_NONSELF(tskid);
  101: 
  102:         tcb = get_tcb(tskid);
  103: 
  104:         BEGIN_CRITICAL_SECTION;
  105:         if ( tcb->state == TS_NONEXIST ) {
  106:                 ercd = E_NOEXS;
  107:         } else {
  108:                 knl_get_reg(tcb, pk_regs, pk_eit, pk_cregs);
  109:         }
  110:         END_CRITICAL_SECTION;
  111: 
  112:         return ercd;
  113: }
  114: 
  115: #endif /* USE_FUNC_TK_GET_REG */
  116: #endif /* TK_SUPPORT_REGOPS */
  117: 
  118: #if NUM_COPROCESSOR > 0
  119: #ifdef USE_FUNC_TK_SET_CPR
  120: /* ------------------------------------------------------------------------ */
  121: /*
  122:  * Set coprocessor registers contents
  123:  */
  124: SYSCALL ER tk_set_cpr( ID tskid, INT copno, CONST T_COPREGS *pk_copregs )
  125: {
  126:         TCB            *tcb;
  127:         ER             ercd = E_OK;
  128: 
  129:         CHECK_INTSK();
  130:         CHECK_TSKID(tskid);
  131:         CHECK_NONSELF(tskid);
  132: 
  133:         tcb = get_tcb(tskid);
  134:         if((copno < 0) || (copno >= NUM_COPROCESSOR)
  135:                 || !(tcb->tskatr & (TA_COP0 << copno))) {
  136:                 return E_PAR;
  137:         }
  138: 
  139:         BEGIN_CRITICAL_SECTION;
  140:         if ( tcb->state == TS_NONEXIST ) {
  141:                 ercd = E_NOEXS;
  142:         } else {
  143:                 ercd = knl_set_cpr(tcb, copno, pk_copregs);
  144:         }
  145:         END_CRITICAL_SECTION;
  146: 
  147:         return ercd;
  148: }
  149: #endif /* USE_FUNC_TK_SET_CPR */
  150: 
  151: #ifdef USE_FUNC_TK_GET_CPR
  152: /* ------------------------------------------------------------------------ */
  153: /*
  154:  * Get coprocessor registers contents
  155:  */
  156: SYSCALL ER tk_get_cpr( ID tskid, INT copno, T_COPREGS *pk_copregs )
  157: {
  158:         TCB            *tcb;
  159:         ER             ercd = E_OK;
  160: 
  161:         CHECK_INTSK();
  162:         CHECK_TSKID(tskid);
  163:         CHECK_NONSELF(tskid);
  164: 
  165:         tcb = get_tcb(tskid);
  166:         if((copno < 0) || (copno >= NUM_COPROCESSOR)
  167:                 || !(tcb->tskatr & (TA_COP0 << copno))) {
  168:                 return E_PAR;
  169:         }
  170: 
  171:         BEGIN_CRITICAL_SECTION;
  172:         if ( tcb->state == TS_NONEXIST ) {
  173:                 ercd = E_NOEXS;
  174:         } else {
  175:                 ercd = knl_get_cpr(tcb, copno, pk_copregs);
  176:         }
  177:         END_CRITICAL_SECTION;
  178: 
  179:         return ercd;
  180: }
  181: #endif /* USE_FUNC_TK_GET_CPR */
  182: #endif /* NUM_COPROCESSOR > 0 */
  183: 
  184: #if USE_DBGSPT
  185: /* ------------------------------------------------------------------------ */
  186: /*
  187:  *      Debugger support function
  188:  */
  189: 
  190: #if TK_SUPPORT_REGOPS
  191: #ifdef USE_FUNC_TD_SET_REG
  192: /* ------------------------------------------------------------------------ */
  193: /*
  194:  * Set task register
  195:  */
  196: SYSCALL ER td_set_reg( ID tskid, CONST T_REGS *regs, CONST T_EIT *eit, CONST T_CREGS *cregs )
  197: {
  198:         TCB    *tcb;
  199:         ER     ercd = E_OK;
  200: 
  201:         CHECK_TSKID(tskid);
  202: 
  203:         tcb = get_tcb(tskid);
  204:         if ( tcb == knl_ctxtsk ) {
  205:                 return E_OBJ;
  206:         }
  207: 
  208:         BEGIN_DISABLE_INTERRUPT;
  209:         if ( tcb->state == TS_NONEXIST ) {
  210:                 ercd = E_NOEXS;
  211:         } else {
  212:                 knl_set_reg(tcb, regs, eit, cregs);
  213:         }
  214:         END_DISABLE_INTERRUPT;
  215: 
  216:         return ercd;
  217: }
  218: #endif /* USE_FUNC_TD_SET_REG */
  219: 
  220: #ifdef USE_FUNC_TD_GET_REG
  221: /* ------------------------------------------------------------------------ */
  222: /*
  223:  * Get task register
  224:  */
  225: SYSCALL ER td_get_reg( ID tskid, T_REGS *regs, T_EIT *eit, T_CREGS *cregs )
  226: {
  227:         TCB    *tcb;
  228:         ER     ercd = E_OK;
  229: 
  230:         CHECK_TSKID(tskid);
  231: 
  232:         tcb = get_tcb(tskid);
  233:         if ( tcb == knl_ctxtsk ) {
  234:                 return E_OBJ;
  235:         }
  236: 
  237:         BEGIN_DISABLE_INTERRUPT;
  238:         if ( tcb->state == TS_NONEXIST ) {
  239:                 ercd = E_NOEXS;
  240:         } else {
  241:                 knl_get_reg(tcb, regs, eit, cregs);
  242:         }
  243:         END_DISABLE_INTERRUPT;
  244: 
  245:         return ercd;
  246: }
  247: #endif /* USE_FUNC_TD_GET_REG */
  248: #endif /* TK_SUPPORT_REGOPS */
  249: 
  250: #endif /* USE_DBGSPT */