* 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.
- *
- * Authors: Andreas Hansson
*/
/**
#ifndef __MEM_PORT_PROXY_HH__
#define __MEM_PORT_PROXY_HH__
+#include <functional>
+#include <limits>
+
#include "mem/port.hh"
#include "sim/byteswap.hh"
/**
- * This object is a proxy for a structural port, to be used for debug
- * accesses.
+ * This object is a proxy for a port or other object which implements the
+ * functional response protocol, to be used for debug accesses.
*
* This proxy object is used when non structural entities
* (e.g. thread contexts, object file loaders) need access to the
* memory system. It calls the corresponding functions on the underlying
- * structural port, and provides templatized convenience access functions.
+ * protocol, and provides templatized convenience access functions.
*
* The addresses are interpreted as physical addresses.
*
* @sa SETranslatingProxy
* @sa FSTranslatingProxy
*/
-class PortProxy
+class PortProxy : FunctionalRequestProtocol
{
- private:
+ public:
+ typedef std::function<void(PacketPtr pkt)> SendFunctionalFunc;
- /** The actual physical port used by this proxy. */
- MasterPort &_port;
+ private:
+ SendFunctionalFunc sendFunctional;
/** Granularity of any transactions issued through this proxy. */
const unsigned int _cacheLineSize;
+ void
+ recvFunctionalSnoop(PacketPtr pkt) override
+ {
+ // Since port proxies aren't anyone else's peer, they should never
+ // receive snoops.
+ panic("Port proxies should never receive snoops.");
+ }
+
public:
- PortProxy(MasterPort &port, unsigned int cacheLineSize) :
- _port(port), _cacheLineSize(cacheLineSize)
+ PortProxy(SendFunctionalFunc func, unsigned int cacheLineSize) :
+ sendFunctional(func), _cacheLineSize(cacheLineSize)
+ {}
+ PortProxy(const RequestPort &port, unsigned int cacheLineSize) :
+ sendFunctional([&port](PacketPtr pkt)->void {
+ port.sendFunctional(pkt);
+ }), _cacheLineSize(cacheLineSize)
{}
virtual ~PortProxy() { }
* Write object T to address. Writes sizeof(T) bytes.
*/
template <typename T>
- void write(Addr address, T data) const;
+ void write(Addr address, const T &data) const;
/**
* Read sizeof(T) bytes from address and return as object T.
if (!tryReadString(str, addr))
fatal("readString(%#x, ...) failed", addr);
}
+
+ /**
+ * Reads the string at guest address addr into the char * str, reading up
+ * to maxlen characters. The last character read is always a nul
+ * terminator. Returns true on success and false on failure.
+ */
+ bool tryReadString(char *str, Addr addr, size_t maxlen) const;
+
+ /**
+ * Same as tryReadString, but insists on success.
+ */
+ void
+ readString(char *str, Addr addr, size_t maxlen) const
+ {
+ if (!tryReadString(str, addr, maxlen))
+ fatal("readString(%#x, ...) failed", addr);
+ }
};
template <typename T>
void
-PortProxy::write(Addr address, T data) const
+PortProxy::write(Addr address, const T &data) const
{
writeBlob(address, &data, sizeof(T));
}