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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc1/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Diff between revs 28 and 30

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

Rev 28 Rev 30
Line 15... Line 15...
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
/* Most of the general OR1K architecture simulation (not specific
 
   to OR32 or OR16 ISA) is done in this file. */
 
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
 
 
#include "arch.h"
#include "arch.h"
#include "sprs.h"
#include "sprs.h"
 
 
extern int cont_run;
extern int cont_run;
 
 
sprword sprs[MAX_SPRS];
static sprword sprs[MAX_SPRS];
 
 
/* Set a specific SPR with a value. */
/* Set a specific SPR with a value. */
 
void mtspr(int regno, sprword value)
void mtsr(int regno, sprword value)
 
{
{
 
        int ofs = regno % MAX_SPRS_PER_GRP;
 
 
 
        regno /= MAX_SPRS_PER_GRP;
 
        regno += ofs;
 
 
        if (regno < MAX_SPRS)
        if (regno < MAX_SPRS)
                sprs[regno] = value;
                sprs[regno] = value;
        else {
        else {
                printf("\nEXCEPTION: write out of SPR's range\n");
                printf("\nABORT: write out of SPR range\n");
                cont_run = 0;
                cont_run = 0;
        }
        }
 
 
        return;
        return;
}
}
 
 
/* Get a specific SPR. */
/* Get a specific SPR. */
 
sprword mfspr(int regno)
sprword mfsr(int regno)
 
{
{
 
        int ofs = regno % MAX_SPRS_PER_GRP;
 
 
 
        regno /= MAX_SPRS_PER_GRP;
 
        regno += ofs;
 
 
        if (regno < MAX_SPRS)
        if (regno < MAX_SPRS)
                return sprs[regno];
                return sprs[regno];
        else {
        else {
                printf("\nEXCEPTION: read out of SPR's range\n");
                printf("\nABORT: read out of SPR range\n");
                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)
void setsprbit(int regno, int bitnum, unsigned long bitvalue)
{
{
        sprword mask;
        sprword mask;
        sprword regvalue = mfsr(regno);
        sprword regvalue = mfspr(regno);
 
 
        mask = ~(1 << bitnum);
        mask = ~(1 << bitnum);
 
 
        mtsr(regno, (regvalue & mask) | ((bitvalue & 0x1) << bitnum));
        mtspr(regno, (regvalue & mask) | ((bitvalue & 0x1) << bitnum));
 
 
        return;
        return;
}
}
 
 
/* Get a specific bit from SPR. */
/* Get a specific bit from SPR. */
 
 
int getsprbit(int regno, int bitnum)
int getsprbit(int regno, int bitnum)
{
{
        sprword regvalue = mfsr(regno);
        sprword regvalue = mfspr(regno);
 
 
        return (regvalue >> bitnum) & 0x1;
        return (regvalue >> bitnum) & 0x1;
}
}
 
 
 No newline at end of file
 No newline at end of file
 
/* Show status of important SPRs. */
 
void sprs_status()
 
{
 
        printf("VR   : 0x%.8x  MPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_MPR));
 
        printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
 
        printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
 
        printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
 
        printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
 
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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