From patchwork Sat May 14 15:54:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 785082 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4EFtAoh026324 for ; Sat, 14 May 2011 15:55:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758174Ab1ENPzG (ORCPT ); Sat, 14 May 2011 11:55:06 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:52950 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757560Ab1ENPzE (ORCPT ); Sat, 14 May 2011 11:55:04 -0400 Received: by pvg12 with SMTP id 12so1540043pvg.19 for ; Sat, 14 May 2011 08:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:x-mailer :mime-version:content-type:content-transfer-encoding; bh=KPQYNbTSykYMyqx/PWDafmSQDg/NnorMpnV/irNy8ts=; b=kcWlJ6wLy3nXB9J8wf/ExYIZ5lHUpbecf0SiCeX75Ku6dShdQKqXGvqEeYZChmdRaC XU3fxg3CfzhwbOdLk4QmdscdNF6aUQ9/h12VnaXZmTraHusMA/EmN2MET6SPP+RZ8YBF 1I8c4TC61uL3iwWoF2U9+SjuqFiTvCyMURAHU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; b=xXNgNwa1dJvK8lgVbQijiVAKOvq4WUIMPxF5IvS/2XoeBVeJjTOQvpOMvBsHfn0g0Q XYAq/kAUaQX0KXO1W3xbcW6DDSa7qWInFz3uQEIkH+YDPwp3jb1CWTq+ulESa0nQDu5f zWd5W61FHimJSwjIqChLx9fs5HqTzGrrcf1NU= Received: by 10.142.245.5 with SMTP id s5mr1668878wfh.425.1305388503999; Sat, 14 May 2011 08:55:03 -0700 (PDT) Received: from amd (s198099.dynamic.ppp.asahi-net.or.jp [220.157.198.99]) by mx.google.com with ESMTPS id e4sm2102408pbj.4.2011.05.14.08.55.00 (version=SSLv3 cipher=OTHER); Sat, 14 May 2011 08:55:01 -0700 (PDT) Date: Sun, 15 May 2011 00:54:58 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp, gleb@redhat.com Subject: [PATCH 1/3] KVM: x86 emulator: Place insn_fetch helpers together Message-Id: <20110515005458.9964c7b8.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.1.0 (GTK+ 2.24.4; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 14 May 2011 15:55:10 +0000 (UTC) From: Takuya Yoshikawa The two macros need special care to use: Assume rc, ctxt, ops and done exist outside of them. Can goto outside. Considering the fact that these are used only in decode functions, moving these right after do_insn_fetch() seems to be a right thing to improve the readability. We also rename do_fetch_insn_byte() to do_insn_fetch_byte() to be consistent. Signed-off-by: Takuya Yoshikawa --- arch/x86/kvm/emulate.c | 38 +++++++++++++++++++------------------- 1 files changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 291c872..9df0895 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -405,23 +405,6 @@ struct gprefix { } \ } while (0) -/* Fetch next part of the instruction being emulated. */ -#define insn_fetch(_type, _size, _eip) \ -({ unsigned long _x; \ - rc = do_insn_fetch(ctxt, ops, (_eip), &_x, (_size)); \ - if (rc != X86EMUL_CONTINUE) \ - goto done; \ - (_eip) += (_size); \ - (_type)_x; \ -}) - -#define insn_fetch_arr(_arr, _size, _eip) \ -({ rc = do_insn_fetch(ctxt, ops, (_eip), _arr, (_size)); \ - if (rc != X86EMUL_CONTINUE) \ - goto done; \ - (_eip) += (_size); \ -}) - static int emulator_check_intercept(struct x86_emulate_ctxt *ctxt, enum x86_intercept intercept, enum x86_intercept_stage stage) @@ -669,7 +652,7 @@ static int segmented_read_std(struct x86_emulate_ctxt *ctxt, return ctxt->ops->read_std(ctxt, linear, data, size, &ctxt->exception); } -static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt, +static int do_insn_fetch_byte(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops, unsigned long eip, u8 *dest) { @@ -705,13 +688,30 @@ static int do_insn_fetch(struct x86_emulate_ctxt *ctxt, if (eip + size - ctxt->eip > 15) return X86EMUL_UNHANDLEABLE; while (size--) { - rc = do_fetch_insn_byte(ctxt, ops, eip++, dest++); + rc = do_insn_fetch_byte(ctxt, ops, eip++, dest++); if (rc != X86EMUL_CONTINUE) return rc; } return X86EMUL_CONTINUE; } +/* Fetch next part of the instruction being emulated. */ +#define insn_fetch(_type, _size, _eip) \ +({ unsigned long _x; \ + rc = do_insn_fetch(ctxt, ops, (_eip), &_x, (_size)); \ + if (rc != X86EMUL_CONTINUE) \ + goto done; \ + (_eip) += (_size); \ + (_type)_x; \ +}) + +#define insn_fetch_arr(_arr, _size, _eip) \ +({ rc = do_insn_fetch(ctxt, ops, (_eip), _arr, (_size)); \ + if (rc != X86EMUL_CONTINUE) \ + goto done; \ + (_eip) += (_size); \ +}) + /* * Given the 'reg' portion of a ModRM byte, and a register block, return a * pointer into the block that addresses the relevant register.