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 V3_CONFIG_DEBUG_DECODER
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_deinit_decoder(struct guest_info * core) {
184 V3_Free(core->decoder_state);
192 static int decode_string_op(struct guest_info * info,
193 xed_decoded_inst_t * xed_instr, const xed_inst_t * xi,
194 struct x86_instr * instr) {
196 PrintDebug("String operation\n");
198 if (instr->op_type == V3_OP_MOVS) {
199 instr->num_operands = 2;
201 if (get_memory_operand(info, xed_instr, 0, &(instr->dst_operand)) == -1) {
202 PrintError("Could not get Destination memory operand\n");
207 if (get_memory_operand(info, xed_instr, 1, &(instr->src_operand)) == -1) {
208 PrintError("Could not get Source memory operand\n");
212 instr->dst_operand.write = 1;
213 instr->src_operand.read = 1;
215 if (instr->prefixes.rep == 1) {
217 uint_t reg_length = 0;
219 xed_reg_to_v3_reg(info, xed_decoded_inst_get_reg(xed_instr, XED_OPERAND_REG0), ®_addr, ®_length);
220 instr->str_op_length = MASK(*(addr_t *)reg_addr, reg_length);
222 instr->str_op_length = 1;
225 } else if (instr->op_type == V3_OP_STOS) {
226 instr->num_operands = 2;
228 if (get_memory_operand(info, xed_instr, 0, &(instr->dst_operand)) == -1) {
229 PrintError("Could not get Destination memory operand\n");
233 // STOS reads from rax
234 xed_reg_to_v3_reg(info, xed_decoded_inst_get_reg(xed_instr, XED_OPERAND_REG0),
235 &(instr->src_operand.operand),
236 &(instr->src_operand.size));
237 instr->src_operand.type = REG_OPERAND;
239 instr->src_operand.read = 1;
240 instr->dst_operand.write = 1;
242 if (instr->prefixes.rep == 1) {
244 uint_t reg_length = 0;
246 xed_reg_to_v3_reg(info, xed_decoded_inst_get_reg(xed_instr, XED_OPERAND_REG1),
247 ®_addr, ®_length);
248 instr->str_op_length = MASK(*(addr_t *)reg_addr, reg_length);
250 instr->str_op_length = 1;
254 PrintError("Unhandled String OP\n");
263 int v3_disasm(struct guest_info * info, void *instr_ptr, addr_t * rip, int mark) {
267 xed_decoded_inst_t xed_instr;
268 xed_error_enum_t xed_error;
270 /* disassemble the specified instruction */
271 if (set_decoder_mode(info, info->decoder_state) == -1) {
272 PrintError("Could not set decoder mode\n");
276 xed_decoded_inst_zero_set_mode(&xed_instr, info->decoder_state);
278 xed_error = xed_decode(&xed_instr,
279 REINTERPRET_CAST(const xed_uint8_t *, instr_ptr),
280 XED_MAX_INSTRUCTION_BYTES);
282 if (xed_error != XED_ERROR_NONE) {
283 PrintError("Xed error: %s\n", xed_error_enum_t2str(xed_error));
287 /* obtain string representation in AT&T syntax */
288 if (!xed_format_att(&xed_instr, buffer, sizeof(buffer), *rip)) {
289 PrintError("Xed error: cannot disaaemble\n");
293 /* print address, opcode bytes and the disassembled instruction */
294 length = xed_decoded_inst_get_length(&xed_instr);
295 V3_Print("0x%p %c ", (void *) *rip, mark ? '*' : ' ');
296 for (i = 0; i < length; i++) {
297 unsigned char b = ((unsigned char *) instr_ptr)[i];
298 V3_Print("%x%x ", b >> 4, b & 0xf);
303 V3_Print("%s\n", buffer);
305 /* move on to next instruction */
312 int v3_decode(struct guest_info * info, addr_t instr_ptr, struct x86_instr * instr) {
313 xed_decoded_inst_t xed_instr;
314 xed_error_enum_t xed_error;
316 memset(instr, 0, sizeof(struct x86_instr));
319 v3_get_prefixes((uchar_t *)instr_ptr, &(instr->prefixes));
321 if (set_decoder_mode(info, info->decoder_state) == -1) {
322 PrintError("Could not set decoder mode\n");
326 xed_decoded_inst_zero_set_mode(&xed_instr, info->decoder_state);
328 xed_error = xed_decode(&xed_instr,
329 REINTERPRET_CAST(const xed_uint8_t *, instr_ptr),
330 XED_MAX_INSTRUCTION_BYTES);
333 if (xed_error != XED_ERROR_NONE) {
334 PrintError("Xed error: %s\n", xed_error_enum_t2str(xed_error));
338 const xed_inst_t * xi = xed_decoded_inst_inst(&xed_instr);
340 instr->instr_length = xed_decoded_inst_get_length(&xed_instr);
343 xed_iform_enum_t iform = xed_decoded_inst_get_iform_enum(&xed_instr);
345 #ifdef V3_CONFIG_DEBUG_DECODER
346 xed_iclass_enum_t iclass = xed_decoded_inst_get_iclass(&xed_instr);
348 PrintDebug("iform=%s, iclass=%s\n", xed_iform_enum_t2str(iform), xed_iclass_enum_t2str(iclass));
352 if ((instr->op_type = get_opcode(iform)) == V3_INVALID_OP) {
353 PrintError("Could not get opcode. (iform=%s)\n", xed_iform_enum_t2str(iform));
358 // We special case the string operations...
359 if (xed_decoded_inst_get_category(&xed_instr) == XED_CATEGORY_STRINGOP) {
360 instr->is_str_op = 1;
361 return decode_string_op(info, &xed_instr, xi, instr);
363 instr->is_str_op = 0;
364 instr->str_op_length = 0;
367 instr->num_operands = xed_decoded_inst_noperands(&xed_instr);
370 if (instr->num_operands > 3) {
371 PrintDebug("Special Case Not Handled (more than 3 operands) (iform=%s)\n", xed_iform_enum_t2str(iform)
374 } else if (instr->num_operands == 3) {
375 const xed_operand_t * op = xed_inst_operand(xi, 2);
376 xed_operand_enum_t op_enum = xed_operand_name(op);
378 if ((!xed_operand_is_register(op_enum)) ||
379 (!is_flags_reg(xed_decoded_inst_get_reg(&xed_instr, op_enum)))) {
381 PrintError("Special Case not handled (iform=%s)\n", xed_iform_enum_t2str(iform));
387 //PrintDebug("Number of operands: %d\n", instr->num_operands);
388 //PrintDebug("INSTR length: %d\n", instr->instr_length);
391 if (instr->num_operands >= 1) {
392 const xed_operand_t * op = xed_inst_operand(xi, 0);
393 xed_operand_enum_t op_enum = xed_operand_name(op);
395 struct x86_operand * v3_op = NULL;
398 if (xed_operand_written(op)) {
399 v3_op = &(instr->dst_operand);
401 v3_op = &(instr->src_operand);
405 v3_op = &(instr->dst_operand);
407 if (xed_operand_is_register(op_enum)) {
408 xed_reg_enum_t xed_reg = xed_decoded_inst_get_reg(&xed_instr, op_enum);
409 int v3_reg_type = xed_reg_to_v3_reg(info,
414 if (v3_reg_type == -1) {
415 PrintError("First operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
416 v3_op->type = INVALID_OPERAND;
418 } else if (v3_reg_type == SEGMENT_REGISTER) {
419 struct v3_segment * seg_reg = (struct v3_segment *)(v3_op->operand);
420 v3_op->operand = (addr_t)&(seg_reg->selector);
423 v3_op->type = REG_OPERAND;
428 case XED_OPERAND_MEM0:
430 PrintDebug("Memory operand (1)\n");
431 if (get_memory_operand(info, &xed_instr, 0, v3_op) == -1) {
432 PrintError("Could not get first memory operand\n");
438 case XED_OPERAND_MEM1:
439 case XED_OPERAND_IMM1:
441 PrintError("Illegal Operand Order\n");
445 case XED_OPERAND_IMM0:
447 v3_op->size = xed_decoded_inst_get_immediate_width(&xed_instr);
449 if (v3_op->size > 4) {
450 PrintError("Unhandled 64 bit immediates\n");
453 v3_op->operand = xed_decoded_inst_get_unsigned_immediate(&xed_instr);
455 v3_op->type = IMM_OPERAND;
459 case XED_OPERAND_AGEN:
460 case XED_OPERAND_PTR:
461 case XED_OPERAND_RELBR:
463 PrintError("Unhandled Operand Type\n");
468 // V3_Print("Operand 0 mode: %s\n", xed_operand_action_enum_t2str(xed_operand_rw(op)));
471 if (xed_operand_read(op)) {
475 if (xed_operand_written(op)) {
481 // set second operand
482 if (instr->num_operands >= 2) {
483 const xed_operand_t * op = xed_inst_operand(xi, 1);
484 // xed_operand_type_enum_t op_type = xed_operand_type(op);
485 xed_operand_enum_t op_enum = xed_operand_name(op);
487 struct x86_operand * v3_op;
490 if (xed_operand_written(op)) {
491 v3_op = &(instr->dst_operand);
493 v3_op = &(instr->src_operand);
496 v3_op = &(instr->src_operand);
499 if (xed_operand_is_register(op_enum)) {
500 xed_reg_enum_t xed_reg = xed_decoded_inst_get_reg(&xed_instr, op_enum);
501 int v3_reg_type = xed_reg_to_v3_reg(info,
505 if (v3_reg_type == -1) {
506 PrintError("Second operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
507 v3_op->type = INVALID_OPERAND;
509 } else if (v3_reg_type == SEGMENT_REGISTER) {
510 struct v3_segment * seg_reg = (struct v3_segment *)(v3_op->operand);
511 v3_op->operand = (addr_t)&(seg_reg->selector);
514 v3_op->type = REG_OPERAND;
518 case XED_OPERAND_MEM0:
520 PrintDebug("Memory operand (2)\n");
521 if (get_memory_operand(info, &xed_instr, 0, v3_op) == -1) {
522 PrintError("Could not get first memory operand\n");
528 case XED_OPERAND_IMM0:
530 instr->src_operand.size = xed_decoded_inst_get_immediate_width(&xed_instr);
532 if (instr->src_operand.size > 4) {
533 PrintError("Unhandled 64 bit immediates\n");
536 instr->src_operand.operand = xed_decoded_inst_get_unsigned_immediate(&xed_instr);
538 instr->src_operand.type = IMM_OPERAND;
543 case XED_OPERAND_MEM1:
544 case XED_OPERAND_IMM1:
546 PrintError("Illegal Operand Order\n");
549 case XED_OPERAND_AGEN:
550 case XED_OPERAND_PTR:
551 case XED_OPERAND_RELBR:
553 PrintError("Unhandled Operand Type\n");
558 // V3_Print("Operand 1 mode: %s\n", xed_operand_action_enum_t2str(xed_operand_rw(op)));
560 if (xed_operand_read(op)) {
564 if (xed_operand_written(op)) {
571 if (instr->num_operands >= 3) {
572 const xed_operand_t * op = xed_inst_operand(xi, 2);
573 xed_operand_type_enum_t op_type = xed_operand_type(op);
574 xed_operand_enum_t op_enum = xed_operand_name(op);
578 if (xed_operand_is_register(op_enum)) {
579 xed_reg_enum_t xed_reg = xed_decoded_inst_get_reg(&xed_instr, op_enum);
580 int v3_reg_type = xed_reg_to_v3_reg(info,
582 &(instr->third_operand.operand),
583 &(instr->third_operand.size));
585 if (v3_reg_type == -1) {
586 PrintError("Third operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
587 instr->third_operand.type = INVALID_OPERAND;
589 } else if (v3_reg_type == SEGMENT_REGISTER) {
590 struct v3_segment * seg_reg = (struct v3_segment *)(instr->third_operand.operand);
591 instr->third_operand.operand = (addr_t)&(seg_reg->selector);
595 instr->third_operand.type = REG_OPERAND;
597 PrintDebug("Operand 2 mode: %s\n", xed_operand_action_enum_t2str(xed_operand_rw(op)));
600 if (xed_operand_read(op)) {
601 instr->third_operand.read = 1;
604 if (xed_operand_written(op)) {
605 instr->third_operand.write = 1;
609 PrintError("Unhandled third operand type %s\n", xed_operand_type_enum_t2str(op_type));
610 instr->num_operands = 2;
618 int v3_encode(struct guest_info * info, struct x86_instr * instr, uint8_t * instr_buf) {
627 static int get_memory_operand(struct guest_info * info, xed_decoded_inst_t * xed_instr, uint_t op_index, struct x86_operand * operand) {
628 struct memory_operand mem_op;
634 ullong_t displacement;
635 int addr_width = v3_get_addr_width(info);
636 v3_cpu_mode_t cpu_mode = v3_get_vm_cpu_mode(info);
637 // struct v3_segment * seg_reg;
639 PrintDebug("Xed mode = %s\n", xed_machine_mode_enum_t2str(xed_state_get_machine_mode(info->decoder_state)));
640 PrintDebug("Address width: %s\n",
641 xed_address_width_enum_t2str(xed_state_get_address_width(info->decoder_state)));
642 PrintDebug("Stack Address width: %s\n",
643 xed_address_width_enum_t2str(xed_state_get_stack_address_width(info->decoder_state)));
647 memset((void*)&mem_op, '\0', sizeof(struct memory_operand));
649 xed_reg_enum_t xed_seg = xed_decoded_inst_get_seg_reg(xed_instr, op_index);
650 if (xed_seg != XED_REG_INVALID) {
651 struct v3_segment *tmp_segment;
652 if (xed_reg_to_v3_reg(info, xed_seg, (addr_t *)&tmp_segment, &(mem_op.segment_size)) == -1) {
653 PrintError("Unhandled Segment Register\n");
656 mem_op.segment = tmp_segment->base;
659 xed_reg_enum_t xed_base = xed_decoded_inst_get_base_reg(xed_instr, op_index);
660 if (xed_base != XED_REG_INVALID) {
662 if (xed_reg_to_v3_reg(info, xed_base, &base_reg, &(mem_op.base_size)) == -1) {
663 PrintError("Unhandled Base register\n");
666 mem_op.base = *(addr_t *)base_reg;
671 xed_reg_enum_t xed_idx = xed_decoded_inst_get_index_reg(xed_instr, op_index);
672 if ((op_index == 0) && (xed_idx != XED_REG_INVALID)) {
675 if (xed_reg_to_v3_reg(info, xed_idx, &index_reg, &(mem_op.index_size)) == -1) {
676 PrintError("Unhandled Index Register\n");
680 mem_op.index= *(addr_t *)index_reg;
682 xed_uint_t xed_scale = xed_decoded_inst_get_scale(xed_instr, op_index);
683 if (xed_scale != 0) {
684 mem_op.scale = xed_scale;
689 xed_uint_t disp_bits = xed_decoded_inst_get_memory_displacement_width(xed_instr, op_index);
691 xed_int64_t xed_disp = xed_decoded_inst_get_memory_displacement(xed_instr, op_index);
693 mem_op.displacement_size = disp_bits;
694 mem_op.displacement = xed_disp;
697 operand->type = MEM_OPERAND;
698 operand->size = xed_decoded_inst_get_memory_operand_length(xed_instr, op_index);
702 PrintDebug("Struct: Seg=%p (size=%d), base=%p, index=%p, scale=%p, displacement=%p (size=%d)\n",
703 (void *)mem_op.segment, mem_op.segment_size, (void*)mem_op.base, (void *)mem_op.index,
704 (void *)mem_op.scale, (void *)(addr_t)mem_op.displacement, mem_op.displacement_size);
707 PrintDebug("operand size: %d\n", operand->size);
709 seg = MASK(mem_op.segment, mem_op.segment_size);
710 base = MASK(mem_op.base, mem_op.base_size);
711 index = MASK(mem_op.index, mem_op.index_size);
712 scale = mem_op.scale;
714 // XED returns the displacement as a 2s complement signed number, but it can
715 // have different sizes, depending on the instruction encoding.
716 // we put that into a 64 bit unsigned (the unsigned doesn't matter since
717 // we only ever do 2s complement arithmetic on it. However, this means we
718 // need to sign-extend what XED provides through 64 bits.
719 displacement = mem_op.displacement;
720 displacement <<= 64 - mem_op.displacement_size * 8;
721 displacement = ((sllong_t)displacement) >> (64 - mem_op.displacement_size * 8);
724 PrintDebug("Seg=%p, base=%p, index=%p, scale=%p, displacement=%p\n",
725 (void *)seg, (void *)base, (void *)index, (void *)scale, (void *)(addr_t)displacement);
727 if (cpu_mode == REAL) {
728 operand->operand = seg + MASK((base + (scale * index) + displacement), addr_width);
730 operand->operand = MASK((seg + base + (scale * index) + displacement), addr_width);
737 static int xed_reg_to_v3_reg(struct guest_info * info, xed_reg_enum_t xed_reg,
738 addr_t * v3_reg, uint_t * reg_len) {
740 PrintDebug("Xed Register: %s\n", xed_reg_enum_t2str(xed_reg));
743 case XED_REG_INVALID:
752 *v3_reg = (addr_t)&(info->vm_regs.rax);
756 *v3_reg = (addr_t)&(info->vm_regs.rax);
760 *v3_reg = (addr_t)&(info->vm_regs.rax);
764 *v3_reg = (addr_t)(&(info->vm_regs.rax)) + 1;
768 *v3_reg = (addr_t)&(info->vm_regs.rax);
773 *v3_reg = (addr_t)&(info->vm_regs.rcx);
777 *v3_reg = (addr_t)&(info->vm_regs.rcx);
781 *v3_reg = (addr_t)&(info->vm_regs.rcx);
785 *v3_reg = (addr_t)(&(info->vm_regs.rcx)) + 1;
789 *v3_reg = (addr_t)&(info->vm_regs.rcx);
794 *v3_reg = (addr_t)&(info->vm_regs.rdx);
798 *v3_reg = (addr_t)&(info->vm_regs.rdx);
802 *v3_reg = (addr_t)&(info->vm_regs.rdx);
806 *v3_reg = (addr_t)(&(info->vm_regs.rdx)) + 1;
810 *v3_reg = (addr_t)&(info->vm_regs.rdx);
815 *v3_reg = (addr_t)&(info->vm_regs.rbx);
819 *v3_reg = (addr_t)&(info->vm_regs.rbx);
823 *v3_reg = (addr_t)&(info->vm_regs.rbx);
827 *v3_reg = (addr_t)(&(info->vm_regs.rbx)) + 1;
831 *v3_reg = (addr_t)&(info->vm_regs.rbx);
837 *v3_reg = (addr_t)&(info->vm_regs.rsp);
841 *v3_reg = (addr_t)&(info->vm_regs.rsp);
845 *v3_reg = (addr_t)&(info->vm_regs.rsp);
849 *v3_reg = (addr_t)&(info->vm_regs.rsp);
854 *v3_reg = (addr_t)&(info->vm_regs.rbp);
858 *v3_reg = (addr_t)&(info->vm_regs.rbp);
862 *v3_reg = (addr_t)&(info->vm_regs.rbp);
866 *v3_reg = (addr_t)&(info->vm_regs.rbp);
873 *v3_reg = (addr_t)&(info->vm_regs.rsi);
877 *v3_reg = (addr_t)&(info->vm_regs.rsi);
881 *v3_reg = (addr_t)&(info->vm_regs.rsi);
885 *v3_reg = (addr_t)&(info->vm_regs.rsi);
891 *v3_reg = (addr_t)&(info->vm_regs.rdi);
895 *v3_reg = (addr_t)&(info->vm_regs.rdi);
899 *v3_reg = (addr_t)&(info->vm_regs.rdi);
903 *v3_reg = (addr_t)&(info->vm_regs.rdi);
912 *v3_reg = (addr_t)&(info->vm_regs.r8);
916 *v3_reg = (addr_t)&(info->vm_regs.r8);
920 *v3_reg = (addr_t)&(info->vm_regs.r8);
924 *v3_reg = (addr_t)&(info->vm_regs.r8);
929 *v3_reg = (addr_t)&(info->vm_regs.r9);
933 *v3_reg = (addr_t)&(info->vm_regs.r9);
937 *v3_reg = (addr_t)&(info->vm_regs.r9);
941 *v3_reg = (addr_t)&(info->vm_regs.r9);
946 *v3_reg = (addr_t)&(info->vm_regs.r10);
950 *v3_reg = (addr_t)&(info->vm_regs.r10);
954 *v3_reg = (addr_t)&(info->vm_regs.r10);
958 *v3_reg = (addr_t)&(info->vm_regs.r10);
963 *v3_reg = (addr_t)&(info->vm_regs.r11);
967 *v3_reg = (addr_t)&(info->vm_regs.r11);
971 *v3_reg = (addr_t)&(info->vm_regs.r11);
975 *v3_reg = (addr_t)&(info->vm_regs.r11);
980 *v3_reg = (addr_t)&(info->vm_regs.r12);
984 *v3_reg = (addr_t)&(info->vm_regs.r12);
988 *v3_reg = (addr_t)&(info->vm_regs.r12);
992 *v3_reg = (addr_t)&(info->vm_regs.r12);
997 *v3_reg = (addr_t)&(info->vm_regs.r13);
1001 *v3_reg = (addr_t)&(info->vm_regs.r13);
1003 return GPR_REGISTER;
1005 *v3_reg = (addr_t)&(info->vm_regs.r13);
1007 return GPR_REGISTER;
1009 *v3_reg = (addr_t)&(info->vm_regs.r13);
1011 return GPR_REGISTER;
1014 *v3_reg = (addr_t)&(info->vm_regs.r14);
1016 return GPR_REGISTER;
1018 *v3_reg = (addr_t)&(info->vm_regs.r14);
1020 return GPR_REGISTER;
1022 *v3_reg = (addr_t)&(info->vm_regs.r14);
1024 return GPR_REGISTER;
1026 *v3_reg = (addr_t)&(info->vm_regs.r14);
1028 return GPR_REGISTER;
1031 *v3_reg = (addr_t)&(info->vm_regs.r15);
1033 return GPR_REGISTER;
1035 *v3_reg = (addr_t)&(info->vm_regs.r15);
1037 return GPR_REGISTER;
1039 *v3_reg = (addr_t)&(info->vm_regs.r15);
1041 return GPR_REGISTER;
1043 *v3_reg = (addr_t)&(info->vm_regs.r15);
1045 return GPR_REGISTER;
1052 *v3_reg = (addr_t)&(info->rip);
1054 return CTRL_REGISTER;
1056 *v3_reg = (addr_t)&(info->rip);
1058 return CTRL_REGISTER;
1060 *v3_reg = (addr_t)&(info->rip);
1062 return CTRL_REGISTER;
1065 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
1067 return CTRL_REGISTER;
1068 case XED_REG_EFLAGS:
1069 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
1071 return CTRL_REGISTER;
1072 case XED_REG_RFLAGS:
1073 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
1075 return CTRL_REGISTER;
1078 *v3_reg = (addr_t)&(info->ctrl_regs.cr0);
1080 return CTRL_REGISTER;
1082 *v3_reg = (addr_t)&(info->ctrl_regs.cr2);
1084 return CTRL_REGISTER;
1086 *v3_reg = (addr_t)&(info->ctrl_regs.cr3);
1088 return CTRL_REGISTER;
1090 *v3_reg = (addr_t)&(info->ctrl_regs.cr4);
1092 return CTRL_REGISTER;
1094 *v3_reg = (addr_t)&(info->ctrl_regs.cr8);
1096 return CTRL_REGISTER;
1118 *v3_reg = (addr_t)&(info->segments.cs);
1120 return SEGMENT_REGISTER;
1122 *v3_reg = (addr_t)&(info->segments.ds);
1124 return SEGMENT_REGISTER;
1126 *v3_reg = (addr_t)&(info->segments.es);
1128 return SEGMENT_REGISTER;
1130 *v3_reg = (addr_t)&(info->segments.ss);
1132 return SEGMENT_REGISTER;
1134 *v3_reg = (addr_t)&(info->segments.fs);
1136 return SEGMENT_REGISTER;
1138 *v3_reg = (addr_t)&(info->segments.gs);
1140 return SEGMENT_REGISTER;
1147 PrintError("Segment selector operand... Don't know how to handle this...\n");
1212 case XED_REG_STACKPUSH:
1213 case XED_REG_STACKPOP:
1216 case XED_REG_TSCAUX:
1219 case XED_REG_X87CONTROL:
1220 case XED_REG_X87STATUS:
1221 case XED_REG_X87TOP:
1222 case XED_REG_X87TAG:
1223 case XED_REG_X87PUSH:
1224 case XED_REG_X87POP:
1225 case XED_REG_X87POP2:
1260 static v3_op_type_t get_opcode(xed_iform_enum_t iform) {
1264 /* Control Instructions */
1266 case XED_IFORM_MOV_CR_GPR64_CR:
1267 case XED_IFORM_MOV_CR_GPR32_CR:
1268 return V3_OP_MOVCR2;
1270 case XED_IFORM_MOV_CR_CR_GPR64:
1271 case XED_IFORM_MOV_CR_CR_GPR32:
1272 return V3_OP_MOV2CR;
1274 case XED_IFORM_SMSW_GPRv:
1277 case XED_IFORM_LMSW_GPR16:
1280 case XED_IFORM_CLTS:
1283 case XED_IFORM_INVLPG_MEMb:
1284 return V3_OP_INVLPG;
1286 case XED_IFORM_INT_IMM:
1290 /* Data Instructions */
1293 case XED_IFORM_ADC_MEMv_GPRv:
1294 case XED_IFORM_ADC_MEMv_IMM:
1295 case XED_IFORM_ADC_MEMb_GPR8:
1296 case XED_IFORM_ADC_MEMb_IMM:
1298 case XED_IFORM_ADC_GPRv_MEMv:
1299 case XED_IFORM_ADC_GPR8_MEMb:
1303 case XED_IFORM_ADD_MEMv_GPRv:
1304 case XED_IFORM_ADD_MEMb_IMM:
1305 case XED_IFORM_ADD_MEMb_GPR8:
1306 case XED_IFORM_ADD_MEMv_IMM:
1308 case XED_IFORM_ADD_GPRv_MEMv:
1309 case XED_IFORM_ADD_GPR8_MEMb:
1313 case XED_IFORM_AND_MEMv_IMM:
1314 case XED_IFORM_AND_MEMb_GPR8:
1315 case XED_IFORM_AND_MEMv_GPRv:
1316 case XED_IFORM_AND_MEMb_IMM:
1318 case XED_IFORM_AND_GPR8_MEMb:
1319 case XED_IFORM_AND_GPRv_MEMv:
1323 case XED_IFORM_SUB_MEMv_IMM:
1324 case XED_IFORM_SUB_MEMb_GPR8:
1325 case XED_IFORM_SUB_MEMb_IMM:
1326 case XED_IFORM_SUB_MEMv_GPRv:
1328 case XED_IFORM_SUB_GPR8_MEMb:
1329 case XED_IFORM_SUB_GPRv_MEMv:
1333 case XED_IFORM_MOV_MEMv_GPRv:
1334 case XED_IFORM_MOV_MEMb_GPR8:
1335 case XED_IFORM_MOV_MEMv_OrAX:
1336 case XED_IFORM_MOV_MEMb_AL:
1337 case XED_IFORM_MOV_MEMv_IMM:
1338 case XED_IFORM_MOV_MEMb_IMM:
1340 case XED_IFORM_MOV_GPRv_MEMv:
1341 case XED_IFORM_MOV_GPR8_MEMb:
1342 case XED_IFORM_MOV_OrAX_MEMv:
1343 case XED_IFORM_MOV_AL_MEMb:
1348 case XED_IFORM_MOVZX_GPRv_MEMb:
1349 case XED_IFORM_MOVZX_GPRv_MEMw:
1353 case XED_IFORM_MOVSX_GPRv_MEMb:
1354 case XED_IFORM_MOVSX_GPRv_MEMw:
1359 case XED_IFORM_DEC_MEMv:
1360 case XED_IFORM_DEC_MEMb:
1363 case XED_IFORM_INC_MEMb:
1364 case XED_IFORM_INC_MEMv:
1368 case XED_IFORM_OR_MEMv_IMM:
1369 case XED_IFORM_OR_MEMb_IMM:
1370 case XED_IFORM_OR_MEMv_GPRv:
1371 case XED_IFORM_OR_MEMb_GPR8:
1373 case XED_IFORM_OR_GPRv_MEMv:
1374 case XED_IFORM_OR_GPR8_MEMb:
1378 case XED_IFORM_XOR_MEMv_GPRv:
1379 case XED_IFORM_XOR_MEMb_IMM:
1380 case XED_IFORM_XOR_MEMb_GPR8:
1381 case XED_IFORM_XOR_MEMv_IMM:
1383 case XED_IFORM_XOR_GPRv_MEMv:
1384 case XED_IFORM_XOR_GPR8_MEMb:
1387 case XED_IFORM_NEG_MEMb:
1388 case XED_IFORM_NEG_MEMv:
1391 case XED_IFORM_NOT_MEMv:
1392 case XED_IFORM_NOT_MEMb:
1395 case XED_IFORM_XCHG_MEMv_GPRv:
1396 case XED_IFORM_XCHG_MEMb_GPR8:
1399 case XED_IFORM_SETB_MEMb:
1402 case XED_IFORM_SETBE_MEMb:
1405 case XED_IFORM_SETL_MEMb:
1408 case XED_IFORM_SETLE_MEMb:
1411 case XED_IFORM_SETNB_MEMb:
1414 case XED_IFORM_SETNBE_MEMb:
1415 return V3_OP_SETNBE;
1417 case XED_IFORM_SETNL_MEMb:
1420 case XED_IFORM_SETNLE_MEMb:
1421 return V3_OP_SETNLE;
1423 case XED_IFORM_SETNO_MEMb:
1426 case XED_IFORM_SETNP_MEMb:
1429 case XED_IFORM_SETNS_MEMb:
1432 case XED_IFORM_SETNZ_MEMb:
1435 case XED_IFORM_SETO_MEMb:
1438 case XED_IFORM_SETP_MEMb:
1441 case XED_IFORM_SETS_MEMb:
1444 case XED_IFORM_SETZ_MEMb:
1447 case XED_IFORM_MOVSB:
1448 case XED_IFORM_MOVSW:
1449 case XED_IFORM_MOVSD:
1450 case XED_IFORM_MOVSQ:
1453 case XED_IFORM_STOSB:
1454 case XED_IFORM_STOSW:
1455 case XED_IFORM_STOSD:
1456 case XED_IFORM_STOSQ:
1461 return V3_INVALID_OP;