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 virtual ~DecoderVisitor() {} | |
93 | |
94 #define DECLARE(A) virtual void Visit##A(Instruction* instr) = 0; | |
95 VISITOR_LIST(DECLARE) | |
96 #undef DECLARE | |
97 }; | |
98 | |
99 | |
100 // A visitor that dispatches to a list of visitors. | |
101 class DispatchingDecoderVisitor : public DecoderVisitor { | |
102 public: | |
103 DispatchingDecoderVisitor() {} | |
104 virtual ~DispatchingDecoderVisitor() {} | |
105 | |
106 // Register a new visitor class with the decoder. | |
107 // Decode() will call the corresponding visitor method from all registered | |
108 // visitor classes when decoding reaches the leaf node of the instruction | |
109 // decode tree. | |
110 // Visitors are called in the order. | |
111 // A visitor can only be registered once. | |
112 // Registering an already registered visitor will update its position. | |
113 // | |
114 // d.AppendVisitor(V1); | |
115 // d.AppendVisitor(V2); | |
116 // d.PrependVisitor(V2); // Move V2 at the start of the list. | |
117 // d.InsertVisitorBefore(V3, V2); | |
118 // d.AppendVisitor(V4); | |
119 // d.AppendVisitor(V4); // No effect. | |
120 // | |
121 // d.Decode(i); | |
122 // | |
123 // will call in order visitor methods in V3, V2, V1, V4. | |
124 void AppendVisitor(DecoderVisitor* visitor); | |
125 void PrependVisitor(DecoderVisitor* visitor); | |
126 void InsertVisitorBefore(DecoderVisitor* new_visitor, | |
127 DecoderVisitor* registered_visitor); | |
128 void InsertVisitorAfter(DecoderVisitor* new_visitor, | |
129 DecoderVisitor* registered_visitor); | |
130 | |
131 // Remove a previously registered visitor class from the list of visitors | |
132 // stored by the decoder. | |
133 void RemoveVisitor(DecoderVisitor* visitor); | |
134 | |
135 #define DECLARE(A) void Visit##A(Instruction* instr); | |
136 VISITOR_LIST(DECLARE) | |
137 #undef DECLARE | |
138 | |
139 private: | |
140 // Visitors are registered in a list. | |
141 std::list<DecoderVisitor*> visitors_; | |
142 }; | |
143 | |
144 | |
145 template<typename V> | |
146 class Decoder : public V { | |
147 public: | |
148 Decoder() {} | |
149 virtual ~Decoder() {} | |
150 | |
151 // Top-level instruction decoder function. Decodes an instruction and calls | |
152 // the visitor functions registered with the Decoder class. | |
153 virtual void Decode(Instruction *instr); | |
154 | |
155 private: | |
156 // Decode the PC relative addressing instruction, and call the corresponding | |
157 // visitors. | |
158 // On entry, instruction bits 27:24 = 0x0. | |
159 void DecodePCRelAddressing(Instruction* instr); | |
160 | |
161 // Decode the add/subtract immediate instruction, and call the corresponding | |
162 // visitors. | |
163 // On entry, instruction bits 27:24 = 0x1. | |
164 void DecodeAddSubImmediate(Instruction* instr); | |
165 | |
166 // Decode the branch, system command, and exception generation parts of | |
167 // the instruction tree, and call the corresponding visitors. | |
168 // On entry, instruction bits 27:24 = {0x4, 0x5, 0x6, 0x7}. | |
169 void DecodeBranchSystemException(Instruction* instr); | |
170 | |
171 // Decode the load and store parts of the instruction tree, and call | |
172 // the corresponding visitors. | |
173 // On entry, instruction bits 27:24 = {0x8, 0x9, 0xC, 0xD}. | |
174 void DecodeLoadStore(Instruction* instr); | |
175 | |
176 // Decode the logical immediate and move wide immediate parts of the | |
177 // instruction tree, and call the corresponding visitors. | |
178 // On entry, instruction bits 27:24 = 0x2. | |
179 void DecodeLogical(Instruction* instr); | |
180 | |
181 // Decode the bitfield and extraction parts of the instruction tree, | |
182 // and call the corresponding visitors. | |
183 // On entry, instruction bits 27:24 = 0x3. | |
184 void DecodeBitfieldExtract(Instruction* instr); | |
185 | |
186 // Decode the data processing parts of the instruction tree, and call the | |
187 // corresponding visitors. | |
188 // On entry, instruction bits 27:24 = {0x1, 0xA, 0xB}. | |
189 void DecodeDataProcessing(Instruction* instr); | |
190 | |
191 // Decode the floating point parts of the instruction tree, and call the | |
192 // corresponding visitors. | |
193 // On entry, instruction bits 27:24 = {0xE, 0xF}. | |
194 void DecodeFP(Instruction* instr); | |
195 | |
196 // Decode the Advanced SIMD (NEON) load/store part of the instruction tree, | |
197 // and call the corresponding visitors. | |
198 // On entry, instruction bits 29:25 = 0x6. | |
199 void DecodeAdvSIMDLoadStore(Instruction* instr); | |
200 | |
201 // Decode the Advanced SIMD (NEON) data processing part of the instruction | |
202 // tree, and call the corresponding visitors. | |
203 // On entry, instruction bits 27:25 = 0x7. | |
204 void DecodeAdvSIMDDataProcessing(Instruction* instr); | |
205 }; | |
206 | |
207 | |
208 } } // namespace v8::internal | |
209 | |
210 #endif // V8_A64_DECODER_A64_H_ | |
OLD | NEW |