2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #ifdef __DECODER_TEST__
21 #include "vmm_decoder.h"
23 #include <xed/xed-interface.h>
29 #include <palacios/vmm_decoder.h>
30 #include <palacios/vmm_xed.h>
31 #include <xed/xed-interface.h>
32 #include <palacios/vm_guest.h>
33 #include <palacios/vmm.h>
38 #ifndef CONFIG_DEBUG_XED
40 #define PrintDebug(fmt, args...)
46 static uint_t tables_inited = 0;
49 #define GPR_REGISTER 0
50 #define SEGMENT_REGISTER 1
51 #define CTRL_REGISTER 2
52 #define DEBUG_REGISTER 3
56 /* Disgusting mask hack...
57 I can't think right now, so we'll do it this way...
59 static const ullong_t mask_1 = 0x00000000000000ffLL;
60 static const ullong_t mask_2 = 0x000000000000ffffLL;
61 static const ullong_t mask_4 = 0x00000000ffffffffLL;
62 static const ullong_t mask_8 = 0xffffffffffffffffLL;
65 #define MASK(val, length) ({ \
66 ullong_t mask = 0x0LL; \
84 struct memory_operand {
92 uint_t displacement_size;
93 ullong_t displacement;
99 static v3_op_type_t get_opcode(xed_iform_enum_t iform);
101 static int xed_reg_to_v3_reg(struct guest_info * info, xed_reg_enum_t xed_reg, addr_t * v3_reg, uint_t * reg_len);
102 static int get_memory_operand(struct guest_info * info, xed_decoded_inst_t * xed_instr, uint_t index, struct x86_operand * operand);
104 static int set_decoder_mode(struct guest_info * info, xed_state_t * state) {
105 switch (v3_get_vm_cpu_mode(info)) {
107 if (state->mmode != XED_MACHINE_MODE_LEGACY_16) {
108 xed_state_init(state,
109 XED_MACHINE_MODE_LEGACY_16,
110 XED_ADDRESS_WIDTH_16b,
111 XED_ADDRESS_WIDTH_16b);
116 if (state->mmode != XED_MACHINE_MODE_LEGACY_32) {
117 xed_state_init(state,
118 XED_MACHINE_MODE_LEGACY_32,
119 XED_ADDRESS_WIDTH_32b,
120 XED_ADDRESS_WIDTH_32b);
124 if (state->mmode != XED_MACHINE_MODE_LONG_COMPAT_32) {
125 xed_state_init(state,
126 XED_MACHINE_MODE_LONG_COMPAT_32,
127 XED_ADDRESS_WIDTH_32b,
128 XED_ADDRESS_WIDTH_32b);
132 if (state->mmode != XED_MACHINE_MODE_LONG_64) {
133 PrintDebug("Setting decoder to long mode\n");
134 // state->mmode = XED_MACHINE_MODE_LONG_64;
135 //xed_state_set_machine_mode(state, XED_MACHINE_MODE_LONG_64);
136 xed_state_init(state,
137 XED_MACHINE_MODE_LONG_64,
138 XED_ADDRESS_WIDTH_64b,
139 XED_ADDRESS_WIDTH_64b);
143 PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
150 static int is_flags_reg(xed_reg_enum_t xed_reg) {
162 int v3_init_decoder(struct guest_info * info) {
163 // Global library initialization, only do it once
164 if (tables_inited == 0) {
169 xed_state_t * decoder_state = (xed_state_t *)V3_Malloc(sizeof(xed_state_t));
170 xed_state_zero(decoder_state);
171 xed_state_init(decoder_state,
172 XED_MACHINE_MODE_LEGACY_32,
173 XED_ADDRESS_WIDTH_32b,
174 XED_ADDRESS_WIDTH_32b);
176 info->decoder_state = decoder_state;
183 int v3_basic_mem_decode(struct guest_info * info, addr_t instr_ptr, struct basic_instr_info * instr_info) {
184 xed_decoded_inst_t xed_instr;
185 xed_error_enum_t xed_error;
188 if (set_decoder_mode(info, info->decoder_state) == -1) {
189 PrintError("Could not set decoder mode\n");
194 xed_decoded_inst_zero_set_mode(&xed_instr, info->decoder_state);
196 xed_error = xed_decode(&xed_instr,
197 REINTERPRET_CAST(const xed_uint8_t *, instr_ptr),
198 XED_MAX_INSTRUCTION_BYTES);
200 if (xed_error != XED_ERROR_NONE) {
201 PrintError("Xed error: %s\n", xed_error_enum_t2str(xed_error));
205 instr_info->instr_length = xed_decoded_inst_get_length(&xed_instr);
208 if (xed_decoded_inst_number_of_memory_operands(&xed_instr) == 0) {
209 PrintError("Tried to decode memory operation with no memory operands\n");
213 instr_info->op_size = xed_decoded_inst_get_memory_operand_length(&xed_instr, 0);
216 xed_category_enum_t cat = xed_decoded_inst_get_category(&xed_instr);
217 if (cat == XED_CATEGORY_STRINGOP) {
218 instr_info->str_op = 1;
220 instr_info->str_op = 0;
223 xed_operand_values_t * operands = xed_decoded_inst_operands(&xed_instr);
224 if (xed_operand_values_has_real_rep(operands)) {
225 instr_info->has_rep = 1;
227 instr_info->has_rep = 0;
234 static int decode_string_op(struct guest_info * info,
235 xed_decoded_inst_t * xed_instr, const xed_inst_t * xi,
236 struct x86_instr * instr) {
238 PrintDebug("String operation\n");
240 if (instr->op_type == V3_OP_MOVS) {
241 instr->num_operands = 2;
243 if (get_memory_operand(info, xed_instr, 0, &(instr->dst_operand)) == -1) {
244 PrintError("Could not get Destination memory operand\n");
248 if (get_memory_operand(info, xed_instr, 1, &(instr->src_operand)) == -1) {
249 PrintError("Could not get Source memory operand\n");
253 if (instr->prefixes.rep == 1) {
255 uint_t reg_length = 0;
257 xed_reg_to_v3_reg(info, xed_decoded_inst_get_reg(xed_instr, XED_OPERAND_REG0), ®_addr, ®_length);
258 instr->str_op_length = MASK(*(addr_t *)reg_addr, reg_length);
260 instr->str_op_length = 1;
263 } else if (instr->op_type == V3_OP_STOS) {
264 instr->num_operands = 2;
266 if (get_memory_operand(info, xed_instr, 0, &(instr->dst_operand)) == -1) {
267 PrintError("Could not get Destination memory operand\n");
271 // STOS reads from rax
272 xed_reg_to_v3_reg(info, xed_decoded_inst_get_reg(xed_instr, XED_OPERAND_REG0),
273 &(instr->src_operand.operand),
274 &(instr->src_operand.size));
275 instr->src_operand.type = REG_OPERAND;
277 if (instr->prefixes.rep == 1) {
279 uint_t reg_length = 0;
281 xed_reg_to_v3_reg(info, xed_decoded_inst_get_reg(xed_instr, XED_OPERAND_REG1), ®_addr, ®_length);
282 instr->str_op_length = MASK(*(addr_t *)reg_addr, reg_length);
284 instr->str_op_length = 1;
288 PrintError("Unhandled String OP\n");
297 int v3_decode(struct guest_info * info, addr_t instr_ptr, struct x86_instr * instr) {
298 xed_decoded_inst_t xed_instr;
299 xed_error_enum_t xed_error;
302 v3_get_prefixes((uchar_t *)instr_ptr, &(instr->prefixes));
304 if (set_decoder_mode(info, info->decoder_state) == -1) {
305 PrintError("Could not set decoder mode\n");
309 xed_decoded_inst_zero_set_mode(&xed_instr, info->decoder_state);
311 xed_error = xed_decode(&xed_instr,
312 REINTERPRET_CAST(const xed_uint8_t *, instr_ptr),
313 XED_MAX_INSTRUCTION_BYTES);
316 if (xed_error != XED_ERROR_NONE) {
317 PrintError("Xed error: %s\n", xed_error_enum_t2str(xed_error));
321 const xed_inst_t * xi = xed_decoded_inst_inst(&xed_instr);
323 instr->instr_length = xed_decoded_inst_get_length(&xed_instr);
326 xed_iform_enum_t iform = xed_decoded_inst_get_iform_enum(&xed_instr);
328 #ifdef CONFIG_DEBUG_XED
329 xed_iclass_enum_t iclass = xed_decoded_inst_get_iclass(&xed_instr);
331 PrintDebug("iform=%s, iclass=%s\n", xed_iform_enum_t2str(iform), xed_iclass_enum_t2str(iclass));
335 if ((instr->op_type = get_opcode(iform)) == V3_INVALID_OP) {
336 PrintError("Could not get opcode. (iform=%s)\n", xed_iform_enum_t2str(iform));
341 // We special case the string operations...
342 if (xed_decoded_inst_get_category(&xed_instr) == XED_CATEGORY_STRINGOP) {
343 instr->is_str_op = 1;
344 return decode_string_op(info, &xed_instr, xi, instr);
346 instr->is_str_op = 0;
347 instr->str_op_length = 0;
350 instr->num_operands = xed_decoded_inst_noperands(&xed_instr);
353 if (instr->num_operands > 3) {
354 PrintDebug("Special Case Not Handled (more than 3 operands) (iform=%s)\n", xed_iform_enum_t2str(iform)
357 } else if (instr->num_operands == 3) {
358 const xed_operand_t * op = xed_inst_operand(xi, 2);
359 xed_operand_enum_t op_enum = xed_operand_name(op);
361 if ((!xed_operand_is_register(op_enum)) ||
362 (!is_flags_reg(xed_decoded_inst_get_reg(&xed_instr, op_enum)))) {
364 PrintError("Special Case not handled (iform=%s)\n", xed_iform_enum_t2str(iform));
370 //PrintDebug("Number of operands: %d\n", instr->num_operands);
371 //PrintDebug("INSTR length: %d\n", instr->instr_length);
374 if (instr->num_operands >= 1) {
375 const xed_operand_t * op = xed_inst_operand(xi, 0);
376 xed_operand_enum_t op_enum = xed_operand_name(op);
378 struct x86_operand * v3_op = NULL;
381 if (xed_operand_written(op)) {
382 v3_op = &(instr->dst_operand);
384 v3_op = &(instr->src_operand);
388 v3_op = &(instr->dst_operand);
390 if (xed_operand_is_register(op_enum)) {
391 xed_reg_enum_t xed_reg = xed_decoded_inst_get_reg(&xed_instr, op_enum);
392 int v3_reg_type = xed_reg_to_v3_reg(info,
397 if (v3_reg_type == -1) {
398 PrintError("First operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
399 v3_op->type = INVALID_OPERAND;
401 } else if (v3_reg_type == SEGMENT_REGISTER) {
402 struct v3_segment * seg_reg = (struct v3_segment *)(v3_op->operand);
403 v3_op->operand = (addr_t)&(seg_reg->selector);
406 v3_op->type = REG_OPERAND;
411 case XED_OPERAND_MEM0:
413 PrintDebug("Memory operand (1)\n");
414 if (get_memory_operand(info, &xed_instr, 0, v3_op) == -1) {
415 PrintError("Could not get first memory operand\n");
421 case XED_OPERAND_MEM1:
422 case XED_OPERAND_IMM1:
424 PrintError("Illegal Operand Order\n");
428 case XED_OPERAND_IMM0:
429 case XED_OPERAND_AGEN:
430 case XED_OPERAND_PTR:
431 case XED_OPERAND_RELBR:
433 PrintError("Unhandled Operand Type\n");
439 // set second operand
440 if (instr->num_operands >= 2) {
441 const xed_operand_t * op = xed_inst_operand(xi, 1);
442 // xed_operand_type_enum_t op_type = xed_operand_type(op);
443 xed_operand_enum_t op_enum = xed_operand_name(op);
445 struct x86_operand * v3_op;
448 if (xed_operand_written(op)) {
449 v3_op = &(instr->dst_operand);
451 v3_op = &(instr->src_operand);
454 v3_op = &(instr->src_operand);
456 if (xed_operand_is_register(op_enum)) {
457 xed_reg_enum_t xed_reg = xed_decoded_inst_get_reg(&xed_instr, op_enum);
458 int v3_reg_type = xed_reg_to_v3_reg(info,
462 if (v3_reg_type == -1) {
463 PrintError("Second operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
464 v3_op->type = INVALID_OPERAND;
466 } else if (v3_reg_type == SEGMENT_REGISTER) {
467 struct v3_segment * seg_reg = (struct v3_segment *)(v3_op->operand);
468 v3_op->operand = (addr_t)&(seg_reg->selector);
471 v3_op->type = REG_OPERAND;
475 case XED_OPERAND_MEM0:
477 PrintDebug("Memory operand (2)\n");
478 if (get_memory_operand(info, &xed_instr, 0, v3_op) == -1) {
479 PrintError("Could not get first memory operand\n");
485 case XED_OPERAND_IMM0:
487 instr->src_operand.size = xed_decoded_inst_get_immediate_width(&xed_instr);
489 if (instr->src_operand.size > 4) {
490 PrintError("Unhandled 64 bit immediates\n");
493 instr->src_operand.operand = xed_decoded_inst_get_unsigned_immediate(&xed_instr);
495 instr->src_operand.type = IMM_OPERAND;
500 case XED_OPERAND_MEM1:
501 case XED_OPERAND_IMM1:
503 PrintError("Illegal Operand Order\n");
506 case XED_OPERAND_AGEN:
507 case XED_OPERAND_PTR:
508 case XED_OPERAND_RELBR:
510 PrintError("Unhandled Operand Type\n");
517 if (instr->num_operands >= 3) {
518 const xed_operand_t * op = xed_inst_operand(xi, 2);
519 xed_operand_type_enum_t op_type = xed_operand_type(op);
520 xed_operand_enum_t op_enum = xed_operand_name(op);
522 if (xed_operand_is_register(op_enum)) {
523 xed_reg_enum_t xed_reg = xed_decoded_inst_get_reg(&xed_instr, op_enum);
524 int v3_reg_type = xed_reg_to_v3_reg(info,
526 &(instr->third_operand.operand),
527 &(instr->third_operand.size));
529 if (v3_reg_type == -1) {
530 PrintError("Third operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
531 instr->third_operand.type = INVALID_OPERAND;
533 } else if (v3_reg_type == SEGMENT_REGISTER) {
534 struct v3_segment * seg_reg = (struct v3_segment *)(instr->third_operand.operand);
535 instr->third_operand.operand = (addr_t)&(seg_reg->selector);
539 instr->third_operand.type = REG_OPERAND;
542 PrintError("Unhandled third operand type %s\n", xed_operand_type_enum_t2str(op_type));
543 instr->num_operands = 2;
551 int v3_encode(struct guest_info * info, struct x86_instr * instr, char * instr_buf) {
560 static int get_memory_operand(struct guest_info * info, xed_decoded_inst_t * xed_instr, uint_t op_index, struct x86_operand * operand) {
561 struct memory_operand mem_op;
567 ullong_t displacement;
568 int addr_width = v3_get_addr_width(info);
569 v3_cpu_mode_t cpu_mode = v3_get_vm_cpu_mode(info);
570 // struct v3_segment * seg_reg;
572 PrintDebug("Xed mode = %s\n", xed_machine_mode_enum_t2str(xed_state_get_machine_mode(info->decoder_state)));
573 PrintDebug("Address width: %s\n",
574 xed_address_width_enum_t2str(xed_state_get_address_width(info->decoder_state)));
575 PrintDebug("Stack Address width: %s\n",
576 xed_address_width_enum_t2str(xed_state_get_stack_address_width(info->decoder_state)));
580 memset((void*)&mem_op, '\0', sizeof(struct memory_operand));
582 xed_reg_enum_t xed_seg = xed_decoded_inst_get_seg_reg(xed_instr, op_index);
583 if (xed_seg != XED_REG_INVALID) {
584 struct v3_segment *tmp_segment;
585 if (xed_reg_to_v3_reg(info, xed_seg, (addr_t *)&tmp_segment, &(mem_op.segment_size)) == -1) {
586 PrintError("Unhandled Segment Register\n");
589 mem_op.segment = tmp_segment->base;
592 xed_reg_enum_t xed_base = xed_decoded_inst_get_base_reg(xed_instr, op_index);
593 if (xed_base != XED_REG_INVALID) {
595 if (xed_reg_to_v3_reg(info, xed_base, &base_reg, &(mem_op.base_size)) == -1) {
596 PrintError("Unhandled Base register\n");
599 mem_op.base = *(addr_t *)base_reg;
604 xed_reg_enum_t xed_idx = xed_decoded_inst_get_index_reg(xed_instr, op_index);
605 if ((op_index == 0) && (xed_idx != XED_REG_INVALID)) {
608 if (xed_reg_to_v3_reg(info, xed_idx, &index_reg, &(mem_op.index_size)) == -1) {
609 PrintError("Unhandled Index Register\n");
613 mem_op.index= *(addr_t *)index_reg;
615 xed_uint_t xed_scale = xed_decoded_inst_get_scale(xed_instr, op_index);
616 if (xed_scale != 0) {
617 mem_op.scale = xed_scale;
622 xed_uint_t disp_bits = xed_decoded_inst_get_memory_displacement_width(xed_instr, op_index);
624 xed_int64_t xed_disp = xed_decoded_inst_get_memory_displacement(xed_instr, op_index);
626 mem_op.displacement_size = disp_bits;
627 mem_op.displacement = xed_disp;
630 operand->type = MEM_OPERAND;
631 operand->size = xed_decoded_inst_get_memory_operand_length(xed_instr, op_index);
635 PrintDebug("Struct: Seg=%p (size=%d), base=%p, index=%p, scale=%p, displacement=%p (size=%d)\n",
636 (void *)mem_op.segment, mem_op.segment_size, (void*)mem_op.base, (void *)mem_op.index,
637 (void *)mem_op.scale, (void *)(addr_t)mem_op.displacement, mem_op.displacement_size);
640 PrintDebug("operand size: %d\n", operand->size);
642 seg = MASK(mem_op.segment, mem_op.segment_size);
643 base = MASK(mem_op.base, mem_op.base_size);
644 index = MASK(mem_op.index, mem_op.index_size);
645 scale = mem_op.scale;
647 // This is a horrendous hack...
648 // XED really screwed the pooch in calculating the displacement
649 if (cpu_mode == LONG) {
650 displacement = mem_op.displacement;
652 displacement = MASK(mem_op.displacement, mem_op.displacement_size);
655 PrintDebug("Seg=%p, base=%p, index=%p, scale=%p, displacement=%p\n",
656 (void *)seg, (void *)base, (void *)index, (void *)scale, (void *)(addr_t)displacement);
658 if (cpu_mode == REAL) {
659 operand->operand = seg + MASK((base + (scale * index) + displacement), addr_width);
661 operand->operand = MASK((seg + base + (scale * index) + displacement), addr_width);
668 static int xed_reg_to_v3_reg(struct guest_info * info, xed_reg_enum_t xed_reg, addr_t * v3_reg, uint_t * reg_len) {
670 PrintDebug("Xed Register: %s\n", xed_reg_enum_t2str(xed_reg));
673 case XED_REG_INVALID:
682 *v3_reg = (addr_t)&(info->vm_regs.rax);
686 *v3_reg = (addr_t)&(info->vm_regs.rax);
690 *v3_reg = (addr_t)&(info->vm_regs.rax);
694 *v3_reg = (addr_t)(&(info->vm_regs.rax)) + 1;
698 *v3_reg = (addr_t)&(info->vm_regs.rax);
703 *v3_reg = (addr_t)&(info->vm_regs.rcx);
707 *v3_reg = (addr_t)&(info->vm_regs.rcx);
711 *v3_reg = (addr_t)&(info->vm_regs.rcx);
715 *v3_reg = (addr_t)(&(info->vm_regs.rcx)) + 1;
719 *v3_reg = (addr_t)&(info->vm_regs.rcx);
724 *v3_reg = (addr_t)&(info->vm_regs.rdx);
728 *v3_reg = (addr_t)&(info->vm_regs.rdx);
732 *v3_reg = (addr_t)&(info->vm_regs.rdx);
736 *v3_reg = (addr_t)(&(info->vm_regs.rdx)) + 1;
740 *v3_reg = (addr_t)&(info->vm_regs.rdx);
745 *v3_reg = (addr_t)&(info->vm_regs.rbx);
749 *v3_reg = (addr_t)&(info->vm_regs.rbx);
753 *v3_reg = (addr_t)&(info->vm_regs.rbx);
757 *v3_reg = (addr_t)(&(info->vm_regs.rbx)) + 1;
761 *v3_reg = (addr_t)&(info->vm_regs.rbx);
767 *v3_reg = (addr_t)&(info->vm_regs.rsp);
771 *v3_reg = (addr_t)&(info->vm_regs.rsp);
775 *v3_reg = (addr_t)&(info->vm_regs.rsp);
779 *v3_reg = (addr_t)&(info->vm_regs.rsp);
784 *v3_reg = (addr_t)&(info->vm_regs.rbp);
788 *v3_reg = (addr_t)&(info->vm_regs.rbp);
792 *v3_reg = (addr_t)&(info->vm_regs.rbp);
796 *v3_reg = (addr_t)&(info->vm_regs.rbp);
803 *v3_reg = (addr_t)&(info->vm_regs.rsi);
807 *v3_reg = (addr_t)&(info->vm_regs.rsi);
811 *v3_reg = (addr_t)&(info->vm_regs.rsi);
815 *v3_reg = (addr_t)&(info->vm_regs.rsi);
821 *v3_reg = (addr_t)&(info->vm_regs.rdi);
825 *v3_reg = (addr_t)&(info->vm_regs.rdi);
829 *v3_reg = (addr_t)&(info->vm_regs.rdi);
833 *v3_reg = (addr_t)&(info->vm_regs.rdi);
842 *v3_reg = (addr_t)&(info->vm_regs.r8);
846 *v3_reg = (addr_t)&(info->vm_regs.r8);
850 *v3_reg = (addr_t)&(info->vm_regs.r8);
854 *v3_reg = (addr_t)&(info->vm_regs.r8);
859 *v3_reg = (addr_t)&(info->vm_regs.r9);
863 *v3_reg = (addr_t)&(info->vm_regs.r9);
867 *v3_reg = (addr_t)&(info->vm_regs.r9);
871 *v3_reg = (addr_t)&(info->vm_regs.r9);
876 *v3_reg = (addr_t)&(info->vm_regs.r10);
880 *v3_reg = (addr_t)&(info->vm_regs.r10);
884 *v3_reg = (addr_t)&(info->vm_regs.r10);
888 *v3_reg = (addr_t)&(info->vm_regs.r10);
893 *v3_reg = (addr_t)&(info->vm_regs.r11);
897 *v3_reg = (addr_t)&(info->vm_regs.r11);
901 *v3_reg = (addr_t)&(info->vm_regs.r11);
905 *v3_reg = (addr_t)&(info->vm_regs.r11);
910 *v3_reg = (addr_t)&(info->vm_regs.r12);
914 *v3_reg = (addr_t)&(info->vm_regs.r12);
918 *v3_reg = (addr_t)&(info->vm_regs.r12);
922 *v3_reg = (addr_t)&(info->vm_regs.r12);
927 *v3_reg = (addr_t)&(info->vm_regs.r13);
931 *v3_reg = (addr_t)&(info->vm_regs.r13);
935 *v3_reg = (addr_t)&(info->vm_regs.r13);
939 *v3_reg = (addr_t)&(info->vm_regs.r13);
944 *v3_reg = (addr_t)&(info->vm_regs.r14);
948 *v3_reg = (addr_t)&(info->vm_regs.r14);
952 *v3_reg = (addr_t)&(info->vm_regs.r14);
956 *v3_reg = (addr_t)&(info->vm_regs.r14);
961 *v3_reg = (addr_t)&(info->vm_regs.r15);
965 *v3_reg = (addr_t)&(info->vm_regs.r15);
969 *v3_reg = (addr_t)&(info->vm_regs.r15);
973 *v3_reg = (addr_t)&(info->vm_regs.r15);
982 *v3_reg = (addr_t)&(info->rip);
984 return CTRL_REGISTER;
986 *v3_reg = (addr_t)&(info->rip);
988 return CTRL_REGISTER;
990 *v3_reg = (addr_t)&(info->rip);
992 return CTRL_REGISTER;
995 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
997 return CTRL_REGISTER;
999 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
1001 return CTRL_REGISTER;
1002 case XED_REG_RFLAGS:
1003 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
1005 return CTRL_REGISTER;
1008 *v3_reg = (addr_t)&(info->ctrl_regs.cr0);
1010 return CTRL_REGISTER;
1012 *v3_reg = (addr_t)&(info->ctrl_regs.cr2);
1014 return CTRL_REGISTER;
1016 *v3_reg = (addr_t)&(info->ctrl_regs.cr3);
1018 return CTRL_REGISTER;
1020 *v3_reg = (addr_t)&(info->ctrl_regs.cr4);
1022 return CTRL_REGISTER;
1024 *v3_reg = (addr_t)&(info->ctrl_regs.cr8);
1026 return CTRL_REGISTER;
1048 *v3_reg = (addr_t)&(info->segments.cs);
1050 return SEGMENT_REGISTER;
1052 *v3_reg = (addr_t)&(info->segments.ds);
1054 return SEGMENT_REGISTER;
1056 *v3_reg = (addr_t)&(info->segments.es);
1058 return SEGMENT_REGISTER;
1060 *v3_reg = (addr_t)&(info->segments.ss);
1062 return SEGMENT_REGISTER;
1064 *v3_reg = (addr_t)&(info->segments.fs);
1066 return SEGMENT_REGISTER;
1068 *v3_reg = (addr_t)&(info->segments.gs);
1070 return SEGMENT_REGISTER;
1077 PrintError("Segment selector operand... Don't know how to handle this...\n");
1142 case XED_REG_STACKPUSH:
1143 case XED_REG_STACKPOP:
1146 case XED_REG_TSCAUX:
1149 case XED_REG_X87CONTROL:
1150 case XED_REG_X87STATUS:
1151 case XED_REG_X87TOP:
1152 case XED_REG_X87TAG:
1153 case XED_REG_X87PUSH:
1154 case XED_REG_X87POP:
1155 case XED_REG_X87POP2:
1190 static v3_op_type_t get_opcode(xed_iform_enum_t iform) {
1194 /* Control Instructions */
1196 case XED_IFORM_MOV_CR_GPR64_CR:
1197 case XED_IFORM_MOV_CR_GPR32_CR:
1198 return V3_OP_MOVCR2;
1200 case XED_IFORM_MOV_CR_CR_GPR64:
1201 case XED_IFORM_MOV_CR_CR_GPR32:
1202 return V3_OP_MOV2CR;
1204 case XED_IFORM_SMSW_GPRv:
1207 case XED_IFORM_LMSW_GPR16:
1210 case XED_IFORM_CLTS:
1213 case XED_IFORM_INVLPG_MEMb:
1214 return V3_OP_INVLPG;
1217 /* Data Instructions */
1220 case XED_IFORM_ADC_MEMv_GPRv:
1221 case XED_IFORM_ADC_MEMv_IMM:
1222 case XED_IFORM_ADC_MEMb_GPR8:
1223 case XED_IFORM_ADC_MEMb_IMM:
1225 case XED_IFORM_ADC_GPRv_MEMv:
1226 case XED_IFORM_ADC_GPR8_MEMb:
1230 case XED_IFORM_ADD_MEMv_GPRv:
1231 case XED_IFORM_ADD_MEMb_IMM:
1232 case XED_IFORM_ADD_MEMb_GPR8:
1233 case XED_IFORM_ADD_MEMv_IMM:
1235 case XED_IFORM_ADD_GPRv_MEMv:
1236 case XED_IFORM_ADD_GPR8_MEMb:
1240 case XED_IFORM_AND_MEMv_IMM:
1241 case XED_IFORM_AND_MEMb_GPR8:
1242 case XED_IFORM_AND_MEMv_GPRv:
1243 case XED_IFORM_AND_MEMb_IMM:
1245 case XED_IFORM_AND_GPR8_MEMb:
1246 case XED_IFORM_AND_GPRv_MEMv:
1250 case XED_IFORM_SUB_MEMv_IMM:
1251 case XED_IFORM_SUB_MEMb_GPR8:
1252 case XED_IFORM_SUB_MEMb_IMM:
1253 case XED_IFORM_SUB_MEMv_GPRv:
1255 case XED_IFORM_SUB_GPR8_MEMb:
1256 case XED_IFORM_SUB_GPRv_MEMv:
1260 case XED_IFORM_MOV_MEMv_GPRv:
1261 case XED_IFORM_MOV_MEMb_GPR8:
1262 case XED_IFORM_MOV_MEMv_OrAX:
1263 case XED_IFORM_MOV_MEMb_AL:
1264 case XED_IFORM_MOV_MEMv_IMM:
1265 case XED_IFORM_MOV_MEMb_IMM:
1267 case XED_IFORM_MOV_GPRv_MEMv:
1268 case XED_IFORM_MOV_GPR8_MEMb:
1269 case XED_IFORM_MOV_OrAX_MEMv:
1270 case XED_IFORM_MOV_AL_MEMb:
1275 case XED_IFORM_MOVZX_GPRv_MEMb:
1276 case XED_IFORM_MOVZX_GPRv_MEMw:
1280 case XED_IFORM_MOVSX_GPRv_MEMb:
1281 case XED_IFORM_MOVSX_GPRv_MEMw:
1286 case XED_IFORM_DEC_MEMv:
1287 case XED_IFORM_DEC_MEMb:
1290 case XED_IFORM_INC_MEMb:
1291 case XED_IFORM_INC_MEMv:
1295 case XED_IFORM_OR_MEMv_IMM:
1296 case XED_IFORM_OR_MEMb_IMM:
1297 case XED_IFORM_OR_MEMv_GPRv:
1298 case XED_IFORM_OR_MEMb_GPR8:
1300 case XED_IFORM_OR_GPRv_MEMv:
1301 case XED_IFORM_OR_GPR8_MEMb:
1305 case XED_IFORM_XOR_MEMv_GPRv:
1306 case XED_IFORM_XOR_MEMb_IMM:
1307 case XED_IFORM_XOR_MEMb_GPR8:
1308 case XED_IFORM_XOR_MEMv_IMM:
1310 case XED_IFORM_XOR_GPRv_MEMv:
1311 case XED_IFORM_XOR_GPR8_MEMb:
1314 case XED_IFORM_NEG_MEMb:
1315 case XED_IFORM_NEG_MEMv:
1318 case XED_IFORM_NOT_MEMv:
1319 case XED_IFORM_NOT_MEMb:
1322 case XED_IFORM_XCHG_MEMv_GPRv:
1323 case XED_IFORM_XCHG_MEMb_GPR8:
1326 case XED_IFORM_SETB_MEMb:
1329 case XED_IFORM_SETBE_MEMb:
1332 case XED_IFORM_SETL_MEMb:
1335 case XED_IFORM_SETLE_MEMb:
1338 case XED_IFORM_SETNB_MEMb:
1341 case XED_IFORM_SETNBE_MEMb:
1342 return V3_OP_SETNBE;
1344 case XED_IFORM_SETNL_MEMb:
1347 case XED_IFORM_SETNLE_MEMb:
1348 return V3_OP_SETNLE;
1350 case XED_IFORM_SETNO_MEMb:
1353 case XED_IFORM_SETNP_MEMb:
1356 case XED_IFORM_SETNS_MEMb:
1359 case XED_IFORM_SETNZ_MEMb:
1362 case XED_IFORM_SETO_MEMb:
1365 case XED_IFORM_SETP_MEMb:
1368 case XED_IFORM_SETS_MEMb:
1371 case XED_IFORM_SETZ_MEMb:
1374 case XED_IFORM_MOVSB:
1375 case XED_IFORM_MOVSW:
1376 case XED_IFORM_MOVSD:
1377 case XED_IFORM_MOVSQ:
1380 case XED_IFORM_STOSB:
1381 case XED_IFORM_STOSW:
1382 case XED_IFORM_STOSD:
1383 case XED_IFORM_STOSQ:
1388 return V3_INVALID_OP;