#ifndef _cache_fs
#define _cache_fs
/******************************************************************************
** FILE: cache.fs
** Cache and memory simulator.
*/

// Provide the cache simulator an opertunity to initialize itself.
extern cache_init() : void;

// Flush the cache.
extern cache_flush() : void;

///////////////////////////////////////////////////////////////////////////////
// Start processing a load: The args are (inum,va,first,var delay) where:
//  "inum" is the index of the load instruction in the current OOO-queue,
//  "va" is the virtual address accessed by the load, and
//  "first" is true if this is the oldest non-executing load in the OOO-queue.
//
// If true is returned, then the load hit in the L1 cache and the data
// will be available after "delay" cycles.
//
// If false is returned and delay is >0, then we must continue the
// load in "delay" cycles.
//
// If false is returned and delay is <0, then we must retry this load,
// and "delay" is a hint that this load cannot be accepted for at
// least "delay" cycles.
//

extern cache_load_start(ulong,ulong,bool,var short) : bool;

///////////////////////////////////////////////////////////////////////////////
// Continue load processing. The args are (inum,var delay).
//
// If true is returned, then the load hit and the data will be
// available after "delay" cycles.
//
// If false is returned, then we must continue the load again in
// "delay" cycles.
//

extern cache_load_continue(ulong,var short) : bool;

///////////////////////////////////////////////////////////////////////////////
// Start processing a store: The args are (inum,va,is_spec,var delay) where:
//  "inum" and "va" are the same as above and
//  "is_spec" is true if this store is part of a speculative execution.
//
// If true is returned, then this store has been successfully added to
// the write buffer.
//
// If false is returned, then we must retry this store, and "delay" is
// a hint that this store cannot be accepted for at least "delay"
// cycles.
//

extern cache_store_start(ulong,ulong,bool,var short) : bool;

///////////////////////////////////////////////////////////////////////////////
// Rollback or Commit specualtive stores: The only arument is (inum).
//
// All stores that were flagged as speculative when they started msut
// be either rolled back or committed. Rollback will remove the store
// from the write buffer without completing it. Commit will allow a
// speculative sotre to complete normally.
//
// Non-specualtive stores do not need to be committed, and will
// complete normally on their own.
//

extern cache_store_commit(ulong,var short) : bool;
extern cache_store_rollback(ulong) : void;

///////////////////////////////////////////////////////////////////////////////
// Update queue state to reflect that N instructions have retired.
// The only argument is (N).
//
// This is needed because the inum index used in the cache interface
// calls is relative to the start of the OOO-queue, which changes when
// instructions retire and are removed.
//

extern cache_retire(ulong) : void;

#endif