arch-power: Fix disassembly for compare instructions
[gem5.git] / src / sim / pseudo_inst.cc
index b11a5a4436457518e211d56a62fcbd0148fe076a..9b51b9fc06fc7e1eef6b0bdc05c725a9c79e5dc8 100644 (file)
 #include "base/output.hh"
 #include "config/the_isa.hh"
 #include "cpu/base.hh"
-#include "cpu/quiesce_event.hh"
 #include "cpu/thread_context.hh"
 #include "debug/Loader.hh"
 #include "debug/Quiesce.hh"
 #include "debug/WorkItems.hh"
 #include "dev/net/dist_iface.hh"
-#include "kern/kernel_stats.hh"
 #include "params/BaseCPU.hh"
-#include "sim/full_system.hh"
 #include "sim/process.hh"
 #include "sim/serialize.hh"
 #include "sim/sim_events.hh"
@@ -71,9 +68,7 @@
 #include "sim/stat_control.hh"
 #include "sim/stats.hh"
 #include "sim/system.hh"
-#include "sim/vptr.hh"
 
-using namespace std;
 using namespace Stats;
 
 namespace PseudoInst
@@ -103,21 +98,14 @@ const std::string DIST_SIZE = "dist-size";
 
 } // namespace InitParamKey
 
-static inline void
-panicFsOnlyPseudoInst(const char *name)
-{
-    panic("Pseudo inst \"%s\" is only available in Full System mode.");
-}
-
 void
 arm(ThreadContext *tc)
 {
     DPRINTF(PseudoInst, "PseudoInst::arm()\n");
-    if (!FullSystem)
-        panicFsOnlyPseudoInst("arm");
 
-    if (tc->getKernelStats())
-        tc->getKernelStats()->arm();
+    auto *workload = tc->getSystemPtr()->workload;
+    if (workload)
+        workload->recordArm();
 }
 
 void
@@ -170,13 +158,13 @@ wakeCPU(ThreadContext *tc, uint64_t cpuid)
     DPRINTF(PseudoInst, "PseudoInst::wakeCPU(%i)\n", cpuid);
     System *sys = tc->getSystemPtr();
 
-    if (sys->numContexts() <= cpuid) {
+    if (sys->threads.size() <= cpuid) {
         warn("PseudoInst::wakeCPU(%i), cpuid greater than number of contexts"
-             "(%i)\n",cpuid, sys->numContexts());
+             "(%i)\n", cpuid, sys->threads.size());
         return;
     }
 
-    ThreadContext *other_tc = sys->threadContexts[cpuid];
+    ThreadContext *other_tc = sys->threads[cpuid];
     if (other_tc->status() == ThreadContext::Suspended)
         other_tc->activate();
 }
@@ -191,6 +179,16 @@ m5exit(ThreadContext *tc, Tick delay)
     }
 }
 
+// m5sum is for sanity checking the gem5 op interface.
+uint64_t
+m5sum(ThreadContext *tc, uint64_t a, uint64_t b, uint64_t c,
+                         uint64_t d, uint64_t e, uint64_t f)
+{
+    DPRINTF(PseudoInst, "PseudoInst::m5sum(%#x, %#x, %#x, %#x, %#x, %#x)\n",
+            a, b, c, d, e, f);
+    return a + b + c + d + e + f;
+}
+
 void
 m5fail(ThreadContext *tc, Tick delay, uint64_t code)
 {
@@ -203,16 +201,14 @@ void
 loadsymbol(ThreadContext *tc)
 {
     DPRINTF(PseudoInst, "PseudoInst::loadsymbol()\n");
-    if (!FullSystem)
-        panicFsOnlyPseudoInst("loadsymbol");
 
-    const string &filename = tc->getCpuPtr()->system->params()->symbolfile;
+    const std::string &filename = tc->getCpuPtr()->system->params().symbolfile;
     if (filename.empty()) {
         return;
     }
 
     std::string buffer;
-    ifstream file(filename.c_str());
+    std::ifstream file(filename.c_str());
 
     if (!file)
         fatal("file error: Can't open symbol table file %s\n", filename);
@@ -223,17 +219,17 @@ loadsymbol(ThreadContext *tc)
         if (buffer.empty())
             continue;
 
-        string::size_type idx = buffer.find(' ');
-        if (idx == string::npos)
+        std::string::size_type idx = buffer.find(' ');
+        if (idx == std::string::npos)
             continue;
 
-        string address = "0x" + buffer.substr(0, idx);
+        std::string address = "0x" + buffer.substr(0, idx);
         eat_white(address);
         if (address.empty())
             continue;
 
         // Skip over letter and space
-        string symbol = buffer.substr(idx + 3);
+        std::string symbol = buffer.substr(idx + 3);
         eat_white(symbol);
         if (symbol.empty())
             continue;
@@ -242,8 +238,10 @@ loadsymbol(ThreadContext *tc)
         if (!to_number(address, addr))
             continue;
 
-        if (!tc->getSystemPtr()->workload->insertSymbol(addr, symbol))
+        if (!tc->getSystemPtr()->workload->insertSymbol(
+                    { Loader::Symbol::Binding::Global, symbol, addr })) {
             continue;
+        }
 
 
         DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
@@ -256,16 +254,16 @@ addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr)
 {
     DPRINTF(PseudoInst, "PseudoInst::addsymbol(0x%x, 0x%x)\n",
             addr, symbolAddr);
-    if (!FullSystem)
-        panicFsOnlyPseudoInst("addSymbol");
 
     std::string symbol;
     tc->getVirtProxy().readString(symbol, symbolAddr);
 
     DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
 
-    tc->getSystemPtr()->workload->insertSymbol(addr, symbol);
-    Loader::debugSymbolTable->insert(addr, symbol);
+    tc->getSystemPtr()->workload->insertSymbol(
+            { Loader::Symbol::Binding::Global, symbol, addr });
+    Loader::debugSymbolTable.insert(
+            { Loader::Symbol::Binding::Global, symbol, addr });
 }
 
 uint64_t
@@ -273,21 +271,17 @@ initParam(ThreadContext *tc, uint64_t key_str1, uint64_t key_str2)
 {
     DPRINTF(PseudoInst, "PseudoInst::initParam() key:%s%s\n", (char *)&key_str1,
             (char *)&key_str2);
-    if (!FullSystem) {
-        panicFsOnlyPseudoInst("initParam");
-        return 0;
-    }
 
     // The key parameter string is passed in via two 64-bit registers. We copy
     // out the characters from the 64-bit integer variables here, and
     // concatenate them in the key character buffer
     const int len = 2 * sizeof(uint64_t) + 1;
     char key[len];
-    memset(key, '\0', len);
+    std::memset(key, '\0', len);
 
-    std::array<uint64_t, 2> key_regs = { key_str1, key_str2 };
+    std::array<uint64_t, 2> key_regs = {{ key_str1, key_str2 }};
     key_regs = letoh(key_regs);
-    memcpy(key, key_regs.data(), sizeof(key_regs));
+    std::memcpy(key, key_regs.data(), sizeof(key_regs));
 
     // Check key parameter to figure out what to return.
     const std::string key_str(key);
@@ -306,7 +300,7 @@ void
 resetstats(ThreadContext *tc, Tick delay, Tick period)
 {
     DPRINTF(PseudoInst, "PseudoInst::resetstats(%i, %i)\n", delay, period);
-    if (!tc->getCpuPtr()->params()->do_statistics_insts)
+    if (!tc->getCpuPtr()->params().do_statistics_insts)
         return;
 
 
@@ -320,7 +314,7 @@ void
 dumpstats(ThreadContext *tc, Tick delay, Tick period)
 {
     DPRINTF(PseudoInst, "PseudoInst::dumpstats(%i, %i)\n", delay, period);
-    if (!tc->getCpuPtr()->params()->do_statistics_insts)
+    if (!tc->getCpuPtr()->params().do_statistics_insts)
         return;
 
 
@@ -334,7 +328,7 @@ void
 dumpresetstats(ThreadContext *tc, Tick delay, Tick period)
 {
     DPRINTF(PseudoInst, "PseudoInst::dumpresetstats(%i, %i)\n", delay, period);
-    if (!tc->getCpuPtr()->params()->do_statistics_insts)
+    if (!tc->getCpuPtr()->params().do_statistics_insts)
         return;
 
 
@@ -348,7 +342,7 @@ void
 m5checkpoint(ThreadContext *tc, Tick delay, Tick period)
 {
     DPRINTF(PseudoInst, "PseudoInst::m5checkpoint(%i, %i)\n", delay, period);
-    if (!tc->getCpuPtr()->params()->do_checkpoint_insts)
+    if (!tc->getCpuPtr()->params().do_checkpoint_insts)
         return;
 
     if (DistIface::readyToCkpt(delay, period)) {
@@ -363,12 +357,8 @@ readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset)
 {
     DPRINTF(PseudoInst, "PseudoInst::readfile(0x%x, 0x%x, 0x%x)\n",
             vaddr, len, offset);
-    if (!FullSystem) {
-        panicFsOnlyPseudoInst("readfile");
-        return 0;
-    }
 
-    const string &file = tc->getSystemPtr()->params()->readfile;
+    const std::string &file = tc->getSystemPtr()->params().readfile;
     if (file.empty()) {
         return ULL(0);
     }
@@ -419,10 +409,11 @@ writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset,
         // do not truncate file if offset is non-zero
         // (ios::in flag is required as well to keep the existing data
         //  intact, otherwise existing data will be zeroed out.)
-        out = simout.open(filename, ios::in | ios::out | ios::binary, true);
+        out = simout.open(filename,
+                std::ios::in | std::ios::out | std::ios::binary, true);
     }
 
-    ostream *os(out->stream());
+    std::ostream *os(out->stream());
     if (!os)
         panic("could not open file %s\n", filename);
 
@@ -459,23 +450,18 @@ switchcpu(ThreadContext *tc)
     exitSimLoop("switchcpu");
 }
 
-/*
- * This function is executed when the simulation is executing the syscall
- * handler in System Emulation mode.
- */
 void
-m5Syscall(ThreadContext *tc)
+togglesync(ThreadContext *tc)
 {
-    DPRINTF(PseudoInst, "PseudoInst::m5Syscall()\n");
-    Fault fault;
-    tc->syscall(&fault);
+    DPRINTF(PseudoInst, "PseudoInst::togglesync()\n");
+    DistIface::toggleSync(tc);
 }
 
 void
-togglesync(ThreadContext *tc)
+triggerWorkloadEvent(ThreadContext *tc)
 {
-    DPRINTF(PseudoInst, "PseudoInst::togglesync()\n");
-    DistIface::toggleSync(tc);
+    DPRINTF(PseudoInst, "PseudoInst::triggerWorkloadEvent()\n");
+    tc->getSystemPtr()->workload->event(tc);
 }
 
 //
@@ -488,9 +474,9 @@ workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid)
 {
     DPRINTF(PseudoInst, "PseudoInst::workbegin(%i, %i)\n", workid, threadid);
     System *sys = tc->getSystemPtr();
-    const System::Params *params = sys->params();
+    const System::Params &params = sys->params();
 
-    if (params->exit_on_work_items) {
+    if (params.exit_on_work_items) {
         exitSimLoop("workbegin", static_cast<int>(workid));
         return;
     }
@@ -504,20 +490,20 @@ workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid)
     // If specified, determine if this is the specific work item the user
     // identified
     //
-    if (params->work_item_id == -1 || params->work_item_id == workid) {
+    if (params.work_item_id == -1 || params.work_item_id == workid) {
 
         uint64_t systemWorkBeginCount = sys->incWorkItemsBegin();
         int cpuId = tc->getCpuPtr()->cpuId();
 
-        if (params->work_cpus_ckpt_count != 0 &&
-            sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) {
+        if (params.work_cpus_ckpt_count != 0 &&
+            sys->markWorkItem(cpuId) >= params.work_cpus_ckpt_count) {
             //
             // If active cpus equals checkpoint count, create checkpoint
             //
             exitSimLoop("checkpoint");
         }
 
-        if (systemWorkBeginCount == params->work_begin_ckpt_count) {
+        if (systemWorkBeginCount == params.work_begin_ckpt_count) {
             //
             // Note: the string specified as the cause of the exit event must
             // exactly equal "checkpoint" inorder to create a checkpoint
@@ -525,14 +511,14 @@ workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid)
             exitSimLoop("checkpoint");
         }
 
-        if (systemWorkBeginCount == params->work_begin_exit_count) {
+        if (systemWorkBeginCount == params.work_begin_exit_count) {
             //
             // If a certain number of work items started, exit simulation
             //
             exitSimLoop("work started count reach");
         }
 
-        if (cpuId == params->work_begin_cpu_id_exit) {
+        if (cpuId == params.work_begin_cpu_id_exit) {
             //
             // If work started on the cpu id specified, exit simulation
             //
@@ -551,9 +537,9 @@ workend(ThreadContext *tc, uint64_t workid, uint64_t threadid)
 {
     DPRINTF(PseudoInst, "PseudoInst::workend(%i, %i)\n", workid, threadid);
     System *sys = tc->getSystemPtr();
-    const System::Params *params = sys->params();
+    const System::Params &params = sys->params();
 
-    if (params->exit_on_work_items) {
+    if (params.exit_on_work_items) {
         exitSimLoop("workend", static_cast<int>(workid));
         return;
     }
@@ -566,21 +552,21 @@ workend(ThreadContext *tc, uint64_t workid, uint64_t threadid)
     // If specified, determine if this is the specific work item the user
     // identified
     //
-    if (params->work_item_id == -1 || params->work_item_id == workid) {
+    if (params.work_item_id == -1 || params.work_item_id == workid) {
 
         uint64_t systemWorkEndCount = sys->incWorkItemsEnd();
         int cpuId = tc->getCpuPtr()->cpuId();
 
-        if (params->work_cpus_ckpt_count != 0 &&
-            sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) {
+        if (params.work_cpus_ckpt_count != 0 &&
+            sys->markWorkItem(cpuId) >= params.work_cpus_ckpt_count) {
             //
             // If active cpus equals checkpoint count, create checkpoint
             //
             exitSimLoop("checkpoint");
         }
 
-        if (params->work_end_ckpt_count != 0 &&
-            systemWorkEndCount == params->work_end_ckpt_count) {
+        if (params.work_end_ckpt_count != 0 &&
+            systemWorkEndCount == params.work_end_ckpt_count) {
             //
             // If total work items completed equals checkpoint count, create
             // checkpoint
@@ -588,8 +574,8 @@ workend(ThreadContext *tc, uint64_t workid, uint64_t threadid)
             exitSimLoop("checkpoint");
         }
 
-        if (params->work_end_exit_count != 0 &&
-            systemWorkEndCount == params->work_end_exit_count) {
+        if (params.work_end_exit_count != 0 &&
+            systemWorkEndCount == params.work_end_exit_count) {
             //
             // If total work items completed equals exit count, exit simulation
             //