/* sprs.h -- OR1K architecture specific special-purpose registers
|
/* sprs.h -- OR1K architecture specific special-purpose registers
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
(at your option) any later version.
|
(at your option) any later version.
|
|
|
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
GNU General Public License for more details.
|
|
|
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. */
|
|
|
#include "spr_defs.h"
|
#include "spr_defs.h"
|
|
|
typedef unsigned long sprword;
|
typedef unsigned long sprword;
|
|
|
/* Prototypes */
|
/* Prototypes */
|
inline void mtspr(uint16_t regno, const sprword value);
|
inline void mtspr(uint16_t regno, const sprword value);
|
static inline sprword mfspr_(const uint16_t regno);
|
static inline sprword mfspr_(const uint16_t regno);
|
extern sprword sprs[MAX_SPRS];
|
extern sprword sprs[MAX_SPRS];
|
#define mfspr(regno) mfspr_(regno)
|
#define mfspr(regno) mfspr_(regno)
|
|
|
static inline void setsprbit(const int regno, const int bitnum, const unsigned long bitvalue);
|
static inline void setsprbit(const int regno, const int bitnum, const unsigned long bitvalue);
|
static inline int getsprbit(const int regno, const int bitnum);
|
static inline int getsprbit(const int regno, const int bitnum);
|
void sprs_status();
|
void sprs_status();
|
|
|
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "tick.h"
|
#include "tick.h"
|
|
|
/* Ugly, but fast */
|
/* Ugly, but fast */
|
/* Get a specific SPR. */
|
/* Get a specific SPR. */
|
static inline sprword
|
static inline sprword
|
mfspr_(const uint16_t regno)
|
mfspr_(const uint16_t regno)
|
{
|
{
|
extern oraddr_t pcprev;
|
extern oraddr_t pcprev;
|
|
|
switch (regno) {
|
switch (regno) {
|
case SPR_NPC:
|
case SPR_NPC:
|
return cpu_state.pc;
|
return cpu_state.pc;
|
case SPR_PPC:
|
case SPR_PPC:
|
return pcprev;
|
return pcprev;
|
case SPR_TTCR:
|
case SPR_TTCR:
|
return spr_read_ttcr();
|
return spr_read_ttcr();
|
default:
|
default:
|
/* Links to GPRS */
|
/* Links to GPRS */
|
if(regno >= 0x0400 && regno < 0x0420)
|
if(regno >= 0x0400 && regno < 0x0420)
|
return cpu_state.reg[regno - 0x0400];
|
return cpu_state.reg[regno - 0x0400];
|
else if (regno < MAX_SPRS)
|
else if (regno < MAX_SPRS)
|
return cpu_state.sprs[regno];
|
return cpu_state.sprs[regno];
|
}
|
}
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
PRINTF ("WARNING: read out of SPR range %08X\n", regno);
|
PRINTF ("WARNING: read out of SPR range %08X\n", regno);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/* Set specific SPR bit(s) identified by mask. */
|
/* Set specific SPR bit(s) identified by mask. */
|
static inline void
|
static inline void
|
setsprbits(const int regno, const unsigned long mask, const unsigned long value)
|
setsprbits(const int regno, const unsigned long mask, const unsigned long value)
|
{
|
{
|
sprword regvalue = cpu_state.sprs[regno];
|
sprword regvalue = cpu_state.sprs[regno];
|
sprword shifted = 0x0;
|
sprword shifted = 0x0;
|
int m, v = 0;
|
int m, v = 0;
|
|
|
/* m counts bits in valuemask */
|
/* m counts bits in valuemask */
|
/* v counts bits in value */
|
/* v counts bits in value */
|
for (m = 0; m < 32; m++)
|
for (m = 0; m < 32; m++)
|
if ((mask >> m) & 0x1) {
|
if ((mask >> m) & 0x1) {
|
shifted |= ((value >> v) & 0x1) << m;
|
shifted |= ((value >> v) & 0x1) << m;
|
v++;
|
v++;
|
}
|
}
|
|
|
/* PRINTF("oldvalue %x setsprbits(%x, %x, %x) shifted %x", regvalue, regno, mask, value, shifted); */
|
/* PRINTF("oldvalue %x setsprbits(%x, %x, %x) shifted %x", regvalue, regno, mask, value, shifted); */
|
cpu_state.sprs[regno] = (regvalue & ~mask) | shifted;
|
cpu_state.sprs[regno] = (regvalue & ~mask) | shifted;
|
}
|
}
|
|
|
/* Get specific SPR bit(s) identified by mask. */
|
/* Get specific SPR bit(s) identified by mask. */
|
static inline unsigned long
|
static inline unsigned long
|
getsprbits(const int regno, const unsigned long mask)
|
getsprbits(const int regno, const unsigned long mask)
|
{
|
{
|
sprword regvalue = cpu_state.sprs[regno];
|
sprword regvalue = cpu_state.sprs[regno];
|
sprword shifted = 0x0;
|
sprword shifted = 0x0;
|
int m, v = 0;
|
int m, v = 0;
|
|
|
/* m counts bits in valuemask */
|
/* m counts bits in valuemask */
|
/* v counts bits in regvalue */
|
/* v counts bits in regvalue */
|
for (m = 0; m < 32; m++)
|
for (m = 0; m < 32; m++)
|
if ((mask >> m) & 0x1) {
|
if ((mask >> m) & 0x1) {
|
shifted |= ((regvalue >> m) & 0x1) << v;
|
shifted |= ((regvalue >> m) & 0x1) << v;
|
v++;
|
v++;
|
}
|
}
|
|
|
return shifted;
|
return shifted;
|
}
|
}
|
|
|
/* 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. */
|
static inline void
|
static inline void
|
setsprbit(const int regno, const int bitnum, const unsigned long bitvalue)
|
setsprbit(const int regno, const int bitnum, const unsigned long bitvalue)
|
{
|
{
|
sprword mask;
|
sprword mask;
|
sprword regvalue = cpu_state.sprs[regno];
|
sprword regvalue = cpu_state.sprs[regno];
|
|
|
mask = ~(1 << bitnum);
|
mask = ~(1 << bitnum);
|
|
|
cpu_state.sprs[regno] = (regvalue & mask) | ((bitvalue & 0x1) << bitnum);
|
cpu_state.sprs[regno] = (regvalue & mask) | ((bitvalue & 0x1) << bitnum);
|
|
|
return;
|
return;
|
}
|
}
|
|
|
/* Get a specific bit from SPR. */
|
/* Get a specific bit from SPR. */
|
static inline int
|
static inline int
|
getsprbit(const int regno, const int bitnum)
|
getsprbit(const int regno, const int bitnum)
|
{
|
{
|
sprword regvalue = cpu_state.sprs[regno];
|
sprword regvalue = cpu_state.sprs[regno];
|
|
|
return (regvalue >> bitnum) & 0x1;
|
return (regvalue >> bitnum) & 0x1;
|
}
|
}
|
|
|
/* Get specific SPR bit(s) identified by mask. */
|
/* Get specific SPR bit(s) identified by mask. */
|
static inline unsigned long
|
static inline unsigned long
|
testsprbits(const int regno, const unsigned long mask)
|
testsprbits(const int regno, const unsigned long mask)
|
{
|
{
|
sprword regvalue = cpu_state.sprs[regno];
|
sprword regvalue = cpu_state.sprs[regno];
|
return regvalue & mask;
|
return regvalue & mask;
|
}
|
}
|
|
|
|
|