1 static struct ins x86__instructions[] = { 2 { .name = "add", .ops = &mov_ops, }, 3 { .name = "addl", .ops = &mov_ops, }, 4 { .name = "addq", .ops = &mov_ops, }, 5 { .name = "addw", .ops = &mov_ops, }, 6 { .name = "and", .ops = &mov_ops, }, 7 { .name = "bts", .ops = &mov_ops, }, 8 { .name = "call", .ops = &call_ops, }, 9 { .name = "callq", .ops = &call_ops, }, 10 { .name = "cmp", .ops = &mov_ops, }, 11 { .name = "cmpb", .ops = &mov_ops, }, 12 { .name = "cmpl", .ops = &mov_ops, }, 13 { .name = "cmpq", .ops = &mov_ops, }, 14 { .name = "cmpw", .ops = &mov_ops, }, 15 { .name = "cmpxch", .ops = &mov_ops, }, 16 { .name = "dec", .ops = &dec_ops, }, 17 { .name = "decl", .ops = &dec_ops, }, 18 { .name = "imul", .ops = &mov_ops, }, 19 { .name = "inc", .ops = &dec_ops, }, 20 { .name = "incl", .ops = &dec_ops, }, 21 { .name = "ja", .ops = &jump_ops, }, 22 { .name = "jae", .ops = &jump_ops, }, 23 { .name = "jb", .ops = &jump_ops, }, 24 { .name = "jbe", .ops = &jump_ops, }, 25 { .name = "jc", .ops = &jump_ops, }, 26 { .name = "jcxz", .ops = &jump_ops, }, 27 { .name = "je", .ops = &jump_ops, }, 28 { .name = "jecxz", .ops = &jump_ops, }, 29 { .name = "jg", .ops = &jump_ops, }, 30 { .name = "jge", .ops = &jump_ops, }, 31 { .name = "jl", .ops = &jump_ops, }, 32 { .name = "jle", .ops = &jump_ops, }, 33 { .name = "jmp", .ops = &jump_ops, }, 34 { .name = "jmpq", .ops = &jump_ops, }, 35 { .name = "jna", .ops = &jump_ops, }, 36 { .name = "jnae", .ops = &jump_ops, }, 37 { .name = "jnb", .ops = &jump_ops, }, 38 { .name = "jnbe", .ops = &jump_ops, }, 39 { .name = "jnc", .ops = &jump_ops, }, 40 { .name = "jne", .ops = &jump_ops, }, 41 { .name = "jng", .ops = &jump_ops, }, 42 { .name = "jnge", .ops = &jump_ops, }, 43 { .name = "jnl", .ops = &jump_ops, }, 44 { .name = "jnle", .ops = &jump_ops, }, 45 { .name = "jno", .ops = &jump_ops, }, 46 { .name = "jnp", .ops = &jump_ops, }, 47 { .name = "jns", .ops = &jump_ops, }, 48 { .name = "jnz", .ops = &jump_ops, }, 49 { .name = "jo", .ops = &jump_ops, }, 50 { .name = "jp", .ops = &jump_ops, }, 51 { .name = "jpe", .ops = &jump_ops, }, 52 { .name = "jpo", .ops = &jump_ops, }, 53 { .name = "jrcxz", .ops = &jump_ops, }, 54 { .name = "js", .ops = &jump_ops, }, 55 { .name = "jz", .ops = &jump_ops, }, 56 { .name = "lea", .ops = &mov_ops, }, 57 { .name = "lock", .ops = &lock_ops, }, 58 { .name = "mov", .ops = &mov_ops, }, 59 { .name = "movb", .ops = &mov_ops, }, 60 { .name = "movdqa", .ops = &mov_ops, }, 61 { .name = "movl", .ops = &mov_ops, }, 62 { .name = "movq", .ops = &mov_ops, }, 63 { .name = "movslq", .ops = &mov_ops, }, 64 { .name = "movzbl", .ops = &mov_ops, }, 65 { .name = "movzwl", .ops = &mov_ops, }, 66 { .name = "nop", .ops = &nop_ops, }, 67 { .name = "nopl", .ops = &nop_ops, }, 68 { .name = "nopw", .ops = &nop_ops, }, 69 { .name = "or", .ops = &mov_ops, }, 70 { .name = "orl", .ops = &mov_ops, }, 71 { .name = "test", .ops = &mov_ops, }, 72 { .name = "testb", .ops = &mov_ops, }, 73 { .name = "testl", .ops = &mov_ops, }, 74 { .name = "xadd", .ops = &mov_ops, }, 75 { .name = "xbeginl", .ops = &jump_ops, }, 76 { .name = "xbeginq", .ops = &jump_ops, }, 77 { .name = "retq", .ops = &ret_ops, }, 78 }; 79 80 static bool x86__ins_is_fused(struct arch *arch, const char *ins1, 81 const char *ins2) 82 { 83 if (arch->family != 6 || arch->model < 0x1e || strstr(ins2, "jmp")) 84 return false; 85 86 if (arch->model == 0x1e) { 87 /* Nehalem */ 88 if ((strstr(ins1, "cmp") && !strstr(ins1, "xchg")) || 89 strstr(ins1, "test")) { 90 return true; 91 } 92 } else { 93 /* Newer platform */ 94 if ((strstr(ins1, "cmp") && !strstr(ins1, "xchg")) || 95 strstr(ins1, "test") || 96 strstr(ins1, "add") || 97 strstr(ins1, "sub") || 98 strstr(ins1, "and") || 99 strstr(ins1, "inc") || 100 strstr(ins1, "dec")) { 101 return true; 102 } 103 } 104 105 return false; 106 } 107 108 static int x86__cpuid_parse(struct arch *arch, char *cpuid) 109 { 110 unsigned int family, model, stepping; 111 int ret; 112 113 /* 114 * cpuid = "GenuineIntel,family,model,stepping" 115 */ 116 ret = sscanf(cpuid, "%*[^,],%u,%u,%u", &family, &model, &stepping); 117 if (ret == 3) { 118 arch->family = family; 119 arch->model = model; 120 return 0; 121 } 122 123 return -1; 124 } 125