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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc1/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 30

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 30 lampret
        regno /= MAX_SPRS_PER_GRP;
37
        regno += ofs;
38
 
39 23 lampret
        if (regno < MAX_SPRS)
40
                sprs[regno] = value;
41
        else {
42 30 lampret
                printf("\nABORT: write out of SPR range\n");
43 23 lampret
                cont_run = 0;
44
        }
45
 
46
        return;
47
}
48
 
49
/* Get a specific SPR. */
50 30 lampret
sprword mfspr(int regno)
51
{
52
        int ofs = regno % MAX_SPRS_PER_GRP;
53 23 lampret
 
54 30 lampret
        regno /= MAX_SPRS_PER_GRP;
55
        regno += ofs;
56
 
57 23 lampret
        if (regno < MAX_SPRS)
58
                return sprs[regno];
59
        else {
60 30 lampret
                printf("\nABORT: read out of SPR range\n");
61 23 lampret
                cont_run = 0;
62
        }
63
 
64
        return 0;
65
}
66
 
67
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
68
void setsprbit(int regno, int bitnum, unsigned long bitvalue)
69
{
70
        sprword mask;
71 30 lampret
        sprword regvalue = mfspr(regno);
72 23 lampret
 
73
        mask = ~(1 << bitnum);
74
 
75 30 lampret
        mtspr(regno, (regvalue & mask) | ((bitvalue & 0x1) << bitnum));
76 23 lampret
 
77
        return;
78
}
79
 
80
/* Get a specific bit from SPR. */
81
int getsprbit(int regno, int bitnum)
82
{
83 30 lampret
        sprword regvalue = mfspr(regno);
84 23 lampret
 
85
        return (regvalue >> bitnum) & 0x1;
86
}
87 30 lampret
 
88
/* Show status of important SPRs. */
89
void sprs_status()
90
{
91
        printf("VR   : 0x%.8x  MPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_MPR));
92
        printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
93
        printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
94
        printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
95
        printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
96
}

powered by: WebSVN 2.1.0

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