cp0.h 4.35 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. 
 *
 */

/*****************************************************************
 * cp0.h
 * 
 * Definitions for CP0 - TLB and exception handling
 * Written for BIG ENDIAN!!!
 *
 * $Author: blythe $
 * $Date: 2002/05/29 01:09:10 $
 *****************************************************************/

#ifndef MIPSY_CP0_H
#define MIPSY_CP0_H

#include "simtypes.h"
#include "mips_arch.h"
#include "addr_layout.h"
#include "mipsy.h"
#include "list.h"

/* Global CP0 Functions */
extern void   MipsyInitTLBHashTable(CPUState *P);
extern void   EXCEPTION(CPUState *P, int);
extern int    ExecuteC0Instruction(CPUState *P, Inst instr);
extern void   EnableInterruptCheck(CPUState *P, int interval);
extern Result TranslateVirtual(CPUState *P,VA, PA *, uint *tlbFlavor, void **bdoorAddr);
extern Result TranslateVirtualNoSideeffect(CPUState *P, VA, PA *);
extern void   MipsyCheckForInterrupts(CPUState *P);
extern void   MipsyCacheError(int cpuNum, bool isAsync);

/* Global CP0 Constants */

#define TLB_CACHED     0x00000000
#define TLB_BDOOR      0x00000001
#define TLB_UNCACHED   0x00000002
/* Make sure that you can do a (value&TLB_BDOOR) */
#define TLB_BDOOR_DATA 0x00000011
#define TLB_BDOOR_FUNC 0x00000021
/* jump to a backdoor function -- only used in compatibility mode */
#define TLB_BDOOR_FUNC_COMPAT 0x00000031

#define TLB_READING    0x0
#define TLB_WRITING    0x00000004

#define TLB_DFETCH   0x0
#define TLB_IFETCH   0x00000008
#define TLB_PREFETCH 0x00000040

#define TLB_ACCELERATED 0x00000010

#ifdef HWBCOPY
#define TLB_MSG_SPACE 0x00000020
#endif

/* Return values for a cop0 instruction */
#define C0_SUCCESS       0
#define C0_ILLEGAL_INST  1
#define C0_CONTINUE      2


#define TLB_IS_IFETCH(_flag)    (_flag & TLB_IFETCH)
#define TLB_IS_PREFETCH(_flag)  (_flag & TLB_PREFETCH)
#define TLB_IS_WRITE(_flag)     (_flag & TLB_WRITING)

/*****************************************************************
 *  Hash table support for mipsy's TLB - From Emmett's mshade 
 *  This uses the List_Links package from Sprite -
 *****************************************************************/

/* 
 * Exception handling routines. 
 */
#define _MIPSY_RECORD_EXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) { \
 (_P)->CP0[C0_BADVADDR] = (_badaddr); \
 (_P)->CP0[C0_TLBHI] = (_hireg); \
 (_P)->CP0[C0_CTXT] = (_ctxtreg); \
 (_P)->CP0[C0_XCTXT] = (_xctxtreg); \
 EXCEPTION((_P), (_cause)); \
}

#define _MIPSY_RECORD_UTLBEXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) { \
 (_P)->CP0[C0_BADVADDR] = (_badaddr); \
 (_P)->CP0[C0_TLBHI] = (_hireg); \
 (_P)->CP0[C0_CTXT] = (_ctxtreg); \
 (_P)->CP0[C0_XCTXT] = (_xctxtreg); \
 UTLB_EXCEPTION((_P), (_cause)); \
}

#ifdef MIPSY_MXS
#define _MXS_RECORD_EXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) { \
 (_P)->lastException = (((_P)->lastException+1) % MAX_NUM_EXCEPTIONS); \
 (_P)->exception[(_P)->lastException].cause = (_cause); \
 (_P)->exception[(_P)->lastException].vec = (_vec); \
 (_P)->exception[(_P)->lastException].badaddr = (_badaddr); \
 (_P)->exception[(_P)->lastException].hireg = (_hireg); \
 (_P)->exception[(_P)->lastException].ctxtreg = (_ctxtreg); \
 (_P)->exception[(_P)->lastException].xctxtreg = (_xctxtreg);   }

#define RECORD_EXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) \
 if ((_P)->inMXS) \
    _MXS_RECORD_EXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) \
 else  \
    _MIPSY_RECORD_EXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) 

#define RECORD_UTLBEXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) \
 if ((_P)->inMXS) \
    _MXS_RECORD_EXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) \
 else  \
    _MIPSY_RECORD_UTLBEXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) 

#endif /* MIPSY_MXS */

#ifndef RECORD_EXCEPTION
#define RECORD_EXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) \
  _MIPSY_RECORD_EXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) 
#define RECORD_UTLBEXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) \
  _MIPSY_RECORD_UTLBEXCEPTION(_P, _cause, _vec, _badaddr, _hireg, _ctxtreg,_xctxtreg) 

#endif /* RECORD_EXCEPTION */

#endif /* !MIPSY_CP0_H */