misc: Delete the now unnecessary create methods.
[gem5.git] / src / mem / port_proxy.hh
index 096f82664a884120558b1db305270dbe8aef9066..9f3945be8ad1a9aa6c7cf8b2e38c672ab795b007 100644 (file)
@@ -33,8 +33,6 @@
  * 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() { }
 
@@ -195,7 +210,7 @@ class PortProxy
      * Write object T to address. Writes sizeof(T) bytes.
      */
     template <typename T>
-    void write(Addr address, data) const;
+    void write(Addr address, const T &data) const;
 
     /**
      * Read sizeof(T) bytes from address and return as object T.
@@ -242,6 +257,23 @@ class PortProxy
         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);
+    }
 };
 
 
@@ -256,7 +288,7 @@ PortProxy::read(Addr address) const
 
 template <typename T>
 void
-PortProxy::write(Addr address, data) const
+PortProxy::write(Addr address, const T &data) const
 {
     writeBlob(address, &data, sizeof(T));
 }