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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_33/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 102

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

Line No. Rev Author Line
1 28 lampret
/* sprs.c -- Simulation of OR1K special-purpose registers
2 23 lampret
   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
#include <stdlib.h>
21
#include <stdio.h>
22
#include <string.h>
23
 
24
#include "arch.h"
25
#include "sprs.h"
26
 
27
extern int cont_run;
28
 
29 30 lampret
static sprword sprs[MAX_SPRS];
30 23 lampret
 
31
/* Set a specific SPR with a value. */
32 30 lampret
void mtspr(int regno, sprword value)
33
{
34
        int ofs = regno % MAX_SPRS_PER_GRP;
35 23 lampret
 
36 77 lampret
        if (regno == 0x1234)
37
                printf("MTSPR(0x1234, %x);\n", value);
38
 
39 30 lampret
        regno /= MAX_SPRS_PER_GRP;
40
        regno += ofs;
41
 
42 63 lampret
/*      printf("mtspr(%x, %x)\n", regno, value);
43
*/      if (regno < MAX_SPRS)
44 23 lampret
                sprs[regno] = value;
45
        else {
46 30 lampret
                printf("\nABORT: write out of SPR range\n");
47 23 lampret
                cont_run = 0;
48
        }
49
 
50
        return;
51
}
52
 
53
/* Get a specific SPR. */
54 30 lampret
sprword mfspr(int regno)
55
{
56
        int ofs = regno % MAX_SPRS_PER_GRP;
57 23 lampret
 
58 30 lampret
        regno /= MAX_SPRS_PER_GRP;
59
        regno += ofs;
60
 
61 63 lampret
/*      printf("mfspr(%x)%x\n", regno, sprs[regno]);
62
*/      if (regno < MAX_SPRS)
63 23 lampret
                return sprs[regno];
64
        else {
65 30 lampret
                printf("\nABORT: read out of SPR range\n");
66 23 lampret
                cont_run = 0;
67
        }
68
 
69
        return 0;
70
}
71
 
72
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
73
void setsprbit(int regno, int bitnum, unsigned long bitvalue)
74
{
75
        sprword mask;
76 30 lampret
        sprword regvalue = mfspr(regno);
77 23 lampret
 
78
        mask = ~(1 << bitnum);
79
 
80 30 lampret
        mtspr(regno, (regvalue & mask) | ((bitvalue & 0x1) << bitnum));
81 23 lampret
 
82
        return;
83
}
84
 
85
/* Get a specific bit from SPR. */
86
int getsprbit(int regno, int bitnum)
87
{
88 30 lampret
        sprword regvalue = mfspr(regno);
89 23 lampret
 
90
        return (regvalue >> bitnum) & 0x1;
91
}
92 30 lampret
 
93 63 lampret
/* Set specific SPR bit(s) identified by mask. */
94
void setsprbits(int regno, unsigned long mask, unsigned long value)
95
{
96
        sprword regvalue = mfspr(regno);
97
        sprword shifted = 0x0;
98
        int m, v = 0;
99
 
100
        /* m counts bits in valuemask */
101
        /* v counts bits in value */
102
        for (m = 0; m < 32; m++)
103
                if ((mask >> m) & 0x1) {
104
                        shifted |= ((value >> v) & 0x1) << m;
105
                        v++;
106
                }
107
 
108
/*      printf("oldvalue %x setsprbits(%x, %x, %x)  shifted %x", regvalue, regno, mask, value, shifted); */
109
        mtspr(regno, (regvalue & ~mask) | shifted);
110
 
111
        return;
112
}
113
 
114
/* Get specific SPR bit(s) identified by mask. */
115
unsigned long getsprbits(int regno, unsigned long mask)
116
{
117
        sprword regvalue = mfspr(regno);
118
        sprword shifted = 0x0;
119
        int m, v = 0;
120
 
121
        /* m counts bits in valuemask */
122
        /* v counts bits in regvalue */
123
        for (m = 0; m < 32; m++)
124
                if ((mask >> m) & 0x1) {
125
                        shifted |= ((regvalue >> m) & 0x1) << v;
126
                        v++;
127
                }
128
 
129
        return shifted;
130
}
131
 
132 30 lampret
/* Show status of important SPRs. */
133
void sprs_status()
134
{
135 102 lampret
        printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
136 30 lampret
        printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
137
        printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
138
        printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
139
        printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
140 63 lampret
        printf("ESR0 : 0x%.8x  ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
141 30 lampret
}

powered by: WebSVN 2.1.0

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