Patchwork [06/18] backdoor: [i386] Declare guest-side interface macros

login
register
mail settings
Submitter =?utf-8?Q?Llu=C3=ADs?=
Date Oct. 18, 2010, 6:08 p.m.
Message ID <24199c1d4204958e5fe5294fb6e5c11189c5c493.1287772676.git.vilanova@ac.upc.edu>
Download mbox | patch
Permalink /patch/68962/
State New
Headers show

Comments

=?utf-8?Q?Llu=C3=ADs?= - Oct. 18, 2010, 6:08 p.m.
Guest-side macros to generate backdoor instructions.

Signed-off-by: LluĂ­s Vilanova <vilanova@ac.upc.edu>
---
 backdoor/guest.h |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

Patch

diff --git a/backdoor/guest.h b/backdoor/guest.h
index 58847e2..17029d3 100644
--- a/backdoor/guest.h
+++ b/backdoor/guest.h
@@ -26,8 +26,32 @@ 
  * -  V: value passed in register
  */
 
+#if __i386__ || __i486__ || __x86_64__
+
+#define __BACKDOOR_BASE asm volatile (".byte 0x0f, 0x04")
+#define __BACKDOOR_V(v) asm volatile ("movl %0, %%eax" : : "g"(v) : "%eax")
+
+#define BACKDOOR_i8(cmd)                                        \
+    do {                                                        \
+        __BACKDOOR_BASE;                                        \
+        __BACKDOOR_i8(0x00);                                    \
+        __BACKDOOR_i8(cmd);                                     \
+    } while (0)
+
+#define BACKDOOR_i8_V(cmd, value)                               \
+    do {                                                        \
+        __BACKDOOR_V(value);                                    \
+        __BACKDOOR_BASE;                                        \
+        __BACKDOOR_i8(0x01);                                    \
+        __BACKDOOR_i8(cmd);                                     \
+    } while (0)
+
+#else
+
 #error Undefined instruction-based backdoor interface for guest architecture
 
+#endif
+
 #define __str(s) #s
 #define __xstr(s) __str(s)