pseudo_inst.cc revision 3089
1298SN/A/* 22188SN/A * Copyright (c) 2003-2006 The Regents of The University of Michigan 3298SN/A * All rights reserved. 4298SN/A * 5298SN/A * Redistribution and use in source and binary forms, with or without 6298SN/A * modification, are permitted provided that the following conditions are 7298SN/A * met: redistributions of source code must retain the above copyright 8298SN/A * notice, this list of conditions and the following disclaimer; 9298SN/A * redistributions in binary form must reproduce the above copyright 10298SN/A * notice, this list of conditions and the following disclaimer in the 11298SN/A * documentation and/or other materials provided with the distribution; 12298SN/A * neither the name of the copyright holders nor the names of its 13298SN/A * contributors may be used to endorse or promote products derived from 14298SN/A * this software without specific prior written permission. 15298SN/A * 16298SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17298SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18298SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19298SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20298SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21298SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22298SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23298SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24298SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25298SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26298SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 29298SN/A */ 30298SN/A 311642SN/A#include <errno.h> 32954SN/A#include <fcntl.h> 33956SN/A#include <unistd.h> 34956SN/A 35299SN/A#include <string> 36299SN/A 372081SN/A#include "sim/pseudo_inst.hh" 382170SN/A#include "arch/vtophys.hh" 393089Ssaidi@eecs.umich.edu#include "base/annotate.hh" 401717SN/A#include "cpu/base.hh" 412680Sktlim@umich.edu#include "cpu/thread_context.hh" 422313SN/A#include "cpu/quiesce_event.hh" 431070SN/A#include "kern/kernel_stats.hh" 44299SN/A#include "sim/param.hh" 45298SN/A#include "sim/serialize.hh" 46298SN/A#include "sim/sim_exit.hh" 47695SN/A#include "sim/stat_control.hh" 48695SN/A#include "sim/stats.hh" 49954SN/A#include "sim/system.hh" 501052SN/A#include "sim/debug.hh" 512080SN/A#include "sim/vptr.hh" 52298SN/A 53299SN/Ausing namespace std; 541052SN/A 55729SN/Ausing namespace Stats; 562107SN/Ausing namespace TheISA; 57298SN/A 58298SN/Anamespace AlphaPseudo 59298SN/A{ 60299SN/A bool doStatisticsInsts; 61299SN/A bool doCheckpointInsts; 62310SN/A bool doQuiesce; 63310SN/A 64310SN/A void 652680Sktlim@umich.edu arm(ThreadContext *tc) 66711SN/A { 672680Sktlim@umich.edu if (tc->getKernelStats()) 682680Sktlim@umich.edu tc->getKernelStats()->arm(); 69711SN/A } 70711SN/A 71711SN/A void 722680Sktlim@umich.edu quiesce(ThreadContext *tc) 73310SN/A { 74310SN/A if (!doQuiesce) 75310SN/A return; 76310SN/A 772680Sktlim@umich.edu tc->suspend(); 782680Sktlim@umich.edu if (tc->getKernelStats()) 792680Sktlim@umich.edu tc->getKernelStats()->quiesce(); 80310SN/A } 81299SN/A 82298SN/A void 832680Sktlim@umich.edu quiesceNs(ThreadContext *tc, uint64_t ns) 842188SN/A { 852188SN/A if (!doQuiesce || ns == 0) 862188SN/A return; 872188SN/A 882680Sktlim@umich.edu EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 892235SN/A 902235SN/A if (quiesceEvent->scheduled()) 912235SN/A quiesceEvent->reschedule(curTick + Clock::Int::ns * ns); 922188SN/A else 932235SN/A quiesceEvent->schedule(curTick + Clock::Int::ns * ns); 942188SN/A 952680Sktlim@umich.edu tc->suspend(); 962680Sktlim@umich.edu if (tc->getKernelStats()) 972680Sktlim@umich.edu tc->getKernelStats()->quiesce(); 982188SN/A } 992188SN/A 1002188SN/A void 1012680Sktlim@umich.edu quiesceCycles(ThreadContext *tc, uint64_t cycles) 1022188SN/A { 1032188SN/A if (!doQuiesce || cycles == 0) 1042188SN/A return; 1052188SN/A 1062680Sktlim@umich.edu EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 1072235SN/A 1082235SN/A if (quiesceEvent->scheduled()) 1092235SN/A quiesceEvent->reschedule(curTick + 1102680Sktlim@umich.edu tc->getCpuPtr()->cycles(cycles)); 1112188SN/A else 1122235SN/A quiesceEvent->schedule(curTick + 1132680Sktlim@umich.edu tc->getCpuPtr()->cycles(cycles)); 1142188SN/A 1152680Sktlim@umich.edu tc->suspend(); 1162680Sktlim@umich.edu if (tc->getKernelStats()) 1172680Sktlim@umich.edu tc->getKernelStats()->quiesce(); 1182188SN/A } 1192188SN/A 1202188SN/A uint64_t 1212680Sktlim@umich.edu quiesceTime(ThreadContext *tc) 1222188SN/A { 1232680Sktlim@umich.edu return (tc->readLastActivate() - tc->readLastSuspend()) / Clock::Int::ns; 1242188SN/A } 1252188SN/A 1262188SN/A void 1272680Sktlim@umich.edu ivlb(ThreadContext *tc) 128711SN/A { 1292680Sktlim@umich.edu if (tc->getKernelStats()) 1302680Sktlim@umich.edu tc->getKernelStats()->ivlb(); 131711SN/A } 132711SN/A 133711SN/A void 1342680Sktlim@umich.edu ivle(ThreadContext *tc) 135711SN/A { 136711SN/A } 137711SN/A 138711SN/A void 1392680Sktlim@umich.edu m5exit_old(ThreadContext *tc) 140298SN/A { 1412667Sstever@eecs.umich.edu exitSimLoop(curTick, "m5_exit_old instruction encountered"); 142298SN/A } 143298SN/A 144298SN/A void 1452680Sktlim@umich.edu m5exit(ThreadContext *tc, Tick delay) 146298SN/A { 1471609SN/A Tick when = curTick + delay * Clock::Int::ns; 1482667Sstever@eecs.umich.edu exitSimLoop(when, "m5_exit instruction encountered"); 149298SN/A } 150298SN/A 151298SN/A void 1522680Sktlim@umich.edu resetstats(ThreadContext *tc, Tick delay, Tick period) 153298SN/A { 154299SN/A if (!doStatisticsInsts) 155299SN/A return; 156299SN/A 157298SN/A 1581609SN/A Tick when = curTick + delay * Clock::Int::ns; 1591609SN/A Tick repeat = period * Clock::Int::ns; 160298SN/A 161729SN/A using namespace Stats; 162298SN/A SetupEvent(Reset, when, repeat); 163298SN/A } 164298SN/A 165298SN/A void 1662680Sktlim@umich.edu dumpstats(ThreadContext *tc, Tick delay, Tick period) 167298SN/A { 168299SN/A if (!doStatisticsInsts) 169299SN/A return; 170299SN/A 171298SN/A 1721609SN/A Tick when = curTick + delay * Clock::Int::ns; 1731609SN/A Tick repeat = period * Clock::Int::ns; 174298SN/A 175729SN/A using namespace Stats; 176298SN/A SetupEvent(Dump, when, repeat); 177298SN/A } 178298SN/A 179298SN/A void 1802680Sktlim@umich.edu addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 1811973SN/A { 1821973SN/A char symb[100]; 1832680Sktlim@umich.edu CopyStringOut(tc, symb, symbolAddr, 100); 1841973SN/A std::string symbol(symb); 1851973SN/A 1861973SN/A DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 1871973SN/A 1882680Sktlim@umich.edu tc->getSystemPtr()->kernelSymtab->insert(addr,symbol); 1891973SN/A } 1901973SN/A 1911973SN/A void 1923089Ssaidi@eecs.umich.edu anBegin(ThreadContext *tc, uint64_t cur) 1933089Ssaidi@eecs.umich.edu { 1943089Ssaidi@eecs.umich.edu Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur & 1953089Ssaidi@eecs.umich.edu 0xFFFFFFFF, 0,0); 1963089Ssaidi@eecs.umich.edu } 1973089Ssaidi@eecs.umich.edu 1983089Ssaidi@eecs.umich.edu void 1993089Ssaidi@eecs.umich.edu anWait(ThreadContext *tc, uint64_t cur, uint64_t wait) 2003089Ssaidi@eecs.umich.edu { 2013089Ssaidi@eecs.umich.edu Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur & 2023089Ssaidi@eecs.umich.edu 0xFFFFFFFF, wait >> 32, wait & 0xFFFFFFFF); 2033089Ssaidi@eecs.umich.edu } 2043089Ssaidi@eecs.umich.edu 2053089Ssaidi@eecs.umich.edu 2063089Ssaidi@eecs.umich.edu void 2072680Sktlim@umich.edu dumpresetstats(ThreadContext *tc, Tick delay, Tick period) 208298SN/A { 209299SN/A if (!doStatisticsInsts) 210299SN/A return; 211299SN/A 212298SN/A 2131609SN/A Tick when = curTick + delay * Clock::Int::ns; 2141609SN/A Tick repeat = period * Clock::Int::ns; 215298SN/A 216729SN/A using namespace Stats; 217298SN/A SetupEvent(Dump|Reset, when, repeat); 218298SN/A } 219298SN/A 220298SN/A void 2212680Sktlim@umich.edu m5checkpoint(ThreadContext *tc, Tick delay, Tick period) 222298SN/A { 223299SN/A if (!doCheckpointInsts) 224299SN/A return; 2252841Sktlim@umich.edu exitSimLoop("checkpoint"); 226298SN/A } 227298SN/A 2282081SN/A uint64_t 2292680Sktlim@umich.edu readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) 230954SN/A { 2312680Sktlim@umich.edu const string &file = tc->getCpuPtr()->system->params()->readfile; 232954SN/A if (file.empty()) { 2332081SN/A return ULL(0); 234954SN/A } 235954SN/A 236954SN/A uint64_t result = 0; 237954SN/A 238954SN/A int fd = ::open(file.c_str(), O_RDONLY, 0); 239954SN/A if (fd < 0) 240954SN/A panic("could not open file %s\n", file); 241954SN/A 2421642SN/A if (::lseek(fd, offset, SEEK_SET) < 0) 2431642SN/A panic("could not seek: %s", strerror(errno)); 2441642SN/A 245954SN/A char *buf = new char[len]; 246954SN/A char *p = buf; 247954SN/A while (len > 0) { 2481642SN/A int bytes = ::read(fd, p, len); 249954SN/A if (bytes <= 0) 250954SN/A break; 251954SN/A 252954SN/A p += bytes; 253954SN/A result += bytes; 254954SN/A len -= bytes; 255954SN/A } 256954SN/A 257954SN/A close(fd); 2582680Sktlim@umich.edu CopyIn(tc, vaddr, buf, result); 259954SN/A delete [] buf; 2602081SN/A return result; 261954SN/A } 262954SN/A 263299SN/A class Context : public ParamContext 264299SN/A { 265299SN/A public: 266299SN/A Context(const string §ion) : ParamContext(section) {} 267299SN/A void checkParams(); 268299SN/A }; 269299SN/A 2701343SN/A Context context("pseudo_inst"); 271299SN/A 272310SN/A Param<bool> __quiesce(&context, "quiesce", 273310SN/A "enable quiesce instructions", 274310SN/A true); 275300SN/A Param<bool> __statistics(&context, "statistics", 276310SN/A "enable statistics pseudo instructions", 277301SN/A true); 278300SN/A Param<bool> __checkpoint(&context, "checkpoint", 279310SN/A "enable checkpoint pseudo instructions", 280301SN/A true); 281299SN/A 282299SN/A void 283299SN/A Context::checkParams() 284299SN/A { 285310SN/A doQuiesce = __quiesce; 286299SN/A doStatisticsInsts = __statistics; 287299SN/A doCheckpointInsts = __checkpoint; 288299SN/A } 2891052SN/A 2902680Sktlim@umich.edu void debugbreak(ThreadContext *tc) 2911052SN/A { 2921052SN/A debug_break(); 2931052SN/A } 2941052SN/A 2952680Sktlim@umich.edu void switchcpu(ThreadContext *tc) 2961052SN/A { 2972841Sktlim@umich.edu exitSimLoop("switchcpu"); 2981052SN/A } 299298SN/A} 300