root.cc revision 1609
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/universe.hh" 41 42using namespace std; 43 44Tick curTick = 0; 45bool fullSystem; 46ostream *outputStream; 47ostream *configStream; 48 49/// The simulated frequency of curTick. (This is only here for a short time) 50Tick ticksPerSecond; 51 52namespace Clock { 53/// The simulated frequency of curTick. (In ticks per second) 54Tick Frequency; 55 56namespace Float { 57double s; 58double ms; 59double us; 60double ns; 61double ps; 62 63double Hz; 64double kHz; 65double MHz; 66double GHZ; 67/* namespace Float */ } 68 69namespace Int { 70Tick s; 71Tick ms; 72Tick us; 73Tick ns; 74Tick ps; 75/* namespace Float */ } 76 77/* namespace Clock */ } 78 79 80// Dummy Object 81class Root : public SimObject 82{ 83 public: 84 Root(const std::string &name) : SimObject(name) {} 85}; 86 87BEGIN_DECLARE_SIM_OBJECT_PARAMS(Root) 88 89 Param<bool> full_system; 90 Param<Tick> frequency; 91 Param<string> output_file; 92 93END_DECLARE_SIM_OBJECT_PARAMS(Root) 94 95BEGIN_INIT_SIM_OBJECT_PARAMS(Root) 96 97 INIT_PARAM(full_system, "full system simulation"), 98 INIT_PARAM(frequency, "tick frequency"), 99 INIT_PARAM(output_file, "file to dump simulator output to") 100 101END_INIT_SIM_OBJECT_PARAMS(Root) 102 103CREATE_SIM_OBJECT(Root) 104{ 105 static bool created = false; 106 if (created) 107 panic("only one root object allowed!"); 108 109 created = true; 110 fullSystem = full_system; 111 112#ifdef FULL_SYSTEM 113 if (!fullSystem) 114 panic("FULL_SYSTEM compiled and configuration not full_system"); 115#else 116 if (fullSystem) 117 panic("FULL_SYSTEM not compiled but configuration is full_system"); 118#endif 119 120 outputStream = simout.find(output_file); 121 Root *root = new Root(getInstanceName()); 122 123 ticksPerSecond = frequency; 124 125 using namespace Clock; 126 Frequency = frequency; 127 Float::s = static_cast<double>(Frequency); 128 Float::ms = Float::s / 1.0e3; 129 Float::us = Float::s / 1.0e6; 130 Float::ns = Float::s / 1.0e9; 131 Float::ps = Float::s / 1.0e12; 132 133 Float::Hz = 1.0 / Float::s; 134 Float::kHz = 1.0 / Float::ms; 135 Float::MHz = 1.0 / Float::us; 136 Float::GHZ = 1.0 / Float::ns; 137 138 Int::s = Frequency; 139 Int::ms = Int::s / 1000; 140 Int::us = Int::ms / 1000; 141 Int::ns = Int::us / 1000; 142 Int::ps = Int::ns / 1000; 143 144 return root; 145} 146 147REGISTER_SIM_OBJECT("Root", Root) 148