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

Side by Side Diff: src/trusted/validator/x86/testing/enuminsts/xed_tester.c

Issue 9861030: Modify enuminsts to be able to communicate matched instructions accross (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 8 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 * xed_tester.c 8 * xed_tester.c
9 * Implements a xed decoder that can be used as a NaClEnumeratorDecoder. 9 * Implements a xed decoder that can be used as a NaClEnumeratorDecoder.
10 */ 10 */
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 static const char* GetInstOperandsText(NaClEnumerator* enumerator) { 145 static const char* GetInstOperandsText(NaClEnumerator* enumerator) {
146 /* Force caching of operands and return. */ 146 /* Force caching of operands and return. */
147 if (xed_decoder._xed_operands[0] == 0) GetInstMnemonic(enumerator); 147 if (xed_decoder._xed_operands[0] == 0) GetInstMnemonic(enumerator);
148 return xed_decoder._xed_operands; 148 return xed_decoder._xed_operands;
149 } 149 }
150 150
151 /* Prints out the disassembled instruction. */ 151 /* Prints out the disassembled instruction. */
152 static void PrintInst(NaClEnumerator* enumerator) { 152 static void PrintInst(NaClEnumerator* enumerator) {
153 int i; 153 int i;
154 if (enumerator->_print_opcode_bytes_only) { 154 size_t opcode_size;
155 for (i = 0; i < xed_decoder._xedd._decoded_length; ++i) { 155 NaClPcAddress pc_address = (NaClPcAddress) xed_decoder._pc_address;
156 printf("%02x", enumerator->_itext[i]); 156 printf(" XED: %"NACL_PRIxNaClPcAddressAll": ", pc_address);
157 } 157
158 printf("\n"); 158 /* Since xed doesn't print out opcode sequence, and it is
159 } else { 159 * useful to know, add it to the print out. Note: Use same
160 size_t opcode_size; 160 * spacing scheme as nacl decoder, so things line up.
161 if (!enumerator->_print_enumerated_instruction) { 161 */
162 NaClPcAddress pc_address = (NaClPcAddress) xed_decoder._pc_address; 162 size_t num_bytes = MAX_INST_LENGTH;
163 printf(" XED: %"NACL_PRIxNaClPcAddressAll": ", pc_address); 163 if (enumerator->_num_bytes > num_bytes)
164 } 164 num_bytes = enumerator->_num_bytes;
165 /* Since xed doesn't print out opcode sequence, and it is 165 for (i = 0; i < num_bytes; ++i) {
166 * useful to know, add it to the print out. Note: Use same 166 if (i < xed_decoder._xedd._decoded_length) {
167 * spacing scheme as nacl decoder, so things line up. 167 printf("%02x ", enumerator->_itext[i]);
168 */
169 size_t num_bytes = MAX_INST_LENGTH;
170 if (enumerator->_num_bytes > num_bytes)
171 num_bytes = enumerator->_num_bytes;
172 for (i = 0; i < num_bytes; ++i) {
173 if (i < xed_decoder._xedd._decoded_length) {
174 printf("%02x ", enumerator->_itext[i]);
175 } else if (!enumerator->_print_enumerated_instruction) {
176 printf(" ");
177 }
178 }
179 if (enumerator->_print_enumerated_instruction) {
180 printf("#%s %s\n", GetInstMnemonic(enumerator),
181 GetInstOperandsText(enumerator));
182 } else { 168 } else {
183 printf("%s\n", Disassemble(enumerator)); 169 printf(" ");
184 } 170 }
185 } 171 }
172 printf("%s\n", Disassemble(enumerator));
186 } 173 }
187 174
188 static size_t InstLength(NaClEnumerator* enumerator) { 175 static size_t InstLength(NaClEnumerator* enumerator) {
189 return (size_t) xed_decoder._xedd._decoded_length; 176 return (size_t) xed_decoder._xedd._decoded_length;
190 } 177 }
191 178
192 static inline xed_inst_t const* GetXedInst() { 179 static inline xed_inst_t const* GetXedInst() {
193 if (xed_decoder._xed_inst == NULL) { 180 if (xed_decoder._xed_inst == NULL) {
194 xed_decoder._xed_inst = xed_decoded_inst_inst(&xed_decoder._xedd); 181 xed_decoder._xed_inst = xed_decoded_inst_inst(&xed_decoder._xedd);
195 } 182 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 222 }
236 #elif NACL_TARGET_SUBARCH == 32 223 #elif NACL_TARGET_SUBARCH == 32
237 static Bool WritesToReservedReg(NaClEnumerator* enumerator, 224 static Bool WritesToReservedReg(NaClEnumerator* enumerator,
238 size_t n) { 225 size_t n) {
239 return FALSE; 226 return FALSE;
240 } 227 }
241 #else 228 #else
242 #error("Bad NACL_TARGET_SUBARCH") 229 #error("Bad NACL_TARGET_SUBARCH")
243 #endif 230 #endif
244 231
245 static const char* Usage() {
246 return "Runs xed to decode instructions.";
247 }
248
249 static void InstallFlag(NaClEnumerator* enumerator, 232 static void InstallFlag(NaClEnumerator* enumerator,
250 const char* flag_name, 233 const char* flag_name,
251 void* flag_address) { 234 void* flag_address) {
252 } 235 }
253 236
254 /* Defines the registry function that creates a xed decoder, and returns 237 /* Defines the registry function that creates a xed decoder, and returns
255 * the decoder to be registered. 238 * the decoder to be registered.
256 */ 239 */
257 NaClEnumeratorDecoder* RegisterXedDecoder() { 240 NaClEnumeratorDecoder* RegisterXedDecoder() {
258 XedSetup(); 241 XedSetup();
259 xed_decoder._base._id_name = "xed"; 242 xed_decoder._base._id_name = "xed";
260 xed_decoder._base._legal_only = TRUE;
261 xed_decoder._base._print_only = FALSE;
262 xed_decoder._base._parse_inst_fn = ParseInst; 243 xed_decoder._base._parse_inst_fn = ParseInst;
263 xed_decoder._base._inst_length_fn = InstLength; 244 xed_decoder._base._inst_length_fn = InstLength;
264 xed_decoder._base._print_inst_fn = PrintInst; 245 xed_decoder._base._print_inst_fn = PrintInst;
265 xed_decoder._base._get_inst_mnemonic_fn = GetInstMnemonic; 246 xed_decoder._base._get_inst_mnemonic_fn = GetInstMnemonic;
266 xed_decoder._base._get_inst_num_operands_fn = GetNumOperands; 247 xed_decoder._base._get_inst_num_operands_fn = GetNumOperands;
267 xed_decoder._base._get_inst_operands_text_fn = GetInstOperandsText; 248 xed_decoder._base._get_inst_operands_text_fn = GetInstOperandsText;
268 xed_decoder._base._writes_to_reserved_reg_fn = WritesToReservedReg; 249 xed_decoder._base._writes_to_reserved_reg_fn = WritesToReservedReg;
269 xed_decoder._base._is_inst_legal_fn = IsInstLegal; 250 xed_decoder._base._is_inst_legal_fn = IsInstLegal;
270 xed_decoder._base._maybe_inst_validates_fn = NULL; 251 xed_decoder._base._maybe_inst_validates_fn = NULL;
271 xed_decoder._base._segment_validates_fn = NULL; 252 xed_decoder._base._segment_validates_fn = NULL;
272 xed_decoder._base._install_flag_fn = InstallFlag; 253 xed_decoder._base._install_flag_fn = InstallFlag;
273 xed_decoder._base._usage_message = "Runs xed to decode instructions."; 254 xed_decoder._base._usage_message = "Runs xed to decode instructions.";
274 return &xed_decoder._base; 255 return &xed_decoder._base;
275 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698