/*
 * Author   : Kavita Bala 
 * Email    : kaybee@lcs.mit.edu
 * Comment  : Header file for all declarations
 */

#define KB_DEBUG         0

/* 
 * Offsets for temporaries
 */
 
#define KB_TOTAL_TRAPS_PTR                  29   + 512
#define KB_TOTAL_TRAPS                      29*4 + 2048  /* 512 + 29 */


#define KB_K1                               33*4 + 2048 
#define KB_T0                               34*4 + 2048 
#define KB_T1                               35*4 + 2048 
#define KB_AT                               36*4 + 2048 

#define KB_STATUS                           37*4 + 2048 
#define KB_EPC                              38*4 + 2048 

#define KB_TLB_MISS_NEXT_PTR                39   +  512  /* 512 + 39 */
#define KB_TLB_MISS_NEXT                    39*4 + 2048  

#define KB_STLB_SERVICED_PTR                40   +  512  /* 512 + 40 */
#define KB_STLB_SERVICED                    40*4 + 2048  



#define KB_TLB_HI_VPN_MASK                  0xfffff000


#define KB_STLB_INDEX_CTXT_MASK           0x7ff8
#define KB_STLB_TAG_MASK                  0xff  

#define KB_STLB_TAG_BLANK_MASK            0xffffff00
#define	KB_STLB_VALID_MASK		  0x00000200        /* PG_V     */
#define KB_STLB_DIRTY_MASK                0x00000400        /* TLB_LO_D */
#define	KB_STLB_L2_MASK 		  0x00000100        /* PG_G     */


#define KB_STLB_SHIFT_VADDR                9
#define KB_STLB_TAG_SIZE                   8      
#define KB_L2_CHECK_SHIFT                 31

#define KB_PAGE_SIZE                4*1024 /* in bytes */
#define KB_NO_OF_ENTRIES_PER_PAGE   1024
#define KB_STLB_NO_OF_ENTRIES       1024*4 /* no of entries in STLB*/
#define KB_STLB_BYTE_SIZE           8*KB_STLB_NO_OF_ENTRIES
                                    /* Since each entry is 8 bytes */



#define KB_TLB_LOAD_POINT            0x80000008 /* Need to change this if
						  I add to umiss*/



#ifndef ASSEMBLER
#define TW_RESET       -2
#define TW_STATS       -3
extern vm_offset_t     kb_stlb_tmp_space_ptr;
extern vm_offset_t     kb_stlb_ptr;

#endif

#define KB_PREFETCH_RESET                 0
#define KB_PREFETCH_STATS                 1
#define KB_PREFETCH_START                 2
#define KB_PREFETCH_STOP                  3
#define KB_PREFETCH_TLB_PID               4
#define MAX_COMMAND                       4

#ifndef ASSEMBLER
#include <mach/mach_types.h>
extern int             prefetch_intercept_enabled;
extern int             kb_prefetch_trace_on, kb_prefetch_index;
extern int             kb_server_pc_index, kb_sys_trace_index;
extern unsigned int    kb_overhead_added;



extern int             kb_already_there, kb_prefetch_l2, kb_prefetch_l1k,
                       kb_prefetch_kpt, kb_basic_other;
extern int             kb_basic_user_pt, kb_basic_l2, kb_basic_l1k,
                       kb_basic_kpt;

struct prefetch_stats {
  int                     already_there;
  int                     prefetch_l2;
  int                     prefetch_l1k;
  int                     prefetch_kpt;
  int                     basic_user_pt;
  int                     basic_l2;
  int                     basic_l1k;
  int                     basic_kpt;
  int                     other;
  int                     nested_l2;
  int                     nested_l1k;
  int                     nested_user_pt;

  unsigned int            l2_time;
  int                     tlb_traps;

  unsigned int            stlb_time;
  int                     stlb_serviced;

  unsigned int            other_time;

  int       tmr_max;
  int       tmr_min;
  unsigned int       overhead_added;
};


typedef struct prefetch_stats prefetch_stats_t;
extern prefetch_stats_t kb_stats;
#endif ASSEMBLER





