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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_54/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 1432

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 23 lampret
 
43 1432 nogj
 
44 167 markom
extern int flag;
45 23 lampret
 
46 133 markom
int audio_cnt = 0;
47 123 markom
 
48 133 markom
static FILE *fo = 0;
49 23 lampret
/* Set a specific SPR with a value. */
50 167 markom
inline void
51 1350 nogj
mtspr(uint16_t regno, const sprword value)
52 30 lampret
{
53 728 markom
  regno %= MAX_SPRS;
54 1432 nogj
  cpu_state.sprs[regno] = value;
55 133 markom
 
56
  /* MM: Register hooks.  */
57
  switch (regno) {
58
  case SPR_TTCR:
59 728 markom
    spr_write_ttcr (value);
60 133 markom
    break;
61 728 markom
  case SPR_TTMR:
62
    spr_write_ttmr (value);
63
    break;
64 1402 nogj
  /* Data cache simulateing stuff */
65
  case SPR_DCBPR:
66
    if(value) {
67
      dc_simulate_read(value, 4);
68 1432 nogj
      cpu_state.sprs[SPR_DCBPR] = 0;
69 1402 nogj
    }
70
    break;
71
  case SPR_DCBFR:
72
    if(value != -1) {
73
      dc_inv(value);
74 1432 nogj
      cpu_state.sprs[SPR_DCBFR] = -1;
75 1402 nogj
    }
76
    break;
77
  case SPR_DCBIR:
78
    if(value != 0) {
79
      dc_inv(value);
80 1432 nogj
      cpu_state.sprs[SPR_DCBIR] = 0;
81 1402 nogj
    }
82
    break;
83
  case SPR_DCBWR:
84 1432 nogj
    cpu_state.sprs[SPR_DCBWR] = 0;
85 1402 nogj
    break;
86
  case SPR_DCBLR:
87 1432 nogj
    cpu_state.sprs[SPR_DCBLR] = 0;
88 1402 nogj
    break;
89 1404 nogj
  /* Instruction cache simulateing stuff */
90
  case SPR_ICBPR:
91
    if(value) {
92
      ic_simulate_fetch(value);
93 1432 nogj
      cpu_state.sprs[SPR_ICBPR] = 0;
94 1404 nogj
    }
95
    break;
96
  case SPR_ICBIR:
97
    if(value) {
98
      ic_inv(value);
99 1432 nogj
      cpu_state.sprs[SPR_ICBIR] = 0;
100 1404 nogj
    }
101
    break;
102
  case SPR_ICBLR:
103 1432 nogj
    cpu_state.sprs[SPR_ICBLR] = 0;
104 1404 nogj
    break;
105 167 markom
  case SPR_SR:
106 728 markom
    /* Set internal flag also */
107
    if(value & SPR_SR_F) flag = 1;
108
    else flag = 0;
109 1432 nogj
    cpu_state.sprs[regno] |= SPR_SR_FO;
110 167 markom
    break;
111 378 markom
  case SPR_NPC:
112 139 chris
    {
113 242 markom
      /* The debugger has redirected us to a new address */
114
      /* This is usually done to reissue an instruction
115
         which just caused a breakpoint exception. */
116 1432 nogj
      cpu_state.pc = value;
117 242 markom
 
118 479 markom
      if(!value && config.sim.verbose)
119 997 markom
        PRINTF("WARNING: PC just set to 0!\n");
120 242 markom
 
121
      /* Clear any pending delay slot jumps also */
122 1432 nogj
      cpu_state.delay_insn = 0;
123 479 markom
      pcnext = value + 4;
124 139 chris
    }
125 242 markom
    break;
126 728 markom
  case 0xFFFD:
127
    fo = fopen ("audiosim.pcm", "wb+");
128 997 markom
    if (!fo) PRINTF("Cannot open audiosim.pcm\n");
129
    PRINTF("Audio opened.\n");
130 728 markom
    break;
131
  case 0xFFFE:
132 997 markom
    if (!fo) PRINTF("audiosim.pcm not opened\n");
133 728 markom
    fputc (value & 0xFF, fo);
134
    if ((audio_cnt % 1024) == 0)
135 997 markom
      PRINTF("%i\n", audio_cnt);
136 728 markom
    audio_cnt++;
137
    break;
138
  case 0xFFFF:
139
    fclose(fo);
140 997 markom
    PRINTF("Audio closed.\n");
141 884 markom
    runtime.sim.cont_run = 0;
142 728 markom
    break;
143 805 markom
        case SPR_PMR:
144
          /* PMR[SDF] and PMR[DCGE] are ignored completely. */
145
          if (value & SPR_PMR_SUME) {
146 997 markom
                  PRINTF ("SUSPEND: PMR[SUME] bit was set.\n");
147 884 markom
                  runtime.sim.cont_run = 0;
148 805 markom
          }
149
          break;
150 479 markom
  default:
151 886 simons
    /* Mask reseved bits in DTLBMR and DTLBMR registers */
152
    if ( (regno >= SPR_DTLBMR_BASE(0)) && (regno < SPR_DTLBTR_LAST(3))) {
153
      if((regno & 0xff) < 0x80)
154 1432 nogj
        cpu_state.sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
155 886 simons
                              (value & (SPR_DTLBMR_V | SPR_DTLBMR_PL1 | SPR_DTLBMR_CID | SPR_DTLBMR_LRU));
156
      else
157 1432 nogj
        cpu_state.sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
158 886 simons
                              (value & (SPR_DTLBTR_CC | SPR_DTLBTR_CI | SPR_DTLBTR_WBC | SPR_DTLBTR_WOM |
159
                              SPR_DTLBTR_A | SPR_DTLBTR_D | SPR_DTLBTR_URE | SPR_DTLBTR_UWE | SPR_DTLBTR_SRE |
160
                              SPR_DTLBTR_SWE));
161
    }
162
 
163
    /* Mask reseved bits in ITLBMR and ITLBMR registers */
164
    if ( (regno >= SPR_ITLBMR_BASE(0)) && (regno < SPR_ITLBTR_LAST(3))) {
165
      if((regno & 0xff) < 0x80)
166 1432 nogj
        cpu_state.sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
167 886 simons
                              (value & (SPR_ITLBMR_V | SPR_ITLBMR_PL1 | SPR_ITLBMR_CID | SPR_ITLBMR_LRU));
168
      else
169 1432 nogj
        cpu_state.sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
170 886 simons
                              (value & (SPR_ITLBTR_CC | SPR_ITLBTR_CI | SPR_ITLBTR_WBC | SPR_ITLBTR_WOM |
171
                              SPR_ITLBTR_A | SPR_ITLBTR_D | SPR_ITLBTR_SXE | SPR_ITLBTR_UXE));
172
    }
173 1432 nogj
 
174 479 markom
    /* Links to GPRS */
175 728 markom
    if(regno >= 0x0400 && regno < 0x0420) {
176 1432 nogj
      cpu_state.reg[regno - 0x0400] = value;
177 728 markom
    }
178 479 markom
    break;
179 378 markom
  }
180 23 lampret
}
181
 
182 30 lampret
/* Show status of important SPRs. */
183
void sprs_status()
184
{
185 1308 phoenix
  PRINTF("VR   : 0x%.8lx  UPR  : 0x%.8lx\n", mfspr(SPR_VR), mfspr(SPR_UPR));
186
  PRINTF("SR   : 0x%.8lx\n", mfspr(SPR_SR));
187
  PRINTF("MACLO: 0x%.8lx  MACHI: 0x%.8lx\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
188
  PRINTF("EPCR0: 0x%.8lx  EPCR1: 0x%.8lx\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
189
  PRINTF("EEAR0: 0x%.8lx  EEAR1: 0x%.8lx\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
190
  PRINTF("ESR0 : 0x%.8lx  ESR1 : 0x%.8lx\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
191
  PRINTF("TTMR : 0x%.8lx  TTCR : 0x%.8lx\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
192
  PRINTF("PICMR: 0x%.8lx  PICSR: 0x%.8lx\n", mfspr(SPR_PICMR), mfspr(SPR_PICSR));
193
  PRINTF("PPC:   0x%.8lx  NPC   : 0x%.8lx\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
194 133 markom
}

powered by: WebSVN 2.1.0

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