{
}
-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();
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();
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();
PortProxy::memsetBlobPhys(paddr, 0, v, gen.size());
}
+ return true;
}
void
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);
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;
+ }
+}
{}
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.
*/
template <typename T>
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);
+ }
};
process(p), allocating(alloc)
{ }
-SETranslatingPortProxy::~SETranslatingPortProxy()
-{ }
-
bool
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,
}
-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
{
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);
-}
-
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__
#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;
}
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__