1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 * Steve Reinhardt 30 */ 31 32#include <cstring> 33#include <fstream> 34#include <list> 35#include <string> 36#include <vector> 37 38#include "base/misc.hh"
| 1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 * Steve Reinhardt 30 */ 31 32#include <cstring> 33#include <fstream> 34#include <list> 35#include <string> 36#include <vector> 37 38#include "base/misc.hh"
|
39#include "base/output.hh"
| |
40#include "sim/builder.hh"
| 39#include "sim/builder.hh"
|
41#include "sim/host.hh" 42#include "sim/sim_events.hh" 43#include "sim/sim_exit.hh"
| |
44#include "sim/sim_object.hh"
| 40#include "sim/sim_object.hh"
|
45#include "sim/root.hh"
| |
46
| 41
|
47using namespace std; 48 49Tick curTick = 0; 50ostream *outputStream; 51ostream *configStream; 52 53/// The simulated frequency of curTick. (This is only here for a short time) 54Tick ticksPerSecond; 55 56namespace Clock { 57/// The simulated frequency of curTick. (In ticks per second) 58Tick Frequency; 59 60namespace Float { 61double s; 62double ms; 63double us; 64double ns; 65double ps; 66 67double Hz; 68double kHz; 69double MHz; 70double GHZ; 71/* namespace Float */ } 72 73namespace Int { 74Tick s; 75Tick ms; 76Tick us; 77Tick ns; 78Tick ps; 79/* namespace Float */ } 80 81/* namespace Clock */ } 82 83
| |
84// Dummy Object
| 42// Dummy Object
|
85class Root : public SimObject
| 43struct Root : public SimObject
|
86{
| 44{
|
87 private: 88 Tick max_tick; 89 Tick progress_interval; 90 91 public: 92 Root(const std::string &name, Tick maxtick, Tick pi) 93 : SimObject(name), max_tick(maxtick), progress_interval(pi) 94 {} 95 96 virtual void startup();
| 45 Root(const std::string &name) : SimObject(name) {}
|
97}; 98
| 46}; 47
|
99void 100Root::startup() 101{ 102 if (max_tick != 0) 103 schedExitSimLoop("reached maximum cycle count", curTick + max_tick); 104 105 if (progress_interval != 0) 106 new ProgressEvent(&mainEventQueue, progress_interval); 107} 108
| |
109BEGIN_DECLARE_SIM_OBJECT_PARAMS(Root) 110
| 48BEGIN_DECLARE_SIM_OBJECT_PARAMS(Root) 49
|
111 Param<Tick> clock; 112 Param<Tick> max_tick; 113 Param<Tick> progress_interval; 114 Param<string> output_file;
| 50 Param<int> dummy; // needed below
|
115 116END_DECLARE_SIM_OBJECT_PARAMS(Root) 117 118BEGIN_INIT_SIM_OBJECT_PARAMS(Root) 119
| 51 52END_DECLARE_SIM_OBJECT_PARAMS(Root) 53 54BEGIN_INIT_SIM_OBJECT_PARAMS(Root) 55
|
120 INIT_PARAM(clock, "tick frequency"), 121 INIT_PARAM(max_tick, "maximum simulation time"), 122 INIT_PARAM(progress_interval, "print a progress message"), 123 INIT_PARAM(output_file, "file to dump simulator output to")
| 56 INIT_PARAM(dummy, "") // All SimObjects must have params
|
124 125END_INIT_SIM_OBJECT_PARAMS(Root) 126 127CREATE_SIM_OBJECT(Root) 128{ 129 static bool created = false; 130 if (created) 131 panic("only one root object allowed!"); 132 133 created = true; 134
| 57 58END_INIT_SIM_OBJECT_PARAMS(Root) 59 60CREATE_SIM_OBJECT(Root) 61{ 62 static bool created = false; 63 if (created) 64 panic("only one root object allowed!"); 65 66 created = true; 67
|
135 outputStream = simout.find(output_file); 136 Root *root = new Root(getInstanceName(), max_tick, progress_interval); 137 138 using namespace Clock; 139 Frequency = clock; 140 Float::s = static_cast<double>(Frequency); 141 Float::ms = Float::s / 1.0e3; 142 Float::us = Float::s / 1.0e6; 143 Float::ns = Float::s / 1.0e9; 144 Float::ps = Float::s / 1.0e12; 145 146 Float::Hz = 1.0 / Float::s; 147 Float::kHz = 1.0 / Float::ms; 148 Float::MHz = 1.0 / Float::us; 149 Float::GHZ = 1.0 / Float::ns; 150 151 Int::s = Frequency; 152 Int::ms = Int::s / 1000; 153 Int::us = Int::ms / 1000; 154 Int::ns = Int::us / 1000; 155 Int::ps = Int::ns / 1000; 156 157 return root;
| 68 return new Root(getInstanceName());
|
158} 159 160REGISTER_SIM_OBJECT("Root", Root)
| 69} 70 71REGISTER_SIM_OBJECT("Root", Root)
|