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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_33/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 1350

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

powered by: WebSVN 2.1.0

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