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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 1386

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

powered by: WebSVN 2.1.0

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