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 561

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_TTMR:
67 183 chris
    if(~value & SPR_TTMR_IP & sprs[SPR_TTMR])
68 561 simons
      setsprbit(SPR_PICSR, config.tick.irq, 0);
69
    break;
70 133 markom
  case SPR_TTCR:
71
    tt_stopped = 0;
72
    break;
73 167 markom
  case SPR_SR:
74
    if(value & SPR_SR_F)
75
      flag = 1;
76
    else
77
      flag = 0;
78 450 simons
    sprs[SPR_SR] = value | SPR_SR_EXR; /* Exceptions are allways enabled */
79 167 markom
    break;
80 378 markom
  case SPR_NPC:
81 139 chris
    {
82
      extern unsigned long pc;
83 153 chris
      extern unsigned long pcnext;
84
      extern int delay_insn;
85
      extern unsigned long pcdelay;
86 242 markom
 
87 479 markom
      clear_pending_exception ();
88
 
89 242 markom
      /* The debugger has redirected us to a new address */
90
      /* This is usually done to reissue an instruction
91
         which just caused a breakpoint exception. */
92 479 markom
      pc = value;
93 242 markom
 
94 479 markom
      if(!value && config.sim.verbose)
95 242 markom
        printf("WARNING: PC just set to 0!\n");
96
 
97
      /* Clear any pending delay slot jumps also */
98
      delay_insn = 0;
99 479 markom
      pcnext = value + 4;
100 139 chris
    }
101 242 markom
    break;
102 479 markom
  default:
103
    /* Links to GPRS */
104
    if(regno >= 0x0400 && regno < 0x0420)
105
      reg[regno - 0x0400] = value;
106
    break;
107 378 markom
  }
108
 
109
  if (regno < MAX_SPRS)
110
    sprs[regno] = value;
111 479 markom
  else if (config.sim.verbose)
112
    printf("WARNING: write out of SPR range %08X\n", regno);
113 23 lampret
}
114
 
115 517 markom
#if 0
116 23 lampret
/* Get a specific SPR. */
117 167 markom
inline sprword
118
mfspr_(const int regno)
119 30 lampret
{
120 479 markom
  extern unsigned long reg[32];
121
  extern unsigned long pc;
122
  extern unsigned long pcprev;
123
 
124
  switch (regno) {
125 517 markom
  case SPR_SR:
126
    /* Exceptions are always enabled */
127
    return sprs[regno] | SPR_SR_EXR;
128 479 markom
  case SPR_NPC:
129
    return pc;
130
  case SPR_PPC:
131
    return pcprev;
132
  default:
133
    /* Links to GPRS */
134
    if(regno >= 0x0400 && regno < 0x0420)
135
      return reg[regno - 0x0400];
136 517 markom
    else if (regno < MAX_SPRS)
137
      return sprs[regno];
138 479 markom
  }
139
  if (config.sim.verbose)
140
    printf ("WARNING: read out of SPR range %08X\n", regno);
141 378 markom
  return 0;
142 23 lampret
}
143 517 markom
#endif
144 23 lampret
 
145 30 lampret
/* Show status of important SPRs. */
146
void sprs_status()
147
{
148 133 markom
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
149
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
150
  printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
151
  printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
152
  printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
153
  printf("ESR0 : 0x%.8x  ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
154 292 lampret
  printf("TTMR : 0x%.8x  TTCR : 0x%.8x\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
155
  printf("PICMR: 0x%.8x  PICPR: 0x%.8x\n", mfspr(SPR_PICMR), mfspr(SPR_PICPR));
156
  printf("PICSR: 0x%.8x\n", mfspr(SPR_PICSR));
157 378 markom
  printf("PPC:   0x%.8x  NPC   : 0x%.8x\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
158 133 markom
}

powered by: WebSVN 2.1.0

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