root.cc revision 1762
1955SN/A/* 2955SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 31762SN/A * All rights reserved. 4955SN/A * 5955SN/A * Redistribution and use in source and binary forms, with or without 6955SN/A * modification, are permitted provided that the following conditions are 7955SN/A * met: redistributions of source code must retain the above copyright 8955SN/A * notice, this list of conditions and the following disclaimer; 9955SN/A * redistributions in binary form must reproduce the above copyright 10955SN/A * notice, this list of conditions and the following disclaimer in the 11955SN/A * documentation and/or other materials provided with the distribution; 12955SN/A * neither the name of the copyright holders nor the names of its 13955SN/A * contributors may be used to endorse or promote products derived from 14955SN/A * this software without specific prior written permission. 15955SN/A * 16955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27955SN/A */ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu#include <cstring> 30955SN/A#include <fstream> 31955SN/A#include <list> 32955SN/A#include <string> 333583Sbinkertn@umich.edu#include <vector> 34955SN/A 35955SN/A#include "base/misc.hh" 36955SN/A#include "base/output.hh" 37955SN/A#include "sim/builder.hh" 38955SN/A#include "sim/host.hh" 39955SN/A#include "sim/sim_object.hh" 40955SN/A#include "sim/root.hh" 41955SN/A 42955SN/Ausing namespace std; 43955SN/A 44955SN/ATick curTick = 0; 45955SN/Aostream *outputStream; 46955SN/Aostream *configStream; 47955SN/A 482023SN/A/// The simulated frequency of curTick. (This is only here for a short time) 49955SN/ATick ticksPerSecond; 503089Ssaidi@eecs.umich.edu 51955SN/Anamespace Clock { 52955SN/A/// The simulated frequency of curTick. (In ticks per second) 53955SN/ATick Frequency; 54955SN/A 55955SN/Anamespace Float { 56955SN/Adouble s; 57955SN/Adouble ms; 58955SN/Adouble us; 591031SN/Adouble ns; 60955SN/Adouble ps; 611388SN/A 62955SN/Adouble Hz; 63955SN/Adouble kHz; 641296SN/Adouble MHz; 65955SN/Adouble GHZ; 66955SN/A/* namespace Float */ } 67955SN/A 68955SN/Anamespace Int { 69955SN/ATick s; 70955SN/ATick ms; 71955SN/ATick us; 72955SN/ATick ns; 73955SN/ATick ps; 74955SN/A/* namespace Float */ } 75955SN/A 76955SN/A/* namespace Clock */ } 773584Ssaidi@eecs.umich.edu 78955SN/A 79955SN/A// Dummy Object 80955SN/Aclass Root : public SimObject 81955SN/A{ 82955SN/A public: 83955SN/A Root(const std::string &name) : SimObject(name) {} 84955SN/A}; 852325SN/A 861717SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(Root) 872652Ssaidi@eecs.umich.edu 88955SN/A Param<Tick> clock; 892736Sktlim@umich.edu Param<string> output_file; 902410SN/A 91955SN/AEND_DECLARE_SIM_OBJECT_PARAMS(Root) 922290SN/A 93955SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(Root) 942683Sktlim@umich.edu 952683Sktlim@umich.edu INIT_PARAM(clock, "tick frequency"), 962669Sktlim@umich.edu INIT_PARAM(output_file, "file to dump simulator output to") 972568SN/A 982568SN/AEND_INIT_SIM_OBJECT_PARAMS(Root) 993012Ssaidi@eecs.umich.edu 1002462SN/ACREATE_SIM_OBJECT(Root) 1012568SN/A{ 1022395SN/A static bool created = false; 1032405SN/A if (created) 1042914Ssaidi@eecs.umich.edu panic("only one root object allowed!"); 105955SN/A 1062811Srdreslin@umich.edu created = true; 1072811Srdreslin@umich.edu 1082811Srdreslin@umich.edu outputStream = simout.find(output_file); 1092811Srdreslin@umich.edu Root *root = new Root(getInstanceName()); 1102811Srdreslin@umich.edu 1112811Srdreslin@umich.edu using namespace Clock; 1122811Srdreslin@umich.edu Frequency = clock; 1132811Srdreslin@umich.edu Float::s = static_cast<double>(Frequency); 1142811Srdreslin@umich.edu Float::ms = Float::s / 1.0e3; 1152811Srdreslin@umich.edu Float::us = Float::s / 1.0e6; 1162811Srdreslin@umich.edu Float::ns = Float::s / 1.0e9; 1172811Srdreslin@umich.edu Float::ps = Float::s / 1.0e12; 1182811Srdreslin@umich.edu 1192811Srdreslin@umich.edu Float::Hz = 1.0 / Float::s; 1202811Srdreslin@umich.edu Float::kHz = 1.0 / Float::ms; 1212811Srdreslin@umich.edu Float::MHz = 1.0 / Float::us; 1222814Srdreslin@umich.edu Float::GHZ = 1.0 / Float::ns; 1232811Srdreslin@umich.edu 1242811Srdreslin@umich.edu Int::s = Frequency; 1252811Srdreslin@umich.edu Int::ms = Int::s / 1000; 1262811Srdreslin@umich.edu Int::us = Int::ms / 1000; 1272811Srdreslin@umich.edu Int::ns = Int::us / 1000; 1282811Srdreslin@umich.edu Int::ps = Int::ns / 1000; 1292811Srdreslin@umich.edu 1302813Srdreslin@umich.edu return root; 1312813Srdreslin@umich.edu} 1323645Sbinkertn@umich.edu 1333624Sbinkertn@umich.eduREGISTER_SIM_OBJECT("Root", Root) 1343624Sbinkertn@umich.edu