blob: e5d42f9a5e241d3d5e1c55bf37650d29ff913ab4 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright (c) 1994-2006 Sun Microsystems Inc.
2// All Rights Reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions
6// are met:
7//
8// - Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10//
11// - Redistribution in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the
14// distribution.
15//
16// - Neither the name of Sun Microsystems or the names of contributors may
17// be used to endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31// OF THE POSSIBILITY OF SUCH DAMAGE.
32
Leon Clarked91b9f72010-01-27 17:25:45 +000033// The original source code covered by the above license above has been
34// modified significantly by Google Inc.
35// Copyright 2010 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +000036
37// A light-weight ARM Assembler
38// Generates user mode instructions for the ARM architecture up to version 5
39
40#ifndef V8_ARM_ASSEMBLER_ARM_H_
41#define V8_ARM_ASSEMBLER_ARM_H_
42#include <stdio.h>
43#include "assembler.h"
Steve Blockd0582a62009-12-15 09:54:21 +000044#include "serialize.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000045
46namespace v8 {
47namespace internal {
48
49// CPU Registers.
50//
51// 1) We would prefer to use an enum, but enum values are assignment-
52// compatible with int, which has caused code-generation bugs.
53//
54// 2) We would prefer to use a class instead of a struct but we don't like
55// the register initialization to depend on the particular initialization
56// order (which appears to be different on OS X, Linux, and Windows for the
57// installed versions of C++ we tried). Using a struct permits C-style
58// "initialization". Also, the Register objects cannot be const as this
59// forces initialization stubs in MSVC, making us dependent on initialization
60// order.
61//
62// 3) By not using an enum, we are possibly preventing the compiler from
63// doing certain constant folds, which may significantly reduce the
64// code generated for some assembly instructions (because they boil down
65// to a few constants). If this is a problem, we could change the code
66// such that we use an enum in optimized mode, and the struct in debug
67// mode. This way we get the compile-time error checking in debug mode
68// and best performance in optimized code.
69//
70// Core register
71struct Register {
72 bool is_valid() const { return 0 <= code_ && code_ < 16; }
73 bool is(Register reg) const { return code_ == reg.code_; }
74 int code() const {
75 ASSERT(is_valid());
76 return code_;
77 }
78 int bit() const {
79 ASSERT(is_valid());
80 return 1 << code_;
81 }
82
Leon Clarkef7060e22010-06-03 12:02:55 +010083 void set_code(int code) {
84 code_ = code;
85 ASSERT(is_valid());
86 }
87
Andrei Popescu31002712010-02-23 13:46:05 +000088 // Unfortunately we can't make this private in a struct.
Steve Blocka7e24c12009-10-30 11:49:00 +000089 int code_;
90};
91
Steve Block6ded16b2010-05-10 14:33:55 +010092const Register no_reg = { -1 };
Steve Blocka7e24c12009-10-30 11:49:00 +000093
Steve Block6ded16b2010-05-10 14:33:55 +010094const Register r0 = { 0 };
95const Register r1 = { 1 };
96const Register r2 = { 2 };
97const Register r3 = { 3 };
98const Register r4 = { 4 };
99const Register r5 = { 5 };
100const Register r6 = { 6 };
101const Register r7 = { 7 };
102const Register r8 = { 8 }; // Used as context register.
103const Register r9 = { 9 };
104const Register r10 = { 10 }; // Used as roots register.
105const Register fp = { 11 };
106const Register ip = { 12 };
107const Register sp = { 13 };
108const Register lr = { 14 };
109const Register pc = { 15 };
Steve Blockd0582a62009-12-15 09:54:21 +0000110
Leon Clarkee46be812010-01-19 14:06:41 +0000111// Single word VFP register.
112struct SwVfpRegister {
113 bool is_valid() const { return 0 <= code_ && code_ < 32; }
114 bool is(SwVfpRegister reg) const { return code_ == reg.code_; }
115 int code() const {
116 ASSERT(is_valid());
117 return code_;
118 }
119 int bit() const {
120 ASSERT(is_valid());
121 return 1 << code_;
122 }
123
124 int code_;
125};
126
127
128// Double word VFP register.
129struct DwVfpRegister {
130 // Supporting d0 to d15, can be later extended to d31.
131 bool is_valid() const { return 0 <= code_ && code_ < 16; }
132 bool is(DwVfpRegister reg) const { return code_ == reg.code_; }
133 int code() const {
134 ASSERT(is_valid());
135 return code_;
136 }
137 int bit() const {
138 ASSERT(is_valid());
139 return 1 << code_;
140 }
141
142 int code_;
143};
144
145
Steve Block6ded16b2010-05-10 14:33:55 +0100146// Support for the VFP registers s0 to s31 (d0 to d15).
Leon Clarkee46be812010-01-19 14:06:41 +0000147// Note that "s(N):s(N+1)" is the same as "d(N/2)".
Steve Block6ded16b2010-05-10 14:33:55 +0100148const SwVfpRegister s0 = { 0 };
149const SwVfpRegister s1 = { 1 };
150const SwVfpRegister s2 = { 2 };
151const SwVfpRegister s3 = { 3 };
152const SwVfpRegister s4 = { 4 };
153const SwVfpRegister s5 = { 5 };
154const SwVfpRegister s6 = { 6 };
155const SwVfpRegister s7 = { 7 };
156const SwVfpRegister s8 = { 8 };
157const SwVfpRegister s9 = { 9 };
158const SwVfpRegister s10 = { 10 };
159const SwVfpRegister s11 = { 11 };
160const SwVfpRegister s12 = { 12 };
161const SwVfpRegister s13 = { 13 };
162const SwVfpRegister s14 = { 14 };
163const SwVfpRegister s15 = { 15 };
164const SwVfpRegister s16 = { 16 };
165const SwVfpRegister s17 = { 17 };
166const SwVfpRegister s18 = { 18 };
167const SwVfpRegister s19 = { 19 };
168const SwVfpRegister s20 = { 20 };
169const SwVfpRegister s21 = { 21 };
170const SwVfpRegister s22 = { 22 };
171const SwVfpRegister s23 = { 23 };
172const SwVfpRegister s24 = { 24 };
173const SwVfpRegister s25 = { 25 };
174const SwVfpRegister s26 = { 26 };
175const SwVfpRegister s27 = { 27 };
176const SwVfpRegister s28 = { 28 };
177const SwVfpRegister s29 = { 29 };
178const SwVfpRegister s30 = { 30 };
179const SwVfpRegister s31 = { 31 };
Leon Clarkee46be812010-01-19 14:06:41 +0000180
Steve Block6ded16b2010-05-10 14:33:55 +0100181const DwVfpRegister d0 = { 0 };
182const DwVfpRegister d1 = { 1 };
183const DwVfpRegister d2 = { 2 };
184const DwVfpRegister d3 = { 3 };
185const DwVfpRegister d4 = { 4 };
186const DwVfpRegister d5 = { 5 };
187const DwVfpRegister d6 = { 6 };
188const DwVfpRegister d7 = { 7 };
189const DwVfpRegister d8 = { 8 };
190const DwVfpRegister d9 = { 9 };
191const DwVfpRegister d10 = { 10 };
192const DwVfpRegister d11 = { 11 };
193const DwVfpRegister d12 = { 12 };
194const DwVfpRegister d13 = { 13 };
195const DwVfpRegister d14 = { 14 };
196const DwVfpRegister d15 = { 15 };
Leon Clarkee46be812010-01-19 14:06:41 +0000197
Steve Blocka7e24c12009-10-30 11:49:00 +0000198
199// Coprocessor register
200struct CRegister {
201 bool is_valid() const { return 0 <= code_ && code_ < 16; }
202 bool is(CRegister creg) const { return code_ == creg.code_; }
203 int code() const {
204 ASSERT(is_valid());
205 return code_;
206 }
207 int bit() const {
208 ASSERT(is_valid());
209 return 1 << code_;
210 }
211
Andrei Popescu31002712010-02-23 13:46:05 +0000212 // Unfortunately we can't make this private in a struct.
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 int code_;
214};
215
216
Steve Block6ded16b2010-05-10 14:33:55 +0100217const CRegister no_creg = { -1 };
218
219const CRegister cr0 = { 0 };
220const CRegister cr1 = { 1 };
221const CRegister cr2 = { 2 };
222const CRegister cr3 = { 3 };
223const CRegister cr4 = { 4 };
224const CRegister cr5 = { 5 };
225const CRegister cr6 = { 6 };
226const CRegister cr7 = { 7 };
227const CRegister cr8 = { 8 };
228const CRegister cr9 = { 9 };
229const CRegister cr10 = { 10 };
230const CRegister cr11 = { 11 };
231const CRegister cr12 = { 12 };
232const CRegister cr13 = { 13 };
233const CRegister cr14 = { 14 };
234const CRegister cr15 = { 15 };
Steve Blocka7e24c12009-10-30 11:49:00 +0000235
236
237// Coprocessor number
238enum Coprocessor {
239 p0 = 0,
240 p1 = 1,
241 p2 = 2,
242 p3 = 3,
243 p4 = 4,
244 p5 = 5,
245 p6 = 6,
246 p7 = 7,
247 p8 = 8,
248 p9 = 9,
249 p10 = 10,
250 p11 = 11,
251 p12 = 12,
252 p13 = 13,
253 p14 = 14,
254 p15 = 15
255};
256
257
Andrei Popescu31002712010-02-23 13:46:05 +0000258// Condition field in instructions.
Steve Blocka7e24c12009-10-30 11:49:00 +0000259enum Condition {
260 eq = 0 << 28, // Z set equal.
261 ne = 1 << 28, // Z clear not equal.
262 nz = 1 << 28, // Z clear not zero.
263 cs = 2 << 28, // C set carry set.
264 hs = 2 << 28, // C set unsigned higher or same.
265 cc = 3 << 28, // C clear carry clear.
266 lo = 3 << 28, // C clear unsigned lower.
267 mi = 4 << 28, // N set negative.
268 pl = 5 << 28, // N clear positive or zero.
269 vs = 6 << 28, // V set overflow.
270 vc = 7 << 28, // V clear no overflow.
271 hi = 8 << 28, // C set, Z clear unsigned higher.
272 ls = 9 << 28, // C clear or Z set unsigned lower or same.
273 ge = 10 << 28, // N == V greater or equal.
274 lt = 11 << 28, // N != V less than.
275 gt = 12 << 28, // Z clear, N == V greater than.
276 le = 13 << 28, // Z set or N != V less then or equal
277 al = 14 << 28 // always.
278};
279
280
281// Returns the equivalent of !cc.
282INLINE(Condition NegateCondition(Condition cc));
283
284
285// Corresponds to transposing the operands of a comparison.
286inline Condition ReverseCondition(Condition cc) {
287 switch (cc) {
288 case lo:
289 return hi;
290 case hi:
291 return lo;
292 case hs:
293 return ls;
294 case ls:
295 return hs;
296 case lt:
297 return gt;
298 case gt:
299 return lt;
300 case ge:
301 return le;
302 case le:
303 return ge;
304 default:
305 return cc;
306 };
307}
308
309
310// Branch hints are not used on the ARM. They are defined so that they can
311// appear in shared function signatures, but will be ignored in ARM
312// implementations.
313enum Hint { no_hint };
314
315// Hints are not used on the arm. Negating is trivial.
316inline Hint NegateHint(Hint ignored) { return no_hint; }
317
318
319// -----------------------------------------------------------------------------
320// Addressing modes and instruction variants
321
322// Shifter operand shift operation
323enum ShiftOp {
324 LSL = 0 << 5,
325 LSR = 1 << 5,
326 ASR = 2 << 5,
327 ROR = 3 << 5,
328 RRX = -1
329};
330
331
332// Condition code updating mode
333enum SBit {
334 SetCC = 1 << 20, // set condition code
335 LeaveCC = 0 << 20 // leave condition code unchanged
336};
337
338
339// Status register selection
340enum SRegister {
341 CPSR = 0 << 22,
342 SPSR = 1 << 22
343};
344
345
346// Status register fields
347enum SRegisterField {
348 CPSR_c = CPSR | 1 << 16,
349 CPSR_x = CPSR | 1 << 17,
350 CPSR_s = CPSR | 1 << 18,
351 CPSR_f = CPSR | 1 << 19,
352 SPSR_c = SPSR | 1 << 16,
353 SPSR_x = SPSR | 1 << 17,
354 SPSR_s = SPSR | 1 << 18,
355 SPSR_f = SPSR | 1 << 19
356};
357
358// Status register field mask (or'ed SRegisterField enum values)
359typedef uint32_t SRegisterFieldMask;
360
361
362// Memory operand addressing mode
363enum AddrMode {
364 // bit encoding P U W
365 Offset = (8|4|0) << 21, // offset (without writeback to base)
366 PreIndex = (8|4|1) << 21, // pre-indexed addressing with writeback
367 PostIndex = (0|4|0) << 21, // post-indexed addressing with writeback
368 NegOffset = (8|0|0) << 21, // negative offset (without writeback to base)
369 NegPreIndex = (8|0|1) << 21, // negative pre-indexed with writeback
370 NegPostIndex = (0|0|0) << 21 // negative post-indexed with writeback
371};
372
373
374// Load/store multiple addressing mode
375enum BlockAddrMode {
376 // bit encoding P U W
377 da = (0|0|0) << 21, // decrement after
378 ia = (0|4|0) << 21, // increment after
379 db = (8|0|0) << 21, // decrement before
380 ib = (8|4|0) << 21, // increment before
381 da_w = (0|0|1) << 21, // decrement after with writeback to base
382 ia_w = (0|4|1) << 21, // increment after with writeback to base
383 db_w = (8|0|1) << 21, // decrement before with writeback to base
384 ib_w = (8|4|1) << 21 // increment before with writeback to base
385};
386
387
388// Coprocessor load/store operand size
389enum LFlag {
390 Long = 1 << 22, // long load/store coprocessor
391 Short = 0 << 22 // short load/store coprocessor
392};
393
394
395// -----------------------------------------------------------------------------
396// Machine instruction Operands
397
398// Class Operand represents a shifter operand in data processing instructions
399class Operand BASE_EMBEDDED {
400 public:
401 // immediate
402 INLINE(explicit Operand(int32_t immediate,
403 RelocInfo::Mode rmode = RelocInfo::NONE));
404 INLINE(explicit Operand(const ExternalReference& f));
405 INLINE(explicit Operand(const char* s));
Steve Blocka7e24c12009-10-30 11:49:00 +0000406 explicit Operand(Handle<Object> handle);
407 INLINE(explicit Operand(Smi* value));
408
409 // rm
410 INLINE(explicit Operand(Register rm));
411
412 // rm <shift_op> shift_imm
413 explicit Operand(Register rm, ShiftOp shift_op, int shift_imm);
414
415 // rm <shift_op> rs
416 explicit Operand(Register rm, ShiftOp shift_op, Register rs);
417
418 // Return true if this is a register operand.
419 INLINE(bool is_reg() const);
420
421 Register rm() const { return rm_; }
422
423 private:
424 Register rm_;
425 Register rs_;
426 ShiftOp shift_op_;
427 int shift_imm_; // valid if rm_ != no_reg && rs_ == no_reg
428 int32_t imm32_; // valid if rm_ == no_reg
429 RelocInfo::Mode rmode_;
430
431 friend class Assembler;
432};
433
434
435// Class MemOperand represents a memory operand in load and store instructions
436class MemOperand BASE_EMBEDDED {
437 public:
438 // [rn +/- offset] Offset/NegOffset
439 // [rn +/- offset]! PreIndex/NegPreIndex
440 // [rn], +/- offset PostIndex/NegPostIndex
441 // offset is any signed 32-bit value; offset is first loaded to register ip if
442 // it does not fit the addressing mode (12-bit unsigned and sign bit)
443 explicit MemOperand(Register rn, int32_t offset = 0, AddrMode am = Offset);
444
445 // [rn +/- rm] Offset/NegOffset
446 // [rn +/- rm]! PreIndex/NegPreIndex
447 // [rn], +/- rm PostIndex/NegPostIndex
448 explicit MemOperand(Register rn, Register rm, AddrMode am = Offset);
449
450 // [rn +/- rm <shift_op> shift_imm] Offset/NegOffset
451 // [rn +/- rm <shift_op> shift_imm]! PreIndex/NegPreIndex
452 // [rn], +/- rm <shift_op> shift_imm PostIndex/NegPostIndex
453 explicit MemOperand(Register rn, Register rm,
454 ShiftOp shift_op, int shift_imm, AddrMode am = Offset);
455
Kristian Monsen25f61362010-05-21 11:50:48 +0100456 void set_offset(int32_t offset) {
457 ASSERT(rm_.is(no_reg));
458 offset_ = offset;
459 }
460
461 uint32_t offset() {
462 ASSERT(rm_.is(no_reg));
463 return offset_;
464 }
465
Leon Clarkef7060e22010-06-03 12:02:55 +0100466 Register rn() const { return rn_; }
467 Register rm() const { return rm_; }
Kristian Monsen25f61362010-05-21 11:50:48 +0100468
Steve Blocka7e24c12009-10-30 11:49:00 +0000469 private:
470 Register rn_; // base
471 Register rm_; // register offset
472 int32_t offset_; // valid if rm_ == no_reg
473 ShiftOp shift_op_;
474 int shift_imm_; // valid if rm_ != no_reg && rs_ == no_reg
475 AddrMode am_; // bits P, U, and W
476
477 friend class Assembler;
478};
479
Steve Blockd0582a62009-12-15 09:54:21 +0000480// CpuFeatures keeps track of which features are supported by the target CPU.
481// Supported features must be enabled by a Scope before use.
482class CpuFeatures : public AllStatic {
483 public:
484 // Detect features of the target CPU. Set safe defaults if the serializer
485 // is enabled (snapshots must be portable).
486 static void Probe();
487
488 // Check whether a feature is supported by the target CPU.
489 static bool IsSupported(CpuFeature f) {
490 if (f == VFP3 && !FLAG_enable_vfp3) return false;
491 return (supported_ & (1u << f)) != 0;
492 }
493
494 // Check whether a feature is currently enabled.
495 static bool IsEnabled(CpuFeature f) {
496 return (enabled_ & (1u << f)) != 0;
497 }
498
499 // Enable a specified feature within a scope.
500 class Scope BASE_EMBEDDED {
501#ifdef DEBUG
502 public:
503 explicit Scope(CpuFeature f) {
504 ASSERT(CpuFeatures::IsSupported(f));
505 ASSERT(!Serializer::enabled() ||
506 (found_by_runtime_probing_ & (1u << f)) == 0);
507 old_enabled_ = CpuFeatures::enabled_;
508 CpuFeatures::enabled_ |= 1u << f;
509 }
510 ~Scope() { CpuFeatures::enabled_ = old_enabled_; }
511 private:
512 unsigned old_enabled_;
513#else
514 public:
515 explicit Scope(CpuFeature f) {}
516#endif
517 };
518
519 private:
520 static unsigned supported_;
521 static unsigned enabled_;
522 static unsigned found_by_runtime_probing_;
523};
524
Steve Blocka7e24c12009-10-30 11:49:00 +0000525
526typedef int32_t Instr;
527
528
529extern const Instr kMovLrPc;
Steve Block6ded16b2010-05-10 14:33:55 +0100530extern const Instr kLdrPCMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000531extern const Instr kLdrPCPattern;
Steve Block6ded16b2010-05-10 14:33:55 +0100532extern const Instr kBlxRegMask;
533extern const Instr kBlxRegPattern;
Steve Blocka7e24c12009-10-30 11:49:00 +0000534
535
536class Assembler : public Malloced {
537 public:
538 // Create an assembler. Instructions and relocation information are emitted
539 // into a buffer, with the instructions starting from the beginning and the
540 // relocation information starting from the end of the buffer. See CodeDesc
541 // for a detailed comment on the layout (globals.h).
542 //
543 // If the provided buffer is NULL, the assembler allocates and grows its own
544 // buffer, and buffer_size determines the initial buffer size. The buffer is
545 // owned by the assembler and deallocated upon destruction of the assembler.
546 //
547 // If the provided buffer is not NULL, the assembler uses the provided buffer
548 // for code generation and assumes its size to be buffer_size. If the buffer
549 // is too small, a fatal error occurs. No deallocation of the buffer is done
550 // upon destruction of the assembler.
551 Assembler(void* buffer, int buffer_size);
552 ~Assembler();
553
554 // GetCode emits any pending (non-emitted) code and fills the descriptor
555 // desc. GetCode() is idempotent; it returns the same result if no other
556 // Assembler functions are invoked in between GetCode() calls.
557 void GetCode(CodeDesc* desc);
558
559 // Label operations & relative jumps (PPUM Appendix D)
560 //
561 // Takes a branch opcode (cc) and a label (L) and generates
562 // either a backward branch or a forward branch and links it
563 // to the label fixup chain. Usage:
564 //
565 // Label L; // unbound label
566 // j(cc, &L); // forward branch to unbound label
567 // bind(&L); // bind label to the current pc
568 // j(cc, &L); // backward branch to bound label
569 // bind(&L); // illegal: a label may be bound only once
570 //
571 // Note: The same Label can be used for forward and backward branches
572 // but it may be bound only once.
573
574 void bind(Label* L); // binds an unbound label L to the current code position
575
576 // Returns the branch offset to the given label from the current code position
577 // Links the label to the current position if it is still unbound
578 // Manages the jump elimination optimization if the second parameter is true.
579 int branch_offset(Label* L, bool jump_elimination_allowed);
580
581 // Puts a labels target address at the given position.
582 // The high 8 bits are set to zero.
583 void label_at_put(Label* L, int at_offset);
584
585 // Return the address in the constant pool of the code target address used by
586 // the branch/call instruction at pc.
587 INLINE(static Address target_address_address_at(Address pc));
588
589 // Read/Modify the code target address in the branch/call instruction at pc.
590 INLINE(static Address target_address_at(Address pc));
591 INLINE(static void set_target_address_at(Address pc, Address target));
592
Steve Blockd0582a62009-12-15 09:54:21 +0000593 // This sets the branch destination (which is in the constant pool on ARM).
594 // This is for calls and branches within generated code.
595 inline static void set_target_at(Address constant_pool_entry, Address target);
596
597 // This sets the branch destination (which is in the constant pool on ARM).
598 // This is for calls and branches to runtime code.
599 inline static void set_external_target_at(Address constant_pool_entry,
600 Address target) {
601 set_target_at(constant_pool_entry, target);
602 }
603
604 // Here we are patching the address in the constant pool, not the actual call
605 // instruction. The address in the constant pool is the same size as a
606 // pointer.
607 static const int kCallTargetSize = kPointerSize;
608 static const int kExternalTargetSize = kPointerSize;
609
Steve Blocka7e24c12009-10-30 11:49:00 +0000610 // Size of an instruction.
611 static const int kInstrSize = sizeof(Instr);
612
613 // Distance between the instruction referring to the address of the call
Steve Block6ded16b2010-05-10 14:33:55 +0100614 // target and the return address.
615#ifdef USE_BLX
616 // Call sequence is:
617 // ldr ip, [pc, #...] @ call address
618 // blx ip
619 // @ return address
620 static const int kCallTargetAddressOffset = 2 * kInstrSize;
621#else
622 // Call sequence is:
623 // mov lr, pc
624 // ldr pc, [pc, #...] @ call address
625 // @ return address
Steve Blocka7e24c12009-10-30 11:49:00 +0000626 static const int kCallTargetAddressOffset = kInstrSize;
Steve Block6ded16b2010-05-10 14:33:55 +0100627#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000628
629 // Distance between start of patched return sequence and the emitted address
630 // to jump to.
Steve Block6ded16b2010-05-10 14:33:55 +0100631#ifdef USE_BLX
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100632 // Patched return sequence is:
Steve Block6ded16b2010-05-10 14:33:55 +0100633 // ldr ip, [pc, #0] @ emited address and start
634 // blx ip
635 static const int kPatchReturnSequenceAddressOffset = 0 * kInstrSize;
636#else
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100637 // Patched return sequence is:
Steve Block6ded16b2010-05-10 14:33:55 +0100638 // mov lr, pc @ start of sequence
639 // ldr pc, [pc, #-4] @ emited address
640 static const int kPatchReturnSequenceAddressOffset = kInstrSize;
641#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000642
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100643 // Distance between start of patched debug break slot and the emitted address
644 // to jump to.
645#ifdef USE_BLX
646 // Patched debug break slot code is:
647 // ldr ip, [pc, #0] @ emited address and start
648 // blx ip
649 static const int kPatchDebugBreakSlotAddressOffset = 0 * kInstrSize;
650#else
651 // Patched debug break slot code is:
652 // mov lr, pc @ start of sequence
653 // ldr pc, [pc, #-4] @ emited address
654 static const int kPatchDebugBreakSlotAddressOffset = kInstrSize;
655#endif
656
Steve Blocka7e24c12009-10-30 11:49:00 +0000657 // Difference between address of current opcode and value read from pc
658 // register.
659 static const int kPcLoadDelta = 8;
660
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100661 static const int kJSReturnSequenceInstructions = 4;
662 static const int kDebugBreakSlotInstructions = 3;
663 static const int kDebugBreakSlotLength =
664 kDebugBreakSlotInstructions * kInstrSize;
Steve Blocka7e24c12009-10-30 11:49:00 +0000665
666 // ---------------------------------------------------------------------------
667 // Code generation
668
669 // Insert the smallest number of nop instructions
670 // possible to align the pc offset to a multiple
671 // of m. m must be a power of 2 (>= 4).
672 void Align(int m);
673
674 // Branch instructions
675 void b(int branch_offset, Condition cond = al);
676 void bl(int branch_offset, Condition cond = al);
677 void blx(int branch_offset); // v5 and above
678 void blx(Register target, Condition cond = al); // v5 and above
679 void bx(Register target, Condition cond = al); // v5 and above, plus v4t
680
681 // Convenience branch instructions using labels
682 void b(Label* L, Condition cond = al) {
683 b(branch_offset(L, cond == al), cond);
684 }
685 void b(Condition cond, Label* L) { b(branch_offset(L, cond == al), cond); }
686 void bl(Label* L, Condition cond = al) { bl(branch_offset(L, false), cond); }
687 void bl(Condition cond, Label* L) { bl(branch_offset(L, false), cond); }
688 void blx(Label* L) { blx(branch_offset(L, false)); } // v5 and above
689
690 // Data-processing instructions
Andrei Popescu31002712010-02-23 13:46:05 +0000691
Steve Blocka7e24c12009-10-30 11:49:00 +0000692 void and_(Register dst, Register src1, const Operand& src2,
693 SBit s = LeaveCC, Condition cond = al);
694
695 void eor(Register dst, Register src1, const Operand& src2,
696 SBit s = LeaveCC, Condition cond = al);
697
698 void sub(Register dst, Register src1, const Operand& src2,
699 SBit s = LeaveCC, Condition cond = al);
700 void sub(Register dst, Register src1, Register src2,
701 SBit s = LeaveCC, Condition cond = al) {
702 sub(dst, src1, Operand(src2), s, cond);
703 }
704
705 void rsb(Register dst, Register src1, const Operand& src2,
706 SBit s = LeaveCC, Condition cond = al);
707
708 void add(Register dst, Register src1, const Operand& src2,
709 SBit s = LeaveCC, Condition cond = al);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100710 void add(Register dst, Register src1, Register src2,
711 SBit s = LeaveCC, Condition cond = al) {
712 add(dst, src1, Operand(src2), s, cond);
713 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000714
715 void adc(Register dst, Register src1, const Operand& src2,
716 SBit s = LeaveCC, Condition cond = al);
717
718 void sbc(Register dst, Register src1, const Operand& src2,
719 SBit s = LeaveCC, Condition cond = al);
720
721 void rsc(Register dst, Register src1, const Operand& src2,
722 SBit s = LeaveCC, Condition cond = al);
723
724 void tst(Register src1, const Operand& src2, Condition cond = al);
725 void tst(Register src1, Register src2, Condition cond = al) {
726 tst(src1, Operand(src2), cond);
727 }
728
729 void teq(Register src1, const Operand& src2, Condition cond = al);
730
731 void cmp(Register src1, const Operand& src2, Condition cond = al);
732 void cmp(Register src1, Register src2, Condition cond = al) {
733 cmp(src1, Operand(src2), cond);
734 }
735
736 void cmn(Register src1, const Operand& src2, Condition cond = al);
737
738 void orr(Register dst, Register src1, const Operand& src2,
739 SBit s = LeaveCC, Condition cond = al);
740 void orr(Register dst, Register src1, Register src2,
741 SBit s = LeaveCC, Condition cond = al) {
742 orr(dst, src1, Operand(src2), s, cond);
743 }
744
745 void mov(Register dst, const Operand& src,
746 SBit s = LeaveCC, Condition cond = al);
747 void mov(Register dst, Register src, SBit s = LeaveCC, Condition cond = al) {
748 mov(dst, Operand(src), s, cond);
749 }
750
751 void bic(Register dst, Register src1, const Operand& src2,
752 SBit s = LeaveCC, Condition cond = al);
753
754 void mvn(Register dst, const Operand& src,
755 SBit s = LeaveCC, Condition cond = al);
756
757 // Multiply instructions
758
759 void mla(Register dst, Register src1, Register src2, Register srcA,
760 SBit s = LeaveCC, Condition cond = al);
761
762 void mul(Register dst, Register src1, Register src2,
763 SBit s = LeaveCC, Condition cond = al);
764
765 void smlal(Register dstL, Register dstH, Register src1, Register src2,
766 SBit s = LeaveCC, Condition cond = al);
767
768 void smull(Register dstL, Register dstH, Register src1, Register src2,
769 SBit s = LeaveCC, Condition cond = al);
770
771 void umlal(Register dstL, Register dstH, Register src1, Register src2,
772 SBit s = LeaveCC, Condition cond = al);
773
774 void umull(Register dstL, Register dstH, Register src1, Register src2,
775 SBit s = LeaveCC, Condition cond = al);
776
777 // Miscellaneous arithmetic instructions
778
779 void clz(Register dst, Register src, Condition cond = al); // v5 and above
780
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100781 // Bitfield manipulation instructions. v7 and above.
782
783 void ubfx(Register dst, Register src, int lsb, int width,
784 Condition cond = al);
785
786 void sbfx(Register dst, Register src, int lsb, int width,
787 Condition cond = al);
788
789 void bfc(Register dst, int lsb, int width, Condition cond = al);
790
791 void bfi(Register dst, Register src, int lsb, int width,
792 Condition cond = al);
793
Steve Blocka7e24c12009-10-30 11:49:00 +0000794 // Status register access instructions
795
796 void mrs(Register dst, SRegister s, Condition cond = al);
797 void msr(SRegisterFieldMask fields, const Operand& src, Condition cond = al);
798
799 // Load/Store instructions
800 void ldr(Register dst, const MemOperand& src, Condition cond = al);
801 void str(Register src, const MemOperand& dst, Condition cond = al);
802 void ldrb(Register dst, const MemOperand& src, Condition cond = al);
803 void strb(Register src, const MemOperand& dst, Condition cond = al);
804 void ldrh(Register dst, const MemOperand& src, Condition cond = al);
805 void strh(Register src, const MemOperand& dst, Condition cond = al);
806 void ldrsb(Register dst, const MemOperand& src, Condition cond = al);
807 void ldrsh(Register dst, const MemOperand& src, Condition cond = al);
Leon Clarkef7060e22010-06-03 12:02:55 +0100808 void ldrd(Register dst1,
809 Register dst2,
810 const MemOperand& src, Condition cond = al);
811 void strd(Register src1,
812 Register src2,
813 const MemOperand& dst, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000814
815 // Load/Store multiple instructions
816 void ldm(BlockAddrMode am, Register base, RegList dst, Condition cond = al);
817 void stm(BlockAddrMode am, Register base, RegList src, Condition cond = al);
818
Steve Blocka7e24c12009-10-30 11:49:00 +0000819 // Exception-generating instructions and debugging support
820 void stop(const char* msg);
821
822 void bkpt(uint32_t imm16); // v5 and above
823 void swi(uint32_t imm24, Condition cond = al);
824
825 // Coprocessor instructions
826
827 void cdp(Coprocessor coproc, int opcode_1,
828 CRegister crd, CRegister crn, CRegister crm,
829 int opcode_2, Condition cond = al);
830
831 void cdp2(Coprocessor coproc, int opcode_1,
832 CRegister crd, CRegister crn, CRegister crm,
833 int opcode_2); // v5 and above
834
835 void mcr(Coprocessor coproc, int opcode_1,
836 Register rd, CRegister crn, CRegister crm,
837 int opcode_2 = 0, Condition cond = al);
838
839 void mcr2(Coprocessor coproc, int opcode_1,
840 Register rd, CRegister crn, CRegister crm,
841 int opcode_2 = 0); // v5 and above
842
843 void mrc(Coprocessor coproc, int opcode_1,
844 Register rd, CRegister crn, CRegister crm,
845 int opcode_2 = 0, Condition cond = al);
846
847 void mrc2(Coprocessor coproc, int opcode_1,
848 Register rd, CRegister crn, CRegister crm,
849 int opcode_2 = 0); // v5 and above
850
851 void ldc(Coprocessor coproc, CRegister crd, const MemOperand& src,
852 LFlag l = Short, Condition cond = al);
853 void ldc(Coprocessor coproc, CRegister crd, Register base, int option,
854 LFlag l = Short, Condition cond = al);
855
856 void ldc2(Coprocessor coproc, CRegister crd, const MemOperand& src,
857 LFlag l = Short); // v5 and above
858 void ldc2(Coprocessor coproc, CRegister crd, Register base, int option,
859 LFlag l = Short); // v5 and above
860
861 void stc(Coprocessor coproc, CRegister crd, const MemOperand& dst,
862 LFlag l = Short, Condition cond = al);
863 void stc(Coprocessor coproc, CRegister crd, Register base, int option,
864 LFlag l = Short, Condition cond = al);
865
866 void stc2(Coprocessor coproc, CRegister crd, const MemOperand& dst,
867 LFlag l = Short); // v5 and above
868 void stc2(Coprocessor coproc, CRegister crd, Register base, int option,
869 LFlag l = Short); // v5 and above
870
Steve Blockd0582a62009-12-15 09:54:21 +0000871 // Support for VFP.
872 // All these APIs support S0 to S31 and D0 to D15.
873 // Currently these APIs do not support extended D registers, i.e, D16 to D31.
874 // However, some simple modifications can allow
875 // these APIs to support D16 to D31.
876
Leon Clarked91b9f72010-01-27 17:25:45 +0000877 void vldr(const DwVfpRegister dst,
878 const Register base,
879 int offset, // Offset must be a multiple of 4.
880 const Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100881
882 void vldr(const SwVfpRegister dst,
883 const Register base,
884 int offset, // Offset must be a multiple of 4.
885 const Condition cond = al);
886
Leon Clarked91b9f72010-01-27 17:25:45 +0000887 void vstr(const DwVfpRegister src,
888 const Register base,
889 int offset, // Offset must be a multiple of 4.
890 const Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000891 void vmov(const DwVfpRegister dst,
892 const Register src1,
Steve Blockd0582a62009-12-15 09:54:21 +0000893 const Register src2,
Leon Clarkee46be812010-01-19 14:06:41 +0000894 const Condition cond = al);
895 void vmov(const Register dst1,
896 const Register dst2,
897 const DwVfpRegister src,
898 const Condition cond = al);
899 void vmov(const SwVfpRegister dst,
900 const Register src,
901 const Condition cond = al);
902 void vmov(const Register dst,
903 const SwVfpRegister src,
904 const Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100905 void vcvt_f64_s32(const DwVfpRegister dst,
906 const SwVfpRegister src,
907 const Condition cond = al);
908 void vcvt_f32_s32(const SwVfpRegister dst,
909 const SwVfpRegister src,
910 const Condition cond = al);
911 void vcvt_f64_u32(const DwVfpRegister dst,
912 const SwVfpRegister src,
913 const Condition cond = al);
914 void vcvt_s32_f64(const SwVfpRegister dst,
915 const DwVfpRegister src,
916 const Condition cond = al);
917 void vcvt_u32_f64(const SwVfpRegister dst,
918 const DwVfpRegister src,
919 const Condition cond = al);
920 void vcvt_f64_f32(const DwVfpRegister dst,
921 const SwVfpRegister src,
922 const Condition cond = al);
923 void vcvt_f32_f64(const SwVfpRegister dst,
924 const DwVfpRegister src,
925 const Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000926
927 void vadd(const DwVfpRegister dst,
928 const DwVfpRegister src1,
929 const DwVfpRegister src2,
930 const Condition cond = al);
931 void vsub(const DwVfpRegister dst,
932 const DwVfpRegister src1,
933 const DwVfpRegister src2,
934 const Condition cond = al);
935 void vmul(const DwVfpRegister dst,
936 const DwVfpRegister src1,
937 const DwVfpRegister src2,
938 const Condition cond = al);
939 void vdiv(const DwVfpRegister dst,
940 const DwVfpRegister src1,
941 const DwVfpRegister src2,
942 const Condition cond = al);
943 void vcmp(const DwVfpRegister src1,
944 const DwVfpRegister src2,
Steve Blockd0582a62009-12-15 09:54:21 +0000945 const SBit s = LeaveCC,
946 const Condition cond = al);
947 void vmrs(const Register dst,
948 const Condition cond = al);
949
Steve Blocka7e24c12009-10-30 11:49:00 +0000950 // Pseudo instructions
Steve Block6ded16b2010-05-10 14:33:55 +0100951 void nop(int type = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000952
953 void push(Register src, Condition cond = al) {
954 str(src, MemOperand(sp, 4, NegPreIndex), cond);
955 }
956
957 void pop(Register dst, Condition cond = al) {
958 ldr(dst, MemOperand(sp, 4, PostIndex), cond);
959 }
960
961 void pop() {
962 add(sp, sp, Operand(kPointerSize));
963 }
964
Steve Blocka7e24c12009-10-30 11:49:00 +0000965 // Jump unconditionally to given label.
966 void jmp(Label* L) { b(L, al); }
967
968 // Check the code size generated from label to here.
969 int InstructionsGeneratedSince(Label* l) {
970 return (pc_offset() - l->pos()) / kInstrSize;
971 }
972
Steve Blockd0582a62009-12-15 09:54:21 +0000973 // Check whether an immediate fits an addressing mode 1 instruction.
974 bool ImmediateFitsAddrMode1Instruction(int32_t imm32);
975
Steve Block6ded16b2010-05-10 14:33:55 +0100976 // Class for scoping postponing the constant pool generation.
977 class BlockConstPoolScope {
978 public:
979 explicit BlockConstPoolScope(Assembler* assem) : assem_(assem) {
980 assem_->StartBlockConstPool();
981 }
982 ~BlockConstPoolScope() {
983 assem_->EndBlockConstPool();
984 }
985
986 private:
987 Assembler* assem_;
988
989 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockConstPoolScope);
990 };
991
Steve Blockd0582a62009-12-15 09:54:21 +0000992 // Postpone the generation of the constant pool for the specified number of
993 // instructions.
994 void BlockConstPoolFor(int instructions);
995
Steve Blocka7e24c12009-10-30 11:49:00 +0000996 // Debugging
997
998 // Mark address of the ExitJSFrame code.
999 void RecordJSReturn();
1000
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001001 // Mark address of a debug break slot.
1002 void RecordDebugBreakSlot();
1003
Steve Blocka7e24c12009-10-30 11:49:00 +00001004 // Record a comment relocation entry that can be used by a disassembler.
1005 // Use --debug_code to enable.
1006 void RecordComment(const char* msg);
1007
1008 void RecordPosition(int pos);
1009 void RecordStatementPosition(int pos);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001010 bool WriteRecordedPositions();
Steve Blocka7e24c12009-10-30 11:49:00 +00001011
1012 int pc_offset() const { return pc_ - buffer_; }
1013 int current_position() const { return current_position_; }
Steve Block6ded16b2010-05-10 14:33:55 +01001014 int current_statement_position() const { return current_statement_position_; }
1015
Leon Clarkef7060e22010-06-03 12:02:55 +01001016 bool can_peephole_optimize(int instructions) {
1017 if (!FLAG_peephole_optimization) return false;
1018 if (last_bound_pos_ > pc_offset() - instructions * kInstrSize) return false;
1019 return reloc_info_writer.last_pc() <= pc_ - instructions * kInstrSize;
1020 }
1021
Steve Block6ded16b2010-05-10 14:33:55 +01001022 // Read/patch instructions
1023 static Instr instr_at(byte* pc) { return *reinterpret_cast<Instr*>(pc); }
1024 static void instr_at_put(byte* pc, Instr instr) {
1025 *reinterpret_cast<Instr*>(pc) = instr;
1026 }
1027 static bool IsNop(Instr instr, int type = 0);
1028 static bool IsBranch(Instr instr);
1029 static int GetBranchOffset(Instr instr);
1030 static bool IsLdrRegisterImmediate(Instr instr);
1031 static int GetLdrRegisterImmediateOffset(Instr instr);
1032 static Instr SetLdrRegisterImmediateOffset(Instr instr, int offset);
Leon Clarkef7060e22010-06-03 12:02:55 +01001033 static Register GetRd(Instr instr);
1034 static bool IsPush(Instr instr);
1035 static bool IsPop(Instr instr);
1036 static bool IsStrRegFpOffset(Instr instr);
1037 static bool IsLdrRegFpOffset(Instr instr);
1038 static bool IsStrRegFpNegOffset(Instr instr);
1039 static bool IsLdrRegFpNegOffset(Instr instr);
Steve Block6ded16b2010-05-10 14:33:55 +01001040
Steve Blocka7e24c12009-10-30 11:49:00 +00001041
1042 protected:
1043 int buffer_space() const { return reloc_info_writer.pos() - pc_; }
1044
1045 // Read/patch instructions
Steve Blocka7e24c12009-10-30 11:49:00 +00001046 Instr instr_at(int pos) { return *reinterpret_cast<Instr*>(buffer_ + pos); }
1047 void instr_at_put(int pos, Instr instr) {
1048 *reinterpret_cast<Instr*>(buffer_ + pos) = instr;
1049 }
1050
1051 // Decode branch instruction at pos and return branch target pos
1052 int target_at(int pos);
1053
1054 // Patch branch instruction at pos to branch to given branch target pos
1055 void target_at_put(int pos, int target_pos);
1056
1057 // Check if is time to emit a constant pool for pending reloc info entries
1058 void CheckConstPool(bool force_emit, bool require_jump);
1059
1060 // Block the emission of the constant pool before pc_offset
1061 void BlockConstPoolBefore(int pc_offset) {
1062 if (no_const_pool_before_ < pc_offset) no_const_pool_before_ = pc_offset;
1063 }
1064
Steve Block6ded16b2010-05-10 14:33:55 +01001065 void StartBlockConstPool() {
1066 const_pool_blocked_nesting_++;
1067 }
1068 void EndBlockConstPool() {
1069 const_pool_blocked_nesting_--;
1070 }
1071
Steve Blocka7e24c12009-10-30 11:49:00 +00001072 private:
1073 // Code buffer:
1074 // The buffer into which code and relocation info are generated.
1075 byte* buffer_;
1076 int buffer_size_;
1077 // True if the assembler owns the buffer, false if buffer is external.
1078 bool own_buffer_;
1079
1080 // Buffer size and constant pool distance are checked together at regular
1081 // intervals of kBufferCheckInterval emitted bytes
1082 static const int kBufferCheckInterval = 1*KB/2;
1083 int next_buffer_check_; // pc offset of next buffer check
1084
1085 // Code generation
1086 // The relocation writer's position is at least kGap bytes below the end of
1087 // the generated instructions. This is so that multi-instruction sequences do
1088 // not have to check for overflow. The same is true for writes of large
1089 // relocation info entries.
1090 static const int kGap = 32;
1091 byte* pc_; // the program counter; moves forward
1092
1093 // Constant pool generation
1094 // Pools are emitted in the instruction stream, preferably after unconditional
1095 // jumps or after returns from functions (in dead code locations).
1096 // If a long code sequence does not contain unconditional jumps, it is
1097 // necessary to emit the constant pool before the pool gets too far from the
1098 // location it is accessed from. In this case, we emit a jump over the emitted
1099 // constant pool.
1100 // Constants in the pool may be addresses of functions that gets relocated;
1101 // if so, a relocation info entry is associated to the constant pool entry.
1102
1103 // Repeated checking whether the constant pool should be emitted is rather
1104 // expensive. By default we only check again once a number of instructions
1105 // has been generated. That also means that the sizing of the buffers is not
1106 // an exact science, and that we rely on some slop to not overrun buffers.
1107 static const int kCheckConstIntervalInst = 32;
1108 static const int kCheckConstInterval = kCheckConstIntervalInst * kInstrSize;
1109
1110
1111 // Pools are emitted after function return and in dead code at (more or less)
1112 // regular intervals of kDistBetweenPools bytes
1113 static const int kDistBetweenPools = 1*KB;
1114
1115 // Constants in pools are accessed via pc relative addressing, which can
1116 // reach +/-4KB thereby defining a maximum distance between the instruction
1117 // and the accessed constant. We satisfy this constraint by limiting the
1118 // distance between pools.
1119 static const int kMaxDistBetweenPools = 4*KB - 2*kBufferCheckInterval;
1120
Steve Block6ded16b2010-05-10 14:33:55 +01001121 // Emission of the constant pool may be blocked in some code sequences.
1122 int const_pool_blocked_nesting_; // Block emission if this is not zero.
1123 int no_const_pool_before_; // Block emission before this pc offset.
Steve Blocka7e24c12009-10-30 11:49:00 +00001124
1125 // Keep track of the last emitted pool to guarantee a maximal distance
1126 int last_const_pool_end_; // pc offset following the last constant pool
1127
1128 // Relocation info generation
1129 // Each relocation is encoded as a variable size value
1130 static const int kMaxRelocSize = RelocInfoWriter::kMaxSize;
1131 RelocInfoWriter reloc_info_writer;
1132 // Relocation info records are also used during code generation as temporary
1133 // containers for constants and code target addresses until they are emitted
1134 // to the constant pool. These pending relocation info records are temporarily
1135 // stored in a separate buffer until a constant pool is emitted.
1136 // If every instruction in a long sequence is accessing the pool, we need one
1137 // pending relocation entry per instruction.
1138 static const int kMaxNumPRInfo = kMaxDistBetweenPools/kInstrSize;
1139 RelocInfo prinfo_[kMaxNumPRInfo]; // the buffer of pending relocation info
1140 int num_prinfo_; // number of pending reloc info entries in the buffer
1141
1142 // The bound position, before this we cannot do instruction elimination.
1143 int last_bound_pos_;
1144
1145 // source position information
1146 int current_position_;
1147 int current_statement_position_;
1148 int written_position_;
1149 int written_statement_position_;
1150
1151 // Code emission
1152 inline void CheckBuffer();
1153 void GrowBuffer();
1154 inline void emit(Instr x);
1155
1156 // Instruction generation
1157 void addrmod1(Instr instr, Register rn, Register rd, const Operand& x);
1158 void addrmod2(Instr instr, Register rd, const MemOperand& x);
1159 void addrmod3(Instr instr, Register rd, const MemOperand& x);
1160 void addrmod4(Instr instr, Register rn, RegList rl);
1161 void addrmod5(Instr instr, CRegister crd, const MemOperand& x);
1162
1163 // Labels
1164 void print(Label* L);
1165 void bind_to(Label* L, int pos);
1166 void link_to(Label* L, Label* appendix);
1167 void next(Label* L);
1168
1169 // Record reloc info for current pc_
1170 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
1171
1172 friend class RegExpMacroAssemblerARM;
1173 friend class RelocInfo;
1174 friend class CodePatcher;
Steve Block6ded16b2010-05-10 14:33:55 +01001175 friend class BlockConstPoolScope;
Steve Blocka7e24c12009-10-30 11:49:00 +00001176};
1177
1178} } // namespace v8::internal
1179
1180#endif // V8_ARM_ASSEMBLER_ARM_H_