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

Subversion Repositories or1k

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

powered by: WebSVN 2.1.0

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