root.cc revision 1762
12391SN/A/*
22391SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32391SN/A * All rights reserved.
42391SN/A *
52391SN/A * Redistribution and use in source and binary forms, with or without
62391SN/A * modification, are permitted provided that the following conditions are
72391SN/A * met: redistributions of source code must retain the above copyright
82391SN/A * notice, this list of conditions and the following disclaimer;
92391SN/A * redistributions in binary form must reproduce the above copyright
102391SN/A * notice, this list of conditions and the following disclaimer in the
112391SN/A * documentation and/or other materials provided with the distribution;
122391SN/A * neither the name of the copyright holders nor the names of its
132391SN/A * contributors may be used to endorse or promote products derived from
142391SN/A * this software without specific prior written permission.
152391SN/A *
162391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282665Ssaidi@eecs.umich.edu
292914Ssaidi@eecs.umich.edu#include <cstring>
302391SN/A#include <fstream>
312391SN/A#include <list>
322391SN/A#include <string>
332391SN/A#include <vector>
342391SN/A
352391SN/A#include "base/misc.hh"
362391SN/A#include "base/output.hh"
372391SN/A#include "sim/builder.hh"
382391SN/A#include "sim/host.hh"
392391SN/A#include "sim/sim_object.hh"
402391SN/A#include "sim/root.hh"
412391SN/A
423348Sbinkertn@umich.eduusing namespace std;
432391SN/A
442391SN/ATick curTick = 0;
453879Ssaidi@eecs.umich.eduostream *outputStream;
462394SN/Aostream *configStream;
472391SN/A
482415SN/A/// The simulated frequency of curTick. (This is only here for a short time)
493348Sbinkertn@umich.eduTick ticksPerSecond;
502394SN/A
512391SN/Anamespace Clock {
522423SN/A/// The simulated frequency of curTick. (In ticks per second)
532391SN/ATick Frequency;
543012Ssaidi@eecs.umich.edu
553012Ssaidi@eecs.umich.edunamespace Float {
562391SN/Adouble s;
573012Ssaidi@eecs.umich.edudouble ms;
582391SN/Adouble us;
592391SN/Adouble ns;
602391SN/Adouble ps;
613012Ssaidi@eecs.umich.edu
623918Ssaidi@eecs.umich.edudouble Hz;
632391SN/Adouble kHz;
643012Ssaidi@eecs.umich.edudouble MHz;
652391SN/Adouble GHZ;
662391SN/A/* namespace Float */ }
672391SN/A
682391SN/Anamespace Int {
693751Sgblack@eecs.umich.eduTick s;
703751Sgblack@eecs.umich.eduTick ms;
713751Sgblack@eecs.umich.eduTick us;
723751Sgblack@eecs.umich.eduTick ns;
733012Ssaidi@eecs.umich.eduTick ps;
742391SN/A/* namespace Float */ }
752391SN/A
762541SN/A/* namespace Clock */ }
772541SN/A
782541SN/A
792541SN/A// Dummy Object
802541SN/Aclass Root : public SimObject
812541SN/A{
822541SN/A  public:
832541SN/A    Root(const std::string &name) : SimObject(name) {}
842391SN/A};
852391SN/A
863012Ssaidi@eecs.umich.eduBEGIN_DECLARE_SIM_OBJECT_PARAMS(Root)
873918Ssaidi@eecs.umich.edu
882416SN/A    Param<Tick> clock;
892391SN/A    Param<string> output_file;
902391SN/A
912391SN/AEND_DECLARE_SIM_OBJECT_PARAMS(Root)
922391SN/A
932391SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(Root)
943012Ssaidi@eecs.umich.edu
954040Ssaidi@eecs.umich.edu    INIT_PARAM(clock, "tick frequency"),
962391SN/A    INIT_PARAM(output_file, "file to dump simulator output to")
973012Ssaidi@eecs.umich.edu
982391SN/AEND_INIT_SIM_OBJECT_PARAMS(Root)
992391SN/A
1002391SN/ACREATE_SIM_OBJECT(Root)
1012408SN/A{
1022408SN/A    static bool created = false;
1032408SN/A    if (created)
1042409SN/A        panic("only one root object allowed!");
1052409SN/A
1062408SN/A    created = true;
1072408SN/A
1083012Ssaidi@eecs.umich.edu    outputStream = simout.find(output_file);
1093349Sbinkertn@umich.edu    Root *root = new Root(getInstanceName());
1103012Ssaidi@eecs.umich.edu
1113012Ssaidi@eecs.umich.edu    using namespace Clock;
1123012Ssaidi@eecs.umich.edu    Frequency = clock;
1132413SN/A    Float::s = static_cast<double>(Frequency);
1143170Sstever@eecs.umich.edu    Float::ms = Float::s / 1.0e3;
1153170Sstever@eecs.umich.edu    Float::us = Float::s / 1.0e6;
1163170Sstever@eecs.umich.edu    Float::ns = Float::s / 1.0e9;
1173170Sstever@eecs.umich.edu    Float::ps = Float::s / 1.0e12;
1183170Sstever@eecs.umich.edu
1193170Sstever@eecs.umich.edu    Float::Hz  = 1.0 / Float::s;
1203170Sstever@eecs.umich.edu    Float::kHz = 1.0 / Float::ms;
1213170Sstever@eecs.umich.edu    Float::MHz = 1.0 / Float::us;
1223170Sstever@eecs.umich.edu    Float::GHZ = 1.0 / Float::ns;
1233170Sstever@eecs.umich.edu
1243170Sstever@eecs.umich.edu    Int::s  = Frequency;
1253170Sstever@eecs.umich.edu    Int::ms = Int::s / 1000;
1263170Sstever@eecs.umich.edu    Int::us = Int::ms / 1000;
1273170Sstever@eecs.umich.edu    Int::ns = Int::us / 1000;
1283170Sstever@eecs.umich.edu    Int::ps = Int::ns / 1000;
1293170Sstever@eecs.umich.edu
1303170Sstever@eecs.umich.edu    return root;
1313170Sstever@eecs.umich.edu}
1323170Sstever@eecs.umich.edu
1333170Sstever@eecs.umich.eduREGISTER_SIM_OBJECT("Root", Root)
1343170Sstever@eecs.umich.edu