memref.h 3.85 KB
/*
 * Copyright (C) 1996-1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * 
 * This file is part of the SimOS distribution. 
 * See LICENSE file for terms of the license. 
 *
 */


/*****************************************************************
 * memref.h
 * 
 * This is the generic cache interface from mipsy that allows a 
 * cache/memory system simulator to see all the memory references and 
 * control the memory  * system delays seen by the processor. 
 *
 * Author: $Author: blythe $
 * Date: $Date: 2002/05/29 01:09:09 $
 *******************************************************************/

#ifndef _MEMREF_H
#define _MEMREF_H

#include "simtypes.h"

typedef enum {
  BYTE_SZ, HALF_SZ, WORD_SZ, DOUBLE_SZ
} RefSize;

typedef enum {
  NO_FLAVOR, LL_FLAVOR, SC_FLAVOR, PREF_FLAVOR, PREFX_FLAVOR, GETX_FLAVOR
} RefFlavor;


#ifdef QUICK_CHECK
# define QUICK_ICACHE_CHECK(_p, _P) (ICACHE_ONE_LINE(_p) == (_P)->cachedILine)
#else
# define QUICK_ICACHE_CHECK(_p, _P)   (0)
#endif


/*
 * MemRefInit() - Call to initialize memory system simulator.
 * 
 */
extern void MemRefInit(void);

/*
 * MemRefResetStats(cpuNum) - Call to reset all statistics
 *    cpuNum     - CPU to reset
 */
extern void MemRefResetStats(int cpuNum);

/*
 * MemRefPrintPeriodicStats() - Call to print out any periodic stats
 *                 that the cache might be keeping.
 *    cpuNum     - CPU's cache to print
 */
extern void MemRefPeriodicStats(int cpuNum);

/*
 * MemRefDumpStats() - Can be called anytime to dump all statistics.
 *    cpuNum     - CPU's cache to print
 */
extern void MemRefDumpStats(int cpuNum);

/*
 * MemRefExit() - Clean up and print final statistics.
 */
extern void MemRefExit(void);



/*
 * MemRef... calls
 *    cpuNum     - CPU generating reference. 
 *    accessType - Type of reference. Defined by macros below.
 *    vAddr      - Virtual address of reference.
 *    pAddr      - Physical address of reference.
 */
extern Result MemRefReadInst(int cpuNum, VA, PA, Inst *inst);
extern Result MemRefReadData(int cpuNum, VA, PA, void *data, 
                             RefSize size, RefFlavor flavor);
extern Result MemRefWriteData(int cpuNum, VA, PA, uint64 data, 
                              RefSize size, RefFlavor flavor);

/*
 * MemRefSync- Called when a CPU executes a "sync" instruction.
 */
extern Result MemRefSync(int cpuNum);


/* 
 * Debugging interface - methods for reading and writing data without 
 * affecting the caches.
 */
extern void MemRefDebugReadData(int cpuNum, VA, PA, char *buff, int size);
extern void MemRefDebugWriteData(int cpuNum, VA, PA, char *buff, int size);

/* 
 * Support routines for cache operations callable from the
 * CPU. We don't implement all different cache ops.
 */
extern Result MemRefIndexHitWBInval(int cpuNum, VA, PA);
extern Result MemRefHitWBInval(int cpuNum, VA, PA);


/* 
 * Handle prefetch operations. Returns non-zero if the prefetch 
 * fails. This interface needs some work.
 */
extern Result MemRefPrefetch(int cpuNum, VA vAddr, PA pAddr, int hint);

extern Result MemRefReadUncached(int cpuNum, VA, PA, void *data, RefSize size);

extern Result MemRefWriteUncached(int cpuNum, VA, PA, void *data, 
                                  RefSize size, bool accelerated);

extern Result MemRefDMAWrite(int cpuNum, PA pAddr, int transId, int length, 
                             byte *data);
extern Result MemRefDMARead(int cpuNum, PA pAddr, int transId, int length, 
                             byte *data);

void MemRefRemoveReq(int cpuNum, PA pAddr, int size);


/* CALLS THAT MEMREF MAKE BACK TO THE CPU MODEL */
extern void MemRefDone(int cpuNum);


/*
 * Here are some useful utility that a memory simulator will want to use.
 *
 * MemRefTime - Return the current simulator time.
 * MemRefMode - Return the current mode of cpu.
 */

extern SimTime MemRefTime(int cpuNum);
extern int     MemRefMode(int cpuNum);

#endif /* _MEMREF_H */