blob: 4e88e640e5fbf78f4e6f124570710327e370d74c [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
Vladimir Marko93205e32016-04-13 11:59:46 +010024#include "base/arena_containers.h"
Serban Constantinescued8dd492014-02-11 14:15:10 +000025#include "base/logging.h"
Serban Constantinescued8dd492014-02-11 14:15:10 +000026#include "utils/arm64/managed_register_arm64.h"
27#include "utils/assembler.h"
28#include "offsets.h"
Andreas Gampe277ccbd2014-11-03 21:36:10 -080029
Scott Wakeling97c72b72016-06-24 16:19:36 +010030// TODO: make vixl clean wrt -Wshadow, -Wunknown-pragmas, -Wmissing-noreturn
Andreas Gampe277ccbd2014-11-03 21:36:10 -080031#pragma GCC diagnostic push
Andreas Gampe65b798e2015-04-06 09:35:22 -070032#pragma GCC diagnostic ignored "-Wunknown-pragmas"
Andreas Gampe277ccbd2014-11-03 21:36:10 -080033#pragma GCC diagnostic ignored "-Wshadow"
Andreas Gampe65b798e2015-04-06 09:35:22 -070034#pragma GCC diagnostic ignored "-Wmissing-noreturn"
Scott Wakeling97c72b72016-06-24 16:19:36 +010035#include "a64/disasm-a64.h"
36#include "a64/macro-assembler-a64.h"
Andreas Gampe277ccbd2014-11-03 21:36:10 -080037#pragma GCC diagnostic pop
Serban Constantinescued8dd492014-02-11 14:15:10 +000038
39namespace art {
40namespace arm64 {
41
Scott Wakeling97c72b72016-06-24 16:19:36 +010042#define MEM_OP(...) vixl::aarch64::MemOperand(__VA_ARGS__)
Serban Constantinescued8dd492014-02-11 14:15:10 +000043
44enum LoadOperandType {
45 kLoadSignedByte,
46 kLoadUnsignedByte,
47 kLoadSignedHalfword,
48 kLoadUnsignedHalfword,
49 kLoadWord,
50 kLoadCoreWord,
51 kLoadSWord,
52 kLoadDWord
53};
54
55enum StoreOperandType {
56 kStoreByte,
57 kStoreHalfword,
58 kStoreWord,
59 kStoreCoreWord,
60 kStoreSWord,
61 kStoreDWord
62};
63
Andreas Gampedcf30142016-08-08 16:06:34 -070064class Arm64Assembler FINAL : public Assembler {
Serban Constantinescued8dd492014-02-11 14:15:10 +000065 public:
Andreas Gampedcf30142016-08-08 16:06:34 -070066 explicit Arm64Assembler(ArenaAllocator* arena) : Assembler(arena) {}
Serban Constantinescued8dd492014-02-11 14:15:10 +000067
Alexandre Rames087930f2016-08-02 13:45:28 +010068 virtual ~Arm64Assembler() {}
69
70 vixl::aarch64::MacroAssembler* GetVIXLAssembler() { return &vixl_masm_; }
Serban Constantinescued8dd492014-02-11 14:15:10 +000071
Vladimir Markocf93a5c2015-06-16 11:33:24 +000072 // Finalize the code.
73 void FinalizeCode() OVERRIDE;
Serban Constantinescued8dd492014-02-11 14:15:10 +000074
75 // Size of generated code.
Alexandre Rameseb7b7392015-06-19 14:47:01 +010076 size_t CodeSize() const OVERRIDE;
77 const uint8_t* CodeBufferBaseAddress() const OVERRIDE;
Serban Constantinescued8dd492014-02-11 14:15:10 +000078
79 // Copy instructions out of assembly buffer into the given region of memory.
80 void FinalizeInstructions(const MemoryRegion& region);
81
Andreas Gampedcf30142016-08-08 16:06:34 -070082 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs);
83
Scott Wakeling97c72b72016-06-24 16:19:36 +010084 void SpillRegisters(vixl::aarch64::CPURegList registers, int offset);
85 void UnspillRegisters(vixl::aarch64::CPURegList registers, int offset);
Zheng Xu69a50302015-04-14 20:04:41 +080086
Andreas Gampec6ee54e2014-03-24 16:45:44 -070087 // Jump to address (not setting link register)
88 void JumpTo(ManagedRegister m_base, Offset offs, ManagedRegister m_scratch);
89
Roland Levillain4d027112015-07-01 15:41:14 +010090 //
91 // Heap poisoning.
92 //
93
94 // Poison a heap reference contained in `reg`.
Scott Wakeling97c72b72016-06-24 16:19:36 +010095 void PoisonHeapReference(vixl::aarch64::Register reg);
Roland Levillain4d027112015-07-01 15:41:14 +010096 // Unpoison a heap reference contained in `reg`.
Scott Wakeling97c72b72016-06-24 16:19:36 +010097 void UnpoisonHeapReference(vixl::aarch64::Register reg);
Roland Levillain4d027112015-07-01 15:41:14 +010098 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
Scott Wakeling97c72b72016-06-24 16:19:36 +010099 void MaybeUnpoisonHeapReference(vixl::aarch64::Register reg);
Roland Levillain4d027112015-07-01 15:41:14 +0100100
Andreas Gampe85b62f22015-09-09 13:15:38 -0700101 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 Wakeling97c72b72016-06-24 16:19:36 +0100108 static vixl::aarch64::Register reg_x(int code) {
Alexandre Rames37c92df2014-10-17 14:35:27 +0100109 CHECK(code < kNumberOfXRegisters) << code;
Serban Constantinescued8dd492014-02-11 14:15:10 +0000110 if (code == SP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100111 return vixl::aarch64::sp;
Serban Constantinescu15523732014-04-02 13:18:05 +0100112 } else if (code == XZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100113 return vixl::aarch64::xzr;
Serban Constantinescued8dd492014-02-11 14:15:10 +0000114 }
Scott Wakeling97c72b72016-06-24 16:19:36 +0100115 return vixl::aarch64::Register::GetXRegFromCode(code);
Serban Constantinescued8dd492014-02-11 14:15:10 +0000116 }
117
Scott Wakeling97c72b72016-06-24 16:19:36 +0100118 static vixl::aarch64::Register reg_w(int code) {
Alexandre Rames37c92df2014-10-17 14:35:27 +0100119 CHECK(code < kNumberOfWRegisters) << code;
Alexandre Ramesa304f972014-10-17 14:35:27 +0100120 if (code == WSP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100121 return vixl::aarch64::wsp;
Alexandre Ramesa304f972014-10-17 14:35:27 +0100122 } else if (code == WZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100123 return vixl::aarch64::wzr;
Alexandre Ramesa304f972014-10-17 14:35:27 +0100124 }
Scott Wakeling97c72b72016-06-24 16:19:36 +0100125 return vixl::aarch64::Register::GetWRegFromCode(code);
Serban Constantinescued8dd492014-02-11 14:15:10 +0000126 }
127
Scott Wakeling97c72b72016-06-24 16:19:36 +0100128 static vixl::aarch64::FPRegister reg_d(int code) {
129 return vixl::aarch64::FPRegister::GetDRegFromCode(code);
Serban Constantinescued8dd492014-02-11 14:15:10 +0000130 }
131
Scott Wakeling97c72b72016-06-24 16:19:36 +0100132 static vixl::aarch64::FPRegister reg_s(int code) {
133 return vixl::aarch64::FPRegister::GetSRegFromCode(code);
Serban Constantinescued8dd492014-02-11 14:15:10 +0000134 }
135
Andreas Gampedcf30142016-08-08 16:06:34 -0700136 private:
Alexandre Rames087930f2016-08-02 13:45:28 +0100137 // VIXL assembler.
138 vixl::aarch64::MacroAssembler vixl_masm_;
Alexandre Rames5319def2014-10-23 10:03:10 +0100139
Serban Constantinescu15523732014-04-02 13:18:05 +0100140 // Used for testing.
141 friend class Arm64ManagedRegister_VixlRegisters_Test;
Serban Constantinescued8dd492014-02-11 14:15:10 +0000142};
143
Serban Constantinescued8dd492014-02-11 14:15:10 +0000144} // namespace arm64
145} // namespace art
146
147#endif // ART_COMPILER_UTILS_ARM64_ASSEMBLER_ARM64_H_