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 linker {
27 
28 class Thumb2RelativePatcher final : public ArmBaseRelativePatcher {
29  public:
30   explicit Thumb2RelativePatcher(RelativePatcherThunkProvider* thunk_provider,
31                                  RelativePatcherTargetProvider* target_provider);
32 
33   void PatchCall(std::vector<uint8_t>* code,
34                  uint32_t literal_offset,
35                  uint32_t patch_offset,
36                  uint32_t target_offset) override;
37   void PatchPcRelativeReference(std::vector<uint8_t>* code,
38                                 const LinkerPatch& patch,
39                                 uint32_t patch_offset,
40                                 uint32_t target_offset) override;
41   void PatchEntrypointCall(std::vector<uint8_t>* code,
42                            const LinkerPatch& patch,
43                            uint32_t patch_offset) override;
44   void PatchBakerReadBarrierBranch(std::vector<uint8_t>* code,
45                                    const LinkerPatch& patch,
46                                    uint32_t patch_offset) override;
47 
48  protected:
49   uint32_t MaxPositiveDisplacement(const ThunkKey& key) override;
50   uint32_t MaxNegativeDisplacement(const ThunkKey& key) override;
51 
52  private:
53   static void PatchBl(std::vector<uint8_t>* code, uint32_t literal_offset, uint32_t displacement);
54 
55   static void SetInsn32(std::vector<uint8_t>* code, uint32_t offset, uint32_t value);
56   static uint32_t GetInsn32(ArrayRef<const uint8_t> code, uint32_t offset);
57 
58   template <typename Vector>
59   static uint32_t GetInsn32(Vector* code, uint32_t offset);
60 
61   static uint32_t GetInsn16(ArrayRef<const uint8_t> code, uint32_t offset);
62 
63   template <typename Vector>
64   static uint32_t GetInsn16(Vector* code, uint32_t offset);
65 
66   friend class Thumb2RelativePatcherTest;
67 
68   DISALLOW_COPY_AND_ASSIGN(Thumb2RelativePatcher);
69 };
70 
71 }  // namespace linker
72 }  // namespace art
73 
74 #endif  // ART_DEX2OAT_LINKER_ARM_RELATIVE_PATCHER_THUMB2_H_
75