1 // Copyright 2013, ARM Limited
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
12 // * Neither the name of ARM Limited nor the names of its contributors may be
13 // used to endorse or promote products derived from this software without
14 // specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef VIXL_A64_DECODER_A64_H_
28 #define VIXL_A64_DECODER_A64_H_
32 #include "hphp/vixl/globals.h"
33 #include "hphp/vixl/a64/instructions-a64.h"
36 // List macro containing all visitors needed by the decoder class.
38 #define VISITOR_LIST(V) \
42 V(MoveWideImmediate) \
45 V(UnconditionalBranch) \
46 V(UnconditionalBranchToRegister) \
49 V(ConditionalBranch) \
52 V(LoadStorePairPostIndex) \
53 V(LoadStorePairOffset) \
54 V(LoadStorePairPreIndex) \
55 V(LoadStorePairNonTemporal) \
57 V(LoadStoreUnscaledOffset) \
58 V(LoadStorePostIndex) \
59 V(LoadStorePreIndex) \
60 V(LoadStoreRegisterOffset) \
61 V(LoadStoreUnsignedOffset) \
62 V(LoadStoreExclusive) \
68 V(ConditionalCompareRegister) \
69 V(ConditionalCompareImmediate) \
70 V(ConditionalSelect) \
71 V(DataProcessing1Source) \
72 V(DataProcessing2Source) \
73 V(DataProcessing3Source) \
75 V(FPConditionalCompare) \
76 V(FPConditionalSelect) \
78 V(FPDataProcessing1Source) \
79 V(FPDataProcessing2Source) \
80 V(FPDataProcessing3Source) \
82 V(FPFixedPointConvert) \
88 // The Visitor interface. Disassembler and simulator (and other tools)
89 // must provide implementations for all of these functions.
90 class DecoderVisitor
{
92 #define DECLARE(A) virtual void Visit##A(Instruction* instr) = 0;
96 virtual ~DecoderVisitor() {}
99 // Visitors are registered in a list.
100 std::list
<DecoderVisitor
*> visitors_
;
102 friend class Decoder
;
106 class Decoder
: public DecoderVisitor
{
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
);
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
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.
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.
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
);
139 // Remove a previously registered visitor class from the list of visitors
140 // stored by the decoder.
141 void RemoveVisitor(DecoderVisitor
* visitor
);
143 #define DECLARE(A) void Visit##A(Instruction* instr);
144 VISITOR_LIST(DECLARE
)
148 // Decode the PC relative addressing instruction, and call the corresponding
150 // On entry, instruction bits 27:24 = 0x0.
151 void DecodePCRelAddressing(Instruction
* instr
);
153 // Decode the add/subtract immediate instruction, and call the corresponding
155 // On entry, instruction bits 27:24 = 0x1.
156 void DecodeAddSubImmediate(Instruction
* instr
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
200 #endif // VIXL_A64_DECODER_A64_H_