gonzui


Format: Advanced Search

tkernel_2/kernel/sysdepend/device/tef_em1d/devinit.cbare 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 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:  *      devinit.c (EM1-D512)
   18:  *      Device-Dependent Initialization
   19:  */
   20: 
   21: #include "sysinit.h"
   22: #include "kernel.h"
   23: #include <tk/sysdef.h>
   24: #include <sys/sysinfo.h>
   25: #include <sys/rominfo.h>
   26: #include <sys/util.h>
   27: #include <device/devconf.h>
   28: #include <libstr.h>
   29: 
   30: /*
   31:  * Display the progress of start processing
   32:  *      0x10 - 0x1F : Initialization (before kernel starts)
   33:  *      0x20 - 0x2F : Kernel start processing
   34:  *      0x30 - 0x3F : Start processing (after kernel starts)
   35:  */
   36: EXPORT void DispProgress( W n )
   37: {
   38: }
   39: 
   40: /* ------------------------------------------------------------------------ */
   41: 
   42: /*
   43:  * Initialization at ROM startup
   44:  *      This function is called before 'main()'.
   45:  *      (same as 'SBOOT' for disk boot)
   46:  */
   47: EXPORT ER ROM_startup( void )
   48: {
   49:         W      val[L_DEVCONF_VAL];
   50:         W      n;
   51: 
   52:         /* Set SYSCONF/DEVCONF */
   53:         SCInfo.sysconf = ROMInfo->sysconf;
   54:         SCInfo.devconf = ROMInfo->devconf;
   55: 
   56:         /* Set debug mode */
   57:         n = GetDevConf(DCTAG_DEBUGMODE, val);
   58:         SCInfo.bm.c.debug = ( n >= 1 && val[0] > 0 )? 1: 0;
   59: 
   60:         /* Set boot device (no boot device) */
   61:         SCInfo.bootdev[0] = '\0';
   62: 
   63:         return E_OK;
   64: }
   65: 
   66: /*
   67:  * Set stack by exception mode
   68:  */
   69: LOCAL void setExcStack( UW mode, UW stack )
   70: {
   71:         Asm("  msr      cpsr_c, %1   \n"
   72:         "      mov  sp, %0           \n"
   73:         "      msr  cpsr_c, %2       "
   74:         :: "l"(stack), "r"(mode|PSR_I|PSR_F), "i"(PSR_SVC|PSR_I|PSR_F));
   75: }
   76: 
   77: /*
   78:  * Initialization before T-Kernel starts
   79:  */
   80: #define SYSCONF_VAL_MAX (16)
   81: 
   82: EXPORT ER init_device( void )
   83: {
   84: IMPORT  void     CountWaitUsec( void );      /* cntwus.c */
   85: 
   86: /* Low level memory manager information */
   87: IMPORT  UW       lowmem_top;
   88: 
   89:         W      n, v[SYSCONF_VAL_MAX];
   90: 
   91:         /* Compute loop count of micro second wait */
   92:         CountWaitUsec();
   93: 
   94:         /* Set stack for each exception mode */
   95:         lowmem_top = (lowmem_top + 3) & ~0x00000003U; /* Alignment match */
   96:         n = GetSysConf(SCTAG_ABTSTKSZ, v);     /* Abort (MMU) */
   97:         n = ( n < 1 )? 64: v[0];
   98:         lowmem_top += (n + 3) & ~0x00000003U;
   99:         setExcStack(PSR_ABT, lowmem_top);
  100: 
  101:         n = GetSysConf(SCTAG_UNDSTKSZ, v);     /* Undefined order exception */
  102:         n = ( n < 1 )? 64: v[0];
  103:         lowmem_top += (n + 3) & ~0x00000003U;
  104:         setExcStack(PSR_UND, lowmem_top);
  105: 
  106:         n = GetSysConf(SCTAG_IRQSTKSZ, v);     /* Interrupt (IRQ) */
  107:         n = ( n < 1 )? 512: v[0];
  108:         lowmem_top += (n + 3) & ~0x00000003U;
  109:         setExcStack(PSR_IRQ, lowmem_top);
  110: 
  111:         n = GetSysConf(SCTAG_FIQSTKSZ, v);     /* Fast interrupt (FIQ) */
  112:         n = ( n < 1 )? 128: v[0];
  113:         lowmem_top += (n + 3) & ~0x00000003U;
  114:         setExcStack(PSR_FIQ, lowmem_top);
  115: 
  116:         return E_OK;
  117: }
  118: 
  119: /* ------------------------------------------------------------------------ */
  120: /*
  121:  * Start processing after T-Kernel starts
  122:  *      Called from the initial task contexts.
  123:  */
  124: EXPORT ER start_device( void )
  125: {
  126:         return E_OK;
  127: }
  128: 
  129: /* ------------------------------------------------------------------------ */
  130: /*
  131:  * System finalization
  132:  *      Called just before system shutdown.
  133:  *      Execute finalization that must be done before system shutdown.
  134:  */
  135: EXPORT ER finish_device( void )
  136: {
  137:         return E_OK;
  138: }
  139: 
  140: /* ------------------------------------------------------------------------ */
  141: /*
  142:  *      Re-starting processing
  143:  */
  144: 
  145: /*
  146:  * Re-starting processing
  147:  *      mode = -1            Reset and re-start        (cold boot)
  148:  *      mode = -2            Re-start          (warm boot)
  149:  *      mode = -3            Reboot                    (normal boot)
  150:  *      mode = 0xFFhhmmss    Re-start at hh:mm:ss
  151:  *                              0 <= hh < 24, 0 <= mm,ss < 60
  152:  */
  153: EXPORT ER restart_device( W mode )
  154: {
  155:         if ( mode == -1 ) {
  156:                 /* Reset and re-start (cold boot) */
  157: #if USE_KERNEL_MESSAGE
  158:                 tm_putstring((UB*)"\n<< SYSTEM RESTART >>\n");
  159: #endif
  160:                 tm_exit(-1);  /* no return */
  161:                 return E_OBJ;
  162:         }
  163: 
  164:         if ( mode == -3 ) {
  165:                 /* Reboot (normal boot) */
  166:                 UB bdcmd[4 + L_DEVNM] = "bd ";
  167: #if USE_KERNEL_MESSAGE
  168:                 tm_putstring((UB*)"\n<< SYSTEM REBOOT >>\n");
  169: #endif
  170:                 STRNCAT((char*)bdcmd, (char*)SCInfo.bootdev, L_DEVNM);
  171:                 tm_command(bdcmd);    /* Normally no return */
  172:                 return E_OBJ;         /* When the BD command is an error */
  173:         }
  174: 
  175:         if ( mode == -2 ) {
  176:                 return E_NOSPT; /* Unsupported */
  177:         }
  178: 
  179:         if ( (mode & 0xff000000) == 0xff000000 ) {
  180:                 /* Re-start at specified time */
  181:                 return E_NOSPT;       /* Unsupported */
  182:         }
  183: 
  184:         return E_PAR;
  185: }