| 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 {0x01, "add", OPER_REG_OP_ORDER}, | 58 {0x01, "add", OPER_REG_OP_ORDER}, |
| 59 {0x03, "add", REG_OPER_OP_ORDER}, | 59 {0x03, "add", REG_OPER_OP_ORDER}, |
| 60 {0x09, "or", OPER_REG_OP_ORDER}, | 60 {0x09, "or", OPER_REG_OP_ORDER}, |
| 61 {0x0B, "or", REG_OPER_OP_ORDER}, | 61 {0x0B, "or", REG_OPER_OP_ORDER}, |
| 62 {0x1B, "sbb", REG_OPER_OP_ORDER}, | 62 {0x1B, "sbb", REG_OPER_OP_ORDER}, |
| 63 {0x21, "and", OPER_REG_OP_ORDER}, | 63 {0x21, "and", OPER_REG_OP_ORDER}, |
| 64 {0x23, "and", REG_OPER_OP_ORDER}, | 64 {0x23, "and", REG_OPER_OP_ORDER}, |
| 65 {0x29, "sub", OPER_REG_OP_ORDER}, | 65 {0x29, "sub", OPER_REG_OP_ORDER}, |
| 66 {0x2A, "subb", REG_OPER_OP_ORDER}, | 66 {0x2A, "subb", REG_OPER_OP_ORDER}, |
| 67 {0x2B, "sub", REG_OPER_OP_ORDER}, | 67 {0x2B, "sub", REG_OPER_OP_ORDER}, |
| 68 {0x31, "xor", OPER_REG_OP_ORDER}, | 68 {0x31, "xor", OPER_REG_OP_ORDER}, |
| 69 {0x33, "xor", REG_OPER_OP_ORDER}, | 69 {0x33, "xor", REG_OPER_OP_ORDER}, |
| 70 {0x38, "cmpb", OPER_REG_OP_ORDER}, | 70 {0x38, "cmpb", OPER_REG_OP_ORDER}, |
| 71 {0x3A, "cmpb", REG_OPER_OP_ORDER}, | 71 {0x3A, "cmpb", REG_OPER_OP_ORDER}, |
| 72 {0x3B, "cmp", REG_OPER_OP_ORDER}, | 72 {0x3B, "cmp", REG_OPER_OP_ORDER}, |
| 73 {0x84, "test_b", REG_OPER_OP_ORDER}, | 73 {0x84, "test_b", REG_OPER_OP_ORDER}, |
| 74 {0x85, "test", REG_OPER_OP_ORDER}, | 74 {0x85, "test", REG_OPER_OP_ORDER}, |
| 75 {0x87, "xchg", REG_OPER_OP_ORDER}, | 75 {0x87, "xchg", REG_OPER_OP_ORDER}, |
| 76 {0x8A, "mov_b", REG_OPER_OP_ORDER}, | 76 {0x8A, "mov_b", REG_OPER_OP_ORDER}, |
| 77 {0x8B, "mov", REG_OPER_OP_ORDER}, | 77 {0x8B, "mov", REG_OPER_OP_ORDER}, |
| 78 {0x8D, "lea", REG_OPER_OP_ORDER}, | 78 {0x8D, "lea", REG_OPER_OP_ORDER}, |
| 79 {-1, "", UNSET_OP_ORDER} | 79 {-1, "", UNSET_OP_ORDER} |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 | 82 |
| 83 static ByteMnemonic zero_operands_instr[] = { | 83 static const ByteMnemonic zero_operands_instr[] = { |
| 84 {0xC3, "ret", UNSET_OP_ORDER}, | 84 {0xC3, "ret", UNSET_OP_ORDER}, |
| 85 {0xC9, "leave", UNSET_OP_ORDER}, | 85 {0xC9, "leave", UNSET_OP_ORDER}, |
| 86 {0x90, "nop", UNSET_OP_ORDER}, | 86 {0x90, "nop", UNSET_OP_ORDER}, |
| 87 {0xF4, "hlt", UNSET_OP_ORDER}, | 87 {0xF4, "hlt", UNSET_OP_ORDER}, |
| 88 {0xCC, "int3", UNSET_OP_ORDER}, | 88 {0xCC, "int3", UNSET_OP_ORDER}, |
| 89 {0x60, "pushad", UNSET_OP_ORDER}, | 89 {0x60, "pushad", UNSET_OP_ORDER}, |
| 90 {0x61, "popad", UNSET_OP_ORDER}, | 90 {0x61, "popad", UNSET_OP_ORDER}, |
| 91 {0x9C, "pushfd", UNSET_OP_ORDER}, | 91 {0x9C, "pushfd", UNSET_OP_ORDER}, |
| 92 {0x9D, "popfd", UNSET_OP_ORDER}, | 92 {0x9D, "popfd", UNSET_OP_ORDER}, |
| 93 {0x9E, "sahf", UNSET_OP_ORDER}, | 93 {0x9E, "sahf", UNSET_OP_ORDER}, |
| 94 {0x99, "cdq", UNSET_OP_ORDER}, | 94 {0x99, "cdq", UNSET_OP_ORDER}, |
| 95 {0x9B, "fwait", UNSET_OP_ORDER}, | 95 {0x9B, "fwait", UNSET_OP_ORDER}, |
| 96 {0xFC, "cld", UNSET_OP_ORDER}, | 96 {0xFC, "cld", UNSET_OP_ORDER}, |
| 97 {0xAB, "stos", UNSET_OP_ORDER}, | 97 {0xAB, "stos", UNSET_OP_ORDER}, |
| 98 {-1, "", UNSET_OP_ORDER} | 98 {-1, "", UNSET_OP_ORDER} |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 | 101 |
| 102 static ByteMnemonic call_jump_instr[] = { | 102 static const ByteMnemonic call_jump_instr[] = { |
| 103 {0xE8, "call", UNSET_OP_ORDER}, | 103 {0xE8, "call", UNSET_OP_ORDER}, |
| 104 {0xE9, "jmp", UNSET_OP_ORDER}, | 104 {0xE9, "jmp", UNSET_OP_ORDER}, |
| 105 {-1, "", UNSET_OP_ORDER} | 105 {-1, "", UNSET_OP_ORDER} |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 | 108 |
| 109 static ByteMnemonic short_immediate_instr[] = { | 109 static const ByteMnemonic short_immediate_instr[] = { |
| 110 {0x05, "add", UNSET_OP_ORDER}, | 110 {0x05, "add", UNSET_OP_ORDER}, |
| 111 {0x0D, "or", UNSET_OP_ORDER}, | 111 {0x0D, "or", UNSET_OP_ORDER}, |
| 112 {0x15, "adc", UNSET_OP_ORDER}, | 112 {0x15, "adc", UNSET_OP_ORDER}, |
| 113 {0x25, "and", UNSET_OP_ORDER}, | 113 {0x25, "and", UNSET_OP_ORDER}, |
| 114 {0x2D, "sub", UNSET_OP_ORDER}, | 114 {0x2D, "sub", UNSET_OP_ORDER}, |
| 115 {0x35, "xor", UNSET_OP_ORDER}, | 115 {0x35, "xor", UNSET_OP_ORDER}, |
| 116 {0x3D, "cmp", UNSET_OP_ORDER}, | 116 {0x3D, "cmp", UNSET_OP_ORDER}, |
| 117 {-1, "", UNSET_OP_ORDER} | 117 {-1, "", UNSET_OP_ORDER} |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 | 120 |
| 121 // Generally we don't want to generate these because they are subject to partial | 121 // Generally we don't want to generate these because they are subject to partial |
| 122 // register stalls. They are included for completeness and because the cmp | 122 // register stalls. They are included for completeness and because the cmp |
| 123 // variant is used by the RecordWrite stub. Because it does not update the | 123 // variant is used by the RecordWrite stub. Because it does not update the |
| 124 // register it is npt subject to partial register stalls. | 124 // register it is not subject to partial register stalls. |
| 125 static ByteMnemonic byte_immediate_instr[] = { | 125 static ByteMnemonic byte_immediate_instr[] = { |
| 126 {0x0c, "or", UNSET_OP_ORDER}, | 126 {0x0c, "or", UNSET_OP_ORDER}, |
| 127 {0x24, "and", UNSET_OP_ORDER}, | 127 {0x24, "and", UNSET_OP_ORDER}, |
| 128 {0x34, "xor", UNSET_OP_ORDER}, | 128 {0x34, "xor", UNSET_OP_ORDER}, |
| 129 {0x3c, "cmp", UNSET_OP_ORDER}, | 129 {0x3c, "cmp", UNSET_OP_ORDER}, |
| 130 {-1, "", UNSET_OP_ORDER} | 130 {-1, "", UNSET_OP_ORDER} |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 | 133 |
| 134 static const char* jump_conditional_mnem[] = { | 134 static const char* const jump_conditional_mnem[] = { |
| 135 /*0*/ "jo", "jno", "jc", "jnc", | 135 /*0*/ "jo", "jno", "jc", "jnc", |
| 136 /*4*/ "jz", "jnz", "jna", "ja", | 136 /*4*/ "jz", "jnz", "jna", "ja", |
| 137 /*8*/ "js", "jns", "jpe", "jpo", | 137 /*8*/ "js", "jns", "jpe", "jpo", |
| 138 /*12*/ "jl", "jnl", "jng", "jg" | 138 /*12*/ "jl", "jnl", "jng", "jg" |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 | 141 |
| 142 static const char* set_conditional_mnem[] = { | 142 static const char* const set_conditional_mnem[] = { |
| 143 /*0*/ "seto", "setno", "setc", "setnc", | 143 /*0*/ "seto", "setno", "setc", "setnc", |
| 144 /*4*/ "setz", "setnz", "setna", "seta", | 144 /*4*/ "setz", "setnz", "setna", "seta", |
| 145 /*8*/ "sets", "setns", "setpe", "setpo", | 145 /*8*/ "sets", "setns", "setpe", "setpo", |
| 146 /*12*/ "setl", "setnl", "setng", "setg" | 146 /*12*/ "setl", "setnl", "setng", "setg" |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 | 149 |
| 150 static const char* conditional_move_mnem[] = { | 150 static const char* const conditional_move_mnem[] = { |
| 151 /*0*/ "cmovo", "cmovno", "cmovc", "cmovnc", | 151 /*0*/ "cmovo", "cmovno", "cmovc", "cmovnc", |
| 152 /*4*/ "cmovz", "cmovnz", "cmovna", "cmova", | 152 /*4*/ "cmovz", "cmovnz", "cmovna", "cmova", |
| 153 /*8*/ "cmovs", "cmovns", "cmovpe", "cmovpo", | 153 /*8*/ "cmovs", "cmovns", "cmovpe", "cmovpo", |
| 154 /*12*/ "cmovl", "cmovnl", "cmovng", "cmovg" | 154 /*12*/ "cmovl", "cmovnl", "cmovng", "cmovg" |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 | 157 |
| 158 enum InstructionType { | 158 enum InstructionType { |
| 159 NO_INSTR, | 159 NO_INSTR, |
| 160 ZERO_OPERANDS_INSTR, | 160 ZERO_OPERANDS_INSTR, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 177 | 177 |
| 178 class InstructionTable { | 178 class InstructionTable { |
| 179 public: | 179 public: |
| 180 InstructionTable(); | 180 InstructionTable(); |
| 181 const InstructionDesc& Get(byte x) const { return instructions_[x]; } | 181 const InstructionDesc& Get(byte x) const { return instructions_[x]; } |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 InstructionDesc instructions_[256]; | 184 InstructionDesc instructions_[256]; |
| 185 void Clear(); | 185 void Clear(); |
| 186 void Init(); | 186 void Init(); |
| 187 void CopyTable(ByteMnemonic bm[], InstructionType type); | 187 void CopyTable(const ByteMnemonic bm[], InstructionType type); |
| 188 void SetTableRange(InstructionType type, | 188 void SetTableRange(InstructionType type, |
| 189 byte start, | 189 byte start, |
| 190 byte end, | 190 byte end, |
| 191 const char* mnem); | 191 const char* mnem); |
| 192 void AddJumpConditionalShort(); | 192 void AddJumpConditionalShort(); |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 | 195 |
| 196 InstructionTable::InstructionTable() { | 196 InstructionTable::InstructionTable() { |
| 197 Clear(); | 197 Clear(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 217 AddJumpConditionalShort(); | 217 AddJumpConditionalShort(); |
| 218 SetTableRange(REGISTER_INSTR, 0x40, 0x47, "inc"); | 218 SetTableRange(REGISTER_INSTR, 0x40, 0x47, "inc"); |
| 219 SetTableRange(REGISTER_INSTR, 0x48, 0x4F, "dec"); | 219 SetTableRange(REGISTER_INSTR, 0x48, 0x4F, "dec"); |
| 220 SetTableRange(REGISTER_INSTR, 0x50, 0x57, "push"); | 220 SetTableRange(REGISTER_INSTR, 0x50, 0x57, "push"); |
| 221 SetTableRange(REGISTER_INSTR, 0x58, 0x5F, "pop"); | 221 SetTableRange(REGISTER_INSTR, 0x58, 0x5F, "pop"); |
| 222 SetTableRange(REGISTER_INSTR, 0x91, 0x97, "xchg eax,"); // 0x90 is nop. | 222 SetTableRange(REGISTER_INSTR, 0x91, 0x97, "xchg eax,"); // 0x90 is nop. |
| 223 SetTableRange(MOVE_REG_INSTR, 0xB8, 0xBF, "mov"); | 223 SetTableRange(MOVE_REG_INSTR, 0xB8, 0xBF, "mov"); |
| 224 } | 224 } |
| 225 | 225 |
| 226 | 226 |
| 227 void InstructionTable::CopyTable(ByteMnemonic bm[], InstructionType type) { | 227 void InstructionTable::CopyTable(const ByteMnemonic bm[], |
| 228 InstructionType type) { |
| 228 for (int i = 0; bm[i].b >= 0; i++) { | 229 for (int i = 0; bm[i].b >= 0; i++) { |
| 229 InstructionDesc* id = &instructions_[bm[i].b]; | 230 InstructionDesc* id = &instructions_[bm[i].b]; |
| 230 id->mnem = bm[i].mnem; | 231 id->mnem = bm[i].mnem; |
| 231 id->op_order_ = bm[i].op_order_; | 232 id->op_order_ = bm[i].op_order_; |
| 232 ASSERT_EQ(NO_INSTR, id->type); // Information not already entered. | 233 ASSERT_EQ(NO_INSTR, id->type); // Information not already entered. |
| 233 id->type = type; | 234 id->type = type; |
| 234 } | 235 } |
| 235 } | 236 } |
| 236 | 237 |
| 237 | 238 |
| (...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 fprintf(f, " "); | 1637 fprintf(f, " "); |
| 1637 } | 1638 } |
| 1638 fprintf(f, " %s\n", buffer.start()); | 1639 fprintf(f, " %s\n", buffer.start()); |
| 1639 } | 1640 } |
| 1640 } | 1641 } |
| 1641 | 1642 |
| 1642 | 1643 |
| 1643 } // namespace disasm | 1644 } // namespace disasm |
| 1644 | 1645 |
| 1645 #endif // V8_TARGET_ARCH_IA32 | 1646 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |