aboutsummaryrefslogtreecommitdiff
path: root/sys/amd64/vmm/vmm_instruction_emul.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/amd64/vmm/vmm_instruction_emul.c')
-rw-r--r--sys/amd64/vmm/vmm_instruction_emul.c415
1 files changed, 206 insertions, 209 deletions
diff --git a/sys/amd64/vmm/vmm_instruction_emul.c b/sys/amd64/vmm/vmm_instruction_emul.c
index 06dffe6a80b9..1b042621c0eb 100644
--- a/sys/amd64/vmm/vmm_instruction_emul.c
+++ b/sys/amd64/vmm/vmm_instruction_emul.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 Sandvine, Inc.
* Copyright (c) 2012 NetApp, Inc.
@@ -25,13 +25,9 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#ifdef _KERNEL
#include <sys/param.h>
#include <sys/pcpu.h>
@@ -290,11 +286,11 @@ static uint64_t size2mask[] = {
};
static int
-vie_read_register(void *vm, int vcpuid, enum vm_reg_name reg, uint64_t *rval)
+vie_read_register(struct vcpu *vcpu, enum vm_reg_name reg, uint64_t *rval)
{
int error;
- error = vm_get_register(vm, vcpuid, reg, rval);
+ error = vm_get_register(vcpu, reg, rval);
return (error);
}
@@ -326,14 +322,14 @@ vie_calc_bytereg(struct vie *vie, enum vm_reg_name *reg, int *lhbr)
}
static int
-vie_read_bytereg(void *vm, int vcpuid, struct vie *vie, uint8_t *rval)
+vie_read_bytereg(struct vcpu *vcpu, struct vie *vie, uint8_t *rval)
{
uint64_t val;
int error, lhbr;
enum vm_reg_name reg;
vie_calc_bytereg(vie, &reg, &lhbr);
- error = vm_get_register(vm, vcpuid, reg, &val);
+ error = vm_get_register(vcpu, reg, &val);
/*
* To obtain the value of a legacy high byte register shift the
@@ -347,14 +343,14 @@ vie_read_bytereg(void *vm, int vcpuid, struct vie *vie, uint8_t *rval)
}
static int
-vie_write_bytereg(void *vm, int vcpuid, struct vie *vie, uint8_t byte)
+vie_write_bytereg(struct vcpu *vcpu, struct vie *vie, uint8_t byte)
{
uint64_t origval, val, mask;
int error, lhbr;
enum vm_reg_name reg;
vie_calc_bytereg(vie, &reg, &lhbr);
- error = vm_get_register(vm, vcpuid, reg, &origval);
+ error = vm_get_register(vcpu, reg, &origval);
if (error == 0) {
val = byte;
mask = 0xff;
@@ -367,13 +363,13 @@ vie_write_bytereg(void *vm, int vcpuid, struct vie *vie, uint8_t byte)
mask <<= 8;
}
val |= origval & ~mask;
- error = vm_set_register(vm, vcpuid, reg, val);
+ error = vm_set_register(vcpu, reg, val);
}
return (error);
}
int
-vie_update_register(void *vm, int vcpuid, enum vm_reg_name reg,
+vie_update_register(struct vcpu *vcpu, enum vm_reg_name reg,
uint64_t val, int size)
{
int error;
@@ -382,7 +378,7 @@ vie_update_register(void *vm, int vcpuid, enum vm_reg_name reg,
switch (size) {
case 1:
case 2:
- error = vie_read_register(vm, vcpuid, reg, &origval);
+ error = vie_read_register(vcpu, reg, &origval);
if (error)
return (error);
val &= size2mask[size];
@@ -397,7 +393,7 @@ vie_update_register(void *vm, int vcpuid, enum vm_reg_name reg,
return (EINVAL);
}
- error = vm_set_register(vm, vcpuid, reg, val);
+ error = vm_set_register(vcpu, reg, val);
return (error);
}
@@ -509,7 +505,7 @@ getandflags(int opsize, uint64_t x, uint64_t y)
}
static int
-emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+emulate_mov(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
{
int error, size;
@@ -528,9 +524,9 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* REX + 88/r: mov r/m8, r8 (%ah, %ch, %dh, %bh not available)
*/
size = 1; /* override for byte operation */
- error = vie_read_bytereg(vm, vcpuid, vie, &byte);
+ error = vie_read_bytereg(vcpu, vie, &byte);
if (error == 0)
- error = memwrite(vm, vcpuid, gpa, byte, size, arg);
+ error = memwrite(vcpu, gpa, byte, size, arg);
break;
case 0x89:
/*
@@ -540,10 +536,10 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* REX.W + 89/r mov r/m64, r64
*/
reg = gpr_map[vie->reg];
- error = vie_read_register(vm, vcpuid, reg, &val);
+ error = vie_read_register(vcpu, reg, &val);
if (error == 0) {
val &= size2mask[size];
- error = memwrite(vm, vcpuid, gpa, val, size, arg);
+ error = memwrite(vcpu, gpa, val, size, arg);
}
break;
case 0x8A:
@@ -553,9 +549,9 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* REX + 8A/r: mov r8, r/m8
*/
size = 1; /* override for byte operation */
- error = memread(vm, vcpuid, gpa, &val, size, arg);
+ error = memread(vcpu, gpa, &val, size, arg);
if (error == 0)
- error = vie_write_bytereg(vm, vcpuid, vie, val);
+ error = vie_write_bytereg(vcpu, vie, val);
break;
case 0x8B:
/*
@@ -564,10 +560,10 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* 8B/r: mov r32, r/m32
* REX.W 8B/r: mov r64, r/m64
*/
- error = memread(vm, vcpuid, gpa, &val, size, arg);
+ error = memread(vcpu, gpa, &val, size, arg);
if (error == 0) {
reg = gpr_map[vie->reg];
- error = vie_update_register(vm, vcpuid, reg, val, size);
+ error = vie_update_register(vcpu, reg, val, size);
}
break;
case 0xA1:
@@ -577,10 +573,10 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* A1: mov EAX, moffs32
* REX.W + A1: mov RAX, moffs64
*/
- error = memread(vm, vcpuid, gpa, &val, size, arg);
+ error = memread(vcpu, gpa, &val, size, arg);
if (error == 0) {
reg = VM_REG_GUEST_RAX;
- error = vie_update_register(vm, vcpuid, reg, val, size);
+ error = vie_update_register(vcpu, reg, val, size);
}
break;
case 0xA3:
@@ -590,10 +586,10 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* A3: mov moffs32, EAX
* REX.W + A3: mov moffs64, RAX
*/
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RAX, &val);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RAX, &val);
if (error == 0) {
val &= size2mask[size];
- error = memwrite(vm, vcpuid, gpa, val, size, arg);
+ error = memwrite(vcpu, gpa, val, size, arg);
}
break;
case 0xC6:
@@ -603,7 +599,7 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* REX + C6/0 mov r/m8, imm8
*/
size = 1; /* override for byte operation */
- error = memwrite(vm, vcpuid, gpa, vie->immediate, size, arg);
+ error = memwrite(vcpu, gpa, vie->immediate, size, arg);
break;
case 0xC7:
/*
@@ -613,7 +609,7 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* REX.W + C7/0 mov r/m64, imm32 (sign-extended to 64-bits)
*/
val = vie->immediate & size2mask[size];
- error = memwrite(vm, vcpuid, gpa, val, size, arg);
+ error = memwrite(vcpu, gpa, val, size, arg);
break;
default:
break;
@@ -623,9 +619,8 @@ emulate_mov(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
}
static int
-emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- mem_region_read_t memread, mem_region_write_t memwrite,
- void *arg)
+emulate_movx(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ mem_region_read_t memread, mem_region_write_t memwrite __unused, void *arg)
{
int error, size;
enum vm_reg_name reg;
@@ -646,7 +641,7 @@ emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
*/
/* get the first operand */
- error = memread(vm, vcpuid, gpa, &val, 1, arg);
+ error = memread(vcpu, gpa, &val, 1, arg);
if (error)
break;
@@ -657,7 +652,7 @@ emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
val = (uint8_t)val;
/* write the result */
- error = vie_update_register(vm, vcpuid, reg, val, size);
+ error = vie_update_register(vcpu, reg, val, size);
break;
case 0xB7:
/*
@@ -667,7 +662,7 @@ emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* 0F B7/r movzx r32, r/m16
* REX.W + 0F B7/r movzx r64, r/m16
*/
- error = memread(vm, vcpuid, gpa, &val, 2, arg);
+ error = memread(vcpu, gpa, &val, 2, arg);
if (error)
return (error);
@@ -676,7 +671,7 @@ emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
/* zero-extend word */
val = (uint16_t)val;
- error = vie_update_register(vm, vcpuid, reg, val, size);
+ error = vie_update_register(vcpu, reg, val, size);
break;
case 0xBE:
/*
@@ -689,7 +684,7 @@ emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
*/
/* get the first operand */
- error = memread(vm, vcpuid, gpa, &val, 1, arg);
+ error = memread(vcpu, gpa, &val, 1, arg);
if (error)
break;
@@ -700,7 +695,7 @@ emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
val = (int8_t)val;
/* write the result */
- error = vie_update_register(vm, vcpuid, reg, val, size);
+ error = vie_update_register(vcpu, reg, val, size);
break;
default:
break;
@@ -712,47 +707,47 @@ emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* Helper function to calculate and validate a linear address.
*/
static int
-get_gla(void *vm, int vcpuid, struct vie *vie, struct vm_guest_paging *paging,
- int opsize, int addrsize, int prot, enum vm_reg_name seg,
- enum vm_reg_name gpr, uint64_t *gla, int *fault)
+get_gla(struct vcpu *vcpu, struct vie *vie __unused,
+ struct vm_guest_paging *paging, int opsize, int addrsize, int prot,
+ enum vm_reg_name seg, enum vm_reg_name gpr, uint64_t *gla, int *fault)
{
struct seg_desc desc;
uint64_t cr0, val, rflags;
int error __diagused;
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_CR0, &cr0);
+ error = vie_read_register(vcpu, VM_REG_GUEST_CR0, &cr0);
KASSERT(error == 0, ("%s: error %d getting cr0", __func__, error));
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
KASSERT(error == 0, ("%s: error %d getting rflags", __func__, error));
- error = vm_get_seg_desc(vm, vcpuid, seg, &desc);
+ error = vm_get_seg_desc(vcpu, seg, &desc);
KASSERT(error == 0, ("%s: error %d getting segment descriptor %d",
__func__, error, seg));
- error = vie_read_register(vm, vcpuid, gpr, &val);
+ error = vie_read_register(vcpu, gpr, &val);
KASSERT(error == 0, ("%s: error %d getting register %d", __func__,
error, gpr));
if (vie_calculate_gla(paging->cpu_mode, seg, &desc, val, opsize,
addrsize, prot, gla)) {
if (seg == VM_REG_GUEST_SS)
- vm_inject_ss(vm, vcpuid, 0);
+ vm_inject_ss(vcpu, 0);
else
- vm_inject_gp(vm, vcpuid);
+ vm_inject_gp(vcpu);
goto guest_fault;
}
if (vie_canonical_check(paging->cpu_mode, *gla)) {
if (seg == VM_REG_GUEST_SS)
- vm_inject_ss(vm, vcpuid, 0);
+ vm_inject_ss(vcpu, 0);
else
- vm_inject_gp(vm, vcpuid);
+ vm_inject_gp(vcpu);
goto guest_fault;
}
if (vie_alignment_check(paging->cpl, opsize, cr0, rflags, *gla)) {
- vm_inject_ac(vm, vcpuid, 0);
+ vm_inject_ac(vcpu, 0);
goto guest_fault;
}
@@ -765,7 +760,7 @@ guest_fault:
}
static int
-emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+emulate_movs(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
struct vm_guest_paging *paging, mem_region_read_t memread,
mem_region_write_t memwrite, void *arg)
{
@@ -792,7 +787,7 @@ emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
repeat = vie->repz_present | vie->repnz_present;
if (repeat) {
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RCX, &rcx);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RCX, &rcx);
KASSERT(!error, ("%s: error %d getting rcx", __func__, error));
/*
@@ -822,12 +817,12 @@ emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
*/
seg = vie->segment_override ? vie->segment_register : VM_REG_GUEST_DS;
- error = get_gla(vm, vcpuid, vie, paging, opsize, vie->addrsize,
+ error = get_gla(vcpu, vie, paging, opsize, vie->addrsize,
PROT_READ, seg, VM_REG_GUEST_RSI, &srcaddr, &fault);
if (error || fault)
goto done;
- error = vm_copy_setup(vm, vcpuid, paging, srcaddr, opsize, PROT_READ,
+ error = vm_copy_setup(vcpu, paging, srcaddr, opsize, PROT_READ,
copyinfo, nitems(copyinfo), &fault);
if (error == 0) {
if (fault)
@@ -836,9 +831,9 @@ emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
/*
* case (2): read from system memory and write to mmio.
*/
- vm_copyin(vm, vcpuid, copyinfo, &val, opsize);
- vm_copy_teardown(vm, vcpuid, copyinfo, nitems(copyinfo));
- error = memwrite(vm, vcpuid, gpa, val, opsize, arg);
+ vm_copyin(copyinfo, &val, opsize);
+ vm_copy_teardown(copyinfo, nitems(copyinfo));
+ error = memwrite(vcpu, gpa, val, opsize, arg);
if (error)
goto done;
} else {
@@ -847,13 +842,13 @@ emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* if 'srcaddr' is in the mmio space.
*/
- error = get_gla(vm, vcpuid, vie, paging, opsize, vie->addrsize,
+ error = get_gla(vcpu, vie, paging, opsize, vie->addrsize,
PROT_WRITE, VM_REG_GUEST_ES, VM_REG_GUEST_RDI, &dstaddr,
&fault);
if (error || fault)
goto done;
- error = vm_copy_setup(vm, vcpuid, paging, dstaddr, opsize,
+ error = vm_copy_setup(vcpu, paging, dstaddr, opsize,
PROT_WRITE, copyinfo, nitems(copyinfo), &fault);
if (error == 0) {
if (fault)
@@ -868,12 +863,12 @@ emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* injected into the guest then it will happen
* before the MMIO read is attempted.
*/
- error = memread(vm, vcpuid, gpa, &val, opsize, arg);
+ error = memread(vcpu, gpa, &val, opsize, arg);
if (error)
goto done;
- vm_copyout(vm, vcpuid, &val, copyinfo, opsize);
- vm_copy_teardown(vm, vcpuid, copyinfo, nitems(copyinfo));
+ vm_copyout(&val, copyinfo, opsize);
+ vm_copy_teardown(copyinfo, nitems(copyinfo));
} else {
/*
* Case (4): read from and write to mmio.
@@ -883,33 +878,33 @@ emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* instruction is not going to be restarted due
* to address translation faults.
*/
- error = vm_gla2gpa(vm, vcpuid, paging, srcaddr,
+ error = vm_gla2gpa(vcpu, paging, srcaddr,
PROT_READ, &srcgpa, &fault);
if (error || fault)
goto done;
- error = vm_gla2gpa(vm, vcpuid, paging, dstaddr,
+ error = vm_gla2gpa(vcpu, paging, dstaddr,
PROT_WRITE, &dstgpa, &fault);
if (error || fault)
goto done;
- error = memread(vm, vcpuid, srcgpa, &val, opsize, arg);
+ error = memread(vcpu, srcgpa, &val, opsize, arg);
if (error)
goto done;
- error = memwrite(vm, vcpuid, dstgpa, val, opsize, arg);
+ error = memwrite(vcpu, dstgpa, val, opsize, arg);
if (error)
goto done;
}
}
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RSI, &rsi);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RSI, &rsi);
KASSERT(error == 0, ("%s: error %d getting rsi", __func__, error));
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RDI, &rdi);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RDI, &rdi);
KASSERT(error == 0, ("%s: error %d getting rdi", __func__, error));
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
KASSERT(error == 0, ("%s: error %d getting rflags", __func__, error));
if (rflags & PSL_D) {
@@ -920,17 +915,17 @@ emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
rdi += opsize;
}
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RSI, rsi,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RSI, rsi,
vie->addrsize);
KASSERT(error == 0, ("%s: error %d updating rsi", __func__, error));
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RDI, rdi,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RDI, rdi,
vie->addrsize);
KASSERT(error == 0, ("%s: error %d updating rdi", __func__, error));
if (repeat) {
rcx = rcx - 1;
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RCX,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RCX,
rcx, vie->addrsize);
KASSERT(!error, ("%s: error %d updating rcx", __func__, error));
@@ -938,7 +933,7 @@ emulate_movs(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* Repeat the instruction if the count register is not zero.
*/
if ((rcx & vie_size2mask(vie->addrsize)) != 0)
- vm_restart_instruction(vm, vcpuid);
+ vm_restart_instruction(vcpu);
}
done:
KASSERT(error == 0 || error == EFAULT, ("%s: unexpected error %d",
@@ -947,8 +942,8 @@ done:
}
static int
-emulate_stos(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- struct vm_guest_paging *paging, mem_region_read_t memread,
+emulate_stos(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ struct vm_guest_paging *paging __unused, mem_region_read_t memread __unused,
mem_region_write_t memwrite, void *arg)
{
int error, opsize, repeat;
@@ -959,7 +954,7 @@ emulate_stos(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
repeat = vie->repz_present | vie->repnz_present;
if (repeat) {
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RCX, &rcx);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RCX, &rcx);
KASSERT(!error, ("%s: error %d getting rcx", __func__, error));
/*
@@ -970,17 +965,17 @@ emulate_stos(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
return (0);
}
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RAX, &val);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RAX, &val);
KASSERT(!error, ("%s: error %d getting rax", __func__, error));
- error = memwrite(vm, vcpuid, gpa, val, opsize, arg);
+ error = memwrite(vcpu, gpa, val, opsize, arg);
if (error)
return (error);
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RDI, &rdi);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RDI, &rdi);
KASSERT(error == 0, ("%s: error %d getting rdi", __func__, error));
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
KASSERT(error == 0, ("%s: error %d getting rflags", __func__, error));
if (rflags & PSL_D)
@@ -988,13 +983,13 @@ emulate_stos(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
else
rdi += opsize;
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RDI, rdi,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RDI, rdi,
vie->addrsize);
KASSERT(error == 0, ("%s: error %d updating rdi", __func__, error));
if (repeat) {
rcx = rcx - 1;
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RCX,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RCX,
rcx, vie->addrsize);
KASSERT(!error, ("%s: error %d updating rcx", __func__, error));
@@ -1002,14 +997,14 @@ emulate_stos(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* Repeat the instruction if the count register is not zero.
*/
if ((rcx & vie_size2mask(vie->addrsize)) != 0)
- vm_restart_instruction(vm, vcpuid);
+ vm_restart_instruction(vcpu);
}
return (0);
}
static int
-emulate_and(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+emulate_and(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
{
int error, size;
@@ -1032,18 +1027,18 @@ emulate_and(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
/* get the first operand */
reg = gpr_map[vie->reg];
- error = vie_read_register(vm, vcpuid, reg, &val1);
+ error = vie_read_register(vcpu, reg, &val1);
if (error)
break;
/* get the second operand */
- error = memread(vm, vcpuid, gpa, &val2, size, arg);
+ error = memread(vcpu, gpa, &val2, size, arg);
if (error)
break;
/* perform the operation and write the result */
result = val1 & val2;
- error = vie_update_register(vm, vcpuid, reg, result, size);
+ error = vie_update_register(vcpu, reg, result, size);
break;
case 0x81:
case 0x83:
@@ -1061,7 +1056,7 @@ emulate_and(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
*/
/* get the first operand */
- error = memread(vm, vcpuid, gpa, &val1, size, arg);
+ error = memread(vcpu, gpa, &val1, size, arg);
if (error)
break;
@@ -1070,7 +1065,7 @@ emulate_and(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* operand and write the result
*/
result = val1 & vie->immediate;
- error = memwrite(vm, vcpuid, gpa, result, size, arg);
+ error = memwrite(vcpu, gpa, result, size, arg);
break;
default:
break;
@@ -1078,7 +1073,7 @@ emulate_and(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
if (error)
return (error);
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
if (error)
return (error);
@@ -1092,12 +1087,12 @@ emulate_and(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
rflags &= ~RFLAGS_STATUS_BITS;
rflags |= rflags2 & (PSL_PF | PSL_Z | PSL_N);
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, rflags, 8);
+ error = vie_update_register(vcpu, VM_REG_GUEST_RFLAGS, rflags, 8);
return (error);
}
static int
-emulate_or(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+emulate_or(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
{
int error, size;
@@ -1120,18 +1115,18 @@ emulate_or(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
/* get the first operand */
reg = gpr_map[vie->reg];
- error = vie_read_register(vm, vcpuid, reg, &val1);
+ error = vie_read_register(vcpu, reg, &val1);
if (error)
break;
/* get the second operand */
- error = memread(vm, vcpuid, gpa, &val2, size, arg);
+ error = memread(vcpu, gpa, &val2, size, arg);
if (error)
break;
/* perform the operation and write the result */
result = val1 | val2;
- error = vie_update_register(vm, vcpuid, reg, result, size);
+ error = vie_update_register(vcpu, reg, result, size);
break;
case 0x81:
case 0x83:
@@ -1149,7 +1144,7 @@ emulate_or(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
*/
/* get the first operand */
- error = memread(vm, vcpuid, gpa, &val1, size, arg);
+ error = memread(vcpu, gpa, &val1, size, arg);
if (error)
break;
@@ -1158,7 +1153,7 @@ emulate_or(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* operand and write the result
*/
result = val1 | vie->immediate;
- error = memwrite(vm, vcpuid, gpa, result, size, arg);
+ error = memwrite(vcpu, gpa, result, size, arg);
break;
default:
break;
@@ -1166,7 +1161,7 @@ emulate_or(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
if (error)
return (error);
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
if (error)
return (error);
@@ -1180,13 +1175,13 @@ emulate_or(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
rflags &= ~RFLAGS_STATUS_BITS;
rflags |= rflags2 & (PSL_PF | PSL_Z | PSL_N);
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, rflags, 8);
+ error = vie_update_register(vcpu, VM_REG_GUEST_RFLAGS, rflags, 8);
return (error);
}
static int
-emulate_cmp(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
+emulate_cmp(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ mem_region_read_t memread, mem_region_write_t memwrite __unused, void *arg)
{
int error, size;
uint64_t regop, memop, op1, op2, rflags, rflags2;
@@ -1213,12 +1208,12 @@ emulate_cmp(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
/* Get the register operand */
reg = gpr_map[vie->reg];
- error = vie_read_register(vm, vcpuid, reg, &regop);
+ error = vie_read_register(vcpu, reg, &regop);
if (error)
return (error);
/* Get the memory operand */
- error = memread(vm, vcpuid, gpa, &memop, size, arg);
+ error = memread(vcpu, gpa, &memop, size, arg);
if (error)
return (error);
@@ -1257,7 +1252,7 @@ emulate_cmp(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
size = 1;
/* get the first operand */
- error = memread(vm, vcpuid, gpa, &op1, size, arg);
+ error = memread(vcpu, gpa, &op1, size, arg);
if (error)
return (error);
@@ -1266,19 +1261,19 @@ emulate_cmp(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
default:
return (EINVAL);
}
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
if (error)
return (error);
rflags &= ~RFLAGS_STATUS_BITS;
rflags |= rflags2 & RFLAGS_STATUS_BITS;
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, rflags, 8);
+ error = vie_update_register(vcpu, VM_REG_GUEST_RFLAGS, rflags, 8);
return (error);
}
static int
-emulate_test(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
+emulate_test(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ mem_region_read_t memread, mem_region_write_t memwrite __unused, void *arg)
{
int error, size;
uint64_t op1, rflags, rflags2;
@@ -1301,7 +1296,7 @@ emulate_test(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
if ((vie->reg & 7) != 0)
return (EINVAL);
- error = memread(vm, vcpuid, gpa, &op1, size, arg);
+ error = memread(vcpu, gpa, &op1, size, arg);
if (error)
return (error);
@@ -1310,7 +1305,7 @@ emulate_test(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
default:
return (EINVAL);
}
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
if (error)
return (error);
@@ -1321,18 +1316,18 @@ emulate_test(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
rflags &= ~RFLAGS_STATUS_BITS;
rflags |= rflags2 & (PSL_PF | PSL_Z | PSL_N);
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, rflags, 8);
+ error = vie_update_register(vcpu, VM_REG_GUEST_RFLAGS, rflags, 8);
return (error);
}
static int
-emulate_bextr(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+emulate_bextr(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
struct vm_guest_paging *paging, mem_region_read_t memread,
- mem_region_write_t memwrite, void *arg)
+ mem_region_write_t memwrite __unused, void *arg)
{
uint64_t src1, src2, dst, rflags;
- unsigned start, len;
- int error, size;
+ unsigned start, len, size;
+ int error;
size = vie->opsize;
error = EINVAL;
@@ -1354,13 +1349,13 @@ emulate_bextr(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* operand) using an index and length specified in the second /source/
* operand (third operand).
*/
- error = memread(vm, vcpuid, gpa, &src1, size, arg);
+ error = memread(vcpu, gpa, &src1, size, arg);
if (error)
return (error);
- error = vie_read_register(vm, vcpuid, gpr_map[vie->vex_reg], &src2);
+ error = vie_read_register(vcpu, gpr_map[vie->vex_reg], &src2);
if (error)
return (error);
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
if (error)
return (error);
@@ -1386,7 +1381,7 @@ emulate_bextr(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
dst = src1;
done:
- error = vie_update_register(vm, vcpuid, gpr_map[vie->reg], dst, size);
+ error = vie_update_register(vcpu, gpr_map[vie->reg], dst, size);
if (error)
return (error);
@@ -1397,14 +1392,14 @@ done:
rflags &= ~RFLAGS_STATUS_BITS;
if (dst == 0)
rflags |= PSL_Z;
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, rflags,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RFLAGS, rflags,
8);
return (error);
}
static int
-emulate_add(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
+emulate_add(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ mem_region_read_t memread, mem_region_write_t memwrite __unused, void *arg)
{
int error, size;
uint64_t nval, rflags, rflags2, val1, val2;
@@ -1425,18 +1420,18 @@ emulate_add(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
/* get the first operand */
reg = gpr_map[vie->reg];
- error = vie_read_register(vm, vcpuid, reg, &val1);
+ error = vie_read_register(vcpu, reg, &val1);
if (error)
break;
/* get the second operand */
- error = memread(vm, vcpuid, gpa, &val2, size, arg);
+ error = memread(vcpu, gpa, &val2, size, arg);
if (error)
break;
/* perform the operation and write the result */
nval = val1 + val2;
- error = vie_update_register(vm, vcpuid, reg, nval, size);
+ error = vie_update_register(vcpu, reg, nval, size);
break;
default:
break;
@@ -1444,14 +1439,14 @@ emulate_add(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
if (!error) {
rflags2 = getaddflags(size, val1, val2);
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS,
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS,
&rflags);
if (error)
return (error);
rflags &= ~RFLAGS_STATUS_BITS;
rflags |= rflags2 & RFLAGS_STATUS_BITS;
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RFLAGS,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RFLAGS,
rflags, 8);
}
@@ -1459,8 +1454,8 @@ emulate_add(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
}
static int
-emulate_sub(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
+emulate_sub(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ mem_region_read_t memread, mem_region_write_t memwrite __unused, void *arg)
{
int error, size;
uint64_t nval, rflags, rflags2, val1, val2;
@@ -1481,18 +1476,18 @@ emulate_sub(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
/* get the first operand */
reg = gpr_map[vie->reg];
- error = vie_read_register(vm, vcpuid, reg, &val1);
+ error = vie_read_register(vcpu, reg, &val1);
if (error)
break;
/* get the second operand */
- error = memread(vm, vcpuid, gpa, &val2, size, arg);
+ error = memread(vcpu, gpa, &val2, size, arg);
if (error)
break;
/* perform the operation and write the result */
nval = val1 - val2;
- error = vie_update_register(vm, vcpuid, reg, nval, size);
+ error = vie_update_register(vcpu, reg, nval, size);
break;
default:
break;
@@ -1500,14 +1495,14 @@ emulate_sub(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
if (!error) {
rflags2 = getcc(size, val1, val2);
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS,
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS,
&rflags);
if (error)
return (error);
rflags &= ~RFLAGS_STATUS_BITS;
rflags |= rflags2 & RFLAGS_STATUS_BITS;
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RFLAGS,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RFLAGS,
rflags, 8);
}
@@ -1515,7 +1510,7 @@ emulate_sub(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
}
static int
-emulate_stack_op(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
+emulate_stack_op(struct vcpu *vcpu, uint64_t mmio_gpa, struct vie *vie,
struct vm_guest_paging *paging, mem_region_read_t memread,
mem_region_write_t memwrite, void *arg)
{
@@ -1553,7 +1548,7 @@ emulate_stack_op(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
* stack-segment descriptor determines the size of the
* stack pointer.
*/
- error = vm_get_seg_desc(vm, vcpuid, VM_REG_GUEST_SS, &ss_desc);
+ error = vm_get_seg_desc(vcpu, VM_REG_GUEST_SS, &ss_desc);
KASSERT(error == 0, ("%s: error %d getting SS descriptor",
__func__, error));
if (SEG_DESC_DEF32(ss_desc.access))
@@ -1562,13 +1557,13 @@ emulate_stack_op(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
stackaddrsize = 2;
}
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_CR0, &cr0);
+ error = vie_read_register(vcpu, VM_REG_GUEST_CR0, &cr0);
KASSERT(error == 0, ("%s: error %d getting cr0", __func__, error));
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
KASSERT(error == 0, ("%s: error %d getting rflags", __func__, error));
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RSP, &rsp);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RSP, &rsp);
KASSERT(error == 0, ("%s: error %d getting rsp", __func__, error));
if (pushop) {
rsp -= size;
@@ -1577,39 +1572,39 @@ emulate_stack_op(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
if (vie_calculate_gla(paging->cpu_mode, VM_REG_GUEST_SS, &ss_desc,
rsp, size, stackaddrsize, pushop ? PROT_WRITE : PROT_READ,
&stack_gla)) {
- vm_inject_ss(vm, vcpuid, 0);
+ vm_inject_ss(vcpu, 0);
return (0);
}
if (vie_canonical_check(paging->cpu_mode, stack_gla)) {
- vm_inject_ss(vm, vcpuid, 0);
+ vm_inject_ss(vcpu, 0);
return (0);
}
if (vie_alignment_check(paging->cpl, size, cr0, rflags, stack_gla)) {
- vm_inject_ac(vm, vcpuid, 0);
+ vm_inject_ac(vcpu, 0);
return (0);
}
- error = vm_copy_setup(vm, vcpuid, paging, stack_gla, size,
+ error = vm_copy_setup(vcpu, paging, stack_gla, size,
pushop ? PROT_WRITE : PROT_READ, copyinfo, nitems(copyinfo),
&fault);
if (error || fault)
return (error);
if (pushop) {
- error = memread(vm, vcpuid, mmio_gpa, &val, size, arg);
+ error = memread(vcpu, mmio_gpa, &val, size, arg);
if (error == 0)
- vm_copyout(vm, vcpuid, &val, copyinfo, size);
+ vm_copyout(&val, copyinfo, size);
} else {
- vm_copyin(vm, vcpuid, copyinfo, &val, size);
- error = memwrite(vm, vcpuid, mmio_gpa, val, size, arg);
+ vm_copyin(copyinfo, &val, size);
+ error = memwrite(vcpu, mmio_gpa, val, size, arg);
rsp += size;
}
- vm_copy_teardown(vm, vcpuid, copyinfo, nitems(copyinfo));
+ vm_copy_teardown(copyinfo, nitems(copyinfo));
if (error == 0) {
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RSP, rsp,
+ error = vie_update_register(vcpu, VM_REG_GUEST_RSP, rsp,
stackaddrsize);
KASSERT(error == 0, ("error %d updating rsp", error));
}
@@ -1617,7 +1612,7 @@ emulate_stack_op(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
}
static int
-emulate_push(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
+emulate_push(struct vcpu *vcpu, uint64_t mmio_gpa, struct vie *vie,
struct vm_guest_paging *paging, mem_region_read_t memread,
mem_region_write_t memwrite, void *arg)
{
@@ -1632,13 +1627,13 @@ emulate_push(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
if ((vie->reg & 7) != 6)
return (EINVAL);
- error = emulate_stack_op(vm, vcpuid, mmio_gpa, vie, paging, memread,
+ error = emulate_stack_op(vcpu, mmio_gpa, vie, paging, memread,
memwrite, arg);
return (error);
}
static int
-emulate_pop(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
+emulate_pop(struct vcpu *vcpu, uint64_t mmio_gpa, struct vie *vie,
struct vm_guest_paging *paging, mem_region_read_t memread,
mem_region_write_t memwrite, void *arg)
{
@@ -1653,29 +1648,29 @@ emulate_pop(void *vm, int vcpuid, uint64_t mmio_gpa, struct vie *vie,
if ((vie->reg & 7) != 0)
return (EINVAL);
- error = emulate_stack_op(vm, vcpuid, mmio_gpa, vie, paging, memread,
+ error = emulate_stack_op(vcpu, mmio_gpa, vie, paging, memread,
memwrite, arg);
return (error);
}
static int
-emulate_group1(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- struct vm_guest_paging *paging, mem_region_read_t memread,
+emulate_group1(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ struct vm_guest_paging *paging __unused, mem_region_read_t memread,
mem_region_write_t memwrite, void *memarg)
{
int error;
switch (vie->reg & 7) {
case 0x1: /* OR */
- error = emulate_or(vm, vcpuid, gpa, vie,
+ error = emulate_or(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case 0x4: /* AND */
- error = emulate_and(vm, vcpuid, gpa, vie,
+ error = emulate_and(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case 0x7: /* CMP */
- error = emulate_cmp(vm, vcpuid, gpa, vie,
+ error = emulate_cmp(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
default:
@@ -1687,8 +1682,9 @@ emulate_group1(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
}
static int
-emulate_bittest(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- mem_region_read_t memread, mem_region_write_t memwrite, void *memarg)
+emulate_bittest(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ mem_region_read_t memread, mem_region_write_t memwrite __unused,
+ void *memarg)
{
uint64_t val, rflags;
int error, bitmask, bitoff;
@@ -1702,10 +1698,10 @@ emulate_bittest(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
if ((vie->reg & 7) != 4)
return (EINVAL);
- error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, &rflags);
+ error = vie_read_register(vcpu, VM_REG_GUEST_RFLAGS, &rflags);
KASSERT(error == 0, ("%s: error %d getting rflags", __func__, error));
- error = memread(vm, vcpuid, gpa, &val, vie->opsize, memarg);
+ error = memread(vcpu, gpa, &val, vie->opsize, memarg);
if (error)
return (error);
@@ -1722,15 +1718,16 @@ emulate_bittest(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
else
rflags &= ~PSL_C;
- error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, rflags, 8);
+ error = vie_update_register(vcpu, VM_REG_GUEST_RFLAGS, rflags, 8);
KASSERT(error == 0, ("%s: error %d updating rflags", __func__, error));
return (0);
}
static int
-emulate_twob_group15(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- mem_region_read_t memread, mem_region_write_t memwrite, void *memarg)
+emulate_twob_group15(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
+ mem_region_read_t memread, mem_region_write_t memwrite __unused,
+ void *memarg)
{
int error;
uint64_t buf;
@@ -1748,7 +1745,7 @@ emulate_twob_group15(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
* CLFLUSH, CLFLUSHOPT. Only check for access
* rights.
*/
- error = memread(vm, vcpuid, gpa, &buf, 1, memarg);
+ error = memread(vcpu, gpa, &buf, 1, memarg);
}
break;
default:
@@ -1760,7 +1757,7 @@ emulate_twob_group15(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
}
int
-vmm_emulate_instruction(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+vmm_emulate_instruction(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
struct vm_guest_paging *paging, mem_region_read_t memread,
mem_region_write_t memwrite, void *memarg)
{
@@ -1771,68 +1768,68 @@ vmm_emulate_instruction(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
switch (vie->op.op_type) {
case VIE_OP_TYPE_GROUP1:
- error = emulate_group1(vm, vcpuid, gpa, vie, paging, memread,
+ error = emulate_group1(vcpu, gpa, vie, paging, memread,
memwrite, memarg);
break;
case VIE_OP_TYPE_POP:
- error = emulate_pop(vm, vcpuid, gpa, vie, paging, memread,
+ error = emulate_pop(vcpu, gpa, vie, paging, memread,
memwrite, memarg);
break;
case VIE_OP_TYPE_PUSH:
- error = emulate_push(vm, vcpuid, gpa, vie, paging, memread,
+ error = emulate_push(vcpu, gpa, vie, paging, memread,
memwrite, memarg);
break;
case VIE_OP_TYPE_CMP:
- error = emulate_cmp(vm, vcpuid, gpa, vie,
+ error = emulate_cmp(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_MOV:
- error = emulate_mov(vm, vcpuid, gpa, vie,
+ error = emulate_mov(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_MOVSX:
case VIE_OP_TYPE_MOVZX:
- error = emulate_movx(vm, vcpuid, gpa, vie,
+ error = emulate_movx(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_MOVS:
- error = emulate_movs(vm, vcpuid, gpa, vie, paging, memread,
+ error = emulate_movs(vcpu, gpa, vie, paging, memread,
memwrite, memarg);
break;
case VIE_OP_TYPE_STOS:
- error = emulate_stos(vm, vcpuid, gpa, vie, paging, memread,
+ error = emulate_stos(vcpu, gpa, vie, paging, memread,
memwrite, memarg);
break;
case VIE_OP_TYPE_AND:
- error = emulate_and(vm, vcpuid, gpa, vie,
+ error = emulate_and(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_OR:
- error = emulate_or(vm, vcpuid, gpa, vie,
+ error = emulate_or(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_SUB:
- error = emulate_sub(vm, vcpuid, gpa, vie,
+ error = emulate_sub(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_BITTEST:
- error = emulate_bittest(vm, vcpuid, gpa, vie,
+ error = emulate_bittest(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_TWOB_GRP15:
- error = emulate_twob_group15(vm, vcpuid, gpa, vie,
+ error = emulate_twob_group15(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_ADD:
- error = emulate_add(vm, vcpuid, gpa, vie, memread,
+ error = emulate_add(vcpu, gpa, vie, memread,
memwrite, memarg);
break;
case VIE_OP_TYPE_TEST:
- error = emulate_test(vm, vcpuid, gpa, vie,
+ error = emulate_test(vcpu, gpa, vie,
memread, memwrite, memarg);
break;
case VIE_OP_TYPE_BEXTR:
- error = emulate_bextr(vm, vcpuid, gpa, vie, paging,
+ error = emulate_bextr(vcpu, gpa, vie, paging,
memread, memwrite, memarg);
break;
default:
@@ -2055,17 +2052,17 @@ ptp_release(void **cookie)
}
static void *
-ptp_hold(struct vm *vm, int vcpu, vm_paddr_t ptpphys, size_t len, void **cookie)
+ptp_hold(struct vcpu *vcpu, vm_paddr_t ptpphys, size_t len, void **cookie)
{
void *ptr;
ptp_release(cookie);
- ptr = vm_gpa_hold(vm, vcpu, ptpphys, len, VM_PROT_RW, cookie);
+ ptr = vm_gpa_hold(vcpu, ptpphys, len, VM_PROT_RW, cookie);
return (ptr);
}
static int
-_vm_gla2gpa(struct vm *vm, int vcpuid, struct vm_guest_paging *paging,
+_vm_gla2gpa(struct vcpu *vcpu, struct vm_guest_paging *paging,
uint64_t gla, int prot, uint64_t *gpa, int *guest_fault, bool check_only)
{
int nlevels, pfcode, ptpshift, ptpindex, retval, usermode, writable;
@@ -2093,7 +2090,7 @@ restart:
* should be generated.
*/
if (!check_only)
- vm_inject_gp(vm, vcpuid);
+ vm_inject_gp(vcpu);
goto fault;
}
@@ -2108,7 +2105,7 @@ restart:
/* Zero out the lower 12 bits. */
ptpphys &= ~0xfff;
- ptpbase32 = ptp_hold(vm, vcpuid, ptpphys, PAGE_SIZE,
+ ptpbase32 = ptp_hold(vcpu, ptpphys, PAGE_SIZE,
&cookie);
if (ptpbase32 == NULL)
@@ -2126,7 +2123,7 @@ restart:
if (!check_only) {
pfcode = pf_error_code(usermode, prot, 0,
pte32);
- vm_inject_pf(vm, vcpuid, pfcode, gla);
+ vm_inject_pf(vcpu, pfcode, gla);
}
goto fault;
}
@@ -2170,7 +2167,7 @@ restart:
/* Zero out the lower 5 bits and the upper 32 bits */
ptpphys &= 0xffffffe0UL;
- ptpbase = ptp_hold(vm, vcpuid, ptpphys, sizeof(*ptpbase) * 4,
+ ptpbase = ptp_hold(vcpu, ptpphys, sizeof(*ptpbase) * 4,
&cookie);
if (ptpbase == NULL)
goto error;
@@ -2182,7 +2179,7 @@ restart:
if ((pte & PG_V) == 0) {
if (!check_only) {
pfcode = pf_error_code(usermode, prot, 0, pte);
- vm_inject_pf(vm, vcpuid, pfcode, gla);
+ vm_inject_pf(vcpu, pfcode, gla);
}
goto fault;
}
@@ -2200,7 +2197,7 @@ restart:
/* Zero out the lower 12 bits and the upper 12 bits */
ptpphys >>= 12; ptpphys <<= 24; ptpphys >>= 12;
- ptpbase = ptp_hold(vm, vcpuid, ptpphys, PAGE_SIZE, &cookie);
+ ptpbase = ptp_hold(vcpu, ptpphys, PAGE_SIZE, &cookie);
if (ptpbase == NULL)
goto error;
@@ -2215,7 +2212,7 @@ restart:
(writable && (pte & PG_RW) == 0)) {
if (!check_only) {
pfcode = pf_error_code(usermode, prot, 0, pte);
- vm_inject_pf(vm, vcpuid, pfcode, gla);
+ vm_inject_pf(vcpu, pfcode, gla);
}
goto fault;
}
@@ -2233,7 +2230,7 @@ restart:
if (!check_only) {
pfcode = pf_error_code(usermode, prot, 1,
pte);
- vm_inject_pf(vm, vcpuid, pfcode, gla);
+ vm_inject_pf(vcpu, pfcode, gla);
}
goto fault;
}
@@ -2266,25 +2263,25 @@ fault:
}
int
-vm_gla2gpa(struct vm *vm, int vcpuid, struct vm_guest_paging *paging,
+vm_gla2gpa(struct vcpu *vcpu, struct vm_guest_paging *paging,
uint64_t gla, int prot, uint64_t *gpa, int *guest_fault)
{
- return (_vm_gla2gpa(vm, vcpuid, paging, gla, prot, gpa, guest_fault,
+ return (_vm_gla2gpa(vcpu, paging, gla, prot, gpa, guest_fault,
false));
}
int
-vm_gla2gpa_nofault(struct vm *vm, int vcpuid, struct vm_guest_paging *paging,
+vm_gla2gpa_nofault(struct vcpu *vcpu, struct vm_guest_paging *paging,
uint64_t gla, int prot, uint64_t *gpa, int *guest_fault)
{
- return (_vm_gla2gpa(vm, vcpuid, paging, gla, prot, gpa, guest_fault,
+ return (_vm_gla2gpa(vcpu, paging, gla, prot, gpa, guest_fault,
true));
}
int
-vmm_fetch_instruction(struct vm *vm, int vcpuid, struct vm_guest_paging *paging,
+vmm_fetch_instruction(struct vcpu *vcpu, struct vm_guest_paging *paging,
uint64_t rip, int inst_length, struct vie *vie, int *faultptr)
{
struct vm_copyinfo copyinfo[2];
@@ -2294,13 +2291,13 @@ vmm_fetch_instruction(struct vm *vm, int vcpuid, struct vm_guest_paging *paging,
panic("vmm_fetch_instruction: invalid length %d", inst_length);
prot = PROT_READ | PROT_EXEC;
- error = vm_copy_setup(vm, vcpuid, paging, rip, inst_length, prot,
+ error = vm_copy_setup(vcpu, paging, rip, inst_length, prot,
copyinfo, nitems(copyinfo), faultptr);
if (error || *faultptr)
return (error);
- vm_copyin(vm, vcpuid, copyinfo, vie->inst, inst_length);
- vm_copy_teardown(vm, vcpuid, copyinfo, nitems(copyinfo));
+ vm_copyin(copyinfo, vie->inst, inst_length);
+ vm_copy_teardown(copyinfo, nitems(copyinfo));
vie->num_valid = inst_length;
return (0);
}
@@ -2812,7 +2809,7 @@ decode_moffset(struct vie *vie)
* page table fault matches with our instruction decoding.
*/
static int
-verify_gla(struct vm *vm, int cpuid, uint64_t gla, struct vie *vie,
+verify_gla(struct vcpu *vcpu, uint64_t gla, struct vie *vie,
enum vm_cpu_mode cpu_mode)
{
int error;
@@ -2826,7 +2823,7 @@ verify_gla(struct vm *vm, int cpuid, uint64_t gla, struct vie *vie,
base = 0;
if (vie->base_register != VM_REG_LAST) {
- error = vm_get_register(vm, cpuid, vie->base_register, &base);
+ error = vm_get_register(vcpu, vie->base_register, &base);
if (error) {
printf("verify_gla: error %d getting base reg %d\n",
error, vie->base_register);
@@ -2843,7 +2840,7 @@ verify_gla(struct vm *vm, int cpuid, uint64_t gla, struct vie *vie,
idx = 0;
if (vie->index_register != VM_REG_LAST) {
- error = vm_get_register(vm, cpuid, vie->index_register, &idx);
+ error = vm_get_register(vcpu, vie->index_register, &idx);
if (error) {
printf("verify_gla: error %d getting index reg %d\n",
error, vie->index_register);
@@ -2875,7 +2872,7 @@ verify_gla(struct vm *vm, int cpuid, uint64_t gla, struct vie *vie,
seg != VM_REG_GUEST_GS) {
segbase = 0;
} else {
- error = vm_get_seg_desc(vm, cpuid, seg, &desc);
+ error = vm_get_seg_desc(vcpu, seg, &desc);
if (error) {
printf("verify_gla: error %d getting segment"
" descriptor %d", error,
@@ -2902,7 +2899,7 @@ verify_gla(struct vm *vm, int cpuid, uint64_t gla, struct vie *vie,
int
#ifdef _KERNEL
-vmm_decode_instruction(struct vm *vm, int cpuid, uint64_t gla,
+vmm_decode_instruction(struct vcpu *vcpu, uint64_t gla,
enum vm_cpu_mode cpu_mode, int cs_d, struct vie *vie)
#else
vmm_decode_instruction(enum vm_cpu_mode cpu_mode, int cs_d, struct vie *vie)
@@ -2932,7 +2929,7 @@ vmm_decode_instruction(enum vm_cpu_mode cpu_mode, int cs_d, struct vie *vie)
#ifdef _KERNEL
if ((vie->op.op_flags & VIE_OP_F_NO_GLA_VERIFICATION) == 0) {
- if (verify_gla(vm, cpuid, gla, vie, cpu_mode))
+ if (verify_gla(vcpu, gla, vie, cpu_mode))
return (-1);
}
#endif