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 884

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
    /* Links to GPRS */
105 728 markom
    if(regno >= 0x0400 && regno < 0x0420) {
106
      extern unsigned long reg[32];
107 479 markom
      reg[regno - 0x0400] = value;
108 728 markom
    }
109 479 markom
    break;
110 378 markom
  }
111 23 lampret
}
112
 
113 30 lampret
/* Show status of important SPRs. */
114
void sprs_status()
115
{
116 133 markom
  printf("VR   : 0x%.8x  UPR  : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
117
  printf("SR   : 0x%.8x\n", mfspr(SPR_SR));
118
  printf("MACLO: 0x%.8x  MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
119
  printf("EPCR0: 0x%.8x  EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
120
  printf("EEAR0: 0x%.8x  EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
121
  printf("ESR0 : 0x%.8x  ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
122 292 lampret
  printf("TTMR : 0x%.8x  TTCR : 0x%.8x\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
123 600 simons
  printf("PICMR: 0x%.8x  PICSR: 0x%.8x\n", mfspr(SPR_PICMR), mfspr(SPR_PICSR));
124 378 markom
  printf("PPC:   0x%.8x  NPC   : 0x%.8x\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
125 133 markom
}

powered by: WebSVN 2.1.0

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