Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1137)

Side by Side Diff: src/trusted/validator_ragel/unreviewed/decoder_internal.h

Issue 11000033: Move validator_x86_XX.rl out of unreviewed. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * This file contains common parts of x86-32 and x86-64 internals (inline 8 * This file contains common parts of x86-32 and x86-64 internals (inline
9 * functions and defines). 9 * functions and defines).
10 */ 10 */
11 11
12 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ 12 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_
13 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ 13 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_
14 14
15 #include "native_client/src/trusted/validator_ragel/unreviewed/decoder.h" 15 #define GET_REX_PREFIX() instruction.prefix.rex
16 #define SET_REX_PREFIX(P) instruction.prefix.rex = (P)
17 #define GET_VEX_PREFIX2() vex_prefix2
18 #define SET_VEX_PREFIX2(P) vex_prefix2 = (P)
19 #define GET_VEX_PREFIX3() vex_prefix3
20 #define SET_VEX_PREFIX3(P) vex_prefix3 = (P)
21 #define SET_DATA16_PREFIX(S) instruction.prefix.data16 = (S)
22 #define SET_LOCK_PREFIX(S) instruction.prefix.lock = (S)
23 #define SET_REPZ_PREFIX(S) instruction.prefix.repz = (S)
24 #define SET_REPNZ_PREFIX(S) instruction.prefix.repnz = (S)
25 #define SET_BRANCH_TAKEN(S) instruction.prefix.branch_taken = (S)
26 #define SET_BRANCH_NOT_TAKEN(S) instruction.prefix.branch_not_taken = (S)
27 #define SET_INSTRUCTION_NAME(N) instruction.name = (N)
28 #define GET_OPERAND_NAME(N) instruction.operands[(N)].name
29 #define SET_OPERAND_NAME(N, S) instruction.operands[(N)].name = (S)
30 #define SET_OPERAND_TYPE(N, S) instruction.operands[(N)].type = (S)
31 #define SET_OPERANDS_COUNT(N) instruction.operands_count = (N)
32 #define SET_MODRM_BASE(N) instruction.rm.base = (N)
33 #define SET_MODRM_INDEX(N) instruction.rm.index = (N)
34 #define SET_MODRM_SCALE(S) instruction.rm.scale = (S)
35 #define SET_DISP_TYPE(T) instruction.rm.disp_type = (T)
36 #define SET_DISP_PTR(P) \
37 switch (instruction.rm.disp_type) { \
38 case DISPNONE: \
39 instruction.rm.offset = 0; \
40 break; \
41 case DISP8: \
42 instruction.rm.offset = AnyFieldValue8bitSigned(P); \
43 case DISP16: \
44 instruction.rm.offset = AnyFieldValue16bitSigned(P); \
45 break; \
46 case DISP32: \
47 instruction.rm.offset = AnyFieldValue32bitSigned(P); \
48 break; \
49 case DISP64: \
50 instruction.rm.offset = AnyFieldValue64bitSigned(P); \
51 break; \
52 }
53 #define SET_IMM_TYPE(T) imm_operand = (T)
54 #define SET_IMM_PTR(P) SET_IMM_PTR(P, 0, imm2_operand)
55 #define SET_IMM2_TYPE(T) imm2_operand = (T)
56 #define SET_IMM2_PTR(P) SET_IMM_PTR(P, 1, imm2_operand)
57 #define SET_IMM_PTR(P, N, O) \
58 switch (O) { \
59 case IMMNONE: \
60 instruction.imm[N] = 0; \
61 break; \
62 case IMM2: \
63 instruction.imm[N] = P[0] & 0x03; \
64 break; \
65 case IMM8: \
66 instruction.imm[N] = AnyFieldValue8bitUnsigned(P); \
67 break; \
68 case IMM16: \
69 instruction.imm[N] = AnyFieldValue16bitUnsigned(P); \
70 break; \
71 case IMM32: \
72 instruction.imm[N] = AnyFieldValue32bitUnsigned(P); \
73 break; \
74 case IMM64: \
75 instruction.imm[N] = AnyFieldValue64bitUnsigned(P); \
76 break; \
77 }
78 #define SET_CPU_FEATURE(F)
16 79
17 #if NACL_WINDOWS 80 enum {
18 # define FORCEINLINE __forceinline 81 REX_B = 1,
19 #else 82 REX_X = 2,
20 # define FORCEINLINE __inline __attribute__ ((always_inline)) 83 REX_R = 4,
21 #endif 84 REX_W = 8
85 };
22 86
23 static FORCEINLINE uint8_t RegFromOpcode(uint8_t modrm) { 87 enum imm_mode {
24 return modrm & 0x07; 88 IMMNONE,
25 } 89 IMM2,
26 90 IMM8,
27 static FORCEINLINE uint8_t ModFromModRM(uint8_t modrm) { 91 IMM16,
28 return modrm >> 6; 92 IMM32,
29 } 93 IMM64
30
31 static FORCEINLINE uint8_t RegFromModRM(uint8_t modrm) {
32 return (modrm & 0x38) >> 3;
33 }
34
35 static FORCEINLINE uint8_t RMFromModRM(uint8_t modrm) {
36 return modrm & 0x07;
37 }
38
39 static FORCEINLINE uint8_t ScaleFromSIB(uint8_t sib) {
40 return sib >> 6;
41 }
42
43 static FORCEINLINE uint8_t IndexFromSIB(uint8_t sib) {
44 return (sib & 0x38) >> 3;
45 }
46
47 static FORCEINLINE uint8_t BaseFromSIB(uint8_t sib) {
48 return sib & 0x07;
49 }
50
51 static FORCEINLINE uint8_t BaseExtentionFromREX(uint8_t rex) {
52 return (rex & 0x01) << 3;
53 }
54
55 static FORCEINLINE uint8_t BaseExtentionFromVEX(uint8_t vex2) {
56 return ((~vex2) & 0x20) >> 2;
57 }
58
59 static FORCEINLINE uint8_t IndexExtentionFromREX(uint8_t rex) {
60 return (rex & 0x02) << 2;
61 }
62
63 static FORCEINLINE uint8_t IndexExtentionFromVEX(uint8_t vex2) {
64 return ((~vex2) & 0x40) >> 3;
65 }
66
67 static FORCEINLINE uint8_t RegisterExtentionFromREX(uint8_t rex) {
68 return (rex & 0x04) << 1;
69 }
70
71 static FORCEINLINE uint8_t RegisterExtentionFromVEX(uint8_t vex2) {
72 return ((~vex2) & 0x80) >> 4;
73 }
74
75 static FORCEINLINE uint8_t GetOperandFromVexIA32(uint8_t vex3) {
76 return ((~vex3) & 0x38) >> 3;
77 }
78
79 static FORCEINLINE uint8_t GetOperandFromVexAMD64(uint8_t vex3) {
80 return ((~vex3) & 0x78) >> 3;
81 }
82
83 static FORCEINLINE uint8_t RegisterFromIS4(uint8_t is4) {
84 return is4 >> 4;
85 }
86
87 static const uint8_t index_registers[] = {
88 /* Note how REG_RIZ falls out of the pattern. */
89 REG_RAX, REG_RCX, REG_RDX, REG_RBX,
90 REG_RIZ, REG_RBP, REG_RSI, REG_RDI,
91 REG_R8, REG_R9, REG_R10, REG_R11,
92 REG_R12, REG_R13, REG_R14, REG_R15
93 }; 94 };
94 95
95 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ */ 96 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698