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 805

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 167 markom
extern int flag;
32 23 lampret
 
33 167 markom
sprword sprs[MAX_SPRS];
34 23 lampret
 
35 133 markom
int audio_cnt = 0;
36 123 markom
 
37 133 markom
static FILE *fo = 0;
38 23 lampret
/* Set a specific SPR with a value. */
39 167 markom
inline void
40
mtspr(const int regno, const sprword value)
41 30 lampret
{
42 728 markom
  regno %= MAX_SPRS;
43
  sprs[regno] = value;
44 133 markom
 
45
  /* MM: Register hooks.  */
46
  switch (regno) {
47
  case SPR_TTCR:
48 728 markom
    spr_write_ttcr (value);
49 133 markom
    break;
50 728 markom
  case SPR_TTMR:
51
    spr_write_ttmr (value);
52
    break;
53 167 markom
  case SPR_SR:
54 728 markom
    /* Set internal flag also */
55
    if(value & SPR_SR_F) flag = 1;
56
    else flag = 0;
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 242 markom
        printf("WARNING: PC just set to 0!\n");
74
 
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
    if (!fo) printf("Cannot open audiosim.pcm\n");
83
    printf("Audio opened.\n");
84
    break;
85
  case 0xFFFE:
86
    if (!fo) printf("audiosim.pcm not opened\n");
87
    fputc (value & 0xFF, fo);
88
    if ((audio_cnt % 1024) == 0)
89
      printf("%i\n", audio_cnt);
90
    audio_cnt++;
91
    break;
92
  case 0xFFFF:
93
    fclose(fo);
94
    printf("Audio closed.\n");
95
    cont_run = 0;
96
    break;
97 805 markom
        case SPR_PMR:
98
          /* PMR[SDF] and PMR[DCGE] are ignored completely. */
99
          if (value & SPR_PMR_SUME) {
100
                  printf ("SUSPEND: PMR[SUME] bit was set.\n");
101
                  cont_run = 0;
102
          }
103
          break;
104 479 markom
  default:
105
    /* Links to GPRS */
106 728 markom
    if(regno >= 0x0400 && regno < 0x0420) {
107
      extern unsigned long reg[32];
108 479 markom
      reg[regno - 0x0400] = value;
109 728 markom
    }
110 479 markom
    break;
111 378 markom
  }
112 23 lampret
}
113
 
114 30 lampret
/* Show status of important SPRs. */
115
void sprs_status()
116
{
117 133 markom
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
118
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
119
  printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
120
  printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
121
  printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
122
  printf("ESR0 : 0x%.8x  ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
123 292 lampret
  printf("TTMR : 0x%.8x  TTCR : 0x%.8x\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
124 600 simons
  printf("PICMR: 0x%.8x  PICSR: 0x%.8x\n", mfspr(SPR_PICMR), mfspr(SPR_PICSR));
125 378 markom
  printf("PPC:   0x%.8x  NPC   : 0x%.8x\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
126 133 markom
}

powered by: WebSVN 2.1.0

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