alpha.h 4.93 KB
/*
 * Copyright (C) 1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * Copyright (C) 1998 Digital Equipment Corporation
 *
 * This file is part of the SimOS distribution.
 * See LICENSE file for terms of the license.
 *
 */


#ifndef _ALPHA_H
#define _ALPHA_H

#include <alpha/inst.h>

#include "alpha_regs.h"
#if 0
#include "alpha_ipr.h"
#endif
#include "syslimits.h"
#include "cpu_interface.h"

#define ZERO_REGISTER 31
#define ZERO_REDIRECT(x) (x==31?32:x)

extern int alphaLateInitDone;
extern void ExecuteGamma(void);
extern void ExecuteDelta(void);
extern void ExecuteEpsilon(void);
extern void ExecuteKappa(void);


typedef enum MMUStatus {
   MMU_SUCCESS,
   MMU_EXCEPTION,
   MMU_UNCACHED,
   MMU_LL,
   MMU_SC
} MMUStatus;


/**********************************************************************
 * Interrupt levels
 * ********************************************************************/

#define INTLEVEL_SOFTWARE_MIN 4
#define INTLEVEL_SOFTWARE_MAX 19

#define INTLEVEL_EXTERNAL_MIN 20
#define INTLEVEL_EXTERNAL_MAX 34

#define INTLEVEL_IRQ0 20
#define INTLEVEL_IRQ1 21
#define INTLEVEL_IRQ2 22
#define INTLEVEL_IRQ3 23

#define INTLEVEL_SERIAL 33


typedef enum {
  ATR_EXC_ADDR,
  ATR_EXC_SUM,
  ATR_EXC_MASK,
  ATR_MM_STAT,
  ATR_VA,
  ATR_VA_FORM,
  ATR_IVA,
  ATR_ITB_TAG,
  ATR_IVA_F,
  ATR_IPL,
  ATR_ISR,
  ATR_INTID,
  ATR_MAX
} AlphaTrapStateRegisters;

typedef struct AlphaTrapState {
  Reg atr[ATR_MAX];
  long lockedRegisters;
  int useShadowRegisters;
  struct AlphaTrapState *prev;
} AlphaTrapState;

typedef struct AlphaState {
   int cpuState;

   /* Processor state */
   Reg_s reg[33];         /* General-purpose registers */ 		 
   double fp[33];         /* Floating point registers */
   Reg_s shadowRegs[16];  /* 2 sets of shadow register values */
   Reg fpcr;              /* The Floating point control register */
   VA PC;    
   unsigned lockedRegisters; /* latch VA on next trap? */
   int dtbNLU, itbNLU;    /* TB replacement */
   struct TBState *tb;    /* TB State, managed by tb.c */
   Reg *ipr;              /* Keep only a pointer since there are a LOT of them */
   AlphaTrapState *trapState; /* Keep a pointer so we can have speculative traps */
   int alt_flag;          /* HW LD/ST alt mode - always 0 between instructions*/
   int lock_flag;         /* LL/SC */
   PA locked_addr;        /* LL/SC */
   

   /* Interrupt state */
   Reg pending_irq;
   int pending_irq_count[INTLEVEL_EXTERNAL_MAX];
   int takeInterrupt; 
   int takeInterruptAtRei; 
  

   /*
    * derived information
    */
   int useShadowRegisters;
   
   /*
    * common state 
    */
   int myNum;
   struct QCTable *curIQC;
   struct QCTable *curDQC;
   struct QCTable *altDQC;
   struct QCTable *palDQC;


   /*
    * The following is used only by GAMMA
    */

   union alpha_instruction instr; /*current instruction */


   /*
    * The following are only used by the DELTA simulator
    */
   struct AlphaState * nextCPU;
   void ** constantsPtr;
   SimTime cycleCount;
   int64   cycleCountDown;
   int64   timeQuantum;
   VA      llAddr;
   Reg     llValue;

   /*
    * SOLO only 
    */
   struct thread *aintThread;
} AlphaState;

extern AlphaState *PE[];
extern AlphaState *curPE;


/* **************************************************
 * following hardcoded constants should be replaced by 
 * genassym
 * **************************************************/


/* *************************************************
 * Privileged stuff, most likley implementation independent 
 * The implementation part is in ev5_ipr.h
 * *************************************************/

#define PAL_BASE 0x4000  
#define IS_PAL(_p) ((_p)->PC&0x1)
#define BITMASK(_i)     ((1LL<<(_i))-1)
#define ALIGN4(_i)      ((_i)&~3)

/* ***********************************************************
 * Page converstion macros:
 *   the VPN is the bit 13-63          of the vAddr (shifted down 13)
 *   the tag is the bit 13-(VA)BITS-1) of the vAddr (shifted down 13)
 * ***********************************************************/

#define _SEXT64(_x,_bit)  ((uint64) ( ((int64)((_x)<<(64-(_bit))))>>(64-(_bit))))
#define PAGE_BITS       13
#define PAGE2ADDR(_x)   ((_x)<<PAGE_BITS)

#define VADDR2VPN(_x) (((int64)(_x)) >> PAGE_BITS)
#define VADDR2TAG(_vA) (((_vA)&VA_MASK)>>PAGE_BITS)

#define TAG2VADDR(_tag)   _SEXT64(PAGE2ADDR(tag),VA_BITS)

#define	VA_BITS		43
#define	PA_BITS		40
#define VA_MASK         BITMASK(VA_BITS)
#define PA_MASK         BITMASK(PA_BITS)

#define	PA_BITS_32	30
#define PA_MASK_32      BITMASK(PA_BITS_32)

/* ****************************************************************************
 * Priviledged opcodes, not in /usr/include/alpha/inst.h
 * ****************************************************************************/

#define PRIV_OP_HW_LD   op_pal1b
#define PRIV_OP_HW_ST   op_pal1f
#define PRIV_OP_REI     op_pal1e
#define PRIV_OP_MFPR    op_pal19
#define PRIV_OP_MTPR    op_pal1d



/*
 * random
 */

#define PAGE_NUMBER(_x) ((_x)/PAGE_SIZE)




#endif  /* ALPHA_H */