*/
-int handle_cr0_write(struct guest_info * info);
-int handle_cr0_read(struct guest_info * info);
+int v3_handle_cr0_write(struct guest_info * info);
+int v3_handle_cr0_read(struct guest_info * info);
-int handle_cr3_write(struct guest_info * info);
-int handle_cr3_read(struct guest_info * info);
+int v3_handle_cr3_write(struct guest_info * info);
+int v3_handle_cr3_read(struct guest_info * info);
#endif // ! __V3VEE__
#include <palacios/vmm.h>
-typedef enum {INVALID_OPERAND, REG_OPERAND, MEM_OPERAND, IMM_OPERAND} operand_type_t;
+typedef enum {INVALID_OPERAND, REG_OPERAND, MEM_OPERAND, IMM_OPERAND} v3_operand_type_t;
struct x86_operand {
addr_t operand;
uint_t size;
- operand_type_t type;
+ v3_operand_type_t type;
};
struct x86_prefixes {
/*
* Initializes a decoder
*/
-int init_decoder();
+int v3_init_decoder();
/*
* Decodes an instruction
/* Removes a rep prefix in place */
-void strip_rep_prefix(uchar_t * instr, int length);
+void v3_strip_rep_prefix(uchar_t * instr, int length);
#define PREFIX_OP_SIZE 0x66
#define PREFIX_ADDR_SIZE 0x67
-int opcode_cmp(const uchar_t * op1, const uchar_t * op2);
+int v3_opcode_cmp(const uchar_t * op1, const uchar_t * op2);
static inline int is_prefix_byte(uchar_t byte) {
-static inline operand_type_t decode_operands16(struct v3_gprs * gprs, // input/output
+static inline v3_operand_type_t decode_operands16(struct v3_gprs * gprs, // input/output
char * modrm_instr, // input
int * offset, // output
addr_t * first_operand, // output
struct modrm_byte * modrm = (struct modrm_byte *)modrm_instr;
addr_t base_addr = 0;
modrm_mode_t mod_mode = 0;
- operand_type_t addr_type = INVALID_OPERAND;
+ v3_operand_type_t addr_type = INVALID_OPERAND;
char * instr_cursor = modrm_instr;
// PrintDebug("ModRM mod=%d\n", modrm->mod);
-static inline operand_type_t decode_operands32(struct v3_gprs * gprs, // input/output
+static inline v3_operand_type_t decode_operands32(struct v3_gprs * gprs, // input/output
uchar_t * modrm_instr, // input
int * offset, // output
addr_t * first_operand, // output
addr_t base_addr = 0;
modrm_mode_t mod_mode = 0;
uint_t has_sib_byte = 0;
- operand_type_t addr_type = INVALID_OPERAND;
+ v3_operand_type_t addr_type = INVALID_OPERAND;
};
-int init_emulator(struct guest_info * info);
+int v3_init_emulator(struct guest_info * info);
int v3_emulation_exit_handler(struct guest_info * info);
-void init_interrupt_state(struct guest_info * info);
+void v3_init_interrupt_state(struct guest_info * info);
int v3_raise_irq(struct guest_info * info, int irq);
-
-/*Zheng 07/30/2008*/
int v3_lower_irq(struct guest_info * info, int irq);
-/*Zheng 07/30/2008*/
struct intr_ctrl_ops {
int (*intr_pending)(void * private_data);
-void set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state);
+void v3_set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state);
int v3_raise_exception(struct guest_info * info, uint_t excp);
int v3_raise_exception_with_error(struct guest_info * info, uint_t excp, uint_t error_code);
-int intr_pending(struct guest_info * info);
-uint_t get_intr_number(struct guest_info * info);
-intr_type_t get_intr_type(struct guest_info * info);
+int v3_intr_pending(struct guest_info * info);
+uint_t v3_get_intr_number(struct guest_info * info);
+intr_type_t v3_get_intr_type(struct guest_info * info);
-int injecting_intr(struct guest_info * info, uint_t intr_num, intr_type_t type);
+int v3_injecting_intr(struct guest_info * info, uint_t intr_num, intr_type_t type);
/*
int start_irq(struct vm_intr * intr);
};
-void init_vmm_io_map(struct guest_info * info);
+void v3_init_vmm_io_map(struct guest_info * info);
// FOREACH_IO_HOOK(vmm_io_map_t * io_map, vmm_io_hook_t * io_hook)
#define FOREACH_IO_HOOK(io_map, io_hook) for (io_hook = (io_map).head; io_hook != NULL; io_hook = (io_hook)->next)
struct vmm_io_hook * v3_get_io_hook(struct vmm_io_map * io_map, uint_t port);
-void PrintDebugIOMap(struct vmm_io_map * io_map);
+void v3_print_io_map(struct vmm_io_map * io_map);
-int cache_page_tables32(struct guest_info * info, addr_t pde);
+int v3_cache_page_tables32(struct guest_info * info, addr_t pde);
-int init_shadow_page_state(struct guest_info * info);
+int v3_init_shadow_page_state(struct guest_info * info);
-addr_t create_new_shadow_pt32();
+addr_t v3_create_new_shadow_pt32();
-int handle_shadow_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code);
-int handle_shadow_invlpg(struct guest_info * info);
+int v3_handle_shadow_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code);
+int v3_handle_shadow_invlpg(struct guest_info * info);
void v3_update_time(struct guest_info * info, ullong_t cycles);
-#endif // !__V3VEE__
-
void v3_init_time(struct guest_info * info);
-
+#endif // !__V3VEE__
#endif
static int pic_init(struct vm_device * dev) {
struct pic_internal * state = (struct pic_internal*)dev->private_data;
- set_intr_controller(dev->vm, &intr_ops, state);
+ v3_set_intr_controller(dev->vm, &intr_ops, state);
state->master_irr = 0;
state->master_isr = 0;
static int pic_init_device(struct vm_device * dev) {
struct pic_internal * data = (struct pic_internal *)dev->private_data;
- set_intr_controller(dev->vm, &intr_ops, data);
+ v3_set_intr_controller(dev->vm, &intr_ops, data);
data->pending_irq = 0;
return 0;
#ifdef DEBUG_CTRL_REGS
PrintDebug("CR0 Write\n");
#endif
- if (handle_cr0_write(info) == -1) {
+ if (v3_handle_cr0_write(info) == -1) {
return -1;
}
}
#ifdef DEBUG_CTRL_REGS
PrintDebug("CR0 Read\n");
#endif
- if (handle_cr0_read(info) == -1) {
+ if (v3_handle_cr0_read(info) == -1) {
return -1;
}
}
#ifdef DEBUG_CTRL_REGS
PrintDebug("CR3 Write\n");
#endif
- if (handle_cr3_write(info) == -1) {
+ if (v3_handle_cr3_write(info) == -1) {
return -1;
}
}
#ifdef DEBUG_CTRL_REGS
PrintDebug("CR3 Read\n");
#endif
- if (handle_cr3_read(info) == -1) {
+ if (v3_handle_cr3_read(info) == -1) {
return -1;
}
}
PrintDebug("PageFault at %x (error=%d)\n", fault_addr, *error_code);
#endif
if (info->shdw_pg_mode == SHADOW_PAGING) {
- if (handle_shadow_pagefault(info, fault_addr, *error_code) == -1) {
+ if (v3_handle_shadow_pagefault(info, fault_addr, *error_code) == -1) {
return -1;
}
} else {
#ifdef DEBUG_SHADOW_PAGING
PrintDebug("Invlpg\n");
#endif
- if (handle_shadow_invlpg(info) == -1) {
+ if (v3_handle_shadow_invlpg(info) == -1) {
return -1;
}
}
// Update the low level state
- if (intr_pending(info)) {
+ if (v3_intr_pending(info)) {
- switch (get_intr_type(info)) {
+ switch (v3_get_intr_type(info)) {
case EXTERNAL_IRQ:
{
- uint_t irq = get_intr_number(info);
+ uint_t irq = v3_get_intr_number(info);
// check to see if ==-1 (non exists)
#ifdef DEBUG_INTERRUPTS
PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->guest_ctrl.V_INTR_VECTOR, info->rip);
#endif
- injecting_intr(info, irq, EXTERNAL_IRQ);
+ v3_injecting_intr(info, irq, EXTERNAL_IRQ);
break;
}
break;
case EXCEPTION:
{
- uint_t excp = get_intr_number(info);
+ uint_t excp = v3_get_intr_number(info);
guest_ctrl->EVENTINJ.type = SVM_INJECTION_EXCEPTION;
#ifdef DEBUG_INTERRUPTS
PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->EVENTINJ.vector, info->rip);
#endif
- injecting_intr(info, excp, EXCEPTION);
+ v3_injecting_intr(info, excp, EXCEPTION);
break;
}
case SOFTWARE_INTR:
v3_cpu_type = V3_INVALID_CPU;
- init_decoder();
+ v3_init_decoder();
if (v3_is_svm_capable()) {
if (v3_cpu_type == V3_SVM_REV3_CPU) {
info->shdw_pg_mode = NESTED_PAGING;
} else {
- init_shadow_page_state(info);
+ v3_init_shadow_page_state(info);
info->shdw_pg_mode = SHADOW_PAGING;
}
info->mem_mode = PHYSICAL_MEM;
- init_vmm_io_map(info);
- init_interrupt_state(info);
+ v3_init_vmm_io_map(info);
+ v3_init_interrupt_state(info);
v3_init_dev_mgr(info);
- init_emulator(info);
+ v3_init_emulator(info);
v3_init_host_events(info);
// First Attempt = 494 lines
// current = 106 lines
-int handle_cr0_write(struct guest_info * info) {
+int v3_handle_cr0_write(struct guest_info * info) {
uchar_t instr[15];
int ret;
struct x86_instr dec_instr;
}
- if (opcode_cmp(V3_OPCODE_LMSW, (const uchar_t *)(dec_instr.opcode)) == 0) {
+ if (v3_opcode_cmp(V3_OPCODE_LMSW, (const uchar_t *)(dec_instr.opcode)) == 0) {
struct cr0_real *real_cr0 = (struct cr0_real*)&(info->ctrl_regs.cr0);
struct cr0_real *new_cr0 = (struct cr0_real *)(dec_instr.src_operand.operand);
uchar_t new_cr0_val;
*(uchar_t*)shadow_cr0 |= new_cr0_val;
PrintDebug("New Shadow CR0=%x\n", *shadow_cr0);
}
- } else if (opcode_cmp(V3_OPCODE_MOV2CR, (const uchar_t *)(dec_instr.opcode)) == 0) {
+ } else if (v3_opcode_cmp(V3_OPCODE_MOV2CR, (const uchar_t *)(dec_instr.opcode)) == 0) {
PrintDebug("MOV2CR0\n");
if (info->cpu_mode == LONG) {
PrintDebug("New CR0=%x\n", *real_cr0);
}
- } else if (opcode_cmp(V3_OPCODE_CLTS, (const uchar_t *)(dec_instr.opcode)) == 0) {
+ } else if (v3_opcode_cmp(V3_OPCODE_CLTS, (const uchar_t *)(dec_instr.opcode)) == 0) {
// CLTS
struct cr0_32 *real_cr0 = (struct cr0_32*)&(info->ctrl_regs.cr0);
// First attempt = 253 lines
// current = 51 lines
-int handle_cr0_read(struct guest_info * info) {
+int v3_handle_cr0_read(struct guest_info * info) {
uchar_t instr[15];
int ret;
struct x86_instr dec_instr;
return -1;
}
- if (opcode_cmp(V3_OPCODE_MOVCR2, (const uchar_t *)(dec_instr.opcode)) == 0) {
+ if (v3_opcode_cmp(V3_OPCODE_MOVCR2, (const uchar_t *)(dec_instr.opcode)) == 0) {
struct cr0_32 * virt_cr0 = (struct cr0_32 *)(dec_instr.dst_operand.operand);
struct cr0_32 * real_cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
PrintDebug("real CR0: %x\n", *(uint_t*)real_cr0);
PrintDebug("returned CR0: %x\n", *(uint_t*)virt_cr0);
- } else if (opcode_cmp(V3_OPCODE_SMSW, (const uchar_t *)(dec_instr.opcode)) == 0) {
+ } else if (v3_opcode_cmp(V3_OPCODE_SMSW, (const uchar_t *)(dec_instr.opcode)) == 0) {
struct cr0_real *real_cr0= (struct cr0_real*)&(info->ctrl_regs.cr0);
struct cr0_real *virt_cr0 = (struct cr0_real *)(dec_instr.dst_operand.operand);
char cr0_val = *(char*)real_cr0 & 0x0f;
// First Attempt = 256 lines
// current = 65 lines
-int handle_cr3_write(struct guest_info * info) {
+int v3_handle_cr3_write(struct guest_info * info) {
int ret;
uchar_t instr[15];
struct x86_instr dec_instr;
return -1;
}
- if (opcode_cmp(V3_OPCODE_MOV2CR, (const uchar_t *)(dec_instr.opcode)) == 0) {
+ if (v3_opcode_cmp(V3_OPCODE_MOV2CR, (const uchar_t *)(dec_instr.opcode)) == 0) {
PrintDebug("MOV2CR3\n");
*(uint_t*)shadow_cr3, *(uint_t*)guest_cr3);
- cached = cache_page_tables32(info, CR3_TO_PDE32(*(addr_t *)new_cr3));
+ cached = v3_cache_page_tables32(info, CR3_TO_PDE32(*(addr_t *)new_cr3));
if (cached == -1) {
PrintError("CR3 Cache failed\n");
delete_page_tables_pde32((pde32_t *)CR3_TO_PDE32(*(uint_t*)shadow_cr3));
- shadow_pt = create_new_shadow_pt32();
+ shadow_pt = v3_create_new_shadow_pt32();
shadow_cr3->pdt_base_addr = PD32_BASE_ADDR(shadow_pt);
} else {
// first attempt = 156 lines
// current = 36 lines
-int handle_cr3_read(struct guest_info * info) {
+int v3_handle_cr3_read(struct guest_info * info) {
uchar_t instr[15];
int ret;
struct x86_instr dec_instr;
return -1;
}
- if (opcode_cmp(V3_OPCODE_MOVCR2, (const uchar_t *)(dec_instr.opcode)) == 0) {
+ if (v3_opcode_cmp(V3_OPCODE_MOVCR2, (const uchar_t *)(dec_instr.opcode)) == 0) {
PrintDebug("MOVCR32\n");
struct cr3_32 * virt_cr3 = (struct cr3_32 *)(dec_instr.dst_operand.operand);
#include <palacios/vmm_decoder.h>
-int opcode_cmp(const uchar_t * op1, const uchar_t * op2) {
+int v3_opcode_cmp(const uchar_t * op1, const uchar_t * op2) {
if (op1[0] != op2[0]) {
return op1[0] - op2[0];;
} else {
}
-void strip_rep_prefix(uchar_t * instr, int length) {
+void v3_strip_rep_prefix(uchar_t * instr, int length) {
int read_ctr = 0;
int write_ctr = 0;
int found = 0;
#endif
-int init_emulator(struct guest_info * info) {
+int v3_init_emulator(struct guest_info * info) {
struct emulation_state * emulator = &(info->emulator);
emulator->num_emulated_pages = 0;
-void init_interrupt_state(struct guest_info * info) {
+void v3_init_interrupt_state(struct guest_info * info) {
info->intr_state.excp_pending = 0;
info->intr_state.excp_num = 0;
info->intr_state.excp_error_code = 0;
info->vm_ops.lower_irq = &v3_lower_irq;
}
-void set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state) {
+void v3_set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state) {
info->intr_state.controller = ops;
info->intr_state.controller_state = state;
}
-int intr_pending(struct guest_info * info) {
+int v3_intr_pending(struct guest_info * info) {
struct v3_intr_state * intr_state = &(info->intr_state);
// PrintDebug("[intr_pending]\n");
}
-uint_t get_intr_number(struct guest_info * info) {
+uint_t v3_get_intr_number(struct guest_info * info) {
struct v3_intr_state * intr_state = &(info->intr_state);
if (intr_state->excp_pending == 1) {
}
-intr_type_t get_intr_type(struct guest_info * info) {
+intr_type_t v3_get_intr_type(struct guest_info * info) {
struct v3_intr_state * intr_state = &(info->intr_state);
if (intr_state->excp_pending) {
-int injecting_intr(struct guest_info * info, uint_t intr_num, intr_type_t type) {
+int v3_injecting_intr(struct guest_info * info, uint_t intr_num, intr_type_t type) {
struct v3_intr_state * intr_state = &(info->intr_state);
if (type == EXCEPTION) {
static int default_read(ushort_t port, void * dst, uint_t length, void * priv_data);
-void init_vmm_io_map(struct guest_info * info) {
+void v3_init_vmm_io_map(struct guest_info * info) {
struct vmm_io_map * io_map = &(info->io_map);
io_map->num_ports = 0;
io_map->head = NULL;
-void PrintDebugIOMap(struct vmm_io_map * io_map) {
+void v3_print_io_map(struct vmm_io_map * io_map) {
struct vmm_io_hook * iter = io_map->head;
PrintDebug("VMM IO Map (Entries=%d)\n", io_map->num_ports);
static int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code);
-int init_shadow_page_state(struct guest_info * info) {
+int v3_init_shadow_page_state(struct guest_info * info) {
struct shadow_page_state * state = &(info->shdw_pg_state);
state->guest_mode = PDE32;
state->shadow_mode = PDE32;
}
*/
-int cache_page_tables32(struct guest_info * info, addr_t pde) {
+int v3_cache_page_tables32(struct guest_info * info, addr_t pde) {
struct shadow_page_state * state = &(info->shdw_pg_state);
addr_t pde_host_addr;
pde32_t * tmp_pde;
-int handle_shadow_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
+int v3_handle_shadow_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
if (info->mem_mode == PHYSICAL_MEM) {
// If paging is not turned on we need to handle the special cases
}
}
-addr_t create_new_shadow_pt32() {
+addr_t v3_create_new_shadow_pt32() {
void * host_pde = 0;
host_pde = V3_AllocPages(1);
if (shadow_pde_access == PT_ENTRY_NOT_PRESENT)
{
- pte32_t * shadow_pt = (pte32_t *)create_new_shadow_pt32();
+ pte32_t * shadow_pt = (pte32_t *)v3_create_new_shadow_pt32();
shadow_pde->present = 1;
shadow_pde->user_page = guest_pde->user_page;
/* Currently Does not work with Segmentation!!! */
-int handle_shadow_invlpg(struct guest_info * info) {
+int v3_handle_shadow_invlpg(struct guest_info * info) {
if (info->mem_mode != VIRTUAL_MEM) {
// Paging must be turned on...
// should handle with some sort of fault I think
addr_t first_operand;
addr_t second_operand;
- operand_type_t addr_type;
+ v3_operand_type_t addr_type;
addr_t guest_cr3 = CR3_TO_PDE32(info->shdw_pg_state.guest_cr3);
pde32_t * guest_pd = NULL;
return 0;
}
-int is_flags_reg(xed_reg_enum_t xed_reg) {
+static int is_flags_reg(xed_reg_enum_t xed_reg) {
switch (xed_reg) {
case XED_REG_FLAGS:
case XED_REG_EFLAGS:
-int init_decoder() {
+int v3_init_decoder() {
xed_tables_init();
xed_state_zero(&decoder_state);
return 0;