OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 //------------------------------------------------------------------ | 47 //------------------------------------------------------------------ |
48 // Tables | 48 // Tables |
49 //------------------------------------------------------------------ | 49 //------------------------------------------------------------------ |
50 struct ByteMnemonic { | 50 struct ByteMnemonic { |
51 int b; // -1 terminates, otherwise must be in range (0..255) | 51 int b; // -1 terminates, otherwise must be in range (0..255) |
52 const char* mnem; | 52 const char* mnem; |
53 OperandOrder op_order_; | 53 OperandOrder op_order_; |
54 }; | 54 }; |
55 | 55 |
56 | 56 |
57 static ByteMnemonic two_operands_instr[] = { | 57 static const ByteMnemonic two_operands_instr[] = { |
58 {0x03, "add", REG_OPER_OP_ORDER}, | 58 {0x03, "add", REG_OPER_OP_ORDER}, |
59 {0x09, "or", OPER_REG_OP_ORDER}, | 59 {0x09, "or", OPER_REG_OP_ORDER}, |
60 {0x0B, "or", REG_OPER_OP_ORDER}, | 60 {0x0B, "or", REG_OPER_OP_ORDER}, |
61 {0x1B, "sbb", REG_OPER_OP_ORDER}, | 61 {0x1B, "sbb", REG_OPER_OP_ORDER}, |
62 {0x21, "and", OPER_REG_OP_ORDER}, | 62 {0x21, "and", OPER_REG_OP_ORDER}, |
63 {0x23, "and", REG_OPER_OP_ORDER}, | 63 {0x23, "and", REG_OPER_OP_ORDER}, |
64 {0x29, "sub", OPER_REG_OP_ORDER}, | 64 {0x29, "sub", OPER_REG_OP_ORDER}, |
65 {0x2A, "subb", REG_OPER_OP_ORDER}, | 65 {0x2A, "subb", REG_OPER_OP_ORDER}, |
66 {0x2B, "sub", REG_OPER_OP_ORDER}, | 66 {0x2B, "sub", REG_OPER_OP_ORDER}, |
67 {0x31, "xor", OPER_REG_OP_ORDER}, | 67 {0x31, "xor", OPER_REG_OP_ORDER}, |
68 {0x33, "xor", REG_OPER_OP_ORDER}, | 68 {0x33, "xor", REG_OPER_OP_ORDER}, |
69 {0x38, "cmpb", OPER_REG_OP_ORDER}, | 69 {0x38, "cmpb", OPER_REG_OP_ORDER}, |
70 {0x3A, "cmpb", REG_OPER_OP_ORDER}, | 70 {0x3A, "cmpb", REG_OPER_OP_ORDER}, |
71 {0x3B, "cmp", REG_OPER_OP_ORDER}, | 71 {0x3B, "cmp", REG_OPER_OP_ORDER}, |
72 {0x84, "test_b", REG_OPER_OP_ORDER}, | 72 {0x84, "test_b", REG_OPER_OP_ORDER}, |
73 {0x85, "test", REG_OPER_OP_ORDER}, | 73 {0x85, "test", REG_OPER_OP_ORDER}, |
74 {0x87, "xchg", REG_OPER_OP_ORDER}, | 74 {0x87, "xchg", REG_OPER_OP_ORDER}, |
75 {0x8A, "mov_b", REG_OPER_OP_ORDER}, | 75 {0x8A, "mov_b", REG_OPER_OP_ORDER}, |
76 {0x8B, "mov", REG_OPER_OP_ORDER}, | 76 {0x8B, "mov", REG_OPER_OP_ORDER}, |
77 {0x8D, "lea", REG_OPER_OP_ORDER}, | 77 {0x8D, "lea", REG_OPER_OP_ORDER}, |
78 {-1, "", UNSET_OP_ORDER} | 78 {-1, "", UNSET_OP_ORDER} |
79 }; | 79 }; |
80 | 80 |
81 | 81 |
82 static ByteMnemonic zero_operands_instr[] = { | 82 static const ByteMnemonic zero_operands_instr[] = { |
83 {0xC3, "ret", UNSET_OP_ORDER}, | 83 {0xC3, "ret", UNSET_OP_ORDER}, |
84 {0xC9, "leave", UNSET_OP_ORDER}, | 84 {0xC9, "leave", UNSET_OP_ORDER}, |
85 {0x90, "nop", UNSET_OP_ORDER}, | 85 {0x90, "nop", UNSET_OP_ORDER}, |
86 {0xF4, "hlt", UNSET_OP_ORDER}, | 86 {0xF4, "hlt", UNSET_OP_ORDER}, |
87 {0xCC, "int3", UNSET_OP_ORDER}, | 87 {0xCC, "int3", UNSET_OP_ORDER}, |
88 {0x60, "pushad", UNSET_OP_ORDER}, | 88 {0x60, "pushad", UNSET_OP_ORDER}, |
89 {0x61, "popad", UNSET_OP_ORDER}, | 89 {0x61, "popad", UNSET_OP_ORDER}, |
90 {0x9C, "pushfd", UNSET_OP_ORDER}, | 90 {0x9C, "pushfd", UNSET_OP_ORDER}, |
91 {0x9D, "popfd", UNSET_OP_ORDER}, | 91 {0x9D, "popfd", UNSET_OP_ORDER}, |
92 {0x9E, "sahf", UNSET_OP_ORDER}, | 92 {0x9E, "sahf", UNSET_OP_ORDER}, |
93 {0x99, "cdq", UNSET_OP_ORDER}, | 93 {0x99, "cdq", UNSET_OP_ORDER}, |
94 {0x9B, "fwait", UNSET_OP_ORDER}, | 94 {0x9B, "fwait", UNSET_OP_ORDER}, |
95 {0xFC, "cld", UNSET_OP_ORDER}, | 95 {0xFC, "cld", UNSET_OP_ORDER}, |
96 {0xAB, "stos", UNSET_OP_ORDER}, | 96 {0xAB, "stos", UNSET_OP_ORDER}, |
97 {-1, "", UNSET_OP_ORDER} | 97 {-1, "", UNSET_OP_ORDER} |
98 }; | 98 }; |
99 | 99 |
100 | 100 |
101 static ByteMnemonic call_jump_instr[] = { | 101 static const ByteMnemonic call_jump_instr[] = { |
102 {0xE8, "call", UNSET_OP_ORDER}, | 102 {0xE8, "call", UNSET_OP_ORDER}, |
103 {0xE9, "jmp", UNSET_OP_ORDER}, | 103 {0xE9, "jmp", UNSET_OP_ORDER}, |
104 {-1, "", UNSET_OP_ORDER} | 104 {-1, "", UNSET_OP_ORDER} |
105 }; | 105 }; |
106 | 106 |
107 | 107 |
108 static ByteMnemonic short_immediate_instr[] = { | 108 static const ByteMnemonic short_immediate_instr[] = { |
109 {0x05, "add", UNSET_OP_ORDER}, | 109 {0x05, "add", UNSET_OP_ORDER}, |
110 {0x0D, "or", UNSET_OP_ORDER}, | 110 {0x0D, "or", UNSET_OP_ORDER}, |
111 {0x15, "adc", UNSET_OP_ORDER}, | 111 {0x15, "adc", UNSET_OP_ORDER}, |
112 {0x25, "and", UNSET_OP_ORDER}, | 112 {0x25, "and", UNSET_OP_ORDER}, |
113 {0x2D, "sub", UNSET_OP_ORDER}, | 113 {0x2D, "sub", UNSET_OP_ORDER}, |
114 {0x35, "xor", UNSET_OP_ORDER}, | 114 {0x35, "xor", UNSET_OP_ORDER}, |
115 {0x3D, "cmp", UNSET_OP_ORDER}, | 115 {0x3D, "cmp", UNSET_OP_ORDER}, |
116 {-1, "", UNSET_OP_ORDER} | 116 {-1, "", UNSET_OP_ORDER} |
117 }; | 117 }; |
118 | 118 |
119 | 119 |
120 static const char* jump_conditional_mnem[] = { | 120 static const char* const jump_conditional_mnem[] = { |
121 /*0*/ "jo", "jno", "jc", "jnc", | 121 /*0*/ "jo", "jno", "jc", "jnc", |
122 /*4*/ "jz", "jnz", "jna", "ja", | 122 /*4*/ "jz", "jnz", "jna", "ja", |
123 /*8*/ "js", "jns", "jpe", "jpo", | 123 /*8*/ "js", "jns", "jpe", "jpo", |
124 /*12*/ "jl", "jnl", "jng", "jg" | 124 /*12*/ "jl", "jnl", "jng", "jg" |
125 }; | 125 }; |
126 | 126 |
127 | 127 |
128 static const char* set_conditional_mnem[] = { | 128 static const char* const set_conditional_mnem[] = { |
129 /*0*/ "seto", "setno", "setc", "setnc", | 129 /*0*/ "seto", "setno", "setc", "setnc", |
130 /*4*/ "setz", "setnz", "setna", "seta", | 130 /*4*/ "setz", "setnz", "setna", "seta", |
131 /*8*/ "sets", "setns", "setpe", "setpo", | 131 /*8*/ "sets", "setns", "setpe", "setpo", |
132 /*12*/ "setl", "setnl", "setng", "setg" | 132 /*12*/ "setl", "setnl", "setng", "setg" |
133 }; | 133 }; |
134 | 134 |
135 | 135 |
136 static const char* conditional_move_mnem[] = { | 136 static const char* const conditional_move_mnem[] = { |
137 /*0*/ "cmovo", "cmovno", "cmovc", "cmovnc", | 137 /*0*/ "cmovo", "cmovno", "cmovc", "cmovnc", |
138 /*4*/ "cmovz", "cmovnz", "cmovna", "cmova", | 138 /*4*/ "cmovz", "cmovnz", "cmovna", "cmova", |
139 /*8*/ "cmovs", "cmovns", "cmovpe", "cmovpo", | 139 /*8*/ "cmovs", "cmovns", "cmovpe", "cmovpo", |
140 /*12*/ "cmovl", "cmovnl", "cmovng", "cmovg" | 140 /*12*/ "cmovl", "cmovnl", "cmovng", "cmovg" |
141 }; | 141 }; |
142 | 142 |
143 | 143 |
144 enum InstructionType { | 144 enum InstructionType { |
145 NO_INSTR, | 145 NO_INSTR, |
146 ZERO_OPERANDS_INSTR, | 146 ZERO_OPERANDS_INSTR, |
(...skipping 15 matching lines...) Expand all Loading... |
162 | 162 |
163 class InstructionTable { | 163 class InstructionTable { |
164 public: | 164 public: |
165 InstructionTable(); | 165 InstructionTable(); |
166 const InstructionDesc& Get(byte x) const { return instructions_[x]; } | 166 const InstructionDesc& Get(byte x) const { return instructions_[x]; } |
167 | 167 |
168 private: | 168 private: |
169 InstructionDesc instructions_[256]; | 169 InstructionDesc instructions_[256]; |
170 void Clear(); | 170 void Clear(); |
171 void Init(); | 171 void Init(); |
172 void CopyTable(ByteMnemonic bm[], InstructionType type); | 172 void CopyTable(const ByteMnemonic bm[], InstructionType type); |
173 void SetTableRange(InstructionType type, | 173 void SetTableRange(InstructionType type, |
174 byte start, | 174 byte start, |
175 byte end, | 175 byte end, |
176 const char* mnem); | 176 const char* mnem); |
177 void AddJumpConditionalShort(); | 177 void AddJumpConditionalShort(); |
178 }; | 178 }; |
179 | 179 |
180 | 180 |
181 InstructionTable::InstructionTable() { | 181 InstructionTable::InstructionTable() { |
182 Clear(); | 182 Clear(); |
(...skipping 18 matching lines...) Expand all Loading... |
201 AddJumpConditionalShort(); | 201 AddJumpConditionalShort(); |
202 SetTableRange(REGISTER_INSTR, 0x40, 0x47, "inc"); | 202 SetTableRange(REGISTER_INSTR, 0x40, 0x47, "inc"); |
203 SetTableRange(REGISTER_INSTR, 0x48, 0x4F, "dec"); | 203 SetTableRange(REGISTER_INSTR, 0x48, 0x4F, "dec"); |
204 SetTableRange(REGISTER_INSTR, 0x50, 0x57, "push"); | 204 SetTableRange(REGISTER_INSTR, 0x50, 0x57, "push"); |
205 SetTableRange(REGISTER_INSTR, 0x58, 0x5F, "pop"); | 205 SetTableRange(REGISTER_INSTR, 0x58, 0x5F, "pop"); |
206 SetTableRange(REGISTER_INSTR, 0x91, 0x97, "xchg eax,"); // 0x90 is nop. | 206 SetTableRange(REGISTER_INSTR, 0x91, 0x97, "xchg eax,"); // 0x90 is nop. |
207 SetTableRange(MOVE_REG_INSTR, 0xB8, 0xBF, "mov"); | 207 SetTableRange(MOVE_REG_INSTR, 0xB8, 0xBF, "mov"); |
208 } | 208 } |
209 | 209 |
210 | 210 |
211 void InstructionTable::CopyTable(ByteMnemonic bm[], InstructionType type) { | 211 void InstructionTable::CopyTable(const ByteMnemonic bm[], |
| 212 InstructionType type) { |
212 for (int i = 0; bm[i].b >= 0; i++) { | 213 for (int i = 0; bm[i].b >= 0; i++) { |
213 InstructionDesc* id = &instructions_[bm[i].b]; | 214 InstructionDesc* id = &instructions_[bm[i].b]; |
214 id->mnem = bm[i].mnem; | 215 id->mnem = bm[i].mnem; |
215 id->op_order_ = bm[i].op_order_; | 216 id->op_order_ = bm[i].op_order_; |
216 ASSERT_EQ(NO_INSTR, id->type); // Information not already entered. | 217 ASSERT_EQ(NO_INSTR, id->type); // Information not already entered. |
217 id->type = type; | 218 id->type = type; |
218 } | 219 } |
219 } | 220 } |
220 | 221 |
221 | 222 |
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1619 fprintf(f, " "); | 1620 fprintf(f, " "); |
1620 } | 1621 } |
1621 fprintf(f, " %s\n", buffer.start()); | 1622 fprintf(f, " %s\n", buffer.start()); |
1622 } | 1623 } |
1623 } | 1624 } |
1624 | 1625 |
1625 | 1626 |
1626 } // namespace disasm | 1627 } // namespace disasm |
1627 | 1628 |
1628 #endif // V8_TARGET_ARCH_IA32 | 1629 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |