📄 cachearchlib.c
字号:
return (ERROR); /* invalid cache */ lockKey = intLock (); if (cache == DATA_CACHE) { if (_pSysL3CacheFlushDisableFunc != NULL) (*_pSysL3CacheFlushDisableFunc) (); if (_pSysL2CacheFlush != NULL) (*_pSysL2CacheFlush) (); if (_pSysL2CacheDisable != NULL) (*_pSysL2CacheDisable) (); } cachePpcDisable (cache); intUnlock (lockKey); if (cache == DATA_CACHE) { cacheDataEnabled = FALSE; /* data cache is off */ cacheFuncsSet (); /* update data function ptrs */ } return (OK); }/******************************************************************************** cacheErrnoSet -** RETURNS: ERROR, always.** NOMANUAL*/STATUS cacheErrnoSet (void) { errno = S_cacheLib_INVALID_CACHE; return (ERROR); }/********************************************************************************* cacheIsOn - boolean function to return state of cache**/LOCAL BOOL cacheIsOn ( CACHE_TYPE cache /* cache to examine state */ ) {#if ((CPU == PPC601) || (CPU == PPC603) || (CPU == PPCEC603) || (CPU == PPC604)) if (cache == DATA_CACHE) return ((vxHid0Get () & 0x00004000) != 0); if (cache == INSTRUCTION_CACHE) return ((vxHid0Get () & 0x00008000) != 0);#elif (CPU == PPC860) if (cache == INSTRUCTION_CACHE) return ((vxIcCstGet() & 0x80000000) != 0); if (cache == DATA_CACHE) return ((vxDcCstGet() & 0x80000000) != 0);#elif (CPU == PPC403) if (cache == DATA_CACHE) return ((vxDccrGet() & ppc403DccrVal) != 0); if (cache == INSTRUCTION_CACHE) return ((vxIccrGet() & ppc403IccrVal) != 0);#elif ( (CPU == PPC405) || (CPU == PPC405F) ) if (cache == DATA_CACHE) return ((vxDccrGet() & ppc405DccrVal) != 0); if (cache == INSTRUCTION_CACHE) return ((vxIccrGet() & ppc405IccrVal) != 0);#elif (CPU == PPC85XX) if (cache == DATA_CACHE) return ((vxL1CSR0Get() & 0x1) !=0); if (cache == INSTRUCTION_CACHE) return ((vxL1CSR1Get() & 0x1) !=0);#endif #if (CPU == PPC440) return (cache440Enabled);#else /* CPU != PPC440 */ return (FALSE);#endif /* CPU */ }/********************************************************************************* cacheArchDmaMalloc - allocate a cache-safe buffer**/void * cacheArchDmaMalloc ( size_t bytes /* size of cache-safe buffer */ ) { void * pBuf;#if (CPU != PPC403) int pageSize; if (!cacheIsOn (DATA_CACHE)) /* cache is off just allocate buffer */ { return (malloc (bytes)); } if ((pageSize = VM_PAGE_SIZE_GET ()) == ERROR) return (NULL); /* make sure bytes is a multiple of pageSize */ bytes = ROUND_UP(bytes,pageSize); if ((_func_memalign == NULL) || ((pBuf = (void *)(* _func_memalign) (MMU_PPC_PAGE_SIZE, bytes)) == NULL)) return (NULL); if (snoopEnable == TRUE) { VM_STATE_SET (NULL, pBuf, bytes, VM_STATE_MASK_CACHEABLE | VM_STATE_MASK_MEM_COHERENCY, VM_STATE_CACHEABLE | VM_STATE_MEM_COHERENCY); } else { VM_STATE_SET (NULL, pBuf, bytes, VM_STATE_MASK_CACHEABLE, VM_STATE_CACHEABLE_NOT); } return (pBuf);#else /* CPU == PPC403 */ pBuf = malloc (bytes); if (!cacheIsOn (DATA_CACHE)) /* cache is off just allocate buffer */ return (pBuf); else return ((void *)((UINT32) pBuf ^ (UINT32) 0x80000000)); /* return double-mapped adress */#endif /* CPU != PPC403 */ }/********************************************************************************* cacheArchDmaFree - free the buffer acquired by cacheArchDmaMalloc()*/STATUS cacheArchDmaFree ( void * pBuf /* ptr returned by cacheArchDmaMalloc() */ ) {#if (CPU != PPC403) BLOCK_HDR * pHdr; /* pointer to block header */ STATUS status = OK; /* return value */ if (cacheIsOn (DATA_CACHE) && ((vmLibInfo.vmBaseLibInstalled) || (vmLibInfo.vmLibInstalled))) { pHdr = BLOCK_TO_HDR (pBuf); status = VM_STATE_SET (NULL,pBuf,(pHdr->nWords * 2) - sizeof(BLOCK_HDR), (VM_STATE_MASK_CACHEABLE | VM_STATE_MASK_MEM_COHERENCY), (VM_STATE_CACHEABLE|VM_STATE_MEM_COHERENCY_NOT)); } free (pBuf); /* free buffer after modified */ return (status);#else /* CPU == PPC403 */ if (!cacheIsOn (DATA_CACHE)) free (pBuf); else free ((void *) ((UINT32)pBuf ^ (UINT32)0x80000000)); return (OK);#endif /* CPU != PPC403 */ }#if FALSE#if (CPU == PPC860)typedef union { struct { UINT reserved1:18; UINT tag:1; UINT way:1; UINT reserved2:1; UINT set:7; UINT word:2; UINT reserved3:2; } field; struct { UINT word; } bytes; } IC_ADR_T;typedef union { struct { UINT tag:21; UINT reserved1:1; UINT v:1; UINT l:1; UINT lru:1; UINT reserved3:7; } field; struct { UINT word; } bytes; } IC_DAT_T;void iCachePpcShow () { UINT ix; IC_ADR_T icAdr; IC_DAT_T icDat; IC_DAT_T icDat00; IC_DAT_T icDat01; IC_DAT_T icDat02; IC_DAT_T icDat03; for (ix = 0; ix <128; ix++) { icAdr.field.tag = 0; icAdr.field.way = 0; icAdr.field.set = ix; icAdr.field.word = 0; vxIcAdrSet (icAdr.bytes.word); icDat.bytes.word = vxIcDatGet(); icAdr.field.tag = 1; vxIcAdrSet (icAdr.bytes.word); icDat00.bytes.word = vxIcDatGet(); icAdr.field.word = 1; vxIcAdrSet (icAdr.bytes.word); icDat01.bytes.word = vxIcDatGet(); icAdr.field.word = 2; vxIcAdrSet (icAdr.bytes.word); icDat02.bytes.word = vxIcDatGet(); icAdr.field.word = 3; vxIcAdrSet (icAdr.bytes.word); icDat03.bytes.word = vxIcDatGet(); printf ("Set: %d tag: 0x%x v: %d l: %d lru: %d w00: 0x%x w01: 0x%x w02: 0x%x w03: 0x%x\n", ix, icDat.bytes.word & 0xfffff800, icDat.field.v, icDat.field.l, icDat.field.lru, icDat00.bytes.word, icDat01.bytes.word, icDat02.bytes.word, icDat03.bytes.word); icAdr.field.way = 1; icAdr.field.tag = 0; icAdr.field.word = 0; vxIcAdrSet (icAdr.bytes.word); icDat.bytes.word = vxIcDatGet(); icAdr.field.tag = 1; vxIcAdrSet (icAdr.bytes.word); icDat00.bytes.word = vxIcDatGet(); icAdr.field.word = 1; vxIcAdrSet (icAdr.bytes.word); icDat01.bytes.word = vxIcDatGet(); icAdr.field.word = 2; vxIcAdrSet (icAdr.bytes.word); icDat02.bytes.word = vxIcDatGet(); icAdr.field.word = 3; vxIcAdrSet (icAdr.bytes.word); icDat03.bytes.word = vxIcDatGet(); printf (" tag: 0x%x v: %d l: %d lru: %d w00: 0x%x w01: 0x%x w02: 0x%x w03: 0x%x\n", icDat.bytes.word & 0xfffff800, icDat.field.v, icDat.field.l, icDat.field.lru, icDat00.bytes.word, icDat01.bytes.word, icDat02.bytes.word, icDat03.bytes.word); } }void dCachePpcShow () { UINT ix; IC_ADR_T dcAdr; IC_DAT_T dcDat; IC_DAT_T dcDat00; IC_DAT_T dcDat01; IC_DAT_T dcDat02; IC_DAT_T dcDat03; for (ix = 0; ix <128; ix++) { dcAdr.field.tag = 0; dcAdr.field.way = 0; dcAdr.field.set = ix; dcAdr.field.word = 0; vxDcAdrSet (dcAdr.bytes.word); dcDat.bytes.word = vxDcDatGet(); dcAdr.field.tag = 1; vxDcAdrSet (dcAdr.bytes.word); dcDat00.bytes.word = vxDcDatGet(); dcAdr.field.word = 1; vxDcAdrSet (dcAdr.bytes.word); dcDat01.bytes.word = vxDcDatGet(); dcAdr.field.word = 2; vxDcAdrSet (dcAdr.bytes.word); dcDat02.bytes.word = vxDcDatGet(); dcAdr.field.word = 3; vxDcAdrSet (dcAdr.bytes.word); dcDat03.bytes.word = vxDcDatGet(); printf ("Set: %d tag: 0x%x v: %d l: %d lru: %d w00: 0x%x w01: 0x%x w02: 0x%x w03: 0x%x\n", ix, dcDat.bytes.word & 0xfffff800, dcDat.field.v, dcDat.field.l, dcDat.field.lru, dcDat00.bytes.word, dcDat01.bytes.word, dcDat02.bytes.word, dcDat03.bytes.word); dcAdr.field.way = 1; dcAdr.field.tag = 0; dcAdr.field.word = 0; vxDcAdrSet (dcAdr.bytes.word); dcDat.bytes.word = vxDcDatGet(); dcAdr.field.tag = 1; vxDcAdrSet (dcAdr.bytes.word); dcDat00.bytes.word = vxDcDatGet(); dcAdr.field.word = 1; vxDcAdrSet (dcAdr.bytes.word); dcDat01.bytes.word = vxDcDatGet(); dcAdr.field.word = 2; vxDcAdrSet (dcAdr.bytes.word); dcDat02.bytes.word = vxDcDatGet(); dcAdr.field.word = 3; vxDcAdrSet (dcAdr.bytes.word); dcDat03.bytes.word = vxDcDatGet(); printf (" tag: 0x%x v: %d l: %d lru: %d w00: 0x%x w01: 0x%x w02: 0x%x w03: 0x%x\n", dcDat.bytes.word & 0xfffff800, dcDat.field.v, dcDat.field.l, dcDat.field.lru, dcDat00.bytes.word, dcDat01.bytes.word, dcDat02.bytes.word, dcDat03.bytes.word); } }#endif /* (CPU == PPC860) */#endif /* FALSE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -