示例#1
0
/* Get the ST register defined from the difference of the opcode, and
 * its opcode base.
 */
static NaClExp* NaClAppendStOpcodeBaseReg(NaClInstState* state) {
  int reg_index;
  reg_index = NaClGetOpcodePlusR(state->inst->opcode_ext);
  assert(reg_index >= 0 && reg_index < 8);
  DEBUG(NaClLog(LOG_INFO, "Translate opcode base register %d\n", reg_index));
  return NaClAppendReg(RegST0 + reg_index, &state->nodes);
}
示例#2
0
/* Get the register index from the difference of the opcode, and
 * its opcode base.
 */
static NaClExp* NaClAppendOpcodeBaseReg(
    NaClInstState* state, const NaClOp* operand) {
  int reg_index;
  reg_index = NaClGetOpcodePlusR(state->inst->opcode_ext);
  assert(reg_index >= 0 && reg_index < 8);
  DEBUG(NaClLog(LOG_INFO, "Translate opcode base register %d\n", reg_index));
  return NaClAppendRegKind(state, NaClExtractOpRegKind(state, operand),
                            NaClGetRexBReg(state, reg_index));
}
/* Inspect the parsed instruction to print out the opcode sequence matched. */
static void NaClInstPrintOpcodeSeq(struct Gio* gout,
                                   const NaClInstState* state) {
  size_t count = 0;
  if (state->num_opcode_bytes == 0) {
    /* Hard coded bytes sequence for instruction. */
    gprintf(gout, "  %s", kHardCodedMessage);
    count = strlen(kHardCodedMessage) + 2;
  } else {
    /* Modeled instruction. Pull out parsed opcode bytes from parsed
     * instruction.
     */
    int i;
    gprintf(gout, " ");
    count = 1;

    /* Add prefix selector if applicable. */
    if (state->opcode_prefix) {
      gprintf(gout, " %02x", state->opcode_prefix);
      count += 3;
    }

    /* Add opcode bytes. */
    for (i = 0; i < state->num_opcode_bytes; ++i) {
      gprintf(gout, " %02x", state->bytes.byte[state->num_prefix_bytes + i]);
      count += 3;
    }
    if (state->inst->flags & NACL_IFLAG(OpcodeInModRm)) {
      gprintf(gout, " / %d", modrm_opcode(state->modrm));
      count += 4;
    } else if (state->inst->flags & NACL_IFLAG(OpcodePlusR)) {
      gprintf(gout, " - r%d",
              NaClGetOpcodePlusR(state->inst->opcode_ext));
      count += 5;
    }
    if (state->inst->flags & NACL_IFLAG(OpcodeInModRmRm)) {
      gprintf(gout, " / %d", modrm_rm(state->modrm));
      count += 4;
    }
    /* Add opcode for 0f0f instructions, where the opcode is the last
     * byte of the instruction.
     */
    if ((state->num_opcode_bytes >= 2) &&
        (0 == (state->inst->flags & NACL_IFLAG(Opcode0F0F))) &&
        (0x0F == state->bytes.byte[state->num_prefix_bytes]) &&
        (0x0F == state->bytes.byte[state->num_prefix_bytes + 1])) {
      gprintf(gout, " %02x", state->bytes.byte[state->bytes.length - 1]);
      count += 3;
    }
  }
  while (count < 30) {
    gprintf(gout, " ");
    ++count;
  }
}