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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_39/] [or1ksim/] [cpu/] [or1k/] [sprs.c] - Blame information for rev 600

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
  if (regno < MAX_SPRS)
105
    sprs[regno] = value;
106 479 markom
  else if (config.sim.verbose)
107
    printf("WARNING: write out of SPR range %08X\n", regno);
108 23 lampret
}
109
 
110 517 markom
#if 0
111 23 lampret
/* Get a specific SPR. */
112 167 markom
inline sprword
113
mfspr_(const int regno)
114 30 lampret
{
115 479 markom
  extern unsigned long reg[32];
116
  extern unsigned long pc;
117
  extern unsigned long pcprev;
118
 
119
  switch (regno) {
120 517 markom
  case SPR_SR:
121
    /* Exceptions are always enabled */
122
    return sprs[regno] | SPR_SR_EXR;
123 479 markom
  case SPR_NPC:
124
    return pc;
125
  case SPR_PPC:
126
    return pcprev;
127
  default:
128
    /* Links to GPRS */
129
    if(regno >= 0x0400 && regno < 0x0420)
130
      return reg[regno - 0x0400];
131 517 markom
    else if (regno < MAX_SPRS)
132
      return sprs[regno];
133 479 markom
  }
134
  if (config.sim.verbose)
135
    printf ("WARNING: read out of SPR range %08X\n", regno);
136 378 markom
  return 0;
137 23 lampret
}
138 517 markom
#endif
139 23 lampret
 
140 30 lampret
/* Show status of important SPRs. */
141
void sprs_status()
142
{
143 133 markom
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
144
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
145
  printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
146
  printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
147
  printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
148
  printf("ESR0 : 0x%.8x  ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
149 292 lampret
  printf("TTMR : 0x%.8x  TTCR : 0x%.8x\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
150 600 simons
  printf("PICMR: 0x%.8x  PICSR: 0x%.8x\n", mfspr(SPR_PICMR), mfspr(SPR_PICSR));
151 378 markom
  printf("PPC:   0x%.8x  NPC   : 0x%.8x\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.