root.cc revision 1695
1955SN/A/*
2955SN/A * Copyright (c) 2002-2004 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
294762Snate@binkert.org#include <cstring>
30955SN/A#include <fstream>
314762Snate@binkert.org#include <list>
32955SN/A#include <string>
33955SN/A#include <vector>
344202Sbinkertn@umich.edu
354382Sbinkertn@umich.edu#include "base/misc.hh"
364202Sbinkertn@umich.edu#include "base/output.hh"
374762Snate@binkert.org#include "sim/builder.hh"
384762Snate@binkert.org#include "sim/host.hh"
394762Snate@binkert.org#include "sim/sim_object.hh"
40955SN/A#include "sim/universe.hh"
414381Sbinkertn@umich.edu
424381Sbinkertn@umich.eduusing namespace std;
43955SN/A
44955SN/ATick curTick = 0;
45955SN/Aostream *outputStream;
464202Sbinkertn@umich.eduostream *configStream;
47955SN/A
484382Sbinkertn@umich.edu/// The simulated frequency of curTick. (This is only here for a short time)
494382Sbinkertn@umich.eduTick ticksPerSecond;
504382Sbinkertn@umich.edu
514762Snate@binkert.orgnamespace Clock {
524762Snate@binkert.org/// The simulated frequency of curTick. (In ticks per second)
534762Snate@binkert.orgTick Frequency;
544762Snate@binkert.org
554762Snate@binkert.orgnamespace Float {
564762Snate@binkert.orgdouble s;
574762Snate@binkert.orgdouble ms;
584762Snate@binkert.orgdouble us;
594762Snate@binkert.orgdouble ns;
604762Snate@binkert.orgdouble ps;
614762Snate@binkert.org
624762Snate@binkert.orgdouble Hz;
634762Snate@binkert.orgdouble kHz;
644762Snate@binkert.orgdouble MHz;
654762Snate@binkert.orgdouble GHZ;
664762Snate@binkert.org/* namespace Float */ }
674762Snate@binkert.org
684762Snate@binkert.orgnamespace Int {
694762Snate@binkert.orgTick s;
704762Snate@binkert.orgTick ms;
714762Snate@binkert.orgTick us;
724762Snate@binkert.orgTick ns;
734762Snate@binkert.orgTick ps;
744762Snate@binkert.org/* namespace Float */ }
754762Snate@binkert.org
764762Snate@binkert.org/* namespace Clock */ }
774762Snate@binkert.org
784762Snate@binkert.org
794762Snate@binkert.org// Dummy Object
804762Snate@binkert.orgclass Root : public SimObject
814762Snate@binkert.org{
824762Snate@binkert.org  public:
834762Snate@binkert.org    Root(const std::string &name) : SimObject(name) {}
844382Sbinkertn@umich.edu};
854762Snate@binkert.org
864382Sbinkertn@umich.eduBEGIN_DECLARE_SIM_OBJECT_PARAMS(Root)
874762Snate@binkert.org
884381Sbinkertn@umich.edu    Param<Tick> clock;
894762Snate@binkert.org    Param<string> output_file;
904762Snate@binkert.org
914762Snate@binkert.orgEND_DECLARE_SIM_OBJECT_PARAMS(Root)
924762Snate@binkert.org
934762Snate@binkert.orgBEGIN_INIT_SIM_OBJECT_PARAMS(Root)
944762Snate@binkert.org
954762Snate@binkert.org    INIT_PARAM(clock, "tick frequency"),
964762Snate@binkert.org    INIT_PARAM(output_file, "file to dump simulator output to")
974762Snate@binkert.org
984762Snate@binkert.orgEND_INIT_SIM_OBJECT_PARAMS(Root)
994762Snate@binkert.org
1004762Snate@binkert.orgCREATE_SIM_OBJECT(Root)
1014762Snate@binkert.org{
1024762Snate@binkert.org    static bool created = false;
1034762Snate@binkert.org    if (created)
1044762Snate@binkert.org        panic("only one root object allowed!");
1054762Snate@binkert.org
1064762Snate@binkert.org    created = true;
1074762Snate@binkert.org
1084762Snate@binkert.org    outputStream = simout.find(output_file);
1094762Snate@binkert.org    Root *root = new Root(getInstanceName());
1104762Snate@binkert.org
1114762Snate@binkert.org    using namespace Clock;
1124762Snate@binkert.org    Frequency = clock;
1134762Snate@binkert.org    Float::s = static_cast<double>(Frequency);
1144762Snate@binkert.org    Float::ms = Float::s / 1.0e3;
1154762Snate@binkert.org    Float::us = Float::s / 1.0e6;
1164762Snate@binkert.org    Float::ns = Float::s / 1.0e9;
1174762Snate@binkert.org    Float::ps = Float::s / 1.0e12;
1184762Snate@binkert.org
1194762Snate@binkert.org    Float::Hz  = 1.0 / Float::s;
1204762Snate@binkert.org    Float::kHz = 1.0 / Float::ms;
1214762Snate@binkert.org    Float::MHz = 1.0 / Float::us;
1224762Snate@binkert.org    Float::GHZ = 1.0 / Float::ns;
1234762Snate@binkert.org
1244762Snate@binkert.org    Int::s  = Frequency;
1254762Snate@binkert.org    Int::ms = Int::s / 1000;
1264762Snate@binkert.org    Int::us = Int::ms / 1000;
1274762Snate@binkert.org    Int::ns = Int::us / 1000;
1284762Snate@binkert.org    Int::ps = Int::ns / 1000;
129955SN/A
1304382Sbinkertn@umich.edu    return root;
1314202Sbinkertn@umich.edu}
1324382Sbinkertn@umich.edu
1334382Sbinkertn@umich.eduREGISTER_SIM_OBJECT("Root", Root)
1344382Sbinkertn@umich.edu