From 75001363923d0f64a8b1454890db575e7c7ca099 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 2 Mar 2023 09:25:17 -0800 Subject: [PATCH] mem: Add a parameter which will make a memory truly a ROM. This piggy-backs on the writeOK method which already exists. It also modifies the flags returned as part of the memory's backdoor descriptor which doesn't enforce that the memory is read only, but will let the other party know it's expected not to write to it. Change-Id: Ib95e619c76c327d302e62a88515a92af11815981 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/68557 Maintainer: Gabe Black Tested-by: kokoro Reviewed-by: Matthew Poremba --- src/mem/AbstractMemory.py | 2 ++ src/mem/abstract_mem.cc | 7 ++++--- src/mem/abstract_mem.hh | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/mem/AbstractMemory.py b/src/mem/AbstractMemory.py index ea88fd879c..7ab24bc118 100644 --- a/src/mem/AbstractMemory.py +++ b/src/mem/AbstractMemory.py @@ -74,3 +74,5 @@ class AbstractMemory(ClockedObject): image_file = Param.String( "", "Image to load into memory as its initial contents" ) + + writeable = Param.Bool(True, "Allow writes to this memory") diff --git a/src/mem/abstract_mem.cc b/src/mem/abstract_mem.cc index 03f2557d63..9340f7e96f 100644 --- a/src/mem/abstract_mem.cc +++ b/src/mem/abstract_mem.cc @@ -59,10 +59,11 @@ namespace memory AbstractMemory::AbstractMemory(const Params &p) : ClockedObject(p), range(p.range), pmemAddr(NULL), backdoor(params().range, nullptr, - (MemBackdoor::Flags)(MemBackdoor::Readable | - MemBackdoor::Writeable)), + (MemBackdoor::Flags)(p.writeable ? + MemBackdoor::Readable | MemBackdoor::Writeable : + MemBackdoor::Readable)), confTableReported(p.conf_table_reported), inAddrMap(p.in_addr_map), - kvmMap(p.kvm_map), _system(NULL), + kvmMap(p.kvm_map), writeable(p.writeable), _system(NULL), stats(*this) { panic_if(!range.valid() || !range.size(), diff --git a/src/mem/abstract_mem.hh b/src/mem/abstract_mem.hh index 53b794012d..7f12487421 100644 --- a/src/mem/abstract_mem.hh +++ b/src/mem/abstract_mem.hh @@ -129,6 +129,9 @@ class AbstractMemory : public ClockedObject // Should KVM map this memory for the guest const bool kvmMap; + // Are writes allowed to this memory + const bool writeable; + std::list lockedAddrList; // helper function for checkLockedAddrs(): we really want to @@ -149,8 +152,12 @@ class AbstractMemory : public ClockedObject // requesting execution context), 'true' otherwise. Note that // this method must be called on *all* stores since even // non-conditional stores must clear any matching lock addresses. - bool writeOK(PacketPtr pkt) { + bool + writeOK(PacketPtr pkt) + { const RequestPtr &req = pkt->req; + if (!writeable) + return false; if (lockedAddrList.empty()) { // no locked addrs: nothing to check, store_conditional fails bool isLLSC = pkt->isLLSC();