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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 1508

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 1350 nogj
#include "config.h"
26
 
27
#ifdef HAVE_INTTYPES_H
28
#include <inttypes.h>
29
#endif
30
 
31
#include "port.h"
32 23 lampret
#include "arch.h"
33 1350 nogj
#include "abstract.h"
34 479 markom
#include "sim-config.h"
35 1308 phoenix
#include "except.h"
36 1432 nogj
#include "opcode/or32.h"
37
#include "spr_defs.h"
38 1350 nogj
#include "execute.h"
39 1432 nogj
#include "sprs.h"
40 1402 nogj
#include "dcache_model.h"
41 1404 nogj
#include "icache_model.h"
42 1452 nogj
#include "debug.h"
43 23 lampret
 
44 1452 nogj
DECLARE_DEBUG_CHANNEL(immu);
45 1432 nogj
 
46 167 markom
extern int flag;
47 23 lampret
 
48 133 markom
int audio_cnt = 0;
49 123 markom
 
50 133 markom
static FILE *fo = 0;
51 23 lampret
/* Set a specific SPR with a value. */
52 1452 nogj
void
53 1508 nogj
mtspr(uint16_t regno, const uorreg_t value)
54 30 lampret
{
55 1508 nogj
  uorreg_t prev_val;
56 1452 nogj
 
57 728 markom
  regno %= MAX_SPRS;
58 1452 nogj
  prev_val = cpu_state.sprs[regno];
59 1432 nogj
  cpu_state.sprs[regno] = value;
60 133 markom
 
61
  /* MM: Register hooks.  */
62
  switch (regno) {
63
  case SPR_TTCR:
64 728 markom
    spr_write_ttcr (value);
65 133 markom
    break;
66 728 markom
  case SPR_TTMR:
67
    spr_write_ttmr (value);
68
    break;
69 1402 nogj
  /* Data cache simulateing stuff */
70
  case SPR_DCBPR:
71
    if(value) {
72 1486 nogj
      /* FIXME: The arch. manual says "DCBPR is written with the effective
73
       *        address" which suggests it is written with a _virtual_ address,
74
       *        but it seems that the cache sits behind the mmu.  How is this
75
       *        address translated then? */
76
      dc_simulate_read(value, value, 4);
77 1432 nogj
      cpu_state.sprs[SPR_DCBPR] = 0;
78 1402 nogj
    }
79
    break;
80
  case SPR_DCBFR:
81
    if(value != -1) {
82
      dc_inv(value);
83 1432 nogj
      cpu_state.sprs[SPR_DCBFR] = -1;
84 1402 nogj
    }
85
    break;
86
  case SPR_DCBIR:
87
    if(value != 0) {
88
      dc_inv(value);
89 1432 nogj
      cpu_state.sprs[SPR_DCBIR] = 0;
90 1402 nogj
    }
91
    break;
92
  case SPR_DCBWR:
93 1432 nogj
    cpu_state.sprs[SPR_DCBWR] = 0;
94 1402 nogj
    break;
95
  case SPR_DCBLR:
96 1432 nogj
    cpu_state.sprs[SPR_DCBLR] = 0;
97 1402 nogj
    break;
98 1404 nogj
  /* Instruction cache simulateing stuff */
99
  case SPR_ICBPR:
100
    if(value) {
101 1486 nogj
      /* FIXME: The arch. manual says "ICBPR is written with the effective
102
       *        address" which suggests it is written with a _virtual_ address,
103
       *        but it seems that the cache sits behind the mmu.  How is this
104
       *        address translated then? */
105
      ic_simulate_fetch(value, value);
106 1432 nogj
      cpu_state.sprs[SPR_ICBPR] = 0;
107 1404 nogj
    }
108
    break;
109
  case SPR_ICBIR:
110
    if(value) {
111
      ic_inv(value);
112 1432 nogj
      cpu_state.sprs[SPR_ICBIR] = 0;
113 1404 nogj
    }
114
    break;
115
  case SPR_ICBLR:
116 1432 nogj
    cpu_state.sprs[SPR_ICBLR] = 0;
117 1404 nogj
    break;
118 167 markom
  case SPR_SR:
119 728 markom
    /* Set internal flag also */
120
    if(value & SPR_SR_F) flag = 1;
121
    else flag = 0;
122 1432 nogj
    cpu_state.sprs[regno] |= SPR_SR_FO;
123 1452 nogj
#if DYNAMIC_EXECUTION
124
    if((value & SPR_SR_IME) && !(prev_val & SPR_SR_IME)) {
125
      TRACE_(immu)("IMMU just became enabled (%lli).\n", runtime.sim.cycles);
126
      recheck_immu(IMMU_GOT_ENABLED);
127
    } else if(!(value & SPR_SR_IME) && (prev_val & SPR_SR_IME)) {
128
      TRACE_(immu)("Remove counting of mmu hit delay with cycles (%lli)\n",
129
                   runtime.sim.cycles);
130
      recheck_immu(IMMU_GOT_DISABLED);
131
    }
132
#endif
133 167 markom
    break;
134 378 markom
  case SPR_NPC:
135 139 chris
    {
136 242 markom
      /* The debugger has redirected us to a new address */
137
      /* This is usually done to reissue an instruction
138
         which just caused a breakpoint exception. */
139 1432 nogj
      cpu_state.pc = value;
140 242 markom
 
141 479 markom
      if(!value && config.sim.verbose)
142 997 markom
        PRINTF("WARNING: PC just set to 0!\n");
143 242 markom
 
144
      /* Clear any pending delay slot jumps also */
145 1432 nogj
      cpu_state.delay_insn = 0;
146 479 markom
      pcnext = value + 4;
147 139 chris
    }
148 242 markom
    break;
149 728 markom
  case 0xFFFD:
150
    fo = fopen ("audiosim.pcm", "wb+");
151 997 markom
    if (!fo) PRINTF("Cannot open audiosim.pcm\n");
152
    PRINTF("Audio opened.\n");
153 728 markom
    break;
154
  case 0xFFFE:
155 997 markom
    if (!fo) PRINTF("audiosim.pcm not opened\n");
156 728 markom
    fputc (value & 0xFF, fo);
157
    if ((audio_cnt % 1024) == 0)
158 997 markom
      PRINTF("%i\n", audio_cnt);
159 728 markom
    audio_cnt++;
160
    break;
161
  case 0xFFFF:
162
    fclose(fo);
163 997 markom
    PRINTF("Audio closed.\n");
164 1471 nogj
    sim_done();
165 728 markom
    break;
166 1446 nogj
  case SPR_PMR:
167
    /* PMR[SDF] and PMR[DCGE] are ignored completely. */
168
    if (value & SPR_PMR_SUME) {
169
      PRINTF ("SUSPEND: PMR[SUME] bit was set.\n");
170 1471 nogj
      sim_done();
171 1446 nogj
    }
172
    break;
173 479 markom
  default:
174 886 simons
    /* Mask reseved bits in DTLBMR and DTLBMR registers */
175
    if ( (regno >= SPR_DTLBMR_BASE(0)) && (regno < SPR_DTLBTR_LAST(3))) {
176
      if((regno & 0xff) < 0x80)
177 1432 nogj
        cpu_state.sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
178 886 simons
                              (value & (SPR_DTLBMR_V | SPR_DTLBMR_PL1 | SPR_DTLBMR_CID | SPR_DTLBMR_LRU));
179
      else
180 1432 nogj
        cpu_state.sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
181 886 simons
                              (value & (SPR_DTLBTR_CC | SPR_DTLBTR_CI | SPR_DTLBTR_WBC | SPR_DTLBTR_WOM |
182
                              SPR_DTLBTR_A | SPR_DTLBTR_D | SPR_DTLBTR_URE | SPR_DTLBTR_UWE | SPR_DTLBTR_SRE |
183
                              SPR_DTLBTR_SWE));
184
    }
185
 
186
    /* Mask reseved bits in ITLBMR and ITLBMR registers */
187
    if ( (regno >= SPR_ITLBMR_BASE(0)) && (regno < SPR_ITLBTR_LAST(3))) {
188 1452 nogj
      TRACE_(immu)("Writting to an mmu way (reg: %"PRIx16", value: %"PRIx32")\n",
189
                   regno, value);
190 886 simons
      if((regno & 0xff) < 0x80)
191 1432 nogj
        cpu_state.sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
192 886 simons
                              (value & (SPR_ITLBMR_V | SPR_ITLBMR_PL1 | SPR_ITLBMR_CID | SPR_ITLBMR_LRU));
193
      else
194 1432 nogj
        cpu_state.sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
195 886 simons
                              (value & (SPR_ITLBTR_CC | SPR_ITLBTR_CI | SPR_ITLBTR_WBC | SPR_ITLBTR_WOM |
196
                              SPR_ITLBTR_A | SPR_ITLBTR_D | SPR_ITLBTR_SXE | SPR_ITLBTR_UXE));
197 1452 nogj
 
198
#if DYNAMIC_EXECUTION
199
      if(cpu_state.sprs[SPR_SR] & SPR_SR_IME) {
200
        /* The immu got reconfigured.  Recheck if the current page in execution
201
         * is resident in the immu ways.  This check would be done during the
202
         * instruction fetch but since the dynamic execution model does not do
203
         * instruction fetchs, do it now. */
204
        recheck_immu(0);
205
      }
206
#endif
207 886 simons
    }
208 1432 nogj
 
209 479 markom
    /* Links to GPRS */
210 728 markom
    if(regno >= 0x0400 && regno < 0x0420) {
211 1432 nogj
      cpu_state.reg[regno - 0x0400] = value;
212 728 markom
    }
213 479 markom
    break;
214 378 markom
  }
215 23 lampret
}
216
 
217 1508 nogj
/* Get a specific SPR. */
218
uorreg_t mfspr(const uint16_t regno)
219
{
220
  extern oraddr_t pcprev;
221
 
222
  switch (regno) {
223
  case SPR_NPC:
224
    return cpu_state.pc;
225
  case SPR_PPC:
226
    return pcprev;
227
  case SPR_TTCR:
228
    return spr_read_ttcr();
229
  default:
230
    /* Links to GPRS */
231
    if(regno >= 0x0400 && regno < 0x0420)
232
      return cpu_state.reg[regno - 0x0400];
233
    else if (regno < MAX_SPRS)
234
      return cpu_state.sprs[regno];
235
  }
236
  if (config.sim.verbose)
237
    PRINTF ("WARNING: read out of SPR range %08X\n", regno);
238
  return 0;
239
}
240
 
241 30 lampret
/* Show status of important SPRs. */
242 1508 nogj
void sprs_status(void)
243 30 lampret
{
244 1508 nogj
  PRINTF("VR   : 0x%"PRIxREG"  UPR  : 0x%"PRIxREG"\n", cpu_state.sprs[SPR_VR],
245
         cpu_state.sprs[SPR_UPR]);
246
  PRINTF("SR   : 0x%"PRIxREG"\n", cpu_state.sprs[SPR_SR]);
247
  PRINTF("MACLO: 0x%"PRIxREG"  MACHI: 0x%"PRIxREG"\n",
248
         cpu_state.sprs[SPR_MACLO], cpu_state.sprs[SPR_MACHI]);
249
  PRINTF("EPCR0: 0x%"PRIxADDR"  EPCR1: 0x%"PRIxADDR"\n",
250
         cpu_state.sprs[SPR_EPCR_BASE], cpu_state.sprs[SPR_EPCR_BASE+1]);
251
  PRINTF("EEAR0: 0x%"PRIxADDR"  EEAR1: 0x%"PRIxADDR"\n",
252
         cpu_state.sprs[SPR_EEAR_BASE], cpu_state.sprs[SPR_EEAR_BASE+1]);
253
  PRINTF("ESR0 : 0x%"PRIxREG"  ESR1 : 0x%"PRIxREG"\n",
254
         cpu_state.sprs[SPR_ESR_BASE], cpu_state.sprs[SPR_ESR_BASE+1]);
255
  PRINTF("TTMR : 0x%"PRIxREG"  TTCR : 0x%"PRIxREG"\n",
256
         cpu_state.sprs[SPR_TTMR], cpu_state.sprs[SPR_TTCR]);
257
  PRINTF("PICMR: 0x%"PRIxREG"  PICSR: 0x%"PRIxREG"\n",
258
         cpu_state.sprs[SPR_PICMR], cpu_state.sprs[SPR_PICSR]);
259
  PRINTF("PPC:   0x%"PRIxADDR"  NPC   : 0x%"PRIxADDR"\n",
260
         cpu_state.sprs[SPR_PPC], cpu_state.sprs[SPR_NPC]);
261 133 markom
}

powered by: WebSVN 2.1.0

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