High Level API for Encoding Instructions


Detailed Description

This is a higher level API for encoding instructions.

A full example is present in examples/xed-ex5-enc.c

In the following example we create one instructions template that can be passed to the encoder.

 xed_encoder_instruction_t x; 
 xed_encoder_request_t enc_req;
 xed_state_t dstate;

 dstate.mmode=XED_MACHINE_MODE_LEGACY_32;
 dstate.stack_addr_width=XED_ADDRESS_WIDTH_32b;

 xed_inst2(&x, state, XED_ICLASS_ADD, 32, 
           xreg(XED_REG_EAX), 
           xmem_bd(XED_REG_EDX, xdisp(0x11223344, 32), 32));
  
 xed_encoder_request_zero_set_mode(&enc_req, &dstate);
 convert_ok = xed_convert_to_encoder_request(&enc_req, &x);
 if (!convert_ok) {
      fprintf(stderr,"conversion to encode request failed\n");
      continue;
 }
 xed_error = xed_encode(&enc_req, itext, ilen, &olen);


Register and Immmediate Operands

static XED_INLINE xed_encoder_operand_t imm0 (xed_uint64_t v, xed_uint_t width)
 a first immediate operand (known as IMM0)
static XED_INLINE xed_encoder_operand_t imm1 (xed_uint8_t v)
 an second immediate operand (known as IMM1)
static XED_INLINE xed_encoder_operand_t simm0 (xed_int64_t v, xed_uint_t width)
 an signed immediate operand
static XED_INLINE xed_encoder_operand_t xreg (xed_reg_enum_t reg)
 a register operand

Instruction Properties and prefixes

static XED_INLINE void xaddr (xed_encoder_instruction_t *x, xed_uint_t width)
 This is to specify effective address size different than the default.
xed_bool_t xed_convert_to_encoder_request (xed_encoder_request_t *out, xed_encoder_instruction_t *in)
 convert a xed_encoder_instruction_t to a xed_encoder_request_t for encoding
static XED_INLINE void xlock (xed_encoder_instruction_t *x)
static XED_INLINE void xrep (xed_encoder_instruction_t *x)
static XED_INLINE void xrepne (xed_encoder_instruction_t *x)

Memory Displacement

static XED_INLINE xed_enc_displacement_t xdisp (xed_uint64_t displacement, xed_uint32_t displacement_width)
 a memory displacement (not for branches)

Creating instructions from operands

static XED_INLINE void xed_inst0 (xed_encoder_instruction_t *inst, xed_state_t mode, xed_iclass_enum_t iclass, xed_uint_t effective_operand_width)
 instruction with no operands
static XED_INLINE void xed_inst1 (xed_encoder_instruction_t *inst, xed_state_t mode, xed_iclass_enum_t iclass, xed_uint_t effective_operand_width, xed_encoder_operand_t op0)
 instruction with one operand
static XED_INLINE void xed_inst2 (xed_encoder_instruction_t *inst, xed_state_t mode, xed_iclass_enum_t iclass, xed_uint_t effective_operand_width, xed_encoder_operand_t op0, xed_encoder_operand_t op1)
 instruction with two operands
static XED_INLINE void xed_inst3 (xed_encoder_instruction_t *inst, xed_state_t mode, xed_iclass_enum_t iclass, xed_uint_t effective_operand_width, xed_encoder_operand_t op0, xed_encoder_operand_t op1, xed_encoder_operand_t op2)
 instruction with three operands

Memory and Segment-releated Operands

static XED_INLINE xed_encoder_operand_t xmem_b (xed_reg_enum_t base, xed_uint_t width)
 memory operand - base only
static XED_INLINE xed_encoder_operand_t xmem_bd (xed_reg_enum_t base, xed_enc_displacement_t disp, xed_uint_t width)
 memory operand - base and displacement only
static XED_INLINE xed_encoder_operand_t xmem_bisd (xed_reg_enum_t base, xed_reg_enum_t index, xed_uint_t scale, xed_enc_displacement_t disp, xed_uint_t width)
 memory operand - base, index, scale, displacement
static XED_INLINE xed_encoder_operand_t xmem_gb (xed_reg_enum_t seg, xed_reg_enum_t base, xed_uint_t width)
 memory operand - segment and base only
static XED_INLINE xed_encoder_operand_t xmem_gbd (xed_reg_enum_t seg, xed_reg_enum_t base, xed_enc_displacement_t disp, xed_uint_t width)
 memory operand - segment, base and displacement only
static XED_INLINE xed_encoder_operand_t xmem_gbisd (xed_reg_enum_t seg, xed_reg_enum_t base, xed_reg_enum_t index, xed_uint_t scale, xed_enc_displacement_t disp, xed_uint_t width)
 memory operand - segment, base, index, scale, and displacement
static XED_INLINE xed_encoder_operand_t xseg0 (xed_reg_enum_t seg0)
 seg reg override for implicit suppressed memory ops
static XED_INLINE xed_encoder_operand_t xseg1 (xed_reg_enum_t seg1)
 seg reg override for implicit suppressed memory ops

Pointer Displacement

static XED_INLINE xed_encoder_operand_t xptr (xed_int32_t brdisp, xed_uint_t width)
 a relative displacement for a PTR operand -- the subsequent imm0 holds the 16b selector

Branch Displacement

static XED_INLINE xed_encoder_operand_t xrelbr (xed_int32_t brdisp, xed_uint_t width)
 a relative branch displacement operand


Function Documentation

static XED_INLINE xed_encoder_operand_t imm0 (  xed_uint64_t  v,
xed_uint_t  width
)  [static]
 

a first immediate operand (known as IMM0)

Definition at line 136 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t imm1 (  xed_uint8_t  v  )  [static]
 

an second immediate operand (known as IMM1)

Definition at line 155 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t simm0 (  xed_int64_t  v,
xed_uint_t  width
)  [static]
 

an signed immediate operand

Definition at line 145 of file xed-encoder-hl.h.

static XED_INLINE void xaddr (  xed_encoder_instruction_t *  x,
xed_uint_t  width
)  [static]
 

This is to specify effective address size different than the default.

For things with base or index regs, XED picks it up from the registers. But for things that have implicit memops, or no base or index reg, we must allow the user to set the address width directly.

Definition at line 325 of file xed-encoder-hl.h.

static XED_INLINE xed_enc_displacement_t xdisp (  xed_uint64_t  displacement,
xed_uint32_t  displacement_width
)  [static]
 

a memory displacement (not for branches)

Definition at line 53 of file xed-encoder-hl.h.

xed_bool_t xed_convert_to_encoder_request (  xed_encoder_request_t *  out,
xed_encoder_instruction_t *  in
) 
 

convert a xed_encoder_instruction_t to a xed_encoder_request_t for encoding

static XED_INLINE void xed_inst0 (  xed_encoder_instruction_t *  inst,
xed_state_t  mode,
xed_iclass_enum_t  iclass,
xed_uint_t  effective_operand_width
)  [static]
 

instruction with no operands

Definition at line 367 of file xed-encoder-hl.h.

static XED_INLINE void xed_inst1 (  xed_encoder_instruction_t *  inst,
xed_state_t  mode,
xed_iclass_enum_t  iclass,
xed_uint_t  effective_operand_width,
xed_encoder_operand_t  op0
)  [static]
 

instruction with one operand

Definition at line 383 of file xed-encoder-hl.h.

static XED_INLINE void xed_inst2 (  xed_encoder_instruction_t *  inst,
xed_state_t  mode,
xed_iclass_enum_t  iclass,
xed_uint_t  effective_operand_width,
xed_encoder_operand_t  op0,
xed_encoder_operand_t  op1
)  [static]
 

instruction with two operands

Definition at line 401 of file xed-encoder-hl.h.

static XED_INLINE void xed_inst3 (  xed_encoder_instruction_t *  inst,
xed_state_t  mode,
xed_iclass_enum_t  iclass,
xed_uint_t  effective_operand_width,
xed_encoder_operand_t  op0,
xed_encoder_operand_t  op1,
xed_encoder_operand_t  op2
)  [static]
 

instruction with three operands

Definition at line 421 of file xed-encoder-hl.h.

static XED_INLINE void xlock (  xed_encoder_instruction_t *  x  )  [static]
 

Definition at line 342 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xmem_b (  xed_reg_enum_t  base,
xed_uint_t  width
)  [static]
 

memory operand - base only

Definition at line 188 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xmem_bd (  xed_reg_enum_t  base,
xed_enc_displacement_t  disp,
xed_uint_t  width
)  [static]
 

memory operand - base and displacement only

Definition at line 203 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xmem_bisd (  xed_reg_enum_t  base,
xed_reg_enum_t  index,
xed_uint_t  scale,
xed_enc_displacement_t  disp,
xed_uint_t  width
)  [static]
 

memory operand - base, index, scale, displacement

Definition at line 219 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xmem_gb (  xed_reg_enum_t  seg,
xed_reg_enum_t  base,
xed_uint_t  width
)  [static]
 

memory operand - segment and base only

Definition at line 238 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xmem_gbd (  xed_reg_enum_t  seg,
xed_reg_enum_t  base,
xed_enc_displacement_t  disp,
xed_uint_t  width
)  [static]
 

memory operand - segment, base and displacement only

Definition at line 253 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xmem_gbisd (  xed_reg_enum_t  seg,
xed_reg_enum_t  base,
xed_reg_enum_t  index,
xed_uint_t  scale,
xed_enc_displacement_t  disp,
xed_uint_t  width
)  [static]
 

memory operand - segment, base, index, scale, and displacement

Definition at line 269 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xptr (  xed_int32_t  brdisp,
xed_uint_t  width
)  [static]
 

a relative displacement for a PTR operand -- the subsequent imm0 holds the 16b selector

Definition at line 113 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xreg (  xed_reg_enum_t  reg  )  [static]
 

a register operand

Definition at line 126 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xrelbr (  xed_int32_t  brdisp,
xed_uint_t  width
)  [static]
 

a relative branch displacement operand

Definition at line 100 of file xed-encoder-hl.h.

static XED_INLINE void xrep (  xed_encoder_instruction_t *  x  )  [static]
 

Definition at line 332 of file xed-encoder-hl.h.

static XED_INLINE void xrepne (  xed_encoder_instruction_t *  x  )  [static]
 

Definition at line 337 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xseg0 (  xed_reg_enum_t  seg0  )  [static]
 

seg reg override for implicit suppressed memory ops

Definition at line 170 of file xed-encoder-hl.h.

static XED_INLINE xed_encoder_operand_t xseg1 (  xed_reg_enum_t  seg1  )  [static]
 

seg reg override for implicit suppressed memory ops

Definition at line 179 of file xed-encoder-hl.h.


Generated on Wed Dec 3 03:10:46 2008 for XED2 by  doxygen 1.4.6