fastmodel: Use current execution state for memory lookup

The previous implementation used the physical memory view when reporting
memory back to GDB. This circumvents MMUs and caches, and leads to wrong
backtraces at the least.

Current architectures support EL3, EL2, and EL1/EL0, and the Iris
interface presents a Msn that corresponds to that (`0x10ff`), see
table "Canonical memory space numbers" in the Iris user guide.

As GDB expects the view of the processor when querying memory (e.g. for
backtraces), this will allow proper backtraces.

Not sure if there is an implicit way of expressing memory attributes
(like in Lauterbach with the access modifiers before address
specifications), or if there is a need to implement special monitor
commands. But for the common use, using `CurrentMsn` should be the
correct choice.

Change-Id: Ibd14c1f94163105539a7fb9132550fe713b5c295
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/61951
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Philip Metzler
2022-07-28 13:52:58 -07:00
committed by Earl Ou
parent 1dd30723c4
commit 50c8d9655e
7 changed files with 154 additions and 9 deletions

View File

@@ -437,3 +437,4 @@ SimObject('FastModel.py', sim_objects=[
'AmbaToTlmBridge64', 'AmbaFromTlmBridge64'], tags='arm fastmodel')
Source('amba_to_tlm_bridge.cc', tags='arm fastmodel')
Source('amba_from_tlm_bridge.cc', tags='arm fastmodel')
Source('remote_gdb.cc', tags='arm fastmodel')

View File

@@ -533,6 +533,19 @@ ThreadContext::sendFunctional(PacketPtr pkt)
writeMem(id, addr, data, size);
}
void
ThreadContext::readMemWithCurrentMsn(Addr vaddr, size_t size, char *data)
{
readMem(getMemorySpaceId(Iris::CurrentMsn), vaddr, data, size);
}
void
ThreadContext::writeMemWithCurrentMsn(Addr vaddr, size_t size,
const char *data)
{
writeMem(getMemorySpaceId(Iris::CurrentMsn), vaddr, data, size);
}
ThreadContext::Status
ThreadContext::status() const
{

View File

@@ -461,6 +461,8 @@ class ThreadContext : public gem5::ThreadContext
{
panic("%s not implemented.", __FUNCTION__);
}
void readMemWithCurrentMsn(Addr vaddr, size_t size, char *data);
void writeMemWithCurrentMsn(Addr vaddr, size_t size, const char *data);
};
} // namespace Iris

View File

@@ -0,0 +1,61 @@
/* * Copyright 2022 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "arch/arm/fastmodel/remote_gdb.hh"
#include "arch/arm/fastmodel/iris/thread_context.hh"
namespace gem5 {
namespace fastmodel {
FastmodelRemoteGDB::FastmodelRemoteGDB(System *_system, int port)
: gem5::ArmISA::RemoteGDB(_system, port)
{
}
bool
FastmodelRemoteGDB::readBlob(Addr vaddr, size_t size, char *data)
{
auto tc = dynamic_cast<Iris::ThreadContext *>(context());
panic_if(!tc,
"FastmodelRemoteGdb can only work on Iris::ThreadContext");
tc->readMemWithCurrentMsn(vaddr, size, data);
return true;
}
bool
FastmodelRemoteGDB::writeBlob(Addr vaddr, size_t size, const char *data)
{
auto tc = dynamic_cast<Iris::ThreadContext *>(context());
panic_if(!tc,
"FastmodelRemoteGdb can only work on Iris::ThreadContext");
tc->writeMemWithCurrentMsn(vaddr, size, data);
return true;
}
} // namespace fastmodel
} // namespace gem5

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2022 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ARCH_ARM_FASTMODEL_REMOTE_GDB_HH__
#define __ARCH_ARM_FASTMODEL_REMOTE_GDB_HH__
#include "arch/arm/remote_gdb.hh"
namespace gem5
{
namespace fastmodel
{
class FastmodelRemoteGDB : public gem5::ArmISA::RemoteGDB
{
public:
FastmodelRemoteGDB(System *_system, int port);
private:
bool readBlob(Addr vaddr, size_t size, char *data) override;
bool writeBlob(Addr vaddr, size_t size, const char *data) override;
};
} // namespace fastmodel
} // namespace gem5
#endif // __ARCH_ARM_FASTMODEL_FASTMODEL_REMOTE_GDB_HH__

View File

@@ -720,14 +720,32 @@ BaseRemoteGDB::processCommands(int signum)
}
}
bool
BaseRemoteGDB::readBlob(Addr vaddr, size_t size, char *data)
{
(FullSystem ? TranslatingPortProxy(tc) : SETranslatingPortProxy(tc))
.readBlob(vaddr, data, size);
return true;
}
bool
BaseRemoteGDB::writeBlob(Addr vaddr, size_t size, const char *data)
{
(FullSystem ? TranslatingPortProxy(tc) : SETranslatingPortProxy(tc))
.writeBlob(vaddr, data, size);
return true;
}
// Read bytes from kernel address space for debugger.
bool
BaseRemoteGDB::read(Addr vaddr, size_t size, char *data)
{
DPRINTF(GDBRead, "read: addr=%#x, size=%d", vaddr, size);
(FullSystem ? TranslatingPortProxy(tc) : SETranslatingPortProxy(tc)).
readBlob(vaddr, data, size);
bool res = readBlob(vaddr, size, data);
if (!res)
return false;
#if TRACING_ON
if (debug::GDBRead) {
@@ -756,10 +774,7 @@ BaseRemoteGDB::write(Addr vaddr, size_t size, const char *data)
} else
DPRINTFNR("\n");
}
(FullSystem ? TranslatingPortProxy(tc) : SETranslatingPortProxy(tc)).
writeBlob(vaddr, data, size);
return true;
return writeBlob(vaddr, size, data);
}
void

View File

@@ -293,9 +293,10 @@ class BaseRemoteGDB
/*
* The interface to the simulated system.
*/
// Machine memory.
bool read(Addr addr, size_t size, char *data);
bool write(Addr addr, size_t size, const char *data);
virtual bool readBlob(Addr vaddr, size_t size, char *data);
virtual bool writeBlob(Addr vaddr, size_t size, const char *data);
bool read(Addr vaddr, size_t size, char *data);
bool write(Addr vaddr, size_t size, const char *data);
template <class T> T read(Addr addr);
template <class T> void write(Addr addr, T data);