From: Gabe Black Date: Thu, 2 May 2019 03:12:05 +0000 (-0700) Subject: mem, arm: Replace the pointer type in PortProxy with void *. X-Git-Tag: v19.0.0.0~810 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d7c4cad240fd4f378d7362da5e9e44b9f0dd80d3;p=gem5.git mem, arm: Replace the pointer type in PortProxy with void *. The void * type is for pointers which point to an unknown type. We should use that when handling anonymous buffers in the PortProxy functions, instead of uint8_t * which points to bytes. Importantly, C/C++ doesn't require you to do any casting to turn an arbitrary pointer type into a void *. This will get rid of lots of tedious, verbose casting throughout the code base. Change-Id: Id1adecc283c866d8e24524efd64f37b079088bd9 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18571 Tested-by: kokoro Reviewed-by: Andreas Sandberg 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 a21d3283a..2e17cbf63 100644 --- a/src/mem/fs_translating_port_proxy.cc +++ b/src/mem/fs_translating_port_proxy.cc @@ -67,7 +67,7 @@ FSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port, } bool -FSTranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const +FSTranslatingPortProxy::tryReadBlob(Addr addr, void *p, int size) const { Addr paddr; for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); @@ -79,14 +79,14 @@ FSTranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const paddr = TheISA::vtophys(gen.addr()); PortProxy::readBlobPhys(paddr, 0, p, gen.size()); - p += gen.size(); + p = static_cast(p) + gen.size(); } return true; } bool FSTranslatingPortProxy::tryWriteBlob( - Addr addr, const uint8_t *p, int size) const + Addr addr, const void *p, int size) const { Addr paddr; for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); @@ -98,7 +98,7 @@ FSTranslatingPortProxy::tryWriteBlob( paddr = TheISA::vtophys(gen.addr()); PortProxy::writeBlobPhys(paddr, 0, p, gen.size()); - p += gen.size(); + p = static_cast(p) + gen.size(); } return true; } diff --git a/src/mem/fs_translating_port_proxy.hh b/src/mem/fs_translating_port_proxy.hh index 5ae87001c..78adf1ac5 100644 --- a/src/mem/fs_translating_port_proxy.hh +++ b/src/mem/fs_translating_port_proxy.hh @@ -85,11 +85,11 @@ class FSTranslatingPortProxy : public PortProxy /** Version of tryReadblob that translates virt->phys and deals * with page boundries. */ - bool tryReadBlob(Addr addr, uint8_t *p, int size) const override; + bool tryReadBlob(Addr addr, void *p, int size) const override; /** Version of tryWriteBlob that translates virt->phys and deals * with page boundries. */ - bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override; + bool tryWriteBlob(Addr addr, const void *p, int size) const override; /** * Fill size bytes starting at addr with byte value val. diff --git a/src/mem/port_proxy.cc b/src/mem/port_proxy.cc index 97eb67eff..f56bfeb55 100644 --- a/src/mem/port_proxy.cc +++ b/src/mem/port_proxy.cc @@ -43,7 +43,7 @@ void PortProxy::readBlobPhys(Addr addr, Request::Flags flags, - uint8_t *p, int size) const + void *p, int size) const { for (ChunkGenerator gen(addr, size, _cacheLineSize); !gen.done(); gen.next()) { @@ -52,15 +52,15 @@ PortProxy::readBlobPhys(Addr addr, Request::Flags flags, gen.addr(), gen.size(), flags, Request::funcMasterId); Packet pkt(req, MemCmd::ReadReq); - pkt.dataStatic(p); + pkt.dataStatic(static_cast(p)); _port.sendFunctional(&pkt); - p += gen.size(); + p = static_cast(p) + gen.size(); } } void PortProxy::writeBlobPhys(Addr addr, Request::Flags flags, - const uint8_t *p, int size) const + const void *p, int size) const { for (ChunkGenerator gen(addr, size, _cacheLineSize); !gen.done(); gen.next()) { @@ -69,9 +69,9 @@ PortProxy::writeBlobPhys(Addr addr, Request::Flags flags, gen.addr(), gen.size(), flags, Request::funcMasterId); Packet pkt(req, MemCmd::WriteReq); - pkt.dataStaticConst(p); + pkt.dataStaticConst(static_cast(p)); _port.sendFunctional(&pkt); - p += gen.size(); + p = static_cast(p) + gen.size(); } } @@ -92,7 +92,7 @@ bool PortProxy::tryWriteString(Addr addr, const char *str) const { do { - if (!tryWriteBlob(addr++, (uint8_t *)str, 1)) + if (!tryWriteBlob(addr++, str, 1)) return false; } while (*str++); return true; diff --git a/src/mem/port_proxy.hh b/src/mem/port_proxy.hh index dcc1905a5..096f82664 100644 --- a/src/mem/port_proxy.hh +++ b/src/mem/port_proxy.hh @@ -100,13 +100,13 @@ class PortProxy * Read size bytes memory at physical address and store in p. */ void readBlobPhys(Addr addr, Request::Flags flags, - uint8_t* p, int size) const; + void *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; + const void *p, int size) const; /** * Fill size bytes starting at physical addr with byte value val. @@ -123,7 +123,7 @@ class PortProxy * Returns true on success and false on failure. */ virtual bool - tryReadBlob(Addr addr, uint8_t *p, int size) const + tryReadBlob(Addr addr, void *p, int size) const { readBlobPhys(addr, 0, p, size); return true; @@ -134,7 +134,7 @@ class PortProxy * Returns true on success and false on failure. */ virtual bool - tryWriteBlob(Addr addr, const uint8_t *p, int size) const + tryWriteBlob(Addr addr, const void *p, int size) const { writeBlobPhys(addr, 0, p, size); return true; @@ -159,7 +159,7 @@ class PortProxy * Same as tryReadBlob, but insists on success. */ void - readBlob(Addr addr, uint8_t* p, int size) const + readBlob(Addr addr, void *p, int size) const { if (!tryReadBlob(addr, p, size)) fatal("readBlob(%#x, ...) failed", addr); @@ -169,7 +169,7 @@ class PortProxy * Same as tryWriteBlob, but insists on success. */ void - writeBlob(Addr addr, const uint8_t* p, int size) const + writeBlob(Addr addr, const void *p, int size) const { if (!tryWriteBlob(addr, p, size)) fatal("writeBlob(%#x, ...) failed", addr); @@ -250,7 +250,7 @@ T PortProxy::read(Addr address) const { T data; - readBlob(address, (uint8_t*)&data, sizeof(T)); + readBlob(address, &data, sizeof(T)); return data; } @@ -258,7 +258,7 @@ template void PortProxy::write(Addr address, T data) const { - writeBlob(address, (uint8_t*)&data, sizeof(T)); + writeBlob(address, &data, sizeof(T)); } template @@ -266,7 +266,7 @@ T PortProxy::read(Addr address, ByteOrder byte_order) const { T data; - readBlob(address, (uint8_t*)&data, sizeof(T)); + readBlob(address, &data, sizeof(T)); return gtoh(data, byte_order); } @@ -275,7 +275,7 @@ void PortProxy::write(Addr address, T data, ByteOrder byte_order) const { data = htog(data, byte_order); - writeBlob(address, (uint8_t*)&data, sizeof(T)); + writeBlob(address, &data, sizeof(T)); } #endif // __MEM_PORT_PROXY_HH__ diff --git a/src/mem/se_translating_port_proxy.cc b/src/mem/se_translating_port_proxy.cc index de5335a05..c5f38f1cd 100644 --- a/src/mem/se_translating_port_proxy.cc +++ b/src/mem/se_translating_port_proxy.cc @@ -62,9 +62,10 @@ SETranslatingPortProxy::SETranslatingPortProxy(MasterPort& port, Process *p, { } bool -SETranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const +SETranslatingPortProxy::tryReadBlob(Addr addr, void *p, int size) const { int prevSize = 0; + auto *bytes = static_cast(p); for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) { Addr paddr; @@ -72,7 +73,7 @@ SETranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const if (!pTable->translate(gen.addr(),paddr)) return false; - PortProxy::readBlobPhys(paddr, 0, p + prevSize, gen.size()); + PortProxy::readBlobPhys(paddr, 0, bytes + prevSize, gen.size()); prevSize += gen.size(); } @@ -81,10 +82,10 @@ SETranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const bool -SETranslatingPortProxy::tryWriteBlob(Addr addr, const uint8_t *p, - int size) const +SETranslatingPortProxy::tryWriteBlob(Addr addr, const void *p, int size) const { int prevSize = 0; + auto *bytes = static_cast(p); for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) { Addr paddr; @@ -104,7 +105,7 @@ SETranslatingPortProxy::tryWriteBlob(Addr addr, const uint8_t *p, pTable->translate(gen.addr(), paddr); } - PortProxy::writeBlobPhys(paddr, 0, p + prevSize, gen.size()); + PortProxy::writeBlobPhys(paddr, 0, bytes + prevSize, gen.size()); prevSize += gen.size(); } diff --git a/src/mem/se_translating_port_proxy.hh b/src/mem/se_translating_port_proxy.hh index 1c8828bbf..718e44a57 100644 --- a/src/mem/se_translating_port_proxy.hh +++ b/src/mem/se_translating_port_proxy.hh @@ -85,8 +85,8 @@ class SETranslatingPortProxy : public PortProxy void setPageTable(EmulationPageTable *p) { pTable = p; } void setProcess(Process *p) { process = p; } - bool tryReadBlob(Addr addr, uint8_t *p, int size) const override; - bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override; + bool tryReadBlob(Addr addr, void *p, int size) const override; + bool tryWriteBlob(Addr addr, const void *p, int size) const override; bool tryMemsetBlob(Addr addr, uint8_t val, int size) const override; }; diff --git a/src/mem/secure_port_proxy.cc b/src/mem/secure_port_proxy.cc index 645baa948..01195f4b9 100644 --- a/src/mem/secure_port_proxy.cc +++ b/src/mem/secure_port_proxy.cc @@ -40,14 +40,14 @@ #include "mem/secure_port_proxy.hh" bool -SecurePortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const +SecurePortProxy::tryReadBlob(Addr addr, void *p, int size) const { readBlobPhys(addr, Request::SECURE, p, size); return true; } bool -SecurePortProxy::tryWriteBlob(Addr addr, const uint8_t *p, int size) const +SecurePortProxy::tryWriteBlob(Addr addr, const void *p, int size) const { writeBlobPhys(addr, Request::SECURE, p, size); return true; diff --git a/src/mem/secure_port_proxy.hh b/src/mem/secure_port_proxy.hh index 032331210..9a2200c9e 100644 --- a/src/mem/secure_port_proxy.hh +++ b/src/mem/secure_port_proxy.hh @@ -73,8 +73,8 @@ class SecurePortProxy : public PortProxy SecurePortProxy(MasterPort &port, unsigned int cache_line_size) : PortProxy(port, cache_line_size) {} - bool tryReadBlob(Addr addr, uint8_t *p, int size) const override; - bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override; + bool tryReadBlob(Addr addr, void *p, int size) const override; + bool tryWriteBlob(Addr addr, const void *p, int size) const override; bool tryMemsetBlob(Addr addr, uint8_t val, int size) const override; };