blob: 64d76b881db661b654783f8db6f1e7ab6b1b36a6 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 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 */
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070016
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_COMPILER_UTILS_ASSEMBLER_H_
18#define ART_COMPILER_UTILS_ASSEMBLER_H_
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070019
Ian Rogers2c8f6532011-09-02 17:16:34 -070020#include <vector>
21
Ian Rogersd582fa42014-11-05 23:46:43 -080022#include "arch/instruction_set.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080023#include "base/logging.h"
Elliott Hughes76160052012-12-12 16:31:20 -080024#include "base/macros.h"
Ian Rogers166db042013-07-26 12:05:57 -070025#include "arm/constants_arm.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070026#include "managed_register.h"
27#include "memory_region.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080028#include "mips/constants_mips.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070029#include "offsets.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080030#include "x86/constants_x86.h"
31#include "x86_64/constants_x86_64.h"
David Srbeckydd973932015-04-07 20:29:48 +010032#include "dwarf/debug_frame_opcode_writer.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070033
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070034namespace art {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070035
36class Assembler;
37class AssemblerBuffer;
38class AssemblerFixup;
39
Ian Rogers2c8f6532011-09-02 17:16:34 -070040namespace arm {
41 class ArmAssembler;
Dave Allison65fcc2c2014-04-28 13:45:27 -070042 class Arm32Assembler;
43 class Thumb2Assembler;
Ian Rogers2c8f6532011-09-02 17:16:34 -070044}
Stuart Monteithb95a5342014-03-12 13:32:32 +000045namespace arm64 {
46 class Arm64Assembler;
47}
jeffhao7fbee072012-08-24 17:56:54 -070048namespace mips {
49 class MipsAssembler;
50}
Andreas Gampe57b34292015-01-14 15:45:59 -080051namespace mips64 {
52 class Mips64Assembler;
53}
Ian Rogers2c8f6532011-09-02 17:16:34 -070054namespace x86 {
55 class X86Assembler;
Mark Mendell73f455e2015-08-21 09:30:05 -040056 class NearLabel;
Ian Rogers2c8f6532011-09-02 17:16:34 -070057}
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070058namespace x86_64 {
59 class X86_64Assembler;
Mark Mendell73f455e2015-08-21 09:30:05 -040060 class NearLabel;
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070061}
Ian Rogers2c8f6532011-09-02 17:16:34 -070062
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000063class ExternalLabel {
64 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -080065 ExternalLabel(const char* name_in, uintptr_t address_in)
66 : name_(name_in), address_(address_in) {
67 DCHECK(name_in != nullptr);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000068 }
69
70 const char* name() const { return name_; }
Ian Rogers13735952014-10-08 12:43:28 -070071 uintptr_t address() const {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000072 return address_;
73 }
74
75 private:
76 const char* name_;
Ian Rogers13735952014-10-08 12:43:28 -070077 const uintptr_t address_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000078};
79
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070080class Label {
81 public:
82 Label() : position_(0) {}
83
84 ~Label() {
85 // Assert if label is being destroyed with unresolved branches pending.
86 CHECK(!IsLinked());
87 }
88
89 // Returns the position for bound and linked labels. Cannot be used
90 // for unused labels.
91 int Position() const {
92 CHECK(!IsUnused());
Ian Rogers13735952014-10-08 12:43:28 -070093 return IsBound() ? -position_ - sizeof(void*) : position_ - sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070094 }
95
96 int LinkPosition() const {
97 CHECK(IsLinked());
Ian Rogers13735952014-10-08 12:43:28 -070098 return position_ - sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070099 }
100
101 bool IsBound() const { return position_ < 0; }
102 bool IsUnused() const { return position_ == 0; }
103 bool IsLinked() const { return position_ > 0; }
104
105 private:
106 int position_;
107
108 void Reinitialize() {
109 position_ = 0;
110 }
111
112 void BindTo(int position) {
113 CHECK(!IsBound());
Ian Rogers13735952014-10-08 12:43:28 -0700114 position_ = -position - sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700115 CHECK(IsBound());
116 }
117
118 void LinkTo(int position) {
119 CHECK(!IsBound());
Ian Rogers13735952014-10-08 12:43:28 -0700120 position_ = position + sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700121 CHECK(IsLinked());
122 }
123
Ian Rogers2c8f6532011-09-02 17:16:34 -0700124 friend class arm::ArmAssembler;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700125 friend class arm::Arm32Assembler;
126 friend class arm::Thumb2Assembler;
Alexandre Rames5319def2014-10-23 10:03:10 +0100127 friend class arm64::Arm64Assembler;
jeffhao7fbee072012-08-24 17:56:54 -0700128 friend class mips::MipsAssembler;
Andreas Gampe57b34292015-01-14 15:45:59 -0800129 friend class mips64::Mips64Assembler;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700130 friend class x86::X86Assembler;
Mark Mendell73f455e2015-08-21 09:30:05 -0400131 friend class x86::NearLabel;
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700132 friend class x86_64::X86_64Assembler;
Mark Mendell73f455e2015-08-21 09:30:05 -0400133 friend class x86_64::NearLabel;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700134
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700135 DISALLOW_COPY_AND_ASSIGN(Label);
136};
137
138
139// Assembler fixups are positions in generated code that require processing
140// after the code has been copied to executable memory. This includes building
141// relocation information.
142class AssemblerFixup {
143 public:
144 virtual void Process(const MemoryRegion& region, int position) = 0;
145 virtual ~AssemblerFixup() {}
146
147 private:
148 AssemblerFixup* previous_;
149 int position_;
150
151 AssemblerFixup* previous() const { return previous_; }
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800152 void set_previous(AssemblerFixup* previous_in) { previous_ = previous_in; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700153
154 int position() const { return position_; }
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800155 void set_position(int position_in) { position_ = position_in; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700156
157 friend class AssemblerBuffer;
158};
159
Ian Rogers45a76cb2011-07-21 22:00:15 -0700160// Parent of all queued slow paths, emitted during finalization
161class SlowPath {
162 public:
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700163 SlowPath() : next_(nullptr) {}
Ian Rogers45a76cb2011-07-21 22:00:15 -0700164 virtual ~SlowPath() {}
165
166 Label* Continuation() { return &continuation_; }
167 Label* Entry() { return &entry_; }
168 // Generate code for slow path
169 virtual void Emit(Assembler *sp_asm) = 0;
170
171 protected:
172 // Entry branched to by fast path
173 Label entry_;
174 // Optional continuation that is branched to at the end of the slow path
175 Label continuation_;
176 // Next in linked list of slow paths
177 SlowPath *next_;
178
Mathieu Chartier02e25112013-08-14 16:14:24 -0700179 private:
Ian Rogers45a76cb2011-07-21 22:00:15 -0700180 friend class AssemblerBuffer;
181 DISALLOW_COPY_AND_ASSIGN(SlowPath);
182};
183
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700184class AssemblerBuffer {
185 public:
186 AssemblerBuffer();
187 ~AssemblerBuffer();
188
189 // Basic support for emitting, loading, and storing.
190 template<typename T> void Emit(T value) {
191 CHECK(HasEnsuredCapacity());
192 *reinterpret_cast<T*>(cursor_) = value;
193 cursor_ += sizeof(T);
194 }
195
196 template<typename T> T Load(size_t position) {
197 CHECK_LE(position, Size() - static_cast<int>(sizeof(T)));
198 return *reinterpret_cast<T*>(contents_ + position);
199 }
200
201 template<typename T> void Store(size_t position, T value) {
202 CHECK_LE(position, Size() - static_cast<int>(sizeof(T)));
203 *reinterpret_cast<T*>(contents_ + position) = value;
204 }
205
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000206 void Resize(size_t new_size) {
207 if (new_size > Capacity()) {
208 ExtendCapacity(new_size);
209 }
210 cursor_ = contents_ + new_size;
211 }
212
213 void Move(size_t newposition, size_t oldposition, size_t size) {
214 // Move a chunk of the buffer from oldposition to newposition.
215 DCHECK_LE(oldposition + size, Size());
216 DCHECK_LE(newposition + size, Size());
217 memmove(contents_ + newposition, contents_ + oldposition, size);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700218 }
219
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700220 // Emit a fixup at the current location.
221 void EmitFixup(AssemblerFixup* fixup) {
222 fixup->set_previous(fixup_);
223 fixup->set_position(Size());
224 fixup_ = fixup;
225 }
226
Ian Rogers45a76cb2011-07-21 22:00:15 -0700227 void EnqueueSlowPath(SlowPath* slowpath) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700228 if (slow_path_ == nullptr) {
Ian Rogers45a76cb2011-07-21 22:00:15 -0700229 slow_path_ = slowpath;
230 } else {
231 SlowPath* cur = slow_path_;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700232 for ( ; cur->next_ != nullptr ; cur = cur->next_) {}
Ian Rogers45a76cb2011-07-21 22:00:15 -0700233 cur->next_ = slowpath;
234 }
235 }
236
237 void EmitSlowPaths(Assembler* sp_asm) {
238 SlowPath* cur = slow_path_;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700239 SlowPath* next = nullptr;
240 slow_path_ = nullptr;
241 for ( ; cur != nullptr ; cur = next) {
Ian Rogers45a76cb2011-07-21 22:00:15 -0700242 cur->Emit(sp_asm);
243 next = cur->next_;
244 delete cur;
245 }
246 }
247
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700248 // Get the size of the emitted code.
249 size_t Size() const {
250 CHECK_GE(cursor_, contents_);
251 return cursor_ - contents_;
252 }
253
Ian Rogers13735952014-10-08 12:43:28 -0700254 uint8_t* contents() const { return contents_; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700255
256 // Copy the assembled instructions into the specified memory block
257 // and apply all fixups.
258 void FinalizeInstructions(const MemoryRegion& region);
259
260 // To emit an instruction to the assembler buffer, the EnsureCapacity helper
261 // must be used to guarantee that the underlying data area is big enough to
262 // hold the emitted instruction. Usage:
263 //
264 // AssemblerBuffer buffer;
265 // AssemblerBuffer::EnsureCapacity ensured(&buffer);
266 // ... emit bytes for single instruction ...
267
Elliott Hughes31f1f4f2012-03-12 13:57:36 -0700268#ifndef NDEBUG
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700269
270 class EnsureCapacity {
271 public:
272 explicit EnsureCapacity(AssemblerBuffer* buffer) {
Elliott Hughes31f1f4f2012-03-12 13:57:36 -0700273 if (buffer->cursor() >= buffer->limit()) {
274 buffer->ExtendCapacity();
275 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700276 // In debug mode, we save the assembler buffer along with the gap
277 // size before we start emitting to the buffer. This allows us to
278 // check that any single generated instruction doesn't overflow the
279 // limit implied by the minimum gap size.
280 buffer_ = buffer;
281 gap_ = ComputeGap();
282 // Make sure that extending the capacity leaves a big enough gap
283 // for any kind of instruction.
284 CHECK_GE(gap_, kMinimumGap);
285 // Mark the buffer as having ensured the capacity.
286 CHECK(!buffer->HasEnsuredCapacity()); // Cannot nest.
287 buffer->has_ensured_capacity_ = true;
288 }
289
290 ~EnsureCapacity() {
291 // Unmark the buffer, so we cannot emit after this.
292 buffer_->has_ensured_capacity_ = false;
293 // Make sure the generated instruction doesn't take up more
294 // space than the minimum gap.
295 int delta = gap_ - ComputeGap();
Ian Rogersb033c752011-07-20 12:22:35 -0700296 CHECK_LE(delta, kMinimumGap);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700297 }
298
299 private:
300 AssemblerBuffer* buffer_;
301 int gap_;
302
303 int ComputeGap() { return buffer_->Capacity() - buffer_->Size(); }
304 };
305
306 bool has_ensured_capacity_;
307 bool HasEnsuredCapacity() const { return has_ensured_capacity_; }
308
309#else
310
311 class EnsureCapacity {
312 public:
313 explicit EnsureCapacity(AssemblerBuffer* buffer) {
314 if (buffer->cursor() >= buffer->limit()) buffer->ExtendCapacity();
315 }
316 };
317
318 // When building the C++ tests, assertion code is enabled. To allow
319 // asserting that the user of the assembler buffer has ensured the
320 // capacity needed for emitting, we add a dummy method in non-debug mode.
321 bool HasEnsuredCapacity() const { return true; }
322
323#endif
324
325 // Returns the position in the instruction stream.
326 int GetPosition() { return cursor_ - contents_; }
327
328 private:
329 // The limit is set to kMinimumGap bytes before the end of the data area.
330 // This leaves enough space for the longest possible instruction and allows
331 // for a single, fast space check per instruction.
332 static const int kMinimumGap = 32;
333
Ian Rogers13735952014-10-08 12:43:28 -0700334 uint8_t* contents_;
335 uint8_t* cursor_;
336 uint8_t* limit_;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700337 AssemblerFixup* fixup_;
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800338#ifndef NDEBUG
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700339 bool fixups_processed_;
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800340#endif
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700341
Ian Rogers45a76cb2011-07-21 22:00:15 -0700342 // Head of linked list of slow paths
343 SlowPath* slow_path_;
344
Ian Rogers13735952014-10-08 12:43:28 -0700345 uint8_t* cursor() const { return cursor_; }
346 uint8_t* limit() const { return limit_; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700347 size_t Capacity() const {
348 CHECK_GE(limit_, contents_);
349 return (limit_ - contents_) + kMinimumGap;
350 }
351
352 // Process the fixup chain starting at the given fixup. The offset is
353 // non-zero for fixups in the body if the preamble is non-empty.
354 void ProcessFixups(const MemoryRegion& region);
355
356 // Compute the limit based on the data area and the capacity. See
357 // description of kMinimumGap for the reasoning behind the value.
Ian Rogers13735952014-10-08 12:43:28 -0700358 static uint8_t* ComputeLimit(uint8_t* data, size_t capacity) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700359 return data + capacity - kMinimumGap;
360 }
361
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000362 void ExtendCapacity(size_t min_capacity = 0u);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700363
364 friend class AssemblerFixup;
365};
366
David Srbeckydd973932015-04-07 20:29:48 +0100367// The purpose of this class is to ensure that we do not have to explicitly
368// call the AdvancePC method (which is good for convenience and correctness).
369class DebugFrameOpCodeWriterForAssembler FINAL
370 : public dwarf::DebugFrameOpCodeWriter<> {
371 public:
372 // This method is called the by the opcode writers.
373 virtual void ImplicitlyAdvancePC() FINAL;
374
375 explicit DebugFrameOpCodeWriterForAssembler(Assembler* buffer)
376 : dwarf::DebugFrameOpCodeWriter<>(),
377 assembler_(buffer) {
378 }
379
380 private:
381 Assembler* assembler_;
382};
383
Ian Rogers2c8f6532011-09-02 17:16:34 -0700384class Assembler {
385 public:
386 static Assembler* Create(InstructionSet instruction_set);
387
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000388 // Finalize the code; emit slow paths, fixup branches, add literal pool, etc.
389 virtual void FinalizeCode() { buffer_.EmitSlowPaths(this); }
Ian Rogers2c8f6532011-09-02 17:16:34 -0700390
391 // Size of generated code
Serban Constantinescued8dd492014-02-11 14:15:10 +0000392 virtual size_t CodeSize() const { return buffer_.Size(); }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100393 virtual const uint8_t* CodeBufferBaseAddress() const { return buffer_.contents(); }
Ian Rogers2c8f6532011-09-02 17:16:34 -0700394
395 // Copy instructions out of assembly buffer into the given region of memory
Serban Constantinescued8dd492014-02-11 14:15:10 +0000396 virtual void FinalizeInstructions(const MemoryRegion& region) {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700397 buffer_.FinalizeInstructions(region);
398 }
399
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000400 // TODO: Implement with disassembler.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700401 virtual void Comment(const char* format, ...) { UNUSED(format); }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000402
Ian Rogers2c8f6532011-09-02 17:16:34 -0700403 // Emit code that will create an activation on the stack
404 virtual void BuildFrame(size_t frame_size, ManagedRegister method_reg,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800405 const std::vector<ManagedRegister>& callee_save_regs,
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700406 const ManagedRegisterEntrySpills& entry_spills) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700407
408 // Emit code that will remove an activation from the stack
409 virtual void RemoveFrame(size_t frame_size,
Ian Rogersbdb03912011-09-14 00:55:44 -0700410 const std::vector<ManagedRegister>& callee_save_regs) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700411
412 virtual void IncreaseFrameSize(size_t adjust) = 0;
413 virtual void DecreaseFrameSize(size_t adjust) = 0;
414
415 // Store routines
416 virtual void Store(FrameOffset offs, ManagedRegister src, size_t size) = 0;
417 virtual void StoreRef(FrameOffset dest, ManagedRegister src) = 0;
418 virtual void StoreRawPtr(FrameOffset dest, ManagedRegister src) = 0;
419
420 virtual void StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
421 ManagedRegister scratch) = 0;
422
Ian Rogersdd7624d2014-03-14 17:43:00 -0700423 virtual void StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm,
424 ManagedRegister scratch);
425 virtual void StoreImmediateToThread64(ThreadOffset<8> dest, uint32_t imm,
426 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700427
Ian Rogersdd7624d2014-03-14 17:43:00 -0700428 virtual void StoreStackOffsetToThread32(ThreadOffset<4> thr_offs,
429 FrameOffset fr_offs,
430 ManagedRegister scratch);
431 virtual void StoreStackOffsetToThread64(ThreadOffset<8> thr_offs,
432 FrameOffset fr_offs,
433 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700434
Ian Rogersdd7624d2014-03-14 17:43:00 -0700435 virtual void StoreStackPointerToThread32(ThreadOffset<4> thr_offs);
436 virtual void StoreStackPointerToThread64(ThreadOffset<8> thr_offs);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700437
438 virtual void StoreSpanning(FrameOffset dest, ManagedRegister src,
439 FrameOffset in_off, ManagedRegister scratch) = 0;
440
441 // Load routines
442 virtual void Load(ManagedRegister dest, FrameOffset src, size_t size) = 0;
443
Ian Rogersdd7624d2014-03-14 17:43:00 -0700444 virtual void LoadFromThread32(ManagedRegister dest, ThreadOffset<4> src, size_t size);
445 virtual void LoadFromThread64(ManagedRegister dest, ThreadOffset<8> src, size_t size);
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700446
Mathieu Chartiere401d142015-04-22 13:56:20 -0700447 virtual void LoadRef(ManagedRegister dest, FrameOffset src) = 0;
Roland Levillain4d027112015-07-01 15:41:14 +0100448 // If unpoison_reference is true and kPoisonReference is true, then we negate the read reference.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700449 virtual void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +0100450 bool unpoison_reference) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700451
Ian Rogersdd7624d2014-03-14 17:43:00 -0700452 virtual void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700453
Ian Rogersdd7624d2014-03-14 17:43:00 -0700454 virtual void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset<4> offs);
455 virtual void LoadRawPtrFromThread64(ManagedRegister dest, ThreadOffset<8> offs);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700456
457 // Copying routines
Ian Rogersb5d09b22012-03-06 22:14:17 -0800458 virtual void Move(ManagedRegister dest, ManagedRegister src, size_t size) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700459
Ian Rogersdd7624d2014-03-14 17:43:00 -0700460 virtual void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset<4> thr_offs,
461 ManagedRegister scratch);
462 virtual void CopyRawPtrFromThread64(FrameOffset fr_offs, ThreadOffset<8> thr_offs,
463 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700464
Ian Rogersdd7624d2014-03-14 17:43:00 -0700465 virtual void CopyRawPtrToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs,
466 ManagedRegister scratch);
467 virtual void CopyRawPtrToThread64(ThreadOffset<8> thr_offs, FrameOffset fr_offs,
468 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700469
470 virtual void CopyRef(FrameOffset dest, FrameOffset src,
471 ManagedRegister scratch) = 0;
472
Elliott Hughesa09aea22012-01-06 18:58:27 -0800473 virtual void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700474
Ian Rogersdc51b792011-09-22 20:41:37 -0700475 virtual void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
476 ManagedRegister scratch, size_t size) = 0;
477
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700478 virtual void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
479 ManagedRegister scratch, size_t size) = 0;
480
Ian Rogersdc51b792011-09-22 20:41:37 -0700481 virtual void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset,
482 ManagedRegister scratch, size_t size) = 0;
483
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700484 virtual void Copy(ManagedRegister dest, Offset dest_offset,
485 ManagedRegister src, Offset src_offset,
486 ManagedRegister scratch, size_t size) = 0;
487
488 virtual void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
489 ManagedRegister scratch, size_t size) = 0;
Ian Rogersdc51b792011-09-22 20:41:37 -0700490
Ian Rogerse5de95b2011-09-18 20:31:38 -0700491 virtual void MemoryBarrier(ManagedRegister scratch) = 0;
492
jeffhao58136ca2012-05-24 13:40:11 -0700493 // Sign extension
494 virtual void SignExtend(ManagedRegister mreg, size_t size) = 0;
495
jeffhaocee4d0c2012-06-15 14:42:01 -0700496 // Zero extension
497 virtual void ZeroExtend(ManagedRegister mreg, size_t size) = 0;
498
Ian Rogers2c8f6532011-09-02 17:16:34 -0700499 // Exploit fast access in managed code to Thread::Current()
500 virtual void GetCurrentThread(ManagedRegister tr) = 0;
501 virtual void GetCurrentThread(FrameOffset dest_offset,
502 ManagedRegister scratch) = 0;
503
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700504 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700505 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700506 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700507 // null.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700508 virtual void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700509 ManagedRegister in_reg, bool null_allowed) = 0;
510
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700511 // Set up out_off to hold a Object** into the handle scope, or to be null if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700512 // value is null and null_allowed.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700513 virtual void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700514 ManagedRegister scratch, bool null_allowed) = 0;
515
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700516 // src holds a handle scope entry (Object**) load this into dst
517 virtual void LoadReferenceFromHandleScope(ManagedRegister dst,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700518 ManagedRegister src) = 0;
519
520 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
521 // know that src may not be null.
522 virtual void VerifyObject(ManagedRegister src, bool could_be_null) = 0;
523 virtual void VerifyObject(FrameOffset src, bool could_be_null) = 0;
524
525 // Call to address held at [base+offset]
526 virtual void Call(ManagedRegister base, Offset offset,
527 ManagedRegister scratch) = 0;
528 virtual void Call(FrameOffset base, Offset offset,
529 ManagedRegister scratch) = 0;
Ian Rogersdd7624d2014-03-14 17:43:00 -0700530 virtual void CallFromThread32(ThreadOffset<4> offset, ManagedRegister scratch);
531 virtual void CallFromThread64(ThreadOffset<8> offset, ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700532
Ian Rogers2c8f6532011-09-02 17:16:34 -0700533 // Generate code to check if Thread::Current()->exception_ is non-null
534 // and branch to a ExceptionSlowPath if it is.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700535 virtual void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700536
537 virtual ~Assembler() {}
538
David Srbeckydd973932015-04-07 20:29:48 +0100539 /**
540 * @brief Buffer of DWARF's Call Frame Information opcodes.
541 * @details It is used by debuggers and other tools to unwind the call stack.
542 */
543 DebugFrameOpCodeWriterForAssembler& cfi() { return cfi_; }
544
Ian Rogers2c8f6532011-09-02 17:16:34 -0700545 protected:
David Srbeckydd973932015-04-07 20:29:48 +0100546 Assembler() : buffer_(), cfi_(this) {}
Ian Rogers2c8f6532011-09-02 17:16:34 -0700547
548 AssemblerBuffer buffer_;
David Srbeckydd973932015-04-07 20:29:48 +0100549
550 DebugFrameOpCodeWriterForAssembler cfi_;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700551};
552
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700553} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700554
Ian Rogers166db042013-07-26 12:05:57 -0700555#endif // ART_COMPILER_UTILS_ASSEMBLER_H_