From 096598c05a6c352bfd4b93adf06143a43a8f4e11 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 1 May 2019 21:43:09 -0700 Subject: [PATCH] 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 Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/arch/alpha/stacktrace.cc | 7 ++--- src/arch/arm/stacktrace.cc | 2 +- src/arch/generic/linux/threadinfo.hh | 43 +++++++++------------------- src/arch/mips/stacktrace.cc | 7 ++--- src/arch/x86/stacktrace.cc | 7 ++--- src/base/cp_annotate.cc | 34 +++++++++++----------- src/sim/arguments.hh | 7 ++--- src/sim/pseudo_inst.cc | 13 ++++----- 8 files changed, 48 insertions(+), 72 deletions(-) diff --git a/src/arch/alpha/stacktrace.cc b/src/arch/alpha/stacktrace.cc index dfe74742e..f5833b070 100644 --- a/src/arch/alpha/stacktrace.cc +++ b/src/arch/alpha/stacktrace.cc @@ -111,7 +111,7 @@ ProcessInfo::name(Addr ksp) const 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 @@ StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, int &size, 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(pc); int reg, disp; if (decodeStack(inst, disp)) { @@ -323,7 +322,7 @@ StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, int &size, 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(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 b4dbf728b..837b6ad8b 100644 --- a/src/arch/arm/stacktrace.cc +++ b/src/arch/arm/stacktrace.cc @@ -104,7 +104,7 @@ ProcessInfo::name(Addr ksp) const 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 1595da499..626de58e8 100644 --- a/src/arch/generic/linux/threadinfo.hh +++ b/src/arch/generic/linux/threadinfo.hh @@ -58,9 +58,7 @@ class ThreadInfo return false; } - CopyOut(tc, &data, addr, sizeof(T)); - - data = TheISA::gtoh(data); + data = tc->getVirtProxy().read(addr, TheISA::GuestByteOrder); return true; } @@ -98,29 +96,23 @@ class ThreadInfo // 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(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(task_struct + offset); } int32_t @@ -132,14 +124,11 @@ class ThreadInfo 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(task_struct + offset); } int32_t @@ -151,16 +140,13 @@ class ThreadInfo 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(task_struct + offset); } int64_t @@ -172,8 +158,8 @@ class ThreadInfo 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 @@ class ThreadInfo 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 @@ class ThreadInfo 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(task_struct + offset); } int32_t diff --git a/src/arch/mips/stacktrace.cc b/src/arch/mips/stacktrace.cc index da492f12f..7517b9d0b 100644 --- a/src/arch/mips/stacktrace.cc +++ b/src/arch/mips/stacktrace.cc @@ -84,7 +84,7 @@ ProcessInfo::name(Addr ksp) const 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 @@ StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, 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(pc); int reg, disp; if (decodeStack(inst, disp)) { @@ -213,7 +212,7 @@ StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, 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(sp + disp); if (!ra) { return false; } diff --git a/src/arch/x86/stacktrace.cc b/src/arch/x86/stacktrace.cc index 2d9eaea73..b5fbb5ce5 100644 --- a/src/arch/x86/stacktrace.cc +++ b/src/arch/x86/stacktrace.cc @@ -104,7 +104,7 @@ ProcessInfo::name(Addr ksp) const 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 @@ StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, 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(pc); int reg, disp; if (decodeStack(inst, disp)) { @@ -176,7 +175,7 @@ StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, 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(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 9209ffdd3..b387b99ca 100644 --- a/src/base/cp_annotate.cc +++ b/src/base/cp_annotate.cc @@ -170,7 +170,7 @@ CPA::swSmBegin(ThreadContext *tc) 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 @@ CPA::swSmEnd(ThreadContext *tc) 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 @@ CPA::swExplictBegin(ThreadContext *tc) 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 @@ CPA::swQ(ThreadContext *tc) 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 @@ CPA::swDq(ThreadContext *tc) 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 @@ CPA::swPq(ThreadContext *tc) 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 @@ CPA::swRq(ThreadContext *tc) 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 @@ CPA::swWf(ThreadContext *tc) 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 @@ CPA::swWf(ThreadContext *tc) 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 @@ CPA::swWe(ThreadContext *tc) 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 @@ CPA::swWe(ThreadContext *tc) 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 @@ CPA::swSq(ThreadContext *tc) 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 @@ CPA::swAq(ThreadContext *tc) 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 @@ CPA::swLink(ThreadContext *tc) 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 @@ CPA::swLink(ThreadContext *tc) 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 @@ CPA::swSyscallLink(ThreadContext *tc) 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 @@ CPA::swSyscallLink(ThreadContext *tc) 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 498527ca2..977e3ffc0 100644 --- a/src/sim/arguments.hh +++ b/src/sim/arguments.hh @@ -34,10 +34,9 @@ #include #include +#include "cpu/thread_context.hh" #include "mem/fs_translating_port_proxy.hh" -class ThreadContext; - class Arguments { protected: @@ -137,13 +136,13 @@ class Arguments template 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 8ffb13e3b..92886dacb 100644 --- a/src/sim/pseudo_inst.cc +++ b/src/sim/pseudo_inst.cc @@ -377,9 +377,8 @@ addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 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 @@ readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) } close(fd); - CopyIn(tc, vaddr, buf, result); + tc->getVirtProxy().writeBlob(vaddr, buf, result); delete [] buf; return result; } @@ -538,10 +537,8 @@ writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, 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 @@ writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, // 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"); -- 2.30.2