OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #ifndef V8_A64_DECODER_A64_H_ |
| 29 #define V8_A64_DECODER_A64_H_ |
| 30 |
| 31 #include <list> |
| 32 |
| 33 #include "globals.h" |
| 34 #include "a64/instructions-a64.h" |
| 35 |
| 36 namespace v8 { |
| 37 namespace internal { |
| 38 |
| 39 |
| 40 // List macro containing all visitors needed by the decoder class. |
| 41 |
| 42 #define VISITOR_LIST(V) \ |
| 43 V(PCRelAddressing) \ |
| 44 V(AddSubImmediate) \ |
| 45 V(LogicalImmediate) \ |
| 46 V(MoveWideImmediate) \ |
| 47 V(Bitfield) \ |
| 48 V(Extract) \ |
| 49 V(UnconditionalBranch) \ |
| 50 V(UnconditionalBranchToRegister) \ |
| 51 V(CompareBranch) \ |
| 52 V(TestBranch) \ |
| 53 V(ConditionalBranch) \ |
| 54 V(System) \ |
| 55 V(Exception) \ |
| 56 V(LoadStorePairPostIndex) \ |
| 57 V(LoadStorePairOffset) \ |
| 58 V(LoadStorePairPreIndex) \ |
| 59 V(LoadStorePairNonTemporal) \ |
| 60 V(LoadLiteral) \ |
| 61 V(LoadStoreUnscaledOffset) \ |
| 62 V(LoadStorePostIndex) \ |
| 63 V(LoadStorePreIndex) \ |
| 64 V(LoadStoreRegisterOffset) \ |
| 65 V(LoadStoreUnsignedOffset) \ |
| 66 V(LogicalShifted) \ |
| 67 V(AddSubShifted) \ |
| 68 V(AddSubExtended) \ |
| 69 V(AddSubWithCarry) \ |
| 70 V(ConditionalCompareRegister) \ |
| 71 V(ConditionalCompareImmediate) \ |
| 72 V(ConditionalSelect) \ |
| 73 V(DataProcessing1Source) \ |
| 74 V(DataProcessing2Source) \ |
| 75 V(DataProcessing3Source) \ |
| 76 V(FPCompare) \ |
| 77 V(FPConditionalCompare) \ |
| 78 V(FPConditionalSelect) \ |
| 79 V(FPImmediate) \ |
| 80 V(FPDataProcessing1Source) \ |
| 81 V(FPDataProcessing2Source) \ |
| 82 V(FPDataProcessing3Source) \ |
| 83 V(FPIntegerConvert) \ |
| 84 V(FPFixedPointConvert) \ |
| 85 V(Unallocated) \ |
| 86 V(Unimplemented) |
| 87 |
| 88 // The Visitor interface. Disassembler and simulator (and other tools) |
| 89 // must provide implementations for all of these functions. |
| 90 class DecoderVisitor { |
| 91 public: |
| 92 #define DECLARE(A) virtual void Visit##A(Instruction* instr) = 0; |
| 93 VISITOR_LIST(DECLARE) |
| 94 #undef DECLARE |
| 95 |
| 96 virtual ~DecoderVisitor() {} |
| 97 |
| 98 private: |
| 99 // Visitors are registered in a list. |
| 100 std::list<DecoderVisitor*> visitors_; |
| 101 |
| 102 friend class Decoder; |
| 103 }; |
| 104 |
| 105 |
| 106 class Decoder: public DecoderVisitor { |
| 107 public: |
| 108 explicit Decoder() {} |
| 109 |
| 110 // Top-level instruction decoder function. Decodes an instruction and calls |
| 111 // the visitor functions registered with the Decoder class. |
| 112 void Decode(Instruction *instr); |
| 113 |
| 114 // Register a new visitor class with the decoder. |
| 115 // Decode() will call the corresponding visitor method from all registered |
| 116 // visitor classes when decoding reaches the leaf node of the instruction |
| 117 // decode tree. |
| 118 // Visitors are called in the order. |
| 119 // A visitor can only be registered once. |
| 120 // Registering an already registered visitor will update its position. |
| 121 // |
| 122 // d.AppendVisitor(V1); |
| 123 // d.AppendVisitor(V2); |
| 124 // d.PrependVisitor(V2); // Move V2 at the start of the list. |
| 125 // d.InsertVisitorBefore(V3, V2); |
| 126 // d.AppendVisitor(V4); |
| 127 // d.AppendVisitor(V4); // No effect. |
| 128 // |
| 129 // d.Decode(i); |
| 130 // |
| 131 // will call in order visitor methods in V3, V2, V1, V4. |
| 132 void AppendVisitor(DecoderVisitor* visitor); |
| 133 void PrependVisitor(DecoderVisitor* visitor); |
| 134 void InsertVisitorBefore(DecoderVisitor* new_visitor, |
| 135 DecoderVisitor* registered_visitor); |
| 136 void InsertVisitorAfter(DecoderVisitor* new_visitor, |
| 137 DecoderVisitor* registered_visitor); |
| 138 |
| 139 // Remove a previously registered visitor class from the list of visitors |
| 140 // stored by the decoder. |
| 141 void RemoveVisitor(DecoderVisitor* visitor); |
| 142 |
| 143 #define DECLARE(A) void Visit##A(Instruction* instr); |
| 144 VISITOR_LIST(DECLARE) |
| 145 #undef DECLARE |
| 146 |
| 147 private: |
| 148 // Decode the PC relative addressing instruction, and call the corresponding |
| 149 // visitors. |
| 150 // On entry, instruction bits 27:24 = 0x0. |
| 151 void DecodePCRelAddressing(Instruction* instr); |
| 152 |
| 153 // Decode the add/subtract immediate instruction, and call the corresponding |
| 154 // visitors. |
| 155 // On entry, instruction bits 27:24 = 0x1. |
| 156 void DecodeAddSubImmediate(Instruction* instr); |
| 157 |
| 158 // Decode the branch, system command, and exception generation parts of |
| 159 // the instruction tree, and call the corresponding visitors. |
| 160 // On entry, instruction bits 27:24 = {0x4, 0x5, 0x6, 0x7}. |
| 161 void DecodeBranchSystemException(Instruction* instr); |
| 162 |
| 163 // Decode the load and store parts of the instruction tree, and call |
| 164 // the corresponding visitors. |
| 165 // On entry, instruction bits 27:24 = {0x8, 0x9, 0xC, 0xD}. |
| 166 void DecodeLoadStore(Instruction* instr); |
| 167 |
| 168 // Decode the logical immediate and move wide immediate parts of the |
| 169 // instruction tree, and call the corresponding visitors. |
| 170 // On entry, instruction bits 27:24 = 0x2. |
| 171 void DecodeLogical(Instruction* instr); |
| 172 |
| 173 // Decode the bitfield and extraction parts of the instruction tree, |
| 174 // and call the corresponding visitors. |
| 175 // On entry, instruction bits 27:24 = 0x3. |
| 176 void DecodeBitfieldExtract(Instruction* instr); |
| 177 |
| 178 // Decode the data processing parts of the instruction tree, and call the |
| 179 // corresponding visitors. |
| 180 // On entry, instruction bits 27:24 = {0x1, 0xA, 0xB}. |
| 181 void DecodeDataProcessing(Instruction* instr); |
| 182 |
| 183 // Decode the floating point parts of the instruction tree, and call the |
| 184 // corresponding visitors. |
| 185 // On entry, instruction bits 27:24 = {0xE, 0xF}. |
| 186 void DecodeFP(Instruction* instr); |
| 187 |
| 188 // Decode the Advanced SIMD (NEON) load/store part of the instruction tree, |
| 189 // and call the corresponding visitors. |
| 190 // On entry, instruction bits 29:25 = 0x6. |
| 191 void DecodeAdvSIMDLoadStore(Instruction* instr); |
| 192 |
| 193 // Decode the Advanced SIMD (NEON) data processing part of the instruction |
| 194 // tree, and call the corresponding visitors. |
| 195 // On entry, instruction bits 27:25 = 0x7. |
| 196 void DecodeAdvSIMDDataProcessing(Instruction* instr); |
| 197 }; |
| 198 |
| 199 |
| 200 } } // namespace v8::internal |
| 201 |
| 202 #endif // V8_A64_DECODER_A64_H_ |
OLD | NEW |