pseudo_inst.cc revision 9659
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" 628232Snate@binkert.org#include "debug/Quiesce.hh" 638232Snate@binkert.org#include "debug/WorkItems.hh" 645529Snate@binkert.org#include "params/BaseCPU.hh" 658784Sgblack@eecs.umich.edu#include "sim/full_system.hh" 663565Sgblack@eecs.umich.edu#include "sim/pseudo_inst.hh" 67298SN/A#include "sim/serialize.hh" 685606Snate@binkert.org#include "sim/sim_events.hh" 69298SN/A#include "sim/sim_exit.hh" 70695SN/A#include "sim/stat_control.hh" 71695SN/A#include "sim/stats.hh" 72954SN/A#include "sim/system.hh" 732080SN/A#include "sim/vptr.hh" 74298SN/A 75299SN/Ausing namespace std; 761052SN/A 77729SN/Ausing namespace Stats; 782107SN/Ausing namespace TheISA; 79298SN/A 805504Snate@binkert.orgnamespace PseudoInst { 815504Snate@binkert.org 828784Sgblack@eecs.umich.edustatic inline void 838784Sgblack@eecs.umich.edupanicFsOnlyPseudoInst(const char *name) 848784Sgblack@eecs.umich.edu{ 858784Sgblack@eecs.umich.edu panic("Pseudo inst \"%s\" is only available in Full System mode."); 868784Sgblack@eecs.umich.edu} 875780Ssteve.reinhardt@amd.com 889659SAndreas.Sandberg@ARM.comuint64_t 899659SAndreas.Sandberg@ARM.compseudoInst(ThreadContext *tc, uint8_t func, uint8_t subfunc) 909659SAndreas.Sandberg@ARM.com{ 919659SAndreas.Sandberg@ARM.com uint64_t args[4]; 929659SAndreas.Sandberg@ARM.com 939659SAndreas.Sandberg@ARM.com // We need to do this in a slightly convoluted way since 949659SAndreas.Sandberg@ARM.com // getArgument() might have side-effects on arg_num. We could have 959659SAndreas.Sandberg@ARM.com // used the Argument class, but due to the possible side effects 969659SAndreas.Sandberg@ARM.com // from getArgument, it'd most likely break. 979659SAndreas.Sandberg@ARM.com int arg_num(0); 989659SAndreas.Sandberg@ARM.com for (int i = 0; i < sizeof(args) / sizeof(*args); ++i) 999659SAndreas.Sandberg@ARM.com args[arg_num++] = getArgument(tc, arg_num, sizeof(uint64_t), false); 1009659SAndreas.Sandberg@ARM.com 1019659SAndreas.Sandberg@ARM.com switch (func) { 1029659SAndreas.Sandberg@ARM.com case 0x00: // arm_func 1039659SAndreas.Sandberg@ARM.com arm(tc); 1049659SAndreas.Sandberg@ARM.com break; 1059659SAndreas.Sandberg@ARM.com 1069659SAndreas.Sandberg@ARM.com case 0x01: // quiesce_func 1079659SAndreas.Sandberg@ARM.com quiesce(tc); 1089659SAndreas.Sandberg@ARM.com break; 1099659SAndreas.Sandberg@ARM.com 1109659SAndreas.Sandberg@ARM.com case 0x02: // quiescens_func 1119659SAndreas.Sandberg@ARM.com quiesceSkip(tc); 1129659SAndreas.Sandberg@ARM.com break; 1139659SAndreas.Sandberg@ARM.com 1149659SAndreas.Sandberg@ARM.com case 0x03: // quiescecycle_func 1159659SAndreas.Sandberg@ARM.com quiesceNs(tc, args[0]); 1169659SAndreas.Sandberg@ARM.com break; 1179659SAndreas.Sandberg@ARM.com 1189659SAndreas.Sandberg@ARM.com case 0x04: // quiescetime_func 1199659SAndreas.Sandberg@ARM.com return quiesceTime(tc); 1209659SAndreas.Sandberg@ARM.com 1219659SAndreas.Sandberg@ARM.com case 0x07: // rpns_func 1229659SAndreas.Sandberg@ARM.com return rpns(tc); 1239659SAndreas.Sandberg@ARM.com 1249659SAndreas.Sandberg@ARM.com case 0x09: // wakecpu_func 1259659SAndreas.Sandberg@ARM.com wakeCPU(tc, args[0]); 1269659SAndreas.Sandberg@ARM.com break; 1279659SAndreas.Sandberg@ARM.com 1289659SAndreas.Sandberg@ARM.com case 0x21: // exit_func 1299659SAndreas.Sandberg@ARM.com m5exit(tc, args[0]); 1309659SAndreas.Sandberg@ARM.com break; 1319659SAndreas.Sandberg@ARM.com 1329659SAndreas.Sandberg@ARM.com case 0x30: // initparam_func 1339659SAndreas.Sandberg@ARM.com return initParam(tc); 1349659SAndreas.Sandberg@ARM.com 1359659SAndreas.Sandberg@ARM.com case 0x31: // loadsymbol_func 1369659SAndreas.Sandberg@ARM.com loadsymbol(tc); 1379659SAndreas.Sandberg@ARM.com break; 1389659SAndreas.Sandberg@ARM.com 1399659SAndreas.Sandberg@ARM.com case 0x40: // resetstats_func 1409659SAndreas.Sandberg@ARM.com resetstats(tc, args[0], args[1]); 1419659SAndreas.Sandberg@ARM.com break; 1429659SAndreas.Sandberg@ARM.com 1439659SAndreas.Sandberg@ARM.com case 0x41: // dumpstats_func 1449659SAndreas.Sandberg@ARM.com dumpstats(tc, args[0], args[1]); 1459659SAndreas.Sandberg@ARM.com break; 1469659SAndreas.Sandberg@ARM.com 1479659SAndreas.Sandberg@ARM.com case 0x42: // dumprststats_func 1489659SAndreas.Sandberg@ARM.com dumpresetstats(tc, args[0], args[1]); 1499659SAndreas.Sandberg@ARM.com break; 1509659SAndreas.Sandberg@ARM.com 1519659SAndreas.Sandberg@ARM.com case 0x43: // ckpt_func 1529659SAndreas.Sandberg@ARM.com m5checkpoint(tc, args[0], args[1]); 1539659SAndreas.Sandberg@ARM.com break; 1549659SAndreas.Sandberg@ARM.com 1559659SAndreas.Sandberg@ARM.com case 0x4f: // writefile_func 1569659SAndreas.Sandberg@ARM.com return writefile(tc, args[0], args[1], args[2], args[3]); 1579659SAndreas.Sandberg@ARM.com 1589659SAndreas.Sandberg@ARM.com case 0x50: // readfile_func 1599659SAndreas.Sandberg@ARM.com return readfile(tc, args[0], args[1], args[2]); 1609659SAndreas.Sandberg@ARM.com 1619659SAndreas.Sandberg@ARM.com case 0x51: // debugbreak_func 1629659SAndreas.Sandberg@ARM.com debugbreak(tc); 1639659SAndreas.Sandberg@ARM.com break; 1649659SAndreas.Sandberg@ARM.com 1659659SAndreas.Sandberg@ARM.com case 0x52: // switchcpu_func 1669659SAndreas.Sandberg@ARM.com switchcpu(tc); 1679659SAndreas.Sandberg@ARM.com break; 1689659SAndreas.Sandberg@ARM.com 1699659SAndreas.Sandberg@ARM.com case 0x53: // addsymbol_func 1709659SAndreas.Sandberg@ARM.com addsymbol(tc, args[0], args[1]); 1719659SAndreas.Sandberg@ARM.com break; 1729659SAndreas.Sandberg@ARM.com 1739659SAndreas.Sandberg@ARM.com case 0x54: // panic_func 1749659SAndreas.Sandberg@ARM.com panic("M5 panic instruction called at %s\n", tc->pcState()); 1759659SAndreas.Sandberg@ARM.com 1769659SAndreas.Sandberg@ARM.com case 0x5a: // work_begin_func 1779659SAndreas.Sandberg@ARM.com workbegin(tc, args[0], args[1]); 1789659SAndreas.Sandberg@ARM.com break; 1799659SAndreas.Sandberg@ARM.com 1809659SAndreas.Sandberg@ARM.com case 0x5b: // work_end_func 1819659SAndreas.Sandberg@ARM.com workend(tc, args[0], args[1]); 1829659SAndreas.Sandberg@ARM.com break; 1839659SAndreas.Sandberg@ARM.com 1849659SAndreas.Sandberg@ARM.com case 0x55: // annotate_func 1859659SAndreas.Sandberg@ARM.com case 0x56: // reserved2_func 1869659SAndreas.Sandberg@ARM.com case 0x57: // reserved3_func 1879659SAndreas.Sandberg@ARM.com case 0x58: // reserved4_func 1889659SAndreas.Sandberg@ARM.com case 0x59: // reserved5_func 1899659SAndreas.Sandberg@ARM.com warn("Unimplemented m5 op (0x%x)\n", func); 1909659SAndreas.Sandberg@ARM.com break; 1919659SAndreas.Sandberg@ARM.com 1929659SAndreas.Sandberg@ARM.com default: 1939659SAndreas.Sandberg@ARM.com warn("Unhandled m5 op: 0x%x\n", func); 1949659SAndreas.Sandberg@ARM.com break; 1959659SAndreas.Sandberg@ARM.com } 1969659SAndreas.Sandberg@ARM.com 1979659SAndreas.Sandberg@ARM.com return 0; 1989659SAndreas.Sandberg@ARM.com} 1999659SAndreas.Sandberg@ARM.com 2005504Snate@binkert.orgvoid 2015504Snate@binkert.orgarm(ThreadContext *tc) 202298SN/A{ 2038806Sgblack@eecs.umich.edu if (!FullSystem) 2048784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("arm"); 2058806Sgblack@eecs.umich.edu 2065504Snate@binkert.org if (tc->getKernelStats()) 2075504Snate@binkert.org tc->getKernelStats()->arm(); 2085504Snate@binkert.org} 2095504Snate@binkert.org 2105504Snate@binkert.orgvoid 2115504Snate@binkert.orgquiesce(ThreadContext *tc) 2125504Snate@binkert.org{ 2138806Sgblack@eecs.umich.edu if (!FullSystem) 2148806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesce"); 2158666SPrakash.Ramrakhyani@arm.com 2165529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_quiesce) 2175504Snate@binkert.org return; 2185504Snate@binkert.org 2195504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name()); 2205504Snate@binkert.org 2215504Snate@binkert.org tc->suspend(); 2225504Snate@binkert.org if (tc->getKernelStats()) 2235504Snate@binkert.org tc->getKernelStats()->quiesce(); 2245504Snate@binkert.org} 2255504Snate@binkert.org 2265504Snate@binkert.orgvoid 2278142SAli.Saidi@ARM.comquiesceSkip(ThreadContext *tc) 2288142SAli.Saidi@ARM.com{ 2298806Sgblack@eecs.umich.edu if (!FullSystem) 2308806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceSkip"); 2318666SPrakash.Ramrakhyani@arm.com 2328142SAli.Saidi@ARM.com BaseCPU *cpu = tc->getCpuPtr(); 2338142SAli.Saidi@ARM.com 2348142SAli.Saidi@ARM.com if (!cpu->params()->do_quiesce) 2358142SAli.Saidi@ARM.com return; 2368142SAli.Saidi@ARM.com 2378142SAli.Saidi@ARM.com EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 2388142SAli.Saidi@ARM.com 2398142SAli.Saidi@ARM.com Tick resume = curTick() + 1; 2408142SAli.Saidi@ARM.com 2418142SAli.Saidi@ARM.com cpu->reschedule(quiesceEvent, resume, true); 2428142SAli.Saidi@ARM.com 2438142SAli.Saidi@ARM.com DPRINTF(Quiesce, "%s: quiesceSkip() until %d\n", 2448142SAli.Saidi@ARM.com cpu->name(), resume); 2458142SAli.Saidi@ARM.com 2468142SAli.Saidi@ARM.com tc->suspend(); 2478142SAli.Saidi@ARM.com if (tc->getKernelStats()) 2488142SAli.Saidi@ARM.com tc->getKernelStats()->quiesce(); 2498142SAli.Saidi@ARM.com} 2508142SAli.Saidi@ARM.com 2518142SAli.Saidi@ARM.comvoid 2525504Snate@binkert.orgquiesceNs(ThreadContext *tc, uint64_t ns) 2535504Snate@binkert.org{ 2548806Sgblack@eecs.umich.edu if (!FullSystem) 2558806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceNs"); 2568666SPrakash.Ramrakhyani@arm.com 2577819Ssteve.reinhardt@amd.com BaseCPU *cpu = tc->getCpuPtr(); 2587819Ssteve.reinhardt@amd.com 2597819Ssteve.reinhardt@amd.com if (!cpu->params()->do_quiesce || ns == 0) 2605504Snate@binkert.org return; 2615504Snate@binkert.org 2625504Snate@binkert.org EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 2635504Snate@binkert.org 2647823Ssteve.reinhardt@amd.com Tick resume = curTick() + SimClock::Int::ns * ns; 2655504Snate@binkert.org 2667819Ssteve.reinhardt@amd.com cpu->reschedule(quiesceEvent, resume, true); 2675504Snate@binkert.org 2685504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesceNs(%d) until %d\n", 2697819Ssteve.reinhardt@amd.com cpu->name(), ns, resume); 2705504Snate@binkert.org 2715504Snate@binkert.org tc->suspend(); 2725504Snate@binkert.org if (tc->getKernelStats()) 2735504Snate@binkert.org tc->getKernelStats()->quiesce(); 2745504Snate@binkert.org} 2755504Snate@binkert.org 2765504Snate@binkert.orgvoid 2775504Snate@binkert.orgquiesceCycles(ThreadContext *tc, uint64_t cycles) 2785504Snate@binkert.org{ 2798806Sgblack@eecs.umich.edu if (!FullSystem) 2808806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceCycles"); 2818666SPrakash.Ramrakhyani@arm.com 2827819Ssteve.reinhardt@amd.com BaseCPU *cpu = tc->getCpuPtr(); 2837819Ssteve.reinhardt@amd.com 2847819Ssteve.reinhardt@amd.com if (!cpu->params()->do_quiesce || cycles == 0) 2855504Snate@binkert.org return; 2865504Snate@binkert.org 2875504Snate@binkert.org EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 2885504Snate@binkert.org 2899180Sandreas.hansson@arm.com Tick resume = cpu->clockEdge(Cycles(cycles)); 2905504Snate@binkert.org 2917819Ssteve.reinhardt@amd.com cpu->reschedule(quiesceEvent, resume, true); 2925504Snate@binkert.org 2935504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n", 2947819Ssteve.reinhardt@amd.com cpu->name(), cycles, resume); 2955504Snate@binkert.org 2965504Snate@binkert.org tc->suspend(); 2975504Snate@binkert.org if (tc->getKernelStats()) 2985504Snate@binkert.org tc->getKernelStats()->quiesce(); 2995504Snate@binkert.org} 3005504Snate@binkert.org 3015504Snate@binkert.orguint64_t 3025504Snate@binkert.orgquiesceTime(ThreadContext *tc) 3035504Snate@binkert.org{ 3048806Sgblack@eecs.umich.edu if (!FullSystem) { 3058784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceTime"); 3068784Sgblack@eecs.umich.edu return 0; 3078784Sgblack@eecs.umich.edu } 3088806Sgblack@eecs.umich.edu 3097064Snate@binkert.org return (tc->readLastActivate() - tc->readLastSuspend()) / 3107064Snate@binkert.org SimClock::Int::ns; 3115504Snate@binkert.org} 3125504Snate@binkert.org 3135741Snate@binkert.orguint64_t 3145741Snate@binkert.orgrpns(ThreadContext *tc) 3155741Snate@binkert.org{ 3167823Ssteve.reinhardt@amd.com return curTick() / SimClock::Int::ns; 3175741Snate@binkert.org} 3185741Snate@binkert.org 3195504Snate@binkert.orgvoid 3205808Snate@binkert.orgwakeCPU(ThreadContext *tc, uint64_t cpuid) 3215808Snate@binkert.org{ 3225808Snate@binkert.org System *sys = tc->getSystemPtr(); 3235808Snate@binkert.org ThreadContext *other_tc = sys->threadContexts[cpuid]; 3245808Snate@binkert.org if (other_tc->status() == ThreadContext::Suspended) 3255808Snate@binkert.org other_tc->activate(); 3265808Snate@binkert.org} 3275808Snate@binkert.org 3285808Snate@binkert.orgvoid 3295504Snate@binkert.orgm5exit(ThreadContext *tc, Tick delay) 3305504Snate@binkert.org{ 3317823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 3327819Ssteve.reinhardt@amd.com exitSimLoop("m5_exit instruction encountered", 0, when); 3335504Snate@binkert.org} 3345504Snate@binkert.org 3355504Snate@binkert.orgvoid 3369457Svilanova@ac.upc.edum5fail(ThreadContext *tc, Tick delay, uint64_t code) 3379457Svilanova@ac.upc.edu{ 3389457Svilanova@ac.upc.edu Tick when = curTick() + delay * SimClock::Int::ns; 3399457Svilanova@ac.upc.edu exitSimLoop("m5_fail instruction encountered", code, when); 3409457Svilanova@ac.upc.edu} 3419457Svilanova@ac.upc.edu 3429457Svilanova@ac.upc.eduvoid 3435504Snate@binkert.orgloadsymbol(ThreadContext *tc) 3445504Snate@binkert.org{ 3458806Sgblack@eecs.umich.edu if (!FullSystem) 3468806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("loadsymbol"); 3478784Sgblack@eecs.umich.edu 3485504Snate@binkert.org const string &filename = tc->getCpuPtr()->system->params()->symbolfile; 3495504Snate@binkert.org if (filename.empty()) { 3505504Snate@binkert.org return; 351711SN/A } 352711SN/A 3535504Snate@binkert.org std::string buffer; 3545504Snate@binkert.org ifstream file(filename.c_str()); 355310SN/A 3565504Snate@binkert.org if (!file) 3575504Snate@binkert.org fatal("file error: Can't open symbol table file %s\n", filename); 3583373Sstever@eecs.umich.edu 3595504Snate@binkert.org while (!file.eof()) { 3605504Snate@binkert.org getline(file, buffer); 3615504Snate@binkert.org 3625504Snate@binkert.org if (buffer.empty()) 3635504Snate@binkert.org continue; 3645504Snate@binkert.org 3656227Snate@binkert.org string::size_type idx = buffer.find(' '); 3665504Snate@binkert.org if (idx == string::npos) 3675504Snate@binkert.org continue; 3685504Snate@binkert.org 3695504Snate@binkert.org string address = "0x" + buffer.substr(0, idx); 3705504Snate@binkert.org eat_white(address); 3715504Snate@binkert.org if (address.empty()) 3725504Snate@binkert.org continue; 3735504Snate@binkert.org 3745504Snate@binkert.org // Skip over letter and space 3755504Snate@binkert.org string symbol = buffer.substr(idx + 3); 3765504Snate@binkert.org eat_white(symbol); 3775504Snate@binkert.org if (symbol.empty()) 3785504Snate@binkert.org continue; 3795504Snate@binkert.org 3805504Snate@binkert.org Addr addr; 3815504Snate@binkert.org if (!to_number(address, addr)) 3825504Snate@binkert.org continue; 3835504Snate@binkert.org 3845504Snate@binkert.org if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol)) 3855504Snate@binkert.org continue; 3865504Snate@binkert.org 3875504Snate@binkert.org 3885504Snate@binkert.org DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 3895504Snate@binkert.org } 3905504Snate@binkert.org file.close(); 3915504Snate@binkert.org} 3925504Snate@binkert.org 3935504Snate@binkert.orgvoid 3945780Ssteve.reinhardt@amd.comaddsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 3955780Ssteve.reinhardt@amd.com{ 3968806Sgblack@eecs.umich.edu if (!FullSystem) 3978806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("addSymbol"); 3988666SPrakash.Ramrakhyani@arm.com 3995780Ssteve.reinhardt@amd.com char symb[100]; 4005780Ssteve.reinhardt@amd.com CopyStringOut(tc, symb, symbolAddr, 100); 4015780Ssteve.reinhardt@amd.com std::string symbol(symb); 4025780Ssteve.reinhardt@amd.com 4035780Ssteve.reinhardt@amd.com DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 4045780Ssteve.reinhardt@amd.com 4055780Ssteve.reinhardt@amd.com tc->getSystemPtr()->kernelSymtab->insert(addr,symbol); 4065952Ssaidi@eecs.umich.edu debugSymbolTable->insert(addr,symbol); 4075780Ssteve.reinhardt@amd.com} 4085780Ssteve.reinhardt@amd.com 4098555Sgblack@eecs.umich.eduuint64_t 4108555Sgblack@eecs.umich.eduinitParam(ThreadContext *tc) 4118555Sgblack@eecs.umich.edu{ 4128806Sgblack@eecs.umich.edu if (!FullSystem) { 4138784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("initParam"); 4148784Sgblack@eecs.umich.edu return 0; 4158784Sgblack@eecs.umich.edu } 4168806Sgblack@eecs.umich.edu 4178555Sgblack@eecs.umich.edu return tc->getCpuPtr()->system->init_param; 4188555Sgblack@eecs.umich.edu} 4198555Sgblack@eecs.umich.edu 4205780Ssteve.reinhardt@amd.com 4215780Ssteve.reinhardt@amd.comvoid 4225504Snate@binkert.orgresetstats(ThreadContext *tc, Tick delay, Tick period) 4235504Snate@binkert.org{ 4245529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4255504Snate@binkert.org return; 4265504Snate@binkert.org 4275504Snate@binkert.org 4287823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4297064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4305504Snate@binkert.org 4317822Ssteve.reinhardt@amd.com Stats::schedStatEvent(false, true, when, repeat); 4325504Snate@binkert.org} 4335504Snate@binkert.org 4345504Snate@binkert.orgvoid 4355504Snate@binkert.orgdumpstats(ThreadContext *tc, Tick delay, Tick period) 4365504Snate@binkert.org{ 4375529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4385504Snate@binkert.org return; 4395504Snate@binkert.org 4405504Snate@binkert.org 4417823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4427064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4435504Snate@binkert.org 4447822Ssteve.reinhardt@amd.com Stats::schedStatEvent(true, false, when, repeat); 4455504Snate@binkert.org} 4465504Snate@binkert.org 4475504Snate@binkert.orgvoid 4485504Snate@binkert.orgdumpresetstats(ThreadContext *tc, Tick delay, Tick period) 4495504Snate@binkert.org{ 4505529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4515504Snate@binkert.org return; 4525504Snate@binkert.org 4535504Snate@binkert.org 4547823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4557064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4565504Snate@binkert.org 4577822Ssteve.reinhardt@amd.com Stats::schedStatEvent(true, true, when, repeat); 4585504Snate@binkert.org} 4595504Snate@binkert.org 4605504Snate@binkert.orgvoid 4615504Snate@binkert.orgm5checkpoint(ThreadContext *tc, Tick delay, Tick period) 4625504Snate@binkert.org{ 4635529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_checkpoint_insts) 4645504Snate@binkert.org return; 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 4697819Ssteve.reinhardt@amd.com exitSimLoop("checkpoint", 0, when, repeat); 4705504Snate@binkert.org} 4715504Snate@binkert.org 4725504Snate@binkert.orguint64_t 4735504Snate@binkert.orgreadfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) 4745504Snate@binkert.org{ 4758806Sgblack@eecs.umich.edu if (!FullSystem) { 4768784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("readfile"); 4778784Sgblack@eecs.umich.edu return 0; 4788666SPrakash.Ramrakhyani@arm.com } 4798806Sgblack@eecs.umich.edu 4805504Snate@binkert.org const string &file = tc->getSystemPtr()->params()->readfile; 4815504Snate@binkert.org if (file.empty()) { 4825504Snate@binkert.org return ULL(0); 483310SN/A } 484299SN/A 4855504Snate@binkert.org uint64_t result = 0; 4862188SN/A 4875504Snate@binkert.org int fd = ::open(file.c_str(), O_RDONLY, 0); 4885504Snate@binkert.org if (fd < 0) 4895504Snate@binkert.org panic("could not open file %s\n", file); 4902235SN/A 4915504Snate@binkert.org if (::lseek(fd, offset, SEEK_SET) < 0) 4925504Snate@binkert.org panic("could not seek: %s", strerror(errno)); 4933368Sstever@eecs.umich.edu 4945504Snate@binkert.org char *buf = new char[len]; 4955504Snate@binkert.org char *p = buf; 4965504Snate@binkert.org while (len > 0) { 4975504Snate@binkert.org int bytes = ::read(fd, p, len); 4985504Snate@binkert.org if (bytes <= 0) 4995504Snate@binkert.org break; 5003368Sstever@eecs.umich.edu 5015504Snate@binkert.org p += bytes; 5025504Snate@binkert.org result += bytes; 5035504Snate@binkert.org len -= bytes; 5042188SN/A } 5052188SN/A 5065504Snate@binkert.org close(fd); 5075504Snate@binkert.org CopyIn(tc, vaddr, buf, result); 5085504Snate@binkert.org delete [] buf; 5095504Snate@binkert.org return result; 5105504Snate@binkert.org} 5112188SN/A 5128734Sdam.sunwoo@arm.comuint64_t 5138734Sdam.sunwoo@arm.comwritefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, 5148734Sdam.sunwoo@arm.com Addr filename_addr) 5158734Sdam.sunwoo@arm.com{ 5168734Sdam.sunwoo@arm.com ostream *os; 5178734Sdam.sunwoo@arm.com 5188734Sdam.sunwoo@arm.com // copy out target filename 5198734Sdam.sunwoo@arm.com char fn[100]; 5208734Sdam.sunwoo@arm.com std::string filename; 5218734Sdam.sunwoo@arm.com CopyStringOut(tc, fn, filename_addr, 100); 5228734Sdam.sunwoo@arm.com filename = std::string(fn); 5238734Sdam.sunwoo@arm.com 5248734Sdam.sunwoo@arm.com if (offset == 0) { 5258734Sdam.sunwoo@arm.com // create a new file (truncate) 5268734Sdam.sunwoo@arm.com os = simout.create(filename, true); 5278734Sdam.sunwoo@arm.com } else { 5288734Sdam.sunwoo@arm.com // do not truncate file if offset is non-zero 5298734Sdam.sunwoo@arm.com // (ios::in flag is required as well to keep the existing data 5308734Sdam.sunwoo@arm.com // intact, otherwise existing data will be zeroed out.) 5318734Sdam.sunwoo@arm.com os = simout.openFile(simout.directory() + filename, 5328734Sdam.sunwoo@arm.com ios::in | ios::out | ios::binary); 5338734Sdam.sunwoo@arm.com } 5348734Sdam.sunwoo@arm.com if (!os) 5358734Sdam.sunwoo@arm.com panic("could not open file %s\n", filename); 5368734Sdam.sunwoo@arm.com 5378734Sdam.sunwoo@arm.com // seek to offset 5388734Sdam.sunwoo@arm.com os->seekp(offset); 5398734Sdam.sunwoo@arm.com 5408734Sdam.sunwoo@arm.com // copy out data and write to file 5418734Sdam.sunwoo@arm.com char *buf = new char[len]; 5428734Sdam.sunwoo@arm.com CopyOut(tc, buf, vaddr, len); 5438734Sdam.sunwoo@arm.com os->write(buf, len); 5448734Sdam.sunwoo@arm.com if (os->fail() || os->bad()) 5458734Sdam.sunwoo@arm.com panic("Error while doing writefile!\n"); 5468734Sdam.sunwoo@arm.com 5478734Sdam.sunwoo@arm.com simout.close(os); 5488734Sdam.sunwoo@arm.com 5498734Sdam.sunwoo@arm.com delete [] buf; 5508734Sdam.sunwoo@arm.com 5518734Sdam.sunwoo@arm.com return len; 5528734Sdam.sunwoo@arm.com} 5538734Sdam.sunwoo@arm.com 5545504Snate@binkert.orgvoid 5555504Snate@binkert.orgdebugbreak(ThreadContext *tc) 5565504Snate@binkert.org{ 5578231Snate@binkert.org Debug::breakpoint(); 5585504Snate@binkert.org} 5592235SN/A 5605504Snate@binkert.orgvoid 5615504Snate@binkert.orgswitchcpu(ThreadContext *tc) 5625504Snate@binkert.org{ 5635504Snate@binkert.org exitSimLoop("switchcpu"); 5645504Snate@binkert.org} 5653368Sstever@eecs.umich.edu 5667914SBrad.Beckmann@amd.com// 5677914SBrad.Beckmann@amd.com// This function is executed when annotated work items begin. Depending on 5687914SBrad.Beckmann@amd.com// what the user specified at the command line, the simulation may exit and/or 5697914SBrad.Beckmann@amd.com// take a checkpoint when a certain work item begins. 5707914SBrad.Beckmann@amd.com// 5717914SBrad.Beckmann@amd.comvoid 5727914SBrad.Beckmann@amd.comworkbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid) 5737914SBrad.Beckmann@amd.com{ 5747914SBrad.Beckmann@amd.com tc->getCpuPtr()->workItemBegin(); 5757914SBrad.Beckmann@amd.com System *sys = tc->getSystemPtr(); 5768580Ssteve.reinhardt@amd.com const System::Params *params = sys->params(); 5778666SPrakash.Ramrakhyani@arm.com sys->workItemBegin(threadid, workid); 5787914SBrad.Beckmann@amd.com 5797914SBrad.Beckmann@amd.com DPRINTF(WorkItems, "Work Begin workid: %d, threadid %d\n", workid, 5807914SBrad.Beckmann@amd.com threadid); 5817914SBrad.Beckmann@amd.com 5827914SBrad.Beckmann@amd.com // 5837914SBrad.Beckmann@amd.com // If specified, determine if this is the specific work item the user 5847914SBrad.Beckmann@amd.com // identified 5857914SBrad.Beckmann@amd.com // 5868580Ssteve.reinhardt@amd.com if (params->work_item_id == -1 || params->work_item_id == workid) { 5877914SBrad.Beckmann@amd.com 5887914SBrad.Beckmann@amd.com uint64_t systemWorkBeginCount = sys->incWorkItemsBegin(); 5897914SBrad.Beckmann@amd.com int cpuId = tc->getCpuPtr()->cpuId(); 5907914SBrad.Beckmann@amd.com 5918580Ssteve.reinhardt@amd.com if (params->work_cpus_ckpt_count != 0 && 5928580Ssteve.reinhardt@amd.com sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 5937914SBrad.Beckmann@amd.com // 5947914SBrad.Beckmann@amd.com // If active cpus equals checkpoint count, create checkpoint 5957914SBrad.Beckmann@amd.com // 5968580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 5977914SBrad.Beckmann@amd.com } 5987914SBrad.Beckmann@amd.com 5998580Ssteve.reinhardt@amd.com if (systemWorkBeginCount == params->work_begin_ckpt_count) { 6007914SBrad.Beckmann@amd.com // 6017914SBrad.Beckmann@amd.com // Note: the string specified as the cause of the exit event must 6027914SBrad.Beckmann@amd.com // exactly equal "checkpoint" inorder to create a checkpoint 6037914SBrad.Beckmann@amd.com // 6048580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6057914SBrad.Beckmann@amd.com } 6067914SBrad.Beckmann@amd.com 6078580Ssteve.reinhardt@amd.com if (systemWorkBeginCount == params->work_begin_exit_count) { 6087914SBrad.Beckmann@amd.com // 6097914SBrad.Beckmann@amd.com // If a certain number of work items started, exit simulation 6107914SBrad.Beckmann@amd.com // 6118580Ssteve.reinhardt@amd.com exitSimLoop("work started count reach"); 6127914SBrad.Beckmann@amd.com } 6137914SBrad.Beckmann@amd.com 6148580Ssteve.reinhardt@amd.com if (cpuId == params->work_begin_cpu_id_exit) { 6157914SBrad.Beckmann@amd.com // 6168580Ssteve.reinhardt@amd.com // If work started on the cpu id specified, exit simulation 6177914SBrad.Beckmann@amd.com // 6188580Ssteve.reinhardt@amd.com exitSimLoop("work started on specific cpu"); 6197914SBrad.Beckmann@amd.com } 6207914SBrad.Beckmann@amd.com } 6217914SBrad.Beckmann@amd.com} 6227914SBrad.Beckmann@amd.com 6237914SBrad.Beckmann@amd.com// 6247914SBrad.Beckmann@amd.com// This function is executed when annotated work items end. Depending on 6257914SBrad.Beckmann@amd.com// what the user specified at the command line, the simulation may exit and/or 6267914SBrad.Beckmann@amd.com// take a checkpoint when a certain work item ends. 6277914SBrad.Beckmann@amd.com// 6287914SBrad.Beckmann@amd.comvoid 6297914SBrad.Beckmann@amd.comworkend(ThreadContext *tc, uint64_t workid, uint64_t threadid) 6307914SBrad.Beckmann@amd.com{ 6317914SBrad.Beckmann@amd.com tc->getCpuPtr()->workItemEnd(); 6327914SBrad.Beckmann@amd.com System *sys = tc->getSystemPtr(); 6338580Ssteve.reinhardt@amd.com const System::Params *params = sys->params(); 6348666SPrakash.Ramrakhyani@arm.com sys->workItemEnd(threadid, workid); 6357914SBrad.Beckmann@amd.com 6367914SBrad.Beckmann@amd.com DPRINTF(WorkItems, "Work End workid: %d, threadid %d\n", workid, threadid); 6377914SBrad.Beckmann@amd.com 6387914SBrad.Beckmann@amd.com // 6397914SBrad.Beckmann@amd.com // If specified, determine if this is the specific work item the user 6407914SBrad.Beckmann@amd.com // identified 6417914SBrad.Beckmann@amd.com // 6428580Ssteve.reinhardt@amd.com if (params->work_item_id == -1 || params->work_item_id == workid) { 6437914SBrad.Beckmann@amd.com 6447914SBrad.Beckmann@amd.com uint64_t systemWorkEndCount = sys->incWorkItemsEnd(); 6457914SBrad.Beckmann@amd.com int cpuId = tc->getCpuPtr()->cpuId(); 6467914SBrad.Beckmann@amd.com 6478580Ssteve.reinhardt@amd.com if (params->work_cpus_ckpt_count != 0 && 6488580Ssteve.reinhardt@amd.com sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 6497914SBrad.Beckmann@amd.com // 6507914SBrad.Beckmann@amd.com // If active cpus equals checkpoint count, create checkpoint 6517914SBrad.Beckmann@amd.com // 6528580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6537914SBrad.Beckmann@amd.com } 6547914SBrad.Beckmann@amd.com 6558580Ssteve.reinhardt@amd.com if (params->work_end_ckpt_count != 0 && 6568580Ssteve.reinhardt@amd.com systemWorkEndCount == params->work_end_ckpt_count) { 6577914SBrad.Beckmann@amd.com // 6587914SBrad.Beckmann@amd.com // If total work items completed equals checkpoint count, create 6597914SBrad.Beckmann@amd.com // checkpoint 6607914SBrad.Beckmann@amd.com // 6618580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6627914SBrad.Beckmann@amd.com } 6637914SBrad.Beckmann@amd.com 6648580Ssteve.reinhardt@amd.com if (params->work_end_exit_count != 0 && 6658580Ssteve.reinhardt@amd.com systemWorkEndCount == params->work_end_exit_count) { 6667914SBrad.Beckmann@amd.com // 6677914SBrad.Beckmann@amd.com // If total work items completed equals exit count, exit simulation 6687914SBrad.Beckmann@amd.com // 6698580Ssteve.reinhardt@amd.com exitSimLoop("work items exit count reached"); 6707914SBrad.Beckmann@amd.com } 6717914SBrad.Beckmann@amd.com } 6727914SBrad.Beckmann@amd.com} 6737914SBrad.Beckmann@amd.com 6747811Ssteve.reinhardt@amd.com} // namespace PseudoInst 675