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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 381

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

powered by: WebSVN 2.1.0

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