diff options
author | neel <neel@FreeBSD.org> | 2014-07-23 04:28:51 +0000 |
---|---|---|
committer | neel <neel@FreeBSD.org> | 2014-07-23 04:28:51 +0000 |
commit | e972917c13728442e9cd66ca3f86623f7f7ab351 (patch) | |
tree | 0b8a520e692386324f53c5972af0ec0ef5523d3c /lib/libvmmapi | |
parent | 607bced4fa031f2dbd13539133b0971e2034c49e (diff) | |
download | FreeBSD-src-e972917c13728442e9cd66ca3f86623f7f7ab351.zip FreeBSD-src-e972917c13728442e9cd66ca3f86623f7f7ab351.tar.gz |
Emulate instructions emitted by OpenBSD/i386 version 5.5:
- CMP REG, r/m
- MOV AX/EAX/RAX, moffset
- MOV moffset, AX/EAX/RAX
- PUSH r/m
Diffstat (limited to 'lib/libvmmapi')
-rw-r--r-- | lib/libvmmapi/vmmapi.c | 40 | ||||
-rw-r--r-- | lib/libvmmapi/vmmapi.h | 9 |
2 files changed, 47 insertions, 2 deletions
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c index 483aa51..087d0b7 100644 --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <sys/_iovec.h> #include <sys/cpuset.h> +#include <x86/segments.h> #include <machine/specialreg.h> #include <machine/param.h> @@ -327,6 +328,16 @@ vm_get_desc(struct vmctx *ctx, int vcpu, int reg, } int +vm_get_seg_desc(struct vmctx *ctx, int vcpu, int reg, struct seg_desc *seg_desc) +{ + int error; + + error = vm_get_desc(ctx, vcpu, reg, &seg_desc->base, &seg_desc->limit, + &seg_desc->access); + return (error); +} + +int vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val) { int error; @@ -988,7 +999,7 @@ gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, #endif int -vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, +vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt) { uint64_t gpa; @@ -1135,3 +1146,30 @@ vm_set_intinfo(struct vmctx *ctx, int vcpu, uint64_t info1) error = ioctl(ctx->fd, VM_SET_INTINFO, &vmii); return (error); } + +void +vm_inject_ss(struct vmctx *ctx, int vcpu, int errcode) +{ + int error; + + error = vm_inject_exception2(ctx, vcpu, IDT_SS, errcode); + assert(error == 0); +} + +void +vm_inject_ac(struct vmctx *ctx, int vcpu, int errcode) +{ + int error; + + error = vm_inject_exception2(ctx, vcpu, IDT_AC, errcode); + assert(error == 0); +} + +void +vm_inject_gp(struct vmctx *ctx, int vcpu, int errcode) +{ + int error; + + error = vm_inject_exception2(ctx, vcpu, IDT_GP, errcode); + assert(error == 0); +} diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h index 2040c91..72d75c0 100644 --- a/lib/libvmmapi/vmmapi.h +++ b/lib/libvmmapi/vmmapi.h @@ -66,6 +66,8 @@ int vm_set_desc(struct vmctx *ctx, int vcpu, int reg, uint64_t base, uint32_t limit, uint32_t access); int vm_get_desc(struct vmctx *ctx, int vcpu, int reg, uint64_t *base, uint32_t *limit, uint32_t *access); +int vm_get_seg_desc(struct vmctx *ctx, int vcpu, int reg, + struct seg_desc *seg_desc); int vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val); int vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *retval); int vm_run(struct vmctx *ctx, int vcpu, uint64_t rip, @@ -124,13 +126,18 @@ int vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities); * The 'iovcnt' should be big enough to accomodate all GPA segments. * Returns 0 on success, 1 on a guest fault condition and -1 otherwise. */ -int vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, +int vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *pg, uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt); void vm_copyin(struct vmctx *ctx, int vcpu, struct iovec *guest_iov, void *host_dst, size_t len); void vm_copyout(struct vmctx *ctx, int vcpu, const void *host_src, struct iovec *guest_iov, size_t len); +/* Helper functions to inject exceptions */ +void vm_inject_ss(struct vmctx *ctx, int vcpu, int errcode); +void vm_inject_ac(struct vmctx *ctx, int vcpu, int errcode); +void vm_inject_gp(struct vmctx *ctx, int vcpu, int errcode); + /* Reset vcpu register state */ int vcpu_reset(struct vmctx *ctx, int vcpu); |