arch, base, sim: Replace Copy(String)?(In|Out) with equivalent code.

This expands those functions into code which extracts the virt proxy
and then uses the appropriate method on it. This has two benefits.
First, the Copy* functions where mostly redundant wrappers around the
methods the proxy port already had. Second, using them forced a
particular port which might not actually be what the user wanted.

Change-Id: I62084631dd080061e3c74997125164f40da2d77c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18575
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/arch/alpha/stacktrace.cc b/src/arch/alpha/stacktrace.cc
index dfe7474..f5833b0 100644
--- a/src/arch/alpha/stacktrace.cc
+++ b/src/arch/alpha/stacktrace.cc
@@ -111,7 +111,7 @@
         return "console";
 
     char comm[256];
-    CopyStringOut(tc, comm, task + name_off, sizeof(comm));
+    tc->getVirtProxy().readString(comm, task + name_off, sizeof(comm));
     if (!comm[0])
         return "startup";
 
@@ -311,8 +311,7 @@
     ra = 0;
 
     for (Addr pc = func; pc < callpc; pc += sizeof(MachInst)) {
-        MachInst inst;
-        CopyOut(tc, (uint8_t *)&inst, pc, sizeof(MachInst));
+        MachInst inst = tc->getVirtProxy().read<MachInst>(pc);
 
         int reg, disp;
         if (decodeStack(inst, disp)) {
@@ -323,7 +322,7 @@
             size += disp;
         } else if (decodeSave(inst, reg, disp)) {
             if (!ra && reg == ReturnAddressReg) {
-                CopyOut(tc, (uint8_t *)&ra, sp + disp, sizeof(Addr));
+                ra = tc->getVirtProxy().read<Addr>(sp + disp);
                 if (!ra) {
                     // panic("no return address value pc=%#x\n", pc);
                     return false;
diff --git a/src/arch/arm/stacktrace.cc b/src/arch/arm/stacktrace.cc
index b4dbf72..837b6ad 100644
--- a/src/arch/arm/stacktrace.cc
+++ b/src/arch/arm/stacktrace.cc
@@ -104,7 +104,7 @@
         return "unknown";
 
     char comm[256];
-    CopyStringOut(tc, comm, task + name_off, sizeof(comm));
+    tc->getVirtProxy().readString(comm, task + name_off, sizeof(comm));
     if (!comm[0])
         return "startup";
 
diff --git a/src/arch/generic/linux/threadinfo.hh b/src/arch/generic/linux/threadinfo.hh
index 1595da4..626de58 100644
--- a/src/arch/generic/linux/threadinfo.hh
+++ b/src/arch/generic/linux/threadinfo.hh
@@ -58,9 +58,7 @@
             return false;
         }
 
-        CopyOut(tc, &data, addr, sizeof(T));
-
-        data = TheISA::gtoh(data);
+        data = tc->getVirtProxy().read<T>(addr, TheISA::GuestByteOrder);
 
         return true;
     }
@@ -98,29 +96,23 @@
         // Note that in Linux 4.10 the thread_info struct will no longer have a
         // pointer to the task_struct for arm64. See:
         // https://patchwork.kernel.org/patch/9333699/
-        int32_t offset;
+        int32_t offset = 0;
         if (!get_data("thread_info_task", offset))
             return 0;
 
         if (!thread_info)
             thread_info = curThreadInfo();
 
-        Addr addr;
-        CopyOut(tc, &addr, thread_info + offset, sizeof(addr));
-
-        return addr;
+        return tc->getVirtProxy().read<Addr>(thread_info + offset);
     }
 
     int32_t
     curTaskPIDFromTaskStruct(Addr task_struct) {
-        int32_t offset;
+        int32_t offset = 0;
         if (!get_data("task_struct_pid", offset))
             return -1;
 
-        int32_t pid;
-        CopyOut(tc, &pid, task_struct + offset, sizeof(pid));
-
-        return pid;
+        return tc->getVirtProxy().read<int32_t>(task_struct + offset);
     }
 
     int32_t
@@ -132,14 +124,11 @@
     int32_t
     curTaskTGIDFromTaskStruct(Addr task_struct)
     {
-        int32_t offset;
+        int32_t offset = 0;
         if (!get_data("task_struct_tgid", offset))
             return -1;
 
-        int32_t tgid;
-        CopyOut(tc, &tgid, task_struct + offset, sizeof(tgid));
-
-        return tgid;
+        return tc->getVirtProxy().read<int32_t>(task_struct + offset);
     }
 
     int32_t
@@ -151,16 +140,13 @@
     int64_t
     curTaskStartFromTaskStruct(Addr task_struct)
     {
-        int32_t offset;
+        int32_t offset = 0;
         if (!get_data("task_struct_start_time", offset))
             return -1;
 
-        int64_t data;
         // start_time is actually of type timespec, but if we just
         // grab the first long, we'll get the seconds out of it
-        CopyOut(tc, &data, task_struct + offset, sizeof(data));
-
-        return data;
+        return tc->getVirtProxy().read<int64_t>(task_struct + offset);
     }
 
     int64_t
@@ -172,8 +158,8 @@
     std::string
     curTaskNameFromTaskStruct(Addr task_struct)
     {
-        int32_t offset;
-        int32_t size;
+        int32_t offset = 0;
+        int32_t size = 0;
 
         if (!get_data("task_struct_comm", offset))
             return "FailureIn_curTaskName";
@@ -182,7 +168,7 @@
             return "FailureIn_curTaskName";
 
         char buffer[size + 1];
-        CopyStringOut(tc, buffer, task_struct + offset, size);
+        tc->getVirtProxy().readString(buffer, task_struct + offset, size);
 
         return buffer;
     }
@@ -200,10 +186,7 @@
         if (!get_data("task_struct_mm", offset))
             return -1;
 
-        int32_t mm_ptr;
-        CopyOut(tc, &mm_ptr, task_struct + offset, sizeof(mm_ptr));
-
-        return mm_ptr;
+        return tc->getVirtProxy().read<int32_t>(task_struct + offset);
     }
 
     int32_t
diff --git a/src/arch/mips/stacktrace.cc b/src/arch/mips/stacktrace.cc
index da492f1..7517b9d 100644
--- a/src/arch/mips/stacktrace.cc
+++ b/src/arch/mips/stacktrace.cc
@@ -84,7 +84,7 @@
         return "console";
 
     char comm[256];
-    CopyStringOut(tc, comm, task + name_off, sizeof(comm));
+    tc->getVirtProxy().readString(comm, task + name_off, sizeof(comm));
     if (!comm[0])
         return "startup";
 
@@ -202,8 +202,7 @@
     ra = 0;
 
     for (Addr pc = func; pc < callpc; pc += sizeof(MachInst)) {
-        MachInst inst;
-        CopyOut(tc, (uint8_t *)&inst, pc, sizeof(MachInst));
+        MachInst inst = tc->getVirtProxy().read<MachInst>(pc);
 
         int reg, disp;
         if (decodeStack(inst, disp)) {
@@ -213,7 +212,7 @@
             size += disp;
         } else if (decodeSave(inst, reg, disp)) {
             if (!ra && reg == ReturnAddressReg) {
-                CopyOut(tc, (uint8_t *)&ra, sp + disp, sizeof(Addr));
+                ra = tc->getVirtProxy().read<Addr>(sp + disp);
                 if (!ra) {
                     return false;
                 }
diff --git a/src/arch/x86/stacktrace.cc b/src/arch/x86/stacktrace.cc
index 2d9eaea..b5fbb5c 100644
--- a/src/arch/x86/stacktrace.cc
+++ b/src/arch/x86/stacktrace.cc
@@ -104,7 +104,7 @@
         return "console";
 
     char comm[256];
-    CopyStringOut(tc, comm, task + name_off, sizeof(comm));
+    tc->getVirtProxy().readString(comm, task + name_off, sizeof(comm));
     if (!comm[0])
         return "startup";
 
@@ -164,8 +164,7 @@
     ra = 0;
 
     for (Addr pc = func; pc < callpc; pc += sizeof(MachInst)) {
-        MachInst inst;
-        CopyOut(tc, (uint8_t *)&inst, pc, sizeof(MachInst));
+        MachInst inst = tc->getVirtProxy().read<MachInst>(pc);
 
         int reg, disp;
         if (decodeStack(inst, disp)) {
@@ -176,7 +175,7 @@
             size += disp;
         } else if (decodeSave(inst, reg, disp)) {
             if (!ra && reg == ReturnAddressReg) {
-                CopyOut(tc, (uint8_t *)&ra, sp + disp, sizeof(Addr));
+                ra = tc->getVirtProxy().read<Addr>(sp + disp);
                 if (!ra) {
                     // panic("no return address value pc=%#x\n", pc);
                     return false;
diff --git a/src/base/cp_annotate.cc b/src/base/cp_annotate.cc
index 9209ffd..b387b99 100644
--- a/src/base/cp_annotate.cc
+++ b/src/base/cp_annotate.cc
@@ -170,7 +170,7 @@
         debugSymbolTable->findNearestSymbol(
             tc->readIntReg(ReturnAddressReg), st, junk);
 
-    CopyStringOut(tc, sm, args[0], 50);
+    tc->getVirtProxy().readString(sm, args[0], 50);
     System *sys = tc->getSystemPtr();
     StringWrap name(sys->name());
 
@@ -256,7 +256,7 @@
 
     Arguments args(tc);
     char sm[50];
-    CopyStringOut(tc, sm, args[0], 50);
+    tc->getVirtProxy().readString(sm, args[0], 50);
     System *sys = tc->getSystemPtr();
     doSwSmEnd(sys, tc->contextId(), sm, getFrame(tc));
 }
@@ -324,7 +324,7 @@
 
     Arguments args(tc);
     char st[50];
-    CopyStringOut(tc, st, args[1], 50);
+    tc->getVirtProxy().readString(st, args[1], 50);
 
     StringWrap name(tc->getSystemPtr()->name());
     DPRINTF(Annotate, "Explict begin of state %s\n", st);
@@ -428,7 +428,7 @@
     char q[50];
     Arguments args(tc);
     uint64_t id = args[0];
-    CopyStringOut(tc, q, args[1], 50);
+    tc->getVirtProxy().readString(q, args[1], 50);
     int32_t count = args[2];
     System *sys = tc->getSystemPtr();
 
@@ -459,7 +459,7 @@
     char q[50];
     Arguments args(tc);
     uint64_t id = args[0];
-    CopyStringOut(tc, q, args[1], 50);
+    tc->getVirtProxy().readString(q, args[1], 50);
     int32_t count = args[2];
     System *sys = tc->getSystemPtr();
 
@@ -488,7 +488,7 @@
     char q[50];
     Arguments args(tc);
     uint64_t id = args[0];
-    CopyStringOut(tc, q, args[1], 50);
+    tc->getVirtProxy().readString(q, args[1], 50);
     System *sys = tc->getSystemPtr();
     int32_t count = args[2];
 
@@ -523,7 +523,7 @@
     char q[50];
     Arguments args(tc);
     uint64_t id = args[0];
-    CopyStringOut(tc, q, args[1], 50);
+    tc->getVirtProxy().readString(q, args[1], 50);
     System *sys = tc->getSystemPtr();
     int32_t count = args[2];
 
@@ -554,7 +554,7 @@
     char q[50];
     Arguments args(tc);
     uint64_t id = args[0];
-    CopyStringOut(tc, q, args[1], 50);
+    tc->getVirtProxy().readString(q, args[1], 50);
     System *sys = tc->getSystemPtr();
     int32_t count = args[3];
 
@@ -568,7 +568,7 @@
 
     if (!!args[2]) {
         char sm[50];
-        CopyStringOut(tc, sm, args[2], 50);
+        tc->getVirtProxy().readString(sm, args[2], 50);
         doSwSmEnd(tc->getSystemPtr(), tc->contextId(), sm, getFrame(tc));
     }
 }
@@ -582,7 +582,7 @@
     char q[50];
     Arguments args(tc);
     uint64_t id = args[0];
-    CopyStringOut(tc, q, args[1], 50);
+    tc->getVirtProxy().readString(q, args[1], 50);
     System *sys = tc->getSystemPtr();
     int32_t count = args[3];
 
@@ -596,7 +596,7 @@
 
     if (!!args[2]) {
         char sm[50];
-        CopyStringOut(tc, sm, args[2], 50);
+        tc->getVirtProxy().readString(sm, args[2], 50);
         doSwSmEnd(tc->getSystemPtr(), tc->contextId(), sm, getFrame(tc));
     }
 }
@@ -610,7 +610,7 @@
     char q[50];
     Arguments args(tc);
     uint64_t id = args[0];
-    CopyStringOut(tc, q, args[1], 50);
+    tc->getVirtProxy().readString(q, args[1], 50);
     System *sys = tc->getSystemPtr();
     StringWrap name(sys->name());
     int32_t size = args[2];
@@ -678,7 +678,7 @@
     char q[50];
     Arguments args(tc);
     uint64_t id = args[0];
-    CopyStringOut(tc, q, args[1], 50);
+    tc->getVirtProxy().readString(q, args[1], 50);
     System *sys = tc->getSystemPtr();
     StringWrap name(sys->name());
     int32_t size = args[2];
@@ -714,7 +714,7 @@
 
     char lsm[50];
     Arguments args(tc);
-    CopyStringOut(tc, lsm, args[0], 50);
+    tc->getVirtProxy().readString(lsm, args[0], 50);
     System *sys = tc->getSystemPtr();
     StringWrap name(sys->name());
 
@@ -738,7 +738,7 @@
 
     if (!!args[2]) {
         char sm[50];
-        CopyStringOut(tc, sm, args[2], 50);
+        tc->getVirtProxy().readString(sm, args[2], 50);
         doSwSmEnd(tc->getSystemPtr(), tc->contextId(), sm, getFrame(tc));
     }
 }
@@ -789,7 +789,7 @@
 
     char lsm[50];
     Arguments args(tc);
-    CopyStringOut(tc, lsm, args[0], 50);
+    tc->getVirtProxy().readString(lsm, args[0], 50);
     System *sys = tc->getSystemPtr();
     StringWrap name(sys->name());
     int sysi = getSys(sys);
@@ -815,7 +815,7 @@
 
     if (!!args[1]) {
         char sm[50];
-        CopyStringOut(tc, sm, args[1], 50);
+        tc->getVirtProxy().readString(sm, args[1], 50);
         doSwSmEnd(tc->getSystemPtr(), tc->contextId(), sm, getFrame(tc));
     }
 }
diff --git a/src/sim/arguments.hh b/src/sim/arguments.hh
index 498527c..977e3ff 100644
--- a/src/sim/arguments.hh
+++ b/src/sim/arguments.hh
@@ -34,10 +34,9 @@
 #include <cassert>
 #include <memory>
 
+#include "cpu/thread_context.hh"
 #include "mem/fs_translating_port_proxy.hh"
 
-class ThreadContext;
-
 class Arguments
 {
   protected:
@@ -137,13 +136,13 @@
     template <class T>
     operator T *() {
         T *buf = (T *)data->alloc(sizeof(T));
-        CopyOut(tc, buf, getArg(sizeof(T)), sizeof(T));
+        tc->getVirtProxy().readBlob(getArg(sizeof(T)), buf, sizeof(T));
         return buf;
     }
 
     operator char *() {
         char *buf = data->alloc(2048);
-        CopyStringOut(tc, buf, getArg(), 2048);
+        tc->getVirtProxy().readString(buf, getArg(), 2048);
         return buf;
     }
 };
diff --git a/src/sim/pseudo_inst.cc b/src/sim/pseudo_inst.cc
index 8ffb13e..92886da 100644
--- a/src/sim/pseudo_inst.cc
+++ b/src/sim/pseudo_inst.cc
@@ -377,9 +377,8 @@
     if (!FullSystem)
         panicFsOnlyPseudoInst("addSymbol");
 
-    char symb[100];
-    CopyStringOut(tc, symb, symbolAddr, 100);
-    std::string symbol(symb);
+    std::string symbol;
+    tc->getVirtProxy().readString(symbol, symbolAddr);
 
     DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
 
@@ -525,7 +524,7 @@
     }
 
     close(fd);
-    CopyIn(tc, vaddr, buf, result);
+    tc->getVirtProxy().writeBlob(vaddr, buf, result);
     delete [] buf;
     return result;
 }
@@ -538,10 +537,8 @@
             vaddr, len, offset, filename_addr);
 
     // copy out target filename
-    char fn[100];
     std::string filename;
-    CopyStringOut(tc, fn, filename_addr, 100);
-    filename = std::string(fn);
+    tc->getVirtProxy().readString(filename, filename_addr);
 
     OutputStream *out;
     if (offset == 0) {
@@ -563,7 +560,7 @@
 
     // copy out data and write to file
     char *buf = new char[len];
-    CopyOut(tc, buf, vaddr, len);
+    tc->getVirtProxy().readBlob(vaddr, buf, len);
     os->write(buf, len);
     if (os->fail() || os->bad())
         panic("Error while doing writefile!\n");