void NCPrintInstWithHex(const NCDecoderInst *dinst, struct Gio *fp) {
  int i;
  DEBUG( printf("use format: %s\n", DisFmt(dinst)) );
  gprintf(fp, " %"NACL_PRIxNaClPcAddress":\t%02x",
          NCPrintableInstructionAddress(dinst),
          NCInstBytesByte(&dinst->inst_bytes, 0));
  for (i = 1; i < dinst->inst.bytes.length; i++) {
    gprintf(fp, " %02x", NCInstBytesByte(&dinst->inst_bytes, i));
  }
  for (i = dinst->inst.bytes.length; i < 7; i++) gprintf(fp, "   ");
  gprintf(fp, "\t");
  NCPrintInstWithoutHex(dinst, fp);
}
Exemplo n.º 2
0
static INLINE void RememberInstructionBoundary(const NCDecoderInst *dinst,
                                              struct NCValidatorState *vstate) {
  /* The decoder should never pass us an out-of-bounds instruction. */
  CHECK(dinst->inst_addr < vstate->codesize);
  if (NCGetAdrTable(dinst->inst_addr, vstate->vttable)) {
    vprint(vstate, (reporter,
                    "RememberIP: Saw inst at %"NACL_PRIxNaClPcAddressAll
                    " twice\n", NCPrintableInstructionAddress(dinst)));
    NCStatsInternalError(vstate);
    return;
  }
  NCStatsInst(vstate);
  NCSetAdrTable(dinst->inst_addr, vstate->vttable);
}
Exemplo n.º 3
0
static void ValidatePrintInstructionError(const struct NCDecoderInst *dinst,
                                          const char *msg,
                                          struct NCValidatorState *vstate) {
  ValidatePrintError(NCPrintableInstructionAddress(dinst), msg, vstate);
}
static void InstFormat(const char* format,
                       const NCDecoderInst *dinst,
                       struct Gio* fp) {
  char token_buf[128];
  char* fmt = token_buf;
  int pos = 0;

  strncpy(token_buf, format, sizeof(token_buf));

  while (1) {
    char* token = strtok(fmt, " ,\n");
    DEBUG( printf("\ntoken = '%s'\n", token) );
    if (NULL == token) {
      break;
    }
    if (pos > 1) {
      gprintf(fp, ", ");
    } else if (pos > 0) {
      gprintf(fp, " ");
    }
    if ('$' == token[0]) {
      NaClMRMGroups group = ParseGroupName(token+1);
      if (NOGROUP != group) {
        int mrm = modrm_regInline(dinst->inst.mrm);
        const char* opname = kDisasmModRMOp[group][mrm];
        DEBUG( printf("case: group %d, opname = %s\n", group, opname) );
        gprintf(fp, "%s", opname);
      } else {
        /* Tokens starting with a $ but not $group need formatting */
        DEBUG( printf("case: $ and not group\n") );
        switch (token[1]) {
          case 'A':
            gprintf(fp, "$A");
            break;
          case 'C':
            gprintf(fp, "%%cr%d", modrm_regInline(dinst->inst.mrm));
            break;
          case 'D':
            gprintf(fp, "%%dr%d", modrm_regInline(dinst->inst.mrm));
            break;
          case 'E':
          case 'M': /* mod should never be 3 for 'M' */
            /* TODO(sehr): byte and word accesses */
            RegMemPrint(dinst, gp_regs, 1, fp);
            break;
          case 'F':
            gprintf(fp, "eflags");
            break;
          case 'G':
            gprintf(fp, "%s", gp_regs[modrm_regInline(dinst->inst.mrm)]);
            break;
          case 'I':
            gprintf(fp, "0x%"NACL_PRIx64, ImmedValue64(dinst));
            break;
          case 'J':
            gprintf(fp, "0x%"NACL_PRIxNaClPcAddress,
                    NCPrintableInstructionAddress(dinst)
                    + dinst->inst.bytes.length
                    + ImmedValue32(dinst));
            break;
          case 'O':
            gprintf(fp, "[0x%"NACL_PRIx64"]", ImmedValue64(dinst));
            break;
          case 'P':
            if ('R' == token[2]) {
              gprintf(fp, "%%mm%d", modrm_rmInline(dinst->inst.mrm));
            } else {
              gprintf(fp, "%%mm%d", modrm_regInline(dinst->inst.mrm));
            }
            break;
          case 'Q':
            RegMemPrint(dinst, mmx_regs, 0, fp);
            break;
          case 'R':
            gprintf(fp, "%s", gp_regs[modrm_rmInline(dinst->inst.mrm)]);
            break;
          case 'S':
            gprintf(fp, "%s", seg_regs[modrm_regInline(dinst->inst.mrm)]);
            break;
          case 'V':
            if ('R' == token[2]) {
              gprintf(fp, "%%xmm%d", modrm_rmInline(dinst->inst.mrm));
            } else {
              gprintf(fp, "%%xmm%d", modrm_regInline(dinst->inst.mrm));
            }
            break;
          case 'W':
            RegMemPrint(dinst, xmm_regs, 0, fp);
            break;
          case 'X':
            gprintf(fp, "ds:[esi]");
            break;
          case 'Y':
            gprintf(fp, "es:[edi]");
            break;
          default:
            gprintf(fp, "token('%s')", token);
            break;
        }
      }
    } else {
      /* Print the token as is */
      gprintf(fp, "%s", token);
    }
    fmt = NULL;
    ++pos;
  }
}