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.
8 * API to generator routines for building x86 instruction set.
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_GENERATOR_NCDECODE_TABLEGEN_H__
12 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_GENERATOR_NCDECODE_TABLEGEN_H__
14 #ifndef NACL_TRUSTED_BUT_NOT_TCB
15 #error("This file is not meant for use in the TCB")
18 #include "native_client/src/trusted/validator/x86/decoder/generator/modeled_nacl_inst.h"
20 struct NaClSymbolTable;
22 /* Report the given fatal error, and then quit. */
23 void NaClFatal(const char* s);
25 /* Possible run modes for instructions. */
27 X86_32, /* Model x86-32 bit instructions. */
28 X86_64, /* Model x86-64-bit instructions. */
29 /* Special end of list marker, denoting the number
35 /* Defines the run mode files that should be generated. */
36 extern NaClRunMode NACL_FLAGS_run_mode;
38 /* Change the current opcode prefix to the given value. */
39 void NaClDefInstPrefix(const NaClInstPrefix prefix);
41 /* Resets the default opcode prefix to the value of the last
42 * call to NaClDefDefaultInstPrefix.
44 void NaClResetToDefaultInstPrefix(void);
46 /* Same as NaClDefInstChoices, but you can explicitly define the
47 * prefix associated with the opcode.
49 void NaClDefPrefixInstChoices(const NaClInstPrefix prefix,
53 /* Same as NaClDefPrefixInstChoices, but extends the opcode with
54 * the modrm opcode in the modrm byte (must be in [0..7]).
56 void NaClDefPrefixInstMrmChoices(const NaClInstPrefix prefix,
58 const uint8_t modrm_opcode,
61 /* Same as NaClDefInstChoices_32_64, but you can explicitly define the
62 * prefix associated with the opcode.
64 void NaClDefPrefixInstChoices_32_64(const NaClInstPrefix prefix,
69 /* Same as NaClDefPrefixInstChoices_32_64, but extends the opcode with
70 * the modrm opcode in the modrm byte (must be in [0..7]).
72 void NaClDefPrefixInstMrmChoices_32_64(const NaClInstPrefix prefix,
74 const uint8_t modrm_opcode,
78 /* By default, sanity checks are applied as each defining
79 * call is made. When this is called, these sanity checks
80 * are turned off until the explicit call to NaClApplySanityChecks.
82 void NaClDelaySanityChecks(void);
84 void NaClApplySanityChecks(void);
86 /* Define the next opcode (instruction), initializing with
91 const NaClInstType insttype,
93 const NaClMnemonic name);
95 /* Returns the current instruction being defined.
96 * ***WARNING***: If you call any function within this header file
97 * that modifies the current instruction will invalidate the contents
98 * returned by this function.
100 NaClModeledInst* NaClGetDefInst(void);
102 /* Define an opcode extension for the current instruction, which is
103 * a value between 0 and 7, that appears in the modrm byte of the
106 void NaClDefOpcodeExtension(int opcode);
108 /* Defines an opcode extension stored in the ModRm r/m field (must be
111 void NaClDefineOpcodeModRmRmExtension(int value);
113 /* Define a register value embedded in the opcode value. */
114 void NaClDefOpcodeRegisterValue(int r);
116 /* Add additional instruction flags to the current instruction being
119 void NaClAddIFlags(NaClIFlags more_flags);
121 /* Remove instruction flags from the current instruction being processed. */
122 void NaClRemoveIFlags(NaClIFlags less_flags);
125 * Define the next operand of the current opcode to have the given kind
128 void NaClDefOp(NaClOpKind kind, NaClOpFlags flags);
130 /* Add additional operand flags to the indexed operand of the current
131 * instruction being processed (index is 0 based).
133 void NaClAddOpFlags(uint8_t operand_index, NaClOpFlags more_flags);
135 /* Add format string to the indexed oeprand of the current instruction
136 * being processed (index is 0 based).
138 * Note: the passed in string is copied, and hence its contents can
139 * change once this function returns.
141 void NaClAddOpFormat(uint8_t operand_index, const char* format);
143 /* Removes operand flags from the indexed operand of the current
144 * instruction being processed (index is 0 based).
146 void NaClRemoveOpFlags(uint8_t operand_index, NaClOpFlags flags);
148 /* Returns the set of operand size flags defined for the given instruction. */
149 NaClIFlags NaClOperandSizes(NaClModeledInst* inst);
151 /* Defines one byte opcodes. */
152 void NaClDefOneByteInsts(struct NaClSymbolTable* context_st);
154 /* Defines two byte opcodes beginning with OF. */
155 void NaClDef0FInsts(struct NaClSymbolTable* context_st);
157 /* Defines two byte opcodes beginning with DC. */
158 void NaClDefDCInsts(void);
160 /* Defines SSE instructions (i.e. instructions using MMX and XMM registers). */
161 void NaClDefSseInsts(struct NaClSymbolTable* context_st);
163 /* Define x87 instructions. */
164 void NaClDefX87Insts(struct NaClSymbolTable* context_st);
166 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_GENERATOR_NCDECODE_TABLEGEN_H__ */