gonzui


Format: Advanced Search

tkernel_2/kernel/sysdepend/cpu/em1d/cpu_task.hbare 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:  *      cpu_task.h (EM1-D512)
   17:  *      CPU-Dependent Task Start Processing
   18:  */
   19: 
   20: #ifndef _CPU_TASK_
   21: #define _CPU_TASK_
   22: 
   23: #include "cpu_insn.h"
   24: 
   25: /*
   26:  * System stack configuration at task startup
   27:  */
   28: typedef struct {
   29:         VW     r[12];              /* R0-R11 */
   30:         UW     taskmode;
   31:         void   *usp;             /* R13_usr */
   32:         void   *lr_usr;  /* R14_usr */
   33:         void   *lr_svc;  /* R14_svc */
   34:         VW     ip;         /* R12 */
   35:         void   *pc;              /* R15 */
   36:         VW     spsr_svc;
   37: } SStackFrame;
   38: 
   39: /*
   40:  * User stack configuration at task startup (only RNG 1-3)
   41:  */
   42: typedef struct {
   43:         /* Empty */
   44: } UStackFrame;
   45: 
   46: /*
   47:  * Size of system stack area destroyed by 'make_dormant()'
   48:  * In other words, the size of area required to write by 'setup_context().'
   49:  */
   50: #define DORMANT_STACK_SIZE      ( sizeof(VW) * 7 )   /* To 'taskmode' */
   51: 
   52: /*
   53:  * Size of area kept for special use from system stack
   54:  */
   55: #define RESERVE_SSTACK(tskatr)  0
   56: 
   57: /*
   58:  * Initial value for task startup
   59:  */
   60: #if USE_MMU
   61: #define INIT_PSR(rng)   ( ( (rng) == 0 )? PSR_SVC: \
   62:                           ( (rng) == 3 )? PSR_USR: PSR_SYS )
   63: #else
   64: #define INIT_PSR(rng)   ( ( (rng) == 0 )? PSR_SVC: PSR_SYS )
   65: #endif
   66: 
   67: #define INIT_TMF(rng)   ( TMF_PPL(rng) | TMF_CPL(rng) )
   68: 
   69: /*
   70:  * Switch task space
   71:  */
   72: Inline void change_space( void *uatb, INT lsid )
   73: {
   74:         UW     ttbr;
   75: 
   76:         /* if no task space to switch to is not specified, use system default. */
   77:         Asm("mrc p15, 0, %0, cr2, c0, 1": "=r"(ttbr)); /* TTBR1 */
   78:         if ( uatb != NULL ) {
   79:                 ttbr = (UW)uatb | (ttbr & 0x07f);
   80:         }
   81: 
   82:         /* To synchronize ASID and TTBR change, set ASID to a meaningless value temporarily. */
   83:         Asm("mcr p15, 0, %0, cr13, c0, 1":: "r"(0));   /* CONTEXTIDR */
   84:         ISB();
   85:         Asm("mcr p15, 0, %0, cr2,  c0, 0":: "r"(ttbr)); /* TTBR0 */
   86:         Asm("mcr p15, 0, %0, cr13, c0, 1":: "r"(lsid)); /* CONTEXTIDR */
   87:         ISB();
   88: }
   89: 
   90: /*
   91:  * Create stack frame for task startup
   92:  *      Call from 'make_dormant()'
   93:  */
   94: Inline void setup_context( TCB *tcb )
   95: {
   96:         SStackFrame    *ssp;
   97:         W              rng;
   98:         UW             pc, spsr;
   99: 
  100:         rng = (tcb->tskatr & TA_RNG3) >> 8;
  101:         ssp = tcb->isstack;
  102:         ssp--;
  103: 
  104:         spsr = INIT_PSR(rng);
  105:         pc = (UW)tcb->task;
  106:         if ( (pc & 1) != 0 ) {
  107:                 spsr |= PSR_T;                /* Thumb mode */
  108:         }
  109: 
  110:         /* CPU context initialization */
  111:         ssp->taskmode = INIT_TMF(rng); /* Initial taskmode */
  112:         ssp->spsr_svc = spsr;          /* Initial SR */
  113:         ssp->pc = (void*)(pc & ~0x00000001U);  /* Task startup address */
  114:         tcb->tskctxb.ssp = ssp;                /* System stack */
  115:         tcb->tskctxb.svc_ssp = NULL;   /* ssp when SVC is called */
  116: 
  117:         if ( rng > 0 ) {
  118:                 ssp->usp = tcb->istack;       /* User stack */
  119:         }
  120: }
  121: 
  122: /*
  123:  * Set task startup code
  124:  *      Called by 'tk_sta_tsk()' processing.
  125:  */
  126: Inline void setup_stacd( TCB *tcb, INT stacd )
  127: {
  128:         SStackFrame    *ssp = tcb->tskctxb.ssp;
  129: 
  130:         ssp->r[0] = stacd;
  131:         ssp->r[1] = (VW)tcb->exinf;
  132: }
  133: 
  134: /*
  135:  * Delete task contexts
  136:  */
  137: Inline void cleanup_context( TCB *tcb )
  138: {
  139: }
  140: 
  141: #endif /* _CPU_TASK_ */