Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 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 * Full-blown decoder for amd64 case. Can be used to decode instruction | 8 * Full-blown decoder for amd64 case. Can be used to decode instruction |
| 9 * sequence and process it, but right now is only used in tests. | 9 * sequence and process it, but right now is only used in tests. |
| 10 * | 10 * |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; | 87 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; |
| 88 include relative_fields_decoder_actions | 88 include relative_fields_decoder_actions |
| 89 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; | 89 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; |
| 90 include relative_fields_parsing | 90 include relative_fields_parsing |
| 91 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; | 91 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; |
| 92 include cpuid_actions | 92 include cpuid_actions |
| 93 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; | 93 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; |
| 94 | 94 |
| 95 include decode_x86_64 "decoder_x86_64_instruction.rl"; | 95 include decode_x86_64 "decoder_x86_64_instruction.rl"; |
| 96 | 96 |
| 97 include decoder | 97 action end_of_instruction_cleanup { |
| 98 "native_client/src/trusted/validator_ragel/unreviewed/parse_instruction.rl"; | 98 process_instruction(instruction_begin, current_position + 1, &instruction, |
| 99 userdata); | |
| 100 instruction_begin = current_position + 1; | |
| 101 SET_DISP_TYPE(DISPNONE); | |
| 102 SET_IMM_TYPE(IMMNONE); | |
| 103 SET_IMM2_TYPE(IMMNONE); | |
| 104 SET_REX_PREFIX(FALSE); | |
| 105 SET_DATA16_PREFIX(FALSE); | |
| 106 SET_LOCK_PREFIX(FALSE); | |
| 107 SET_REPNZ_PREFIX(FALSE); | |
| 108 SET_REPZ_PREFIX(FALSE); | |
| 109 SET_BRANCH_NOT_TAKEN(FALSE); | |
| 110 SET_BRANCH_TAKEN(FALSE); | |
| 111 /* Top three bis of VEX2 are inverted: see AMD/Intel manual. */ | |
|
halyavin
2013/03/15 10:59:38
bis->bits
halyavin
2013/03/15 10:59:38
+/* Pass VEX2 prefix value that corresponds to zer
khim
2013/03/15 11:03:21
Done.
khim
2013/03/15 11:03:21
Done.
| |
| 112 SET_VEX_PREFIX2(VEX_R | VEX_X | VEX_B); | |
| 113 SET_VEX_PREFIX3(0x00); | |
| 114 SET_ATT_INSTRUCTION_SUFFIX(NULL); | |
| 115 CLEAR_SPURIOUS_REX_B(); | |
| 116 CLEAR_SPURIOUS_REX_X(); | |
| 117 CLEAR_SPURIOUS_REX_R(); | |
| 118 CLEAR_SPURIOUS_REX_W(); | |
| 119 } | |
| 99 | 120 |
| 100 main := decoder; | 121 action report_fatal_error { |
| 122 process_error(current_position, userdata); | |
| 123 result = FALSE; | |
| 124 goto error_detected; | |
| 125 } | |
| 126 | |
| 127 decoder := (one_instruction @end_of_instruction_cleanup)* | |
| 128 $!report_fatal_error; | |
| 101 }%% | 129 }%% |
| 102 | 130 |
| 103 %% write data; | 131 %% write data; |
| 104 | 132 |
| 105 int DecodeChunkAMD64(const uint8_t *data, size_t size, | 133 int DecodeChunkAMD64(const uint8_t *data, size_t size, |
| 106 ProcessInstructionFunc process_instruction, | 134 ProcessInstructionFunc process_instruction, |
| 107 ProcessDecodingErrorFunc process_error, | 135 ProcessDecodingErrorFunc process_error, |
| 108 void *userdata) { | 136 void *userdata) { |
| 109 const uint8_t *current_position = data; | 137 const uint8_t *current_position = data; |
| 110 const uint8_t *end_of_data = data + size; | 138 const uint8_t *end_of_data = data + size; |
| 111 const uint8_t *instruction_begin = current_position; | 139 const uint8_t *instruction_begin = current_position; |
| 112 uint8_t vex_prefix2 = 0xe0; | 140 /* Top three bis of VEX2 are inverted: see AMD/Intel manual. */ |
|
halyavin
2013/03/15 10:59:38
bis->bits
khim
2013/03/15 11:03:21
Done.
| |
| 141 uint8_t vex_prefix2 = VEX_R | VEX_X | VEX_B; | |
| 113 uint8_t vex_prefix3 = 0x00; | 142 uint8_t vex_prefix3 = 0x00; |
| 114 enum ImmediateMode imm_operand = IMMNONE; | 143 enum ImmediateMode imm_operand = IMMNONE; |
| 115 enum ImmediateMode imm2_operand = IMMNONE; | 144 enum ImmediateMode imm2_operand = IMMNONE; |
| 116 struct Instruction instruction; | 145 struct Instruction instruction; |
| 117 int result = TRUE; | 146 int result = TRUE; |
| 118 | 147 |
| 119 int current_state; | 148 int current_state; |
| 120 | 149 |
| 121 SET_DISP_TYPE(DISPNONE); | 150 memset(&instruction, 0, sizeof instruction); |
| 122 SET_IMM_TYPE(IMMNONE); | |
| 123 SET_IMM2_TYPE(IMMNONE); | |
| 124 SET_REX_PREFIX(FALSE); | |
| 125 SET_DATA16_PREFIX(FALSE); | |
| 126 SET_LOCK_PREFIX(FALSE); | |
| 127 SET_REPNZ_PREFIX(FALSE); | |
| 128 SET_REPZ_PREFIX(FALSE); | |
| 129 SET_BRANCH_NOT_TAKEN(FALSE); | |
| 130 SET_BRANCH_TAKEN(FALSE); | |
| 131 SET_ATT_INSTRUCTION_SUFFIX(NULL); | |
| 132 instruction.prefix.rex_b_spurious = FALSE; | |
| 133 instruction.prefix.rex_x_spurious = FALSE; | |
| 134 instruction.prefix.rex_r_spurious = FALSE; | |
| 135 instruction.prefix.rex_w_spurious = FALSE; | |
| 136 | 151 |
| 137 %% write init; | 152 %% write init; |
| 138 %% write exec; | 153 %% write exec; |
| 139 | 154 |
| 140 error_detected: | 155 error_detected: |
| 141 return result; | 156 return result; |
| 142 } | 157 } |
| OLD | NEW |