From owner-svn-src-head@FreeBSD.ORG Tue Apr 22 16:13:57 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C53A012C; Tue, 22 Apr 2014 16:13:57 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 989C219DC; Tue, 22 Apr 2014 16:13:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3MGDvwm011723; Tue, 22 Apr 2014 16:13:57 GMT (envelope-from tychon@svn.freebsd.org) Received: (from tychon@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3MGDvbJ011721; Tue, 22 Apr 2014 16:13:57 GMT (envelope-from tychon@svn.freebsd.org) Message-Id: <201404221613.s3MGDvbJ011721@svn.freebsd.org> From: Tycho Nightingale Date: Tue, 22 Apr 2014 16:13:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264768 - in head: sys/amd64/vmm usr.sbin/bhyve X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Apr 2014 16:13:57 -0000 Author: tychon Date: Tue Apr 22 16:13:56 2014 New Revision: 264768 URL: http://svnweb.freebsd.org/changeset/base/264768 Log: Factor out common ioport handler code for better hygiene -- pointed out by neel@. Approved by: neel (co-mentor) Modified: head/sys/amd64/vmm/vmm_ioport.c head/usr.sbin/bhyve/inout.c Modified: head/sys/amd64/vmm/vmm_ioport.c ============================================================================== --- head/sys/amd64/vmm/vmm_ioport.c Tue Apr 22 16:04:31 2014 (r264767) +++ head/sys/amd64/vmm/vmm_ioport.c Tue Apr 22 16:13:56 2014 (r264768) @@ -69,18 +69,19 @@ emulate_ioport(struct vm *vm, int vcpuid if (handler == NULL) return (-1); + switch (vmexit->u.inout.bytes) { + case 1: + mask = 0xff; + break; + case 2: + mask = 0xffff; + break; + default: + mask = 0xffffffff; + break; + } + if (!vmexit->u.inout.in) { - switch (vmexit->u.inout.bytes) { - case 1: - mask = 0xff; - break; - case 2: - mask = 0xffff; - break; - default: - mask = 0xffffffff; - break; - } val = vmexit->u.inout.eax & mask; } @@ -88,17 +89,6 @@ emulate_ioport(struct vm *vm, int vcpuid vmexit->u.inout.port, vmexit->u.inout.bytes, &val); if (!error && vmexit->u.inout.in) { - switch (vmexit->u.inout.bytes) { - case 1: - mask = 0xff; - break; - case 2: - mask = 0xffff; - break; - default: - mask = 0xffffffff; - break; - } vmexit->u.inout.eax &= ~mask; vmexit->u.inout.eax |= val & mask; } Modified: head/usr.sbin/bhyve/inout.c ============================================================================== --- head/usr.sbin/bhyve/inout.c Tue Apr 22 16:04:31 2014 (r264767) +++ head/usr.sbin/bhyve/inout.c Tue Apr 22 16:13:56 2014 (r264768) @@ -107,18 +107,19 @@ emulate_inout(struct vmctx *ctx, int vcp if (strict && handler == default_inout) return (-1); + switch (bytes) { + case 1: + mask = 0xff; + break; + case 2: + mask = 0xffff; + break; + default: + mask = 0xffffffff; + break; + } + if (!in) { - switch (bytes) { - case 1: - mask = 0xff; - break; - case 2: - mask = 0xffff; - break; - default: - mask = 0xffffffff; - break; - } val = *eax & mask; } @@ -131,17 +132,6 @@ emulate_inout(struct vmctx *ctx, int vcp error = -1; if (!error && in) { - switch (bytes) { - case 1: - mask = 0xff; - break; - case 2: - mask = 0xffff; - break; - default: - mask = 0xffffffff; - break; - } *eax &= ~mask; *eax |= val & mask; }