gonzui


Format: Advanced Search

t2ex/t2ex_source/kernel/sysdepend_t2ex/cpu/em1d/cpu_task.hbare sourcepermlink (0.03 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T2EX Software Package
    4:  *
    5:  *    Copyright 2012 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 2012/12/12.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/04.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: /*
   15:  * This software package is available for use, modification, 
   16:  * and redistribution in accordance with the terms of the attached 
   17:  * T-License 2.x.
   18:  * If you want to redistribute the source code, you need to attach 
   19:  * the T-License 2.x document.
   20:  * There's no obligation to publish the content, and no obligation 
   21:  * to disclose it to the TRON Forum if you have modified the 
   22:  * software package.
   23:  * You can also distribute the modified source code. In this case, 
   24:  * please register the modification to T-Kernel traceability service.
   25:  * People can know the history of modifications by the service, 
   26:  * and can be sure that the version you have inherited some 
   27:  * modification of a particular version or not.
   28:  *
   29:  *    http://trace.tron.org/tk/?lang=en
   30:  *    http://trace.tron.org/tk/?lang=ja
   31:  *
   32:  * As per the provisions of the T-License 2.x, TRON Forum ensures that 
   33:  * the portion of the software that is copyrighted by Ken Sakamura or 
   34:  * the TRON Forum does not infringe the copyrights of a third party.
   35:  * However, it does not make any warranty other than this.
   36:  * DISCLAIMER: TRON Forum and Ken Sakamura shall not be held
   37:  * responsible for any consequences or damages caused directly or
   38:  * indirectly by the use of this software package.
   39:  *
   40:  * The source codes in bsd_source.tar.gz in this software package are 
   41:  * derived from NetBSD or OpenBSD and not covered under T-License 2.x.
   42:  * They need to be changed or redistributed according to the 
   43:  * representation of each source header.
   44:  */
   45: 
   46: /*
   47:  *      cpu_task.h (EM1-D512)
   48:  *      CPU-Dependent Task Start Processing
   49:  */
   50: 
   51: #ifndef _CPU_TASK_
   52: #define _CPU_TASK_
   53: 
   54: #include "cpu_insn.h"
   55: 
   56: /*
   57:  * System stack configuration at task startup
   58:  */
   59: typedef struct {
   60:         VW     r[12];              /* R0-R11 */
   61:         UW     taskmode;
   62:         void   *usp;             /* R13_usr */
   63:         void   *lr_usr;  /* R14_usr */
   64:         void   *lr_svc;  /* R14_svc */
   65:         VW     ip;         /* R12 */
   66:         void   *pc;              /* R15 */
   67:         VW     spsr_svc;
   68: } SStackFrame;
   69: 
   70: /*
   71:  * User stack configuration at task startup (only RNG 1-3)
   72:  */
   73: typedef struct {
   74:         /* Empty */
   75: } UStackFrame;
   76: 
   77: /*
   78:  * Size of system stack area destroyed by 'make_dormant()'
   79:  * In other words, the size of area required to write by 'setup_context().'
   80:  */
   81: #define DORMANT_STACK_SIZE      ( sizeof(VW) * 7 )   /* To 'taskmode' */
   82: 
   83: /*
   84:  * Size of area kept for special use from system stack
   85:  */
   86: #define RESERVE_SSTACK(tskatr)  0
   87: 
   88: /*
   89:  * Initial value for task startup
   90:  */
   91: #if USE_MMU
   92: #define INIT_PSR(rng)   ( ( (rng) == 0 )? PSR_SVC: \
   93:                           ( (rng) >= MMU_MIN_USER_LEVEL )? PSR_USR: PSR_SYS )
   94: #else
   95: #define INIT_PSR(rng)   ( ( (rng) == 0 )? PSR_SVC: PSR_SYS )
   96: #endif
   97: 
   98: #define INIT_TMF(rng)   ( TMF_PPL(rng) | TMF_CPL(rng) )
   99: 
  100: /*
  101:  * Switch task space
  102:  */
  103: Inline void change_space( void *uatb, INT lsid )
  104: {
  105:         UW     ttbr;
  106: 
  107:         /* if no task space to switch to is not specified, use system default. */
  108:         Asm("mrc p15, 0, %0, cr2, c0, 1": "=r"(ttbr)); /* TTBR1 */
  109:         if ( uatb != NULL ) {
  110:                 ttbr = (UW)uatb | (ttbr & 0x07f);
  111:         }
  112: 
  113:         /* To synchronize ASID and TTBR change, set ASID to a meaningless value temporarily. */
  114:         Asm("mcr p15, 0, %0, cr13, c0, 1":: "r"(0));   /* CONTEXTIDR */
  115:         ISB();
  116:         Asm("mcr p15, 0, %0, cr2,  c0, 0":: "r"(ttbr)); /* TTBR0 */
  117:         Asm("mcr p15, 0, %0, cr13, c0, 1":: "r"(lsid)); /* CONTEXTIDR */
  118:         ISB();
  119: }
  120: 
  121: /*
  122:  * Create stack frame for task startup
  123:  *      Call from 'make_dormant()'
  124:  */
  125: Inline void setup_context( TCB *tcb )
  126: {
  127:         SStackFrame    *ssp;
  128:         W              rng;
  129:         UW             pc, spsr;
  130: 
  131:         rng = (tcb->tskatr & TA_RNG3) >> 8;
  132:         ssp = tcb->isstack;
  133:         ssp--;
  134: 
  135:         spsr = INIT_PSR(rng);
  136:         pc = (UW)tcb->task;
  137:         if ( (pc & 1) != 0 ) {
  138:                 spsr |= PSR_T;                /* Thumb mode */
  139:         }
  140: 
  141:         /* CPU context initialization */
  142:         ssp->taskmode = INIT_TMF(rng); /* Initial taskmode */
  143:         ssp->spsr_svc = spsr;          /* Initial SR */
  144:         ssp->pc = (void*)(pc & ~0x00000001U);  /* Task startup address */
  145:         tcb->tskctxb.ssp = ssp;                /* System stack */
  146:         tcb->tskctxb.svc_ssp = NULL;   /* ssp when SVC is called */
  147: 
  148:         if ( rng > 0 ) {
  149:                 ssp->usp = tcb->istack;       /* User stack */
  150:         }
  151: }
  152: 
  153: /*
  154:  * Set task startup code
  155:  *      Called by 'tk_sta_tsk()' processing.
  156:  */
  157: Inline void setup_stacd( TCB *tcb, INT stacd )
  158: {
  159:         SStackFrame    *ssp = tcb->tskctxb.ssp;
  160: 
  161:         ssp->r[0] = stacd;
  162:         ssp->r[1] = (VW)tcb->exinf;
  163: }
  164: 
  165: /*
  166:  * Delete task contexts
  167:  */
  168: Inline void cleanup_context( TCB *tcb )
  169: {
  170: }
  171: 
  172: #endif /* _CPU_TASK_ */