From: Gabe Black Date: Thu, 2 May 2019 02:03:28 +0000 (-0700) Subject: mem, arm: Move some helper methods into the base PortProxy class. X-Git-Tag: v19.0.0.0~811 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6a69fc18e743006db013797531d9ebcdb352a88d;p=gem5.git mem, arm: Move some helper methods into the base PortProxy class. These were originally in the SETranslatingPortProxy class, but they're not specific to SE mode in any way and are an unnecessary divergence between the SE and FS mode translating port proxies. Change-Id: I8cb77531cc287bd15b2386410ffa7b43cdfa67d0 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18570 Tested-by: kokoro Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power --- diff --git a/src/mem/fs_translating_port_proxy.cc b/src/mem/fs_translating_port_proxy.cc index 15ad8238c..a21d3283a 100644 --- a/src/mem/fs_translating_port_proxy.cc +++ b/src/mem/fs_translating_port_proxy.cc @@ -66,12 +66,8 @@ FSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port, { } -FSTranslatingPortProxy::~FSTranslatingPortProxy() -{ -} - -void -FSTranslatingPortProxy::readBlob(Addr addr, uint8_t *p, int size) const +bool +FSTranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const { Addr paddr; for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); @@ -85,10 +81,12 @@ FSTranslatingPortProxy::readBlob(Addr addr, uint8_t *p, int size) const PortProxy::readBlobPhys(paddr, 0, p, gen.size()); p += gen.size(); } + return true; } -void -FSTranslatingPortProxy::writeBlob(Addr addr, const uint8_t *p, int size) const +bool +FSTranslatingPortProxy::tryWriteBlob( + Addr addr, const uint8_t *p, int size) const { Addr paddr; for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); @@ -102,10 +100,11 @@ FSTranslatingPortProxy::writeBlob(Addr addr, const uint8_t *p, int size) const PortProxy::writeBlobPhys(paddr, 0, p, gen.size()); p += gen.size(); } + return true; } -void -FSTranslatingPortProxy::memsetBlob(Addr address, uint8_t v, int size) const +bool +FSTranslatingPortProxy::tryMemsetBlob(Addr address, uint8_t v, int size) const { Addr paddr; for (ChunkGenerator gen(address, size, TheISA::PageBytes); !gen.done(); @@ -118,6 +117,7 @@ FSTranslatingPortProxy::memsetBlob(Addr address, uint8_t v, int size) const PortProxy::memsetBlobPhys(paddr, 0, v, gen.size()); } + return true; } void diff --git a/src/mem/fs_translating_port_proxy.hh b/src/mem/fs_translating_port_proxy.hh index d4b4eb590..5ae87001c 100644 --- a/src/mem/fs_translating_port_proxy.hh +++ b/src/mem/fs_translating_port_proxy.hh @@ -81,20 +81,20 @@ class FSTranslatingPortProxy : public PortProxy FSTranslatingPortProxy(MasterPort &port, unsigned int cacheLineSize); - ~FSTranslatingPortProxy(); + ~FSTranslatingPortProxy() {} - /** Version of readblob that translates virt->phys and deals + /** Version of tryReadblob that translates virt->phys and deals * with page boundries. */ - void readBlob(Addr addr, uint8_t *p, int size) const override; + bool tryReadBlob(Addr addr, uint8_t *p, int size) const override; - /** Version of writeBlob that translates virt->phys and deals + /** Version of tryWriteBlob that translates virt->phys and deals * with page boundries. */ - void writeBlob(Addr addr, const uint8_t *p, int size) const override; + bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override; /** * Fill size bytes starting at addr with byte value val. */ - void memsetBlob(Addr address, uint8_t v, int size) const override; + bool tryMemsetBlob(Addr address, uint8_t v, int size) const override; }; void CopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen); diff --git a/src/mem/port_proxy.cc b/src/mem/port_proxy.cc index f13bcbe44..97eb67eff 100644 --- a/src/mem/port_proxy.cc +++ b/src/mem/port_proxy.cc @@ -87,3 +87,26 @@ PortProxy::memsetBlobPhys(Addr addr, Request::Flags flags, delete [] buf; } + +bool +PortProxy::tryWriteString(Addr addr, const char *str) const +{ + do { + if (!tryWriteBlob(addr++, (uint8_t *)str, 1)) + return false; + } while (*str++); + return true; +} + +bool +PortProxy::tryReadString(std::string &str, Addr addr) const +{ + while (true) { + uint8_t c; + if (!tryReadBlob(addr++, &c, 1)) + return false; + if (!c) + return true; + str += c; + } +} diff --git a/src/mem/port_proxy.hh b/src/mem/port_proxy.hh index bed448d8f..dcc1905a5 100644 --- a/src/mem/port_proxy.hh +++ b/src/mem/port_proxy.hh @@ -92,50 +92,98 @@ class PortProxy {} virtual ~PortProxy() { } + + + /** Fixed functionality for use in base classes. */ + + /** + * Read size bytes memory at physical address and store in p. + */ + void readBlobPhys(Addr addr, Request::Flags flags, + uint8_t* p, int size) const; + + /** + * Write size bytes from p to physical address. + */ + void writeBlobPhys(Addr addr, Request::Flags flags, + const uint8_t* p, int size) const; + + /** + * Fill size bytes starting at physical addr with byte value val. + */ + void memsetBlobPhys(Addr addr, Request::Flags flags, + uint8_t v, int size) const; + + + + /** Methods to override in base classes */ + /** * Read size bytes memory at address and store in p. + * Returns true on success and false on failure. */ - virtual void - readBlob(Addr addr, uint8_t* p, int size) const + virtual bool + tryReadBlob(Addr addr, uint8_t *p, int size) const { readBlobPhys(addr, 0, p, size); + return true; } /** * Write size bytes from p to address. + * Returns true on success and false on failure. */ - virtual void - writeBlob(Addr addr, const uint8_t* p, int size) const + virtual bool + tryWriteBlob(Addr addr, const uint8_t *p, int size) const { writeBlobPhys(addr, 0, p, size); + return true; } /** * Fill size bytes starting at addr with byte value val. + * Returns true on success and false on failure. */ - virtual void - memsetBlob(Addr addr, uint8_t v, int size) const + virtual bool + tryMemsetBlob(Addr addr, uint8_t val, int size) const { - memsetBlobPhys(addr, 0, v, size); + memsetBlobPhys(addr, 0, val, size); + return true; } + + + /** Higher level interfaces based on the above. */ + /** - * Read size bytes memory at physical address and store in p. + * Same as tryReadBlob, but insists on success. */ - void readBlobPhys(Addr addr, Request::Flags flags, - uint8_t* p, int size) const; + void + readBlob(Addr addr, uint8_t* p, int size) const + { + if (!tryReadBlob(addr, p, size)) + fatal("readBlob(%#x, ...) failed", addr); + } /** - * Write size bytes from p to physical address. + * Same as tryWriteBlob, but insists on success. */ - void writeBlobPhys(Addr addr, Request::Flags flags, - const uint8_t* p, int size) const; + void + writeBlob(Addr addr, const uint8_t* p, int size) const + { + if (!tryWriteBlob(addr, p, size)) + fatal("writeBlob(%#x, ...) failed", addr); + } /** - * Fill size bytes starting at physical addr with byte value val. + * Same as tryMemsetBlob, but insists on success. */ - void memsetBlobPhys(Addr addr, Request::Flags flags, - uint8_t v, int size) const; + void + memsetBlob(Addr addr, uint8_t v, int size) const + { + if (!tryMemsetBlob(addr, v, size)) + fatal("memsetBlob(%#x, ...) failed", addr); + } /** * Read sizeof(T) bytes from address and return as object T. @@ -162,6 +210,38 @@ class PortProxy */ template void write(Addr address, T data, ByteOrder guest_byte_order) const; + + /** + * Write the string str into guest memory at address addr. + * Returns true on success and false on failure. + */ + bool tryWriteString(Addr addr, const char *str) const; + + /** + * Same as tryWriteString, but insists on success. + */ + void + writeString(Addr addr, const char *str) const + { + if (!tryWriteString(addr, str)) + fatal("writeString(%#x, ...) failed", addr); + } + + /** + * Reads the string at guest address addr into the std::string str. + * Returns true on success and false on failure. + */ + bool tryReadString(std::string &str, Addr addr) const; + + /** + * Same as tryReadString, but insists on success. + */ + void + readString(std::string &str, Addr addr) const + { + if (!tryReadString(str, addr)) + fatal("readString(%#x, ...) failed", addr); + } }; diff --git a/src/mem/se_translating_port_proxy.cc b/src/mem/se_translating_port_proxy.cc index bb30ffbd2..de5335a05 100644 --- a/src/mem/se_translating_port_proxy.cc +++ b/src/mem/se_translating_port_proxy.cc @@ -61,9 +61,6 @@ SETranslatingPortProxy::SETranslatingPortProxy(MasterPort& port, Process *p, process(p), allocating(alloc) { } -SETranslatingPortProxy::~SETranslatingPortProxy() -{ } - bool SETranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const { @@ -82,13 +79,6 @@ SETranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const return true; } -void -SETranslatingPortProxy::readBlob(Addr addr, uint8_t *p, int size) const -{ - if (!tryReadBlob(addr, p, size)) - fatal("readBlob(0x%x, ...) failed", addr); -} - bool SETranslatingPortProxy::tryWriteBlob(Addr addr, const uint8_t *p, @@ -122,13 +112,6 @@ SETranslatingPortProxy::tryWriteBlob(Addr addr, const uint8_t *p, } -void -SETranslatingPortProxy::writeBlob(Addr addr, const uint8_t *p, int size) const -{ - if (!tryWriteBlob(addr, p, size)) - fatal("writeBlob(0x%x, ...) failed", addr); -} - bool SETranslatingPortProxy::tryMemsetBlob(Addr addr, uint8_t val, int size) const { @@ -150,69 +133,3 @@ SETranslatingPortProxy::tryMemsetBlob(Addr addr, uint8_t val, int size) const return true; } - -void -SETranslatingPortProxy::memsetBlob(Addr addr, uint8_t val, int size) const -{ - if (!tryMemsetBlob(addr, val, size)) - fatal("memsetBlob(0x%x, ...) failed", addr); -} - - -bool -SETranslatingPortProxy::tryWriteString(Addr addr, const char *str) const -{ - uint8_t c; - - Addr vaddr = addr; - - do { - c = *str++; - Addr paddr; - - if (!pTable->translate(vaddr++, paddr)) - return false; - - PortProxy::writeBlob(paddr, &c, 1); - } while (c); - - return true; -} - -void -SETranslatingPortProxy::writeString(Addr addr, const char *str) const -{ - if (!tryWriteString(addr, str)) - fatal("writeString(0x%x, ...) failed", addr); -} - -bool -SETranslatingPortProxy::tryReadString(std::string &str, Addr addr) const -{ - uint8_t c; - - Addr vaddr = addr; - - while (true) { - Addr paddr; - - if (!pTable->translate(vaddr++, paddr)) - return false; - - PortProxy::readBlob(paddr, &c, 1); - if (c == '\0') - break; - - str += c; - } - - return true; -} - -void -SETranslatingPortProxy::readString(std::string &str, Addr addr) const -{ - if (!tryReadString(str, addr)) - fatal("readString(0x%x, ...) failed", addr); -} - diff --git a/src/mem/se_translating_port_proxy.hh b/src/mem/se_translating_port_proxy.hh index 04bfd8a2b..1c8828bbf 100644 --- a/src/mem/se_translating_port_proxy.hh +++ b/src/mem/se_translating_port_proxy.hh @@ -81,22 +81,13 @@ class SETranslatingPortProxy : public PortProxy public: SETranslatingPortProxy(MasterPort& port, Process* p, AllocType alloc); - ~SETranslatingPortProxy(); + ~SETranslatingPortProxy() {} void setPageTable(EmulationPageTable *p) { pTable = p; } void setProcess(Process *p) { process = p; } - bool tryReadBlob(Addr addr, uint8_t *p, int size) const; - bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const; - bool tryMemsetBlob(Addr addr, uint8_t val, int size) const; - bool tryWriteString(Addr addr, const char *str) const; - bool tryReadString(std::string &str, Addr addr) const; - - void readBlob(Addr addr, uint8_t *p, int size) const override; - void writeBlob(Addr addr, const uint8_t *p, int size) const override; - void memsetBlob(Addr addr, uint8_t val, int size) const override; - - void writeString(Addr addr, const char *str) const; - void readString(std::string &str, Addr addr) const; + bool tryReadBlob(Addr addr, uint8_t *p, int size) const override; + bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override; + bool tryMemsetBlob(Addr addr, uint8_t val, int size) const override; }; #endif // __MEM_SE_TRANSLATING_PORT_PROXY_HH__ diff --git a/src/mem/secure_port_proxy.cc b/src/mem/secure_port_proxy.cc index 7bf23d7de..645baa948 100644 --- a/src/mem/secure_port_proxy.cc +++ b/src/mem/secure_port_proxy.cc @@ -39,20 +39,23 @@ #include "mem/secure_port_proxy.hh" -void -SecurePortProxy::readBlob(Addr addr, uint8_t *p, int size) const +bool +SecurePortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const { readBlobPhys(addr, Request::SECURE, p, size); + return true; } -void -SecurePortProxy::writeBlob(Addr addr, const uint8_t *p, int size) const +bool +SecurePortProxy::tryWriteBlob(Addr addr, const uint8_t *p, int size) const { writeBlobPhys(addr, Request::SECURE, p, size); + return true; } -void -SecurePortProxy::memsetBlob(Addr addr, uint8_t v, int size) const +bool +SecurePortProxy::tryMemsetBlob(Addr addr, uint8_t v, int size) const { memsetBlobPhys(addr, Request::SECURE, v, size); + return true; } diff --git a/src/mem/secure_port_proxy.hh b/src/mem/secure_port_proxy.hh index 857d70bc8..032331210 100644 --- a/src/mem/secure_port_proxy.hh +++ b/src/mem/secure_port_proxy.hh @@ -73,9 +73,9 @@ class SecurePortProxy : public PortProxy SecurePortProxy(MasterPort &port, unsigned int cache_line_size) : PortProxy(port, cache_line_size) {} - void readBlob(Addr addr, uint8_t *p, int size) const override; - void writeBlob(Addr addr, const uint8_t *p, int size) const override; - void memsetBlob(Addr addr, uint8_t val, int size) const override; + bool tryReadBlob(Addr addr, uint8_t *p, int size) const override; + bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override; + bool tryMemsetBlob(Addr addr, uint8_t val, int size) const override; }; #endif // __MEM_SECURE_PORT_PROXY_HH__