root.cc revision 488
112027Sjungma@eit.uni-kl.de/* 212027Sjungma@eit.uni-kl.de * Copyright (c) 2003 The Regents of The University of Michigan 312027Sjungma@eit.uni-kl.de * All rights reserved. 412027Sjungma@eit.uni-kl.de * 512027Sjungma@eit.uni-kl.de * 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 <sys/types.h> 30#include <sys/stat.h> 31 32#include <cstring> 33#include <fstream> 34#include <list> 35#include <string> 36#include <vector> 37 38#include "base/files.hh" 39#include "base/misc.hh" 40#include "sim/universe.hh" 41#include "sim/host.hh" 42#include "sim/param.hh" 43 44using namespace std; 45 46Tick curTick = 0; 47Tick ticksPerSecond; 48double __ticksPerMS; 49double __ticksPerUS; 50double __ticksPerNS; 51 52string outputDirectory; 53ostream *outputStream; 54 55class UniverseParamContext : public ParamContext 56{ 57 private: 58 ofstream outputFile; 59 60 public: 61 UniverseParamContext(const string &is) : ParamContext(is) {} 62 void checkParams(); 63}; 64 65UniverseParamContext universe("Universe"); 66 67Param<Tick> universe_freq(&universe, "frequency", "tick frequency", 68 200000000); 69 70Param<string> universe_output_dir(&universe, "output_dir", 71 "directory to output data to"); 72Param<string> universe_output_file(&universe, "output_file", 73 "file to dump simulator output to"); 74 75void 76UniverseParamContext::checkParams() 77{ 78 ticksPerSecond = universe_freq; 79 double freq = double(ticksPerSecond); 80 __ticksPerMS = freq / 1.0e3; 81 __ticksPerUS = freq / 1.0e6; 82 __ticksPerNS = freq / 1.0e9; 83 84 if (universe_output_dir.isValid()) { 85 outputDirectory = universe_output_dir; 86 87 // guarantee that directory ends with a '/' 88 if (outputDirectory[outputDirectory.size() - 1] != '/') 89 outputDirectory += "/"; 90 91 if (mkdir(outputDirectory.c_str(), 0777) < 0) { 92 if (errno != EEXIST) { 93 panic("%s\ncould not make output directory: %s\n", 94 strerror(errno), outputDirectory); 95 } 96 } 97 } 98 99 string filename; 100 if (universe_output_file.isValid()) { 101 string f = universe_output_file; 102 if (f != "stdout" && f != "cout" && f != "stderr" && f != "cerr") 103 filename = outputDirectory + f; 104 else 105 filename = f; 106 } else { 107 if (outputDirectory.empty()) 108 filename = "stdout"; 109 else 110 filename = outputDirectory + "output.txt"; 111 } 112 113 if (filename == "stdout" || filename == "cout") 114 outputStream = &cout; 115 else if (filename == "stderr" || filename == "cerr") 116 outputStream = &cerr; 117 else { 118 outputFile.open(filename.c_str(), ios::trunc); 119 outputStream = &outputFile; 120 } 121} 122