gonzui


Format: Advanced Search

mtkernel_3/kernel/sysdepend/cpu/core/rxv2/cpu_cntl.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: #include <sys/machine.h>
   15: #ifdef CPU_CORE_RXV2
   16: /*
   17:  *      cpu_cntl.c (RXv2)
   18:  *      CPU-Dependent Control
   19:  */
   20: #include "kernel.h"
   21: #include "../../../sysdepend.h"
   22: 
   23: #include "cpu_task.h"
   24: 
   25: 
   26: /* ------------------------------------------------------------------------ */
   27: /*
   28:  * Task independent status
   29:  */
   30: EXPORT  W        knl_taskindp = 0;
   31: 
   32: /* ------------------------------------------------------------------------ */
   33: /* Temporal stack 
   34:  *      used when 'dispatch_to_schedtsk' is called.
   35:  */
   36: 
   37: Noinit(EXPORT UB knl_tmp_stack[TMP_STACK_SIZE]);
   38: 
   39: #if defined(USE_FUNC_TK_SET_REG) || defined(USE_FUNC_TD_SET_REG)
   40: /* ------------------------------------------------------------------------ */
   41: /*
   42:  * Set task register contents (Used in tk_set_reg())
   43:  */
   44: EXPORT void knl_set_reg( TCB *tcb, CONST T_REGS *regs, CONST T_EIT *eit, CONST T_CREGS *cregs )
   45: {
   46:         SStackFrame    *ssp;
   47:         INT            i;
   48: 
   49:         ssp = (SStackFrame*)(( cregs != NULL )? cregs->ssp: tcb->tskctxb.ssp);
   50: 
   51:         if ( regs != NULL ) {
   52:                 for ( i = 0; i < 15; ++i ) {
   53:                         ssp->r[i] = regs->r[i];
   54:                 }
   55:         }
   56: 
   57:         if ( eit != NULL ) {
   58:                 ssp->spc  = eit->pc;
   59:                 ssp->spsw = eit->psw;
   60:         }
   61: 
   62:         if ( cregs != NULL ) {
   63:                 tcb->tskctxb.ssp = cregs->ssp;
   64:         }
   65: }
   66: #endif /* USE_FUNC_TK_SET_REG || USE_FUNC_TD_SET_REG */
   67: 
   68: #if defined(USE_FUNC_TK_GET_REG) || defined(USE_FUNC_TD_GET_REG)
   69: /* ------------------------------------------------------------------------ */
   70: /*
   71:  * Get task register contents (Used in tk_get_reg())
   72:  */
   73: EXPORT void knl_get_reg( TCB *tcb, T_REGS *regs, T_EIT *eit, T_CREGS *cregs )
   74: {
   75:         SStackFrame    *ssp;
   76:         INT            i;
   77: 
   78:         ssp = (SStackFrame*)tcb->tskctxb.ssp;
   79: 
   80:         if ( regs != NULL ) {
   81:                 for ( i = 0; i < 15; ++i ) {
   82:                         regs->r[i] = ssp->r[i];
   83:                 }
   84:         }
   85: 
   86:         if ( eit != NULL ) {
   87:                 eit->pc = ssp->spc;
   88:                 eit->psw = ssp->spsw;
   89:         }
   90: 
   91:         if ( cregs != NULL ) {
   92:                 cregs->ssp = tcb->tskctxb.ssp; 
   93:         }
   94: }
   95: #endif /* USE_FUNC_TK_GET_REG || USE_FUNC_TD_GET_REG */
   96: 
   97: #if NUM_COPROCESSOR > 0
   98: #ifdef USE_FUNC_TK_SET_CPR
   99: /* ------------------------------------------------------------------------ */
  100: /*
  101:  * Set Coprocessor registers contents (Used in tk_set_cpr())
  102:  */
  103: EXPORT ER knl_set_cpr( TCB *tcb, INT copno, CONST T_COPREGS *copregs )
  104: {
  105:         SStackFrame    *ssp;
  106:         ER             ercd;
  107: 
  108:         ssp = (SStackFrame*)tcb->tskctxb.ssp;
  109:         ercd = E_OK;
  110: 
  111:         switch(copno) {
  112:         case COPNO_0:          /* copno 0: FPU */
  113: #if     USE_FPU
  114:                 ssp->fpsw = copregs->cop0.fpsw;
  115: #else
  116:                 ercd = E_PAR;
  117: #endif
  118:                 break;
  119: 
  120:         case COPNO_1:                  /* copno 1: DSP */
  121: #if     USE_DSP
  122:                 ssp->acc0lo = copregs->cop1.acc0lo;
  123:                 ssp->acc0hi = copregs->cop1.acc0hi;
  124:                 ssp->acc0gu = copregs->cop1.acc0gu;
  125:                 ssp->acc1lo = copregs->cop1.acc1lo;
  126:                 ssp->acc1hi = copregs->cop1.acc1hi;
  127:                 ssp->acc1gu = copregs->cop1.acc1gu;
  128: #else
  129:                 ercd = E_PAR;
  130: #endif
  131:                 break;
  132:         default:
  133:                 ercd = E_PAR;
  134:         }
  135: 
  136:         return ercd;
  137: }
  138: #endif /* USE_FUNC_TK_SET_CPR */
  139: 
  140: #ifdef USE_FUNC_TK_GET_CPR
  141: /* ------------------------------------------------------------------------ */
  142: /*
  143:  * Get Coprocessor registers contents (Used in tk_get_cpr())
  144:  */
  145: EXPORT ER knl_get_cpr( TCB *tcb, INT copno, T_COPREGS *copregs)
  146: {
  147:         SStackFrame    *ssp;
  148:         ER             ercd;
  149: 
  150:         ssp = (SStackFrame*)tcb->tskctxb.ssp;
  151:         ercd = E_OK;
  152: 
  153:         switch (copno) {
  154:         case COPNO_0:                  /* copno 0: FPU */
  155: #if     USE_FPU
  156:                 copregs->cop0.fpsw = ssp->fpsw;
  157: #else
  158:                 ercd = E_PAR;
  159: #endif
  160:                 break;
  161: 
  162:         case COPNO_1:                  /* copno 1: DPS */
  163: #if     USE_DSP
  164:                 copregs->cop1.acc0lo = ssp->acc0lo;
  165:                 copregs->cop1.acc0hi = ssp->acc0hi;
  166:                 copregs->cop1.acc0gu = ssp->acc0gu;
  167:                 copregs->cop1.acc1lo = ssp->acc1lo;
  168:                 copregs->cop1.acc1hi = ssp->acc1hi;
  169:                 copregs->cop1.acc1gu = ssp->acc1gu;
  170: #else
  171:                 ercd = E_PAR;
  172: #endif
  173:                 break;
  174: 
  175:         default:
  176:                 ercd = E_PAR;
  177:                 break;
  178:         }
  179: 
  180:         return ercd;
  181: }
  182: #endif /* USE_FUNC_TK_GET_CPR */
  183: #endif /* NUM_COPROCESSOR > 0 */
  184: 
  185: /* ----------------------------------------------------------------------- */
  186: /*
  187:  *      Task dispatcher startup
  188:  */
  189: EXPORT void knl_force_dispatch( void )
  190: {
  191:         FP     fp = knl_dispatch_to_schedtsk;
  192: 
  193:         Asm("jsr %0" :: "r"(fp));      /* No return */
  194: }
  195: 
  196: EXPORT void knl_dispatch( void )
  197: {
  198:         knl_dispatch_entry();
  199: }
  200: 
  201: #endif /* CPU_CORE_RXV2 */