From patchwork Thu Nov 4 22:36:15 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: 70180 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 BE414B70D5 for ; Fri, 5 Nov 2010 09:46:29 +1100 (EST) Received: from localhost ([127.0.0.1]:37786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PE8Vf-00083j-SA for incoming@patchwork.ozlabs.org; Thu, 04 Nov 2010 18:42:20 -0400 Received: from [140.186.70.92] (port=41566 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PE8Pg-0005Nb-S7 for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:37:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PE8PT-0002dO-Ga for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:35:56 -0400 Received: from mailout-de.gmx.net ([213.165.64.23]:36727 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PE8PT-0002dF-2W for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:35:55 -0400 Received: (qmail invoked by alias); 04 Nov 2010 22:35:53 -0000 Received: from unknown (EHLO localhost) [84.88.53.92] by mail.gmx.net (mp045) with SMTP; 04 Nov 2010 23:35:53 +0100 X-Authenticated: #12333383 X-Provags-ID: V01U2FsdGVkX18f8Ap6fHAfmCxe3zE+ibabWtGhEbz0cTwCZ8KiEN lk1tMR73Q1w84d To: qemu-devel@nongnu.org From: =?utf-8?b?TGx1w61z?= Date: Thu, 04 Nov 2010 23:36:15 +0100 Message-ID: <20101104223614.16669.69856.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 5/6] backdoor: [i386] provide and implement intruction-based backdoor interface 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 Take the unused CPUID 0x40001xxx range as the backdoor instruction. Signed-off-by: LluĂ­s Vilanova --- backdoor/guest.h | 21 +++++++++++++++++++++ target-i386/cpuid.c | 27 +++++++++++++++++++++++++++ target-i386/helper.h | 4 ++++ target-i386/translate.c | 4 ++++ 4 files changed, 56 insertions(+), 0 deletions(-) diff --git a/backdoor/guest.h b/backdoor/guest.h index 8373762..3edcbc6 100644 --- a/backdoor/guest.h +++ b/backdoor/guest.h @@ -26,8 +26,29 @@ * - v32: value of 32 bits */ +#include + +#if __i386__ || __i486__ || __x86_64__ + +#define _BACKDOOR(t, i8, v32) \ + ({ \ + uint32_t eax, ebx, ecx, edx; \ + uint32_t index = (uint32_t)0x40001000 + (t<<8) + (uint8_t)i8; \ + uint32_t count = (uint32_t)v32; \ + asm volatile ("cpuid" \ + : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) \ + : "0"(index), "2"(count) \ + ); \ + eax; \ + }) + +#define BACKDOOR_i8(i) _BACKDOOR(0, i, 0) +#define BACKDOOR_i8_v32(i, v) _BACKDOOR(1, i, v) + +#else #error Undefined instruction-based backdoor interface for guest architecture +#endif #endif /* BACKDOOR__GUEST_H */ diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index 650a719..03fc973 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -27,6 +27,9 @@ #include "qemu-option.h" #include "qemu-config.h" +#include "helper.h" + + /* feature flags taken from "Intel Processor Identification and the CPUID * Instruction" and AMD's "CPUID Specification". In cases of disagreement * between feature naming conventions, aliases may be added. @@ -1033,6 +1036,30 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { +#if defined(CONFIG_BACKDOOR) /* synched with "backdoor/guest.h" */ + if ((index & ~0xfff) == 0x40001000) { + int type = (index >> 8) & 0xf; + uint8_t i8 = index & 0x0ff; + uint32_t v32 = count; + switch (type) { + case 0: + helper_backdoor_i8(i8); + break; + case 1: + helper_backdoor_i8_v32(i8, v32); + break; + default: + printf("invalid backdoor request\n"); + abort(); + } + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; + return; + } +#endif + /* test if maximum index reached */ if (index & 0x80000000) { if (index > env->cpuid_xlevel) diff --git a/target-i386/helper.h b/target-i386/helper.h index 6b518ad..979d94e 100644 --- a/target-i386/helper.h +++ b/target-i386/helper.h @@ -217,4 +217,8 @@ DEF_HELPER_2(rclq, tl, tl, tl) DEF_HELPER_2(rcrq, tl, tl, tl) #endif +#if defined(CONFIG_BACKDOOR) +#include "backdoor/helper.h" +#endif + #include "def-helper.h" diff --git a/target-i386/translate.c b/target-i386/translate.c index 7b6e3c2..dfdc2f0 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -6941,6 +6941,10 @@ static target_ulong disas_insn(DisasContext *s, target_ulong pc_start) gen_op_set_cc_op(s->cc_op); gen_jmp_im(pc_start - s->cs_base); gen_helper_cpuid(); +#if defined(CONFIG_BACKDOOR) + gen_jmp_im(s->pc); + gen_eob(s); +#endif break; case 0xf4: /* hlt */ if (s->cpl != 0) {