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 183

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 167 markom
#include <errno.h>
24 23 lampret
 
25
#include "arch.h"
26
#include "sprs.h"
27 167 markom
#include "abstract.h"
28 23 lampret
 
29 133 markom
extern int cont_run;   /* defined in toplevel.c */
30
extern int tt_stopped; /* defined in tick.c */
31 167 markom
extern int flag;
32 183 chris
extern int GlobalMode; /* CZ 21/06/01 */
33 23 lampret
 
34 167 markom
sprword sprs[MAX_SPRS];
35 23 lampret
 
36 123 markom
int temp_disable_except = 0;
37 133 markom
int audio_cnt = 0;
38 123 markom
 
39 133 markom
static FILE *fo = 0;
40 23 lampret
/* Set a specific SPR with a value. */
41 167 markom
inline void
42
mtspr(const int regno, const sprword value)
43 30 lampret
{
44 133 markom
  int ofs = regno % MAX_SPRS_PER_GRP;
45 183 chris
  extern unsigned long pc_phy;
46 133 markom
 
47
  /* MM: Register hooks.  */
48
  switch (regno) {
49
  case 0xFFFD:
50
    fo = fopen ("audiosim.pcm", "wb+");
51
    if (!fo) printf("Cannot open audiosim.pcm\n");
52
    printf("Audio opened.\n");
53
    return;
54
  case 0xFFFE:
55
    if (!fo) printf("audiosim.pcm not opened\n");
56
    fputc (value & 0xFF, fo);
57
    if ((audio_cnt % 1024) == 0)
58
      printf("%i\n", audio_cnt);
59
    audio_cnt++;
60
    return;
61
  case 0xFFFF:
62
    fclose(fo);
63
    printf("Audio closed.\n");
64
    cont_run = 0;
65
    return;
66
  case SPR_TTMR:
67 183 chris
    /* CZ -- 04/09/01 Clear the interrupt in the PIC also... */
68
    /* If it's cleared now and it was set, then we need to fix it */
69
    if(~value & SPR_TTMR_IP & sprs[SPR_TTMR])
70
      setsprbit(SPR_PICSR, 3, 0);
71
    if (value & SPR_TTMR_M == 2) break;
72 133 markom
  case SPR_TTCR:
73
    tt_stopped = 0;
74
    break;
75
  case 0x1234:
76
    printf("MTSPR(0x1234, %x);\n", value);
77
    break;
78 167 markom
  case 0x1235:
79
    {
80
      FILE *f;
81
      if (!(f = fopen("stdout.txt", "a+")))
82
        {
83
          perror(strerror(errno));
84
          return;
85
        }
86
      fprintf(f, "%c", value);
87
      if (fclose(f))
88
        perror(strerror(errno));
89
    }
90
    break;
91
  case SPR_SR:
92
    if(value & SPR_SR_F)
93
      flag = 1;
94
    else
95
      flag = 0;
96
    break;
97
  case SPR_EPCR_BASE:
98
    if((value & 0xffffff00) == 0x00020600)
99
      {
100
        printf("SIMON: EPCR = ext_int\n");
101
        cont_run = 0;
102
      }
103
    break;
104 133 markom
  }
105 139 chris
 
106
  /* CZ 21/06/01 ... the debugger wants to do this! */
107
  if(GlobalMode)
108
    {
109
      extern unsigned long pc;
110 153 chris
      extern unsigned long pcnext;
111
      extern int delay_insn;
112
      extern unsigned long pcdelay;
113 139 chris
 
114
      if(regno == SPR_PC)
115
        {
116
          sprs[SPR_PC] = value;
117 153 chris
 
118
          /* The debugger has redirected us to a new address */
119
          /* This is usually done to reissue an instruction
120
             which just caused a breakpoint exception. */
121
          pcnext = value;
122
 
123
          if(!value)
124
            {
125
              printf("WARNING: Debugger just set us to 0!\n");
126
            }
127
 
128
          /* Clear any pending delay slot jumps also */
129
          delay_insn = 0;
130
          pcdelay = value+4;
131
 
132 139 chris
          return;
133
        }
134
    }
135
 
136 133 markom
  /*    printf("mtspr(%x, %x)\n", regno, value);
137
   */   if (regno < MAX_SPRS)
138
     sprs[regno] = value;
139
   else {
140 167 markom
     printf("\nABORT: write out of SPR range %08X\n", regno);
141 133 markom
     cont_run = 0;
142
   }
143 23 lampret
}
144
 
145
/* Get a specific SPR. */
146 167 markom
inline sprword
147
mfspr_(const int regno)
148 30 lampret
{
149 139 chris
  /* CZ 21/06/01 ... the debugger wants to do this! */
150 167 markom
  {
151
    extern unsigned long pc;
152
 
153
    if(regno == SPR_PC)
154
      return pc;
155
  }
156 139 chris
 
157 133 markom
  /* MM: l.rfe, for example, temporarly disables
158
     exceptions.  We will make it appear as SR bit
159
     is set.  */
160
  if (regno == SPR_SR && temp_disable_except > 0)
161 167 markom
    return sprs[regno] & ~SPR_SR_EXR;
162 133 markom
  /*  printf("mfspr(%x)%x\n", regno, sprs[regno]); */
163 23 lampret
 
164 133 markom
  if (regno < MAX_SPRS)
165
    return sprs[regno];
166
  else {
167 167 markom
    printf("\nABORT: read out of SPR range %08X\n", regno);
168 133 markom
    cont_run = 0;
169 167 markom
  }
170 133 markom
  return 0;
171 23 lampret
}
172
 
173
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
174 167 markom
inline void
175
setsprbit(const int regno, const int bitnum, const unsigned long bitvalue)
176 23 lampret
{
177 133 markom
  sprword mask;
178
  sprword regvalue = mfspr(regno);
179
 
180
  mask = ~(1 << bitnum);
181
 
182
  mtspr(regno, (regvalue & mask) | ((bitvalue & 0x1) << bitnum));
183
 
184
  return;
185 23 lampret
}
186
 
187
/* Get a specific bit from SPR. */
188 167 markom
inline int
189
getsprbit(const int regno, const int bitnum)
190 23 lampret
{
191 133 markom
  sprword regvalue = mfspr(regno);
192 23 lampret
 
193 133 markom
  return (regvalue >> bitnum) & 0x1;
194 23 lampret
}
195 30 lampret
 
196 63 lampret
/* Set specific SPR bit(s) identified by mask. */
197 167 markom
inline void
198
setsprbits(const int regno, const unsigned long mask, const unsigned long value)
199 63 lampret
{
200 133 markom
  sprword regvalue = mfspr(regno);
201
  sprword shifted = 0x0;
202
  int m, v = 0;
203
 
204
  /* m counts bits in valuemask */
205
  /* v counts bits in value */
206
  for (m = 0; m < 32; m++)
207
    if ((mask >> m) & 0x1) {
208
      shifted |= ((value >> v) & 0x1) << m;
209
      v++;
210
    }
211
 
212
  /* printf("oldvalue %x setsprbits(%x, %x, %x)  shifted %x", regvalue, regno, mask, value, shifted); */
213
  mtspr(regno, (regvalue & ~mask) | shifted);
214
 
215
  return;
216 63 lampret
}
217
 
218
/* Get specific SPR bit(s) identified by mask. */
219 167 markom
inline unsigned long
220
getsprbits(const int regno, const unsigned long mask)
221 63 lampret
{
222 133 markom
  sprword regvalue = mfspr(regno);
223
  sprword shifted = 0x0;
224
  int m, v = 0;
225
 
226
  /* m counts bits in valuemask */
227
  /* v counts bits in regvalue */
228
  for (m = 0; m < 32; m++)
229
    if ((mask >> m) & 0x1) {
230
      shifted |= ((regvalue >> m) & 0x1) << v;
231
      v++;
232
    }
233
 
234
  return shifted;
235 63 lampret
}
236
 
237 167 markom
/* Get specific SPR bit(s) identified by mask. */
238
inline unsigned long
239
testsprbits(const int regno, const unsigned long mask)
240
{
241
  sprword regvalue = mfspr(regno);
242
  return regvalue & mask;
243
}
244
 
245 30 lampret
/* Show status of important SPRs. */
246
void sprs_status()
247
{
248 133 markom
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
249
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
250
  printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
251
  printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
252
  printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
253
  printf("ESR0 : 0x%.8x  ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
254
}

powered by: WebSVN 2.1.0

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