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 28

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
/* Most of the general OR1K architecture simulation (not specific
21
   to OR32 or OR16 ISA) is done in this file. */
22
 
23
#include <stdlib.h>
24
#include <stdio.h>
25
#include <string.h>
26
 
27
#include "arch.h"
28
#include "sprs.h"
29
 
30
extern int cont_run;
31
 
32
sprword sprs[MAX_SPRS];
33
 
34
/* Set a specific SPR with a value. */
35
 
36
void mtsr(int regno, sprword value)
37
{
38
        if (regno < MAX_SPRS)
39
                sprs[regno] = value;
40
        else {
41
                printf("\nEXCEPTION: write out of SPR's range\n");
42
                cont_run = 0;
43
        }
44
 
45
        return;
46
}
47
 
48
/* Get a specific SPR. */
49
 
50
sprword mfsr(int regno)
51
{
52
        if (regno < MAX_SPRS)
53
                return sprs[regno];
54
        else {
55
                printf("\nEXCEPTION: read out of SPR's range\n");
56
                cont_run = 0;
57
        }
58
 
59
        return 0;
60
}
61
 
62
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
63
 
64
void setsprbit(int regno, int bitnum, unsigned long bitvalue)
65
{
66
        sprword mask;
67
        sprword regvalue = mfsr(regno);
68
 
69
        mask = ~(1 << bitnum);
70
 
71
        mtsr(regno, (regvalue & mask) | ((bitvalue & 0x1) << bitnum));
72
 
73
        return;
74
}
75
 
76
/* Get a specific bit from SPR. */
77
 
78
int getsprbit(int regno, int bitnum)
79
{
80
        sprword regvalue = mfsr(regno);
81
 
82
        return (regvalue >> bitnum) & 0x1;
83
}

powered by: WebSVN 2.1.0

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