Skip to content

Commit

Permalink
x86: upgrade core
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Feb 7, 2014
1 parent ea5ed83 commit 13f40d2
Show file tree
Hide file tree
Showing 14 changed files with 67,036 additions and 60,129 deletions.
1 change: 0 additions & 1 deletion MCInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ struct MCInst {
cs_insn_flat flat_insn; // insn to be exposed to public
unsigned OpcodePub;
int insn_size; // instruction size
int x86_segment; // remove when segment mem ref hack is redundant.
uint64_t address; // address of this insn
cs_struct *csh; // save the main csh
};
Expand Down
107 changes: 89 additions & 18 deletions arch/X86/X86ATTInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
const char *X86ATT_getRegisterName(unsigned RegNo);

static void printMemReference(MCInst *MI, unsigned Op, SStream *O);
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);

static void printopaquemem(MCInst *MI, unsigned OpNo, SStream *O)
{
Expand Down Expand Up @@ -116,12 +117,88 @@ static void printf512mem(MCInst *MI, unsigned OpNo, SStream *O)
printMemReference(MI, OpNo, O);
}

static void printSrcIdx(MCInst *MI, unsigned Op, SStream *O)
{
MCOperand *SegReg;

SegReg = MCInst_getOperand(MI, Op+1);

SStream_concat(O, "%s", markup("<mem:"));

// If this has a segment register, print it.
if (MCOperand_getReg(SegReg)) {
printOperand(MI, Op+1, O);
SStream_concat(O, ":");
}

SStream_concat(O, "(");

printOperand(MI, Op, O);

SStream_concat(O, ")%s", markup(">"));
}

static void printDstIdx(MCInst *MI, unsigned Op, SStream *O)
{
SStream_concat(O, "%s%s", markup("<mem:"), "%es:(");
printOperand(MI, Op, O);

SStream_concat(O, ")%s", markup(">"));
}

static void printSrcIdx8(MCInst *MI, unsigned OpNo, SStream *O)
{
printSrcIdx(MI, OpNo, O);
}

static void printSrcIdx16(MCInst *MI, unsigned OpNo, SStream *O)
{
printSrcIdx(MI, OpNo, O);
}

static void printSrcIdx32(MCInst *MI, unsigned OpNo, SStream *O)
{
printSrcIdx(MI, OpNo, O);
}

static void printSrcIdx64(MCInst *MI, unsigned OpNo, SStream *O)
{
printSrcIdx(MI, OpNo, O);
}

static void printDstIdx8(MCInst *MI, unsigned OpNo, SStream *O)
{
printDstIdx(MI, OpNo, O);
}

static void printDstIdx16(MCInst *MI, unsigned OpNo, SStream *O)
{
printDstIdx(MI, OpNo, O);
}

static void printDstIdx32(MCInst *MI, unsigned OpNo, SStream *O)
{
printDstIdx(MI, OpNo, O);
}

static void printDstIdx64(MCInst *MI, unsigned OpNo, SStream *O)
{
printDstIdx(MI, OpNo, O);
}

static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
{
MCOperand *DispSpec = MCInst_getOperand(MI, Op);
MCOperand *SegReg = MCInst_getOperand(MI, Op+1);

SStream_concat(O, "%s", markup("<mem:"));

// If this has a segment register, print it.
if (MCOperand_getReg(SegReg)) {
printOperand(MI, Op+1, O);
SStream_concat(O, ":");
}

if (MI->csh->detail) {
MI->flat_insn.x86.operands[MI->flat_insn.x86.op_count].type = X86_OP_MEM;
MI->flat_insn.x86.operands[MI->flat_insn.x86.op_count].mem.base = X86_REG_INVALID;
Expand Down Expand Up @@ -155,34 +232,16 @@ static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)

static void printMemOffs8(MCInst *MI, unsigned OpNo, SStream *O)
{
// If this has a segment register, print it.
// this is a hack. will fix it later
if (MI->x86_segment) {
SStream_concat(O, "%%%s:", X86_reg_name(1, MI->x86_segment));
}

printMemOffset(MI, OpNo, O);
}

static void printMemOffs16(MCInst *MI, unsigned OpNo, SStream *O)
{
// If this has a segment register, print it.
// this is a hack. will fix it later
if (MI->x86_segment) {
SStream_concat(O, "%%%s:", X86_reg_name(1, MI->x86_segment));
}

printMemOffset(MI, OpNo, O);
}

static void printMemOffs32(MCInst *MI, unsigned OpNo, SStream *O)
{
// If this has a segment register, print it.
// this is a hack. will fix it later
if (MI->x86_segment) {
SStream_concat(O, "%%%s:", X86_reg_name(1, MI->x86_segment));
}

printMemOffset(MI, OpNo, O);
}

Expand Down Expand Up @@ -257,6 +316,18 @@ static void printAVXCC(MCInst *MI, unsigned Op, SStream *O)
}
}

static void printRoundingControl(MCInst *MI, unsigned Op, SStream *O)
{
int64_t Imm = MCOperand_getImm(MCInst_getOperand(MI, Op)) & 0x3;
switch (Imm) {
case 0: SStream_concat(O, "{rn-sae}"); break;
case 1: SStream_concat(O, "{rd-sae}"); break;
case 2: SStream_concat(O, "{ru-sae}"); break;
case 3: SStream_concat(O, "{rz-sae}"); break;
default: break; // never reach
}
}

/// printPCRelImm - This is used to print an immediate value that ends up
/// being encoded as a pc-relative value (e.g. for jumps and calls). These
/// print slightly differently than normal immediates. For example, a $ is not
Expand Down
Loading

0 comments on commit 13f40d2

Please sign in to comment.