pseudo_inst.cc revision 9952
1298SN/A/* 29659SAndreas.Sandberg@ARM.com * Copyright (c) 2010-2012 ARM Limited 38142SAli.Saidi@ARM.com * All rights reserved 48142SAli.Saidi@ARM.com * 58142SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall 68142SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual 78142SAli.Saidi@ARM.com * property including but not limited to intellectual property relating 88142SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software 98142SAli.Saidi@ARM.com * licensed hereunder. You may use the software subject to the license 108142SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated 118142SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software, 128142SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form. 138142SAli.Saidi@ARM.com * 148580Ssteve.reinhardt@amd.com * Copyright (c) 2011 Advanced Micro Devices, Inc. 152188SN/A * Copyright (c) 2003-2006 The Regents of The University of Michigan 16298SN/A * All rights reserved. 17298SN/A * 18298SN/A * Redistribution and use in source and binary forms, with or without 19298SN/A * modification, are permitted provided that the following conditions are 20298SN/A * met: redistributions of source code must retain the above copyright 21298SN/A * notice, this list of conditions and the following disclaimer; 22298SN/A * redistributions in binary form must reproduce the above copyright 23298SN/A * notice, this list of conditions and the following disclaimer in the 24298SN/A * documentation and/or other materials provided with the distribution; 25298SN/A * neither the name of the copyright holders nor the names of its 26298SN/A * contributors may be used to endorse or promote products derived from 27298SN/A * this software without specific prior written permission. 28298SN/A * 29298SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30298SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31298SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32298SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33298SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34298SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35298SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36298SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37298SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38298SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39298SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu * 412665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 42298SN/A */ 43298SN/A 44954SN/A#include <fcntl.h> 45956SN/A#include <unistd.h> 46956SN/A 478229Snate@binkert.org#include <cerrno> 484078Sbinkertn@umich.edu#include <fstream> 49299SN/A#include <string> 509659SAndreas.Sandberg@ARM.com#include <vector> 51299SN/A 528777Sgblack@eecs.umich.edu#include "arch/kernel_stats.hh" 539659SAndreas.Sandberg@ARM.com#include "arch/utility.hh" 542170SN/A#include "arch/vtophys.hh" 555882Snate@binkert.org#include "base/debug.hh" 568734Sdam.sunwoo@arm.com#include "base/output.hh" 576658Snate@binkert.org#include "config/the_isa.hh" 581717SN/A#include "cpu/base.hh" 598229Snate@binkert.org#include "cpu/quiesce_event.hh" 602680Sktlim@umich.edu#include "cpu/thread_context.hh" 618232Snate@binkert.org#include "debug/Loader.hh" 629733Sandreas@sandberg.pp.se#include "debug/PseudoInst.hh" 638232Snate@binkert.org#include "debug/Quiesce.hh" 648232Snate@binkert.org#include "debug/WorkItems.hh" 655529Snate@binkert.org#include "params/BaseCPU.hh" 668784Sgblack@eecs.umich.edu#include "sim/full_system.hh" 673565Sgblack@eecs.umich.edu#include "sim/pseudo_inst.hh" 68298SN/A#include "sim/serialize.hh" 695606Snate@binkert.org#include "sim/sim_events.hh" 70298SN/A#include "sim/sim_exit.hh" 71695SN/A#include "sim/stat_control.hh" 72695SN/A#include "sim/stats.hh" 73954SN/A#include "sim/system.hh" 742080SN/A#include "sim/vptr.hh" 75298SN/A 76299SN/Ausing namespace std; 771052SN/A 78729SN/Ausing namespace Stats; 792107SN/Ausing namespace TheISA; 80298SN/A 815504Snate@binkert.orgnamespace PseudoInst { 825504Snate@binkert.org 838784Sgblack@eecs.umich.edustatic inline void 848784Sgblack@eecs.umich.edupanicFsOnlyPseudoInst(const char *name) 858784Sgblack@eecs.umich.edu{ 868784Sgblack@eecs.umich.edu panic("Pseudo inst \"%s\" is only available in Full System mode."); 878784Sgblack@eecs.umich.edu} 885780Ssteve.reinhardt@amd.com 899659SAndreas.Sandberg@ARM.comuint64_t 909659SAndreas.Sandberg@ARM.compseudoInst(ThreadContext *tc, uint8_t func, uint8_t subfunc) 919659SAndreas.Sandberg@ARM.com{ 929659SAndreas.Sandberg@ARM.com uint64_t args[4]; 939659SAndreas.Sandberg@ARM.com 949733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::pseudoInst(%i, %i)\n", func, subfunc); 959733Sandreas@sandberg.pp.se 969659SAndreas.Sandberg@ARM.com // We need to do this in a slightly convoluted way since 979659SAndreas.Sandberg@ARM.com // getArgument() might have side-effects on arg_num. We could have 989659SAndreas.Sandberg@ARM.com // used the Argument class, but due to the possible side effects 999659SAndreas.Sandberg@ARM.com // from getArgument, it'd most likely break. 1009659SAndreas.Sandberg@ARM.com int arg_num(0); 1019879Sandreas@sandberg.pp.se for (int i = 0; i < sizeof(args) / sizeof(*args); ++i) { 1029879Sandreas@sandberg.pp.se args[arg_num] = getArgument(tc, arg_num, sizeof(uint64_t), false); 1039879Sandreas@sandberg.pp.se ++arg_num; 1049879Sandreas@sandberg.pp.se } 1059659SAndreas.Sandberg@ARM.com 1069659SAndreas.Sandberg@ARM.com switch (func) { 1079659SAndreas.Sandberg@ARM.com case 0x00: // arm_func 1089659SAndreas.Sandberg@ARM.com arm(tc); 1099659SAndreas.Sandberg@ARM.com break; 1109659SAndreas.Sandberg@ARM.com 1119659SAndreas.Sandberg@ARM.com case 0x01: // quiesce_func 1129659SAndreas.Sandberg@ARM.com quiesce(tc); 1139659SAndreas.Sandberg@ARM.com break; 1149659SAndreas.Sandberg@ARM.com 1159659SAndreas.Sandberg@ARM.com case 0x02: // quiescens_func 1169659SAndreas.Sandberg@ARM.com quiesceSkip(tc); 1179659SAndreas.Sandberg@ARM.com break; 1189659SAndreas.Sandberg@ARM.com 1199659SAndreas.Sandberg@ARM.com case 0x03: // quiescecycle_func 1209659SAndreas.Sandberg@ARM.com quiesceNs(tc, args[0]); 1219659SAndreas.Sandberg@ARM.com break; 1229659SAndreas.Sandberg@ARM.com 1239659SAndreas.Sandberg@ARM.com case 0x04: // quiescetime_func 1249659SAndreas.Sandberg@ARM.com return quiesceTime(tc); 1259659SAndreas.Sandberg@ARM.com 1269659SAndreas.Sandberg@ARM.com case 0x07: // rpns_func 1279659SAndreas.Sandberg@ARM.com return rpns(tc); 1289659SAndreas.Sandberg@ARM.com 1299659SAndreas.Sandberg@ARM.com case 0x09: // wakecpu_func 1309659SAndreas.Sandberg@ARM.com wakeCPU(tc, args[0]); 1319659SAndreas.Sandberg@ARM.com break; 1329659SAndreas.Sandberg@ARM.com 1339659SAndreas.Sandberg@ARM.com case 0x21: // exit_func 1349659SAndreas.Sandberg@ARM.com m5exit(tc, args[0]); 1359659SAndreas.Sandberg@ARM.com break; 1369659SAndreas.Sandberg@ARM.com 1379681Sandreas@sandberg.pp.se case 0x22: 1389681Sandreas@sandberg.pp.se m5fail(tc, args[0], args[1]); 1399681Sandreas@sandberg.pp.se break; 1409681Sandreas@sandberg.pp.se 1419659SAndreas.Sandberg@ARM.com case 0x30: // initparam_func 1429659SAndreas.Sandberg@ARM.com return initParam(tc); 1439659SAndreas.Sandberg@ARM.com 1449659SAndreas.Sandberg@ARM.com case 0x31: // loadsymbol_func 1459659SAndreas.Sandberg@ARM.com loadsymbol(tc); 1469659SAndreas.Sandberg@ARM.com break; 1479659SAndreas.Sandberg@ARM.com 1489659SAndreas.Sandberg@ARM.com case 0x40: // resetstats_func 1499659SAndreas.Sandberg@ARM.com resetstats(tc, args[0], args[1]); 1509659SAndreas.Sandberg@ARM.com break; 1519659SAndreas.Sandberg@ARM.com 1529659SAndreas.Sandberg@ARM.com case 0x41: // dumpstats_func 1539659SAndreas.Sandberg@ARM.com dumpstats(tc, args[0], args[1]); 1549659SAndreas.Sandberg@ARM.com break; 1559659SAndreas.Sandberg@ARM.com 1569659SAndreas.Sandberg@ARM.com case 0x42: // dumprststats_func 1579659SAndreas.Sandberg@ARM.com dumpresetstats(tc, args[0], args[1]); 1589659SAndreas.Sandberg@ARM.com break; 1599659SAndreas.Sandberg@ARM.com 1609659SAndreas.Sandberg@ARM.com case 0x43: // ckpt_func 1619659SAndreas.Sandberg@ARM.com m5checkpoint(tc, args[0], args[1]); 1629659SAndreas.Sandberg@ARM.com break; 1639659SAndreas.Sandberg@ARM.com 1649659SAndreas.Sandberg@ARM.com case 0x4f: // writefile_func 1659659SAndreas.Sandberg@ARM.com return writefile(tc, args[0], args[1], args[2], args[3]); 1669659SAndreas.Sandberg@ARM.com 1679659SAndreas.Sandberg@ARM.com case 0x50: // readfile_func 1689659SAndreas.Sandberg@ARM.com return readfile(tc, args[0], args[1], args[2]); 1699659SAndreas.Sandberg@ARM.com 1709659SAndreas.Sandberg@ARM.com case 0x51: // debugbreak_func 1719659SAndreas.Sandberg@ARM.com debugbreak(tc); 1729659SAndreas.Sandberg@ARM.com break; 1739659SAndreas.Sandberg@ARM.com 1749659SAndreas.Sandberg@ARM.com case 0x52: // switchcpu_func 1759659SAndreas.Sandberg@ARM.com switchcpu(tc); 1769659SAndreas.Sandberg@ARM.com break; 1779659SAndreas.Sandberg@ARM.com 1789659SAndreas.Sandberg@ARM.com case 0x53: // addsymbol_func 1799659SAndreas.Sandberg@ARM.com addsymbol(tc, args[0], args[1]); 1809659SAndreas.Sandberg@ARM.com break; 1819659SAndreas.Sandberg@ARM.com 1829659SAndreas.Sandberg@ARM.com case 0x54: // panic_func 1839659SAndreas.Sandberg@ARM.com panic("M5 panic instruction called at %s\n", tc->pcState()); 1849659SAndreas.Sandberg@ARM.com 1859659SAndreas.Sandberg@ARM.com case 0x5a: // work_begin_func 1869659SAndreas.Sandberg@ARM.com workbegin(tc, args[0], args[1]); 1879659SAndreas.Sandberg@ARM.com break; 1889659SAndreas.Sandberg@ARM.com 1899659SAndreas.Sandberg@ARM.com case 0x5b: // work_end_func 1909659SAndreas.Sandberg@ARM.com workend(tc, args[0], args[1]); 1919659SAndreas.Sandberg@ARM.com break; 1929659SAndreas.Sandberg@ARM.com 1939659SAndreas.Sandberg@ARM.com case 0x55: // annotate_func 1949659SAndreas.Sandberg@ARM.com case 0x56: // reserved2_func 1959659SAndreas.Sandberg@ARM.com case 0x57: // reserved3_func 1969659SAndreas.Sandberg@ARM.com case 0x58: // reserved4_func 1979659SAndreas.Sandberg@ARM.com case 0x59: // reserved5_func 1989659SAndreas.Sandberg@ARM.com warn("Unimplemented m5 op (0x%x)\n", func); 1999659SAndreas.Sandberg@ARM.com break; 2009659SAndreas.Sandberg@ARM.com 2019659SAndreas.Sandberg@ARM.com default: 2029659SAndreas.Sandberg@ARM.com warn("Unhandled m5 op: 0x%x\n", func); 2039659SAndreas.Sandberg@ARM.com break; 2049659SAndreas.Sandberg@ARM.com } 2059659SAndreas.Sandberg@ARM.com 2069659SAndreas.Sandberg@ARM.com return 0; 2079659SAndreas.Sandberg@ARM.com} 2089659SAndreas.Sandberg@ARM.com 2095504Snate@binkert.orgvoid 2105504Snate@binkert.orgarm(ThreadContext *tc) 211298SN/A{ 2129733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::arm()\n"); 2138806Sgblack@eecs.umich.edu if (!FullSystem) 2148784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("arm"); 2158806Sgblack@eecs.umich.edu 2165504Snate@binkert.org if (tc->getKernelStats()) 2175504Snate@binkert.org tc->getKernelStats()->arm(); 2185504Snate@binkert.org} 2195504Snate@binkert.org 2205504Snate@binkert.orgvoid 2215504Snate@binkert.orgquiesce(ThreadContext *tc) 2225504Snate@binkert.org{ 2239733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesce()\n"); 2248806Sgblack@eecs.umich.edu if (!FullSystem) 2258806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesce"); 2268666SPrakash.Ramrakhyani@arm.com 2275529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_quiesce) 2285504Snate@binkert.org return; 2295504Snate@binkert.org 2305504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name()); 2315504Snate@binkert.org 2325504Snate@binkert.org tc->suspend(); 2335504Snate@binkert.org if (tc->getKernelStats()) 2345504Snate@binkert.org tc->getKernelStats()->quiesce(); 2355504Snate@binkert.org} 2365504Snate@binkert.org 2375504Snate@binkert.orgvoid 2388142SAli.Saidi@ARM.comquiesceSkip(ThreadContext *tc) 2398142SAli.Saidi@ARM.com{ 2409733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesceSkip()\n"); 2418806Sgblack@eecs.umich.edu if (!FullSystem) 2428806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceSkip"); 2438666SPrakash.Ramrakhyani@arm.com 2448142SAli.Saidi@ARM.com BaseCPU *cpu = tc->getCpuPtr(); 2458142SAli.Saidi@ARM.com 2468142SAli.Saidi@ARM.com if (!cpu->params()->do_quiesce) 2478142SAli.Saidi@ARM.com return; 2488142SAli.Saidi@ARM.com 2498142SAli.Saidi@ARM.com EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 2508142SAli.Saidi@ARM.com 2518142SAli.Saidi@ARM.com Tick resume = curTick() + 1; 2528142SAli.Saidi@ARM.com 2538142SAli.Saidi@ARM.com cpu->reschedule(quiesceEvent, resume, true); 2548142SAli.Saidi@ARM.com 2558142SAli.Saidi@ARM.com DPRINTF(Quiesce, "%s: quiesceSkip() until %d\n", 2568142SAli.Saidi@ARM.com cpu->name(), resume); 2578142SAli.Saidi@ARM.com 2588142SAli.Saidi@ARM.com tc->suspend(); 2598142SAli.Saidi@ARM.com if (tc->getKernelStats()) 2608142SAli.Saidi@ARM.com tc->getKernelStats()->quiesce(); 2618142SAli.Saidi@ARM.com} 2628142SAli.Saidi@ARM.com 2638142SAli.Saidi@ARM.comvoid 2645504Snate@binkert.orgquiesceNs(ThreadContext *tc, uint64_t ns) 2655504Snate@binkert.org{ 2669733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesceNs(%i)\n", ns); 2678806Sgblack@eecs.umich.edu if (!FullSystem) 2688806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceNs"); 2698666SPrakash.Ramrakhyani@arm.com 2707819Ssteve.reinhardt@amd.com BaseCPU *cpu = tc->getCpuPtr(); 2717819Ssteve.reinhardt@amd.com 2727819Ssteve.reinhardt@amd.com if (!cpu->params()->do_quiesce || ns == 0) 2735504Snate@binkert.org return; 2745504Snate@binkert.org 2755504Snate@binkert.org EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 2765504Snate@binkert.org 2777823Ssteve.reinhardt@amd.com Tick resume = curTick() + SimClock::Int::ns * ns; 2785504Snate@binkert.org 2797819Ssteve.reinhardt@amd.com cpu->reschedule(quiesceEvent, resume, true); 2805504Snate@binkert.org 2815504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesceNs(%d) until %d\n", 2827819Ssteve.reinhardt@amd.com cpu->name(), ns, resume); 2835504Snate@binkert.org 2845504Snate@binkert.org tc->suspend(); 2855504Snate@binkert.org if (tc->getKernelStats()) 2865504Snate@binkert.org tc->getKernelStats()->quiesce(); 2875504Snate@binkert.org} 2885504Snate@binkert.org 2895504Snate@binkert.orgvoid 2905504Snate@binkert.orgquiesceCycles(ThreadContext *tc, uint64_t cycles) 2915504Snate@binkert.org{ 2929733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesceCycles(%i)\n", cycles); 2938806Sgblack@eecs.umich.edu if (!FullSystem) 2948806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceCycles"); 2958666SPrakash.Ramrakhyani@arm.com 2967819Ssteve.reinhardt@amd.com BaseCPU *cpu = tc->getCpuPtr(); 2977819Ssteve.reinhardt@amd.com 2987819Ssteve.reinhardt@amd.com if (!cpu->params()->do_quiesce || cycles == 0) 2995504Snate@binkert.org return; 3005504Snate@binkert.org 3015504Snate@binkert.org EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 3025504Snate@binkert.org 3039180Sandreas.hansson@arm.com Tick resume = cpu->clockEdge(Cycles(cycles)); 3045504Snate@binkert.org 3057819Ssteve.reinhardt@amd.com cpu->reschedule(quiesceEvent, resume, true); 3065504Snate@binkert.org 3075504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n", 3087819Ssteve.reinhardt@amd.com cpu->name(), cycles, resume); 3095504Snate@binkert.org 3105504Snate@binkert.org tc->suspend(); 3115504Snate@binkert.org if (tc->getKernelStats()) 3125504Snate@binkert.org tc->getKernelStats()->quiesce(); 3135504Snate@binkert.org} 3145504Snate@binkert.org 3155504Snate@binkert.orguint64_t 3165504Snate@binkert.orgquiesceTime(ThreadContext *tc) 3175504Snate@binkert.org{ 3189733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesceTime()\n"); 3198806Sgblack@eecs.umich.edu if (!FullSystem) { 3208784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceTime"); 3218784Sgblack@eecs.umich.edu return 0; 3228784Sgblack@eecs.umich.edu } 3238806Sgblack@eecs.umich.edu 3247064Snate@binkert.org return (tc->readLastActivate() - tc->readLastSuspend()) / 3257064Snate@binkert.org SimClock::Int::ns; 3265504Snate@binkert.org} 3275504Snate@binkert.org 3285741Snate@binkert.orguint64_t 3295741Snate@binkert.orgrpns(ThreadContext *tc) 3305741Snate@binkert.org{ 3319733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::rpns()\n"); 3327823Ssteve.reinhardt@amd.com return curTick() / SimClock::Int::ns; 3335741Snate@binkert.org} 3345741Snate@binkert.org 3355504Snate@binkert.orgvoid 3365808Snate@binkert.orgwakeCPU(ThreadContext *tc, uint64_t cpuid) 3375808Snate@binkert.org{ 3389733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::wakeCPU(%i)\n", cpuid); 3395808Snate@binkert.org System *sys = tc->getSystemPtr(); 3405808Snate@binkert.org ThreadContext *other_tc = sys->threadContexts[cpuid]; 3415808Snate@binkert.org if (other_tc->status() == ThreadContext::Suspended) 3425808Snate@binkert.org other_tc->activate(); 3435808Snate@binkert.org} 3445808Snate@binkert.org 3455808Snate@binkert.orgvoid 3465504Snate@binkert.orgm5exit(ThreadContext *tc, Tick delay) 3475504Snate@binkert.org{ 3489733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::m5exit(%i)\n", delay); 3497823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 3509952Sdam.sunwoo@arm.com exitSimLoop("m5_exit instruction encountered", 0, when, 0, true); 3515504Snate@binkert.org} 3525504Snate@binkert.org 3535504Snate@binkert.orgvoid 3549457Svilanova@ac.upc.edum5fail(ThreadContext *tc, Tick delay, uint64_t code) 3559457Svilanova@ac.upc.edu{ 3569733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::m5fail(%i, %i)\n", delay, code); 3579457Svilanova@ac.upc.edu Tick when = curTick() + delay * SimClock::Int::ns; 3589952Sdam.sunwoo@arm.com exitSimLoop("m5_fail instruction encountered", code, when, 0, true); 3599457Svilanova@ac.upc.edu} 3609457Svilanova@ac.upc.edu 3619457Svilanova@ac.upc.eduvoid 3625504Snate@binkert.orgloadsymbol(ThreadContext *tc) 3635504Snate@binkert.org{ 3649733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::loadsymbol()\n"); 3658806Sgblack@eecs.umich.edu if (!FullSystem) 3668806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("loadsymbol"); 3678784Sgblack@eecs.umich.edu 3685504Snate@binkert.org const string &filename = tc->getCpuPtr()->system->params()->symbolfile; 3695504Snate@binkert.org if (filename.empty()) { 3705504Snate@binkert.org return; 371711SN/A } 372711SN/A 3735504Snate@binkert.org std::string buffer; 3745504Snate@binkert.org ifstream file(filename.c_str()); 375310SN/A 3765504Snate@binkert.org if (!file) 3775504Snate@binkert.org fatal("file error: Can't open symbol table file %s\n", filename); 3783373Sstever@eecs.umich.edu 3795504Snate@binkert.org while (!file.eof()) { 3805504Snate@binkert.org getline(file, buffer); 3815504Snate@binkert.org 3825504Snate@binkert.org if (buffer.empty()) 3835504Snate@binkert.org continue; 3845504Snate@binkert.org 3856227Snate@binkert.org string::size_type idx = buffer.find(' '); 3865504Snate@binkert.org if (idx == string::npos) 3875504Snate@binkert.org continue; 3885504Snate@binkert.org 3895504Snate@binkert.org string address = "0x" + buffer.substr(0, idx); 3905504Snate@binkert.org eat_white(address); 3915504Snate@binkert.org if (address.empty()) 3925504Snate@binkert.org continue; 3935504Snate@binkert.org 3945504Snate@binkert.org // Skip over letter and space 3955504Snate@binkert.org string symbol = buffer.substr(idx + 3); 3965504Snate@binkert.org eat_white(symbol); 3975504Snate@binkert.org if (symbol.empty()) 3985504Snate@binkert.org continue; 3995504Snate@binkert.org 4005504Snate@binkert.org Addr addr; 4015504Snate@binkert.org if (!to_number(address, addr)) 4025504Snate@binkert.org continue; 4035504Snate@binkert.org 4045504Snate@binkert.org if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol)) 4055504Snate@binkert.org continue; 4065504Snate@binkert.org 4075504Snate@binkert.org 4085504Snate@binkert.org DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 4095504Snate@binkert.org } 4105504Snate@binkert.org file.close(); 4115504Snate@binkert.org} 4125504Snate@binkert.org 4135504Snate@binkert.orgvoid 4145780Ssteve.reinhardt@amd.comaddsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 4155780Ssteve.reinhardt@amd.com{ 4169733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::addsymbol(0x%x, 0x%x)\n", 4179733Sandreas@sandberg.pp.se addr, symbolAddr); 4188806Sgblack@eecs.umich.edu if (!FullSystem) 4198806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("addSymbol"); 4208666SPrakash.Ramrakhyani@arm.com 4215780Ssteve.reinhardt@amd.com char symb[100]; 4225780Ssteve.reinhardt@amd.com CopyStringOut(tc, symb, symbolAddr, 100); 4235780Ssteve.reinhardt@amd.com std::string symbol(symb); 4245780Ssteve.reinhardt@amd.com 4255780Ssteve.reinhardt@amd.com DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 4265780Ssteve.reinhardt@amd.com 4275780Ssteve.reinhardt@amd.com tc->getSystemPtr()->kernelSymtab->insert(addr,symbol); 4285952Ssaidi@eecs.umich.edu debugSymbolTable->insert(addr,symbol); 4295780Ssteve.reinhardt@amd.com} 4305780Ssteve.reinhardt@amd.com 4318555Sgblack@eecs.umich.eduuint64_t 4328555Sgblack@eecs.umich.eduinitParam(ThreadContext *tc) 4338555Sgblack@eecs.umich.edu{ 4349733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::initParam()\n"); 4358806Sgblack@eecs.umich.edu if (!FullSystem) { 4368784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("initParam"); 4378784Sgblack@eecs.umich.edu return 0; 4388784Sgblack@eecs.umich.edu } 4398806Sgblack@eecs.umich.edu 4408555Sgblack@eecs.umich.edu return tc->getCpuPtr()->system->init_param; 4418555Sgblack@eecs.umich.edu} 4428555Sgblack@eecs.umich.edu 4435780Ssteve.reinhardt@amd.com 4445780Ssteve.reinhardt@amd.comvoid 4455504Snate@binkert.orgresetstats(ThreadContext *tc, Tick delay, Tick period) 4465504Snate@binkert.org{ 4479733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::resetstats(%i, %i)\n", delay, period); 4485529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4495504Snate@binkert.org return; 4505504Snate@binkert.org 4515504Snate@binkert.org 4527823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4537064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4545504Snate@binkert.org 4557822Ssteve.reinhardt@amd.com Stats::schedStatEvent(false, true, when, repeat); 4565504Snate@binkert.org} 4575504Snate@binkert.org 4585504Snate@binkert.orgvoid 4595504Snate@binkert.orgdumpstats(ThreadContext *tc, Tick delay, Tick period) 4605504Snate@binkert.org{ 4619733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::dumpstats(%i, %i)\n", delay, period); 4625529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4635504Snate@binkert.org return; 4645504Snate@binkert.org 4655504Snate@binkert.org 4667823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4677064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4685504Snate@binkert.org 4697822Ssteve.reinhardt@amd.com Stats::schedStatEvent(true, false, when, repeat); 4705504Snate@binkert.org} 4715504Snate@binkert.org 4725504Snate@binkert.orgvoid 4735504Snate@binkert.orgdumpresetstats(ThreadContext *tc, Tick delay, Tick period) 4745504Snate@binkert.org{ 4759733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::dumpresetstats(%i, %i)\n", delay, period); 4765529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4775504Snate@binkert.org return; 4785504Snate@binkert.org 4795504Snate@binkert.org 4807823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4817064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4825504Snate@binkert.org 4837822Ssteve.reinhardt@amd.com Stats::schedStatEvent(true, true, when, repeat); 4845504Snate@binkert.org} 4855504Snate@binkert.org 4865504Snate@binkert.orgvoid 4875504Snate@binkert.orgm5checkpoint(ThreadContext *tc, Tick delay, Tick period) 4885504Snate@binkert.org{ 4899733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::m5checkpoint(%i, %i)\n", delay, period); 4905529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_checkpoint_insts) 4915504Snate@binkert.org return; 4925504Snate@binkert.org 4937823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4947064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4955504Snate@binkert.org 4967819Ssteve.reinhardt@amd.com exitSimLoop("checkpoint", 0, when, repeat); 4975504Snate@binkert.org} 4985504Snate@binkert.org 4995504Snate@binkert.orguint64_t 5005504Snate@binkert.orgreadfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) 5015504Snate@binkert.org{ 5029733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::readfile(0x%x, 0x%x, 0x%x)\n", 5039733Sandreas@sandberg.pp.se vaddr, len, offset); 5048806Sgblack@eecs.umich.edu if (!FullSystem) { 5058784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("readfile"); 5068784Sgblack@eecs.umich.edu return 0; 5078666SPrakash.Ramrakhyani@arm.com } 5088806Sgblack@eecs.umich.edu 5095504Snate@binkert.org const string &file = tc->getSystemPtr()->params()->readfile; 5105504Snate@binkert.org if (file.empty()) { 5115504Snate@binkert.org return ULL(0); 512310SN/A } 513299SN/A 5145504Snate@binkert.org uint64_t result = 0; 5152188SN/A 5165504Snate@binkert.org int fd = ::open(file.c_str(), O_RDONLY, 0); 5175504Snate@binkert.org if (fd < 0) 5185504Snate@binkert.org panic("could not open file %s\n", file); 5192235SN/A 5205504Snate@binkert.org if (::lseek(fd, offset, SEEK_SET) < 0) 5215504Snate@binkert.org panic("could not seek: %s", strerror(errno)); 5223368Sstever@eecs.umich.edu 5235504Snate@binkert.org char *buf = new char[len]; 5245504Snate@binkert.org char *p = buf; 5255504Snate@binkert.org while (len > 0) { 5265504Snate@binkert.org int bytes = ::read(fd, p, len); 5275504Snate@binkert.org if (bytes <= 0) 5285504Snate@binkert.org break; 5293368Sstever@eecs.umich.edu 5305504Snate@binkert.org p += bytes; 5315504Snate@binkert.org result += bytes; 5325504Snate@binkert.org len -= bytes; 5332188SN/A } 5342188SN/A 5355504Snate@binkert.org close(fd); 5365504Snate@binkert.org CopyIn(tc, vaddr, buf, result); 5375504Snate@binkert.org delete [] buf; 5385504Snate@binkert.org return result; 5395504Snate@binkert.org} 5402188SN/A 5418734Sdam.sunwoo@arm.comuint64_t 5428734Sdam.sunwoo@arm.comwritefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, 5438734Sdam.sunwoo@arm.com Addr filename_addr) 5448734Sdam.sunwoo@arm.com{ 5459733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::writefile(0x%x, 0x%x, 0x%x, 0x%x)\n", 5469733Sandreas@sandberg.pp.se vaddr, len, offset, filename_addr); 5478734Sdam.sunwoo@arm.com ostream *os; 5488734Sdam.sunwoo@arm.com 5498734Sdam.sunwoo@arm.com // copy out target filename 5508734Sdam.sunwoo@arm.com char fn[100]; 5518734Sdam.sunwoo@arm.com std::string filename; 5528734Sdam.sunwoo@arm.com CopyStringOut(tc, fn, filename_addr, 100); 5538734Sdam.sunwoo@arm.com filename = std::string(fn); 5548734Sdam.sunwoo@arm.com 5558734Sdam.sunwoo@arm.com if (offset == 0) { 5568734Sdam.sunwoo@arm.com // create a new file (truncate) 5578734Sdam.sunwoo@arm.com os = simout.create(filename, true); 5588734Sdam.sunwoo@arm.com } else { 5598734Sdam.sunwoo@arm.com // do not truncate file if offset is non-zero 5608734Sdam.sunwoo@arm.com // (ios::in flag is required as well to keep the existing data 5618734Sdam.sunwoo@arm.com // intact, otherwise existing data will be zeroed out.) 5628734Sdam.sunwoo@arm.com os = simout.openFile(simout.directory() + filename, 5638734Sdam.sunwoo@arm.com ios::in | ios::out | ios::binary); 5648734Sdam.sunwoo@arm.com } 5658734Sdam.sunwoo@arm.com if (!os) 5668734Sdam.sunwoo@arm.com panic("could not open file %s\n", filename); 5678734Sdam.sunwoo@arm.com 5688734Sdam.sunwoo@arm.com // seek to offset 5698734Sdam.sunwoo@arm.com os->seekp(offset); 5708734Sdam.sunwoo@arm.com 5718734Sdam.sunwoo@arm.com // copy out data and write to file 5728734Sdam.sunwoo@arm.com char *buf = new char[len]; 5738734Sdam.sunwoo@arm.com CopyOut(tc, buf, vaddr, len); 5748734Sdam.sunwoo@arm.com os->write(buf, len); 5758734Sdam.sunwoo@arm.com if (os->fail() || os->bad()) 5768734Sdam.sunwoo@arm.com panic("Error while doing writefile!\n"); 5778734Sdam.sunwoo@arm.com 5788734Sdam.sunwoo@arm.com simout.close(os); 5798734Sdam.sunwoo@arm.com 5808734Sdam.sunwoo@arm.com delete [] buf; 5818734Sdam.sunwoo@arm.com 5828734Sdam.sunwoo@arm.com return len; 5838734Sdam.sunwoo@arm.com} 5848734Sdam.sunwoo@arm.com 5855504Snate@binkert.orgvoid 5865504Snate@binkert.orgdebugbreak(ThreadContext *tc) 5875504Snate@binkert.org{ 5889733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::debugbreak()\n"); 5898231Snate@binkert.org Debug::breakpoint(); 5905504Snate@binkert.org} 5912235SN/A 5925504Snate@binkert.orgvoid 5935504Snate@binkert.orgswitchcpu(ThreadContext *tc) 5945504Snate@binkert.org{ 5959733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::switchcpu()\n"); 5965504Snate@binkert.org exitSimLoop("switchcpu"); 5975504Snate@binkert.org} 5983368Sstever@eecs.umich.edu 5997914SBrad.Beckmann@amd.com// 6007914SBrad.Beckmann@amd.com// This function is executed when annotated work items begin. Depending on 6017914SBrad.Beckmann@amd.com// what the user specified at the command line, the simulation may exit and/or 6027914SBrad.Beckmann@amd.com// take a checkpoint when a certain work item begins. 6037914SBrad.Beckmann@amd.com// 6047914SBrad.Beckmann@amd.comvoid 6057914SBrad.Beckmann@amd.comworkbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid) 6067914SBrad.Beckmann@amd.com{ 6079733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::workbegin(%i, %i)\n", workid, threadid); 6087914SBrad.Beckmann@amd.com tc->getCpuPtr()->workItemBegin(); 6097914SBrad.Beckmann@amd.com System *sys = tc->getSystemPtr(); 6108580Ssteve.reinhardt@amd.com const System::Params *params = sys->params(); 6118666SPrakash.Ramrakhyani@arm.com sys->workItemBegin(threadid, workid); 6127914SBrad.Beckmann@amd.com 6137914SBrad.Beckmann@amd.com DPRINTF(WorkItems, "Work Begin workid: %d, threadid %d\n", workid, 6147914SBrad.Beckmann@amd.com threadid); 6157914SBrad.Beckmann@amd.com 6167914SBrad.Beckmann@amd.com // 6177914SBrad.Beckmann@amd.com // If specified, determine if this is the specific work item the user 6187914SBrad.Beckmann@amd.com // identified 6197914SBrad.Beckmann@amd.com // 6208580Ssteve.reinhardt@amd.com if (params->work_item_id == -1 || params->work_item_id == workid) { 6217914SBrad.Beckmann@amd.com 6227914SBrad.Beckmann@amd.com uint64_t systemWorkBeginCount = sys->incWorkItemsBegin(); 6237914SBrad.Beckmann@amd.com int cpuId = tc->getCpuPtr()->cpuId(); 6247914SBrad.Beckmann@amd.com 6258580Ssteve.reinhardt@amd.com if (params->work_cpus_ckpt_count != 0 && 6268580Ssteve.reinhardt@amd.com sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 6277914SBrad.Beckmann@amd.com // 6287914SBrad.Beckmann@amd.com // If active cpus equals checkpoint count, create checkpoint 6297914SBrad.Beckmann@amd.com // 6308580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6317914SBrad.Beckmann@amd.com } 6327914SBrad.Beckmann@amd.com 6338580Ssteve.reinhardt@amd.com if (systemWorkBeginCount == params->work_begin_ckpt_count) { 6347914SBrad.Beckmann@amd.com // 6357914SBrad.Beckmann@amd.com // Note: the string specified as the cause of the exit event must 6367914SBrad.Beckmann@amd.com // exactly equal "checkpoint" inorder to create a checkpoint 6377914SBrad.Beckmann@amd.com // 6388580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6397914SBrad.Beckmann@amd.com } 6407914SBrad.Beckmann@amd.com 6418580Ssteve.reinhardt@amd.com if (systemWorkBeginCount == params->work_begin_exit_count) { 6427914SBrad.Beckmann@amd.com // 6437914SBrad.Beckmann@amd.com // If a certain number of work items started, exit simulation 6447914SBrad.Beckmann@amd.com // 6458580Ssteve.reinhardt@amd.com exitSimLoop("work started count reach"); 6467914SBrad.Beckmann@amd.com } 6477914SBrad.Beckmann@amd.com 6488580Ssteve.reinhardt@amd.com if (cpuId == params->work_begin_cpu_id_exit) { 6497914SBrad.Beckmann@amd.com // 6508580Ssteve.reinhardt@amd.com // If work started on the cpu id specified, exit simulation 6517914SBrad.Beckmann@amd.com // 6528580Ssteve.reinhardt@amd.com exitSimLoop("work started on specific cpu"); 6537914SBrad.Beckmann@amd.com } 6547914SBrad.Beckmann@amd.com } 6557914SBrad.Beckmann@amd.com} 6567914SBrad.Beckmann@amd.com 6577914SBrad.Beckmann@amd.com// 6587914SBrad.Beckmann@amd.com// This function is executed when annotated work items end. Depending on 6597914SBrad.Beckmann@amd.com// what the user specified at the command line, the simulation may exit and/or 6607914SBrad.Beckmann@amd.com// take a checkpoint when a certain work item ends. 6617914SBrad.Beckmann@amd.com// 6627914SBrad.Beckmann@amd.comvoid 6637914SBrad.Beckmann@amd.comworkend(ThreadContext *tc, uint64_t workid, uint64_t threadid) 6647914SBrad.Beckmann@amd.com{ 6659733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::workend(%i, %i)\n", workid, threadid); 6667914SBrad.Beckmann@amd.com tc->getCpuPtr()->workItemEnd(); 6677914SBrad.Beckmann@amd.com System *sys = tc->getSystemPtr(); 6688580Ssteve.reinhardt@amd.com const System::Params *params = sys->params(); 6698666SPrakash.Ramrakhyani@arm.com sys->workItemEnd(threadid, workid); 6707914SBrad.Beckmann@amd.com 6717914SBrad.Beckmann@amd.com DPRINTF(WorkItems, "Work End workid: %d, threadid %d\n", workid, threadid); 6727914SBrad.Beckmann@amd.com 6737914SBrad.Beckmann@amd.com // 6747914SBrad.Beckmann@amd.com // If specified, determine if this is the specific work item the user 6757914SBrad.Beckmann@amd.com // identified 6767914SBrad.Beckmann@amd.com // 6778580Ssteve.reinhardt@amd.com if (params->work_item_id == -1 || params->work_item_id == workid) { 6787914SBrad.Beckmann@amd.com 6797914SBrad.Beckmann@amd.com uint64_t systemWorkEndCount = sys->incWorkItemsEnd(); 6807914SBrad.Beckmann@amd.com int cpuId = tc->getCpuPtr()->cpuId(); 6817914SBrad.Beckmann@amd.com 6828580Ssteve.reinhardt@amd.com if (params->work_cpus_ckpt_count != 0 && 6838580Ssteve.reinhardt@amd.com sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 6847914SBrad.Beckmann@amd.com // 6857914SBrad.Beckmann@amd.com // If active cpus equals checkpoint count, create checkpoint 6867914SBrad.Beckmann@amd.com // 6878580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6887914SBrad.Beckmann@amd.com } 6897914SBrad.Beckmann@amd.com 6908580Ssteve.reinhardt@amd.com if (params->work_end_ckpt_count != 0 && 6918580Ssteve.reinhardt@amd.com systemWorkEndCount == params->work_end_ckpt_count) { 6927914SBrad.Beckmann@amd.com // 6937914SBrad.Beckmann@amd.com // If total work items completed equals checkpoint count, create 6947914SBrad.Beckmann@amd.com // checkpoint 6957914SBrad.Beckmann@amd.com // 6968580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6977914SBrad.Beckmann@amd.com } 6987914SBrad.Beckmann@amd.com 6998580Ssteve.reinhardt@amd.com if (params->work_end_exit_count != 0 && 7008580Ssteve.reinhardt@amd.com systemWorkEndCount == params->work_end_exit_count) { 7017914SBrad.Beckmann@amd.com // 7027914SBrad.Beckmann@amd.com // If total work items completed equals exit count, exit simulation 7037914SBrad.Beckmann@amd.com // 7048580Ssteve.reinhardt@amd.com exitSimLoop("work items exit count reached"); 7057914SBrad.Beckmann@amd.com } 7067914SBrad.Beckmann@amd.com } 7077914SBrad.Beckmann@amd.com} 7087914SBrad.Beckmann@amd.com 7097811Ssteve.reinhardt@amd.com} // namespace PseudoInst 710