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 * ragel_tester.c | 8 * ragel_tester.c |
9 * Implements a ragel decoder that can be used as a NaClEnumeratorDecoder. | 9 * Implements a ragel decoder that can be used as a NaClEnumeratorDecoder. |
10 */ | 10 */ |
11 #ifndef NACL_TRUSTED_BUT_NOT_TCB | 11 #ifndef NACL_TRUSTED_BUT_NOT_TCB |
12 #error("This file is not meant for use in the TCB.") | 12 #error("This file is not meant for use in the TCB.") |
13 #endif | 13 #endif |
14 | 14 |
15 #include "native_client/src/trusted/validator/x86/testing/enuminsts/enuminsts.h" | 15 #include "native_client/src/trusted/validator/x86/testing/enuminsts/enuminsts.h" |
16 | 16 |
17 #include <string.h> | 17 #include <string.h> |
18 #include "native_client/src/trusted/validator/types_memory_model.h" | 18 #include "native_client/src/trusted/validator/types_memory_model.h" |
19 #include "native_client/src/trusted/validator/x86/ncinstbuffer.h" | 19 #include "native_client/src/trusted/validator/x86/ncinstbuffer.h" |
20 #include "native_client/src/trusted/validator/x86/testing/enuminsts/str_utils.h" | 20 #include "native_client/src/trusted/validator/x86/testing/enuminsts/str_utils.h" |
21 #include "native_client/src/trusted/validator_ragel/unreviewed/decoder.h" | 21 #include "native_client/src/trusted/validator_ragel/decoder.h" |
22 #include "native_client/src/trusted/validator_ragel/unreviewed/validator.h" | 22 #include "native_client/src/trusted/validator_ragel/unreviewed/validator.h" |
23 | 23 |
24 #define kBufferSize 1024 | 24 #define kBufferSize 1024 |
25 | 25 |
26 /* Defines the virtual table for the ragel decoder. */ | 26 /* Defines the virtual table for the ragel decoder. */ |
27 struct { | 27 struct { |
28 /* The virtual table that implements this decoder. */ | 28 /* The virtual table that implements this decoder. */ |
29 NaClEnumeratorDecoder _base; | 29 NaClEnumeratorDecoder _base; |
30 } ragel_decoder; | 30 } ragel_decoder; |
31 | 31 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 R15_MODIFIED | BPL_MODIFIED | SPL_MODIFIED | | 81 R15_MODIFIED | BPL_MODIFIED | SPL_MODIFIED | |
82 UNRESTRICTED_RBP_PROCESSED | UNRESTRICTED_RSP_PROCESSED | | 82 UNRESTRICTED_RBP_PROCESSED | UNRESTRICTED_RSP_PROCESSED | |
83 RESTRICTED_RSP_UNPROCESSED | RESTRICTED_RBP_UNPROCESSED)) { | 83 RESTRICTED_RSP_UNPROCESSED | RESTRICTED_RBP_UNPROCESSED)) { |
84 return FALSE; | 84 return FALSE; |
85 } else { | 85 } else { |
86 return TRUE; | 86 return TRUE; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 void RagelInstruction(const uint8_t *begin, const uint8_t *end, | 90 void RagelInstruction(const uint8_t *begin, const uint8_t *end, |
91 struct instruction *instruction, void *userdata) { | 91 struct Instruction *instruction, void *userdata) { |
92 struct RagelDecodeState *rstate = (struct RagelDecodeState *)userdata; | 92 struct RagelDecodeState *rstate = (struct RagelDecodeState *)userdata; |
93 UNREFERENCED_PARAMETER(instruction); | 93 UNREFERENCED_PARAMETER(instruction); |
94 /* Only look at the first instruction. */ | 94 /* Only look at the first instruction. */ |
95 if (rstate->valid_state) return; | 95 if (rstate->valid_state) return; |
96 if (end > begin) { | 96 if (end > begin) { |
97 rstate->inst_num_bytes = (uint8_t)(end - begin); | 97 rstate->inst_num_bytes = (uint8_t)(end - begin); |
98 rstate->inst_name = instruction->name; | 98 rstate->inst_name = instruction->name; |
99 } else { | 99 } else { |
100 rstate->inst_num_bytes = 0; | 100 rstate->inst_num_bytes = 0; |
101 } | 101 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if (RState.inst_is_legal) { | 148 if (RState.inst_is_legal) { |
149 uint8_t chunk[(NACL_ENUM_MAX_INSTRUCTION_BYTES + kBundleMask) & | 149 uint8_t chunk[(NACL_ENUM_MAX_INSTRUCTION_BYTES + kBundleMask) & |
150 ~kBundleMask]; | 150 ~kBundleMask]; |
151 | 151 |
152 /* Copy the command. */ | 152 /* Copy the command. */ |
153 memcpy(chunk, enumerator->_itext, tempstate.inst_num_bytes); | 153 memcpy(chunk, enumerator->_itext, tempstate.inst_num_bytes); |
154 /* Fill the rest with HLTs. */ | 154 /* Fill the rest with HLTs. */ |
155 memset(chunk + tempstate.inst_num_bytes, 0xf4, | 155 memset(chunk + tempstate.inst_num_bytes, 0xf4, |
156 sizeof(chunk) - tempstate.inst_num_bytes); | 156 sizeof(chunk) - tempstate.inst_num_bytes); |
157 res = ValidateChunkArch(chunk, sizeof(chunk), 0 /*options*/, | 157 res = ValidateChunkArch(chunk, sizeof(chunk), 0 /*options*/, |
158 &full_cpuid_features, | 158 &kFullCPUIDFeatures, |
159 RagelValidateError, NULL); | 159 RagelValidateError, NULL); |
160 RState.inst_is_valid = res; | 160 RState.inst_is_valid = res; |
161 } | 161 } |
162 | 162 |
163 #undef DecodeChunkArch | 163 #undef DecodeChunkArch |
164 #undef ValidateChunkArch | 164 #undef ValidateChunkArch |
165 } | 165 } |
166 | 166 |
167 /* Returns true if the instruction parsed a legal instruction. */ | 167 /* Returns true if the instruction parsed a legal instruction. */ |
168 static Bool RIsInstLegal(const NaClEnumerator* enumerator) { | 168 static Bool RIsInstLegal(const NaClEnumerator* enumerator) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 ragel_decoder._base._install_flag_fn = InstallFlag; | 209 ragel_decoder._base._install_flag_fn = InstallFlag; |
210 ragel_decoder._base._get_inst_mnemonic_fn = RGetInstMnemonic; | 210 ragel_decoder._base._get_inst_mnemonic_fn = RGetInstMnemonic; |
211 ragel_decoder._base._get_inst_num_operands_fn = NULL; | 211 ragel_decoder._base._get_inst_num_operands_fn = NULL; |
212 ragel_decoder._base._get_inst_operands_text_fn = NULL; | 212 ragel_decoder._base._get_inst_operands_text_fn = NULL; |
213 ragel_decoder._base._writes_to_reserved_reg_fn = NULL; | 213 ragel_decoder._base._writes_to_reserved_reg_fn = NULL; |
214 ragel_decoder._base._maybe_inst_validates_fn = RIsInstValid; | 214 ragel_decoder._base._maybe_inst_validates_fn = RIsInstValid; |
215 ragel_decoder._base._segment_validates_fn = NULL; | 215 ragel_decoder._base._segment_validates_fn = NULL; |
216 ragel_decoder._base._usage_message = "Runs ragel to decode instructions."; | 216 ragel_decoder._base._usage_message = "Runs ragel to decode instructions."; |
217 return &ragel_decoder._base; | 217 return &ragel_decoder._base; |
218 } | 218 } |
OLD | NEW |