gonzui


Format: Advanced Search

tkernel_2/lib/libtk/src/tkminit.cbare sourcepermlink (0.00 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:  *      @(#)tkminit.c (libtk)
   17:  *
   18:  *      Memory allocation library
   19:  *      T-Kernel initialization sequence
   20:  *
   21:  *      _tkm_init is always linked as it is called from the startup
   22:  *      sequence part.
   23:  *      Note that adding too many processing can make the program
   24:  *      size quite large, irrespective of whether malloc is required
   25:  *      or not.
   26:  */
   27: 
   28: #include <basic.h>
   29: #include <tk/tkernel.h>
   30: #include <sys/memalloc.h>
   31: 
   32: /*
   33:  * Memory allocation
   34:  */
   35: LOCAL void* getblk( INT nblk, UINT mematr )
   36: {
   37:         void*  ptr;
   38:         ER     ercd;
   39: 
   40:         ercd = tk_get_smb(&ptr, nblk, mematr);
   41:         if ( ercd < E_OK ) {
   42:                 return NULL;
   43:         }
   44: 
   45:         return ptr;
   46: }
   47: 
   48: /*
   49:  * Memory release
   50:  */
   51: LOCAL void relblk( void *ptr )
   52: {
   53:         tk_rel_smb(ptr);
   54: }
   55: 
   56: /*
   57:  * MACB initialization
   58:  */
   59: EXPORT ER _tkm_init( UINT mematr, MACB *_macb )
   60: {
   61:         MACB   *macb = AlignMACB(_macb);
   62:         T_RSMB rsmb;
   63:         ER     ercd;
   64: 
   65:         /* Initialize memory allocation management information */
   66:         macb->pagesz   = 0;    /* 0 indicates not available for use */
   67:         macb->mematr   = mematr;
   68:         macb->testmode = 0;
   69:         macb->getblk   = getblk;
   70:         macb->relblk   = relblk;
   71:         QueInit(&macb->areaque);
   72:         QueInit(&macb->freeque);
   73: 
   74:         /* Get memory information */
   75:         ercd = tk_ref_smb(&rsmb);
   76:         if ( ercd < E_OK ) {
   77:                 return ercd;
   78:         }
   79:         macb->pagesz = (UINT)rsmb.blksz;
   80: 
   81:         return E_OK;
   82: }