pseudo_inst.cc revision 11259
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" 5510553Salexandru.dutu@amd.com#include "arch/pseudo_inst.hh" 565882Snate@binkert.org#include "base/debug.hh" 578734Sdam.sunwoo@arm.com#include "base/output.hh" 586658Snate@binkert.org#include "config/the_isa.hh" 591717SN/A#include "cpu/base.hh" 608229Snate@binkert.org#include "cpu/quiesce_event.hh" 612680Sktlim@umich.edu#include "cpu/thread_context.hh" 628232Snate@binkert.org#include "debug/Loader.hh" 639733Sandreas@sandberg.pp.se#include "debug/PseudoInst.hh" 648232Snate@binkert.org#include "debug/Quiesce.hh" 658232Snate@binkert.org#include "debug/WorkItems.hh" 665529Snate@binkert.org#include "params/BaseCPU.hh" 678784Sgblack@eecs.umich.edu#include "sim/full_system.hh" 6810553Salexandru.dutu@amd.com#include "sim/process.hh" 693565Sgblack@eecs.umich.edu#include "sim/pseudo_inst.hh" 70298SN/A#include "sim/serialize.hh" 715606Snate@binkert.org#include "sim/sim_events.hh" 72298SN/A#include "sim/sim_exit.hh" 73695SN/A#include "sim/stat_control.hh" 74695SN/A#include "sim/stats.hh" 75954SN/A#include "sim/system.hh" 762080SN/A#include "sim/vptr.hh" 77298SN/A 78299SN/Ausing namespace std; 791052SN/A 80729SN/Ausing namespace Stats; 812107SN/Ausing namespace TheISA; 82298SN/A 835504Snate@binkert.orgnamespace PseudoInst { 845504Snate@binkert.org 858784Sgblack@eecs.umich.edustatic inline void 868784Sgblack@eecs.umich.edupanicFsOnlyPseudoInst(const char *name) 878784Sgblack@eecs.umich.edu{ 888784Sgblack@eecs.umich.edu panic("Pseudo inst \"%s\" is only available in Full System mode."); 898784Sgblack@eecs.umich.edu} 905780Ssteve.reinhardt@amd.com 919659SAndreas.Sandberg@ARM.comuint64_t 929659SAndreas.Sandberg@ARM.compseudoInst(ThreadContext *tc, uint8_t func, uint8_t subfunc) 939659SAndreas.Sandberg@ARM.com{ 949659SAndreas.Sandberg@ARM.com uint64_t args[4]; 959659SAndreas.Sandberg@ARM.com 969733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::pseudoInst(%i, %i)\n", func, subfunc); 979733Sandreas@sandberg.pp.se 989659SAndreas.Sandberg@ARM.com // We need to do this in a slightly convoluted way since 999659SAndreas.Sandberg@ARM.com // getArgument() might have side-effects on arg_num. We could have 1009659SAndreas.Sandberg@ARM.com // used the Argument class, but due to the possible side effects 1019659SAndreas.Sandberg@ARM.com // from getArgument, it'd most likely break. 1029659SAndreas.Sandberg@ARM.com int arg_num(0); 1039879Sandreas@sandberg.pp.se for (int i = 0; i < sizeof(args) / sizeof(*args); ++i) { 1049879Sandreas@sandberg.pp.se args[arg_num] = getArgument(tc, arg_num, sizeof(uint64_t), false); 1059879Sandreas@sandberg.pp.se ++arg_num; 1069879Sandreas@sandberg.pp.se } 1079659SAndreas.Sandberg@ARM.com 1089659SAndreas.Sandberg@ARM.com switch (func) { 1099659SAndreas.Sandberg@ARM.com case 0x00: // arm_func 1109659SAndreas.Sandberg@ARM.com arm(tc); 1119659SAndreas.Sandberg@ARM.com break; 1129659SAndreas.Sandberg@ARM.com 1139659SAndreas.Sandberg@ARM.com case 0x01: // quiesce_func 1149659SAndreas.Sandberg@ARM.com quiesce(tc); 1159659SAndreas.Sandberg@ARM.com break; 1169659SAndreas.Sandberg@ARM.com 1179659SAndreas.Sandberg@ARM.com case 0x02: // quiescens_func 1189659SAndreas.Sandberg@ARM.com quiesceSkip(tc); 1199659SAndreas.Sandberg@ARM.com break; 1209659SAndreas.Sandberg@ARM.com 1219659SAndreas.Sandberg@ARM.com case 0x03: // quiescecycle_func 1229659SAndreas.Sandberg@ARM.com quiesceNs(tc, args[0]); 1239659SAndreas.Sandberg@ARM.com break; 1249659SAndreas.Sandberg@ARM.com 1259659SAndreas.Sandberg@ARM.com case 0x04: // quiescetime_func 1269659SAndreas.Sandberg@ARM.com return quiesceTime(tc); 1279659SAndreas.Sandberg@ARM.com 1289659SAndreas.Sandberg@ARM.com case 0x07: // rpns_func 1299659SAndreas.Sandberg@ARM.com return rpns(tc); 1309659SAndreas.Sandberg@ARM.com 1319659SAndreas.Sandberg@ARM.com case 0x09: // wakecpu_func 1329659SAndreas.Sandberg@ARM.com wakeCPU(tc, args[0]); 1339659SAndreas.Sandberg@ARM.com break; 1349659SAndreas.Sandberg@ARM.com 1359659SAndreas.Sandberg@ARM.com case 0x21: // exit_func 1369659SAndreas.Sandberg@ARM.com m5exit(tc, args[0]); 1379659SAndreas.Sandberg@ARM.com break; 1389659SAndreas.Sandberg@ARM.com 1399681Sandreas@sandberg.pp.se case 0x22: 1409681Sandreas@sandberg.pp.se m5fail(tc, args[0], args[1]); 1419681Sandreas@sandberg.pp.se break; 1429681Sandreas@sandberg.pp.se 1439659SAndreas.Sandberg@ARM.com case 0x30: // initparam_func 1449659SAndreas.Sandberg@ARM.com return initParam(tc); 1459659SAndreas.Sandberg@ARM.com 1469659SAndreas.Sandberg@ARM.com case 0x31: // loadsymbol_func 1479659SAndreas.Sandberg@ARM.com loadsymbol(tc); 1489659SAndreas.Sandberg@ARM.com break; 1499659SAndreas.Sandberg@ARM.com 1509659SAndreas.Sandberg@ARM.com case 0x40: // resetstats_func 1519659SAndreas.Sandberg@ARM.com resetstats(tc, args[0], args[1]); 1529659SAndreas.Sandberg@ARM.com break; 1539659SAndreas.Sandberg@ARM.com 1549659SAndreas.Sandberg@ARM.com case 0x41: // dumpstats_func 1559659SAndreas.Sandberg@ARM.com dumpstats(tc, args[0], args[1]); 1569659SAndreas.Sandberg@ARM.com break; 1579659SAndreas.Sandberg@ARM.com 1589659SAndreas.Sandberg@ARM.com case 0x42: // dumprststats_func 1599659SAndreas.Sandberg@ARM.com dumpresetstats(tc, args[0], args[1]); 1609659SAndreas.Sandberg@ARM.com break; 1619659SAndreas.Sandberg@ARM.com 1629659SAndreas.Sandberg@ARM.com case 0x43: // ckpt_func 1639659SAndreas.Sandberg@ARM.com m5checkpoint(tc, args[0], args[1]); 1649659SAndreas.Sandberg@ARM.com break; 1659659SAndreas.Sandberg@ARM.com 1669659SAndreas.Sandberg@ARM.com case 0x4f: // writefile_func 1679659SAndreas.Sandberg@ARM.com return writefile(tc, args[0], args[1], args[2], args[3]); 1689659SAndreas.Sandberg@ARM.com 1699659SAndreas.Sandberg@ARM.com case 0x50: // readfile_func 1709659SAndreas.Sandberg@ARM.com return readfile(tc, args[0], args[1], args[2]); 1719659SAndreas.Sandberg@ARM.com 1729659SAndreas.Sandberg@ARM.com case 0x51: // debugbreak_func 1739659SAndreas.Sandberg@ARM.com debugbreak(tc); 1749659SAndreas.Sandberg@ARM.com break; 1759659SAndreas.Sandberg@ARM.com 1769659SAndreas.Sandberg@ARM.com case 0x52: // switchcpu_func 1779659SAndreas.Sandberg@ARM.com switchcpu(tc); 1789659SAndreas.Sandberg@ARM.com break; 1799659SAndreas.Sandberg@ARM.com 1809659SAndreas.Sandberg@ARM.com case 0x53: // addsymbol_func 1819659SAndreas.Sandberg@ARM.com addsymbol(tc, args[0], args[1]); 1829659SAndreas.Sandberg@ARM.com break; 1839659SAndreas.Sandberg@ARM.com 1849659SAndreas.Sandberg@ARM.com case 0x54: // panic_func 1859659SAndreas.Sandberg@ARM.com panic("M5 panic instruction called at %s\n", tc->pcState()); 1869659SAndreas.Sandberg@ARM.com 1879659SAndreas.Sandberg@ARM.com case 0x5a: // work_begin_func 1889659SAndreas.Sandberg@ARM.com workbegin(tc, args[0], args[1]); 1899659SAndreas.Sandberg@ARM.com break; 1909659SAndreas.Sandberg@ARM.com 1919659SAndreas.Sandberg@ARM.com case 0x5b: // work_end_func 1929659SAndreas.Sandberg@ARM.com workend(tc, args[0], args[1]); 1939659SAndreas.Sandberg@ARM.com break; 1949659SAndreas.Sandberg@ARM.com 1959659SAndreas.Sandberg@ARM.com case 0x55: // annotate_func 1969659SAndreas.Sandberg@ARM.com case 0x56: // reserved2_func 1979659SAndreas.Sandberg@ARM.com case 0x57: // reserved3_func 1989659SAndreas.Sandberg@ARM.com case 0x58: // reserved4_func 1999659SAndreas.Sandberg@ARM.com case 0x59: // reserved5_func 2009659SAndreas.Sandberg@ARM.com warn("Unimplemented m5 op (0x%x)\n", func); 2019659SAndreas.Sandberg@ARM.com break; 2029659SAndreas.Sandberg@ARM.com 20310553Salexandru.dutu@amd.com /* SE mode functions */ 20410553Salexandru.dutu@amd.com case 0x60: // syscall_func 20510553Salexandru.dutu@amd.com m5Syscall(tc); 20610553Salexandru.dutu@amd.com break; 20710553Salexandru.dutu@amd.com 20810553Salexandru.dutu@amd.com case 0x61: // pagefault_func 20910553Salexandru.dutu@amd.com m5PageFault(tc); 21010553Salexandru.dutu@amd.com break; 21110553Salexandru.dutu@amd.com 2129659SAndreas.Sandberg@ARM.com default: 2139659SAndreas.Sandberg@ARM.com warn("Unhandled m5 op: 0x%x\n", func); 2149659SAndreas.Sandberg@ARM.com break; 2159659SAndreas.Sandberg@ARM.com } 2169659SAndreas.Sandberg@ARM.com 2179659SAndreas.Sandberg@ARM.com return 0; 2189659SAndreas.Sandberg@ARM.com} 2199659SAndreas.Sandberg@ARM.com 2205504Snate@binkert.orgvoid 2215504Snate@binkert.orgarm(ThreadContext *tc) 222298SN/A{ 2239733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::arm()\n"); 2248806Sgblack@eecs.umich.edu if (!FullSystem) 2258784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("arm"); 2268806Sgblack@eecs.umich.edu 2275504Snate@binkert.org if (tc->getKernelStats()) 2285504Snate@binkert.org tc->getKernelStats()->arm(); 2295504Snate@binkert.org} 2305504Snate@binkert.org 2315504Snate@binkert.orgvoid 2325504Snate@binkert.orgquiesce(ThreadContext *tc) 2335504Snate@binkert.org{ 2349733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesce()\n"); 2358806Sgblack@eecs.umich.edu if (!FullSystem) 2368806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesce"); 2378666SPrakash.Ramrakhyani@arm.com 2385529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_quiesce) 2395504Snate@binkert.org return; 2405504Snate@binkert.org 2415504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name()); 2425504Snate@binkert.org 2435504Snate@binkert.org tc->suspend(); 2445504Snate@binkert.org if (tc->getKernelStats()) 2455504Snate@binkert.org tc->getKernelStats()->quiesce(); 2465504Snate@binkert.org} 2475504Snate@binkert.org 2485504Snate@binkert.orgvoid 2498142SAli.Saidi@ARM.comquiesceSkip(ThreadContext *tc) 2508142SAli.Saidi@ARM.com{ 2519733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesceSkip()\n"); 2528806Sgblack@eecs.umich.edu if (!FullSystem) 2538806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceSkip"); 2548666SPrakash.Ramrakhyani@arm.com 2558142SAli.Saidi@ARM.com BaseCPU *cpu = tc->getCpuPtr(); 2568142SAli.Saidi@ARM.com 2578142SAli.Saidi@ARM.com if (!cpu->params()->do_quiesce) 2588142SAli.Saidi@ARM.com return; 2598142SAli.Saidi@ARM.com 2608142SAli.Saidi@ARM.com EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 2618142SAli.Saidi@ARM.com 2628142SAli.Saidi@ARM.com Tick resume = curTick() + 1; 2638142SAli.Saidi@ARM.com 2648142SAli.Saidi@ARM.com cpu->reschedule(quiesceEvent, resume, true); 2658142SAli.Saidi@ARM.com 2668142SAli.Saidi@ARM.com DPRINTF(Quiesce, "%s: quiesceSkip() until %d\n", 2678142SAli.Saidi@ARM.com cpu->name(), resume); 2688142SAli.Saidi@ARM.com 2698142SAli.Saidi@ARM.com tc->suspend(); 2708142SAli.Saidi@ARM.com if (tc->getKernelStats()) 2718142SAli.Saidi@ARM.com tc->getKernelStats()->quiesce(); 2728142SAli.Saidi@ARM.com} 2738142SAli.Saidi@ARM.com 2748142SAli.Saidi@ARM.comvoid 2755504Snate@binkert.orgquiesceNs(ThreadContext *tc, uint64_t ns) 2765504Snate@binkert.org{ 2779733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesceNs(%i)\n", ns); 2788806Sgblack@eecs.umich.edu if (!FullSystem) 2798806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceNs"); 2808666SPrakash.Ramrakhyani@arm.com 2817819Ssteve.reinhardt@amd.com BaseCPU *cpu = tc->getCpuPtr(); 2827819Ssteve.reinhardt@amd.com 28311058Secastill@bsc.es if (!cpu->params()->do_quiesce) 2845504Snate@binkert.org return; 2855504Snate@binkert.org 2865504Snate@binkert.org EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 2875504Snate@binkert.org 2887823Ssteve.reinhardt@amd.com Tick resume = curTick() + SimClock::Int::ns * ns; 2895504Snate@binkert.org 2907819Ssteve.reinhardt@amd.com cpu->reschedule(quiesceEvent, resume, true); 2915504Snate@binkert.org 2925504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesceNs(%d) until %d\n", 2937819Ssteve.reinhardt@amd.com cpu->name(), ns, resume); 2945504Snate@binkert.org 2955504Snate@binkert.org tc->suspend(); 2965504Snate@binkert.org if (tc->getKernelStats()) 2975504Snate@binkert.org tc->getKernelStats()->quiesce(); 2985504Snate@binkert.org} 2995504Snate@binkert.org 3005504Snate@binkert.orgvoid 3015504Snate@binkert.orgquiesceCycles(ThreadContext *tc, uint64_t cycles) 3025504Snate@binkert.org{ 3039733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesceCycles(%i)\n", cycles); 3048806Sgblack@eecs.umich.edu if (!FullSystem) 3058806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceCycles"); 3068666SPrakash.Ramrakhyani@arm.com 3077819Ssteve.reinhardt@amd.com BaseCPU *cpu = tc->getCpuPtr(); 3087819Ssteve.reinhardt@amd.com 30911058Secastill@bsc.es if (!cpu->params()->do_quiesce) 3105504Snate@binkert.org return; 3115504Snate@binkert.org 3125504Snate@binkert.org EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 3135504Snate@binkert.org 3149180Sandreas.hansson@arm.com Tick resume = cpu->clockEdge(Cycles(cycles)); 3155504Snate@binkert.org 3167819Ssteve.reinhardt@amd.com cpu->reschedule(quiesceEvent, resume, true); 3175504Snate@binkert.org 3185504Snate@binkert.org DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n", 3197819Ssteve.reinhardt@amd.com cpu->name(), cycles, resume); 3205504Snate@binkert.org 3215504Snate@binkert.org tc->suspend(); 3225504Snate@binkert.org if (tc->getKernelStats()) 3235504Snate@binkert.org tc->getKernelStats()->quiesce(); 3245504Snate@binkert.org} 3255504Snate@binkert.org 3265504Snate@binkert.orguint64_t 3275504Snate@binkert.orgquiesceTime(ThreadContext *tc) 3285504Snate@binkert.org{ 3299733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::quiesceTime()\n"); 3308806Sgblack@eecs.umich.edu if (!FullSystem) { 3318784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("quiesceTime"); 3328784Sgblack@eecs.umich.edu return 0; 3338784Sgblack@eecs.umich.edu } 3348806Sgblack@eecs.umich.edu 3357064Snate@binkert.org return (tc->readLastActivate() - tc->readLastSuspend()) / 3367064Snate@binkert.org SimClock::Int::ns; 3375504Snate@binkert.org} 3385504Snate@binkert.org 3395741Snate@binkert.orguint64_t 3405741Snate@binkert.orgrpns(ThreadContext *tc) 3415741Snate@binkert.org{ 3429733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::rpns()\n"); 3437823Ssteve.reinhardt@amd.com return curTick() / SimClock::Int::ns; 3445741Snate@binkert.org} 3455741Snate@binkert.org 3465504Snate@binkert.orgvoid 3475808Snate@binkert.orgwakeCPU(ThreadContext *tc, uint64_t cpuid) 3485808Snate@binkert.org{ 3499733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::wakeCPU(%i)\n", cpuid); 3505808Snate@binkert.org System *sys = tc->getSystemPtr(); 3515808Snate@binkert.org ThreadContext *other_tc = sys->threadContexts[cpuid]; 3525808Snate@binkert.org if (other_tc->status() == ThreadContext::Suspended) 3535808Snate@binkert.org other_tc->activate(); 3545808Snate@binkert.org} 3555808Snate@binkert.org 3565808Snate@binkert.orgvoid 3575504Snate@binkert.orgm5exit(ThreadContext *tc, Tick delay) 3585504Snate@binkert.org{ 3599733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::m5exit(%i)\n", delay); 3607823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 3619952Sdam.sunwoo@arm.com exitSimLoop("m5_exit instruction encountered", 0, when, 0, true); 3625504Snate@binkert.org} 3635504Snate@binkert.org 3645504Snate@binkert.orgvoid 3659457Svilanova@ac.upc.edum5fail(ThreadContext *tc, Tick delay, uint64_t code) 3669457Svilanova@ac.upc.edu{ 3679733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::m5fail(%i, %i)\n", delay, code); 3689457Svilanova@ac.upc.edu Tick when = curTick() + delay * SimClock::Int::ns; 3699952Sdam.sunwoo@arm.com exitSimLoop("m5_fail instruction encountered", code, when, 0, true); 3709457Svilanova@ac.upc.edu} 3719457Svilanova@ac.upc.edu 3729457Svilanova@ac.upc.eduvoid 3735504Snate@binkert.orgloadsymbol(ThreadContext *tc) 3745504Snate@binkert.org{ 3759733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::loadsymbol()\n"); 3768806Sgblack@eecs.umich.edu if (!FullSystem) 3778806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("loadsymbol"); 3788784Sgblack@eecs.umich.edu 3795504Snate@binkert.org const string &filename = tc->getCpuPtr()->system->params()->symbolfile; 3805504Snate@binkert.org if (filename.empty()) { 3815504Snate@binkert.org return; 382711SN/A } 383711SN/A 3845504Snate@binkert.org std::string buffer; 3855504Snate@binkert.org ifstream file(filename.c_str()); 386310SN/A 3875504Snate@binkert.org if (!file) 3885504Snate@binkert.org fatal("file error: Can't open symbol table file %s\n", filename); 3893373Sstever@eecs.umich.edu 3905504Snate@binkert.org while (!file.eof()) { 3915504Snate@binkert.org getline(file, buffer); 3925504Snate@binkert.org 3935504Snate@binkert.org if (buffer.empty()) 3945504Snate@binkert.org continue; 3955504Snate@binkert.org 3966227Snate@binkert.org string::size_type idx = buffer.find(' '); 3975504Snate@binkert.org if (idx == string::npos) 3985504Snate@binkert.org continue; 3995504Snate@binkert.org 4005504Snate@binkert.org string address = "0x" + buffer.substr(0, idx); 4015504Snate@binkert.org eat_white(address); 4025504Snate@binkert.org if (address.empty()) 4035504Snate@binkert.org continue; 4045504Snate@binkert.org 4055504Snate@binkert.org // Skip over letter and space 4065504Snate@binkert.org string symbol = buffer.substr(idx + 3); 4075504Snate@binkert.org eat_white(symbol); 4085504Snate@binkert.org if (symbol.empty()) 4095504Snate@binkert.org continue; 4105504Snate@binkert.org 4115504Snate@binkert.org Addr addr; 4125504Snate@binkert.org if (!to_number(address, addr)) 4135504Snate@binkert.org continue; 4145504Snate@binkert.org 4155504Snate@binkert.org if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol)) 4165504Snate@binkert.org continue; 4175504Snate@binkert.org 4185504Snate@binkert.org 4195504Snate@binkert.org DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 4205504Snate@binkert.org } 4215504Snate@binkert.org file.close(); 4225504Snate@binkert.org} 4235504Snate@binkert.org 4245504Snate@binkert.orgvoid 4255780Ssteve.reinhardt@amd.comaddsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 4265780Ssteve.reinhardt@amd.com{ 4279733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::addsymbol(0x%x, 0x%x)\n", 4289733Sandreas@sandberg.pp.se addr, symbolAddr); 4298806Sgblack@eecs.umich.edu if (!FullSystem) 4308806Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("addSymbol"); 4318666SPrakash.Ramrakhyani@arm.com 4325780Ssteve.reinhardt@amd.com char symb[100]; 4335780Ssteve.reinhardt@amd.com CopyStringOut(tc, symb, symbolAddr, 100); 4345780Ssteve.reinhardt@amd.com std::string symbol(symb); 4355780Ssteve.reinhardt@amd.com 4365780Ssteve.reinhardt@amd.com DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 4375780Ssteve.reinhardt@amd.com 4385780Ssteve.reinhardt@amd.com tc->getSystemPtr()->kernelSymtab->insert(addr,symbol); 4395952Ssaidi@eecs.umich.edu debugSymbolTable->insert(addr,symbol); 4405780Ssteve.reinhardt@amd.com} 4415780Ssteve.reinhardt@amd.com 4428555Sgblack@eecs.umich.eduuint64_t 4438555Sgblack@eecs.umich.eduinitParam(ThreadContext *tc) 4448555Sgblack@eecs.umich.edu{ 4459733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::initParam()\n"); 4468806Sgblack@eecs.umich.edu if (!FullSystem) { 4478784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("initParam"); 4488784Sgblack@eecs.umich.edu return 0; 4498784Sgblack@eecs.umich.edu } 4508806Sgblack@eecs.umich.edu 4518555Sgblack@eecs.umich.edu return tc->getCpuPtr()->system->init_param; 4528555Sgblack@eecs.umich.edu} 4538555Sgblack@eecs.umich.edu 4545780Ssteve.reinhardt@amd.com 4555780Ssteve.reinhardt@amd.comvoid 4565504Snate@binkert.orgresetstats(ThreadContext *tc, Tick delay, Tick period) 4575504Snate@binkert.org{ 4589733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::resetstats(%i, %i)\n", delay, period); 4595529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4605504Snate@binkert.org return; 4615504Snate@binkert.org 4625504Snate@binkert.org 4637823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4647064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4655504Snate@binkert.org 4667822Ssteve.reinhardt@amd.com Stats::schedStatEvent(false, true, when, repeat); 4675504Snate@binkert.org} 4685504Snate@binkert.org 4695504Snate@binkert.orgvoid 4705504Snate@binkert.orgdumpstats(ThreadContext *tc, Tick delay, Tick period) 4715504Snate@binkert.org{ 4729733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::dumpstats(%i, %i)\n", delay, period); 4735529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4745504Snate@binkert.org return; 4755504Snate@binkert.org 4765504Snate@binkert.org 4777823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4787064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4795504Snate@binkert.org 4807822Ssteve.reinhardt@amd.com Stats::schedStatEvent(true, false, when, repeat); 4815504Snate@binkert.org} 4825504Snate@binkert.org 4835504Snate@binkert.orgvoid 4845504Snate@binkert.orgdumpresetstats(ThreadContext *tc, Tick delay, Tick period) 4855504Snate@binkert.org{ 4869733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::dumpresetstats(%i, %i)\n", delay, period); 4875529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_statistics_insts) 4885504Snate@binkert.org return; 4895504Snate@binkert.org 4905504Snate@binkert.org 4917823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 4927064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 4935504Snate@binkert.org 4947822Ssteve.reinhardt@amd.com Stats::schedStatEvent(true, true, when, repeat); 4955504Snate@binkert.org} 4965504Snate@binkert.org 4975504Snate@binkert.orgvoid 4985504Snate@binkert.orgm5checkpoint(ThreadContext *tc, Tick delay, Tick period) 4995504Snate@binkert.org{ 5009733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::m5checkpoint(%i, %i)\n", delay, period); 5015529Snate@binkert.org if (!tc->getCpuPtr()->params()->do_checkpoint_insts) 5025504Snate@binkert.org return; 5035504Snate@binkert.org 5047823Ssteve.reinhardt@amd.com Tick when = curTick() + delay * SimClock::Int::ns; 5057064Snate@binkert.org Tick repeat = period * SimClock::Int::ns; 5065504Snate@binkert.org 5077819Ssteve.reinhardt@amd.com exitSimLoop("checkpoint", 0, when, repeat); 5085504Snate@binkert.org} 5095504Snate@binkert.org 5105504Snate@binkert.orguint64_t 5115504Snate@binkert.orgreadfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) 5125504Snate@binkert.org{ 5139733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::readfile(0x%x, 0x%x, 0x%x)\n", 5149733Sandreas@sandberg.pp.se vaddr, len, offset); 5158806Sgblack@eecs.umich.edu if (!FullSystem) { 5168784Sgblack@eecs.umich.edu panicFsOnlyPseudoInst("readfile"); 5178784Sgblack@eecs.umich.edu return 0; 5188666SPrakash.Ramrakhyani@arm.com } 5198806Sgblack@eecs.umich.edu 5205504Snate@binkert.org const string &file = tc->getSystemPtr()->params()->readfile; 5215504Snate@binkert.org if (file.empty()) { 5225504Snate@binkert.org return ULL(0); 523310SN/A } 524299SN/A 5255504Snate@binkert.org uint64_t result = 0; 5262188SN/A 5275504Snate@binkert.org int fd = ::open(file.c_str(), O_RDONLY, 0); 5285504Snate@binkert.org if (fd < 0) 5295504Snate@binkert.org panic("could not open file %s\n", file); 5302235SN/A 5315504Snate@binkert.org if (::lseek(fd, offset, SEEK_SET) < 0) 5325504Snate@binkert.org panic("could not seek: %s", strerror(errno)); 5333368Sstever@eecs.umich.edu 5345504Snate@binkert.org char *buf = new char[len]; 5355504Snate@binkert.org char *p = buf; 5365504Snate@binkert.org while (len > 0) { 5375504Snate@binkert.org int bytes = ::read(fd, p, len); 5385504Snate@binkert.org if (bytes <= 0) 5395504Snate@binkert.org break; 5403368Sstever@eecs.umich.edu 5415504Snate@binkert.org p += bytes; 5425504Snate@binkert.org result += bytes; 5435504Snate@binkert.org len -= bytes; 5442188SN/A } 5452188SN/A 5465504Snate@binkert.org close(fd); 5475504Snate@binkert.org CopyIn(tc, vaddr, buf, result); 5485504Snate@binkert.org delete [] buf; 5495504Snate@binkert.org return result; 5505504Snate@binkert.org} 5512188SN/A 5528734Sdam.sunwoo@arm.comuint64_t 5538734Sdam.sunwoo@arm.comwritefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, 5548734Sdam.sunwoo@arm.com Addr filename_addr) 5558734Sdam.sunwoo@arm.com{ 5569733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::writefile(0x%x, 0x%x, 0x%x, 0x%x)\n", 5579733Sandreas@sandberg.pp.se vaddr, len, offset, filename_addr); 5588734Sdam.sunwoo@arm.com ostream *os; 5598734Sdam.sunwoo@arm.com 5608734Sdam.sunwoo@arm.com // copy out target filename 5618734Sdam.sunwoo@arm.com char fn[100]; 5628734Sdam.sunwoo@arm.com std::string filename; 5638734Sdam.sunwoo@arm.com CopyStringOut(tc, fn, filename_addr, 100); 5648734Sdam.sunwoo@arm.com filename = std::string(fn); 5658734Sdam.sunwoo@arm.com 5668734Sdam.sunwoo@arm.com if (offset == 0) { 5678734Sdam.sunwoo@arm.com // create a new file (truncate) 56811259Ssascha.bischoff@ARM.com os = simout.create(filename, true, true); 5698734Sdam.sunwoo@arm.com } else { 5708734Sdam.sunwoo@arm.com // do not truncate file if offset is non-zero 5718734Sdam.sunwoo@arm.com // (ios::in flag is required as well to keep the existing data 5728734Sdam.sunwoo@arm.com // intact, otherwise existing data will be zeroed out.) 5738734Sdam.sunwoo@arm.com os = simout.openFile(simout.directory() + filename, 57411259Ssascha.bischoff@ARM.com ios::in | ios::out | ios::binary, true); 5758734Sdam.sunwoo@arm.com } 5768734Sdam.sunwoo@arm.com if (!os) 5778734Sdam.sunwoo@arm.com panic("could not open file %s\n", filename); 5788734Sdam.sunwoo@arm.com 5798734Sdam.sunwoo@arm.com // seek to offset 5808734Sdam.sunwoo@arm.com os->seekp(offset); 5818734Sdam.sunwoo@arm.com 5828734Sdam.sunwoo@arm.com // copy out data and write to file 5838734Sdam.sunwoo@arm.com char *buf = new char[len]; 5848734Sdam.sunwoo@arm.com CopyOut(tc, buf, vaddr, len); 5858734Sdam.sunwoo@arm.com os->write(buf, len); 5868734Sdam.sunwoo@arm.com if (os->fail() || os->bad()) 5878734Sdam.sunwoo@arm.com panic("Error while doing writefile!\n"); 5888734Sdam.sunwoo@arm.com 5898734Sdam.sunwoo@arm.com simout.close(os); 5908734Sdam.sunwoo@arm.com 5918734Sdam.sunwoo@arm.com delete [] buf; 5928734Sdam.sunwoo@arm.com 5938734Sdam.sunwoo@arm.com return len; 5948734Sdam.sunwoo@arm.com} 5958734Sdam.sunwoo@arm.com 5965504Snate@binkert.orgvoid 5975504Snate@binkert.orgdebugbreak(ThreadContext *tc) 5985504Snate@binkert.org{ 5999733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::debugbreak()\n"); 6008231Snate@binkert.org Debug::breakpoint(); 6015504Snate@binkert.org} 6022235SN/A 6035504Snate@binkert.orgvoid 6045504Snate@binkert.orgswitchcpu(ThreadContext *tc) 6055504Snate@binkert.org{ 6069733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::switchcpu()\n"); 6075504Snate@binkert.org exitSimLoop("switchcpu"); 6085504Snate@binkert.org} 6093368Sstever@eecs.umich.edu 6107914SBrad.Beckmann@amd.com// 6117914SBrad.Beckmann@amd.com// This function is executed when annotated work items begin. Depending on 6127914SBrad.Beckmann@amd.com// what the user specified at the command line, the simulation may exit and/or 6137914SBrad.Beckmann@amd.com// take a checkpoint when a certain work item begins. 6147914SBrad.Beckmann@amd.com// 6157914SBrad.Beckmann@amd.comvoid 6167914SBrad.Beckmann@amd.comworkbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid) 6177914SBrad.Beckmann@amd.com{ 6189733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::workbegin(%i, %i)\n", workid, threadid); 6197914SBrad.Beckmann@amd.com tc->getCpuPtr()->workItemBegin(); 6207914SBrad.Beckmann@amd.com System *sys = tc->getSystemPtr(); 6218580Ssteve.reinhardt@amd.com const System::Params *params = sys->params(); 6228666SPrakash.Ramrakhyani@arm.com sys->workItemBegin(threadid, workid); 6237914SBrad.Beckmann@amd.com 6247914SBrad.Beckmann@amd.com DPRINTF(WorkItems, "Work Begin workid: %d, threadid %d\n", workid, 6257914SBrad.Beckmann@amd.com threadid); 6267914SBrad.Beckmann@amd.com 6277914SBrad.Beckmann@amd.com // 6287914SBrad.Beckmann@amd.com // If specified, determine if this is the specific work item the user 6297914SBrad.Beckmann@amd.com // identified 6307914SBrad.Beckmann@amd.com // 6318580Ssteve.reinhardt@amd.com if (params->work_item_id == -1 || params->work_item_id == workid) { 6327914SBrad.Beckmann@amd.com 6337914SBrad.Beckmann@amd.com uint64_t systemWorkBeginCount = sys->incWorkItemsBegin(); 6347914SBrad.Beckmann@amd.com int cpuId = tc->getCpuPtr()->cpuId(); 6357914SBrad.Beckmann@amd.com 6368580Ssteve.reinhardt@amd.com if (params->work_cpus_ckpt_count != 0 && 6378580Ssteve.reinhardt@amd.com sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 6387914SBrad.Beckmann@amd.com // 6397914SBrad.Beckmann@amd.com // If active cpus equals checkpoint count, create checkpoint 6407914SBrad.Beckmann@amd.com // 6418580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6427914SBrad.Beckmann@amd.com } 6437914SBrad.Beckmann@amd.com 6448580Ssteve.reinhardt@amd.com if (systemWorkBeginCount == params->work_begin_ckpt_count) { 6457914SBrad.Beckmann@amd.com // 6467914SBrad.Beckmann@amd.com // Note: the string specified as the cause of the exit event must 6477914SBrad.Beckmann@amd.com // exactly equal "checkpoint" inorder to create a checkpoint 6487914SBrad.Beckmann@amd.com // 6498580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6507914SBrad.Beckmann@amd.com } 6517914SBrad.Beckmann@amd.com 6528580Ssteve.reinhardt@amd.com if (systemWorkBeginCount == params->work_begin_exit_count) { 6537914SBrad.Beckmann@amd.com // 6547914SBrad.Beckmann@amd.com // If a certain number of work items started, exit simulation 6557914SBrad.Beckmann@amd.com // 6568580Ssteve.reinhardt@amd.com exitSimLoop("work started count reach"); 6577914SBrad.Beckmann@amd.com } 6587914SBrad.Beckmann@amd.com 6598580Ssteve.reinhardt@amd.com if (cpuId == params->work_begin_cpu_id_exit) { 6607914SBrad.Beckmann@amd.com // 6618580Ssteve.reinhardt@amd.com // If work started on the cpu id specified, exit simulation 6627914SBrad.Beckmann@amd.com // 6638580Ssteve.reinhardt@amd.com exitSimLoop("work started on specific cpu"); 6647914SBrad.Beckmann@amd.com } 6657914SBrad.Beckmann@amd.com } 6667914SBrad.Beckmann@amd.com} 6677914SBrad.Beckmann@amd.com 6687914SBrad.Beckmann@amd.com// 6697914SBrad.Beckmann@amd.com// This function is executed when annotated work items end. Depending on 6707914SBrad.Beckmann@amd.com// what the user specified at the command line, the simulation may exit and/or 6717914SBrad.Beckmann@amd.com// take a checkpoint when a certain work item ends. 6727914SBrad.Beckmann@amd.com// 6737914SBrad.Beckmann@amd.comvoid 6747914SBrad.Beckmann@amd.comworkend(ThreadContext *tc, uint64_t workid, uint64_t threadid) 6757914SBrad.Beckmann@amd.com{ 6769733Sandreas@sandberg.pp.se DPRINTF(PseudoInst, "PseudoInst::workend(%i, %i)\n", workid, threadid); 6777914SBrad.Beckmann@amd.com tc->getCpuPtr()->workItemEnd(); 6787914SBrad.Beckmann@amd.com System *sys = tc->getSystemPtr(); 6798580Ssteve.reinhardt@amd.com const System::Params *params = sys->params(); 6808666SPrakash.Ramrakhyani@arm.com sys->workItemEnd(threadid, workid); 6817914SBrad.Beckmann@amd.com 6827914SBrad.Beckmann@amd.com DPRINTF(WorkItems, "Work End workid: %d, threadid %d\n", workid, threadid); 6837914SBrad.Beckmann@amd.com 6847914SBrad.Beckmann@amd.com // 6857914SBrad.Beckmann@amd.com // If specified, determine if this is the specific work item the user 6867914SBrad.Beckmann@amd.com // identified 6877914SBrad.Beckmann@amd.com // 6888580Ssteve.reinhardt@amd.com if (params->work_item_id == -1 || params->work_item_id == workid) { 6897914SBrad.Beckmann@amd.com 6907914SBrad.Beckmann@amd.com uint64_t systemWorkEndCount = sys->incWorkItemsEnd(); 6917914SBrad.Beckmann@amd.com int cpuId = tc->getCpuPtr()->cpuId(); 6927914SBrad.Beckmann@amd.com 6938580Ssteve.reinhardt@amd.com if (params->work_cpus_ckpt_count != 0 && 6948580Ssteve.reinhardt@amd.com sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 6957914SBrad.Beckmann@amd.com // 6967914SBrad.Beckmann@amd.com // If active cpus equals checkpoint count, create checkpoint 6977914SBrad.Beckmann@amd.com // 6988580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 6997914SBrad.Beckmann@amd.com } 7007914SBrad.Beckmann@amd.com 7018580Ssteve.reinhardt@amd.com if (params->work_end_ckpt_count != 0 && 7028580Ssteve.reinhardt@amd.com systemWorkEndCount == params->work_end_ckpt_count) { 7037914SBrad.Beckmann@amd.com // 7047914SBrad.Beckmann@amd.com // If total work items completed equals checkpoint count, create 7057914SBrad.Beckmann@amd.com // checkpoint 7067914SBrad.Beckmann@amd.com // 7078580Ssteve.reinhardt@amd.com exitSimLoop("checkpoint"); 7087914SBrad.Beckmann@amd.com } 7097914SBrad.Beckmann@amd.com 7108580Ssteve.reinhardt@amd.com if (params->work_end_exit_count != 0 && 7118580Ssteve.reinhardt@amd.com systemWorkEndCount == params->work_end_exit_count) { 7127914SBrad.Beckmann@amd.com // 7137914SBrad.Beckmann@amd.com // If total work items completed equals exit count, exit simulation 7147914SBrad.Beckmann@amd.com // 7158580Ssteve.reinhardt@amd.com exitSimLoop("work items exit count reached"); 7167914SBrad.Beckmann@amd.com } 7177914SBrad.Beckmann@amd.com } 7187914SBrad.Beckmann@amd.com} 7197914SBrad.Beckmann@amd.com 7207811Ssteve.reinhardt@amd.com} // namespace PseudoInst 721