OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_33/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Diff between revs 153 and 167

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 153 Rev 167
Line 18... Line 18...
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
 
#include <errno.h>
 
 
#include "arch.h"
#include "arch.h"
#include "sprs.h"
#include "sprs.h"
 
#include "abstract.h"
 
 
extern int cont_run;   /* defined in toplevel.c */
extern int cont_run;   /* defined in toplevel.c */
extern int tt_stopped; /* defined in tick.c */
extern int tt_stopped; /* defined in tick.c */
extern int GlobalMode; /* CZ 21/06/01 */
extern int flag;
 
 
static sprword sprs[MAX_SPRS];
sprword sprs[MAX_SPRS];
 
 
int temp_disable_except = 0;
int temp_disable_except = 0;
int audio_cnt = 0;
int audio_cnt = 0;
 
 
static FILE *fo = 0;
static FILE *fo = 0;
/* Set a specific SPR with a value. */
/* Set a specific SPR with a value. */
void mtspr(int regno, sprword value)
inline void
 
mtspr(const int regno, const sprword value)
{
{
  int ofs = regno % MAX_SPRS_PER_GRP;
  int ofs = regno % MAX_SPRS_PER_GRP;
 
 
  /* MM: Register hooks.  */
  /* MM: Register hooks.  */
  switch (regno) {
  switch (regno) {
Line 57... Line 60...
    fclose(fo);
    fclose(fo);
    printf("Audio closed.\n");
    printf("Audio closed.\n");
    cont_run = 0;
    cont_run = 0;
    return;
    return;
  case SPR_TTMR:
  case SPR_TTMR:
    if (value & SPR_TTMR_M == 2) break;
    if (value & SPR_TTMR_M == 0x80000000) break;
  case SPR_TTCR:
  case SPR_TTCR:
    tt_stopped = 0;
    tt_stopped = 0;
    break;
    break;
  case 0x1234:
  case 0x1234:
    printf("MTSPR(0x1234, %x);\n", value);
    printf("MTSPR(0x1234, %x);\n", value);
    break;
    break;
 
  case 0x1235:
 
    {
 
      FILE *f;
 
      if (!(f = fopen("stdout.txt", "a+")))
 
        {
 
          perror(strerror(errno));
 
          return;
 
        }
 
      fprintf(f, "%c", value);
 
      if (fclose(f))
 
        perror(strerror(errno));
 
    }
 
    break;
 
  case SPR_SR:
 
    if(value & SPR_SR_F)
 
      flag = 1;
 
    else
 
      flag = 0;
 
    break;
 
  case SPR_EPCR_BASE:
 
    if((value & 0xffffff00) == 0x00020600)
 
      {
 
        printf("SIMON: EPCR = ext_int\n");
 
        cont_run = 0;
 
      }
 
    break;
  }
  }
 
 
  /* What the hell is happening here? This looks like a bug
  /* What the hell is happening here? This looks like a bug
     waiting to happen. Assume regno = 2*MAX_SPRS_PER_GRP+3,
     waiting to happen. Assume regno = 2*MAX_SPRS_PER_GRP+3,
     which presumably means I want to set register 3 in
     which presumably means I want to set register 3 in
Line 77... Line 106...
     actually supposed to do. It doesn't matter if regno
     actually supposed to do. It doesn't matter if regno
     is less than MAX_SPRS_PER_GRP, which is the only
     is less than MAX_SPRS_PER_GRP, which is the only
     way I use it.  CZ - 21/06/01
     way I use it.  CZ - 21/06/01
  */
  */
 
 
  regno /= MAX_SPRS_PER_GRP;
  //regno /= MAX_SPRS_PER_GRP;
  regno += ofs;
  //regno += ofs;
 
 
  /* CZ 21/06/01 ... the debugger wants to do this! */
  /* CZ 21/06/01 ... the debugger wants to do this! */
  if(GlobalMode)
  if(GlobalMode)
    {
    {
      extern unsigned long pc;
      extern unsigned long pc;
Line 114... Line 143...
 
 
  /*    printf("mtspr(%x, %x)\n", regno, value);
  /*    printf("mtspr(%x, %x)\n", regno, value);
   */   if (regno < MAX_SPRS)
   */   if (regno < MAX_SPRS)
     sprs[regno] = value;
     sprs[regno] = value;
   else {
   else {
     printf("\nABORT: write out of SPR range\n");
     printf("\nABORT: write out of SPR range %08X\n", regno);
     cont_run = 0;
     cont_run = 0;
   }
   }
}
}
 
 
/* Get a specific SPR. */
/* Get a specific SPR. */
sprword mfspr(int regno)
inline sprword
 
mfspr_(const int regno)
{
{
  int ofs = regno % MAX_SPRS_PER_GRP;
 
 
 
  regno /= MAX_SPRS_PER_GRP;
 
  regno += ofs;
 
 
 
  /* CZ 21/06/01 ... the debugger wants to do this! */
  /* CZ 21/06/01 ... the debugger wants to do this! */
  if(GlobalMode)
 
    {
    {
      extern unsigned long pc;
      extern unsigned long pc;
 
 
      if(regno == SPR_PC)
      if(regno == SPR_PC)
        return pc;
        return pc;
Line 140... Line 164...
 
 
  /* MM: l.rfe, for example, temporarly disables
  /* MM: l.rfe, for example, temporarly disables
     exceptions.  We will make it appear as SR bit
     exceptions.  We will make it appear as SR bit
     is set.  */
     is set.  */
  if (regno == SPR_SR && temp_disable_except > 0)
  if (regno == SPR_SR && temp_disable_except > 0)
    return sprs[regno] | SPR_SR_EXR;
    return sprs[regno] & ~SPR_SR_EXR;
  /*  printf("mfspr(%x)%x\n", regno, sprs[regno]); */
  /*  printf("mfspr(%x)%x\n", regno, sprs[regno]); */
 
 
  if (regno < MAX_SPRS)
  if (regno < MAX_SPRS)
    return sprs[regno];
    return sprs[regno];
  else {
  else {
    printf("\nABORT: read out of SPR range\n");
    printf("\nABORT: read out of SPR range %08X\n", regno);
    cont_run = 0;
    cont_run = 0;
  }
  }
 
 
  return 0;
  return 0;
}
}
 
 
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
void setsprbit(int regno, int bitnum, unsigned long bitvalue)
inline void
 
setsprbit(const int regno, const int bitnum, const unsigned long bitvalue)
{
{
  sprword mask;
  sprword mask;
  sprword regvalue = mfspr(regno);
  sprword regvalue = mfspr(regno);
 
 
  mask = ~(1 << bitnum);
  mask = ~(1 << bitnum);
Line 167... Line 191...
 
 
  return;
  return;
}
}
 
 
/* Get a specific bit from SPR. */
/* Get a specific bit from SPR. */
int getsprbit(int regno, int bitnum)
inline int
 
getsprbit(const int regno, const int bitnum)
{
{
  sprword regvalue = mfspr(regno);
  sprword regvalue = mfspr(regno);
 
 
  return (regvalue >> bitnum) & 0x1;
  return (regvalue >> bitnum) & 0x1;
}
}
 
 
/* Set specific SPR bit(s) identified by mask. */
/* Set specific SPR bit(s) identified by mask. */
void setsprbits(int regno, unsigned long mask, unsigned long value)
inline void
 
setsprbits(const int regno, const unsigned long mask, const unsigned long value)
{
{
  sprword regvalue = mfspr(regno);
  sprword regvalue = mfspr(regno);
  sprword shifted = 0x0;
  sprword shifted = 0x0;
  int m, v = 0;
  int m, v = 0;
 
 
Line 196... Line 222...
 
 
  return;
  return;
}
}
 
 
/* Get specific SPR bit(s) identified by mask. */
/* Get specific SPR bit(s) identified by mask. */
unsigned long getsprbits(int regno, unsigned long mask)
inline unsigned long
 
getsprbits(const int regno, const unsigned long mask)
{
{
  sprword regvalue = mfspr(regno);
  sprword regvalue = mfspr(regno);
  sprword shifted = 0x0;
  sprword shifted = 0x0;
  int m, v = 0;
  int m, v = 0;
 
 
Line 213... Line 240...
    }
    }
 
 
  return shifted;
  return shifted;
}
}
 
 
 
/* Get specific SPR bit(s) identified by mask. */
 
inline unsigned long
 
testsprbits(const int regno, const unsigned long mask)
 
{
 
  sprword regvalue = mfspr(regno);
 
  return regvalue & mask;
 
}
 
 
/* Show status of important SPRs. */
/* Show status of important SPRs. */
void sprs_status()
void sprs_status()
{
{
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.