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 886

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

powered by: WebSVN 2.1.0

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