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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [cpu/] [or1k/] [sprs.h] - Blame information for rev 1782

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 lampret
/* sprs.h -- OR1K architecture specific special-purpose registers
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20 64 lampret
#include "spr_defs.h"
21
 
22 23 lampret
typedef unsigned long sprword;
23
 
24 30 lampret
/* Prototypes */
25 1350 nogj
inline void mtspr(uint16_t regno, const sprword value);
26
static inline sprword mfspr_(const uint16_t regno);
27 167 markom
extern sprword sprs[MAX_SPRS];
28
#define mfspr(regno) mfspr_(regno)
29
 
30 518 markom
static inline void setsprbit(const int regno, const int bitnum, const unsigned long bitvalue);
31
static inline int getsprbit(const int regno, const int bitnum);
32 30 lampret
void sprs_status();
33 517 markom
 
34
#include "sim-config.h"
35 728 markom
#include "tick.h"
36 517 markom
 
37
/* Ugly, but fast */
38
/* Get a specific SPR. */
39
static inline sprword
40 1350 nogj
mfspr_(const uint16_t regno)
41 517 markom
{
42 1354 phoenix
  extern uorreg_t reg[32];
43
  extern oraddr_t pcprev;
44 517 markom
  extern sprword sprs[MAX_SPRS];
45
 
46
  switch (regno) {
47
  case SPR_NPC:
48
    return pc;
49
  case SPR_PPC:
50
    return pcprev;
51 728 markom
  case SPR_TTCR:
52
    return spr_read_ttcr();
53 517 markom
  default:
54
    /* Links to GPRS */
55
    if(regno >= 0x0400 && regno < 0x0420)
56
      return reg[regno - 0x0400];
57
    else if (regno < MAX_SPRS)
58
      return sprs[regno];
59
  }
60
  if (config.sim.verbose)
61 997 markom
    PRINTF ("WARNING: read out of SPR range %08X\n", regno);
62 517 markom
  return 0;
63
}
64 518 markom
 
65
/* Set specific SPR bit(s) identified by mask. */
66
static inline void
67
setsprbits(const int regno, const unsigned long mask, const unsigned long value)
68
{
69
  sprword regvalue = mfspr(regno);
70
  sprword shifted = 0x0;
71
  int m, v = 0;
72
 
73
  /* m counts bits in valuemask */
74
  /* v counts bits in value */
75
  for (m = 0; m < 32; m++)
76
    if ((mask >> m) & 0x1) {
77
      shifted |= ((value >> v) & 0x1) << m;
78
      v++;
79
    }
80
 
81 997 markom
  /* PRINTF("oldvalue %x setsprbits(%x, %x, %x)  shifted %x", regvalue, regno, mask, value, shifted); */
82 518 markom
  mtspr(regno, (regvalue & ~mask) | shifted);
83
}
84
 
85
/* Get specific SPR bit(s) identified by mask. */
86
static inline unsigned long
87
getsprbits(const int regno, const unsigned long mask)
88
{
89
  sprword regvalue = mfspr(regno);
90
  sprword shifted = 0x0;
91
  int m, v = 0;
92
 
93
  /* m counts bits in valuemask */
94
  /* v counts bits in regvalue */
95
  for (m = 0; m < 32; m++)
96
    if ((mask >> m) & 0x1) {
97
      shifted |= ((regvalue >> m) & 0x1) << v;
98
      v++;
99
    }
100
 
101
  return shifted;
102
}
103
 
104
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
105
static inline void
106
setsprbit(const int regno, const int bitnum, const unsigned long bitvalue)
107
{
108
  sprword mask;
109
  sprword regvalue = mfspr(regno);
110
 
111
  mask = ~(1 << bitnum);
112
 
113
  mtspr(regno, (regvalue & mask) | ((bitvalue & 0x1) << bitnum));
114
 
115
  return;
116
}
117
 
118
/* Get a specific bit from SPR. */
119
static inline int
120
getsprbit(const int regno, const int bitnum)
121
{
122
  sprword regvalue = mfspr(regno);
123
 
124
  return (regvalue >> bitnum) & 0x1;
125
}
126
 
127
/* Get specific SPR bit(s) identified by mask. */
128
static inline unsigned long
129
testsprbits(const int regno, const unsigned long mask)
130
{
131
  sprword regvalue = mfspr(regno);
132
  return regvalue & mask;
133
}
134
 

powered by: WebSVN 2.1.0

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