root.cc revision 1696
1/* 2 * Copyright (c) 2002-2004 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 29#include <cstring> 30#include <fstream> 31#include <list> 32#include <string> 33#include <vector> 34 35#include "base/misc.hh" 36#include "base/output.hh" 37#include "sim/builder.hh" 38#include "sim/host.hh" 39#include "sim/sim_object.hh" 40#include "sim/root.hh" 41 42using namespace std; 43 44Tick curTick = 0; 45ostream *outputStream; 46ostream *configStream; 47 48/// The simulated frequency of curTick. (This is only here for a short time) 49Tick ticksPerSecond; 50 51namespace Clock { 52/// The simulated frequency of curTick. (In ticks per second) 53Tick Frequency; 54 55namespace Float { 56double s; 57double ms; 58double us; 59double ns; 60double ps; 61 62double Hz; 63double kHz; 64double MHz; 65double GHZ; 66/* namespace Float */ } 67 68namespace Int { 69Tick s; 70Tick ms; 71Tick us; 72Tick ns; 73Tick ps; 74/* namespace Float */ } 75 76/* namespace Clock */ } 77 78 79// Dummy Object 80class Root : public SimObject 81{ 82 public: 83 Root(const std::string &name) : SimObject(name) {} 84}; 85 86BEGIN_DECLARE_SIM_OBJECT_PARAMS(Root) 87 88 Param<Tick> clock; 89 Param<string> output_file; 90 91END_DECLARE_SIM_OBJECT_PARAMS(Root) 92 93BEGIN_INIT_SIM_OBJECT_PARAMS(Root) 94 95 INIT_PARAM(clock, "tick frequency"), 96 INIT_PARAM(output_file, "file to dump simulator output to") 97 98END_INIT_SIM_OBJECT_PARAMS(Root) 99 100CREATE_SIM_OBJECT(Root) 101{ 102 static bool created = false; 103 if (created) 104 panic("only one root object allowed!"); 105 106 created = true; 107 108 outputStream = simout.find(output_file); 109 Root *root = new Root(getInstanceName()); 110 111 using namespace Clock; 112 Frequency = clock; 113 Float::s = static_cast<double>(Frequency); 114 Float::ms = Float::s / 1.0e3; 115 Float::us = Float::s / 1.0e6; 116 Float::ns = Float::s / 1.0e9; 117 Float::ps = Float::s / 1.0e12; 118 119 Float::Hz = 1.0 / Float::s; 120 Float::kHz = 1.0 / Float::ms; 121 Float::MHz = 1.0 / Float::us; 122 Float::GHZ = 1.0 / Float::ns; 123 124 Int::s = Frequency; 125 Int::ms = Int::s / 1000; 126 Int::us = Int::ms / 1000; 127 Int::ns = Int::us / 1000; 128 Int::ps = Int::ns / 1000; 129 130 return root; 131} 132 133REGISTER_SIM_OBJECT("Root", Root) 134