| OLD | NEW |
| (Empty) |
| 1 /* | |
| 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 | |
| 4 * found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 /* | |
| 8 * This file contains common parts of x86-32 and x86-64 internals (inline | |
| 9 * functions and defines). | |
| 10 */ | |
| 11 | |
| 12 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ | |
| 13 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ | |
| 14 | |
| 15 #include "native_client/src/trusted/validator_ragel/unreviewed/decoder.h" | |
| 16 | |
| 17 #if NACL_WINDOWS | |
| 18 # define FORCEINLINE __forceinline | |
| 19 #else | |
| 20 # define FORCEINLINE __inline __attribute__ ((always_inline)) | |
| 21 #endif | |
| 22 | |
| 23 static FORCEINLINE uint8_t RegFromOpcode(uint8_t modrm) { | |
| 24 return modrm & 0x07; | |
| 25 } | |
| 26 | |
| 27 static FORCEINLINE uint8_t ModFromModRM(uint8_t modrm) { | |
| 28 return modrm >> 6; | |
| 29 } | |
| 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 | |
| 95 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ */ | |
| OLD | NEW |