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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_65/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 1765

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 1350 nogj
mtspr(uint16_t regno, const sprword value)
54 30 lampret
{
55 1452 nogj
  sprword prev_val;
56
 
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
      dc_simulate_read(value, 4);
73 1432 nogj
      cpu_state.sprs[SPR_DCBPR] = 0;
74 1402 nogj
    }
75
    break;
76
  case SPR_DCBFR:
77
    if(value != -1) {
78
      dc_inv(value);
79 1432 nogj
      cpu_state.sprs[SPR_DCBFR] = -1;
80 1402 nogj
    }
81
    break;
82
  case SPR_DCBIR:
83
    if(value != 0) {
84
      dc_inv(value);
85 1432 nogj
      cpu_state.sprs[SPR_DCBIR] = 0;
86 1402 nogj
    }
87
    break;
88
  case SPR_DCBWR:
89 1432 nogj
    cpu_state.sprs[SPR_DCBWR] = 0;
90 1402 nogj
    break;
91
  case SPR_DCBLR:
92 1432 nogj
    cpu_state.sprs[SPR_DCBLR] = 0;
93 1402 nogj
    break;
94 1404 nogj
  /* Instruction cache simulateing stuff */
95
  case SPR_ICBPR:
96
    if(value) {
97
      ic_simulate_fetch(value);
98 1432 nogj
      cpu_state.sprs[SPR_ICBPR] = 0;
99 1404 nogj
    }
100
    break;
101
  case SPR_ICBIR:
102
    if(value) {
103
      ic_inv(value);
104 1432 nogj
      cpu_state.sprs[SPR_ICBIR] = 0;
105 1404 nogj
    }
106
    break;
107
  case SPR_ICBLR:
108 1432 nogj
    cpu_state.sprs[SPR_ICBLR] = 0;
109 1404 nogj
    break;
110 167 markom
  case SPR_SR:
111 728 markom
    /* Set internal flag also */
112
    if(value & SPR_SR_F) flag = 1;
113
    else flag = 0;
114 1432 nogj
    cpu_state.sprs[regno] |= SPR_SR_FO;
115 1452 nogj
#if DYNAMIC_EXECUTION
116
    if((value & SPR_SR_IME) && !(prev_val & SPR_SR_IME)) {
117
      TRACE_(immu)("IMMU just became enabled (%lli).\n", runtime.sim.cycles);
118
      recheck_immu(IMMU_GOT_ENABLED);
119
    } else if(!(value & SPR_SR_IME) && (prev_val & SPR_SR_IME)) {
120
      TRACE_(immu)("Remove counting of mmu hit delay with cycles (%lli)\n",
121
                   runtime.sim.cycles);
122
      recheck_immu(IMMU_GOT_DISABLED);
123
    }
124
#endif
125 167 markom
    break;
126 378 markom
  case SPR_NPC:
127 139 chris
    {
128 242 markom
      /* The debugger has redirected us to a new address */
129
      /* This is usually done to reissue an instruction
130
         which just caused a breakpoint exception. */
131 1432 nogj
      cpu_state.pc = value;
132 242 markom
 
133 479 markom
      if(!value && config.sim.verbose)
134 997 markom
        PRINTF("WARNING: PC just set to 0!\n");
135 242 markom
 
136
      /* Clear any pending delay slot jumps also */
137 1432 nogj
      cpu_state.delay_insn = 0;
138 479 markom
      pcnext = value + 4;
139 139 chris
    }
140 242 markom
    break;
141 728 markom
  case 0xFFFD:
142
    fo = fopen ("audiosim.pcm", "wb+");
143 997 markom
    if (!fo) PRINTF("Cannot open audiosim.pcm\n");
144
    PRINTF("Audio opened.\n");
145 728 markom
    break;
146
  case 0xFFFE:
147 997 markom
    if (!fo) PRINTF("audiosim.pcm not opened\n");
148 728 markom
    fputc (value & 0xFF, fo);
149
    if ((audio_cnt % 1024) == 0)
150 997 markom
      PRINTF("%i\n", audio_cnt);
151 728 markom
    audio_cnt++;
152
    break;
153
  case 0xFFFF:
154
    fclose(fo);
155 997 markom
    PRINTF("Audio closed.\n");
156 884 markom
    runtime.sim.cont_run = 0;
157 728 markom
    break;
158 1446 nogj
  case SPR_PMR:
159
    /* PMR[SDF] and PMR[DCGE] are ignored completely. */
160
    if (value & SPR_PMR_SUME) {
161
      PRINTF ("SUSPEND: PMR[SUME] bit was set.\n");
162
      runtime.sim.cont_run = 0;
163
    }
164
    break;
165 479 markom
  default:
166 886 simons
    /* Mask reseved bits in DTLBMR and DTLBMR registers */
167
    if ( (regno >= SPR_DTLBMR_BASE(0)) && (regno < SPR_DTLBTR_LAST(3))) {
168
      if((regno & 0xff) < 0x80)
169 1432 nogj
        cpu_state.sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
170 886 simons
                              (value & (SPR_DTLBMR_V | SPR_DTLBMR_PL1 | SPR_DTLBMR_CID | SPR_DTLBMR_LRU));
171
      else
172 1432 nogj
        cpu_state.sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
173 886 simons
                              (value & (SPR_DTLBTR_CC | SPR_DTLBTR_CI | SPR_DTLBTR_WBC | SPR_DTLBTR_WOM |
174
                              SPR_DTLBTR_A | SPR_DTLBTR_D | SPR_DTLBTR_URE | SPR_DTLBTR_UWE | SPR_DTLBTR_SRE |
175
                              SPR_DTLBTR_SWE));
176
    }
177
 
178
    /* Mask reseved bits in ITLBMR and ITLBMR registers */
179
    if ( (regno >= SPR_ITLBMR_BASE(0)) && (regno < SPR_ITLBTR_LAST(3))) {
180 1452 nogj
      TRACE_(immu)("Writting to an mmu way (reg: %"PRIx16", value: %"PRIx32")\n",
181
                   regno, value);
182 886 simons
      if((regno & 0xff) < 0x80)
183 1432 nogj
        cpu_state.sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
184 886 simons
                              (value & (SPR_ITLBMR_V | SPR_ITLBMR_PL1 | SPR_ITLBMR_CID | SPR_ITLBMR_LRU));
185
      else
186 1432 nogj
        cpu_state.sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
187 886 simons
                              (value & (SPR_ITLBTR_CC | SPR_ITLBTR_CI | SPR_ITLBTR_WBC | SPR_ITLBTR_WOM |
188
                              SPR_ITLBTR_A | SPR_ITLBTR_D | SPR_ITLBTR_SXE | SPR_ITLBTR_UXE));
189 1452 nogj
 
190
#if DYNAMIC_EXECUTION
191
      if(cpu_state.sprs[SPR_SR] & SPR_SR_IME) {
192
        /* The immu got reconfigured.  Recheck if the current page in execution
193
         * is resident in the immu ways.  This check would be done during the
194
         * instruction fetch but since the dynamic execution model does not do
195
         * instruction fetchs, do it now. */
196
        recheck_immu(0);
197
      }
198
#endif
199 886 simons
    }
200 1432 nogj
 
201 479 markom
    /* Links to GPRS */
202 728 markom
    if(regno >= 0x0400 && regno < 0x0420) {
203 1432 nogj
      cpu_state.reg[regno - 0x0400] = value;
204 728 markom
    }
205 479 markom
    break;
206 378 markom
  }
207 23 lampret
}
208
 
209 30 lampret
/* Show status of important SPRs. */
210
void sprs_status()
211
{
212 1308 phoenix
  PRINTF("VR   : 0x%.8lx  UPR  : 0x%.8lx\n", mfspr(SPR_VR), mfspr(SPR_UPR));
213
  PRINTF("SR   : 0x%.8lx\n", mfspr(SPR_SR));
214
  PRINTF("MACLO: 0x%.8lx  MACHI: 0x%.8lx\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
215
  PRINTF("EPCR0: 0x%.8lx  EPCR1: 0x%.8lx\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
216
  PRINTF("EEAR0: 0x%.8lx  EEAR1: 0x%.8lx\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
217
  PRINTF("ESR0 : 0x%.8lx  ESR1 : 0x%.8lx\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
218
  PRINTF("TTMR : 0x%.8lx  TTCR : 0x%.8lx\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
219
  PRINTF("PICMR: 0x%.8lx  PICSR: 0x%.8lx\n", mfspr(SPR_PICMR), mfspr(SPR_PICSR));
220
  PRINTF("PPC:   0x%.8lx  NPC   : 0x%.8lx\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
221 133 markom
}

powered by: WebSVN 2.1.0

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