Received: from [140.186.70.92] (port=41636 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PE8Pr-0005Sz-Ke for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:36:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PE8Pj-0002fQ-Lw for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:36:12 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:48464 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PE8Pj-0002fG-9T for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:36:11 -0400 From: =?utf-8?b?TGx1w61z?= Date: Thu, 04 Nov 2010 23:36:32 +0100 Message-ID: <20101104223631.16669.57268.stgit@ginnungagap.bsc.es> In-Reply-To: <20101104223452.16669.25092.stgit@ginnungagap.bsc.es> References: <20101104223452.16669.25092.stgit@ginnungagap.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v2 6/6] backdoor: add a simple example List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- .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..aeae948 --- /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 + * + * 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 . + */ + +#include + +#include "backdoor/guest.h" + +int main () +{ + int i = 23; + printf("i8 1\n"); + BACKDOOR_i8(0x01); + printf("i8_v32 1 32\n"); + BACKDOOR_i8_v32(0x01, 32); + printf("i8_v32 2 i (%d)\n", i); + BACKDOOR_i8_v32(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..60499c9 --- /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 + * + * 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 . + */ + +#include + +#include "cpu.h" +#include "helper.h" + + +void +helper_backdoor_i8 (uint32_t imm) +{ + printf("backdoor_i8: %u\n", imm); +} + +void +helper_backdoor_i8_v32 (uint32_t imm, uint32_t value) +{ + printf("backdoor_i8_v32: %u %d\n", imm, value); +}