From: Jan Kiszka <[email protected]>

This allows to extract the value of a bitfield from a variable, properly
shifted to the right for direct use.

Signed-off-by: Jan Kiszka <[email protected]>
---
 hypervisor/include/jailhouse/utils.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hypervisor/include/jailhouse/utils.h 
b/hypervisor/include/jailhouse/utils.h
index 89a35067..eae0f390 100644
--- a/hypervisor/include/jailhouse/utils.h
+++ b/hypervisor/include/jailhouse/utils.h
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2014
+ * Copyright (c) Siemens AG, 2014-2018
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -24,5 +24,9 @@
 #define BIT_MASK(last, first) \
        ((0xffffffffffffffffULL >> (64 - ((last) + 1 - (first)))) << (first))
 
+/* extract the field value at [last:first] from an input of up to 64 bits */
+#define GET_FIELD(value, last, first) \
+       (((value) & BIT_MASK((last), (first))) >> (first))
+
 #define MAX(a, b)              ((a) >= (b) ? (a) : (b))
 #define MIN(a, b)              ((a) <= (b) ? (a) : (b))
-- 
2.13.6

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to