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 464

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

powered by: WebSVN 2.1.0

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