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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [or1ksim/] [cpu/] [or1k/] [sprs.h] - Blame information for rev 1765

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 oraddr_t pcprev;
43 517 markom
 
44
  switch (regno) {
45
  case SPR_NPC:
46 1432 nogj
    return cpu_state.pc;
47 517 markom
  case SPR_PPC:
48
    return pcprev;
49 728 markom
  case SPR_TTCR:
50
    return spr_read_ttcr();
51 517 markom
  default:
52
    /* Links to GPRS */
53
    if(regno >= 0x0400 && regno < 0x0420)
54 1432 nogj
      return cpu_state.reg[regno - 0x0400];
55 517 markom
    else if (regno < MAX_SPRS)
56 1432 nogj
      return cpu_state.sprs[regno];
57 517 markom
  }
58
  if (config.sim.verbose)
59 997 markom
    PRINTF ("WARNING: read out of SPR range %08X\n", regno);
60 517 markom
  return 0;
61
}
62 518 markom
 
63
/* Set specific SPR bit(s) identified by mask. */
64
static inline void
65
setsprbits(const int regno, const unsigned long mask, const unsigned long value)
66
{
67 1442 nogj
  sprword regvalue = cpu_state.sprs[regno];
68 518 markom
  sprword shifted = 0x0;
69
  int m, v = 0;
70
 
71
  /* m counts bits in valuemask */
72
  /* v counts bits in value */
73
  for (m = 0; m < 32; m++)
74
    if ((mask >> m) & 0x1) {
75
      shifted |= ((value >> v) & 0x1) << m;
76
      v++;
77
    }
78
 
79 997 markom
  /* PRINTF("oldvalue %x setsprbits(%x, %x, %x)  shifted %x", regvalue, regno, mask, value, shifted); */
80 1442 nogj
  cpu_state.sprs[regno] = (regvalue & ~mask) | shifted;
81 518 markom
}
82
 
83
/* Get specific SPR bit(s) identified by mask. */
84
static inline unsigned long
85
getsprbits(const int regno, const unsigned long mask)
86
{
87 1442 nogj
  sprword regvalue = cpu_state.sprs[regno];
88 518 markom
  sprword shifted = 0x0;
89
  int m, v = 0;
90
 
91
  /* m counts bits in valuemask */
92
  /* v counts bits in regvalue */
93
  for (m = 0; m < 32; m++)
94
    if ((mask >> m) & 0x1) {
95
      shifted |= ((regvalue >> m) & 0x1) << v;
96
      v++;
97
    }
98
 
99
  return shifted;
100
}
101
 
102
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
103
static inline void
104
setsprbit(const int regno, const int bitnum, const unsigned long bitvalue)
105
{
106
  sprword mask;
107 1442 nogj
  sprword regvalue = cpu_state.sprs[regno];
108 518 markom
 
109
  mask = ~(1 << bitnum);
110
 
111 1442 nogj
  cpu_state.sprs[regno] = (regvalue & mask) | ((bitvalue & 0x1) << bitnum);
112 518 markom
 
113
  return;
114
}
115
 
116
/* Get a specific bit from SPR. */
117
static inline int
118
getsprbit(const int regno, const int bitnum)
119
{
120 1442 nogj
  sprword regvalue = cpu_state.sprs[regno];
121 518 markom
 
122
  return (regvalue >> bitnum) & 0x1;
123
}
124
 
125
/* Get specific SPR bit(s) identified by mask. */
126
static inline unsigned long
127
testsprbits(const int regno, const unsigned long mask)
128
{
129 1442 nogj
  sprword regvalue = cpu_state.sprs[regno];
130 518 markom
  return regvalue & mask;
131
}
132
 

powered by: WebSVN 2.1.0

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