ms_simos.c 3.83 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. 
 *
 */

#include "ms.h"
#include "memref.h"
#include "cpu_state.h"

#include "simmisc.h"
#include "remap.h"
#include "machine_params.h"

/*******************************************************************
 * Interface routines to R4000 simos
 * Basem A. Nayfeh
 ******************************************************************/

bool
InterruptIsPending(struct s_cpu_state *st)
{
  CPUState *P = (CPUState *) (st->mipsyPtr);
  P->CP0[C0_CAUSE] = ((P->CP0[C0_CAUSE] & ~CAUSE_EXTINTBITS) |
                      ((P->intrBitsPtr[0] << CAUSE_IPSHIFT) & CAUSE_EXTINTBITS));
  
  if (((P->CP0[C0_CAUSE] & P->CP0[C0_SR]) & SR_IMASK)
      && (P->CP0[C0_SR] & SR_IEC)
      && !(P->CP0[C0_SR] & (SR_EXL|SR_ERL))) {
    return TRUE;
  }
  return FALSE;
}

Result
ReadICache(int cpuNum, VA vAddr, PA pAddr, Inst *pInst)
{
  return MemRefReadInst(cpuNum,vAddr,pAddr,pInst);
}

#define HOST_DATA_ADDR(vAddr, paddr, cpu) \
  (PHYS_TO_MEMADDR(M_FROM_CPU(cpu),paddr)+(IS_REMAPPED_PADDR(paddr,cpu) ? remapVec->NodeAddr[cpu] : 0))


Result
DCacheFetchShared(int cpuNum, VA vAddr, PA pAddr, int flags, char **dataPtr)
{
  (*dataPtr) =  (char *)HOST_DATA_ADDR(vAddr, pAddr, cpuNum);
  return SUCCESS;
}

Result
DCacheFetchExclusive(int cpuNum, VA vAddr, PA pAddr, int size, char **dataPtr)
{
  /* This is bogus as is because we don't handle an SC failure */
  /* See below for the old interface                           */
  (*dataPtr) =  (char *)HOST_DATA_ADDR(vAddr, pAddr, cpuNum);
  return SUCCESS;
}


#if 0
Result
DCacheFetchShared(int cpuNum, VA vAddr, PA pAddr, int flags,
                  char **dataPtr) {
  int mhtind;
  Result ret;
  MemRefHandle handle;
  int accessType;
  int MXSAction;

  if (flags & MXS_SECOND_TIME) {
    goto DCFSHit;
  }
 
  accessType = MEMREF_ACCESS_READ|MEMREF_SOURCE_DFETCH;
  if (flags & LL_FLAVOR) {
    accessType |= MEMREF_FLAVOR_LL;
  }
  handle = MemRef(cpuNum, accessType, vAddr, pAddr);
  if (handle != MEMREF_NOSTALL) {
    /* BAN: Just point the dataPtr to the handle which serves as a unique */
    /*      id in place of the MHT index.  This will be used when calling */
    /*      back into MXS using DoMxsAction along with the contents of    */
    /*      MXSAction                                                     */


    (*dataPtr) = (char *) handle;
    MXSAction = GetMxsAction(PE[cpuNum].st);
#ifdef VERBOSE_TRACE
    CPUPrint("M P: %2d\tA: %8x\tH: %8x\n",cpuNum,pAddr,handle);
#endif
    return STALL;
  }

DCFSHit:
  (*dataPtr) =  (char *)DATA_STORAGE(vAddr, pAddr, cpuNum);
  return SUCCESS;
}


Result
DCacheFetchExclusive(int cpuNum, VA vAddr, PA pAddr, int size,
                     char **dataPtr) {
  int mhtind;
  Result ret;
  MemRefHandle handle;
  int accessType;
  int MXSAction;

  if (size & MXS_SECOND_TIME) {
    goto DCFEHit;
  }


  accessType = MEMREF_ACCESS_WRITE;
  if (size & SC_FLAVOR) {
    accessType |= MEMREF_FLAVOR_SC;
  }
  handle = MemRef(cpuNum, accessType, vAddr, pAddr);
  if (handle != MEMREF_NOSTALL) {
    /* BAN: First special case the SC */
    if (size & SC_FLAVOR) {
      (*dataPtr) = NULL;
      return SCFAILURE;
    }
    /* BAN: Just point the dataPtr to the handle which serves as a unique */
    /*      id in place of the MHT index.  This will be used when calling */
    /*      back into MXS using DoMxsAction along with the contents of    */
    /*      MXSAction                                                     */
    (*dataPtr) = (char *) handle;
    MXSAction = GetMxsAction(PE[cpuNum].st);
#ifdef VERBOSE_TRACE
    CPUPrint("M P: %2d\tA: %8x\tH: %8x\n",cpuNum,pAddr,handle);
#endif
    return STALL;
  }

DCFEHit:
  (*dataPtr) =  (char *)DATA_STORAGE(vAddr, pAddr, cpuNum);
  return SUCCESS;
}
#endif /*0*/