1 : /*
2 : * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : /* Descriptors to model instructions, opcodes, and instruction operands. */
8 :
9 : #include "native_client/src/trusted/validator/x86/decoder/ncopcode_desc.h"
10 :
11 : #include <assert.h>
12 : #include <string.h>
13 :
14 : #include "native_client/src/trusted/validator/x86/decoder/nc_decode_tables.h"
15 :
16 : #include "native_client/src/trusted/validator/x86/decoder/ncopcode_desc_inl.c"
17 :
18 : void NaClInstPrint(struct Gio* f,
19 : const NaClDecodeTables* tables,
20 1 : const NaClInst* inst) {
21 : { /* Print out instruction type less the NACLi_ prefix. */
22 1 : const char* name = NaClInstTypeString(inst->insttype);
23 1 : gprintf(f, "%s ", name + strlen("NACLi_"));
24 : }
25 1 : if (inst->flags) NaClIFlagsPrint(f, inst->flags);
26 1 : gprintf(f, "\n");
27 :
28 : /* If instruction type is invalid, and doesn't have
29 : * special translation purposes, then don't print additional
30 : * (ignored) information stored in the modeled instruction.
31 : */
32 : if ((NACLi_INVALID != inst->insttype) ||
33 1 : ((inst->flags & NACL_IFLAG(Opcode0F0F)))) {
34 1 : Bool is_first = TRUE;
35 : int i;
36 1 : gprintf(f, " %s", NaClMnemonicName(inst->name));
37 1 : for (i = 0; i < inst->num_operands; ++i) {
38 1 : const NaClOp* op = NaClGetInstOperandInline(tables, inst, i);
39 1 : if (NULL == op->format_string) continue;
40 1 : if (is_first) {
41 1 : is_first = FALSE;
42 1 : } else {
43 1 : gprintf(f, ",");
44 : }
45 1 : gprintf(f, " %s", op->format_string);
46 1 : }
47 1 : gprintf(f, "\n");
48 : /* Now print actual encoding of each operand. */
49 1 : for (i = 0; i < inst->num_operands; ++i) {
50 1 : gprintf(f, " ");
51 1 : NaClOpPrint(f, NaClGetInstOperand(tables, inst, i));
52 1 : }
53 : }
54 1 : }
55 :
56 : /* Dummy routine to allow unreferenced NaClGetInstNumberOperandsInline
57 : * inline.
58 : */
59 : uint8_t NaClNcopcodeDescVerboseDummyNaClGetInstNumberOperands(
60 0 : const NaClInst* inst) {
61 0 : return NaClGetInstNumberOperandsInline(inst);
62 0 : }
|