qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 07/18] backdoor: Add a simple example


From: Lluís
Subject: [Qemu-devel] [PATCH 07/18] backdoor: Add a simple example
Date: Tue, 19 Oct 2010 22:05:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Provides a guest application that exercices the instruction-based backdoor
communication, as well as a backdoor callback implementation that prints the
guest requests.

Signed-off-by: Lluís Vilanova <address@hidden>
---
 .gitignore                             |    1 +
 backdoor/examples/print/README         |   13 +++++++++++
 backdoor/examples/print/guest/Makefile |    7 ++++++
 backdoor/examples/print/guest/test.c   |   33 +++++++++++++++++++++++++++++
 backdoor/examples/print/host/Makefile  |   13 +++++++++++
 backdoor/examples/print/host/printcb.c |   36 ++++++++++++++++++++++++++++++++
 6 files changed, 103 insertions(+), 0 deletions(-)
 create mode 100644 backdoor/examples/print/README
 create mode 100644 backdoor/examples/print/guest/Makefile
 create mode 100644 backdoor/examples/print/guest/test.c
 create mode 100644 backdoor/examples/print/host/Makefile
 create mode 100644 backdoor/examples/print/host/printcb.c

diff --git a/.gitignore b/.gitignore
index a43e4d1..e4a351d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -58,3 +58,4 @@ pc-bios/optionrom/multiboot.bin
 pc-bios/optionrom/multiboot.raw
 .stgit-*
 cscope.*
+backdoor/examples/print/guest/test
diff --git a/backdoor/examples/print/README b/backdoor/examples/print/README
new file mode 100644
index 0000000..0675f16
--- /dev/null
+++ b/backdoor/examples/print/README
@@ -0,0 +1,13 @@
+This example simply defines instruction-based backdoors to print their
+arguments, along with a guest example code that makes use of backdoor
+instructions.
+
+To compile the host (quemu) run:
+   /path/to/qemu/configure 
--with-backdoor=/path/to/qemu/backdoor/examples/print/host/
+   make
+
+To compile the guest program run:
+   make -C /path/to/qemu/backdoor/examples/print/guest/
+
+Now you can run it with:
+   /path/to/qemu/i386-linux-user/qemu-i386 
/path/to/qemu/backdoor/examples/print/guest/test
diff --git a/backdoor/examples/print/guest/Makefile 
b/backdoor/examples/print/guest/Makefile
new file mode 100644
index 0000000..ea266f2
--- /dev/null
+++ b/backdoor/examples/print/guest/Makefile
@@ -0,0 +1,7 @@
+CFLAGS += -I../../../../
+PROGS = test
+
+all: $(PROGS)
+
+clean:
+       rm -f $(PROGS)
diff --git a/backdoor/examples/print/guest/test.c 
b/backdoor/examples/print/guest/test.c
new file mode 100644
index 0000000..8146c3d
--- /dev/null
+++ b/backdoor/examples/print/guest/test.c
@@ -0,0 +1,33 @@
+/*
+ * Sample guest program exercising instruction-based backdoor communication.
+ *
+ *  Copyright (c) 2010 Lluís Vilanova <address@hidden>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#include "backdoor/guest.h"
+
+int main ()
+{
+    int i = 23;
+    printf("i8 1\n");
+    BACKDOOR_i8(0x01);
+    printf("i8_v 1 32\n");
+    BACKDOOR_i8_V(0x01, 32);
+    printf("i8_v 2 i (%d)\n", i);
+    BACKDOOR_i8_V(0x02, i);
+}
diff --git a/backdoor/examples/print/host/Makefile 
b/backdoor/examples/print/host/Makefile
new file mode 100644
index 0000000..bfd6311
--- /dev/null
+++ b/backdoor/examples/print/host/Makefile
@@ -0,0 +1,13 @@
+# Makefile for user-provided backdoor code
+
+include $(SRC_PATH)/config-host.mak
+include $(SRC_PATH)/rules.mak
+include $(SRC_PATH)/Makefile.objs
+
+objs = printcb.o
+
+libbackdoor.a: $(objs)
+       $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR    
$(TARGET_DIR)$@")
+
+clean:
+       rm -f libbackdoor.a $(objs)
diff --git a/backdoor/examples/print/host/printcb.c 
b/backdoor/examples/print/host/printcb.c
new file mode 100644
index 0000000..b267b6c
--- /dev/null
+++ b/backdoor/examples/print/host/printcb.c
@@ -0,0 +1,36 @@
+/*
+ * Sample user-defined callbacks for backdoor communication.
+ *
+ *  Copyright (c) 2010 Lluís Vilanova <address@hidden>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#include "cpu.h"
+#include "helper.h"
+
+
+void
+helper_backdoor_i8 (uint32_t imm)
+{
+    printf("backdoor_i8: %u\n", imm);
+}
+
+void
+helper_backdoor_i8_v (uint32_t imm, target_ulong value)
+{
+    printf("backdoor_i8_v: %u "TARGET_FMT_ld"\n", imm, value);
+}
-- 
1.7.1

-- 
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth



reply via email to

[Prev in Thread] Current Thread [Next in Thread]