blob: f8ca48ef57c68514ebdb821388a7753a0085126e [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_ARM_ASSEMBLER_ARM_H_
18#define ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_H_
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070019
Vladimir Markocf93a5c2015-06-16 11:33:24 +000020#include <type_traits>
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021#include <vector>
22
Vladimir Marko80afd022015-05-19 18:08:00 +010023#include "base/bit_utils.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080024#include "base/logging.h"
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070025#include "base/value_object.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070026#include "constants_arm.h"
Ian Rogers166db042013-07-26 12:05:57 -070027#include "utils/arm/managed_register_arm.h"
28#include "utils/assembler.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070029#include "offsets.h"
Carl Shapiroa2e18e12011-06-21 18:57:55 -070030
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070031namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070032namespace arm {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070033
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +000034class Arm32Assembler;
35class Thumb2Assembler;
36
Vladimir Markocf93a5c2015-06-16 11:33:24 +000037// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
38class Literal {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +000039 public:
Vladimir Markocf93a5c2015-06-16 11:33:24 +000040 static constexpr size_t kMaxSize = 8;
41
42 Literal(uint32_t size, const uint8_t* data)
43 : label_(), size_(size) {
44 DCHECK_LE(size, Literal::kMaxSize);
45 memcpy(data_, data, size);
46 }
47
48 template <typename T>
49 T GetValue() const {
50 DCHECK_EQ(size_, sizeof(T));
51 T value;
52 memcpy(&value, data_, sizeof(T));
53 return value;
54 }
55
56 uint32_t GetSize() const {
57 return size_;
58 }
59
60 const uint8_t* GetData() const {
61 return data_;
62 }
63
64 Label* GetLabel() {
65 return &label_;
66 }
67
68 const Label* GetLabel() const {
69 return &label_;
70 }
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +000071
72 private:
Vladimir Markocf93a5c2015-06-16 11:33:24 +000073 Label label_;
74 const uint32_t size_;
75 uint8_t data_[kMaxSize];
76
77 DISALLOW_COPY_AND_ASSIGN(Literal);
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +000078};
79
Carl Shapiroa2e18e12011-06-21 18:57:55 -070080class ShifterOperand {
81 public:
Dave Allison65fcc2c2014-04-28 13:45:27 -070082 ShifterOperand() : type_(kUnknown), rm_(kNoRegister), rs_(kNoRegister),
83 is_rotate_(false), is_shift_(false), shift_(kNoShift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070084 }
85
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010086 explicit ShifterOperand(uint32_t immed);
Carl Shapiroa2e18e12011-06-21 18:57:55 -070087
88 // Data-processing operands - Register
Dave Allison65fcc2c2014-04-28 13:45:27 -070089 explicit ShifterOperand(Register rm) : type_(kRegister), rm_(rm), rs_(kNoRegister),
90 is_rotate_(false), is_shift_(false), shift_(kNoShift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070091 }
92
Dave Allison65fcc2c2014-04-28 13:45:27 -070093 ShifterOperand(uint32_t rotate, uint32_t immed8) : type_(kImmediate), rm_(kNoRegister),
94 rs_(kNoRegister),
95 is_rotate_(true), is_shift_(false), shift_(kNoShift), rotate_(rotate), immed_(immed8) {
96 }
97
98 ShifterOperand(Register rm, Shift shift, uint32_t shift_imm = 0) : type_(kRegister), rm_(rm),
99 rs_(kNoRegister),
100 is_rotate_(false), is_shift_(true), shift_(shift), rotate_(0), immed_(shift_imm) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700101 }
102
103 // Data-processing operands - Logical shift/rotate by register
Dave Allison65fcc2c2014-04-28 13:45:27 -0700104 ShifterOperand(Register rm, Shift shift, Register rs) : type_(kRegister), rm_(rm),
105 rs_(rs),
106 is_rotate_(false), is_shift_(true), shift_(shift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700107 }
108
Dave Allison65fcc2c2014-04-28 13:45:27 -0700109 bool is_valid() const { return (type_ == kImmediate) || (type_ == kRegister); }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700110
111 uint32_t type() const {
112 CHECK(is_valid());
113 return type_;
114 }
115
Dave Allison65fcc2c2014-04-28 13:45:27 -0700116 uint32_t encodingArm() const;
Dave Allison45fdb932014-06-25 12:37:10 -0700117 uint32_t encodingThumb() const;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700118
119 bool IsEmpty() const {
120 return type_ == kUnknown;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700121 }
122
Dave Allison65fcc2c2014-04-28 13:45:27 -0700123 bool IsImmediate() const {
124 return type_ == kImmediate;
125 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700126
Dave Allison65fcc2c2014-04-28 13:45:27 -0700127 bool IsRegister() const {
128 return type_ == kRegister;
129 }
130
131 bool IsShift() const {
132 return is_shift_;
133 }
134
135 uint32_t GetImmediate() const {
136 return immed_;
137 }
138
139 Shift GetShift() const {
140 return shift_;
141 }
142
143 Register GetRegister() const {
144 return rm_;
145 }
146
Guillaume "Vermeille" Sanchezab4a2f52015-03-11 14:00:30 +0000147 Register GetSecondRegister() const {
148 return rs_;
149 }
150
Dave Allison65fcc2c2014-04-28 13:45:27 -0700151 enum Type {
152 kUnknown = -1,
153 kRegister,
154 kImmediate
155 };
156
Dave Allison65fcc2c2014-04-28 13:45:27 -0700157 private:
158 Type type_;
159 Register rm_;
160 Register rs_;
161 bool is_rotate_;
162 bool is_shift_;
163 Shift shift_;
164 uint32_t rotate_;
165 uint32_t immed_;
166
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000167 friend class Arm32Assembler;
168 friend class Thumb2Assembler;
169
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700170#ifdef SOURCE_ASSEMBLER_SUPPORT
171 friend class BinaryAssembler;
172#endif
173};
174
175
176enum LoadOperandType {
177 kLoadSignedByte,
178 kLoadUnsignedByte,
179 kLoadSignedHalfword,
180 kLoadUnsignedHalfword,
181 kLoadWord,
182 kLoadWordPair,
183 kLoadSWord,
184 kLoadDWord
185};
186
187
188enum StoreOperandType {
189 kStoreByte,
190 kStoreHalfword,
191 kStoreWord,
192 kStoreWordPair,
193 kStoreSWord,
194 kStoreDWord
195};
196
197
198// Load/store multiple addressing mode.
199enum BlockAddressMode {
200 // bit encoding P U W
201 DA = (0|0|0) << 21, // decrement after
202 IA = (0|4|0) << 21, // increment after
203 DB = (8|0|0) << 21, // decrement before
204 IB = (8|4|0) << 21, // increment before
205 DA_W = (0|0|1) << 21, // decrement after with writeback to base
206 IA_W = (0|4|1) << 21, // increment after with writeback to base
207 DB_W = (8|0|1) << 21, // decrement before with writeback to base
208 IB_W = (8|4|1) << 21 // increment before with writeback to base
209};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700210inline std::ostream& operator<<(std::ostream& os, const BlockAddressMode& rhs) {
211 os << static_cast<int>(rhs);
212 return os;
213}
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700214
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700215class Address : public ValueObject {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700216 public:
Dave Allison65fcc2c2014-04-28 13:45:27 -0700217 // Memory operand addressing mode (in ARM encoding form. For others we need
218 // to adjust)
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700219 enum Mode {
220 // bit encoding P U W
221 Offset = (8|4|0) << 21, // offset (w/o writeback to base)
222 PreIndex = (8|4|1) << 21, // pre-indexed addressing with writeback
223 PostIndex = (0|4|0) << 21, // post-indexed addressing with writeback
224 NegOffset = (8|0|0) << 21, // negative offset (w/o writeback to base)
225 NegPreIndex = (8|0|1) << 21, // negative pre-indexed with writeback
226 NegPostIndex = (0|0|0) << 21 // negative post-indexed with writeback
227 };
228
Dave Allison45fdb932014-06-25 12:37:10 -0700229 Address(Register rn, int32_t offset = 0, Mode am = Offset) : rn_(rn), rm_(R0),
230 offset_(offset),
231 am_(am), is_immed_offset_(true), shift_(LSL) {
232 }
233
234 Address(Register rn, Register rm, Mode am = Offset) : rn_(rn), rm_(rm), offset_(0),
235 am_(am), is_immed_offset_(false), shift_(LSL) {
236 CHECK_NE(rm, PC);
237 }
238
239 Address(Register rn, Register rm, Shift shift, uint32_t count, Mode am = Offset) :
240 rn_(rn), rm_(rm), offset_(count),
241 am_(am), is_immed_offset_(false), shift_(shift) {
242 CHECK_NE(rm, PC);
243 }
244
245 // LDR(literal) - pc relative load.
246 explicit Address(int32_t offset) :
247 rn_(PC), rm_(R0), offset_(offset),
248 am_(Offset), is_immed_offset_(false), shift_(LSL) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700249 }
250
Dave Allison65fcc2c2014-04-28 13:45:27 -0700251 static bool CanHoldLoadOffsetArm(LoadOperandType type, int offset);
252 static bool CanHoldStoreOffsetArm(StoreOperandType type, int offset);
253
254 static bool CanHoldLoadOffsetThumb(LoadOperandType type, int offset);
255 static bool CanHoldStoreOffsetThumb(StoreOperandType type, int offset);
256
257 uint32_t encodingArm() const;
Dave Allison45fdb932014-06-25 12:37:10 -0700258 uint32_t encodingThumb(bool is_32bit) const;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700259
260 uint32_t encoding3() const;
261 uint32_t vencoding() const;
262
263 uint32_t encodingThumbLdrdStrd() const;
264
265 Register GetRegister() const {
266 return rn_;
267 }
268
Dave Allison45fdb932014-06-25 12:37:10 -0700269 Register GetRegisterOffset() const {
270 return rm_;
271 }
272
Dave Allison65fcc2c2014-04-28 13:45:27 -0700273 int32_t GetOffset() const {
274 return offset_;
275 }
276
277 Mode GetMode() const {
278 return am_;
279 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700280
Dave Allison45fdb932014-06-25 12:37:10 -0700281 bool IsImmediate() const {
282 return is_immed_offset_;
283 }
284
285 Shift GetShift() const {
286 return shift_;
287 }
288
289 int32_t GetShiftCount() const {
290 CHECK(!is_immed_offset_);
291 return offset_;
292 }
293
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700294 private:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700295 const Register rn_;
296 const Register rm_;
297 const int32_t offset_; // Used as shift amount for register offset.
298 const Mode am_;
299 const bool is_immed_offset_;
300 const Shift shift_;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700301};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700302inline std::ostream& operator<<(std::ostream& os, const Address::Mode& rhs) {
303 os << static_cast<int>(rhs);
304 return os;
305}
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700306
Dave Allison65fcc2c2014-04-28 13:45:27 -0700307// Instruction encoding bits.
308enum {
309 H = 1 << 5, // halfword (or byte)
310 L = 1 << 20, // load (or store)
311 S = 1 << 20, // set condition code (or leave unchanged)
312 W = 1 << 21, // writeback base register (or leave unchanged)
313 A = 1 << 21, // accumulate in multiply instruction (or not)
314 B = 1 << 22, // unsigned byte (or word)
315 N = 1 << 22, // long (or short)
316 U = 1 << 23, // positive (or negative) offset/index
317 P = 1 << 24, // offset/pre-indexed addressing (or post-indexed addressing)
318 I = 1 << 25, // immediate shifter operand (or not)
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700319
Dave Allison65fcc2c2014-04-28 13:45:27 -0700320 B0 = 1,
321 B1 = 1 << 1,
322 B2 = 1 << 2,
323 B3 = 1 << 3,
324 B4 = 1 << 4,
325 B5 = 1 << 5,
326 B6 = 1 << 6,
327 B7 = 1 << 7,
328 B8 = 1 << 8,
329 B9 = 1 << 9,
330 B10 = 1 << 10,
331 B11 = 1 << 11,
332 B12 = 1 << 12,
333 B13 = 1 << 13,
334 B14 = 1 << 14,
335 B15 = 1 << 15,
336 B16 = 1 << 16,
337 B17 = 1 << 17,
338 B18 = 1 << 18,
339 B19 = 1 << 19,
340 B20 = 1 << 20,
341 B21 = 1 << 21,
342 B22 = 1 << 22,
343 B23 = 1 << 23,
344 B24 = 1 << 24,
345 B25 = 1 << 25,
346 B26 = 1 << 26,
347 B27 = 1 << 27,
348 B28 = 1 << 28,
349 B29 = 1 << 29,
350 B30 = 1 << 30,
351 B31 = 1 << 31,
352
353 // Instruction bit masks.
354 RdMask = 15 << 12, // in str instruction
355 CondMask = 15 << 28,
356 CoprocessorMask = 15 << 8,
357 OpCodeMask = 15 << 21, // in data-processing instructions
358 Imm24Mask = (1 << 24) - 1,
359 Off12Mask = (1 << 12) - 1,
360
361 // ldrex/strex register field encodings.
362 kLdExRnShift = 16,
363 kLdExRtShift = 12,
364 kStrExRnShift = 16,
365 kStrExRdShift = 12,
366 kStrExRtShift = 0,
367};
368
369// IfThen state for IT instructions.
370enum ItState {
371 kItOmitted,
372 kItThen,
373 kItT = kItThen,
374 kItElse,
375 kItE = kItElse
376};
377
378constexpr uint32_t kNoItCondition = 3;
379constexpr uint32_t kInvalidModifiedImmediate = -1;
380
381extern const char* kRegisterNames[];
382extern const char* kConditionNames[];
Dave Allison65fcc2c2014-04-28 13:45:27 -0700383
384// This is an abstract ARM assembler. Subclasses provide assemblers for the individual
385// instruction sets (ARM32, Thumb2, etc.)
386//
387class ArmAssembler : public Assembler {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700388 public:
Ian Rogers2c8f6532011-09-02 17:16:34 -0700389 virtual ~ArmAssembler() {}
buzbeec143c552011-08-20 17:38:58 -0700390
Dave Allison65fcc2c2014-04-28 13:45:27 -0700391 // Is this assembler for the thumb instruction set?
392 virtual bool IsThumb() const = 0;
393
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700394 // Data-processing instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700395 virtual void and_(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700396
Dave Allison65fcc2c2014-04-28 13:45:27 -0700397 virtual void eor(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700398
Dave Allison65fcc2c2014-04-28 13:45:27 -0700399 virtual void sub(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
400 virtual void subs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700401
Dave Allison65fcc2c2014-04-28 13:45:27 -0700402 virtual void rsb(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
403 virtual void rsbs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700404
Dave Allison65fcc2c2014-04-28 13:45:27 -0700405 virtual void add(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700406
Dave Allison65fcc2c2014-04-28 13:45:27 -0700407 virtual void adds(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700408
Dave Allison65fcc2c2014-04-28 13:45:27 -0700409 virtual void adc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700410
Dave Allison65fcc2c2014-04-28 13:45:27 -0700411 virtual void sbc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700412
Dave Allison65fcc2c2014-04-28 13:45:27 -0700413 virtual void rsc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700414
Dave Allison65fcc2c2014-04-28 13:45:27 -0700415 virtual void tst(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700416
Dave Allison65fcc2c2014-04-28 13:45:27 -0700417 virtual void teq(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700418
Dave Allison65fcc2c2014-04-28 13:45:27 -0700419 virtual void cmp(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700420
Dave Allison65fcc2c2014-04-28 13:45:27 -0700421 virtual void cmn(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700422
Dave Allison65fcc2c2014-04-28 13:45:27 -0700423 virtual void orr(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
424 virtual void orrs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700425
Dave Allison65fcc2c2014-04-28 13:45:27 -0700426 virtual void mov(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
427 virtual void movs(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700428
Dave Allison65fcc2c2014-04-28 13:45:27 -0700429 virtual void bic(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700430
Dave Allison65fcc2c2014-04-28 13:45:27 -0700431 virtual void mvn(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
432 virtual void mvns(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700433
434 // Miscellaneous data-processing instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700435 virtual void clz(Register rd, Register rm, Condition cond = AL) = 0;
436 virtual void movw(Register rd, uint16_t imm16, Condition cond = AL) = 0;
437 virtual void movt(Register rd, uint16_t imm16, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700438
439 // Multiply instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700440 virtual void mul(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
441 virtual void mla(Register rd, Register rn, Register rm, Register ra,
442 Condition cond = AL) = 0;
443 virtual void mls(Register rd, Register rn, Register rm, Register ra,
444 Condition cond = AL) = 0;
Zheng Xuc6667102015-05-15 16:08:45 +0800445 virtual void smull(Register rd_lo, Register rd_hi, Register rn, Register rm,
446 Condition cond = AL) = 0;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700447 virtual void umull(Register rd_lo, Register rd_hi, Register rn, Register rm,
448 Condition cond = AL) = 0;
449
450 virtual void sdiv(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
451 virtual void udiv(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700452
Roland Levillain981e4542014-11-14 11:47:14 +0000453 // Bit field extract instructions.
Roland Levillain51d3fc42014-11-13 14:11:42 +0000454 virtual void sbfx(Register rd, Register rn, uint32_t lsb, uint32_t width,
455 Condition cond = AL) = 0;
Roland Levillain981e4542014-11-14 11:47:14 +0000456 virtual void ubfx(Register rd, Register rn, uint32_t lsb, uint32_t width,
457 Condition cond = AL) = 0;
Roland Levillain51d3fc42014-11-13 14:11:42 +0000458
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700459 // Load/store instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700460 virtual void ldr(Register rd, const Address& ad, Condition cond = AL) = 0;
461 virtual void str(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700462
Dave Allison65fcc2c2014-04-28 13:45:27 -0700463 virtual void ldrb(Register rd, const Address& ad, Condition cond = AL) = 0;
464 virtual void strb(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700465
Dave Allison65fcc2c2014-04-28 13:45:27 -0700466 virtual void ldrh(Register rd, const Address& ad, Condition cond = AL) = 0;
467 virtual void strh(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700468
Dave Allison65fcc2c2014-04-28 13:45:27 -0700469 virtual void ldrsb(Register rd, const Address& ad, Condition cond = AL) = 0;
470 virtual void ldrsh(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700471
Dave Allison65fcc2c2014-04-28 13:45:27 -0700472 virtual void ldrd(Register rd, const Address& ad, Condition cond = AL) = 0;
473 virtual void strd(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700474
Dave Allison65fcc2c2014-04-28 13:45:27 -0700475 virtual void ldm(BlockAddressMode am, Register base,
476 RegList regs, Condition cond = AL) = 0;
477 virtual void stm(BlockAddressMode am, Register base,
478 RegList regs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700479
Dave Allison65fcc2c2014-04-28 13:45:27 -0700480 virtual void ldrex(Register rd, Register rn, Condition cond = AL) = 0;
481 virtual void strex(Register rd, Register rt, Register rn, Condition cond = AL) = 0;
Calin Juravle52c48962014-12-16 17:02:57 +0000482 virtual void ldrexd(Register rt, Register rt2, Register rn, Condition cond = AL) = 0;
483 virtual void strexd(Register rd, Register rt, Register rt2, Register rn, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700484
485 // Miscellaneous instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700486 virtual void clrex(Condition cond = AL) = 0;
487 virtual void nop(Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700488
489 // Note that gdb sets breakpoints using the undefined instruction 0xe7f001f0.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700490 virtual void bkpt(uint16_t imm16) = 0;
491 virtual void svc(uint32_t imm24) = 0;
492
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700493 virtual void it(Condition firstcond ATTRIBUTE_UNUSED,
494 ItState i1 ATTRIBUTE_UNUSED = kItOmitted,
495 ItState i2 ATTRIBUTE_UNUSED = kItOmitted,
496 ItState i3 ATTRIBUTE_UNUSED = kItOmitted) {
Dave Allison65fcc2c2014-04-28 13:45:27 -0700497 // Ignored if not supported.
498 }
499
500 virtual void cbz(Register rn, Label* target) = 0;
501 virtual void cbnz(Register rn, Label* target) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700502
503 // Floating point instructions (VFPv3-D16 and VFPv3-D32 profiles).
Dave Allison65fcc2c2014-04-28 13:45:27 -0700504 virtual void vmovsr(SRegister sn, Register rt, Condition cond = AL) = 0;
505 virtual void vmovrs(Register rt, SRegister sn, Condition cond = AL) = 0;
506 virtual void vmovsrr(SRegister sm, Register rt, Register rt2, Condition cond = AL) = 0;
507 virtual void vmovrrs(Register rt, Register rt2, SRegister sm, Condition cond = AL) = 0;
508 virtual void vmovdrr(DRegister dm, Register rt, Register rt2, Condition cond = AL) = 0;
509 virtual void vmovrrd(Register rt, Register rt2, DRegister dm, Condition cond = AL) = 0;
510 virtual void vmovs(SRegister sd, SRegister sm, Condition cond = AL) = 0;
511 virtual void vmovd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700512
513 // Returns false if the immediate cannot be encoded.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700514 virtual bool vmovs(SRegister sd, float s_imm, Condition cond = AL) = 0;
515 virtual bool vmovd(DRegister dd, double d_imm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700516
Dave Allison65fcc2c2014-04-28 13:45:27 -0700517 virtual void vldrs(SRegister sd, const Address& ad, Condition cond = AL) = 0;
518 virtual void vstrs(SRegister sd, const Address& ad, Condition cond = AL) = 0;
519 virtual void vldrd(DRegister dd, const Address& ad, Condition cond = AL) = 0;
520 virtual void vstrd(DRegister dd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700521
Dave Allison65fcc2c2014-04-28 13:45:27 -0700522 virtual void vadds(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
523 virtual void vaddd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
524 virtual void vsubs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
525 virtual void vsubd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
526 virtual void vmuls(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
527 virtual void vmuld(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
528 virtual void vmlas(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
529 virtual void vmlad(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
530 virtual void vmlss(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
531 virtual void vmlsd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
532 virtual void vdivs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
533 virtual void vdivd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700534
Dave Allison65fcc2c2014-04-28 13:45:27 -0700535 virtual void vabss(SRegister sd, SRegister sm, Condition cond = AL) = 0;
536 virtual void vabsd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
537 virtual void vnegs(SRegister sd, SRegister sm, Condition cond = AL) = 0;
538 virtual void vnegd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
539 virtual void vsqrts(SRegister sd, SRegister sm, Condition cond = AL) = 0;
540 virtual void vsqrtd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700541
Dave Allison65fcc2c2014-04-28 13:45:27 -0700542 virtual void vcvtsd(SRegister sd, DRegister dm, Condition cond = AL) = 0;
543 virtual void vcvtds(DRegister dd, SRegister sm, Condition cond = AL) = 0;
544 virtual void vcvtis(SRegister sd, SRegister sm, Condition cond = AL) = 0;
545 virtual void vcvtid(SRegister sd, DRegister dm, Condition cond = AL) = 0;
546 virtual void vcvtsi(SRegister sd, SRegister sm, Condition cond = AL) = 0;
547 virtual void vcvtdi(DRegister dd, SRegister sm, Condition cond = AL) = 0;
548 virtual void vcvtus(SRegister sd, SRegister sm, Condition cond = AL) = 0;
549 virtual void vcvtud(SRegister sd, DRegister dm, Condition cond = AL) = 0;
550 virtual void vcvtsu(SRegister sd, SRegister sm, Condition cond = AL) = 0;
551 virtual void vcvtdu(DRegister dd, SRegister sm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700552
Dave Allison65fcc2c2014-04-28 13:45:27 -0700553 virtual void vcmps(SRegister sd, SRegister sm, Condition cond = AL) = 0;
554 virtual void vcmpd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
555 virtual void vcmpsz(SRegister sd, Condition cond = AL) = 0;
556 virtual void vcmpdz(DRegister dd, Condition cond = AL) = 0;
557 virtual void vmstat(Condition cond = AL) = 0; // VMRS APSR_nzcv, FPSCR
558
559 virtual void vpushs(SRegister reg, int nregs, Condition cond = AL) = 0;
560 virtual void vpushd(DRegister reg, int nregs, Condition cond = AL) = 0;
561 virtual void vpops(SRegister reg, int nregs, Condition cond = AL) = 0;
562 virtual void vpopd(DRegister reg, int nregs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700563
564 // Branch instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700565 virtual void b(Label* label, Condition cond = AL) = 0;
566 virtual void bl(Label* label, Condition cond = AL) = 0;
567 virtual void blx(Register rm, Condition cond = AL) = 0;
568 virtual void bx(Register rm, Condition cond = AL) = 0;
569
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100570 // Memory barriers.
571 virtual void dmb(DmbOptions flavor) = 0;
572
Dave Allison65fcc2c2014-04-28 13:45:27 -0700573 void Pad(uint32_t bytes);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700574
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000575 // Adjust label position.
576 void AdjustLabelPosition(Label* label) {
577 DCHECK(label->IsBound());
578 uint32_t old_position = static_cast<uint32_t>(label->Position());
579 uint32_t new_position = GetAdjustedPosition(old_position);
580 label->Reinitialize();
581 DCHECK_GE(static_cast<int>(new_position), 0);
582 label->BindTo(static_cast<int>(new_position));
583 }
584
585 // Get the final position of a label after local fixup based on the old position
586 // recorded before FinalizeCode().
587 virtual uint32_t GetAdjustedPosition(uint32_t old_position) = 0;
588
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700589 // Macros.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700590 // Most of these are pure virtual as they need to be implemented per instruction set.
591
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000592 // Create a new literal with a given value.
593 // NOTE: Force the template parameter to be explicitly specified. In the absence of
594 // std::omit_from_type_deduction<T> or std::identity<T>, use std::decay<T>.
595 template <typename T>
596 Literal* NewLiteral(typename std::decay<T>::type value) {
597 static_assert(std::is_integral<T>::value, "T must be an integral type.");
598 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
599 }
600
601 // Create a new literal with the given data.
602 virtual Literal* NewLiteral(size_t size, const uint8_t* data) = 0;
603
604 // Load literal.
605 virtual void LoadLiteral(Register rt, Literal* literal) = 0;
606 virtual void LoadLiteral(Register rt, Register rt2, Literal* literal) = 0;
607 virtual void LoadLiteral(SRegister sd, Literal* literal) = 0;
608 virtual void LoadLiteral(DRegister dd, Literal* literal) = 0;
609
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700610 // Add signed constant value to rd. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700611 virtual void AddConstant(Register rd, int32_t value, Condition cond = AL) = 0;
612 virtual void AddConstant(Register rd, Register rn, int32_t value,
613 Condition cond = AL) = 0;
614 virtual void AddConstantSetFlags(Register rd, Register rn, int32_t value,
615 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700616
617 // Load and Store. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700618 virtual void LoadImmediate(Register rd, int32_t value, Condition cond = AL) = 0;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000619 void LoadSImmediate(SRegister sd, float value, Condition cond = AL) {
620 if (!vmovs(sd, value, cond)) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +0000621 int32_t int_value = bit_cast<int32_t, float>(value);
622 if (int_value == bit_cast<int32_t, float>(0.0f)) {
623 // 0.0 is quite common, so we special case it by loading
624 // 2.0 in `sd` and then substracting it.
625 bool success = vmovs(sd, 2.0, cond);
626 CHECK(success);
627 vsubs(sd, sd, sd, cond);
628 } else {
629 LoadImmediate(IP, int_value, cond);
630 vmovsr(sd, IP, cond);
631 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000632 }
633 }
634
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000635 void LoadDImmediate(DRegister sd, double value, Condition cond = AL) {
636 if (!vmovd(sd, value, cond)) {
637 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +0000638 if (int_value == bit_cast<uint64_t, double>(0.0)) {
639 // 0.0 is quite common, so we special case it by loading
640 // 2.0 in `sd` and then substracting it.
641 bool success = vmovd(sd, 2.0, cond);
642 CHECK(success);
643 vsubd(sd, sd, sd, cond);
644 } else {
645 if (sd < 16) {
646 SRegister low = static_cast<SRegister>(sd << 1);
647 SRegister high = static_cast<SRegister>(low + 1);
648 LoadSImmediate(low, bit_cast<float, uint32_t>(Low32Bits(int_value)), cond);
649 if (High32Bits(int_value) == Low32Bits(int_value)) {
650 vmovs(high, low);
651 } else {
652 LoadSImmediate(high, bit_cast<float, uint32_t>(High32Bits(int_value)), cond);
653 }
654 } else {
655 LOG(FATAL) << "Unimplemented loading of double into a D register "
656 << "that cannot be split into two S registers";
657 }
658 }
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000659 }
660 }
661
Dave Allison65fcc2c2014-04-28 13:45:27 -0700662 virtual void MarkExceptionHandler(Label* label) = 0;
663 virtual void LoadFromOffset(LoadOperandType type,
664 Register reg,
665 Register base,
666 int32_t offset,
667 Condition cond = AL) = 0;
668 virtual void StoreToOffset(StoreOperandType type,
669 Register reg,
670 Register base,
671 int32_t offset,
672 Condition cond = AL) = 0;
673 virtual void LoadSFromOffset(SRegister reg,
674 Register base,
675 int32_t offset,
676 Condition cond = AL) = 0;
677 virtual void StoreSToOffset(SRegister reg,
678 Register base,
679 int32_t offset,
680 Condition cond = AL) = 0;
681 virtual void LoadDFromOffset(DRegister reg,
682 Register base,
683 int32_t offset,
684 Condition cond = AL) = 0;
685 virtual void StoreDToOffset(DRegister reg,
686 Register base,
687 int32_t offset,
688 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700689
Dave Allison65fcc2c2014-04-28 13:45:27 -0700690 virtual void Push(Register rd, Condition cond = AL) = 0;
691 virtual void Pop(Register rd, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700692
Dave Allison65fcc2c2014-04-28 13:45:27 -0700693 virtual void PushList(RegList regs, Condition cond = AL) = 0;
694 virtual void PopList(RegList regs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700695
Dave Allison65fcc2c2014-04-28 13:45:27 -0700696 virtual void Mov(Register rd, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700697
698 // Convenience shift instructions. Use mov instruction with shifter operand
699 // for variants setting the status flags or using a register shift count.
Dave Allison45fdb932014-06-25 12:37:10 -0700700 virtual void Lsl(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
701 Condition cond = AL) = 0;
702 virtual void Lsr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
703 Condition cond = AL) = 0;
704 virtual void Asr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
705 Condition cond = AL) = 0;
706 virtual void Ror(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
707 Condition cond = AL) = 0;
708 virtual void Rrx(Register rd, Register rm, bool setcc = false,
709 Condition cond = AL) = 0;
710
711 virtual void Lsl(Register rd, Register rm, Register rn, bool setcc = false,
712 Condition cond = AL) = 0;
713 virtual void Lsr(Register rd, Register rm, Register rn, bool setcc = false,
714 Condition cond = AL) = 0;
715 virtual void Asr(Register rd, Register rm, Register rn, bool setcc = false,
716 Condition cond = AL) = 0;
717 virtual void Ror(Register rd, Register rm, Register rn, bool setcc = false,
718 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700719
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000720 // Returns whether the `immediate` can fit in a `ShifterOperand`. If yes,
721 // `shifter_op` contains the operand.
722 virtual bool ShifterOperandCanHold(Register rd,
723 Register rn,
724 Opcode opcode,
725 uint32_t immediate,
726 ShifterOperand* shifter_op) = 0;
727
Ian Rogers13735952014-10-08 12:43:28 -0700728 static bool IsInstructionForExceptionHandling(uintptr_t pc);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700729
Dave Allison65fcc2c2014-04-28 13:45:27 -0700730 virtual void Bind(Label* label) = 0;
731
732 virtual void CompareAndBranchIfZero(Register r, Label* label) = 0;
733 virtual void CompareAndBranchIfNonZero(Register r, Label* label) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700734
Ian Rogers2c8f6532011-09-02 17:16:34 -0700735 //
736 // Overridden common assembler high-level functionality
737 //
Ian Rogers45a76cb2011-07-21 22:00:15 -0700738
Ian Rogers2c8f6532011-09-02 17:16:34 -0700739 // Emit code that will create an activation on the stack
Ian Rogersdd7624d2014-03-14 17:43:00 -0700740 void BuildFrame(size_t frame_size, ManagedRegister method_reg,
741 const std::vector<ManagedRegister>& callee_save_regs,
742 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
Ian Rogersb033c752011-07-20 12:22:35 -0700743
Ian Rogers2c8f6532011-09-02 17:16:34 -0700744 // Emit code that will remove an activation from the stack
Ian Rogersdd7624d2014-03-14 17:43:00 -0700745 void RemoveFrame(size_t frame_size, const std::vector<ManagedRegister>& callee_save_regs)
Dave Allison65fcc2c2014-04-28 13:45:27 -0700746 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700747
Ian Rogersdd7624d2014-03-14 17:43:00 -0700748 void IncreaseFrameSize(size_t adjust) OVERRIDE;
749 void DecreaseFrameSize(size_t adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700750
751 // Store routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700752 void Store(FrameOffset offs, ManagedRegister src, size_t size) OVERRIDE;
753 void StoreRef(FrameOffset dest, ManagedRegister src) OVERRIDE;
754 void StoreRawPtr(FrameOffset dest, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700755
Ian Rogersdd7624d2014-03-14 17:43:00 -0700756 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700757
Ian Rogersdd7624d2014-03-14 17:43:00 -0700758 void StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm, ManagedRegister scratch)
759 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700760
Ian Rogersdd7624d2014-03-14 17:43:00 -0700761 void StoreStackOffsetToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs,
762 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700763
Ian Rogersdd7624d2014-03-14 17:43:00 -0700764 void StoreStackPointerToThread32(ThreadOffset<4> thr_offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700765
Ian Rogersdd7624d2014-03-14 17:43:00 -0700766 void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off,
767 ManagedRegister scratch) OVERRIDE;
Ian Rogersbdb03912011-09-14 00:55:44 -0700768
Ian Rogers2c8f6532011-09-02 17:16:34 -0700769 // Load routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700770 void Load(ManagedRegister dest, FrameOffset src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700771
Ian Rogersdd7624d2014-03-14 17:43:00 -0700772 void LoadFromThread32(ManagedRegister dest, ThreadOffset<4> src, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700773
Mathieu Chartiere401d142015-04-22 13:56:20 -0700774 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700775
Mathieu Chartiere401d142015-04-22 13:56:20 -0700776 void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs,
777 bool poison_reference) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700778
Ian Rogersdd7624d2014-03-14 17:43:00 -0700779 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700780
Ian Rogersdd7624d2014-03-14 17:43:00 -0700781 void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset<4> offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700782
783 // Copying routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700784 void Move(ManagedRegister dest, ManagedRegister src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700785
Ian Rogersdd7624d2014-03-14 17:43:00 -0700786 void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset<4> thr_offs,
787 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700788
Ian Rogersdd7624d2014-03-14 17:43:00 -0700789 void CopyRawPtrToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs, ManagedRegister scratch)
790 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700791
Ian Rogersdd7624d2014-03-14 17:43:00 -0700792 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700793
Ian Rogersdd7624d2014-03-14 17:43:00 -0700794 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700795
Ian Rogersdd7624d2014-03-14 17:43:00 -0700796 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister scratch,
797 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700798
Ian Rogersdd7624d2014-03-14 17:43:00 -0700799 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, ManagedRegister scratch,
800 size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700801
Ian Rogersdd7624d2014-03-14 17:43:00 -0700802 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister scratch,
803 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700804
Ian Rogersdd7624d2014-03-14 17:43:00 -0700805 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
806 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700807
Ian Rogersdd7624d2014-03-14 17:43:00 -0700808 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
809 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700810
jeffhao58136ca2012-05-24 13:40:11 -0700811 // Sign extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700812 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao58136ca2012-05-24 13:40:11 -0700813
jeffhaocee4d0c2012-06-15 14:42:01 -0700814 // Zero extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700815 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhaocee4d0c2012-06-15 14:42:01 -0700816
Ian Rogers2c8f6532011-09-02 17:16:34 -0700817 // Exploit fast access in managed code to Thread::Current()
Ian Rogersdd7624d2014-03-14 17:43:00 -0700818 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
819 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700820
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700821 // 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 -0700822 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700823 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700824 // null.
825 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
826 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700827
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700828 // 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 -0700829 // value is null and null_allowed.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700830 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
831 ManagedRegister scratch, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700832
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700833 // src holds a handle scope entry (Object**) load this into dst
834 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700835
836 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
837 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700838 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
839 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700840
841 // Call to address held at [base+offset]
Ian Rogersdd7624d2014-03-14 17:43:00 -0700842 void Call(ManagedRegister base, Offset offset, ManagedRegister scratch) OVERRIDE;
843 void Call(FrameOffset base, Offset offset, ManagedRegister scratch) OVERRIDE;
844 void CallFromThread32(ThreadOffset<4> offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700845
Ian Rogers2c8f6532011-09-02 17:16:34 -0700846 // Generate code to check if Thread::Current()->exception_ is non-null
847 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700848 void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) OVERRIDE;
Ian Rogersb033c752011-07-20 12:22:35 -0700849
Dave Allison65fcc2c2014-04-28 13:45:27 -0700850 static uint32_t ModifiedImmediate(uint32_t value);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700851
Dave Allison45fdb932014-06-25 12:37:10 -0700852 static bool IsLowRegister(Register r) {
853 return r < R8;
854 }
855
856 static bool IsHighRegister(Register r) {
857 return r >= R8;
858 }
859
Dave Allison65fcc2c2014-04-28 13:45:27 -0700860 protected:
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700861 // Returns whether or not the given register is used for passing parameters.
862 static int RegisterCompare(const Register* reg1, const Register* reg2) {
863 return *reg1 - *reg2;
864 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700865};
866
Ian Rogers2c8f6532011-09-02 17:16:34 -0700867// Slowpath entered when Thread::Current()->_exception is non-null
Ian Rogersdd7624d2014-03-14 17:43:00 -0700868class ArmExceptionSlowPath FINAL : public SlowPath {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700869 public:
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700870 explicit ArmExceptionSlowPath(ArmManagedRegister scratch, size_t stack_adjust)
871 : scratch_(scratch), stack_adjust_(stack_adjust) {
872 }
Ian Rogersdd7624d2014-03-14 17:43:00 -0700873 void Emit(Assembler *sp_asm) OVERRIDE;
Ian Rogers67375ac2011-09-14 00:55:44 -0700874 private:
875 const ArmManagedRegister scratch_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700876 const size_t stack_adjust_;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700877};
878
Ian Rogers2c8f6532011-09-02 17:16:34 -0700879} // namespace arm
Ian Rogersb033c752011-07-20 12:22:35 -0700880} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700881
Ian Rogers166db042013-07-26 12:05:57 -0700882#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_H_