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 624

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 133 markom
extern int cont_run;   /* defined in toplevel.c */
31
extern int tt_stopped; /* defined in tick.c */
32 167 markom
extern int flag;
33 23 lampret
 
34 167 markom
sprword sprs[MAX_SPRS];
35 23 lampret
 
36 133 markom
int audio_cnt = 0;
37 123 markom
 
38 133 markom
static FILE *fo = 0;
39 23 lampret
/* Set a specific SPR with a value. */
40 167 markom
inline void
41
mtspr(const int regno, const sprword value)
42 30 lampret
{
43 133 markom
  int ofs = regno % MAX_SPRS_PER_GRP;
44 183 chris
  extern unsigned long pc_phy;
45 479 markom
  extern unsigned long reg[32];
46 133 markom
 
47
  /* MM: Register hooks.  */
48
  switch (regno) {
49
  case 0xFFFD:
50
    fo = fopen ("audiosim.pcm", "wb+");
51
    if (!fo) printf("Cannot open audiosim.pcm\n");
52
    printf("Audio opened.\n");
53
    return;
54
  case 0xFFFE:
55
    if (!fo) printf("audiosim.pcm not opened\n");
56
    fputc (value & 0xFF, fo);
57
    if ((audio_cnt % 1024) == 0)
58
      printf("%i\n", audio_cnt);
59
    audio_cnt++;
60
    return;
61
  case 0xFFFF:
62
    fclose(fo);
63
    printf("Audio closed.\n");
64
    cont_run = 0;
65
    return;
66
  case SPR_TTCR:
67
    tt_stopped = 0;
68
    break;
69 167 markom
  case SPR_SR:
70
    if(value & SPR_SR_F)
71
      flag = 1;
72
    else
73
      flag = 0;
74
    break;
75 378 markom
  case SPR_NPC:
76 139 chris
    {
77
      extern unsigned long pc;
78 153 chris
      extern unsigned long pcnext;
79
      extern int delay_insn;
80
      extern unsigned long pcdelay;
81 242 markom
 
82 479 markom
      clear_pending_exception ();
83
 
84 242 markom
      /* The debugger has redirected us to a new address */
85
      /* This is usually done to reissue an instruction
86
         which just caused a breakpoint exception. */
87 479 markom
      pc = value;
88 242 markom
 
89 479 markom
      if(!value && config.sim.verbose)
90 242 markom
        printf("WARNING: PC just set to 0!\n");
91
 
92
      /* Clear any pending delay slot jumps also */
93
      delay_insn = 0;
94 479 markom
      pcnext = value + 4;
95 139 chris
    }
96 242 markom
    break;
97 479 markom
  default:
98
    /* Links to GPRS */
99
    if(regno >= 0x0400 && regno < 0x0420)
100
      reg[regno - 0x0400] = value;
101
    break;
102 378 markom
  }
103
 
104 624 ivang
  if (regno < MAX_SPRS) {
105 378 markom
    sprs[regno] = value;
106 624 ivang
    if (runtime.sim.fspr_log) {
107
      fprintf(runtime.sim.fspr_log, "Write to SPR  : [%08lX] <- [%08lX]\n", regno, value);
108
    }
109
  }
110 479 markom
  else if (config.sim.verbose)
111
    printf("WARNING: write out of SPR range %08X\n", regno);
112 23 lampret
}
113
 
114 517 markom
#if 0
115 23 lampret
/* Get a specific SPR. */
116 167 markom
inline sprword
117
mfspr_(const int regno)
118 30 lampret
{
119 479 markom
  extern unsigned long reg[32];
120
  extern unsigned long pc;
121
  extern unsigned long pcprev;
122 624 ivang
  sprword val;
123 479 markom
 
124
  switch (regno) {
125 517 markom
  case SPR_SR:
126
    /* Exceptions are always enabled */
127 624 ivang
    val = sprs[regno] | SPR_SR_EXR;
128
    break;
129 479 markom
  case SPR_NPC:
130 624 ivang
    val = pc;
131
    break;
132 479 markom
  case SPR_PPC:
133 624 ivang
    val = pcprev;
134
    break;
135 479 markom
  default:
136
    /* Links to GPRS */
137
    if(regno >= 0x0400 && regno < 0x0420)
138 624 ivang
      val = reg[regno - 0x0400];
139 517 markom
    else if (regno < MAX_SPRS)
140 624 ivang
      val = sprs[regno];
141 479 markom
  }
142 624 ivang
 
143
  if (regno < MAX_SPRS) {
144
    if (runtime.sim.fspr_log) {
145
      fprintf(runtime.sim.fspr_log, "Read from SPR : [%08lX] -> [%08lX]\n", regno, val);
146
    }
147
    return val;
148
  }
149
 
150
  if (config.sim.verbose) {
151 479 markom
    printf ("WARNING: read out of SPR range %08X\n", regno);
152 624 ivang
  }
153
 
154 378 markom
  return 0;
155 23 lampret
}
156 517 markom
#endif
157 23 lampret
 
158 30 lampret
/* Show status of important SPRs. */
159
void sprs_status()
160
{
161 133 markom
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
162
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
163
  printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
164
  printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
165
  printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
166
  printf("ESR0 : 0x%.8x  ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
167 292 lampret
  printf("TTMR : 0x%.8x  TTCR : 0x%.8x\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
168 600 simons
  printf("PICMR: 0x%.8x  PICSR: 0x%.8x\n", mfspr(SPR_PICMR), mfspr(SPR_PICSR));
169 378 markom
  printf("PPC:   0x%.8x  NPC   : 0x%.8x\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
170 133 markom
}

powered by: WebSVN 2.1.0

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