Home | History | Annotate | Download | only in arm64
      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.
      4 
      5 #ifndef V8_ARM64_DECODER_ARM64_H_
      6 #define V8_ARM64_DECODER_ARM64_H_
      7 
      8 #include <list>
      9 
     10 #include "src/arm64/instructions-arm64.h"
     11 #include "src/globals.h"
     12 
     13 namespace v8 {
     14 namespace internal {
     15 
     16 
     17 // List macro containing all visitors needed by the decoder class.
     18 
     19 #define VISITOR_LIST(V)                 \
     20   V(PCRelAddressing)                    \
     21   V(AddSubImmediate)                    \
     22   V(LogicalImmediate)                   \
     23   V(MoveWideImmediate)                  \
     24   V(Bitfield)                           \
     25   V(Extract)                            \
     26   V(UnconditionalBranch)                \
     27   V(UnconditionalBranchToRegister)      \
     28   V(CompareBranch)                      \
     29   V(TestBranch)                         \
     30   V(ConditionalBranch)                  \
     31   V(System)                             \
     32   V(Exception)                          \
     33   V(LoadStorePairPostIndex)             \
     34   V(LoadStorePairOffset)                \
     35   V(LoadStorePairPreIndex)              \
     36   V(LoadLiteral)                        \
     37   V(LoadStoreUnscaledOffset)            \
     38   V(LoadStorePostIndex)                 \
     39   V(LoadStorePreIndex)                  \
     40   V(LoadStoreRegisterOffset)            \
     41   V(LoadStoreUnsignedOffset)            \
     42   V(LoadStoreAcquireRelease)            \
     43   V(LogicalShifted)                     \
     44   V(AddSubShifted)                      \
     45   V(AddSubExtended)                     \
     46   V(AddSubWithCarry)                    \
     47   V(ConditionalCompareRegister)         \
     48   V(ConditionalCompareImmediate)        \
     49   V(ConditionalSelect)                  \
     50   V(DataProcessing1Source)              \
     51   V(DataProcessing2Source)              \
     52   V(DataProcessing3Source)              \
     53   V(FPCompare)                          \
     54   V(FPConditionalCompare)               \
     55   V(FPConditionalSelect)                \
     56   V(FPImmediate)                        \
     57   V(FPDataProcessing1Source)            \
     58   V(FPDataProcessing2Source)            \
     59   V(FPDataProcessing3Source)            \
     60   V(FPIntegerConvert)                   \
     61   V(FPFixedPointConvert)                \
     62   V(NEON2RegMisc)                       \
     63   V(NEON3Different)                     \
     64   V(NEON3Same)                          \
     65   V(NEONAcrossLanes)                    \
     66   V(NEONByIndexedElement)               \
     67   V(NEONCopy)                           \
     68   V(NEONExtract)                        \
     69   V(NEONLoadStoreMultiStruct)           \
     70   V(NEONLoadStoreMultiStructPostIndex)  \
     71   V(NEONLoadStoreSingleStruct)          \
     72   V(NEONLoadStoreSingleStructPostIndex) \
     73   V(NEONModifiedImmediate)              \
     74   V(NEONScalar2RegMisc)                 \
     75   V(NEONScalar3Diff)                    \
     76   V(NEONScalar3Same)                    \
     77   V(NEONScalarByIndexedElement)         \
     78   V(NEONScalarCopy)                     \
     79   V(NEONScalarPairwise)                 \
     80   V(NEONScalarShiftImmediate)           \
     81   V(NEONShiftImmediate)                 \
     82   V(NEONTable)                          \
     83   V(NEONPerm)                           \
     84   V(Unallocated)                        \
     85   V(Unimplemented)
     86 
     87 // The Visitor interface. Disassembler and simulator (and other tools)
     88 // must provide implementations for all of these functions.
     89 class DecoderVisitor {
     90  public:
     91   virtual ~DecoderVisitor() {}
     92 
     93   #define DECLARE(A) virtual void Visit##A(Instruction* instr) = 0;
     94   VISITOR_LIST(DECLARE)
     95   #undef DECLARE
     96 };
     97 
     98 
     99 // A visitor that dispatches to a list of visitors.
    100 class DispatchingDecoderVisitor : public DecoderVisitor {
    101  public:
    102   DispatchingDecoderVisitor() {}
    103   virtual ~DispatchingDecoderVisitor() {}
    104 
    105   // Register a new visitor class with the decoder.
    106   // Decode() will call the corresponding visitor method from all registered
    107   // visitor classes when decoding reaches the leaf node of the instruction
    108   // decode tree.
    109   // Visitors are called in the order.
    110   // A visitor can only be registered once.
    111   // Registering an already registered visitor will update its position.
    112   //
    113   //   d.AppendVisitor(V1);
    114   //   d.AppendVisitor(V2);
    115   //   d.PrependVisitor(V2);            // Move V2 at the start of the list.
    116   //   d.InsertVisitorBefore(V3, V2);
    117   //   d.AppendVisitor(V4);
    118   //   d.AppendVisitor(V4);             // No effect.
    119   //
    120   //   d.Decode(i);
    121   //
    122   // will call in order visitor methods in V3, V2, V1, V4.
    123   void AppendVisitor(DecoderVisitor* visitor);
    124   void PrependVisitor(DecoderVisitor* visitor);
    125   void InsertVisitorBefore(DecoderVisitor* new_visitor,
    126                            DecoderVisitor* registered_visitor);
    127   void InsertVisitorAfter(DecoderVisitor* new_visitor,
    128                           DecoderVisitor* registered_visitor);
    129 
    130   // Remove a previously registered visitor class from the list of visitors
    131   // stored by the decoder.
    132   void RemoveVisitor(DecoderVisitor* visitor);
    133 
    134   void VisitNEONShiftImmediate(const Instruction* instr);
    135 
    136   #define DECLARE(A) void Visit##A(Instruction* instr);
    137   VISITOR_LIST(DECLARE)
    138   #undef DECLARE
    139 
    140  private:
    141   // Visitors are registered in a list.
    142   std::list<DecoderVisitor*> visitors_;
    143 };
    144 
    145 
    146 template<typename V>
    147 class Decoder : public V {
    148  public:
    149   Decoder() {}
    150   virtual ~Decoder() {}
    151 
    152   // Top-level instruction decoder function. Decodes an instruction and calls
    153   // the visitor functions registered with the Decoder class.
    154   virtual void Decode(Instruction *instr);
    155 
    156  private:
    157   // Decode the PC relative addressing instruction, and call the corresponding
    158   // visitors.
    159   // On entry, instruction bits 27:24 = 0x0.
    160   void DecodePCRelAddressing(Instruction* instr);
    161 
    162   // Decode the add/subtract immediate instruction, and call the corresponding
    163   // visitors.
    164   // On entry, instruction bits 27:24 = 0x1.
    165   void DecodeAddSubImmediate(Instruction* instr);
    166 
    167   // Decode the branch, system command, and exception generation parts of
    168   // the instruction tree, and call the corresponding visitors.
    169   // On entry, instruction bits 27:24 = {0x4, 0x5, 0x6, 0x7}.
    170   void DecodeBranchSystemException(Instruction* instr);
    171 
    172   // Decode the load and store parts of the instruction tree, and call
    173   // the corresponding visitors.
    174   // On entry, instruction bits 27:24 = {0x8, 0x9, 0xC, 0xD}.
    175   void DecodeLoadStore(Instruction* instr);
    176 
    177   // Decode the logical immediate and move wide immediate parts of the
    178   // instruction tree, and call the corresponding visitors.
    179   // On entry, instruction bits 27:24 = 0x2.
    180   void DecodeLogical(Instruction* instr);
    181 
    182   // Decode the bitfield and extraction parts of the instruction tree,
    183   // and call the corresponding visitors.
    184   // On entry, instruction bits 27:24 = 0x3.
    185   void DecodeBitfieldExtract(Instruction* instr);
    186 
    187   // Decode the data processing parts of the instruction tree, and call the
    188   // corresponding visitors.
    189   // On entry, instruction bits 27:24 = {0x1, 0xA, 0xB}.
    190   void DecodeDataProcessing(Instruction* instr);
    191 
    192   // Decode the floating point parts of the instruction tree, and call the
    193   // corresponding visitors.
    194   // On entry, instruction bits 27:24 = {0xE, 0xF}.
    195   void DecodeFP(Instruction* instr);
    196 
    197   // Decode the Advanced SIMD (NEON) load/store part of the instruction tree,
    198   // and call the corresponding visitors.
    199   // On entry, instruction bits 29:25 = 0x6.
    200   void DecodeNEONLoadStore(Instruction* instr);
    201 
    202   // Decode the Advanced SIMD (NEON) data processing part of the instruction
    203   // tree, and call the corresponding visitors.
    204   // On entry, instruction bits 27:25 = 0x7.
    205   void DecodeNEONVectorDataProcessing(Instruction* instr);
    206 
    207   // Decode the Advanced SIMD (NEON) scalar data processing part of the
    208   // instruction tree, and call the corresponding visitors.
    209   // On entry, instruction bits 28:25 = 0xF.
    210   void DecodeNEONScalarDataProcessing(Instruction* instr);
    211 };
    212 
    213 
    214 }  // namespace internal
    215 }  // namespace v8
    216 
    217 #endif  // V8_ARM64_DECODER_ARM64_H_
    218