1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_ARM64_DECODER_ARM64_H_
6 #define V8_ARM64_DECODER_ARM64_H_
10 #include "src/arm64/instructions-arm64.h"
11 #include "src/globals.h"
17 // List macro containing all visitors needed by the decoder class.
19 #define VISITOR_LIST(V) \
23 V(MoveWideImmediate) \
26 V(UnconditionalBranch) \
27 V(UnconditionalBranchToRegister) \
30 V(ConditionalBranch) \
33 V(LoadStorePairPostIndex) \
34 V(LoadStorePairOffset) \
35 V(LoadStorePairPreIndex) \
37 V(LoadStoreUnscaledOffset) \
38 V(LoadStorePostIndex) \
39 V(LoadStorePreIndex) \
40 V(LoadStoreRegisterOffset) \
41 V(LoadStoreUnsignedOffset) \
46 V(ConditionalCompareRegister) \
47 V(ConditionalCompareImmediate) \
48 V(ConditionalSelect) \
49 V(DataProcessing1Source) \
50 V(DataProcessing2Source) \
51 V(DataProcessing3Source) \
53 V(FPConditionalCompare) \
54 V(FPConditionalSelect) \
56 V(FPDataProcessing1Source) \
57 V(FPDataProcessing2Source) \
58 V(FPDataProcessing3Source) \
60 V(FPFixedPointConvert) \
64 // The Visitor interface. Disassembler and simulator (and other tools)
65 // must provide implementations for all of these functions.
66 class DecoderVisitor {
68 virtual ~DecoderVisitor() {}
70 #define DECLARE(A) virtual void Visit##A(Instruction* instr) = 0;
76 // A visitor that dispatches to a list of visitors.
77 class DispatchingDecoderVisitor : public DecoderVisitor {
79 DispatchingDecoderVisitor() {}
80 virtual ~DispatchingDecoderVisitor() {}
82 // Register a new visitor class with the decoder.
83 // Decode() will call the corresponding visitor method from all registered
84 // visitor classes when decoding reaches the leaf node of the instruction
86 // Visitors are called in the order.
87 // A visitor can only be registered once.
88 // Registering an already registered visitor will update its position.
90 // d.AppendVisitor(V1);
91 // d.AppendVisitor(V2);
92 // d.PrependVisitor(V2); // Move V2 at the start of the list.
93 // d.InsertVisitorBefore(V3, V2);
94 // d.AppendVisitor(V4);
95 // d.AppendVisitor(V4); // No effect.
99 // will call in order visitor methods in V3, V2, V1, V4.
100 void AppendVisitor(DecoderVisitor* visitor);
101 void PrependVisitor(DecoderVisitor* visitor);
102 void InsertVisitorBefore(DecoderVisitor* new_visitor,
103 DecoderVisitor* registered_visitor);
104 void InsertVisitorAfter(DecoderVisitor* new_visitor,
105 DecoderVisitor* registered_visitor);
107 // Remove a previously registered visitor class from the list of visitors
108 // stored by the decoder.
109 void RemoveVisitor(DecoderVisitor* visitor);
111 #define DECLARE(A) void Visit##A(Instruction* instr);
112 VISITOR_LIST(DECLARE)
116 // Visitors are registered in a list.
117 std::list<DecoderVisitor*> visitors_;
122 class Decoder : public V {
125 virtual ~Decoder() {}
127 // Top-level instruction decoder function. Decodes an instruction and calls
128 // the visitor functions registered with the Decoder class.
129 virtual void Decode(Instruction *instr);
132 // Decode the PC relative addressing instruction, and call the corresponding
134 // On entry, instruction bits 27:24 = 0x0.
135 void DecodePCRelAddressing(Instruction* instr);
137 // Decode the add/subtract immediate instruction, and call the corresponding
139 // On entry, instruction bits 27:24 = 0x1.
140 void DecodeAddSubImmediate(Instruction* instr);
142 // Decode the branch, system command, and exception generation parts of
143 // the instruction tree, and call the corresponding visitors.
144 // On entry, instruction bits 27:24 = {0x4, 0x5, 0x6, 0x7}.
145 void DecodeBranchSystemException(Instruction* instr);
147 // Decode the load and store parts of the instruction tree, and call
148 // the corresponding visitors.
149 // On entry, instruction bits 27:24 = {0x8, 0x9, 0xC, 0xD}.
150 void DecodeLoadStore(Instruction* instr);
152 // Decode the logical immediate and move wide immediate parts of the
153 // instruction tree, and call the corresponding visitors.
154 // On entry, instruction bits 27:24 = 0x2.
155 void DecodeLogical(Instruction* instr);
157 // Decode the bitfield and extraction parts of the instruction tree,
158 // and call the corresponding visitors.
159 // On entry, instruction bits 27:24 = 0x3.
160 void DecodeBitfieldExtract(Instruction* instr);
162 // Decode the data processing parts of the instruction tree, and call the
163 // corresponding visitors.
164 // On entry, instruction bits 27:24 = {0x1, 0xA, 0xB}.
165 void DecodeDataProcessing(Instruction* instr);
167 // Decode the floating point parts of the instruction tree, and call the
168 // corresponding visitors.
169 // On entry, instruction bits 27:24 = {0xE, 0xF}.
170 void DecodeFP(Instruction* instr);
172 // Decode the Advanced SIMD (NEON) load/store part of the instruction tree,
173 // and call the corresponding visitors.
174 // On entry, instruction bits 29:25 = 0x6.
175 void DecodeAdvSIMDLoadStore(Instruction* instr);
177 // Decode the Advanced SIMD (NEON) data processing part of the instruction
178 // tree, and call the corresponding visitors.
179 // On entry, instruction bits 27:25 = 0x7.
180 void DecodeAdvSIMDDataProcessing(Instruction* instr);
184 } } // namespace v8::internal
186 #endif // V8_ARM64_DECODER_ARM64_H_