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 1106

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

powered by: WebSVN 2.1.0

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