Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Apr 2014 16:13:57 +0000 (UTC)
From:      Tycho Nightingale <tychon@FreeBSD.org>
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
Message-ID:  <201404221613.s3MGDvbJ011721@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404221613.s3MGDvbJ011721>