summaryrefslogtreecommitdiff
path: root/src/mem/packet.hh
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2015-08-07 09:59:28 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2015-08-07 09:59:28 +0100
commitbbb3abc16711e14858094b64a2eb1eb53204dded (patch)
treeb01975e299b0eedf7561ee925aee9830b949a54f /src/mem/packet.hh
parentce8939a97e26eb96cfe0604e737c0b155ba07656 (diff)
downloadgem5-bbb3abc16711e14858094b64a2eb1eb53204dded.tar.xz
mem: Cleanup packet accessor methods
The Packet::get() and Packet::set() methods both have very strange semantics. Currently, they automatically convert between the guest system's endianness and the host system's endianness. This behavior is usually undesired and unexpected. This patch introduces three new method pairs to access data: * getLE() / setLE() - Get data stored as little endian. * getBE() / setBE() - Get data stored as big endian. * get(ByteOrder) / set(v, ByteOrder) - Configurable endianness For example, a little endian device that is receiving a write request will use teh getLE() method to get the data from the packet. The old interface will be deprecated once all existing devices have been ported to the new interface.
Diffstat (limited to 'src/mem/packet.hh')
-rw-r--r--src/mem/packet.hh57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/mem/packet.hh b/src/mem/packet.hh
index d6231f48f..2b667d26d 100644
--- a/src/mem/packet.hh
+++ b/src/mem/packet.hh
@@ -767,6 +767,12 @@ class Packet : public Printable
}
+ public:
+ /**
+ * @{
+ * @name Data accessor mehtods
+ */
+
/**
* Set the data pointer to the following value that should not be
* freed. Static data allows us to do a single memcpy even if
@@ -845,15 +851,50 @@ class Packet : public Printable
}
/**
- * return the value of what is pointed to in the packet.
+ * Get the data in the packet byte swapped from big endian to
+ * host endian.
+ */
+ template <typename T>
+ T getBE() const;
+
+ /**
+ * Get the data in the packet byte swapped from little endian to
+ * host endian.
+ */
+ template <typename T>
+ T getLE() const;
+
+ /**
+ * Get the data in the packet byte swapped from the specified
+ * endianness.
+ */
+ template <typename T>
+ T get(ByteOrder endian) const;
+
+ /**
+ * Get the data in the packet byte swapped from guest to host
+ * endian.
*/
template <typename T>
T get() const;
+ /** Set the value in the data pointer to v as big endian. */
+ template <typename T>
+ void setBE(T v);
+
+ /** Set the value in the data pointer to v as little endian. */
+ template <typename T>
+ void setLE(T v);
+
/**
- * set the value in the data pointer to v.
+ * Set the value in the data pointer to v using the specified
+ * endianness.
*/
template <typename T>
+ void set(T v, ByteOrder endian);
+
+ /** Set the value in the data pointer to v as guest endian. */
+ template <typename T>
void set(T v);
/**
@@ -925,6 +966,18 @@ class Packet : public Printable
data = new uint8_t[getSize()];
}
+ /** @} */
+
+ private: // Private data accessor methods
+ /** Get the data in the packet without byte swapping. */
+ template <typename T>
+ T getRaw() const;
+
+ /** Set the value in the data pointer to v without byte swapping. */
+ template <typename T>
+ void setRaw(T v);
+
+ public:
/**
* Check a functional request against a memory value stored in
* another packet (i.e. an in-transit request or