1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_DEX2OAT_LINKER_ARM_RELATIVE_PATCHER_THUMB2_H_
18 #define ART_DEX2OAT_LINKER_ARM_RELATIVE_PATCHER_THUMB2_H_
19 
20 #include "arch/arm/registers_arm.h"
21 #include "base/array_ref.h"
22 #include "linker/arm/relative_patcher_arm_base.h"
23 
24 namespace art {
25 
26 namespace arm {
27 class ArmVIXLAssembler;
28 }  // namespace arm
29 
30 namespace linker {
31 
32 class Thumb2RelativePatcher final : public ArmBaseRelativePatcher {
33  public:
34   explicit Thumb2RelativePatcher(RelativePatcherThunkProvider* thunk_provider,
35                                  RelativePatcherTargetProvider* target_provider);
36 
37   void PatchCall(std::vector<uint8_t>* code,
38                  uint32_t literal_offset,
39                  uint32_t patch_offset,
40                  uint32_t target_offset) override;
41   void PatchPcRelativeReference(std::vector<uint8_t>* code,
42                                 const LinkerPatch& patch,
43                                 uint32_t patch_offset,
44                                 uint32_t target_offset) override;
45   void PatchEntrypointCall(std::vector<uint8_t>* code,
46                            const LinkerPatch& patch,
47                            uint32_t patch_offset) override;
48   void PatchBakerReadBarrierBranch(std::vector<uint8_t>* code,
49                                    const LinkerPatch& patch,
50                                    uint32_t patch_offset) override;
51 
52  protected:
53   uint32_t MaxPositiveDisplacement(const ThunkKey& key) override;
54   uint32_t MaxNegativeDisplacement(const ThunkKey& key) override;
55 
56  private:
57   static void PatchBl(std::vector<uint8_t>* code, uint32_t literal_offset, uint32_t displacement);
58 
59   static void SetInsn32(std::vector<uint8_t>* code, uint32_t offset, uint32_t value);
60   static uint32_t GetInsn32(ArrayRef<const uint8_t> code, uint32_t offset);
61 
62   template <typename Vector>
63   static uint32_t GetInsn32(Vector* code, uint32_t offset);
64 
65   static uint32_t GetInsn16(ArrayRef<const uint8_t> code, uint32_t offset);
66 
67   template <typename Vector>
68   static uint32_t GetInsn16(Vector* code, uint32_t offset);
69 
70   friend class Thumb2RelativePatcherTest;
71 
72   DISALLOW_COPY_AND_ASSIGN(Thumb2RelativePatcher);
73 };
74 
75 }  // namespace linker
76 }  // namespace art
77 
78 #endif  // ART_DEX2OAT_LINKER_ARM_RELATIVE_PATCHER_THUMB2_H_
79