core.cc revision 13409
14123Sbinkertn@umich.edu/* 24123Sbinkertn@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 39983Sstever@gmail.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 49983Sstever@gmail.com * Copyright (c) 2013 Mark D. Hill and David A. Wood 54123Sbinkertn@umich.edu * All rights reserved. 64123Sbinkertn@umich.edu * 74123Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 84123Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are 94123Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright 104123Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer; 114123Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright 124123Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the 134123Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution; 144123Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its 154123Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 164123Sbinkertn@umich.edu * this software without specific prior written permission. 174123Sbinkertn@umich.edu * 184123Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 194123Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 204123Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 214123Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 224123Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 234123Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 244123Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 254123Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 264123Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 274123Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 284123Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 294123Sbinkertn@umich.edu * 304123Sbinkertn@umich.edu * Authors: Nathan Binkert 314123Sbinkertn@umich.edu * Steve Reinhardt 324123Sbinkertn@umich.edu */ 334123Sbinkertn@umich.edu 3411793Sbrandon.potter@amd.com#include "sim/core.hh" 3511793Sbrandon.potter@amd.com 364123Sbinkertn@umich.edu#include <iostream> 374123Sbinkertn@umich.edu#include <string> 384123Sbinkertn@umich.edu 394123Sbinkertn@umich.edu#include "base/callback.hh" 4013409Sgabeblack@google.com#include "base/cprintf.hh" 4113409Sgabeblack@google.com#include "base/logging.hh" 424123Sbinkertn@umich.edu#include "base/output.hh" 439356Snilay@cs.wisc.edu#include "sim/eventq.hh" 444123Sbinkertn@umich.edu 454123Sbinkertn@umich.eduusing namespace std; 464123Sbinkertn@umich.edu 477064Snate@binkert.orgnamespace SimClock { 487823Ssteve.reinhardt@amd.com/// The simulated frequency of curTick(). (In ticks per second) 494167Sbinkertn@umich.eduTick Frequency; 504167Sbinkertn@umich.edu 514167Sbinkertn@umich.edunamespace Float { 524167Sbinkertn@umich.edudouble s; 534167Sbinkertn@umich.edudouble ms; 544167Sbinkertn@umich.edudouble us; 554167Sbinkertn@umich.edudouble ns; 564167Sbinkertn@umich.edudouble ps; 574167Sbinkertn@umich.edu 584167Sbinkertn@umich.edudouble Hz; 594167Sbinkertn@umich.edudouble kHz; 604167Sbinkertn@umich.edudouble MHz; 6112980Sgabeblack@google.comdouble GHz; 627811Ssteve.reinhardt@amd.com} // namespace Float 634167Sbinkertn@umich.edu 644167Sbinkertn@umich.edunamespace Int { 654167Sbinkertn@umich.eduTick s; 664167Sbinkertn@umich.eduTick ms; 674167Sbinkertn@umich.eduTick us; 684167Sbinkertn@umich.eduTick ns; 694167Sbinkertn@umich.eduTick ps; 707811Ssteve.reinhardt@amd.com} // namespace Float 714167Sbinkertn@umich.edu 727811Ssteve.reinhardt@amd.com} // namespace SimClock 734167Sbinkertn@umich.edu 7413409Sgabeblack@google.comnamespace { 7513409Sgabeblack@google.com 7613409Sgabeblack@google.combool _clockFrequencyFixed = false; 7713409Sgabeblack@google.com 7813409Sgabeblack@google.com// Default to 1 THz (1 Tick == 1 ps) 7913409Sgabeblack@google.comTick _ticksPerSecond = 1e12; 8013409Sgabeblack@google.com 8113409Sgabeblack@google.com} // anonymous namespace 8213409Sgabeblack@google.com 834167Sbinkertn@umich.eduvoid 8413409Sgabeblack@google.comfixClockFrequency() 854167Sbinkertn@umich.edu{ 8613409Sgabeblack@google.com if (_clockFrequencyFixed) 8713409Sgabeblack@google.com return; 8813409Sgabeblack@google.com 897064Snate@binkert.org using namespace SimClock; 9013409Sgabeblack@google.com Frequency = _ticksPerSecond; 914167Sbinkertn@umich.edu Float::s = static_cast<double>(Frequency); 924167Sbinkertn@umich.edu Float::ms = Float::s / 1.0e3; 934167Sbinkertn@umich.edu Float::us = Float::s / 1.0e6; 944167Sbinkertn@umich.edu Float::ns = Float::s / 1.0e9; 954167Sbinkertn@umich.edu Float::ps = Float::s / 1.0e12; 964167Sbinkertn@umich.edu 974167Sbinkertn@umich.edu Float::Hz = 1.0 / Float::s; 984167Sbinkertn@umich.edu Float::kHz = 1.0 / Float::ms; 994167Sbinkertn@umich.edu Float::MHz = 1.0 / Float::us; 10012980Sgabeblack@google.com Float::GHz = 1.0 / Float::ns; 1014167Sbinkertn@umich.edu 1024167Sbinkertn@umich.edu Int::s = Frequency; 1034167Sbinkertn@umich.edu Int::ms = Int::s / 1000; 1044167Sbinkertn@umich.edu Int::us = Int::ms / 1000; 1054167Sbinkertn@umich.edu Int::ns = Int::us / 1000; 1064167Sbinkertn@umich.edu Int::ps = Int::ns / 1000; 1074167Sbinkertn@umich.edu 10813409Sgabeblack@google.com cprintf("Global frequency set at %d ticks per second\n", _ticksPerSecond); 10913409Sgabeblack@google.com 11013409Sgabeblack@google.com _clockFrequencyFixed = true; 1114167Sbinkertn@umich.edu} 11213409Sgabeblack@google.combool clockFrequencyFixed() { return _clockFrequencyFixed; } 11313409Sgabeblack@google.com 11413409Sgabeblack@google.comvoid 11513409Sgabeblack@google.comsetClockFrequency(Tick tps) 11613409Sgabeblack@google.com{ 11713409Sgabeblack@google.com panic_if(_clockFrequencyFixed, 11813409Sgabeblack@google.com "Global frequency already fixed at %f ticks/s.", _ticksPerSecond); 11913409Sgabeblack@google.com _ticksPerSecond = tps; 12013409Sgabeblack@google.com} 12113409Sgabeblack@google.comTick getClockFrequency() { return _ticksPerSecond; } 1224167Sbinkertn@umich.edu 1234123Sbinkertn@umich.eduvoid 1244123Sbinkertn@umich.edusetOutputDir(const string &dir) 1254123Sbinkertn@umich.edu{ 1264123Sbinkertn@umich.edu simout.setDirectory(dir); 1274123Sbinkertn@umich.edu} 1284123Sbinkertn@umich.edu 1294123Sbinkertn@umich.edu/** 1304123Sbinkertn@umich.edu * Queue of C++ callbacks to invoke on simulator exit. 1314123Sbinkertn@umich.edu */ 1324123Sbinkertn@umich.eduinline CallbackQueue & 1334123Sbinkertn@umich.eduexitCallbacks() 1344123Sbinkertn@umich.edu{ 1354123Sbinkertn@umich.edu static CallbackQueue theQueue; 1364123Sbinkertn@umich.edu return theQueue; 1374123Sbinkertn@umich.edu} 1384123Sbinkertn@umich.edu 1394123Sbinkertn@umich.edu/** 1404123Sbinkertn@umich.edu * Register an exit callback. 1414123Sbinkertn@umich.edu */ 1424123Sbinkertn@umich.eduvoid 1434123Sbinkertn@umich.eduregisterExitCallback(Callback *callback) 1444123Sbinkertn@umich.edu{ 1454123Sbinkertn@umich.edu exitCallbacks().add(callback); 1464123Sbinkertn@umich.edu} 1474123Sbinkertn@umich.edu 1484123Sbinkertn@umich.edu/** 14911990Sandreas.sandberg@arm.com * Do C++ simulator exit processing. Exported to Python to be invoked 1504123Sbinkertn@umich.edu * when simulator terminates via Python's atexit mechanism. 1514123Sbinkertn@umich.edu */ 1524123Sbinkertn@umich.eduvoid 1534123Sbinkertn@umich.edudoExitCleanup() 1544123Sbinkertn@umich.edu{ 1554123Sbinkertn@umich.edu exitCallbacks().process(); 1564123Sbinkertn@umich.edu exitCallbacks().clear(); 1574123Sbinkertn@umich.edu 1584123Sbinkertn@umich.edu cout.flush(); 1594123Sbinkertn@umich.edu} 1604167Sbinkertn@umich.edu 161