OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

virtio-dev message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: [PATCH 08/16] lguest: implement endian conversion macros.


From: Rusty Russell <rusty@rustcorp.com.au>

Normally, these would be noops: for testing they convert to BIG ENDIAN.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 tools/lguest/lguest.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c
index 4077ace..68de1f7 100644
--- a/tools/lguest/lguest.c
+++ b/tools/lguest/lguest.c
@@ -189,9 +189,62 @@ static struct termios orig_term;
 #define lg_last_avail(vq)	((vq)->last_avail_idx)
 
 /*
- * The virtio configuration space is defined to be little-endian.  x86 is
+ * The virtio ring space is defined to be little-endian.  x86 is
  * little-endian too, but it's nice to be explicit so we have these helpers.
  */
+/* THESE TEST VERSIONS ARE BIG_ENDIAN! */
+static u16 cpu_to_virtio16(u16 v)
+{
+	return ((v & 0xFF00) >> 8)
+		| ((v & 0x00FF) << 8);
+}
+
+static u32 cpu_to_virtio32(u32 v)
+{
+	return ((v & 0xFF000000) >> 24)
+		| ((v & 0x00FF0000) >> 8)
+		| ((v & 0x0000FF00) << 8)
+		| ((v & 0x000000FF) << 24);
+}
+
+static u64 cpu_to_virtio64(u64 v)
+{
+	return ((v & 0xFF00000000000000ULL) >> 56)
+		| ((v & 0x00FF000000000000ULL) >> 40)
+		| ((v & 0x0000FF0000000000ULL) >> 24)
+		| ((v & 0x000000FF00000000ULL) >> 8)
+		| ((v & 0x00000000FF000000ULL) << 8)
+		| ((v & 0x0000000000FF0000ULL) << 24)
+		| ((v & 0x000000000000FF00ULL) << 40)
+		| ((v & 0x00000000000000FFULL) << 56);
+}
+
+static u16 virtio_to_cpu16(u16 v)
+{
+	return ((v & 0xFF00) >> 8)
+		| ((v & 0x00FF) << 8);
+}
+
+static u32 virtio_to_cpu32(u32 v)
+{
+	return ((v & 0xFF000000) >> 24)
+		| ((v & 0x00FF0000) >> 8)
+		| ((v & 0x0000FF00) << 8)
+		| ((v & 0x000000FF) << 24);
+}
+
+static u64 virtio_to_cpu64(u64 v)
+{
+	return ((v & 0xFF00000000000000ULL) >> 56)
+		| ((v & 0x00FF000000000000ULL) >> 40)
+		| ((v & 0x0000FF0000000000ULL) >> 24)
+		| ((v & 0x000000FF00000000ULL) >> 8)
+		| ((v & 0x00000000FF000000ULL) << 8)
+		| ((v & 0x0000000000FF0000ULL) << 24)
+		| ((v & 0x000000000000FF00ULL) << 40)
+		| ((v & 0x00000000000000FFULL) << 56);
+}
+
 #define cpu_to_le16(v16) (v16)
 #define cpu_to_le32(v32) (v32)
 #define cpu_to_le64(v64) (v64)
-- 
1.8.1.2



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]