OLD | NEW |
---|---|
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_DECODING_H_ |
13 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ | 13 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ |
14 | 14 |
15 #include "native_client/src/trusted/validator_ragel/unreviewed/decoder.h" | 15 #include "native_client/src/trusted/validator_ragel/unreviewed/decoder.h" |
16 | 16 |
17 #if NACL_WINDOWS | 17 #if NACL_WINDOWS |
18 # define FORCEINLINE __forceinline | 18 # define FORCEINLINE __forceinline |
19 #else | 19 #else |
20 # define FORCEINLINE __inline __attribute__ ((always_inline)) | 20 # define FORCEINLINE __inline __attribute__ ((always_inline)) |
21 #endif | 21 #endif |
22 | 22 |
23 static FORCEINLINE uint8_t RegFromOpcode(uint8_t modrm) { | 23 static FORCEINLINE uint8_t RegFromOpcode(uint8_t modrm) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 } | 77 } |
78 | 78 |
79 static FORCEINLINE uint8_t GetOperandFromVexAMD64(uint8_t vex3) { | 79 static FORCEINLINE uint8_t GetOperandFromVexAMD64(uint8_t vex3) { |
80 return ((~vex3) & 0x78) >> 3; | 80 return ((~vex3) & 0x78) >> 3; |
81 } | 81 } |
82 | 82 |
83 static FORCEINLINE uint8_t RegisterFromIS4(uint8_t is4) { | 83 static FORCEINLINE uint8_t RegisterFromIS4(uint8_t is4) { |
84 return is4 >> 4; | 84 return is4 >> 4; |
85 } | 85 } |
86 | 86 |
87 /* | |
Brad Chen
2012/09/28 23:31:54
Suggestion: use a macro "SIGN_EXTEND" for example,
khim
2012/10/03 22:30:10
Done.
| |
88 * AnyFieldValue*Signed follow the very strange pattern: they calculate | |
89 * value using unsigned arythmetic, then convert it to signed value and | |
90 * finally they convert it back to unsgined uint64_t. | |
Brad Chen
2012/09/28 23:31:54
unsigned
khim
2012/10/03 22:30:10
Done.
| |
91 * | |
92 * This operation looks pointless and dangerous but it's actually safe | |
Brad Chen
2012/09/28 23:31:54
Some of the wording is a bit strong for such a com
khim
2012/10/03 22:30:10
Done.
| |
93 * and makes sense (even if it's fragile). Conversion from unsigned to | |
94 * signed does not change the value but conversion from signed to wider | |
95 * unsigned does sing-extension - and this is what we need. | |
Brad Chen
2012/09/28 23:31:54
sing => sign
khim
2012/10/03 22:30:10
Done.
| |
96 * | |
97 * Note: conversion from signed-to-unsigned and back is "implementation | |
98 * defined behavior", not "undefined behavior", which means that it may | |
99 * differ from implementation-to-implementation but each implementation | |
100 * must pick one approach and use it in all the appropriate cases. | |
101 * | |
102 * This conversion depends on the underlying architecture and on all | |
103 * x86-based systems it does what we need and at this point we don't | |
104 * care about compatibility of our validator and Cray X1. | |
105 */ | |
106 static FORCEINLINE uint64_t AnyFieldValue8bitSigned(uint8_t *start) { | |
107 return (int8_t) *disp; | |
108 } | |
109 | |
110 static FORCEINLINE uint64_t AnyFieldValue16bitSigned(uint8_t *start) { | |
111 return (int16_t) (disp[0] + 256U * disp[1]); | |
112 } | |
113 | |
114 static FORCEINLINE uint64_t AnyFieldValue32bitSigned(uint8_t *start) { | |
115 return (int32_t) (disp[0] + 256U * (disp[1] + | |
116 256U * (disp[2] + 256U * (disp[3])))); | |
117 } | |
118 static FORCEINLINE uint64_t AnyFieldValue64bitSigned(uint8_t *start) { | |
119 return (int64_t) (*disp + 256ULL * (disp[1] + 256ULL * (disp[2] + | |
120 256ULL * (disp[3] + 256ULL * (disp[4] + | |
121 256ULL * (disp[5] + 256ULL * (disp[6] + | |
122 256ULL * disp[7]))))))); | |
123 } | |
124 | |
125 static FORCEINLINE uint64_t AnyFieldValue8bitUnsigned(uint8_t *start) { | |
126 return *disp; | |
127 } | |
128 | |
129 static FORCEINLINE uint64_t AnyFieldValue16bitUnsigned(uint8_t *start) { | |
130 return (disp[0] + 256U * disp[1]); | |
131 } | |
132 | |
133 static FORCEINLINE uint64_t AnyFieldValue32bitUnsigned(uint8_t *start) { | |
134 return (disp[0] + 256U * (disp[1] + 256U * (disp[2] + 256U * (disp[3])))); | |
135 } | |
136 static FORCEINLINE uint64_t AnyFieldValue64bitUnsigned(uint8_t *start) { | |
137 return (*disp + 256ULL * (disp[1] + 256ULL * (disp[2] + 256ULL * (disp[3] + | |
138 256ULL * (disp[4] + 256ULL * (disp[5] + 256ULL * (disp[6] + | |
139 256ULL * disp[7]))))))); | |
140 } | |
87 static const uint8_t index_registers[] = { | 141 static const uint8_t index_registers[] = { |
88 /* Note how REG_RIZ falls out of the pattern. */ | 142 /* Note how REG_RIZ falls out of the pattern. */ |
89 REG_RAX, REG_RCX, REG_RDX, REG_RBX, | 143 REG_RAX, REG_RCX, REG_RDX, REG_RBX, |
90 REG_RIZ, REG_RBP, REG_RSI, REG_RDI, | 144 REG_RIZ, REG_RBP, REG_RSI, REG_RDI, |
91 REG_R8, REG_R9, REG_R10, REG_R11, | 145 REG_R8, REG_R9, REG_R10, REG_R11, |
92 REG_R12, REG_R13, REG_R14, REG_R15 | 146 REG_R12, REG_R13, REG_R14, REG_R15 |
93 }; | 147 }; |
94 | 148 |
95 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ */ | 149 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ */ |
OLD | NEW |