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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_50/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 479

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 479 markom
#include "sim-config.h"
29 23 lampret
 
30 133 markom
extern int cont_run;   /* defined in toplevel.c */
31
extern int tt_stopped; /* defined in tick.c */
32 167 markom
extern int flag;
33 23 lampret
 
34 167 markom
sprword sprs[MAX_SPRS];
35 23 lampret
 
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 479 markom
  extern unsigned long reg[32];
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 381 markom
    printf("MTSPR(0x1234, 0x%x);\n", value);
77 133 markom
    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 450 simons
    sprs[SPR_SR] = value | SPR_SR_EXR; /* Exceptions are allways enabled */
97 167 markom
    break;
98
  case SPR_EPCR_BASE:
99
    if((value & 0xffffff00) == 0x00020600)
100
      {
101
        printf("SIMON: EPCR = ext_int\n");
102
        cont_run = 0;
103
      }
104
    break;
105 378 markom
  case SPR_NPC:
106 139 chris
    {
107
      extern unsigned long pc;
108 153 chris
      extern unsigned long pcnext;
109
      extern int delay_insn;
110
      extern unsigned long pcdelay;
111 242 markom
 
112 479 markom
      clear_pending_exception ();
113
 
114 242 markom
      /* The debugger has redirected us to a new address */
115
      /* This is usually done to reissue an instruction
116
         which just caused a breakpoint exception. */
117 479 markom
      pc = value;
118 242 markom
 
119 479 markom
      if(!value && config.sim.verbose)
120 242 markom
        printf("WARNING: PC just set to 0!\n");
121
 
122
      /* Clear any pending delay slot jumps also */
123
      delay_insn = 0;
124 479 markom
      pcnext = value + 4;
125 139 chris
    }
126 242 markom
    break;
127 479 markom
  default:
128
    /* Links to GPRS */
129
    if(regno >= 0x0400 && regno < 0x0420)
130
      reg[regno - 0x0400] = value;
131
    break;
132 378 markom
  }
133
 
134
  if (regno < MAX_SPRS)
135
    sprs[regno] = value;
136 479 markom
  else if (config.sim.verbose)
137
    printf("WARNING: write out of SPR range %08X\n", regno);
138 23 lampret
}
139
 
140
/* Get a specific SPR. */
141 167 markom
inline sprword
142
mfspr_(const int regno)
143 30 lampret
{
144 479 markom
  extern unsigned long reg[32];
145
  extern unsigned long pc;
146
  extern unsigned long pcprev;
147
 
148
  switch (regno) {
149
  case SPR_NPC:
150
    return pc;
151
  case SPR_PPC:
152
    return pcprev;
153
  case SPR_SR:
154
    /* Exceptions are always enabled */
155 464 simons
    return sprs[regno] | SPR_SR_EXR;
156 23 lampret
 
157 479 markom
 
158
  default:
159
    /* Links to GPRS */
160
    if(regno >= 0x0400 && regno < 0x0420)
161
      return reg[regno - 0x0400];
162
  }
163 378 markom
  if (regno < MAX_SPRS)
164
    return sprs[regno];
165 479 markom
 
166
  if (config.sim.verbose)
167
    printf ("WARNING: read out of SPR range %08X\n", regno);
168 378 markom
  return 0;
169 23 lampret
}
170
 
171
/* Set a specific bit from SPR. LSB in a word is numbered zero. */
172 167 markom
inline void
173
setsprbit(const int regno, const int bitnum, const unsigned long bitvalue)
174 23 lampret
{
175 133 markom
  sprword mask;
176
  sprword regvalue = mfspr(regno);
177
 
178
  mask = ~(1 << bitnum);
179
 
180
  mtspr(regno, (regvalue & mask) | ((bitvalue & 0x1) << bitnum));
181
 
182
  return;
183 23 lampret
}
184
 
185
/* Get a specific bit from SPR. */
186 167 markom
inline int
187
getsprbit(const int regno, const int bitnum)
188 23 lampret
{
189 133 markom
  sprword regvalue = mfspr(regno);
190 242 markom
 
191 133 markom
  return (regvalue >> bitnum) & 0x1;
192 23 lampret
}
193 30 lampret
 
194 63 lampret
/* Set specific SPR bit(s) identified by mask. */
195 167 markom
inline void
196
setsprbits(const int regno, const unsigned long mask, const unsigned long value)
197 63 lampret
{
198 133 markom
  sprword regvalue = mfspr(regno);
199
  sprword shifted = 0x0;
200
  int m, v = 0;
201
 
202
  /* m counts bits in valuemask */
203
  /* v counts bits in value */
204
  for (m = 0; m < 32; m++)
205
    if ((mask >> m) & 0x1) {
206
      shifted |= ((value >> v) & 0x1) << m;
207
      v++;
208
    }
209
 
210
  /* printf("oldvalue %x setsprbits(%x, %x, %x)  shifted %x", regvalue, regno, mask, value, shifted); */
211
  mtspr(regno, (regvalue & ~mask) | shifted);
212
 
213
  return;
214 63 lampret
}
215
 
216
/* Get specific SPR bit(s) identified by mask. */
217 167 markom
inline unsigned long
218
getsprbits(const int regno, const unsigned long mask)
219 63 lampret
{
220 133 markom
  sprword regvalue = mfspr(regno);
221
  sprword shifted = 0x0;
222
  int m, v = 0;
223
 
224
  /* m counts bits in valuemask */
225
  /* v counts bits in regvalue */
226
  for (m = 0; m < 32; m++)
227
    if ((mask >> m) & 0x1) {
228
      shifted |= ((regvalue >> m) & 0x1) << v;
229
      v++;
230
    }
231
 
232
  return shifted;
233 63 lampret
}
234
 
235 167 markom
/* Get specific SPR bit(s) identified by mask. */
236
inline unsigned long
237
testsprbits(const int regno, const unsigned long mask)
238
{
239
  sprword regvalue = mfspr(regno);
240
  return regvalue & mask;
241
}
242
 
243 30 lampret
/* Show status of important SPRs. */
244
void sprs_status()
245
{
246 133 markom
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
247
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
248
  printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
249
  printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
250
  printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
251
  printf("ESR0 : 0x%.8x  ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
252 292 lampret
  printf("TTMR : 0x%.8x  TTCR : 0x%.8x\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
253
  printf("PICMR: 0x%.8x  PICPR: 0x%.8x\n", mfspr(SPR_PICMR), mfspr(SPR_PICPR));
254
  printf("PICSR: 0x%.8x\n", mfspr(SPR_PICSR));
255 378 markom
  printf("PPC:   0x%.8x  NPC   : 0x%.8x\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
256 133 markom
}

powered by: WebSVN 2.1.0

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