Factor out common ioport handler code for better hygiene -- pointed

out by neel@.

Approved by:	neel (co-mentor)
This commit is contained in:
tychon 2014-04-22 16:13:56 +00:00
parent 5022630d02
commit f44a06b5a1
2 changed files with 24 additions and 44 deletions

View File

@ -69,18 +69,19 @@ emulate_ioport(struct vm *vm, int vcpuid, struct vm_exit *vmexit)
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, struct vm_exit *vmexit)
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;
}

View File

@ -107,18 +107,19 @@ emulate_inout(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
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 vcpu, int in, int port, int bytes,
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;
}