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 * nacl_tester.c | 8 * nacl_tester.c |
9 * Uses the NaCl x86 validator/decoder to implement a NaClEnumeratorDecoder. | 9 * Uses the NaCl x86 validator/decoder to implement a NaClEnumeratorDecoder. |
10 */ | 10 */ |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 if (NULL == after_mnemonic) after_mnemonic = disassembly; | 238 if (NULL == after_mnemonic) after_mnemonic = disassembly; |
239 cstrncpy(operands, after_mnemonic, kBufferSize); | 239 cstrncpy(operands, after_mnemonic, kBufferSize); |
240 strnzapchar(operands, '%'); | 240 strnzapchar(operands, '%'); |
241 strnzapchar(operands, '\n'); | 241 strnzapchar(operands, '\n'); |
242 cstrncpy(nacl_decoder._operands, strip(operands), kBufferSize); | 242 cstrncpy(nacl_decoder._operands, strip(operands), kBufferSize); |
243 return nacl_decoder._operands; | 243 return nacl_decoder._operands; |
244 } | 244 } |
245 | 245 |
246 /* Prints out the disassembled instruction. */ | 246 /* Prints out the disassembled instruction. */ |
247 static void PrintInst(NaClEnumerator* enumerator) { | 247 static void PrintInst(NaClEnumerator* enumerator) { |
248 int i; | 248 printf(" NaCl: %s", Disassemble(enumerator)); |
249 uint8_t length = NaClInstLength(nacl_decoder._inst); | |
250 if (enumerator->_print_opcode_bytes_only) { | |
251 for (i = 0; i < length; ++i) { | |
252 printf("%02x", enumerator->_itext[i]); | |
253 } | |
254 printf("\n"); | |
255 } else { | |
256 if (enumerator->_print_enumerated_instruction) { | |
257 for (i = 0; i < length; ++i) { | |
258 printf("%02x ", enumerator->_itext[i]); | |
259 } | |
260 printf("#%s %s\n", GetInstMnemonic(enumerator), | |
261 GetInstOperandsText(enumerator)); | |
262 } else { | |
263 printf(" NaCl: %s", Disassemble(enumerator)); | |
264 } | |
265 } | |
266 } | 249 } |
267 | 250 |
268 /* Returns the number of bytes in the disassembled instruction. */ | 251 /* Returns the number of bytes in the disassembled instruction. */ |
269 static size_t InstLength(NaClEnumerator* enumerator) { | 252 static size_t InstLength(NaClEnumerator* enumerator) { |
270 return (size_t) NaClInstLength(nacl_decoder._inst); | 253 return (size_t) NaClInstLength(nacl_decoder._inst); |
271 } | 254 } |
272 | 255 |
273 /* Returns true if the instruction decodes, and static (single instruction) | 256 /* Returns true if the instruction decodes, and static (single instruction) |
274 * validator tests pass. | 257 * validator tests pass. |
275 */ | 258 */ |
(...skipping 20 matching lines...) Expand all Loading... |
296 nacl_decoder._translate_to_xed_nops = *((Bool*) flag_address); | 279 nacl_decoder._translate_to_xed_nops = *((Bool*) flag_address); |
297 } else if (0 == strcmp(flag_name, "--xedimplemented")) { | 280 } else if (0 == strcmp(flag_name, "--xedimplemented")) { |
298 nacl_decoder._ignore_instructions_not_xed_implemented = | 281 nacl_decoder._ignore_instructions_not_xed_implemented = |
299 *((Bool*) flag_address); | 282 *((Bool*) flag_address); |
300 } | 283 } |
301 } | 284 } |
302 | 285 |
303 /* Generates a decoder for the (sel_ldr) nacl validator. */ | 286 /* Generates a decoder for the (sel_ldr) nacl validator. */ |
304 NaClEnumeratorDecoder* RegisterNaClDecoder() { | 287 NaClEnumeratorDecoder* RegisterNaClDecoder() { |
305 nacl_decoder._base._id_name = "nacl"; | 288 nacl_decoder._base._id_name = "nacl"; |
306 nacl_decoder._base._legal_only = TRUE; | |
307 nacl_decoder._base._print_only = FALSE; | |
308 nacl_decoder._base._parse_inst_fn = ParseInst; | 289 nacl_decoder._base._parse_inst_fn = ParseInst; |
309 nacl_decoder._base._inst_length_fn = InstLength; | 290 nacl_decoder._base._inst_length_fn = InstLength; |
310 nacl_decoder._base._print_inst_fn = PrintInst; | 291 nacl_decoder._base._print_inst_fn = PrintInst; |
311 nacl_decoder._base._get_inst_mnemonic_fn = GetInstMnemonic; | 292 nacl_decoder._base._get_inst_mnemonic_fn = GetInstMnemonic; |
312 nacl_decoder._base._get_inst_num_operands_fn = NULL; | 293 nacl_decoder._base._get_inst_num_operands_fn = NULL; |
313 nacl_decoder._base._get_inst_operands_text_fn = GetInstOperandsText; | 294 nacl_decoder._base._get_inst_operands_text_fn = GetInstOperandsText; |
314 nacl_decoder._base._writes_to_reserved_reg_fn = NULL; | 295 nacl_decoder._base._writes_to_reserved_reg_fn = NULL; |
315 nacl_decoder._base._is_inst_legal_fn = IsInstLegal; | 296 nacl_decoder._base._is_inst_legal_fn = IsInstLegal; |
316 nacl_decoder._base._maybe_inst_validates_fn = MaybeInstValidates; | 297 nacl_decoder._base._maybe_inst_validates_fn = MaybeInstValidates; |
317 nacl_decoder._base._segment_validates_fn = SegmentValidates; | 298 nacl_decoder._base._segment_validates_fn = SegmentValidates; |
318 nacl_decoder._base._install_flag_fn = InstallFlag; | 299 nacl_decoder._base._install_flag_fn = InstallFlag; |
319 nacl_decoder._base._usage_message = | 300 nacl_decoder._base._usage_message = |
320 "Runs nacl decoder to decode instructions"; | 301 "Runs nacl decoder to decode instructions"; |
321 return &nacl_decoder._base; | 302 return &nacl_decoder._base; |
322 } | 303 } |
OLD | NEW |