blob: 313f365df6d438a7d86b639900b3add728598b68 [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
Elliott Hughes07ed66b2012-12-12 18:34:25 -080020#include <vector>
21
22#include "base/logging.h"
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070023#include "base/value_object.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070024#include "constants_arm.h"
Ian Rogers166db042013-07-26 12:05:57 -070025#include "utils/arm/managed_register_arm.h"
26#include "utils/assembler.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070027#include "offsets.h"
28#include "utils.h"
Carl Shapiroa2e18e12011-06-21 18:57:55 -070029
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070030namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070031namespace arm {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070032
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +000033class Arm32Assembler;
34class Thumb2Assembler;
35
Carl Shapiroa2e18e12011-06-21 18:57:55 -070036class ShifterOperand {
37 public:
Dave Allison65fcc2c2014-04-28 13:45:27 -070038 ShifterOperand() : type_(kUnknown), rm_(kNoRegister), rs_(kNoRegister),
39 is_rotate_(false), is_shift_(false), shift_(kNoShift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070040 }
41
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010042 explicit ShifterOperand(uint32_t immed);
Carl Shapiroa2e18e12011-06-21 18:57:55 -070043
44 // Data-processing operands - Register
Dave Allison65fcc2c2014-04-28 13:45:27 -070045 explicit ShifterOperand(Register rm) : type_(kRegister), rm_(rm), rs_(kNoRegister),
46 is_rotate_(false), is_shift_(false), shift_(kNoShift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070047 }
48
Dave Allison65fcc2c2014-04-28 13:45:27 -070049 ShifterOperand(uint32_t rotate, uint32_t immed8) : type_(kImmediate), rm_(kNoRegister),
50 rs_(kNoRegister),
51 is_rotate_(true), is_shift_(false), shift_(kNoShift), rotate_(rotate), immed_(immed8) {
52 }
53
54 ShifterOperand(Register rm, Shift shift, uint32_t shift_imm = 0) : type_(kRegister), rm_(rm),
55 rs_(kNoRegister),
56 is_rotate_(false), is_shift_(true), shift_(shift), rotate_(0), immed_(shift_imm) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070057 }
58
59 // Data-processing operands - Logical shift/rotate by register
Dave Allison65fcc2c2014-04-28 13:45:27 -070060 ShifterOperand(Register rm, Shift shift, Register rs) : type_(kRegister), rm_(rm),
61 rs_(rs),
62 is_rotate_(false), is_shift_(true), shift_(shift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070063 }
64
Dave Allison65fcc2c2014-04-28 13:45:27 -070065 bool is_valid() const { return (type_ == kImmediate) || (type_ == kRegister); }
Carl Shapiroa2e18e12011-06-21 18:57:55 -070066
67 uint32_t type() const {
68 CHECK(is_valid());
69 return type_;
70 }
71
Dave Allison65fcc2c2014-04-28 13:45:27 -070072 uint32_t encodingArm() const;
Dave Allison45fdb932014-06-25 12:37:10 -070073 uint32_t encodingThumb() const;
Dave Allison65fcc2c2014-04-28 13:45:27 -070074
75 bool IsEmpty() const {
76 return type_ == kUnknown;
Carl Shapiroa2e18e12011-06-21 18:57:55 -070077 }
78
Dave Allison65fcc2c2014-04-28 13:45:27 -070079 bool IsImmediate() const {
80 return type_ == kImmediate;
81 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -070082
Dave Allison65fcc2c2014-04-28 13:45:27 -070083 bool IsRegister() const {
84 return type_ == kRegister;
85 }
86
87 bool IsShift() const {
88 return is_shift_;
89 }
90
91 uint32_t GetImmediate() const {
92 return immed_;
93 }
94
95 Shift GetShift() const {
96 return shift_;
97 }
98
99 Register GetRegister() const {
100 return rm_;
101 }
102
Guillaume "Vermeille" Sanchezab4a2f52015-03-11 14:00:30 +0000103 Register GetSecondRegister() const {
104 return rs_;
105 }
106
Dave Allison65fcc2c2014-04-28 13:45:27 -0700107 enum Type {
108 kUnknown = -1,
109 kRegister,
110 kImmediate
111 };
112
Dave Allison65fcc2c2014-04-28 13:45:27 -0700113 private:
114 Type type_;
115 Register rm_;
116 Register rs_;
117 bool is_rotate_;
118 bool is_shift_;
119 Shift shift_;
120 uint32_t rotate_;
121 uint32_t immed_;
122
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000123 friend class Arm32Assembler;
124 friend class Thumb2Assembler;
125
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700126#ifdef SOURCE_ASSEMBLER_SUPPORT
127 friend class BinaryAssembler;
128#endif
129};
130
131
132enum LoadOperandType {
133 kLoadSignedByte,
134 kLoadUnsignedByte,
135 kLoadSignedHalfword,
136 kLoadUnsignedHalfword,
137 kLoadWord,
138 kLoadWordPair,
139 kLoadSWord,
140 kLoadDWord
141};
142
143
144enum StoreOperandType {
145 kStoreByte,
146 kStoreHalfword,
147 kStoreWord,
148 kStoreWordPair,
149 kStoreSWord,
150 kStoreDWord
151};
152
153
154// Load/store multiple addressing mode.
155enum BlockAddressMode {
156 // bit encoding P U W
157 DA = (0|0|0) << 21, // decrement after
158 IA = (0|4|0) << 21, // increment after
159 DB = (8|0|0) << 21, // decrement before
160 IB = (8|4|0) << 21, // increment before
161 DA_W = (0|0|1) << 21, // decrement after with writeback to base
162 IA_W = (0|4|1) << 21, // increment after with writeback to base
163 DB_W = (8|0|1) << 21, // decrement before with writeback to base
164 IB_W = (8|4|1) << 21 // increment before with writeback to base
165};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700166inline std::ostream& operator<<(std::ostream& os, const BlockAddressMode& rhs) {
167 os << static_cast<int>(rhs);
168 return os;
169}
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700170
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700171class Address : public ValueObject {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700172 public:
Dave Allison65fcc2c2014-04-28 13:45:27 -0700173 // Memory operand addressing mode (in ARM encoding form. For others we need
174 // to adjust)
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700175 enum Mode {
176 // bit encoding P U W
177 Offset = (8|4|0) << 21, // offset (w/o writeback to base)
178 PreIndex = (8|4|1) << 21, // pre-indexed addressing with writeback
179 PostIndex = (0|4|0) << 21, // post-indexed addressing with writeback
180 NegOffset = (8|0|0) << 21, // negative offset (w/o writeback to base)
181 NegPreIndex = (8|0|1) << 21, // negative pre-indexed with writeback
182 NegPostIndex = (0|0|0) << 21 // negative post-indexed with writeback
183 };
184
Dave Allison45fdb932014-06-25 12:37:10 -0700185 Address(Register rn, int32_t offset = 0, Mode am = Offset) : rn_(rn), rm_(R0),
186 offset_(offset),
187 am_(am), is_immed_offset_(true), shift_(LSL) {
188 }
189
190 Address(Register rn, Register rm, Mode am = Offset) : rn_(rn), rm_(rm), offset_(0),
191 am_(am), is_immed_offset_(false), shift_(LSL) {
192 CHECK_NE(rm, PC);
193 }
194
195 Address(Register rn, Register rm, Shift shift, uint32_t count, Mode am = Offset) :
196 rn_(rn), rm_(rm), offset_(count),
197 am_(am), is_immed_offset_(false), shift_(shift) {
198 CHECK_NE(rm, PC);
199 }
200
201 // LDR(literal) - pc relative load.
202 explicit Address(int32_t offset) :
203 rn_(PC), rm_(R0), offset_(offset),
204 am_(Offset), is_immed_offset_(false), shift_(LSL) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700205 }
206
Dave Allison65fcc2c2014-04-28 13:45:27 -0700207 static bool CanHoldLoadOffsetArm(LoadOperandType type, int offset);
208 static bool CanHoldStoreOffsetArm(StoreOperandType type, int offset);
209
210 static bool CanHoldLoadOffsetThumb(LoadOperandType type, int offset);
211 static bool CanHoldStoreOffsetThumb(StoreOperandType type, int offset);
212
213 uint32_t encodingArm() const;
Dave Allison45fdb932014-06-25 12:37:10 -0700214 uint32_t encodingThumb(bool is_32bit) const;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700215
216 uint32_t encoding3() const;
217 uint32_t vencoding() const;
218
219 uint32_t encodingThumbLdrdStrd() const;
220
221 Register GetRegister() const {
222 return rn_;
223 }
224
Dave Allison45fdb932014-06-25 12:37:10 -0700225 Register GetRegisterOffset() const {
226 return rm_;
227 }
228
Dave Allison65fcc2c2014-04-28 13:45:27 -0700229 int32_t GetOffset() const {
230 return offset_;
231 }
232
233 Mode GetMode() const {
234 return am_;
235 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700236
Dave Allison45fdb932014-06-25 12:37:10 -0700237 bool IsImmediate() const {
238 return is_immed_offset_;
239 }
240
241 Shift GetShift() const {
242 return shift_;
243 }
244
245 int32_t GetShiftCount() const {
246 CHECK(!is_immed_offset_);
247 return offset_;
248 }
249
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700250 private:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700251 const Register rn_;
252 const Register rm_;
253 const int32_t offset_; // Used as shift amount for register offset.
254 const Mode am_;
255 const bool is_immed_offset_;
256 const Shift shift_;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700257};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700258inline std::ostream& operator<<(std::ostream& os, const Address::Mode& rhs) {
259 os << static_cast<int>(rhs);
260 return os;
261}
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700262
Dave Allison65fcc2c2014-04-28 13:45:27 -0700263// Instruction encoding bits.
264enum {
265 H = 1 << 5, // halfword (or byte)
266 L = 1 << 20, // load (or store)
267 S = 1 << 20, // set condition code (or leave unchanged)
268 W = 1 << 21, // writeback base register (or leave unchanged)
269 A = 1 << 21, // accumulate in multiply instruction (or not)
270 B = 1 << 22, // unsigned byte (or word)
271 N = 1 << 22, // long (or short)
272 U = 1 << 23, // positive (or negative) offset/index
273 P = 1 << 24, // offset/pre-indexed addressing (or post-indexed addressing)
274 I = 1 << 25, // immediate shifter operand (or not)
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700275
Dave Allison65fcc2c2014-04-28 13:45:27 -0700276 B0 = 1,
277 B1 = 1 << 1,
278 B2 = 1 << 2,
279 B3 = 1 << 3,
280 B4 = 1 << 4,
281 B5 = 1 << 5,
282 B6 = 1 << 6,
283 B7 = 1 << 7,
284 B8 = 1 << 8,
285 B9 = 1 << 9,
286 B10 = 1 << 10,
287 B11 = 1 << 11,
288 B12 = 1 << 12,
289 B13 = 1 << 13,
290 B14 = 1 << 14,
291 B15 = 1 << 15,
292 B16 = 1 << 16,
293 B17 = 1 << 17,
294 B18 = 1 << 18,
295 B19 = 1 << 19,
296 B20 = 1 << 20,
297 B21 = 1 << 21,
298 B22 = 1 << 22,
299 B23 = 1 << 23,
300 B24 = 1 << 24,
301 B25 = 1 << 25,
302 B26 = 1 << 26,
303 B27 = 1 << 27,
304 B28 = 1 << 28,
305 B29 = 1 << 29,
306 B30 = 1 << 30,
307 B31 = 1 << 31,
308
309 // Instruction bit masks.
310 RdMask = 15 << 12, // in str instruction
311 CondMask = 15 << 28,
312 CoprocessorMask = 15 << 8,
313 OpCodeMask = 15 << 21, // in data-processing instructions
314 Imm24Mask = (1 << 24) - 1,
315 Off12Mask = (1 << 12) - 1,
316
317 // ldrex/strex register field encodings.
318 kLdExRnShift = 16,
319 kLdExRtShift = 12,
320 kStrExRnShift = 16,
321 kStrExRdShift = 12,
322 kStrExRtShift = 0,
323};
324
325// IfThen state for IT instructions.
326enum ItState {
327 kItOmitted,
328 kItThen,
329 kItT = kItThen,
330 kItElse,
331 kItE = kItElse
332};
333
334constexpr uint32_t kNoItCondition = 3;
335constexpr uint32_t kInvalidModifiedImmediate = -1;
336
337extern const char* kRegisterNames[];
338extern const char* kConditionNames[];
Dave Allison65fcc2c2014-04-28 13:45:27 -0700339
340// This is an abstract ARM assembler. Subclasses provide assemblers for the individual
341// instruction sets (ARM32, Thumb2, etc.)
342//
343class ArmAssembler : public Assembler {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700344 public:
Ian Rogers2c8f6532011-09-02 17:16:34 -0700345 virtual ~ArmAssembler() {}
buzbeec143c552011-08-20 17:38:58 -0700346
Dave Allison65fcc2c2014-04-28 13:45:27 -0700347 // Is this assembler for the thumb instruction set?
348 virtual bool IsThumb() const = 0;
349
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700350 // Data-processing instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700351 virtual void and_(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700352
Dave Allison65fcc2c2014-04-28 13:45:27 -0700353 virtual void eor(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700354
Dave Allison65fcc2c2014-04-28 13:45:27 -0700355 virtual void sub(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
356 virtual void subs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700357
Dave Allison65fcc2c2014-04-28 13:45:27 -0700358 virtual void rsb(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
359 virtual void rsbs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700360
Dave Allison65fcc2c2014-04-28 13:45:27 -0700361 virtual void add(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700362
Dave Allison65fcc2c2014-04-28 13:45:27 -0700363 virtual void adds(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700364
Dave Allison65fcc2c2014-04-28 13:45:27 -0700365 virtual void adc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700366
Dave Allison65fcc2c2014-04-28 13:45:27 -0700367 virtual void sbc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700368
Dave Allison65fcc2c2014-04-28 13:45:27 -0700369 virtual void rsc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700370
Dave Allison65fcc2c2014-04-28 13:45:27 -0700371 virtual void tst(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700372
Dave Allison65fcc2c2014-04-28 13:45:27 -0700373 virtual void teq(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700374
Dave Allison65fcc2c2014-04-28 13:45:27 -0700375 virtual void cmp(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700376
Dave Allison65fcc2c2014-04-28 13:45:27 -0700377 virtual void cmn(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700378
Dave Allison65fcc2c2014-04-28 13:45:27 -0700379 virtual void orr(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
380 virtual void orrs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700381
Dave Allison65fcc2c2014-04-28 13:45:27 -0700382 virtual void mov(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
383 virtual void movs(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700384
Dave Allison65fcc2c2014-04-28 13:45:27 -0700385 virtual void bic(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700386
Dave Allison65fcc2c2014-04-28 13:45:27 -0700387 virtual void mvn(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
388 virtual void mvns(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700389
390 // Miscellaneous data-processing instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700391 virtual void clz(Register rd, Register rm, Condition cond = AL) = 0;
392 virtual void movw(Register rd, uint16_t imm16, Condition cond = AL) = 0;
393 virtual void movt(Register rd, uint16_t imm16, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700394
395 // Multiply instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700396 virtual void mul(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
397 virtual void mla(Register rd, Register rn, Register rm, Register ra,
398 Condition cond = AL) = 0;
399 virtual void mls(Register rd, Register rn, Register rm, Register ra,
400 Condition cond = AL) = 0;
401 virtual void umull(Register rd_lo, Register rd_hi, Register rn, Register rm,
402 Condition cond = AL) = 0;
403
404 virtual void sdiv(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
405 virtual void udiv(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700406
Roland Levillain981e4542014-11-14 11:47:14 +0000407 // Bit field extract instructions.
Roland Levillain51d3fc42014-11-13 14:11:42 +0000408 virtual void sbfx(Register rd, Register rn, uint32_t lsb, uint32_t width,
409 Condition cond = AL) = 0;
Roland Levillain981e4542014-11-14 11:47:14 +0000410 virtual void ubfx(Register rd, Register rn, uint32_t lsb, uint32_t width,
411 Condition cond = AL) = 0;
Roland Levillain51d3fc42014-11-13 14:11:42 +0000412
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700413 // Load/store instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700414 virtual void ldr(Register rd, const Address& ad, Condition cond = AL) = 0;
415 virtual void str(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700416
Dave Allison65fcc2c2014-04-28 13:45:27 -0700417 virtual void ldrb(Register rd, const Address& ad, Condition cond = AL) = 0;
418 virtual void strb(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700419
Dave Allison65fcc2c2014-04-28 13:45:27 -0700420 virtual void ldrh(Register rd, const Address& ad, Condition cond = AL) = 0;
421 virtual void strh(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700422
Dave Allison65fcc2c2014-04-28 13:45:27 -0700423 virtual void ldrsb(Register rd, const Address& ad, Condition cond = AL) = 0;
424 virtual void ldrsh(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700425
Dave Allison65fcc2c2014-04-28 13:45:27 -0700426 virtual void ldrd(Register rd, const Address& ad, Condition cond = AL) = 0;
427 virtual void strd(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700428
Dave Allison65fcc2c2014-04-28 13:45:27 -0700429 virtual void ldm(BlockAddressMode am, Register base,
430 RegList regs, Condition cond = AL) = 0;
431 virtual void stm(BlockAddressMode am, Register base,
432 RegList regs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700433
Dave Allison65fcc2c2014-04-28 13:45:27 -0700434 virtual void ldrex(Register rd, Register rn, Condition cond = AL) = 0;
435 virtual void strex(Register rd, Register rt, Register rn, Condition cond = AL) = 0;
Calin Juravle52c48962014-12-16 17:02:57 +0000436 virtual void ldrexd(Register rt, Register rt2, Register rn, Condition cond = AL) = 0;
437 virtual void strexd(Register rd, Register rt, Register rt2, Register rn, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700438
439 // Miscellaneous instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700440 virtual void clrex(Condition cond = AL) = 0;
441 virtual void nop(Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700442
443 // Note that gdb sets breakpoints using the undefined instruction 0xe7f001f0.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700444 virtual void bkpt(uint16_t imm16) = 0;
445 virtual void svc(uint32_t imm24) = 0;
446
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700447 virtual void it(Condition firstcond ATTRIBUTE_UNUSED,
448 ItState i1 ATTRIBUTE_UNUSED = kItOmitted,
449 ItState i2 ATTRIBUTE_UNUSED = kItOmitted,
450 ItState i3 ATTRIBUTE_UNUSED = kItOmitted) {
Dave Allison65fcc2c2014-04-28 13:45:27 -0700451 // Ignored if not supported.
452 }
453
454 virtual void cbz(Register rn, Label* target) = 0;
455 virtual void cbnz(Register rn, Label* target) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700456
457 // Floating point instructions (VFPv3-D16 and VFPv3-D32 profiles).
Dave Allison65fcc2c2014-04-28 13:45:27 -0700458 virtual void vmovsr(SRegister sn, Register rt, Condition cond = AL) = 0;
459 virtual void vmovrs(Register rt, SRegister sn, Condition cond = AL) = 0;
460 virtual void vmovsrr(SRegister sm, Register rt, Register rt2, Condition cond = AL) = 0;
461 virtual void vmovrrs(Register rt, Register rt2, SRegister sm, Condition cond = AL) = 0;
462 virtual void vmovdrr(DRegister dm, Register rt, Register rt2, Condition cond = AL) = 0;
463 virtual void vmovrrd(Register rt, Register rt2, DRegister dm, Condition cond = AL) = 0;
464 virtual void vmovs(SRegister sd, SRegister sm, Condition cond = AL) = 0;
465 virtual void vmovd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700466
467 // Returns false if the immediate cannot be encoded.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700468 virtual bool vmovs(SRegister sd, float s_imm, Condition cond = AL) = 0;
469 virtual bool vmovd(DRegister dd, double d_imm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700470
Dave Allison65fcc2c2014-04-28 13:45:27 -0700471 virtual void vldrs(SRegister sd, const Address& ad, Condition cond = AL) = 0;
472 virtual void vstrs(SRegister sd, const Address& ad, Condition cond = AL) = 0;
473 virtual void vldrd(DRegister dd, const Address& ad, Condition cond = AL) = 0;
474 virtual void vstrd(DRegister dd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700475
Dave Allison65fcc2c2014-04-28 13:45:27 -0700476 virtual void vadds(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
477 virtual void vaddd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
478 virtual void vsubs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
479 virtual void vsubd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
480 virtual void vmuls(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
481 virtual void vmuld(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
482 virtual void vmlas(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
483 virtual void vmlad(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
484 virtual void vmlss(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
485 virtual void vmlsd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
486 virtual void vdivs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
487 virtual void vdivd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700488
Dave Allison65fcc2c2014-04-28 13:45:27 -0700489 virtual void vabss(SRegister sd, SRegister sm, Condition cond = AL) = 0;
490 virtual void vabsd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
491 virtual void vnegs(SRegister sd, SRegister sm, Condition cond = AL) = 0;
492 virtual void vnegd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
493 virtual void vsqrts(SRegister sd, SRegister sm, Condition cond = AL) = 0;
494 virtual void vsqrtd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700495
Dave Allison65fcc2c2014-04-28 13:45:27 -0700496 virtual void vcvtsd(SRegister sd, DRegister dm, Condition cond = AL) = 0;
497 virtual void vcvtds(DRegister dd, SRegister sm, Condition cond = AL) = 0;
498 virtual void vcvtis(SRegister sd, SRegister sm, Condition cond = AL) = 0;
499 virtual void vcvtid(SRegister sd, DRegister dm, Condition cond = AL) = 0;
500 virtual void vcvtsi(SRegister sd, SRegister sm, Condition cond = AL) = 0;
501 virtual void vcvtdi(DRegister dd, SRegister sm, Condition cond = AL) = 0;
502 virtual void vcvtus(SRegister sd, SRegister sm, Condition cond = AL) = 0;
503 virtual void vcvtud(SRegister sd, DRegister dm, Condition cond = AL) = 0;
504 virtual void vcvtsu(SRegister sd, SRegister sm, Condition cond = AL) = 0;
505 virtual void vcvtdu(DRegister dd, SRegister sm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700506
Dave Allison65fcc2c2014-04-28 13:45:27 -0700507 virtual void vcmps(SRegister sd, SRegister sm, Condition cond = AL) = 0;
508 virtual void vcmpd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
509 virtual void vcmpsz(SRegister sd, Condition cond = AL) = 0;
510 virtual void vcmpdz(DRegister dd, Condition cond = AL) = 0;
511 virtual void vmstat(Condition cond = AL) = 0; // VMRS APSR_nzcv, FPSCR
512
513 virtual void vpushs(SRegister reg, int nregs, Condition cond = AL) = 0;
514 virtual void vpushd(DRegister reg, int nregs, Condition cond = AL) = 0;
515 virtual void vpops(SRegister reg, int nregs, Condition cond = AL) = 0;
516 virtual void vpopd(DRegister reg, int nregs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700517
518 // Branch instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700519 virtual void b(Label* label, Condition cond = AL) = 0;
520 virtual void bl(Label* label, Condition cond = AL) = 0;
521 virtual void blx(Register rm, Condition cond = AL) = 0;
522 virtual void bx(Register rm, Condition cond = AL) = 0;
523
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100524 // Memory barriers.
525 virtual void dmb(DmbOptions flavor) = 0;
526
Dave Allison65fcc2c2014-04-28 13:45:27 -0700527 void Pad(uint32_t bytes);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700528
529 // Macros.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700530 // Most of these are pure virtual as they need to be implemented per instruction set.
531
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700532 // Add signed constant value to rd. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700533 virtual void AddConstant(Register rd, int32_t value, Condition cond = AL) = 0;
534 virtual void AddConstant(Register rd, Register rn, int32_t value,
535 Condition cond = AL) = 0;
536 virtual void AddConstantSetFlags(Register rd, Register rn, int32_t value,
537 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700538
539 // Load and Store. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700540 virtual void LoadImmediate(Register rd, int32_t value, Condition cond = AL) = 0;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000541 void LoadSImmediate(SRegister sd, float value, Condition cond = AL) {
542 if (!vmovs(sd, value, cond)) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +0000543 int32_t int_value = bit_cast<int32_t, float>(value);
544 if (int_value == bit_cast<int32_t, float>(0.0f)) {
545 // 0.0 is quite common, so we special case it by loading
546 // 2.0 in `sd` and then substracting it.
547 bool success = vmovs(sd, 2.0, cond);
548 CHECK(success);
549 vsubs(sd, sd, sd, cond);
550 } else {
551 LoadImmediate(IP, int_value, cond);
552 vmovsr(sd, IP, cond);
553 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000554 }
555 }
556
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000557 void LoadDImmediate(DRegister sd, double value, Condition cond = AL) {
558 if (!vmovd(sd, value, cond)) {
559 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +0000560 if (int_value == bit_cast<uint64_t, double>(0.0)) {
561 // 0.0 is quite common, so we special case it by loading
562 // 2.0 in `sd` and then substracting it.
563 bool success = vmovd(sd, 2.0, cond);
564 CHECK(success);
565 vsubd(sd, sd, sd, cond);
566 } else {
567 if (sd < 16) {
568 SRegister low = static_cast<SRegister>(sd << 1);
569 SRegister high = static_cast<SRegister>(low + 1);
570 LoadSImmediate(low, bit_cast<float, uint32_t>(Low32Bits(int_value)), cond);
571 if (High32Bits(int_value) == Low32Bits(int_value)) {
572 vmovs(high, low);
573 } else {
574 LoadSImmediate(high, bit_cast<float, uint32_t>(High32Bits(int_value)), cond);
575 }
576 } else {
577 LOG(FATAL) << "Unimplemented loading of double into a D register "
578 << "that cannot be split into two S registers";
579 }
580 }
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000581 }
582 }
583
Dave Allison65fcc2c2014-04-28 13:45:27 -0700584 virtual void MarkExceptionHandler(Label* label) = 0;
585 virtual void LoadFromOffset(LoadOperandType type,
586 Register reg,
587 Register base,
588 int32_t offset,
589 Condition cond = AL) = 0;
590 virtual void StoreToOffset(StoreOperandType type,
591 Register reg,
592 Register base,
593 int32_t offset,
594 Condition cond = AL) = 0;
595 virtual void LoadSFromOffset(SRegister reg,
596 Register base,
597 int32_t offset,
598 Condition cond = AL) = 0;
599 virtual void StoreSToOffset(SRegister reg,
600 Register base,
601 int32_t offset,
602 Condition cond = AL) = 0;
603 virtual void LoadDFromOffset(DRegister reg,
604 Register base,
605 int32_t offset,
606 Condition cond = AL) = 0;
607 virtual void StoreDToOffset(DRegister reg,
608 Register base,
609 int32_t offset,
610 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700611
Dave Allison65fcc2c2014-04-28 13:45:27 -0700612 virtual void Push(Register rd, Condition cond = AL) = 0;
613 virtual void Pop(Register rd, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700614
Dave Allison65fcc2c2014-04-28 13:45:27 -0700615 virtual void PushList(RegList regs, Condition cond = AL) = 0;
616 virtual void PopList(RegList regs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700617
Dave Allison65fcc2c2014-04-28 13:45:27 -0700618 virtual void Mov(Register rd, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700619
620 // Convenience shift instructions. Use mov instruction with shifter operand
621 // for variants setting the status flags or using a register shift count.
Dave Allison45fdb932014-06-25 12:37:10 -0700622 virtual void Lsl(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
623 Condition cond = AL) = 0;
624 virtual void Lsr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
625 Condition cond = AL) = 0;
626 virtual void Asr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
627 Condition cond = AL) = 0;
628 virtual void Ror(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
629 Condition cond = AL) = 0;
630 virtual void Rrx(Register rd, Register rm, bool setcc = false,
631 Condition cond = AL) = 0;
632
633 virtual void Lsl(Register rd, Register rm, Register rn, bool setcc = false,
634 Condition cond = AL) = 0;
635 virtual void Lsr(Register rd, Register rm, Register rn, bool setcc = false,
636 Condition cond = AL) = 0;
637 virtual void Asr(Register rd, Register rm, Register rn, bool setcc = false,
638 Condition cond = AL) = 0;
639 virtual void Ror(Register rd, Register rm, Register rn, bool setcc = false,
640 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700641
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000642 // Returns whether the `immediate` can fit in a `ShifterOperand`. If yes,
643 // `shifter_op` contains the operand.
644 virtual bool ShifterOperandCanHold(Register rd,
645 Register rn,
646 Opcode opcode,
647 uint32_t immediate,
648 ShifterOperand* shifter_op) = 0;
649
Ian Rogers13735952014-10-08 12:43:28 -0700650 static bool IsInstructionForExceptionHandling(uintptr_t pc);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700651
Dave Allison65fcc2c2014-04-28 13:45:27 -0700652 virtual void Bind(Label* label) = 0;
653
654 virtual void CompareAndBranchIfZero(Register r, Label* label) = 0;
655 virtual void CompareAndBranchIfNonZero(Register r, Label* label) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700656
Ian Rogers2c8f6532011-09-02 17:16:34 -0700657 //
658 // Overridden common assembler high-level functionality
659 //
Ian Rogers45a76cb2011-07-21 22:00:15 -0700660
Ian Rogers2c8f6532011-09-02 17:16:34 -0700661 // Emit code that will create an activation on the stack
Ian Rogersdd7624d2014-03-14 17:43:00 -0700662 void BuildFrame(size_t frame_size, ManagedRegister method_reg,
663 const std::vector<ManagedRegister>& callee_save_regs,
664 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
Ian Rogersb033c752011-07-20 12:22:35 -0700665
Ian Rogers2c8f6532011-09-02 17:16:34 -0700666 // Emit code that will remove an activation from the stack
Ian Rogersdd7624d2014-03-14 17:43:00 -0700667 void RemoveFrame(size_t frame_size, const std::vector<ManagedRegister>& callee_save_regs)
Dave Allison65fcc2c2014-04-28 13:45:27 -0700668 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700669
Ian Rogersdd7624d2014-03-14 17:43:00 -0700670 void IncreaseFrameSize(size_t adjust) OVERRIDE;
671 void DecreaseFrameSize(size_t adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700672
673 // Store routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700674 void Store(FrameOffset offs, ManagedRegister src, size_t size) OVERRIDE;
675 void StoreRef(FrameOffset dest, ManagedRegister src) OVERRIDE;
676 void StoreRawPtr(FrameOffset dest, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700677
Ian Rogersdd7624d2014-03-14 17:43:00 -0700678 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700679
Ian Rogersdd7624d2014-03-14 17:43:00 -0700680 void StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm, ManagedRegister scratch)
681 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700682
Ian Rogersdd7624d2014-03-14 17:43:00 -0700683 void StoreStackOffsetToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs,
684 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700685
Ian Rogersdd7624d2014-03-14 17:43:00 -0700686 void StoreStackPointerToThread32(ThreadOffset<4> thr_offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700687
Ian Rogersdd7624d2014-03-14 17:43:00 -0700688 void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off,
689 ManagedRegister scratch) OVERRIDE;
Ian Rogersbdb03912011-09-14 00:55:44 -0700690
Ian Rogers2c8f6532011-09-02 17:16:34 -0700691 // Load routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700692 void Load(ManagedRegister dest, FrameOffset src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700693
Ian Rogersdd7624d2014-03-14 17:43:00 -0700694 void LoadFromThread32(ManagedRegister dest, ThreadOffset<4> src, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700695
Ian Rogersdd7624d2014-03-14 17:43:00 -0700696 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700697
Ian Rogersdd7624d2014-03-14 17:43:00 -0700698 void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700699
Ian Rogersdd7624d2014-03-14 17:43:00 -0700700 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700701
Ian Rogersdd7624d2014-03-14 17:43:00 -0700702 void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset<4> offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700703
704 // Copying routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700705 void Move(ManagedRegister dest, ManagedRegister src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700706
Ian Rogersdd7624d2014-03-14 17:43:00 -0700707 void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset<4> thr_offs,
708 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700709
Ian Rogersdd7624d2014-03-14 17:43:00 -0700710 void CopyRawPtrToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs, ManagedRegister scratch)
711 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700712
Ian Rogersdd7624d2014-03-14 17:43:00 -0700713 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700714
Ian Rogersdd7624d2014-03-14 17:43:00 -0700715 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700716
Ian Rogersdd7624d2014-03-14 17:43:00 -0700717 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister scratch,
718 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700719
Ian Rogersdd7624d2014-03-14 17:43:00 -0700720 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, ManagedRegister scratch,
721 size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700722
Ian Rogersdd7624d2014-03-14 17:43:00 -0700723 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister scratch,
724 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700725
Ian Rogersdd7624d2014-03-14 17:43:00 -0700726 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
727 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700728
Ian Rogersdd7624d2014-03-14 17:43:00 -0700729 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
730 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700731
jeffhao58136ca2012-05-24 13:40:11 -0700732 // Sign extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700733 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao58136ca2012-05-24 13:40:11 -0700734
jeffhaocee4d0c2012-06-15 14:42:01 -0700735 // Zero extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700736 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhaocee4d0c2012-06-15 14:42:01 -0700737
Ian Rogers2c8f6532011-09-02 17:16:34 -0700738 // Exploit fast access in managed code to Thread::Current()
Ian Rogersdd7624d2014-03-14 17:43:00 -0700739 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
740 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700741
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700742 // 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 -0700743 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700744 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700745 // null.
746 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
747 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700748
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700749 // 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 -0700750 // value is null and null_allowed.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700751 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
752 ManagedRegister scratch, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700753
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700754 // src holds a handle scope entry (Object**) load this into dst
755 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700756
757 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
758 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700759 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
760 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700761
762 // Call to address held at [base+offset]
Ian Rogersdd7624d2014-03-14 17:43:00 -0700763 void Call(ManagedRegister base, Offset offset, ManagedRegister scratch) OVERRIDE;
764 void Call(FrameOffset base, Offset offset, ManagedRegister scratch) OVERRIDE;
765 void CallFromThread32(ThreadOffset<4> offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700766
Ian Rogers2c8f6532011-09-02 17:16:34 -0700767 // Generate code to check if Thread::Current()->exception_ is non-null
768 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700769 void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) OVERRIDE;
Ian Rogersb033c752011-07-20 12:22:35 -0700770
Dave Allison65fcc2c2014-04-28 13:45:27 -0700771 static uint32_t ModifiedImmediate(uint32_t value);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700772
Dave Allison45fdb932014-06-25 12:37:10 -0700773 static bool IsLowRegister(Register r) {
774 return r < R8;
775 }
776
777 static bool IsHighRegister(Register r) {
778 return r >= R8;
779 }
780
Dave Allison65fcc2c2014-04-28 13:45:27 -0700781 protected:
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700782 // Returns whether or not the given register is used for passing parameters.
783 static int RegisterCompare(const Register* reg1, const Register* reg2) {
784 return *reg1 - *reg2;
785 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700786};
787
Ian Rogers2c8f6532011-09-02 17:16:34 -0700788// Slowpath entered when Thread::Current()->_exception is non-null
Ian Rogersdd7624d2014-03-14 17:43:00 -0700789class ArmExceptionSlowPath FINAL : public SlowPath {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700790 public:
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700791 explicit ArmExceptionSlowPath(ArmManagedRegister scratch, size_t stack_adjust)
792 : scratch_(scratch), stack_adjust_(stack_adjust) {
793 }
Ian Rogersdd7624d2014-03-14 17:43:00 -0700794 void Emit(Assembler *sp_asm) OVERRIDE;
Ian Rogers67375ac2011-09-14 00:55:44 -0700795 private:
796 const ArmManagedRegister scratch_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700797 const size_t stack_adjust_;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700798};
799
Ian Rogers2c8f6532011-09-02 17:16:34 -0700800} // namespace arm
Ian Rogersb033c752011-07-20 12:22:35 -0700801} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700802
Ian Rogers166db042013-07-26 12:05:57 -0700803#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_H_