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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [Or1200MonitorSC.cpp] - Blame information for rev 49

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 julius
// ----------------------------------------------------------------------------
2
 
3
// SystemC OpenRISC 1200 Monitor: implementation
4
 
5
// Copyright (C) 2008  Embecosm Limited <info@embecosm.com>
6
 
7
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8 44 julius
// Contributor Julius Baxter <jb@orsoc.se>
9 6 julius
 
10
// This file is part of the cycle accurate model of the OpenRISC 1000 based
11
// system-on-chip, ORPSoC, built using Verilator.
12
 
13
// This program is free software: you can redistribute it and/or modify it
14
// under the terms of the GNU Lesser General Public License as published by
15
// the Free Software Foundation, either version 3 of the License, or (at your
16
// option) any later version.
17
 
18
// This program is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
21
// License for more details.
22
 
23
// You should have received a copy of the GNU Lesser General Public License
24
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 
26
// ----------------------------------------------------------------------------
27
 
28
// $Id: Or1200MonitorSC.cpp 303 2009-02-16 11:20:17Z jeremy $
29
 
30
#include <iostream>
31
#include <iomanip>
32 44 julius
#include <fstream>
33 6 julius
 
34 44 julius
using namespace std;
35
 
36 6 julius
#include "Or1200MonitorSC.h"
37 44 julius
#include "OrpsocMain.h"
38 6 julius
 
39
 
40
SC_HAS_PROCESS( Or1200MonitorSC );
41
 
42
//! Constructor for the OpenRISC 1200 monitor
43
 
44
//! @param[in] name  Name of this module, passed to the parent constructor.
45
//! @param[in] accessor  Accessor class for this Verilated ORPSoC model
46
 
47
Or1200MonitorSC::Or1200MonitorSC (sc_core::sc_module_name   name,
48 49 julius
                                  OrpsocAccess             *_accessor,
49
                                  int argc,
50
                                  char *argv[]) :
51 6 julius
  sc_module (name),
52
  accessor (_accessor)
53
{
54 49 julius
 
55
  // If not -log option, then don't log
56
 
57
  string logfileDefault("vlt-executed.log");
58
  string logfileNameString;
59
 
60
  exit_perf_summary_enabled = 1; // Simulation exit performance summary is 
61
                                 // on by default. Turn off with "-q" on the cmd line
62
 
63
  // Parse the command line options
64
  int cmdline_name_found=0;
65
  if (argc > 1)
66
    {
67
      // Search through the command line parameters for the "-log" option
68
      for(int i=1; i < argc; i++)
69
        {
70
          if ((strcmp(argv[i], "-l")==0) ||
71
              (strcmp(argv[i], "--log")==0))
72
            {
73
              logfileNameString = (argv[i+1]);
74
              cmdline_name_found=1;
75
              break;
76
            }
77
        }
78
      // Search through the command line parameters for the "-q","--no-perf-summary" option
79
      for(int i=1; i < argc; i++)
80
        {
81
          if ((strcmp(argv[i], "-q")==0) ||
82
              (strcmp(argv[i], "--quiet")==0))
83
            {
84
              exit_perf_summary_enabled = 0;
85
              break;
86
            }
87
        }
88
    }
89
 
90
 
91
 
92
  if(cmdline_name_found==1) // No -log option specified so don't turn on logging
93
    {
94
 
95
      logging_enabled = 0; // Default is logging disabled      
96
      statusFile.open(logfileNameString.c_str(), ios::out ); // open file to write to it
97
 
98
      if(statusFile.is_open())
99
        {
100
          // If we could open the file then turn on logging
101
          logging_enabled = 1;
102
          cout << "* Processor execution logged to file: " << logfileNameString << endl;
103
        }
104
 
105
    }
106
 
107
 
108
  SC_METHOD (displayState);
109 6 julius
  sensitive << clk.pos();
110
  dont_initialize();
111 49 julius
  start = clock();
112 44 julius
 
113 49 julius
 
114
  // checkInstruction monitors the bus for special NOP instructionsl
115
  SC_METHOD (checkInstruction);
116 44 julius
  sensitive << clk.pos();
117
  dont_initialize();
118 49 julius
 
119
 
120
 
121 6 julius
}       // Or1200MonitorSC ()
122
 
123 49 julius
//! Print command line switches for the options of this module
124
void
125
Or1200MonitorSC::printSwitches()
126
{
127
  printf(" [-l <file>] [-q]");
128
}
129 6 julius
 
130 49 julius
//! Print usage for the options of this module
131
void
132
Or1200MonitorSC::printUsage()
133
{
134
  printf("  -l, --log\t\tLog processor execution to file\n");
135
  printf("  -q, --quiet\t\tDisable the performance summary at end of simulation\n");
136
}
137
 
138 6 julius
//! Method to handle special instrutions
139
 
140
//! These are l.nop instructions with constant values. At present the
141
//! following are implemented:
142
 
143
//! - l.nop 1  Terminate the program
144
//! - l.nop 2  Report the value in R3
145
//! - l.nop 3  Printf the string with the arguments in R3, etc
146
//! - l.nop 4  Print a character
147 49 julius
extern int SIM_RUNNING;
148 6 julius
void
149
Or1200MonitorSC::checkInstruction()
150
{
151
  uint32_t  r3;
152
  double    ts;
153
 
154
  // Check the instruction when the freeze signal is low.
155
  if (!accessor->getWbFreeze())
156
    {
157
      // Do something if we have l.nop
158
      switch (accessor->getWbInsn())
159
        {
160
        case NOP_EXIT:
161
          r3 = accessor->getGpr (3);
162
          ts = sc_time_stamp().to_seconds() * 1000000000.0;
163
          std::cout << std::fixed << std::setprecision (2) << ts;
164
          std::cout << " ns: Exiting (" << r3 << ")" << std::endl;
165 49 julius
          perfSummary();
166 44 julius
          if (logging_enabled != 0) statusFile.close();
167 49 julius
          SIM_RUNNING=0;
168 6 julius
          sc_stop();
169
          break;
170
 
171
        case NOP_REPORT:
172
          ts = sc_time_stamp().to_seconds() * 1000000000.0;
173
          r3 = accessor->getGpr (3);
174
          std::cout << std::fixed << std::setprecision (2) << ts;
175
          std::cout << " ns: report (" << hex << r3 << ")" << std::endl;
176
          break;
177
 
178
        case NOP_PRINTF:
179
          ts = sc_time_stamp().to_seconds() * 1000000000.0;
180
          std::cout << std::fixed << std::setprecision (2) << ts;
181
          std::cout << " ns: printf" << std::endl;
182
          break;
183
 
184
        case NOP_PUTC:
185
          r3 = accessor->getGpr (3);
186
          std::cout << (char)r3 << std::flush;
187
          break;
188
 
189
        default:
190
          break;
191
        }
192
    }
193
 
194
}       // checkInstruction()
195
 
196 44 julius
 
197
//! Method to output the state of the processor
198
 
199
//! This function will output to a file, if enabled, the status of the processor
200
//! For now, it's just the PPC and instruction.
201 49 julius
#define PRINT_REGS 0
202 44 julius
void
203
Or1200MonitorSC::displayState()
204
{
205
  uint32_t  wbinsn;
206
 
207
  // Calculate how many instructions we've actually calculated by ignoring cycles where we're frozen, delay slots and flushpipe cycles
208
  if ((!accessor->getWbFreeze()) && !(accessor->getExceptFlushpipe() && accessor->getExDslot()))
209
        // Increment instruction counter
210
        insn_count++;
211
 
212
  if (logging_enabled == 0)
213
        return; // If we didn't inialise a file, then just return.
214
 
215
  // Output the state if we're not frozen and not flushing during a delay slot
216
  if ((!accessor->getWbFreeze()) && !(accessor->getExceptFlushpipe() && accessor->getExDslot()))
217
    {
218
        // Print PC, instruction
219
        statusFile << "\nEXECUTED("<< std::setfill(' ') << std::setw(11) << dec << insn_count << "): " << std::setfill('0') << hex << std::setw(8) << accessor->getWbPC() << ": " << hex << accessor->getWbInsn() <<  endl;
220 49 julius
#if PRINT_REGS
221 44 julius
        // Print general purpose register contents
222
        for (int i=0; i<32; i++)
223 49 julius
          {
224 44 julius
                if ((i%4 == 0)&&(i>0)) statusFile << endl;
225
                statusFile << std::setfill('0');
226
                statusFile << "GPR" << dec << std::setw(2) << i << ": " <<  hex << std::setw(8) << (uint32_t) accessor->getGpr(i) << "  ";
227
        }
228
        statusFile << endl;
229
 
230
        statusFile << "SR   : " <<  hex << std::setw(8) << (uint32_t) accessor->getSprSr() << "  ";
231
        statusFile << "EPCR0: " <<  hex << std::setw(8) << (uint32_t) accessor->getSprEpcr() << "  ";
232
        statusFile << "EEAR0: " <<  hex << std::setw(8) << (uint32_t) accessor->getSprEear() << "  ";
233
        statusFile << "ESR0 : " <<  hex << std::setw(8) << (uint32_t) accessor->getSprEsr() << endl;
234 49 julius
#endif
235 44 julius
 
236
    }
237
 
238
  return;
239
 
240
}       // displayState()
241
 
242
//! Function to calculate the number of instructions performed and the time taken
243
void
244
Or1200MonitorSC::perfSummary()
245
{
246 49 julius
  if (exit_perf_summary_enabled)
247
    {
248
      double ts;
249
      ts = sc_time_stamp().to_seconds() * 1000000000.0;
250
      int cycles = ts / (BENCH_CLK_HALFPERIOD*2); // Number of clock cycles we had
251
 
252
      clock_t finish = clock();
253
      double elapsed_time = (double(finish)-double(start))/CLOCKS_PER_SEC;
254
      // It took elapsed_time seconds to do insn_count instructions. Divide insn_count by the time to get instructions/second.
255
      double ips = (insn_count/elapsed_time);
256
      double mips = (insn_count/elapsed_time)/1000000;
257
      int hertz = (int) ((cycles/elapsed_time)/1000);
258
      std::cout << "* Or1200Monitor: simulated " << sc_time_stamp() << ",time elapsed: " << elapsed_time << " seconds" << endl;
259
      std::cout << "* Or1200Monitor: simulated " << dec << cycles << " clock cycles, executed at approx " << hertz << "kHz" << endl;
260
      std::cout << "* Or1200Monitor: simulated " << insn_count << " instructions, insn/sec. = " << ips << ", mips = " << mips << endl;
261
    }
262
  return;
263
}       // perfSummary
264 44 julius
 

powered by: WebSVN 2.1.0

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