| 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 |
|
|
|
| 9 |
|
|
// This file is part of the cycle accurate model of the OpenRISC 1000 based
|
| 10 |
|
|
// system-on-chip, ORPSoC, built using Verilator.
|
| 11 |
|
|
|
| 12 |
|
|
// This program is free software: you can redistribute it and/or modify it
|
| 13 |
|
|
// under the terms of the GNU Lesser General Public License as published by
|
| 14 |
|
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
| 15 |
|
|
// option) any later version.
|
| 16 |
|
|
|
| 17 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 18 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 20 |
|
|
// License for more details.
|
| 21 |
|
|
|
| 22 |
|
|
// You should have received a copy of the GNU Lesser General Public License
|
| 23 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 24 |
|
|
|
| 25 |
|
|
// ----------------------------------------------------------------------------
|
| 26 |
|
|
|
| 27 |
|
|
// $Id: Or1200MonitorSC.cpp 303 2009-02-16 11:20:17Z jeremy $
|
| 28 |
|
|
|
| 29 |
|
|
#include <iostream>
|
| 30 |
|
|
#include <iomanip>
|
| 31 |
|
|
|
| 32 |
|
|
#include "Or1200MonitorSC.h"
|
| 33 |
|
|
|
| 34 |
|
|
|
| 35 |
|
|
SC_HAS_PROCESS( Or1200MonitorSC );
|
| 36 |
|
|
|
| 37 |
|
|
//! Constructor for the OpenRISC 1200 monitor
|
| 38 |
|
|
|
| 39 |
|
|
//! @param[in] name Name of this module, passed to the parent constructor.
|
| 40 |
|
|
//! @param[in] accessor Accessor class for this Verilated ORPSoC model
|
| 41 |
|
|
|
| 42 |
|
|
Or1200MonitorSC::Or1200MonitorSC (sc_core::sc_module_name name,
|
| 43 |
|
|
OrpsocAccess *_accessor) :
|
| 44 |
|
|
sc_module (name),
|
| 45 |
|
|
accessor (_accessor)
|
| 46 |
|
|
{
|
| 47 |
|
|
SC_METHOD (checkInstruction);
|
| 48 |
|
|
sensitive << clk.pos();
|
| 49 |
|
|
dont_initialize();
|
| 50 |
|
|
|
| 51 |
|
|
} // Or1200MonitorSC ()
|
| 52 |
|
|
|
| 53 |
|
|
|
| 54 |
|
|
//! Method to handle special instrutions
|
| 55 |
|
|
|
| 56 |
|
|
//! These are l.nop instructions with constant values. At present the
|
| 57 |
|
|
//! following are implemented:
|
| 58 |
|
|
|
| 59 |
|
|
//! - l.nop 1 Terminate the program
|
| 60 |
|
|
//! - l.nop 2 Report the value in R3
|
| 61 |
|
|
//! - l.nop 3 Printf the string with the arguments in R3, etc
|
| 62 |
|
|
//! - l.nop 4 Print a character
|
| 63 |
|
|
|
| 64 |
|
|
void
|
| 65 |
|
|
Or1200MonitorSC::checkInstruction()
|
| 66 |
|
|
{
|
| 67 |
|
|
uint32_t r3;
|
| 68 |
|
|
double ts;
|
| 69 |
|
|
|
| 70 |
|
|
// Check the instruction when the freeze signal is low.
|
| 71 |
|
|
if (!accessor->getWbFreeze())
|
| 72 |
|
|
{
|
| 73 |
|
|
// Do something if we have l.nop
|
| 74 |
|
|
switch (accessor->getWbInsn())
|
| 75 |
|
|
{
|
| 76 |
|
|
case NOP_EXIT:
|
| 77 |
|
|
r3 = accessor->getGpr (3);
|
| 78 |
|
|
ts = sc_time_stamp().to_seconds() * 1000000000.0;
|
| 79 |
|
|
std::cout << std::fixed << std::setprecision (2) << ts;
|
| 80 |
|
|
std::cout << " ns: Exiting (" << r3 << ")" << std::endl;
|
| 81 |
|
|
sc_stop();
|
| 82 |
|
|
break;
|
| 83 |
|
|
|
| 84 |
|
|
case NOP_REPORT:
|
| 85 |
|
|
ts = sc_time_stamp().to_seconds() * 1000000000.0;
|
| 86 |
|
|
r3 = accessor->getGpr (3);
|
| 87 |
|
|
std::cout << std::fixed << std::setprecision (2) << ts;
|
| 88 |
|
|
std::cout << " ns: report (" << hex << r3 << ")" << std::endl;
|
| 89 |
|
|
break;
|
| 90 |
|
|
|
| 91 |
|
|
case NOP_PRINTF:
|
| 92 |
|
|
ts = sc_time_stamp().to_seconds() * 1000000000.0;
|
| 93 |
|
|
std::cout << std::fixed << std::setprecision (2) << ts;
|
| 94 |
|
|
std::cout << " ns: printf" << std::endl;
|
| 95 |
|
|
break;
|
| 96 |
|
|
|
| 97 |
|
|
case NOP_PUTC:
|
| 98 |
|
|
r3 = accessor->getGpr (3);
|
| 99 |
|
|
std::cout << (char)r3 << std::flush;
|
| 100 |
|
|
break;
|
| 101 |
|
|
|
| 102 |
|
|
default:
|
| 103 |
|
|
break;
|
| 104 |
|
|
}
|
| 105 |
|
|
}
|
| 106 |
|
|
|
| 107 |
|
|
} // checkInstruction()
|
| 108 |
|
|
|