blob: 9e01a70ea94e0999c5ba5f2ade33b4329fb23add [file] [log] [blame]
Serban Constantinescued8dd492014-02-11 14:15:10 +00001/*
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 Levillain4d027112015-07-01 15:41:14 +010013 * See the License for the specific language governing permissions and
Serban Constantinescued8dd492014-02-11 14:15:10 +000014 * 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 Monteithb95a5342014-03-12 13:32:32 +000020#include <stdint.h>
Ian Rogers700a4022014-05-19 16:49:03 -070021#include <memory>
22#include <vector>
Serban Constantinescued8dd492014-02-11 14:15:10 +000023
Andreas Gampe57943812017-12-06 21:39:13 -080024#include <android-base/logging.h>
25
Vladimir Marko93205e32016-04-13 11:59:46 +010026#include "base/arena_containers.h"
Andreas Gampe57943812017-12-06 21:39:13 -080027#include "base/macros.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070028#include "offsets.h"
Serban Constantinescued8dd492014-02-11 14:15:10 +000029#include "utils/arm64/managed_register_arm64.h"
30#include "utils/assembler.h"
Andreas Gampe277ccbd2014-11-03 21:36:10 -080031
Artem Serovaf4e42a2016-08-08 15:11:24 +010032// TODO(VIXL): Make VIXL compile with -Wshadow.
Andreas Gampe277ccbd2014-11-03 21:36:10 -080033#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wshadow"
Artem Serovaf4e42a2016-08-08 15:11:24 +010035#include "aarch64/disasm-aarch64.h"
36#include "aarch64/macro-assembler-aarch64.h"
Andreas Gampe277ccbd2014-11-03 21:36:10 -080037#pragma GCC diagnostic pop
Serban Constantinescued8dd492014-02-11 14:15:10 +000038
39namespace art {
Artem Serovaa6f4832018-11-21 18:57:54 +000040
41class Arm64InstructionSetFeatures;
42
Serban Constantinescued8dd492014-02-11 14:15:10 +000043namespace arm64 {
44
Scott Wakeling97c72b72016-06-24 16:19:36 +010045#define MEM_OP(...) vixl::aarch64::MemOperand(__VA_ARGS__)
Serban Constantinescued8dd492014-02-11 14:15:10 +000046
47enum LoadOperandType {
48 kLoadSignedByte,
49 kLoadUnsignedByte,
50 kLoadSignedHalfword,
51 kLoadUnsignedHalfword,
52 kLoadWord,
53 kLoadCoreWord,
54 kLoadSWord,
55 kLoadDWord
56};
57
58enum StoreOperandType {
59 kStoreByte,
60 kStoreHalfword,
61 kStoreWord,
62 kStoreCoreWord,
63 kStoreSWord,
64 kStoreDWord
65};
66
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010067class Arm64Assembler final : public Assembler {
Serban Constantinescued8dd492014-02-11 14:15:10 +000068 public:
Artem Serovaa6f4832018-11-21 18:57:54 +000069 explicit Arm64Assembler(
70 ArenaAllocator* allocator, const Arm64InstructionSetFeatures* features = nullptr);
Serban Constantinescued8dd492014-02-11 14:15:10 +000071
Alexandre Rames087930f2016-08-02 13:45:28 +010072 virtual ~Arm64Assembler() {}
73
74 vixl::aarch64::MacroAssembler* GetVIXLAssembler() { return &vixl_masm_; }
Serban Constantinescued8dd492014-02-11 14:15:10 +000075
Vladimir Markocf93a5c2015-06-16 11:33:24 +000076 // Finalize the code.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010077 void FinalizeCode() override;
Serban Constantinescued8dd492014-02-11 14:15:10 +000078
79 // Size of generated code.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010080 size_t CodeSize() const override;
81 const uint8_t* CodeBufferBaseAddress() const override;
Serban Constantinescued8dd492014-02-11 14:15:10 +000082
83 // Copy instructions out of assembly buffer into the given region of memory.
Yi Kong39402542019-03-24 02:47:16 -070084 void FinalizeInstructions(const MemoryRegion& region) override;
Serban Constantinescued8dd492014-02-11 14:15:10 +000085
Andreas Gampedcf30142016-08-08 16:06:34 -070086 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs);
87
Scott Wakeling97c72b72016-06-24 16:19:36 +010088 void SpillRegisters(vixl::aarch64::CPURegList registers, int offset);
89 void UnspillRegisters(vixl::aarch64::CPURegList registers, int offset);
Zheng Xu69a50302015-04-14 20:04:41 +080090
Andreas Gampec6ee54e2014-03-24 16:45:44 -070091 // Jump to address (not setting link register)
92 void JumpTo(ManagedRegister m_base, Offset offs, ManagedRegister m_scratch);
93
Roland Levillain4d027112015-07-01 15:41:14 +010094 //
95 // Heap poisoning.
96 //
97
98 // Poison a heap reference contained in `reg`.
Scott Wakeling97c72b72016-06-24 16:19:36 +010099 void PoisonHeapReference(vixl::aarch64::Register reg);
Roland Levillain4d027112015-07-01 15:41:14 +0100100 // Unpoison a heap reference contained in `reg`.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100101 void UnpoisonHeapReference(vixl::aarch64::Register reg);
Roland Levillain0b671c02016-08-19 12:02:34 +0100102 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
103 void MaybePoisonHeapReference(vixl::aarch64::Register reg);
Roland Levillain4d027112015-07-01 15:41:14 +0100104 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100105 void MaybeUnpoisonHeapReference(vixl::aarch64::Register reg);
Roland Levillain4d027112015-07-01 15:41:14 +0100106
Roland Levillain2b03a1f2017-06-06 16:09:59 +0100107 // Emit code checking the status of the Marking Register, and aborting
108 // the program if MR does not match the value stored in the art::Thread
109 // object.
110 //
111 // Argument `temp` is used as a temporary register to generate code.
112 // Argument `code` is used to identify the different occurrences of
113 // MaybeGenerateMarkingRegisterCheck and is passed to the BRK instruction.
114 void GenerateMarkingRegisterCheck(vixl::aarch64::Register temp, int code = 0);
115
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100116 void Bind(Label* label ATTRIBUTE_UNUSED) override {
Andreas Gampe85b62f22015-09-09 13:15:38 -0700117 UNIMPLEMENTED(FATAL) << "Do not use Bind for ARM64";
118 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100119 void Jump(Label* label ATTRIBUTE_UNUSED) override {
Andreas Gampe85b62f22015-09-09 13:15:38 -0700120 UNIMPLEMENTED(FATAL) << "Do not use Jump for ARM64";
121 }
122
Scott Wakeling97c72b72016-06-24 16:19:36 +0100123 static vixl::aarch64::Register reg_x(int code) {
Alexandre Rames37c92df2014-10-17 14:35:27 +0100124 CHECK(code < kNumberOfXRegisters) << code;
Serban Constantinescued8dd492014-02-11 14:15:10 +0000125 if (code == SP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100126 return vixl::aarch64::sp;
Serban Constantinescu15523732014-04-02 13:18:05 +0100127 } else if (code == XZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100128 return vixl::aarch64::xzr;
Serban Constantinescued8dd492014-02-11 14:15:10 +0000129 }
Scott Wakeling97c72b72016-06-24 16:19:36 +0100130 return vixl::aarch64::Register::GetXRegFromCode(code);
Serban Constantinescued8dd492014-02-11 14:15:10 +0000131 }
132
Scott Wakeling97c72b72016-06-24 16:19:36 +0100133 static vixl::aarch64::Register reg_w(int code) {
Alexandre Rames37c92df2014-10-17 14:35:27 +0100134 CHECK(code < kNumberOfWRegisters) << code;
Alexandre Ramesa304f972014-10-17 14:35:27 +0100135 if (code == WSP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100136 return vixl::aarch64::wsp;
Alexandre Ramesa304f972014-10-17 14:35:27 +0100137 } else if (code == WZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100138 return vixl::aarch64::wzr;
Alexandre Ramesa304f972014-10-17 14:35:27 +0100139 }
Scott Wakeling97c72b72016-06-24 16:19:36 +0100140 return vixl::aarch64::Register::GetWRegFromCode(code);
Serban Constantinescued8dd492014-02-11 14:15:10 +0000141 }
142
Scott Wakeling97c72b72016-06-24 16:19:36 +0100143 static vixl::aarch64::FPRegister reg_d(int code) {
144 return vixl::aarch64::FPRegister::GetDRegFromCode(code);
Serban Constantinescued8dd492014-02-11 14:15:10 +0000145 }
146
Scott Wakeling97c72b72016-06-24 16:19:36 +0100147 static vixl::aarch64::FPRegister reg_s(int code) {
148 return vixl::aarch64::FPRegister::GetSRegFromCode(code);
Serban Constantinescued8dd492014-02-11 14:15:10 +0000149 }
150
Andreas Gampedcf30142016-08-08 16:06:34 -0700151 private:
Alexandre Rames087930f2016-08-02 13:45:28 +0100152 // VIXL assembler.
153 vixl::aarch64::MacroAssembler vixl_masm_;
Alexandre Rames5319def2014-10-23 10:03:10 +0100154
Serban Constantinescu15523732014-04-02 13:18:05 +0100155 // Used for testing.
156 friend class Arm64ManagedRegister_VixlRegisters_Test;
Serban Constantinescued8dd492014-02-11 14:15:10 +0000157};
158
Serban Constantinescued8dd492014-02-11 14:15:10 +0000159} // namespace arm64
160} // namespace art
161
162#endif // ART_COMPILER_UTILS_ARM64_ASSEMBLER_ARM64_H_