1 /* 2 * Copyright (C) 2015 Mihai Carabas <mihai.carabas@gmail.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #ifndef _VMM_INSTRUCTION_EMUL_H_ 28 #define _VMM_INSTRUCTION_EMUL_H_ 29 30 /* 31 * Callback functions to read and write memory regions. 32 */ 33 typedef int (*mem_region_read_t)(struct vcpu *vcpu, uint64_t gpa, 34 uint64_t *rval, int rsize, void *arg); 35 typedef int (*mem_region_write_t)(struct vcpu *vcpu, uint64_t gpa, 36 uint64_t wval, int wsize, void *arg); 37 38 /* 39 * Callback functions to read and write registers. 40 */ 41 typedef int (*reg_read_t)(struct vcpu *vcpu, uint64_t *rval, void *arg); 42 typedef int (*reg_write_t)(struct vcpu *vcpu, uint64_t wval, void *arg); 43 44 /* 45 * Emulate the decoded 'vie' instruction when it contains a memory operation. 46 * 47 * The callbacks 'mrr' and 'mrw' emulate reads and writes to the memory region 48 * containing 'gpa'. 'mrarg' is an opaque argument that is passed into the 49 * callback functions. 50 * 51 * 'void *vm' should be 'struct vm *' when called from kernel context and 52 * 'struct vmctx *' when called from user context. 53 * 54 */ 55 int vmm_emulate_instruction(struct vcpu *vcpu, uint64_t gpa, struct vie *vie, 56 struct vm_guest_paging *paging, mem_region_read_t mrr, 57 mem_region_write_t mrw, void *mrarg); 58 59 /* 60 * Emulate the decoded 'vre' instruction when it contains a register access. 61 * 62 * The callbacks 'regread' and 'regwrite' emulate reads and writes to the 63 * register from 'vie'. 'regarg' is an opaque argument that is passed into the 64 * callback functions. 65 * 66 * 'void *vm' should be 'struct vm *' when called from kernel context and 67 * 'struct vmctx *' when called from user context. 68 * 69 */ 70 int vmm_emulate_register(struct vcpu *vcpu, struct vre *vre, reg_read_t regread, 71 reg_write_t regwrite, void *regarg); 72 73 #ifdef _KERNEL 74 void vm_register_reg_handler(struct vm *vm, uint64_t iss, uint64_t mask, 75 reg_read_t reg_read, reg_write_t reg_write, void *arg); 76 void vm_deregister_reg_handler(struct vm *vm, uint64_t iss, uint64_t mask); 77 78 void vm_register_inst_handler(struct vm *vm, uint64_t start, uint64_t size, 79 mem_region_read_t mmio_read, mem_region_write_t mmio_write); 80 void vm_deregister_inst_handler(struct vm *vm, uint64_t start, uint64_t size); 81 #endif 82 83 #endif /* _VMM_INSTRUCTION_EMUL_H_ */ 84