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_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 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:
446 case XED_OPERAND_AGEN:
447 case XED_OPERAND_PTR:
448 case XED_OPERAND_RELBR:
450 PrintError("Unhandled Operand Type\n");
455 // V3_Print("Operand 0 mode: %s\n", xed_operand_action_enum_t2str(xed_operand_rw(op)));
458 if (xed_operand_read(op)) {
462 if (xed_operand_written(op)) {
468 // set second operand
469 if (instr->num_operands >= 2) {
470 const xed_operand_t * op = xed_inst_operand(xi, 1);
471 // xed_operand_type_enum_t op_type = xed_operand_type(op);
472 xed_operand_enum_t op_enum = xed_operand_name(op);
474 struct x86_operand * v3_op;
477 if (xed_operand_written(op)) {
478 v3_op = &(instr->dst_operand);
480 v3_op = &(instr->src_operand);
483 v3_op = &(instr->src_operand);
486 if (xed_operand_is_register(op_enum)) {
487 xed_reg_enum_t xed_reg = xed_decoded_inst_get_reg(&xed_instr, op_enum);
488 int v3_reg_type = xed_reg_to_v3_reg(info,
492 if (v3_reg_type == -1) {
493 PrintError("Second operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
494 v3_op->type = INVALID_OPERAND;
496 } else if (v3_reg_type == SEGMENT_REGISTER) {
497 struct v3_segment * seg_reg = (struct v3_segment *)(v3_op->operand);
498 v3_op->operand = (addr_t)&(seg_reg->selector);
501 v3_op->type = REG_OPERAND;
505 case XED_OPERAND_MEM0:
507 PrintDebug("Memory operand (2)\n");
508 if (get_memory_operand(info, &xed_instr, 0, v3_op) == -1) {
509 PrintError("Could not get first memory operand\n");
515 case XED_OPERAND_IMM0:
517 instr->src_operand.size = xed_decoded_inst_get_immediate_width(&xed_instr);
519 if (instr->src_operand.size > 4) {
520 PrintError("Unhandled 64 bit immediates\n");
523 instr->src_operand.operand = xed_decoded_inst_get_unsigned_immediate(&xed_instr);
525 instr->src_operand.type = IMM_OPERAND;
530 case XED_OPERAND_MEM1:
531 case XED_OPERAND_IMM1:
533 PrintError("Illegal Operand Order\n");
536 case XED_OPERAND_AGEN:
537 case XED_OPERAND_PTR:
538 case XED_OPERAND_RELBR:
540 PrintError("Unhandled Operand Type\n");
545 // V3_Print("Operand 1 mode: %s\n", xed_operand_action_enum_t2str(xed_operand_rw(op)));
547 if (xed_operand_read(op)) {
551 if (xed_operand_written(op)) {
558 if (instr->num_operands >= 3) {
559 const xed_operand_t * op = xed_inst_operand(xi, 2);
560 xed_operand_type_enum_t op_type = xed_operand_type(op);
561 xed_operand_enum_t op_enum = xed_operand_name(op);
565 if (xed_operand_is_register(op_enum)) {
566 xed_reg_enum_t xed_reg = xed_decoded_inst_get_reg(&xed_instr, op_enum);
567 int v3_reg_type = xed_reg_to_v3_reg(info,
569 &(instr->third_operand.operand),
570 &(instr->third_operand.size));
572 if (v3_reg_type == -1) {
573 PrintError("Third operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
574 instr->third_operand.type = INVALID_OPERAND;
576 } else if (v3_reg_type == SEGMENT_REGISTER) {
577 struct v3_segment * seg_reg = (struct v3_segment *)(instr->third_operand.operand);
578 instr->third_operand.operand = (addr_t)&(seg_reg->selector);
582 instr->third_operand.type = REG_OPERAND;
584 PrintDebug("Operand 3 mode: %s\n", xed_operand_action_enum_t2str(xed_operand_rw(op)));
587 if (xed_operand_read(op)) {
588 instr->third_operand.read = 1;
591 if (xed_operand_written(op)) {
592 instr->third_operand.write = 1;
596 PrintError("Unhandled third operand type %s\n", xed_operand_type_enum_t2str(op_type));
597 instr->num_operands = 2;
605 int v3_encode(struct guest_info * info, struct x86_instr * instr, uint8_t * instr_buf) {
614 static int get_memory_operand(struct guest_info * info, xed_decoded_inst_t * xed_instr, uint_t op_index, struct x86_operand * operand) {
615 struct memory_operand mem_op;
621 ullong_t displacement;
622 int addr_width = v3_get_addr_width(info);
623 v3_cpu_mode_t cpu_mode = v3_get_vm_cpu_mode(info);
624 // struct v3_segment * seg_reg;
626 PrintDebug("Xed mode = %s\n", xed_machine_mode_enum_t2str(xed_state_get_machine_mode(info->decoder_state)));
627 PrintDebug("Address width: %s\n",
628 xed_address_width_enum_t2str(xed_state_get_address_width(info->decoder_state)));
629 PrintDebug("Stack Address width: %s\n",
630 xed_address_width_enum_t2str(xed_state_get_stack_address_width(info->decoder_state)));
634 memset((void*)&mem_op, '\0', sizeof(struct memory_operand));
636 xed_reg_enum_t xed_seg = xed_decoded_inst_get_seg_reg(xed_instr, op_index);
637 if (xed_seg != XED_REG_INVALID) {
638 struct v3_segment *tmp_segment;
639 if (xed_reg_to_v3_reg(info, xed_seg, (addr_t *)&tmp_segment, &(mem_op.segment_size)) == -1) {
640 PrintError("Unhandled Segment Register\n");
643 mem_op.segment = tmp_segment->base;
646 xed_reg_enum_t xed_base = xed_decoded_inst_get_base_reg(xed_instr, op_index);
647 if (xed_base != XED_REG_INVALID) {
649 if (xed_reg_to_v3_reg(info, xed_base, &base_reg, &(mem_op.base_size)) == -1) {
650 PrintError("Unhandled Base register\n");
653 mem_op.base = *(addr_t *)base_reg;
658 xed_reg_enum_t xed_idx = xed_decoded_inst_get_index_reg(xed_instr, op_index);
659 if ((op_index == 0) && (xed_idx != XED_REG_INVALID)) {
662 if (xed_reg_to_v3_reg(info, xed_idx, &index_reg, &(mem_op.index_size)) == -1) {
663 PrintError("Unhandled Index Register\n");
667 mem_op.index= *(addr_t *)index_reg;
669 xed_uint_t xed_scale = xed_decoded_inst_get_scale(xed_instr, op_index);
670 if (xed_scale != 0) {
671 mem_op.scale = xed_scale;
676 xed_uint_t disp_bits = xed_decoded_inst_get_memory_displacement_width(xed_instr, op_index);
678 xed_int64_t xed_disp = xed_decoded_inst_get_memory_displacement(xed_instr, op_index);
680 mem_op.displacement_size = disp_bits;
681 mem_op.displacement = xed_disp;
684 operand->type = MEM_OPERAND;
685 operand->size = xed_decoded_inst_get_memory_operand_length(xed_instr, op_index);
689 PrintDebug("Struct: Seg=%p (size=%d), base=%p, index=%p, scale=%p, displacement=%p (size=%d)\n",
690 (void *)mem_op.segment, mem_op.segment_size, (void*)mem_op.base, (void *)mem_op.index,
691 (void *)mem_op.scale, (void *)(addr_t)mem_op.displacement, mem_op.displacement_size);
694 PrintDebug("operand size: %d\n", operand->size);
696 seg = MASK(mem_op.segment, mem_op.segment_size);
697 base = MASK(mem_op.base, mem_op.base_size);
698 index = MASK(mem_op.index, mem_op.index_size);
699 scale = mem_op.scale;
701 // XED returns the displacement as a 2s complement signed number, but it can
702 // have different sizes, depending on the instruction encoding.
703 // we put that into a 64 bit unsigned (the unsigned doesn't matter since
704 // we only ever do 2s complement arithmetic on it. However, this means we
705 // need to sign-extend what XED provides through 64 bits.
706 displacement = mem_op.displacement;
707 displacement <<= 64 - mem_op.displacement_size * 8;
708 displacement = ((sllong_t)displacement) >> (64 - mem_op.displacement_size * 8);
711 PrintDebug("Seg=%p, base=%p, index=%p, scale=%p, displacement=%p\n",
712 (void *)seg, (void *)base, (void *)index, (void *)scale, (void *)(addr_t)displacement);
714 if (cpu_mode == REAL) {
715 operand->operand = seg + MASK((base + (scale * index) + displacement), addr_width);
717 operand->operand = MASK((seg + base + (scale * index) + displacement), addr_width);
724 static int xed_reg_to_v3_reg(struct guest_info * info, xed_reg_enum_t xed_reg,
725 addr_t * v3_reg, uint_t * reg_len) {
727 PrintDebug("Xed Register: %s\n", xed_reg_enum_t2str(xed_reg));
730 case XED_REG_INVALID:
739 *v3_reg = (addr_t)&(info->vm_regs.rax);
743 *v3_reg = (addr_t)&(info->vm_regs.rax);
747 *v3_reg = (addr_t)&(info->vm_regs.rax);
751 *v3_reg = (addr_t)(&(info->vm_regs.rax)) + 1;
755 *v3_reg = (addr_t)&(info->vm_regs.rax);
760 *v3_reg = (addr_t)&(info->vm_regs.rcx);
764 *v3_reg = (addr_t)&(info->vm_regs.rcx);
768 *v3_reg = (addr_t)&(info->vm_regs.rcx);
772 *v3_reg = (addr_t)(&(info->vm_regs.rcx)) + 1;
776 *v3_reg = (addr_t)&(info->vm_regs.rcx);
781 *v3_reg = (addr_t)&(info->vm_regs.rdx);
785 *v3_reg = (addr_t)&(info->vm_regs.rdx);
789 *v3_reg = (addr_t)&(info->vm_regs.rdx);
793 *v3_reg = (addr_t)(&(info->vm_regs.rdx)) + 1;
797 *v3_reg = (addr_t)&(info->vm_regs.rdx);
802 *v3_reg = (addr_t)&(info->vm_regs.rbx);
806 *v3_reg = (addr_t)&(info->vm_regs.rbx);
810 *v3_reg = (addr_t)&(info->vm_regs.rbx);
814 *v3_reg = (addr_t)(&(info->vm_regs.rbx)) + 1;
818 *v3_reg = (addr_t)&(info->vm_regs.rbx);
824 *v3_reg = (addr_t)&(info->vm_regs.rsp);
828 *v3_reg = (addr_t)&(info->vm_regs.rsp);
832 *v3_reg = (addr_t)&(info->vm_regs.rsp);
836 *v3_reg = (addr_t)&(info->vm_regs.rsp);
841 *v3_reg = (addr_t)&(info->vm_regs.rbp);
845 *v3_reg = (addr_t)&(info->vm_regs.rbp);
849 *v3_reg = (addr_t)&(info->vm_regs.rbp);
853 *v3_reg = (addr_t)&(info->vm_regs.rbp);
860 *v3_reg = (addr_t)&(info->vm_regs.rsi);
864 *v3_reg = (addr_t)&(info->vm_regs.rsi);
868 *v3_reg = (addr_t)&(info->vm_regs.rsi);
872 *v3_reg = (addr_t)&(info->vm_regs.rsi);
878 *v3_reg = (addr_t)&(info->vm_regs.rdi);
882 *v3_reg = (addr_t)&(info->vm_regs.rdi);
886 *v3_reg = (addr_t)&(info->vm_regs.rdi);
890 *v3_reg = (addr_t)&(info->vm_regs.rdi);
899 *v3_reg = (addr_t)&(info->vm_regs.r8);
903 *v3_reg = (addr_t)&(info->vm_regs.r8);
907 *v3_reg = (addr_t)&(info->vm_regs.r8);
911 *v3_reg = (addr_t)&(info->vm_regs.r8);
916 *v3_reg = (addr_t)&(info->vm_regs.r9);
920 *v3_reg = (addr_t)&(info->vm_regs.r9);
924 *v3_reg = (addr_t)&(info->vm_regs.r9);
928 *v3_reg = (addr_t)&(info->vm_regs.r9);
933 *v3_reg = (addr_t)&(info->vm_regs.r10);
937 *v3_reg = (addr_t)&(info->vm_regs.r10);
941 *v3_reg = (addr_t)&(info->vm_regs.r10);
945 *v3_reg = (addr_t)&(info->vm_regs.r10);
950 *v3_reg = (addr_t)&(info->vm_regs.r11);
954 *v3_reg = (addr_t)&(info->vm_regs.r11);
958 *v3_reg = (addr_t)&(info->vm_regs.r11);
962 *v3_reg = (addr_t)&(info->vm_regs.r11);
967 *v3_reg = (addr_t)&(info->vm_regs.r12);
971 *v3_reg = (addr_t)&(info->vm_regs.r12);
975 *v3_reg = (addr_t)&(info->vm_regs.r12);
979 *v3_reg = (addr_t)&(info->vm_regs.r12);
984 *v3_reg = (addr_t)&(info->vm_regs.r13);
988 *v3_reg = (addr_t)&(info->vm_regs.r13);
992 *v3_reg = (addr_t)&(info->vm_regs.r13);
996 *v3_reg = (addr_t)&(info->vm_regs.r13);
1001 *v3_reg = (addr_t)&(info->vm_regs.r14);
1003 return GPR_REGISTER;
1005 *v3_reg = (addr_t)&(info->vm_regs.r14);
1007 return GPR_REGISTER;
1009 *v3_reg = (addr_t)&(info->vm_regs.r14);
1011 return GPR_REGISTER;
1013 *v3_reg = (addr_t)&(info->vm_regs.r14);
1015 return GPR_REGISTER;
1018 *v3_reg = (addr_t)&(info->vm_regs.r15);
1020 return GPR_REGISTER;
1022 *v3_reg = (addr_t)&(info->vm_regs.r15);
1024 return GPR_REGISTER;
1026 *v3_reg = (addr_t)&(info->vm_regs.r15);
1028 return GPR_REGISTER;
1030 *v3_reg = (addr_t)&(info->vm_regs.r15);
1032 return GPR_REGISTER;
1039 *v3_reg = (addr_t)&(info->rip);
1041 return CTRL_REGISTER;
1043 *v3_reg = (addr_t)&(info->rip);
1045 return CTRL_REGISTER;
1047 *v3_reg = (addr_t)&(info->rip);
1049 return CTRL_REGISTER;
1052 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
1054 return CTRL_REGISTER;
1055 case XED_REG_EFLAGS:
1056 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
1058 return CTRL_REGISTER;
1059 case XED_REG_RFLAGS:
1060 *v3_reg = (addr_t)&(info->ctrl_regs.rflags);
1062 return CTRL_REGISTER;
1065 *v3_reg = (addr_t)&(info->ctrl_regs.cr0);
1067 return CTRL_REGISTER;
1069 *v3_reg = (addr_t)&(info->ctrl_regs.cr2);
1071 return CTRL_REGISTER;
1073 *v3_reg = (addr_t)&(info->ctrl_regs.cr3);
1075 return CTRL_REGISTER;
1077 *v3_reg = (addr_t)&(info->ctrl_regs.cr4);
1079 return CTRL_REGISTER;
1081 *v3_reg = (addr_t)&(info->ctrl_regs.cr8);
1083 return CTRL_REGISTER;
1105 *v3_reg = (addr_t)&(info->segments.cs);
1107 return SEGMENT_REGISTER;
1109 *v3_reg = (addr_t)&(info->segments.ds);
1111 return SEGMENT_REGISTER;
1113 *v3_reg = (addr_t)&(info->segments.es);
1115 return SEGMENT_REGISTER;
1117 *v3_reg = (addr_t)&(info->segments.ss);
1119 return SEGMENT_REGISTER;
1121 *v3_reg = (addr_t)&(info->segments.fs);
1123 return SEGMENT_REGISTER;
1125 *v3_reg = (addr_t)&(info->segments.gs);
1127 return SEGMENT_REGISTER;
1134 PrintError("Segment selector operand... Don't know how to handle this...\n");
1199 case XED_REG_STACKPUSH:
1200 case XED_REG_STACKPOP:
1203 case XED_REG_TSCAUX:
1206 case XED_REG_X87CONTROL:
1207 case XED_REG_X87STATUS:
1208 case XED_REG_X87TOP:
1209 case XED_REG_X87TAG:
1210 case XED_REG_X87PUSH:
1211 case XED_REG_X87POP:
1212 case XED_REG_X87POP2:
1247 static v3_op_type_t get_opcode(xed_iform_enum_t iform) {
1251 /* Control Instructions */
1253 case XED_IFORM_MOV_CR_GPR64_CR:
1254 case XED_IFORM_MOV_CR_GPR32_CR:
1255 return V3_OP_MOVCR2;
1257 case XED_IFORM_MOV_CR_CR_GPR64:
1258 case XED_IFORM_MOV_CR_CR_GPR32:
1259 return V3_OP_MOV2CR;
1261 case XED_IFORM_SMSW_GPRv:
1264 case XED_IFORM_LMSW_GPR16:
1267 case XED_IFORM_CLTS:
1270 case XED_IFORM_INVLPG_MEMb:
1271 return V3_OP_INVLPG;
1274 /* Data Instructions */
1277 case XED_IFORM_ADC_MEMv_GPRv:
1278 case XED_IFORM_ADC_MEMv_IMM:
1279 case XED_IFORM_ADC_MEMb_GPR8:
1280 case XED_IFORM_ADC_MEMb_IMM:
1282 case XED_IFORM_ADC_GPRv_MEMv:
1283 case XED_IFORM_ADC_GPR8_MEMb:
1287 case XED_IFORM_ADD_MEMv_GPRv:
1288 case XED_IFORM_ADD_MEMb_IMM:
1289 case XED_IFORM_ADD_MEMb_GPR8:
1290 case XED_IFORM_ADD_MEMv_IMM:
1292 case XED_IFORM_ADD_GPRv_MEMv:
1293 case XED_IFORM_ADD_GPR8_MEMb:
1297 case XED_IFORM_AND_MEMv_IMM:
1298 case XED_IFORM_AND_MEMb_GPR8:
1299 case XED_IFORM_AND_MEMv_GPRv:
1300 case XED_IFORM_AND_MEMb_IMM:
1302 case XED_IFORM_AND_GPR8_MEMb:
1303 case XED_IFORM_AND_GPRv_MEMv:
1307 case XED_IFORM_SUB_MEMv_IMM:
1308 case XED_IFORM_SUB_MEMb_GPR8:
1309 case XED_IFORM_SUB_MEMb_IMM:
1310 case XED_IFORM_SUB_MEMv_GPRv:
1312 case XED_IFORM_SUB_GPR8_MEMb:
1313 case XED_IFORM_SUB_GPRv_MEMv:
1317 case XED_IFORM_MOV_MEMv_GPRv:
1318 case XED_IFORM_MOV_MEMb_GPR8:
1319 case XED_IFORM_MOV_MEMv_OrAX:
1320 case XED_IFORM_MOV_MEMb_AL:
1321 case XED_IFORM_MOV_MEMv_IMM:
1322 case XED_IFORM_MOV_MEMb_IMM:
1324 case XED_IFORM_MOV_GPRv_MEMv:
1325 case XED_IFORM_MOV_GPR8_MEMb:
1326 case XED_IFORM_MOV_OrAX_MEMv:
1327 case XED_IFORM_MOV_AL_MEMb:
1332 case XED_IFORM_MOVZX_GPRv_MEMb:
1333 case XED_IFORM_MOVZX_GPRv_MEMw:
1337 case XED_IFORM_MOVSX_GPRv_MEMb:
1338 case XED_IFORM_MOVSX_GPRv_MEMw:
1343 case XED_IFORM_DEC_MEMv:
1344 case XED_IFORM_DEC_MEMb:
1347 case XED_IFORM_INC_MEMb:
1348 case XED_IFORM_INC_MEMv:
1352 case XED_IFORM_OR_MEMv_IMM:
1353 case XED_IFORM_OR_MEMb_IMM:
1354 case XED_IFORM_OR_MEMv_GPRv:
1355 case XED_IFORM_OR_MEMb_GPR8:
1357 case XED_IFORM_OR_GPRv_MEMv:
1358 case XED_IFORM_OR_GPR8_MEMb:
1362 case XED_IFORM_XOR_MEMv_GPRv:
1363 case XED_IFORM_XOR_MEMb_IMM:
1364 case XED_IFORM_XOR_MEMb_GPR8:
1365 case XED_IFORM_XOR_MEMv_IMM:
1367 case XED_IFORM_XOR_GPRv_MEMv:
1368 case XED_IFORM_XOR_GPR8_MEMb:
1371 case XED_IFORM_NEG_MEMb:
1372 case XED_IFORM_NEG_MEMv:
1375 case XED_IFORM_NOT_MEMv:
1376 case XED_IFORM_NOT_MEMb:
1379 case XED_IFORM_XCHG_MEMv_GPRv:
1380 case XED_IFORM_XCHG_MEMb_GPR8:
1383 case XED_IFORM_SETB_MEMb:
1386 case XED_IFORM_SETBE_MEMb:
1389 case XED_IFORM_SETL_MEMb:
1392 case XED_IFORM_SETLE_MEMb:
1395 case XED_IFORM_SETNB_MEMb:
1398 case XED_IFORM_SETNBE_MEMb:
1399 return V3_OP_SETNBE;
1401 case XED_IFORM_SETNL_MEMb:
1404 case XED_IFORM_SETNLE_MEMb:
1405 return V3_OP_SETNLE;
1407 case XED_IFORM_SETNO_MEMb:
1410 case XED_IFORM_SETNP_MEMb:
1413 case XED_IFORM_SETNS_MEMb:
1416 case XED_IFORM_SETNZ_MEMb:
1419 case XED_IFORM_SETO_MEMb:
1422 case XED_IFORM_SETP_MEMb:
1425 case XED_IFORM_SETS_MEMb:
1428 case XED_IFORM_SETZ_MEMb:
1431 case XED_IFORM_MOVSB:
1432 case XED_IFORM_MOVSW:
1433 case XED_IFORM_MOVSD:
1434 case XED_IFORM_MOVSQ:
1437 case XED_IFORM_STOSB:
1438 case XED_IFORM_STOSW:
1439 case XED_IFORM_STOSD:
1440 case XED_IFORM_STOSQ:
1445 return V3_INVALID_OP;