blob: 561130305e09c1dddb7c8dbe516b71e301fab3d8 [file] [log] [blame]
Vladimir Markob163bb72015-03-31 21:49:49 +01001/*
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
22namespace art {
23namespace linker {
24
25class Thumb2RelativePatcher FINAL : public ArmBaseRelativePatcher {
26 public:
27 explicit Thumb2RelativePatcher(RelativePatcherTargetProvider* provider);
28
29 void PatchCall(std::vector<uint8_t>* code, uint32_t literal_offset,
30 uint32_t patch_offset, uint32_t target_offset) OVERRIDE;
31 void PatchDexCacheReference(std::vector<uint8_t>* code, const LinkerPatch& patch,
32 uint32_t patch_offset, uint32_t target_offset) OVERRIDE;
33
34 private:
35 static std::vector<uint8_t> CompileThunkCode();
36
37 // PC displacement from patch location; Thumb2 PC is always at instruction address + 4.
38 static constexpr int32_t kPcDisplacement = 4;
39
40 // Maximum positive and negative displacement measured from the patch location.
41 // (Signed 25 bit displacement with the last bit 0 has range [-2^24, 2^24-2] measured from
42 // the Thumb2 PC pointing right after the BL, i.e. 4 bytes later than the patch location.)
43 static constexpr uint32_t kMaxPositiveDisplacement = (1u << 24) - 2 + kPcDisplacement;
44 static constexpr uint32_t kMaxNegativeDisplacement = (1u << 24) - kPcDisplacement;
45
46 DISALLOW_COPY_AND_ASSIGN(Thumb2RelativePatcher);
47};
48
49} // namespace linker
50} // namespace art
51
52#endif // ART_COMPILER_LINKER_ARM_RELATIVE_PATCHER_THUMB2_H_