Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 13 | * See the License for the specific language governing permissions and |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_UTILS_ARM64_ASSEMBLER_ARM64_H_ |
| 18 | #define ART_COMPILER_UTILS_ARM64_ASSEMBLER_ARM64_H_ |
| 19 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 20 | #include <stdint.h> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 21 | #include <memory> |
| 22 | #include <vector> |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 23 | |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 24 | #include "base/arena_containers.h" |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 25 | #include "base/logging.h" |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 26 | #include "utils/arm64/managed_register_arm64.h" |
| 27 | #include "utils/assembler.h" |
| 28 | #include "offsets.h" |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 29 | |
Artem Serov | af4e42a | 2016-08-08 15:11:24 +0100 | [diff] [blame] | 30 | // TODO(VIXL): Make VIXL compile with -Wshadow. |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 31 | #pragma GCC diagnostic push |
| 32 | #pragma GCC diagnostic ignored "-Wshadow" |
Artem Serov | af4e42a | 2016-08-08 15:11:24 +0100 | [diff] [blame] | 33 | #include "aarch64/disasm-aarch64.h" |
| 34 | #include "aarch64/macro-assembler-aarch64.h" |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 35 | #pragma GCC diagnostic pop |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 36 | |
| 37 | namespace art { |
| 38 | namespace arm64 { |
| 39 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 40 | #define MEM_OP(...) vixl::aarch64::MemOperand(__VA_ARGS__) |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 41 | |
| 42 | enum LoadOperandType { |
| 43 | kLoadSignedByte, |
| 44 | kLoadUnsignedByte, |
| 45 | kLoadSignedHalfword, |
| 46 | kLoadUnsignedHalfword, |
| 47 | kLoadWord, |
| 48 | kLoadCoreWord, |
| 49 | kLoadSWord, |
| 50 | kLoadDWord |
| 51 | }; |
| 52 | |
| 53 | enum StoreOperandType { |
| 54 | kStoreByte, |
| 55 | kStoreHalfword, |
| 56 | kStoreWord, |
| 57 | kStoreCoreWord, |
| 58 | kStoreSWord, |
| 59 | kStoreDWord |
| 60 | }; |
| 61 | |
Andreas Gampe | dcf3014 | 2016-08-08 16:06:34 -0700 | [diff] [blame] | 62 | class Arm64Assembler FINAL : public Assembler { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 63 | public: |
Andreas Gampe | dcf3014 | 2016-08-08 16:06:34 -0700 | [diff] [blame] | 64 | explicit Arm64Assembler(ArenaAllocator* arena) : Assembler(arena) {} |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 65 | |
Alexandre Rames | 087930f | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 66 | virtual ~Arm64Assembler() {} |
| 67 | |
| 68 | vixl::aarch64::MacroAssembler* GetVIXLAssembler() { return &vixl_masm_; } |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 69 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 70 | // Finalize the code. |
| 71 | void FinalizeCode() OVERRIDE; |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 72 | |
| 73 | // Size of generated code. |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 74 | size_t CodeSize() const OVERRIDE; |
| 75 | const uint8_t* CodeBufferBaseAddress() const OVERRIDE; |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 76 | |
| 77 | // Copy instructions out of assembly buffer into the given region of memory. |
| 78 | void FinalizeInstructions(const MemoryRegion& region); |
| 79 | |
Andreas Gampe | dcf3014 | 2016-08-08 16:06:34 -0700 | [diff] [blame] | 80 | void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs); |
| 81 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 82 | void SpillRegisters(vixl::aarch64::CPURegList registers, int offset); |
| 83 | void UnspillRegisters(vixl::aarch64::CPURegList registers, int offset); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 84 | |
Andreas Gampe | c6ee54e | 2014-03-24 16:45:44 -0700 | [diff] [blame] | 85 | // Jump to address (not setting link register) |
| 86 | void JumpTo(ManagedRegister m_base, Offset offs, ManagedRegister m_scratch); |
| 87 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 88 | // |
| 89 | // Heap poisoning. |
| 90 | // |
| 91 | |
| 92 | // Poison a heap reference contained in `reg`. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 93 | void PoisonHeapReference(vixl::aarch64::Register reg); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 94 | // Unpoison a heap reference contained in `reg`. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 95 | void UnpoisonHeapReference(vixl::aarch64::Register reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 96 | // Poison a heap reference contained in `reg` if heap poisoning is enabled. |
| 97 | void MaybePoisonHeapReference(vixl::aarch64::Register reg); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 98 | // Unpoison a heap reference contained in `reg` if heap poisoning is enabled. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 99 | void MaybeUnpoisonHeapReference(vixl::aarch64::Register reg); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 100 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 101 | void Bind(Label* label ATTRIBUTE_UNUSED) OVERRIDE { |
| 102 | UNIMPLEMENTED(FATAL) << "Do not use Bind for ARM64"; |
| 103 | } |
| 104 | void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE { |
| 105 | UNIMPLEMENTED(FATAL) << "Do not use Jump for ARM64"; |
| 106 | } |
| 107 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 108 | static vixl::aarch64::Register reg_x(int code) { |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 109 | CHECK(code < kNumberOfXRegisters) << code; |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 110 | if (code == SP) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 111 | return vixl::aarch64::sp; |
Serban Constantinescu | 1552373 | 2014-04-02 13:18:05 +0100 | [diff] [blame] | 112 | } else if (code == XZR) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 113 | return vixl::aarch64::xzr; |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 114 | } |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 115 | return vixl::aarch64::Register::GetXRegFromCode(code); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 118 | static vixl::aarch64::Register reg_w(int code) { |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 119 | CHECK(code < kNumberOfWRegisters) << code; |
Alexandre Rames | a304f97 | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 120 | if (code == WSP) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 121 | return vixl::aarch64::wsp; |
Alexandre Rames | a304f97 | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 122 | } else if (code == WZR) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 123 | return vixl::aarch64::wzr; |
Alexandre Rames | a304f97 | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 124 | } |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 125 | return vixl::aarch64::Register::GetWRegFromCode(code); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 128 | static vixl::aarch64::FPRegister reg_d(int code) { |
| 129 | return vixl::aarch64::FPRegister::GetDRegFromCode(code); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 132 | static vixl::aarch64::FPRegister reg_s(int code) { |
| 133 | return vixl::aarch64::FPRegister::GetSRegFromCode(code); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Andreas Gampe | dcf3014 | 2016-08-08 16:06:34 -0700 | [diff] [blame] | 136 | private: |
Alexandre Rames | 087930f | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 137 | // VIXL assembler. |
| 138 | vixl::aarch64::MacroAssembler vixl_masm_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 139 | |
Serban Constantinescu | 1552373 | 2014-04-02 13:18:05 +0100 | [diff] [blame] | 140 | // Used for testing. |
| 141 | friend class Arm64ManagedRegister_VixlRegisters_Test; |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 144 | } // namespace arm64 |
| 145 | } // namespace art |
| 146 | |
| 147 | #endif // ART_COMPILER_UTILS_ARM64_ASSEMBLER_ARM64_H_ |