1 #ifndef __VMM_EMULATE_H
2 #define __VMM_EMULATE_H
5 /* JRL: Most of this was taken from the Xen sources...
10 #define MAKE_INSTR(nm, ...) static const uchar_t OPCODE_##nm[] = { __VA_ARGS__ }
13 * Here's how it works:
15 * Following bytes: Opcode bytes.
16 * Special case: Last byte, if zero, doesn't need to match.
18 MAKE_INSTR(INVD, 2, 0x0f, 0x08);
19 MAKE_INSTR(CPUID, 2, 0x0f, 0xa2);
20 MAKE_INSTR(RDMSR, 2, 0x0f, 0x32);
21 MAKE_INSTR(WRMSR, 2, 0x0f, 0x30);
22 MAKE_INSTR(RDTSC, 2, 0x0f, 0x31);
23 MAKE_INSTR(RDTSCP, 3, 0x0f, 0x01, 0xf9);
24 MAKE_INSTR(CLI, 1, 0xfa);
25 MAKE_INSTR(STI, 1, 0xfb);
26 MAKE_INSTR(RDPMC, 2, 0x0f, 0x33);
27 MAKE_INSTR(CLGI, 3, 0x0f, 0x01, 0xdd);
28 MAKE_INSTR(STGI, 3, 0x0f, 0x01, 0xdc);
29 MAKE_INSTR(VMRUN, 3, 0x0f, 0x01, 0xd8);
30 MAKE_INSTR(VMLOAD, 3, 0x0f, 0x01, 0xda);
31 MAKE_INSTR(VMSAVE, 3, 0x0f, 0x01, 0xdb);
32 MAKE_INSTR(VMCALL, 3, 0x0f, 0x01, 0xd9);
33 MAKE_INSTR(PAUSE, 2, 0xf3, 0x90);
34 MAKE_INSTR(SKINIT, 3, 0x0f, 0x01, 0xde);
35 MAKE_INSTR(MOV2CR, 3, 0x0f, 0x22, 0x00);
36 MAKE_INSTR(MOVCR2, 3, 0x0f, 0x20, 0x00);
37 MAKE_INSTR(MOV2DR, 3, 0x0f, 0x23, 0x00);
38 MAKE_INSTR(MOVDR2, 3, 0x0f, 0x21, 0x00);
39 MAKE_INSTR(PUSHF, 1, 0x9c);
40 MAKE_INSTR(POPF, 1, 0x9d);
41 MAKE_INSTR(RSM, 2, 0x0f, 0xaa);
42 MAKE_INSTR(INVLPG, 3, 0x0f, 0x01, 0x00);
43 MAKE_INSTR(INVLPGA,3, 0x0f, 0x01, 0xdf);
44 MAKE_INSTR(HLT, 1, 0xf4);
45 MAKE_INSTR(CLTS, 2, 0x0f, 0x06);
46 MAKE_INSTR(LMSW, 3, 0x0f, 0x01, 0x00);
47 MAKE_INSTR(SMSW, 3, 0x0f, 0x01, 0x00);
51 static inline int is_prefix_byte(char byte) {
54 case 0xF2: // REPNE/REPNZ
55 case 0xF3: // REP or REPE/REPZ
56 case 0x2E: // CS override or Branch hint not taken (with Jcc instrs)
57 case 0x36: // SS override
58 case 0x3E: // DS override or Branch hint taken (with Jcc instrs)
59 case 0x26: // ES override
60 case 0x64: // FS override
61 case 0x65: // GS override
62 //case 0x2E: // branch not taken hint
63 // case 0x3E: // branch taken hint
64 case 0x66: // operand size override
65 case 0x67: // address size override