Coverage Report

Created: 2026-09-28 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/X86/X86Mapping.h
Line
Count
Source
1
/* Capstone Disassembly Engine */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */
3
4
#ifndef CS_X86_MAP_H
5
#define CS_X86_MAP_H
6
7
#include "capstone/capstone.h"
8
#include "../../cs_priv.h"
9
10
// map instruction to its characteristics
11
typedef struct insn_map_x86 {
12
  unsigned short id;
13
  unsigned short mapid;
14
  unsigned char is64bit;
15
#ifndef CAPSTONE_DIET
16
  uint16_t regs_use[12]; // list of implicit registers used by this instruction
17
  uint16_t regs_mod
18
    [20]; // list of implicit registers modified by this instruction
19
  unsigned char groups[8]; // list of group this instruction belong to
20
  bool branch; // branch instruction?
21
  bool indirect_branch; // indirect branch instruction?
22
#endif
23
} insn_map_x86;
24
25
extern const insn_map_x86 insns[];
26
27
// map sib_base to x86_reg
28
x86_reg x86_map_sib_base(int r);
29
30
// map sib_index to x86_reg
31
x86_reg x86_map_sib_index(int r);
32
33
// map seg_override to x86_reg
34
x86_reg x86_map_segment(int r);
35
36
// return name of register in friendly string
37
const char *X86_reg_name(csh handle, unsigned int reg);
38
39
// given internal insn id, return public instruction info
40
void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id);
41
42
// return insn name, given insn id
43
const char *X86_insn_name(csh handle, unsigned int id);
44
45
// return group name, given group id
46
const char *X86_group_name(csh handle, unsigned int id);
47
48
// return register of given instruction id
49
// return 0 if not found
50
// this is to handle instructions embedding accumulate registers into AsmStrs[]
51
x86_reg X86_insn_reg_intel(unsigned int id, enum cs_ac_type *access);
52
x86_reg X86_insn_reg_intel_h(cs_struct *h, unsigned int id,
53
           enum cs_ac_type *access);
54
x86_reg X86_insn_reg_att(unsigned int id, enum cs_ac_type *access);
55
x86_reg X86_insn_reg_att_h(cs_struct *h, unsigned int id,
56
         enum cs_ac_type *access);
57
bool X86_insn_reg_intel2(unsigned int id, x86_reg *reg1,
58
       enum cs_ac_type *access1, x86_reg *reg2,
59
       enum cs_ac_type *access2);
60
bool X86_insn_reg_att2(unsigned int id, x86_reg *reg1, enum cs_ac_type *access1,
61
           x86_reg *reg2, enum cs_ac_type *access2);
62
63
extern const uint64_t arch_masks[9];
64
65
// handle LOCK/REP/REPNE prefixes
66
// return True if we patch mnemonic, like in MULPD case
67
bool X86_lockrep(MCInst *MI, SStream *O);
68
69
// map registers to sizes
70
extern const uint8_t regsize_map_32[];
71
extern const uint8_t regsize_map_64[];
72
73
void op_addReg(MCInst *MI, int reg);
74
void op_addImm(MCInst *MI, int v);
75
76
void op_addAvxBroadcast(MCInst *MI, x86_avx_bcast v);
77
78
void op_addXopCC(MCInst *MI, int v);
79
void op_addSseCC(MCInst *MI, int v);
80
void op_addAvxCC(MCInst *MI, int v);
81
82
void op_addAvxZeroOpmask(MCInst *MI);
83
84
void op_addAvxSae(MCInst *MI);
85
86
void op_addAvxRoundingMode(MCInst *MI, int v);
87
88
// given internal insn id, return operand access info
89
const uint8_t *X86_get_op_access(cs_struct *h, unsigned int id,
90
         uint64_t *eflags);
91
92
void X86_reg_access(const cs_insn *insn, cs_regs regs_read,
93
        uint8_t *regs_read_count, cs_regs regs_write,
94
        uint8_t *regs_write_count);
95
96
// given the instruction id, return the size of its immediate operand (or 0)
97
uint8_t X86_immediate_size(unsigned int id, uint8_t *enc_size);
98
99
unsigned short X86_register_map(unsigned short id);
100
101
unsigned int find_insn(unsigned int id);
102
103
void X86_build_lookup_tables(cs_struct *h);
104
105
void X86_postprinter(csh handle, cs_insn *insn, SStream *mnem, MCInst *mci);
106
107
static inline bool x86_has_feature(cs_mode mode, int flag)
108
2.15M
{
109
2.15M
  return (mode & flag) == flag;
110
2.15M
}
X86Module.c:x86_has_feature
Line
Count
Source
108
10.7k
{
109
10.7k
  return (mode & flag) == flag;
110
10.7k
}
X86ATTInstPrinter.c:x86_has_feature
Line
Count
Source
108
365k
{
109
365k
  return (mode & flag) == flag;
110
365k
}
Unexecuted instantiation: X86Disassembler.c:x86_has_feature
X86DisassemblerDecoder.c:x86_has_feature
Line
Count
Source
108
1.01M
{
109
1.01M
  return (mode & flag) == flag;
110
1.01M
}
X86IntelInstPrinter.c:x86_has_feature
Line
Count
Source
108
43.5k
{
109
43.5k
  return (mode & flag) == flag;
110
43.5k
}
Unexecuted instantiation: X86InstPrinterCommon.c:x86_has_feature
X86Mapping.c:x86_has_feature
Line
Count
Source
108
713k
{
109
713k
  return (mode & flag) == flag;
110
713k
}
111
112
static inline int x86_get_bit_mode(cs_mode mode)
113
617k
{
114
617k
  return mode & (CS_MODE_64 | CS_MODE_32 | CS_MODE_16);
115
617k
}
Unexecuted instantiation: X86Module.c:x86_get_bit_mode
X86ATTInstPrinter.c:x86_get_bit_mode
Line
Count
Source
113
6.61k
{
114
6.61k
  return mode & (CS_MODE_64 | CS_MODE_32 | CS_MODE_16);
115
6.61k
}
Unexecuted instantiation: X86Disassembler.c:x86_get_bit_mode
Unexecuted instantiation: X86DisassemblerDecoder.c:x86_get_bit_mode
X86IntelInstPrinter.c:x86_get_bit_mode
Line
Count
Source
113
8.10k
{
114
8.10k
  return mode & (CS_MODE_64 | CS_MODE_32 | CS_MODE_16);
115
8.10k
}
Unexecuted instantiation: X86InstPrinterCommon.c:x86_get_bit_mode
X86Mapping.c:x86_get_bit_mode
Line
Count
Source
113
602k
{
114
602k
  return mode & (CS_MODE_64 | CS_MODE_32 | CS_MODE_16);
115
602k
}
116
117
static inline uint64_t x86_get_address_mask(cs_mode mode)
118
1.68k
{
119
1.68k
  if (x86_has_feature(mode, CS_MODE_16))
120
1.02k
    return UINT16_MAX;
121
664
  if (x86_has_feature(mode, CS_MODE_32))
122
561
    return UINT32_MAX;
123
103
  return UINT64_MAX;
124
664
}
Unexecuted instantiation: X86Module.c:x86_get_address_mask
X86ATTInstPrinter.c:x86_get_address_mask
Line
Count
Source
118
1.21k
{
119
1.21k
  if (x86_has_feature(mode, CS_MODE_16))
120
891
    return UINT16_MAX;
121
328
  if (x86_has_feature(mode, CS_MODE_32))
122
300
    return UINT32_MAX;
123
28
  return UINT64_MAX;
124
328
}
Unexecuted instantiation: X86Disassembler.c:x86_get_address_mask
Unexecuted instantiation: X86DisassemblerDecoder.c:x86_get_address_mask
X86IntelInstPrinter.c:x86_get_address_mask
Line
Count
Source
118
466
{
119
466
  if (x86_has_feature(mode, CS_MODE_16))
120
130
    return UINT16_MAX;
121
336
  if (x86_has_feature(mode, CS_MODE_32))
122
261
    return UINT32_MAX;
123
75
  return UINT64_MAX;
124
336
}
Unexecuted instantiation: X86InstPrinterCommon.c:x86_get_address_mask
Unexecuted instantiation: X86Mapping.c:x86_get_address_mask
125
126
#endif