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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 1402

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

powered by: WebSVN 2.1.0

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