Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 16 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_UTILS_ASSEMBLER_H_ |
| 18 | #define ART_COMPILER_UTILS_ASSEMBLER_H_ |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 22 | #include "base/logging.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 23 | #include "base/macros.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 24 | #include "arm/constants_arm.h" |
| 25 | #include "mips/constants_mips.h" |
| 26 | #include "x86/constants_x86.h" |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 27 | #include "x86_64/constants_x86_64.h" |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 28 | #include "instruction_set.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 29 | #include "managed_register.h" |
| 30 | #include "memory_region.h" |
| 31 | #include "offsets.h" |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 32 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 33 | namespace art { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 34 | |
| 35 | class Assembler; |
| 36 | class AssemblerBuffer; |
| 37 | class AssemblerFixup; |
| 38 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 39 | namespace arm { |
| 40 | class ArmAssembler; |
| 41 | } |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 42 | namespace arm64 { |
| 43 | class Arm64Assembler; |
| 44 | } |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 45 | namespace mips { |
| 46 | class MipsAssembler; |
| 47 | } |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 48 | namespace x86 { |
| 49 | class X86Assembler; |
| 50 | } |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 51 | namespace x86_64 { |
| 52 | class X86_64Assembler; |
| 53 | } |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 54 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 55 | class ExternalLabel { |
| 56 | public: |
| 57 | ExternalLabel(const char* name, uword address) |
| 58 | : name_(name), address_(address) { |
| 59 | DCHECK(name != nullptr); |
| 60 | } |
| 61 | |
| 62 | const char* name() const { return name_; } |
| 63 | uword address() const { |
| 64 | return address_; |
| 65 | } |
| 66 | |
| 67 | private: |
| 68 | const char* name_; |
| 69 | const uword address_; |
| 70 | }; |
| 71 | |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 72 | class Label { |
| 73 | public: |
| 74 | Label() : position_(0) {} |
| 75 | |
| 76 | ~Label() { |
| 77 | // Assert if label is being destroyed with unresolved branches pending. |
| 78 | CHECK(!IsLinked()); |
| 79 | } |
| 80 | |
| 81 | // Returns the position for bound and linked labels. Cannot be used |
| 82 | // for unused labels. |
| 83 | int Position() const { |
| 84 | CHECK(!IsUnused()); |
| 85 | return IsBound() ? -position_ - kPointerSize : position_ - kPointerSize; |
| 86 | } |
| 87 | |
| 88 | int LinkPosition() const { |
| 89 | CHECK(IsLinked()); |
| 90 | return position_ - kWordSize; |
| 91 | } |
| 92 | |
| 93 | bool IsBound() const { return position_ < 0; } |
| 94 | bool IsUnused() const { return position_ == 0; } |
| 95 | bool IsLinked() const { return position_ > 0; } |
| 96 | |
| 97 | private: |
| 98 | int position_; |
| 99 | |
| 100 | void Reinitialize() { |
| 101 | position_ = 0; |
| 102 | } |
| 103 | |
| 104 | void BindTo(int position) { |
| 105 | CHECK(!IsBound()); |
| 106 | position_ = -position - kPointerSize; |
| 107 | CHECK(IsBound()); |
| 108 | } |
| 109 | |
| 110 | void LinkTo(int position) { |
| 111 | CHECK(!IsBound()); |
| 112 | position_ = position + kPointerSize; |
| 113 | CHECK(IsLinked()); |
| 114 | } |
| 115 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 116 | friend class arm::ArmAssembler; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 117 | friend class mips::MipsAssembler; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 118 | friend class x86::X86Assembler; |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 119 | friend class x86_64::X86_64Assembler; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 120 | |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(Label); |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | // Assembler fixups are positions in generated code that require processing |
| 126 | // after the code has been copied to executable memory. This includes building |
| 127 | // relocation information. |
| 128 | class AssemblerFixup { |
| 129 | public: |
| 130 | virtual void Process(const MemoryRegion& region, int position) = 0; |
| 131 | virtual ~AssemblerFixup() {} |
| 132 | |
| 133 | private: |
| 134 | AssemblerFixup* previous_; |
| 135 | int position_; |
| 136 | |
| 137 | AssemblerFixup* previous() const { return previous_; } |
| 138 | void set_previous(AssemblerFixup* previous) { previous_ = previous; } |
| 139 | |
| 140 | int position() const { return position_; } |
| 141 | void set_position(int position) { position_ = position; } |
| 142 | |
| 143 | friend class AssemblerBuffer; |
| 144 | }; |
| 145 | |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 146 | // Parent of all queued slow paths, emitted during finalization |
| 147 | class SlowPath { |
| 148 | public: |
| 149 | SlowPath() : next_(NULL) {} |
| 150 | virtual ~SlowPath() {} |
| 151 | |
| 152 | Label* Continuation() { return &continuation_; } |
| 153 | Label* Entry() { return &entry_; } |
| 154 | // Generate code for slow path |
| 155 | virtual void Emit(Assembler *sp_asm) = 0; |
| 156 | |
| 157 | protected: |
| 158 | // Entry branched to by fast path |
| 159 | Label entry_; |
| 160 | // Optional continuation that is branched to at the end of the slow path |
| 161 | Label continuation_; |
| 162 | // Next in linked list of slow paths |
| 163 | SlowPath *next_; |
| 164 | |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 165 | private: |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 166 | friend class AssemblerBuffer; |
| 167 | DISALLOW_COPY_AND_ASSIGN(SlowPath); |
| 168 | }; |
| 169 | |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 170 | class AssemblerBuffer { |
| 171 | public: |
| 172 | AssemblerBuffer(); |
| 173 | ~AssemblerBuffer(); |
| 174 | |
| 175 | // Basic support for emitting, loading, and storing. |
| 176 | template<typename T> void Emit(T value) { |
| 177 | CHECK(HasEnsuredCapacity()); |
| 178 | *reinterpret_cast<T*>(cursor_) = value; |
| 179 | cursor_ += sizeof(T); |
| 180 | } |
| 181 | |
| 182 | template<typename T> T Load(size_t position) { |
| 183 | CHECK_LE(position, Size() - static_cast<int>(sizeof(T))); |
| 184 | return *reinterpret_cast<T*>(contents_ + position); |
| 185 | } |
| 186 | |
| 187 | template<typename T> void Store(size_t position, T value) { |
| 188 | CHECK_LE(position, Size() - static_cast<int>(sizeof(T))); |
| 189 | *reinterpret_cast<T*>(contents_ + position) = value; |
| 190 | } |
| 191 | |
| 192 | // Emit a fixup at the current location. |
| 193 | void EmitFixup(AssemblerFixup* fixup) { |
| 194 | fixup->set_previous(fixup_); |
| 195 | fixup->set_position(Size()); |
| 196 | fixup_ = fixup; |
| 197 | } |
| 198 | |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 199 | void EnqueueSlowPath(SlowPath* slowpath) { |
| 200 | if (slow_path_ == NULL) { |
| 201 | slow_path_ = slowpath; |
| 202 | } else { |
| 203 | SlowPath* cur = slow_path_; |
| 204 | for ( ; cur->next_ != NULL ; cur = cur->next_) {} |
| 205 | cur->next_ = slowpath; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void EmitSlowPaths(Assembler* sp_asm) { |
| 210 | SlowPath* cur = slow_path_; |
| 211 | SlowPath* next = NULL; |
| 212 | slow_path_ = NULL; |
| 213 | for ( ; cur != NULL ; cur = next) { |
| 214 | cur->Emit(sp_asm); |
| 215 | next = cur->next_; |
| 216 | delete cur; |
| 217 | } |
| 218 | } |
| 219 | |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 220 | // Get the size of the emitted code. |
| 221 | size_t Size() const { |
| 222 | CHECK_GE(cursor_, contents_); |
| 223 | return cursor_ - contents_; |
| 224 | } |
| 225 | |
| 226 | byte* contents() const { return contents_; } |
| 227 | |
| 228 | // Copy the assembled instructions into the specified memory block |
| 229 | // and apply all fixups. |
| 230 | void FinalizeInstructions(const MemoryRegion& region); |
| 231 | |
| 232 | // To emit an instruction to the assembler buffer, the EnsureCapacity helper |
| 233 | // must be used to guarantee that the underlying data area is big enough to |
| 234 | // hold the emitted instruction. Usage: |
| 235 | // |
| 236 | // AssemblerBuffer buffer; |
| 237 | // AssemblerBuffer::EnsureCapacity ensured(&buffer); |
| 238 | // ... emit bytes for single instruction ... |
| 239 | |
Elliott Hughes | 31f1f4f | 2012-03-12 13:57:36 -0700 | [diff] [blame] | 240 | #ifndef NDEBUG |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 241 | |
| 242 | class EnsureCapacity { |
| 243 | public: |
| 244 | explicit EnsureCapacity(AssemblerBuffer* buffer) { |
Elliott Hughes | 31f1f4f | 2012-03-12 13:57:36 -0700 | [diff] [blame] | 245 | if (buffer->cursor() >= buffer->limit()) { |
| 246 | buffer->ExtendCapacity(); |
| 247 | } |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 248 | // In debug mode, we save the assembler buffer along with the gap |
| 249 | // size before we start emitting to the buffer. This allows us to |
| 250 | // check that any single generated instruction doesn't overflow the |
| 251 | // limit implied by the minimum gap size. |
| 252 | buffer_ = buffer; |
| 253 | gap_ = ComputeGap(); |
| 254 | // Make sure that extending the capacity leaves a big enough gap |
| 255 | // for any kind of instruction. |
| 256 | CHECK_GE(gap_, kMinimumGap); |
| 257 | // Mark the buffer as having ensured the capacity. |
| 258 | CHECK(!buffer->HasEnsuredCapacity()); // Cannot nest. |
| 259 | buffer->has_ensured_capacity_ = true; |
| 260 | } |
| 261 | |
| 262 | ~EnsureCapacity() { |
| 263 | // Unmark the buffer, so we cannot emit after this. |
| 264 | buffer_->has_ensured_capacity_ = false; |
| 265 | // Make sure the generated instruction doesn't take up more |
| 266 | // space than the minimum gap. |
| 267 | int delta = gap_ - ComputeGap(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 268 | CHECK_LE(delta, kMinimumGap); |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | private: |
| 272 | AssemblerBuffer* buffer_; |
| 273 | int gap_; |
| 274 | |
| 275 | int ComputeGap() { return buffer_->Capacity() - buffer_->Size(); } |
| 276 | }; |
| 277 | |
| 278 | bool has_ensured_capacity_; |
| 279 | bool HasEnsuredCapacity() const { return has_ensured_capacity_; } |
| 280 | |
| 281 | #else |
| 282 | |
| 283 | class EnsureCapacity { |
| 284 | public: |
| 285 | explicit EnsureCapacity(AssemblerBuffer* buffer) { |
| 286 | if (buffer->cursor() >= buffer->limit()) buffer->ExtendCapacity(); |
| 287 | } |
| 288 | }; |
| 289 | |
| 290 | // When building the C++ tests, assertion code is enabled. To allow |
| 291 | // asserting that the user of the assembler buffer has ensured the |
| 292 | // capacity needed for emitting, we add a dummy method in non-debug mode. |
| 293 | bool HasEnsuredCapacity() const { return true; } |
| 294 | |
| 295 | #endif |
| 296 | |
| 297 | // Returns the position in the instruction stream. |
| 298 | int GetPosition() { return cursor_ - contents_; } |
| 299 | |
| 300 | private: |
| 301 | // The limit is set to kMinimumGap bytes before the end of the data area. |
| 302 | // This leaves enough space for the longest possible instruction and allows |
| 303 | // for a single, fast space check per instruction. |
| 304 | static const int kMinimumGap = 32; |
| 305 | |
| 306 | byte* contents_; |
| 307 | byte* cursor_; |
| 308 | byte* limit_; |
| 309 | AssemblerFixup* fixup_; |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 310 | #ifndef NDEBUG |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 311 | bool fixups_processed_; |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 312 | #endif |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 313 | |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 314 | // Head of linked list of slow paths |
| 315 | SlowPath* slow_path_; |
| 316 | |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 317 | byte* cursor() const { return cursor_; } |
| 318 | byte* limit() const { return limit_; } |
| 319 | size_t Capacity() const { |
| 320 | CHECK_GE(limit_, contents_); |
| 321 | return (limit_ - contents_) + kMinimumGap; |
| 322 | } |
| 323 | |
| 324 | // Process the fixup chain starting at the given fixup. The offset is |
| 325 | // non-zero for fixups in the body if the preamble is non-empty. |
| 326 | void ProcessFixups(const MemoryRegion& region); |
| 327 | |
| 328 | // Compute the limit based on the data area and the capacity. See |
| 329 | // description of kMinimumGap for the reasoning behind the value. |
| 330 | static byte* ComputeLimit(byte* data, size_t capacity) { |
| 331 | return data + capacity - kMinimumGap; |
| 332 | } |
| 333 | |
| 334 | void ExtendCapacity(); |
| 335 | |
| 336 | friend class AssemblerFixup; |
| 337 | }; |
| 338 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 339 | class Assembler { |
| 340 | public: |
| 341 | static Assembler* Create(InstructionSet instruction_set); |
| 342 | |
| 343 | // Emit slow paths queued during assembly |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 344 | virtual void EmitSlowPaths() { buffer_.EmitSlowPaths(this); } |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 345 | |
| 346 | // Size of generated code |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 347 | virtual size_t CodeSize() const { return buffer_.Size(); } |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 348 | |
| 349 | // Copy instructions out of assembly buffer into the given region of memory |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 350 | virtual void FinalizeInstructions(const MemoryRegion& region) { |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 351 | buffer_.FinalizeInstructions(region); |
| 352 | } |
| 353 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 354 | // TODO: Implement with disassembler. |
| 355 | virtual void Comment(const char* format, ...) { } |
| 356 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 357 | // Emit code that will create an activation on the stack |
| 358 | virtual void BuildFrame(size_t frame_size, ManagedRegister method_reg, |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 359 | const std::vector<ManagedRegister>& callee_save_regs, |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 360 | const ManagedRegisterEntrySpills& entry_spills) = 0; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 361 | |
| 362 | // Emit code that will remove an activation from the stack |
| 363 | virtual void RemoveFrame(size_t frame_size, |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 364 | const std::vector<ManagedRegister>& callee_save_regs) = 0; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 365 | |
| 366 | virtual void IncreaseFrameSize(size_t adjust) = 0; |
| 367 | virtual void DecreaseFrameSize(size_t adjust) = 0; |
| 368 | |
| 369 | // Store routines |
| 370 | virtual void Store(FrameOffset offs, ManagedRegister src, size_t size) = 0; |
| 371 | virtual void StoreRef(FrameOffset dest, ManagedRegister src) = 0; |
| 372 | virtual void StoreRawPtr(FrameOffset dest, ManagedRegister src) = 0; |
| 373 | |
| 374 | virtual void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, |
| 375 | ManagedRegister scratch) = 0; |
| 376 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 377 | virtual void StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm, |
| 378 | ManagedRegister scratch); |
| 379 | virtual void StoreImmediateToThread64(ThreadOffset<8> dest, uint32_t imm, |
| 380 | ManagedRegister scratch); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 381 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 382 | virtual void StoreStackOffsetToThread32(ThreadOffset<4> thr_offs, |
| 383 | FrameOffset fr_offs, |
| 384 | ManagedRegister scratch); |
| 385 | virtual void StoreStackOffsetToThread64(ThreadOffset<8> thr_offs, |
| 386 | FrameOffset fr_offs, |
| 387 | ManagedRegister scratch); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 388 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 389 | virtual void StoreStackPointerToThread32(ThreadOffset<4> thr_offs); |
| 390 | virtual void StoreStackPointerToThread64(ThreadOffset<8> thr_offs); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 391 | |
| 392 | virtual void StoreSpanning(FrameOffset dest, ManagedRegister src, |
| 393 | FrameOffset in_off, ManagedRegister scratch) = 0; |
| 394 | |
| 395 | // Load routines |
| 396 | virtual void Load(ManagedRegister dest, FrameOffset src, size_t size) = 0; |
| 397 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 398 | virtual void LoadFromThread32(ManagedRegister dest, ThreadOffset<4> src, size_t size); |
| 399 | virtual void LoadFromThread64(ManagedRegister dest, ThreadOffset<8> src, size_t size); |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 400 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 401 | virtual void LoadRef(ManagedRegister dest, FrameOffset src) = 0; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 402 | virtual void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs) = 0; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 403 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 404 | virtual void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) = 0; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 405 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 406 | virtual void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset<4> offs); |
| 407 | virtual void LoadRawPtrFromThread64(ManagedRegister dest, ThreadOffset<8> offs); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 408 | |
| 409 | // Copying routines |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 410 | virtual void Move(ManagedRegister dest, ManagedRegister src, size_t size) = 0; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 411 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 412 | virtual void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset<4> thr_offs, |
| 413 | ManagedRegister scratch); |
| 414 | virtual void CopyRawPtrFromThread64(FrameOffset fr_offs, ThreadOffset<8> thr_offs, |
| 415 | ManagedRegister scratch); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 416 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 417 | virtual void CopyRawPtrToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs, |
| 418 | ManagedRegister scratch); |
| 419 | virtual void CopyRawPtrToThread64(ThreadOffset<8> thr_offs, FrameOffset fr_offs, |
| 420 | ManagedRegister scratch); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 421 | |
| 422 | virtual void CopyRef(FrameOffset dest, FrameOffset src, |
| 423 | ManagedRegister scratch) = 0; |
| 424 | |
Elliott Hughes | a09aea2 | 2012-01-06 18:58:27 -0800 | [diff] [blame] | 425 | virtual void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) = 0; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 426 | |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 427 | virtual void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, |
| 428 | ManagedRegister scratch, size_t size) = 0; |
| 429 | |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 430 | virtual void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, |
| 431 | ManagedRegister scratch, size_t size) = 0; |
| 432 | |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 433 | virtual void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, |
| 434 | ManagedRegister scratch, size_t size) = 0; |
| 435 | |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 436 | virtual void Copy(ManagedRegister dest, Offset dest_offset, |
| 437 | ManagedRegister src, Offset src_offset, |
| 438 | ManagedRegister scratch, size_t size) = 0; |
| 439 | |
| 440 | virtual void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset, |
| 441 | ManagedRegister scratch, size_t size) = 0; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 442 | |
Ian Rogers | e5de95b | 2011-09-18 20:31:38 -0700 | [diff] [blame] | 443 | virtual void MemoryBarrier(ManagedRegister scratch) = 0; |
| 444 | |
jeffhao | 58136ca | 2012-05-24 13:40:11 -0700 | [diff] [blame] | 445 | // Sign extension |
| 446 | virtual void SignExtend(ManagedRegister mreg, size_t size) = 0; |
| 447 | |
jeffhao | cee4d0c | 2012-06-15 14:42:01 -0700 | [diff] [blame] | 448 | // Zero extension |
| 449 | virtual void ZeroExtend(ManagedRegister mreg, size_t size) = 0; |
| 450 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 451 | // Exploit fast access in managed code to Thread::Current() |
| 452 | virtual void GetCurrentThread(ManagedRegister tr) = 0; |
| 453 | virtual void GetCurrentThread(FrameOffset dest_offset, |
| 454 | ManagedRegister scratch) = 0; |
| 455 | |
| 456 | // Set up out_reg to hold a Object** into the SIRT, or to be NULL if the |
| 457 | // value is null and null_allowed. in_reg holds a possibly stale reference |
| 458 | // that can be used to avoid loading the SIRT entry to see if the value is |
| 459 | // NULL. |
| 460 | virtual void CreateSirtEntry(ManagedRegister out_reg, FrameOffset sirt_offset, |
| 461 | ManagedRegister in_reg, bool null_allowed) = 0; |
| 462 | |
| 463 | // Set up out_off to hold a Object** into the SIRT, or to be NULL if the |
| 464 | // value is null and null_allowed. |
| 465 | virtual void CreateSirtEntry(FrameOffset out_off, FrameOffset sirt_offset, |
| 466 | ManagedRegister scratch, bool null_allowed) = 0; |
| 467 | |
| 468 | // src holds a SIRT entry (Object**) load this into dst |
| 469 | virtual void LoadReferenceFromSirt(ManagedRegister dst, |
| 470 | ManagedRegister src) = 0; |
| 471 | |
| 472 | // Heap::VerifyObject on src. In some cases (such as a reference to this) we |
| 473 | // know that src may not be null. |
| 474 | virtual void VerifyObject(ManagedRegister src, bool could_be_null) = 0; |
| 475 | virtual void VerifyObject(FrameOffset src, bool could_be_null) = 0; |
| 476 | |
| 477 | // Call to address held at [base+offset] |
| 478 | virtual void Call(ManagedRegister base, Offset offset, |
| 479 | ManagedRegister scratch) = 0; |
| 480 | virtual void Call(FrameOffset base, Offset offset, |
| 481 | ManagedRegister scratch) = 0; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame^] | 482 | virtual void CallFromThread32(ThreadOffset<4> offset, ManagedRegister scratch); |
| 483 | virtual void CallFromThread64(ThreadOffset<8> offset, ManagedRegister scratch); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 484 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 485 | // Generate code to check if Thread::Current()->exception_ is non-null |
| 486 | // and branch to a ExceptionSlowPath if it is. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 487 | virtual void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) = 0; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 488 | |
| 489 | virtual ~Assembler() {} |
| 490 | |
| 491 | protected: |
| 492 | Assembler() : buffer_() {} |
| 493 | |
| 494 | AssemblerBuffer buffer_; |
| 495 | }; |
| 496 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 497 | } // namespace art |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 498 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 499 | #endif // ART_COMPILER_UTILS_ASSEMBLER_H_ |