From patchwork Thu Nov 4 22:36:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?Q?Llu=C3=ADs?= X-Patchwork-Id: 70183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4F374B70CC for ; Fri, 5 Nov 2010 09:51:45 +1100 (EST) Received: from localhost ([127.0.0.1]:34143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PE8e6-0002vO-6K for incoming@patchwork.ozlabs.org; Thu, 04 Nov 2010 18:51:02 -0400 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 Received: (qmail invoked by alias); 04 Nov 2010 22:36:09 -0000 Received: from unknown (EHLO localhost) [84.88.53.92] by mail.gmx.net (mp054) with SMTP; 04 Nov 2010 23:36:09 +0100 X-Authenticated: #12333383 X-Provags-ID: V01U2FsdGVkX1/7m1NAzDv7nynwccZ2WexeNeH/Ye542BGjCaJaJI Ex74/HxaOsluJe To: qemu-devel@nongnu.org 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> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH v2 6/6] backdoor: add a simple example X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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); +}