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

Subversion Repositories openrisc

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

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
                                  OrpsocAccess             *_accessor) :
49
  sc_module (name),
50
  accessor (_accessor)
51
{
52
  SC_METHOD (checkInstruction);
53
  sensitive << clk.pos();
54
  dont_initialize();
55 44 julius
 
56
  SC_METHOD (displayState);
57
  logging_enabled = 0; // Default is logging disabled
58
  exit_perf_summary_enabled = 1; // Simulation exit performance summary is on by default. Turn off with "-q" on the cmd line
59
  sensitive << clk.pos();
60
  dont_initialize();
61
 
62
  start = clock();
63 6 julius
 
64
}       // Or1200MonitorSC ()
65
 
66
 
67
//! Method to handle special instrutions
68
 
69
//! These are l.nop instructions with constant values. At present the
70
//! following are implemented:
71
 
72
//! - l.nop 1  Terminate the program
73
//! - l.nop 2  Report the value in R3
74
//! - l.nop 3  Printf the string with the arguments in R3, etc
75
//! - l.nop 4  Print a character
76
 
77
void
78
Or1200MonitorSC::checkInstruction()
79
{
80
  uint32_t  r3;
81
  double    ts;
82
 
83
  // Check the instruction when the freeze signal is low.
84
  if (!accessor->getWbFreeze())
85
    {
86
      // Do something if we have l.nop
87
      switch (accessor->getWbInsn())
88
        {
89
        case NOP_EXIT:
90
          r3 = accessor->getGpr (3);
91
          ts = sc_time_stamp().to_seconds() * 1000000000.0;
92
          std::cout << std::fixed << std::setprecision (2) << ts;
93
          std::cout << " ns: Exiting (" << r3 << ")" << std::endl;
94 44 julius
          if (exit_perf_summary_enabled) perfSummary();
95
          if (logging_enabled != 0) statusFile.close();
96 6 julius
          sc_stop();
97
          break;
98
 
99
        case NOP_REPORT:
100
          ts = sc_time_stamp().to_seconds() * 1000000000.0;
101
          r3 = accessor->getGpr (3);
102
          std::cout << std::fixed << std::setprecision (2) << ts;
103
          std::cout << " ns: report (" << hex << r3 << ")" << std::endl;
104
          break;
105
 
106
        case NOP_PRINTF:
107
          ts = sc_time_stamp().to_seconds() * 1000000000.0;
108
          std::cout << std::fixed << std::setprecision (2) << ts;
109
          std::cout << " ns: printf" << std::endl;
110
          break;
111
 
112
        case NOP_PUTC:
113
          r3 = accessor->getGpr (3);
114
          std::cout << (char)r3 << std::flush;
115
          break;
116
 
117
        default:
118
          break;
119
        }
120
    }
121
 
122
}       // checkInstruction()
123
 
124 44 julius
//! Method to setup the files for outputting the state of the processor
125
 
126
//! This function will setup the output file, if enabled.
127
 
128
void
129
Or1200MonitorSC::init_displayState(int argc, char *argv[])
130
{
131
 
132
  string logfileDefault("vlt-executed.log");
133
  string logfileNameString;
134
 
135
  // Parse the command line options
136
  int cmdline_name_found=0;
137
  if (argc > 1)
138
  {
139
    // Search through the command line parameters for the "-log" option
140
    for(int i=1; i < argc; i++)
141
    {
142
      if (strcmp(argv[i], "-log")==0)
143
        {
144
          logfileNameString = (argv[i+1]);
145
          cmdline_name_found=1;
146
          break;
147
         }
148
    }
149
    // Search through the command line parameters for the "-q","--no-perf-summary" option
150
    for(int i=1; i < argc; i++)
151
    {
152
      if ((strcmp(argv[i], "-q")==0)||(strcmp(argv[i], "--no-perf-summary")==0))
153
        {
154
          exit_perf_summary_enabled = 0;
155
          break;
156
         }
157
    }
158
 
159
 
160
  }
161
 
162
  if(cmdline_name_found==0) // No -log option specified so don't turn on logging
163
      return;
164
 
165
 statusFile.open(logfileNameString.c_str(), ios::out ); // open file to write to it
166
 
167
 if(statusFile.is_open())
168
 {
169
        // If we could open the file then turn on logging
170
        logging_enabled = 1;
171
        cout << "Processor execution logged to file: " << logfileNameString << endl;
172
 }
173
 
174
 return;
175
 
176
}
177
 
178
//! Method to output the state of the processor
179
 
180
//! This function will output to a file, if enabled, the status of the processor
181
//! For now, it's just the PPC and instruction.
182
 
183
void
184
Or1200MonitorSC::displayState()
185
{
186
  uint32_t  wbinsn;
187
 
188
  // Calculate how many instructions we've actually calculated by ignoring cycles where we're frozen, delay slots and flushpipe cycles
189
  if ((!accessor->getWbFreeze()) && !(accessor->getExceptFlushpipe() && accessor->getExDslot()))
190
        // Increment instruction counter
191
        insn_count++;
192
 
193
  if (logging_enabled == 0)
194
        return; // If we didn't inialise a file, then just return.
195
 
196
  // Output the state if we're not frozen and not flushing during a delay slot
197
  if ((!accessor->getWbFreeze()) && !(accessor->getExceptFlushpipe() && accessor->getExDslot()))
198
    {
199
        // Print PC, instruction
200
        statusFile << "\nEXECUTED("<< std::setfill(' ') << std::setw(11) << dec << insn_count << "): " << std::setfill('0') << hex << std::setw(8) << accessor->getWbPC() << ": " << hex << accessor->getWbInsn() <<  endl;
201
 
202
        // Print general purpose register contents
203
        for (int i=0; i<32; i++)
204
        {
205
                if ((i%4 == 0)&&(i>0)) statusFile << endl;
206
                statusFile << std::setfill('0');
207
                statusFile << "GPR" << dec << std::setw(2) << i << ": " <<  hex << std::setw(8) << (uint32_t) accessor->getGpr(i) << "  ";
208
        }
209
        statusFile << endl;
210
 
211
        statusFile << "SR   : " <<  hex << std::setw(8) << (uint32_t) accessor->getSprSr() << "  ";
212
        statusFile << "EPCR0: " <<  hex << std::setw(8) << (uint32_t) accessor->getSprEpcr() << "  ";
213
        statusFile << "EEAR0: " <<  hex << std::setw(8) << (uint32_t) accessor->getSprEear() << "  ";
214
        statusFile << "ESR0 : " <<  hex << std::setw(8) << (uint32_t) accessor->getSprEsr() << endl;
215
 
216
    }
217
 
218
  return;
219
 
220
}       // displayState()
221
 
222
//! Function to calculate the number of instructions performed and the time taken
223
void
224
Or1200MonitorSC::perfSummary()
225
{
226
        double ts;
227
        ts = sc_time_stamp().to_seconds() * 1000000000.0;
228
        int cycles = ts / (BENCH_CLK_HALFPERIOD*2); // Number of clock cycles we had
229
 
230
        clock_t finish = clock();
231
        double elapsed_time = (double(finish)-double(start))/CLOCKS_PER_SEC;
232
        // It took elapsed_time seconds to do insn_count instructions. Divide insn_count by the time to get instructions/second.
233
        double ips = (insn_count/elapsed_time);
234
        double mips = (insn_count/elapsed_time)/1000000;
235
        std::cout << "Or1200Monitor: real time elapsed: " << elapsed_time << " seconds" << endl;
236
        std::cout << "Or1200Monitor: simulated " << dec << cycles << " clock cycles, executed " << insn_count << " instructions" << endl;
237
        std::cout << "Or1200Monitor: simulated insn/sec = " << ips << ", simulator mips = " << mips << endl;
238
        return;
239
}       // calculateMips()
240
 

powered by: WebSVN 2.1.0

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