Example #1
0
File: vmLib.c Project: phoboz/vmx
STATUS vmLibInit(
    int pageSize
    )
{
    STATUS              status;
    int                 i;
    int                 j;
    int                 tableSize;
    unsigned            state;
    unsigned            mask;
    VM2MMU_STATE_TRANS *thisElement;
    unsigned            vmState;
    unsigned            mmuState;
    unsigned            vmMask;
    unsigned            mmuMask;

    /* Check if already installed */
    if (vmLibInstalled == TRUE)
    {
        status = OK;
    }
    else
    {
        /* Check for zero pagesize */
        if (pageSize == 0)
        {
            status = ERROR;
        }
        else
        {
            /* Store page size */
            vmPageSize = pageSize;

            for (i = 0; i < NUM_PAGE_STATES; i++)
            {
                state = 0;
                for (j = 0; j < mmuStateTransTableSize; j++)
                {
                    thisElement = &mmuStateTransTable[j];
                    vmState     = thisElement->vmState;
                    mmuState    = thisElement->mmuState;
                    vmMask      = thisElement->vmMask;

                    if ((i & vmMask) == vmState)
                    {
                        state |= mmuState;
                    }
                }

                vmStateTransTable[i] = state;
            }

            for (i = 0; i < NUM_PAGE_STATES; i++)
            {
                mask = 0;
                for (j = 0; j < mmuStateTransTableSize; j++)
                {
                    thisElement = &mmuStateTransTable[j];
                    vmMask      = thisElement->vmMask;
                    mmuMask     = thisElement->mmuMask;

                    if ((i & vmMask) == vmMask)
                    {
                        mask |= mmuMask;
                    }
                }

                vmMaskTransTable[i] = mask;
            }

            /* Global page block table size */
            tableSize = (unsigned) 0x80000000 / (mmuPageBlockSize / 2);
            globalPageBlockTable = (char *) calloc(
                                                tableSize,
                                                sizeof(globalPageBlockTable[0])
                                                );
            if (globalPageBlockTable == NULL)
            {
                status = ERROR;
            }
            else
            {
                /* Initialize class */
                if (classInit(
                        vmContextClassId,
                        sizeof(VM_CONTEXT),
                        OFFSET(VM_CONTEXT, objCore),
                        memSysPartId,
                        (FUNCPTR) vmContextCreate,
                        (FUNCPTR) vmContextInit,
                        (FUNCPTR) vmContextDestroy) != OK)
                {
                    status = ERROR;
                }
                else
                {
                    semMInit(&globalMemMutex, vmMutexOptions);

                    /* Enable mmu for cache library */
                    cacheMmuAvailable = TRUE;
                    cacheFuncsSet();

                    /* Set as installed */
                    vmLibInstalled = TRUE;
                    status = OK;
                }
            }
        }
    }

    return status;
}
Example #2
0
STATUS cacheLsn2eLibInit
    (
    CACHE_MODE	instMode,	/* instruction cache mode */
    CACHE_MODE	dataMode	/* data cache mode */

#if 0
    UINT32	iCacheSize,
    UINT32	iCacheLineSize,
    UINT32	dCacheSize,
    UINT32	dCacheLineSize,
    UINT32	sCacheSize,
    UINT32	sCacheLineSize
#endif
    )
    {
#if 0
    cacheLsn2eICacheSize = iCacheSize;
    cacheLsn2eDCacheSize = dCacheSize;
    cacheLsn2eSCacheSize = sCacheSize;
    cacheLsn2eICacheLineSize = iCacheLineSize;
    cacheLsn2eDCacheLineSize = dCacheLineSize;
    cacheLsn2eSCacheLineSize = sCacheLineSize;
#endif

    cacheLib.enableRtn = cacheLsn2eEnable;
    cacheLib.disableRtn = cacheLsn2eDisable;

    cacheLib.lockRtn = NULL;			/* cacheLock */
    cacheLib.unlockRtn = NULL;			/* cacheUnlock */

    cacheLib.flushRtn = cacheLsn2eFlush;		/* cacheFlush() */
    cacheLib.pipeFlushRtn = cacheLsn2ePipeFlush;	/* cachePipeFlush() */
    cacheLib.textUpdateRtn = cacheLsn2eTextUpdate;/* cacheTextUpdate() */

    cacheLib.invalidateRtn = cacheLsn2eInvalidate;/* cacheInvalidate() */
    cacheLib.clearRtn = cacheLsn2eInvalidate;	/* cacheClear() */

    cacheLib.dmaMallocRtn = (FUNCPTR) cacheLsn2eMalloc;	/* cacheDmaMalloc() */
    cacheLib.dmaFreeRtn = cacheLsn2eFree;			/* cacheDmaFree() */

#ifdef IS_KSEGM
    if (!IS_KSEGM(cacheLsn2eLibInit))
	{
	cacheLib.dmaVirtToPhysRtn = (FUNCPTR) cacheLsn2eVirtToPhys;
	cacheLib.dmaPhysToVirtRtn = (FUNCPTR) cacheLsn2ePhysToVirt;
	_func_mipsCacheSync = (VOIDFUNCPTR) cacheLsn2eSync;
	}
    else
	{
	_func_mipsCacheSync = (VOIDFUNCPTR) KM_TO_K0(cacheLsn2eSync);
	_func_mmuMipsVirtPageFlush = (VOIDFUNCPTR) cacheLsn2eVirtPageFlush;
	_func_mmuMipsVirtPageFlush = NULL;
	}
#else /* IS_KSEGM */
    cacheLib.dmaVirtToPhysRtn = (FUNCPTR) cacheLsn2eVirtToPhys;
    cacheLib.dmaPhysToVirtRtn = (FUNCPTR) cacheLsn2ePhysToVirt;
#endif /* IS_KSEGM */

    cacheDataMode	= dataMode;		/* save dataMode for enable */
    cacheDataEnabled	= TRUE;			/* d-cache is currently on */
    cacheMmuAvailable	= TRUE;			/* mmu support is provided */

    cacheFuncsSet ();				/* update cache func ptrs */
#if 0
		cacheDmaFuncs.flushRtn = cacheLib.flushRtn;
	    cacheDmaFuncs.invalidateRtn	= cacheLib.invalidateRtn;
	    cacheDmaFuncs.virtToPhysRtn	= cacheLib.dmaVirtToPhysRtn;
	    cacheDmaFuncs.physToVirtRtn	= cacheLib.dmaPhysToVirtRtn;

	    cacheDmaMallocRtn		= cacheLib.dmaMallocRtn;
	    cacheDmaFreeRtn		= cacheLib.dmaFreeRtn;

		cacheUserFuncs.flushRtn = cacheLib.flushRtn;
	    cacheUserFuncs.invalidateRtn	= cacheLib.invalidateRtn;
	   /* cacheUserFuncs.virtToPhysRtn	= cacheLib.dmaVirtToPhysRtn;
	    cacheUserFuncs.physToVirtRtn	= cacheLib.dmaPhysToVirtRtn;*/
#endif
    return (OK);
    }