pseudo_inst.cc revision 2081
12SN/A/* 28733Sgeoffrey.blake@arm.com * Copyright (c) 2003-2005 The Regents of The University of Michigan 37338SAli.Saidi@ARM.com * All rights reserved. 47338SAli.Saidi@ARM.com * 57338SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 67338SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 77338SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright 87338SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 97338SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 107338SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the 117338SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution; 127338SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its 137338SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from 141762SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272SN/A */ 282SN/A 292SN/A#include <errno.h> 302SN/A#include <fcntl.h> 312SN/A#include <unistd.h> 322SN/A#include <cstdio> 332SN/A 342SN/A#include <string> 352SN/A 362SN/A#include "sim/pseudo_inst.hh" 372SN/A#include "targetarch/vtophys.hh" 382SN/A#include "cpu/base.hh" 392665Ssaidi@eecs.umich.edu#include "cpu/sampler/sampler.hh" 402665Ssaidi@eecs.umich.edu#include "cpu/exec_context.hh" 412SN/A#include "kern/kernel_stats.hh" 422SN/A#include "sim/param.hh" 438779Sgblack@eecs.umich.edu#include "sim/serialize.hh" 448779Sgblack@eecs.umich.edu#include "sim/sim_exit.hh" 458779Sgblack@eecs.umich.edu#include "sim/stat_control.hh" 462439SN/A#include "sim/stats.hh" 478779Sgblack@eecs.umich.edu#include "sim/system.hh" 488229Snate@binkert.org#include "sim/debug.hh" 496216Snate@binkert.org#include "sim/vptr.hh" 50146SN/A 51146SN/Ausing namespace std; 52146SN/A 53146SN/Aextern Sampler *SampCPU; 54146SN/A 55146SN/Ausing namespace Stats; 566216Snate@binkert.org 576658Snate@binkert.orgnamespace AlphaPseudo 588229Snate@binkert.org{ 591717SN/A bool doStatisticsInsts; 608887Sgeoffrey.blake@arm.com bool doCheckpointInsts; 618887Sgeoffrey.blake@arm.com bool doQuiesce; 62146SN/A 631977SN/A void 642683Sktlim@umich.edu arm(ExecContext *xc) 651717SN/A { 66146SN/A xc->kernelStats->arm(); 672683Sktlim@umich.edu } 688232Snate@binkert.org 698232Snate@binkert.org void 708232Snate@binkert.org quiesce(ExecContext *xc) 718779Sgblack@eecs.umich.edu { 723348Sbinkertn@umich.edu if (!doQuiesce) 736105Ssteve.reinhardt@amd.com return; 746216Snate@binkert.org 752036SN/A xc->suspend(); 76146SN/A xc->kernelStats->quiesce(); 778817Sgblack@eecs.umich.edu } 788793Sgblack@eecs.umich.edu 7956SN/A void 8056SN/A ivlb(ExecContext *xc) 81695SN/A { 822901Ssaidi@eecs.umich.edu xc->kernelStats->ivlb(); 832SN/A } 842SN/A 852449SN/A void 861355SN/A ivle(ExecContext *xc) 875529Snate@binkert.org { 889023Sgblack@eecs.umich.edu } 89224SN/A 908793Sgblack@eecs.umich.edu void 918793Sgblack@eecs.umich.edu m5exit_old(ExecContext *xc) 928793Sgblack@eecs.umich.edu { 938820Sgblack@eecs.umich.edu SimExit(curTick, "m5_exit_old instruction encountered"); 948820Sgblack@eecs.umich.edu } 952SN/A 966029Ssteve.reinhardt@amd.com void 972672Sktlim@umich.edu m5exit(ExecContext *xc, Tick delay) 982683Sktlim@umich.edu { 992SN/A Tick when = curTick + delay * Clock::Int::ns; 1008733Sgeoffrey.blake@arm.com SimExit(when, "m5_exit instruction encountered"); 1018733Sgeoffrey.blake@arm.com } 1028733Sgeoffrey.blake@arm.com 1038733Sgeoffrey.blake@arm.com void 1048733Sgeoffrey.blake@arm.com resetstats(ExecContext *xc, Tick delay, Tick period) 1058733Sgeoffrey.blake@arm.com { 1068733Sgeoffrey.blake@arm.com if (!doStatisticsInsts) 1078733Sgeoffrey.blake@arm.com return; 1088733Sgeoffrey.blake@arm.com 1098733Sgeoffrey.blake@arm.com 1108733Sgeoffrey.blake@arm.com Tick when = curTick + delay * Clock::Int::ns; 1112SN/A Tick repeat = period * Clock::Int::ns; 112334SN/A 1138834Satgutier@umich.edu using namespace Stats; 1148834Satgutier@umich.edu SetupEvent(Reset, when, repeat); 115140SN/A } 116334SN/A 1172SN/A void 1182SN/A dumpstats(ExecContext *xc, Tick delay, Tick period) 1192SN/A { 1202680Sktlim@umich.edu if (!doStatisticsInsts) 1214377Sgblack@eecs.umich.edu return; 1225169Ssaidi@eecs.umich.edu 1234377Sgblack@eecs.umich.edu 1244377Sgblack@eecs.umich.edu Tick when = curTick + delay * Clock::Int::ns; 1252SN/A Tick repeat = period * Clock::Int::ns; 1262SN/A 1272623SN/A using namespace Stats; 1282SN/A SetupEvent(Dump, when, repeat); 1292SN/A } 1302SN/A 131180SN/A void 1328737Skoansin.tan@gmail.com addsymbol(ExecContext *xc, Addr addr, Addr symbolAddr) 133393SN/A { 134393SN/A char symb[100]; 135393SN/A CopyString(xc, symb, symbolAddr, 100); 136393SN/A std::string symbol(symb); 137384SN/A 138384SN/A DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 139393SN/A 1408737Skoansin.tan@gmail.com xc->system->kernelSymtab->insert(addr,symbol); 141393SN/A } 142393SN/A 143393SN/A void 144393SN/A dumpresetstats(ExecContext *xc, Tick delay, Tick period) 145384SN/A { 146189SN/A if (!doStatisticsInsts) 147189SN/A return; 1482623SN/A 1492SN/A 150729SN/A Tick when = curTick + delay * Clock::Int::ns; 151334SN/A Tick repeat = period * Clock::Int::ns; 1522SN/A 1532SN/A using namespace Stats; 1542SN/A SetupEvent(Dump|Reset, when, repeat); 1558834Satgutier@umich.edu } 1568834Satgutier@umich.edu 1578834Satgutier@umich.edu void 1588834Satgutier@umich.edu m5checkpoint(ExecContext *xc, Tick delay, Tick period) 1598834Satgutier@umich.edu { 1608834Satgutier@umich.edu if (!doCheckpointInsts) 1618834Satgutier@umich.edu return; 1622SN/A 1632SN/A 1647897Shestness@cs.utexas.edu Tick when = curTick + delay * Clock::Int::ns; 1657897Shestness@cs.utexas.edu Tick repeat = period * Clock::Int::ns; 1667897Shestness@cs.utexas.edu 1677897Shestness@cs.utexas.edu Checkpoint::setup(when, repeat); 1687897Shestness@cs.utexas.edu } 1697897Shestness@cs.utexas.edu 1707897Shestness@cs.utexas.edu uint64_t 1717897Shestness@cs.utexas.edu readfile(ExecContext *xc, Addr vaddr, uint64_t len, uint64_t offset) 1727897Shestness@cs.utexas.edu { 1737897Shestness@cs.utexas.edu const string &file = xc->cpu->system->params->readfile; 1747897Shestness@cs.utexas.edu if (file.empty()) { 1757897Shestness@cs.utexas.edu return ULL(0); 1767897Shestness@cs.utexas.edu } 1777897Shestness@cs.utexas.edu 1787897Shestness@cs.utexas.edu uint64_t result = 0; 1797897Shestness@cs.utexas.edu 1807897Shestness@cs.utexas.edu int fd = ::open(file.c_str(), O_RDONLY, 0); 1817897Shestness@cs.utexas.edu if (fd < 0) 1827897Shestness@cs.utexas.edu panic("could not open file %s\n", file); 1837897Shestness@cs.utexas.edu 1847897Shestness@cs.utexas.edu if (::lseek(fd, offset, SEEK_SET) < 0) 1857897Shestness@cs.utexas.edu panic("could not seek: %s", strerror(errno)); 1867897Shestness@cs.utexas.edu 1877897Shestness@cs.utexas.edu char *buf = new char[len]; 1887897Shestness@cs.utexas.edu char *p = buf; 1897897Shestness@cs.utexas.edu while (len > 0) { 1907897Shestness@cs.utexas.edu int bytes = ::read(fd, p, len); 1917897Shestness@cs.utexas.edu if (bytes <= 0) 1927897Shestness@cs.utexas.edu break; 1937897Shestness@cs.utexas.edu 1947897Shestness@cs.utexas.edu p += bytes; 1957897Shestness@cs.utexas.edu result += bytes; 1967897Shestness@cs.utexas.edu len -= bytes; 1977897Shestness@cs.utexas.edu } 1987897Shestness@cs.utexas.edu 1997897Shestness@cs.utexas.edu close(fd); 2007897Shestness@cs.utexas.edu CopyIn(xc, vaddr, buf, result); 2017897Shestness@cs.utexas.edu delete [] buf; 2027897Shestness@cs.utexas.edu return result; 2037897Shestness@cs.utexas.edu } 2047897Shestness@cs.utexas.edu 2057897Shestness@cs.utexas.edu class Context : public ParamContext 2067897Shestness@cs.utexas.edu { 2077897Shestness@cs.utexas.edu public: 2087897Shestness@cs.utexas.edu Context(const string §ion) : ParamContext(section) {} 2097897Shestness@cs.utexas.edu void checkParams(); 2107897Shestness@cs.utexas.edu }; 2117897Shestness@cs.utexas.edu 2127897Shestness@cs.utexas.edu Context context("pseudo_inst"); 2137897Shestness@cs.utexas.edu 2142SN/A Param<bool> __quiesce(&context, "quiesce", 2157897Shestness@cs.utexas.edu "enable quiesce instructions", 2167897Shestness@cs.utexas.edu true); 2177897Shestness@cs.utexas.edu Param<bool> __statistics(&context, "statistics", 2187897Shestness@cs.utexas.edu "enable statistics pseudo instructions", 2197897Shestness@cs.utexas.edu true); 2207897Shestness@cs.utexas.edu Param<bool> __checkpoint(&context, "checkpoint", 2217897Shestness@cs.utexas.edu "enable checkpoint pseudo instructions", 2227897Shestness@cs.utexas.edu true); 2237897Shestness@cs.utexas.edu 2247897Shestness@cs.utexas.edu void 2257897Shestness@cs.utexas.edu Context::checkParams() 2267897Shestness@cs.utexas.edu { 2272SN/A doQuiesce = __quiesce; 2282SN/A doStatisticsInsts = __statistics; 2291001SN/A doCheckpointInsts = __checkpoint; 2301001SN/A } 2311001SN/A 2321001SN/A void debugbreak(ExecContext *xc) 2331001SN/A { 2342SN/A debug_break(); 2352SN/A } 2362SN/A 2372SN/A void switchcpu(ExecContext *xc) 2382SN/A { 2397897Shestness@cs.utexas.edu if (SampCPU) 2407897Shestness@cs.utexas.edu SampCPU->switchCPUs(); 2417897Shestness@cs.utexas.edu } 2427897Shestness@cs.utexas.edu} 2437897Shestness@cs.utexas.edu