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 511

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

powered by: WebSVN 2.1.0

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