Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 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_COMPILER_LINKER_ARM_RELATIVE_PATCHER_THUMB2_H_ |
| 18 | #define ART_COMPILER_LINKER_ARM_RELATIVE_PATCHER_THUMB2_H_ |
| 19 | |
| 20 | #include "linker/arm/relative_patcher_arm_base.h" |
| 21 | |
| 22 | namespace art { |
| 23 | namespace linker { |
| 24 | |
| 25 | class Thumb2RelativePatcher FINAL : public ArmBaseRelativePatcher { |
| 26 | public: |
| 27 | explicit Thumb2RelativePatcher(RelativePatcherTargetProvider* provider); |
| 28 | |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 29 | void PatchCall(std::vector<uint8_t>* code, |
| 30 | uint32_t literal_offset, |
| 31 | uint32_t patch_offset, |
| 32 | uint32_t target_offset) OVERRIDE; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 33 | void PatchPcRelativeReference(std::vector<uint8_t>* code, |
| 34 | const LinkerPatch& patch, |
| 35 | uint32_t patch_offset, |
| 36 | uint32_t target_offset) OVERRIDE; |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | static std::vector<uint8_t> CompileThunkCode(); |
| 40 | |
Vladimir Marko | e5c76c5 | 2015-04-06 12:10:19 +0100 | [diff] [blame] | 41 | void SetInsn32(std::vector<uint8_t>* code, uint32_t offset, uint32_t value); |
| 42 | static uint32_t GetInsn32(ArrayRef<const uint8_t> code, uint32_t offset); |
| 43 | |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 44 | template <typename Vector> |
| 45 | static uint32_t GetInsn32(Vector* code, uint32_t offset); |
Vladimir Marko | e5c76c5 | 2015-04-06 12:10:19 +0100 | [diff] [blame] | 46 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 47 | // PC displacement from patch location; Thumb2 PC is always at instruction address + 4. |
| 48 | static constexpr int32_t kPcDisplacement = 4; |
| 49 | |
| 50 | // Maximum positive and negative displacement measured from the patch location. |
| 51 | // (Signed 25 bit displacement with the last bit 0 has range [-2^24, 2^24-2] measured from |
| 52 | // the Thumb2 PC pointing right after the BL, i.e. 4 bytes later than the patch location.) |
| 53 | static constexpr uint32_t kMaxPositiveDisplacement = (1u << 24) - 2 + kPcDisplacement; |
| 54 | static constexpr uint32_t kMaxNegativeDisplacement = (1u << 24) - kPcDisplacement; |
| 55 | |
| 56 | DISALLOW_COPY_AND_ASSIGN(Thumb2RelativePatcher); |
| 57 | }; |
| 58 | |
| 59 | } // namespace linker |
| 60 | } // namespace art |
| 61 | |
| 62 | #endif // ART_COMPILER_LINKER_ARM_RELATIVE_PATCHER_THUMB2_H_ |