blob: fb75d6dc2282f308a5fe15483cd7d3e230bf70b0 [file] [log] [blame]
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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 are
6// 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 distribution.
14//
15// - Neither the name of Sun Microsystems or the names of contributors may
16// be used to endorse or promote products derived from this software without
17// specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// The original source code covered by the above license above has been
32// modified significantly by Google Inc.
ager@chromium.orgeadaf222009-06-16 09:43:10 +000033// Copyright 2006-2009 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000034
35#ifndef V8_ASSEMBLER_H_
36#define V8_ASSEMBLER_H_
37
38#include "runtime.h"
39#include "top.h"
ager@chromium.org65dad4b2009-04-23 08:48:43 +000040#include "token.h"
kmillikin@chromium.org9155e252010-05-26 13:27:57 +000041#include "objects.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000042
kasperl@chromium.org71affb52009-05-26 05:44:31 +000043namespace v8 {
44namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000045
46
47// -----------------------------------------------------------------------------
48// Labels represent pc locations; they are typically jump or call targets.
49// After declaration, a label can be freely used to denote known or (yet)
50// unknown pc location. Assembler::bind() is used to bind a label to the
51// current pc. A label can be bound only once.
52
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000053class Label BASE_EMBEDDED {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000054 public:
55 INLINE(Label()) { Unuse(); }
56 INLINE(~Label()) { ASSERT(!is_linked()); }
57
58 INLINE(void Unuse()) { pos_ = 0; }
59
60 INLINE(bool is_bound() const) { return pos_ < 0; }
61 INLINE(bool is_unused() const) { return pos_ == 0; }
62 INLINE(bool is_linked() const) { return pos_ > 0; }
63
64 // Returns the position of bound or linked labels. Cannot be used
65 // for unused labels.
66 int pos() const;
67
68 private:
69 // pos_ encodes both the binding state (via its sign)
70 // and the binding position (via its value) of a label.
71 //
72 // pos_ < 0 bound label, pos() returns the jump target position
73 // pos_ == 0 unused label
74 // pos_ > 0 linked label, pos() returns the last reference position
75 int pos_;
76
77 void bind_to(int pos) {
78 pos_ = -pos - 1;
79 ASSERT(is_bound());
80 }
81 void link_to(int pos) {
82 pos_ = pos + 1;
83 ASSERT(is_linked());
84 }
85
86 friend class Assembler;
ager@chromium.orga74f0da2008-12-03 16:05:52 +000087 friend class RegexpAssembler;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000088 friend class Displacement;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000089 friend class ShadowTarget;
ager@chromium.orga74f0da2008-12-03 16:05:52 +000090 friend class RegExpMacroAssemblerIrregexp;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000091};
92
93
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000094// -----------------------------------------------------------------------------
95// Relocation information
96
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000097
98// Relocation information consists of the address (pc) of the datum
99// to which the relocation information applies, the relocation mode
100// (rmode), and an optional data field. The relocation mode may be
101// "descriptive" and not indicate a need for relocation, but simply
102// describe a property of the datum. Such rmodes are useful for GC
103// and nice disassembly output.
104
105class RelocInfo BASE_EMBEDDED {
106 public:
ager@chromium.org236ad962008-09-25 09:45:57 +0000107 // The constant kNoPosition is used with the collecting of source positions
108 // in the relocation information. Two types of source positions are collected
109 // "position" (RelocMode position) and "statement position" (RelocMode
110 // statement_position). The "position" is collected at places in the source
111 // code which are of interest when making stack traces to pin-point the source
112 // location of a stack frame as close as possible. The "statement position" is
113 // collected at the beginning at each statement, and is used to indicate
114 // possible break locations. kNoPosition is used to indicate an
115 // invalid/uninitialized position value.
116 static const int kNoPosition = -1;
117
118 enum Mode {
119 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
120 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000121 CODE_TARGET_CONTEXT, // Code target used for contextual loads.
122 DEBUG_BREAK, // Code target for the debugger statement.
123 CODE_TARGET, // Code target which is not any of the above.
ager@chromium.org236ad962008-09-25 09:45:57 +0000124 EMBEDDED_OBJECT,
ager@chromium.org236ad962008-09-25 09:45:57 +0000125
126 // Everything after runtime_entry (inclusive) is not GC'ed.
127 RUNTIME_ENTRY,
128 JS_RETURN, // Marks start of the ExitJSFrame code.
129 COMMENT,
130 POSITION, // See comment for kNoPosition above.
131 STATEMENT_POSITION, // See comment for kNoPosition above.
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000132 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
ager@chromium.org236ad962008-09-25 09:45:57 +0000133 EXTERNAL_REFERENCE, // The address of an external C++ function.
134 INTERNAL_REFERENCE, // An address inside the same function.
135
136 // add more as needed
137 // Pseudo-types
138 NUMBER_OF_MODES, // must be no greater than 14 - see RelocInfoWriter
139 NONE, // never recorded
140 LAST_CODE_ENUM = CODE_TARGET,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000141 LAST_GCED_ENUM = EMBEDDED_OBJECT
ager@chromium.org236ad962008-09-25 09:45:57 +0000142 };
143
144
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000145 RelocInfo() {}
ager@chromium.org236ad962008-09-25 09:45:57 +0000146 RelocInfo(byte* pc, Mode rmode, intptr_t data)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000147 : pc_(pc), rmode_(rmode), data_(data) {
148 }
149
ager@chromium.org236ad962008-09-25 09:45:57 +0000150 static inline bool IsConstructCall(Mode mode) {
151 return mode == CONSTRUCT_CALL;
152 }
153 static inline bool IsCodeTarget(Mode mode) {
154 return mode <= LAST_CODE_ENUM;
155 }
156 // Is the relocation mode affected by GC?
157 static inline bool IsGCRelocMode(Mode mode) {
158 return mode <= LAST_GCED_ENUM;
159 }
160 static inline bool IsJSReturn(Mode mode) {
161 return mode == JS_RETURN;
162 }
163 static inline bool IsComment(Mode mode) {
164 return mode == COMMENT;
165 }
166 static inline bool IsPosition(Mode mode) {
167 return mode == POSITION || mode == STATEMENT_POSITION;
168 }
169 static inline bool IsStatementPosition(Mode mode) {
170 return mode == STATEMENT_POSITION;
171 }
172 static inline bool IsExternalReference(Mode mode) {
173 return mode == EXTERNAL_REFERENCE;
174 }
175 static inline bool IsInternalReference(Mode mode) {
176 return mode == INTERNAL_REFERENCE;
177 }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000178 static inline bool IsDebugBreakSlot(Mode mode) {
179 return mode == DEBUG_BREAK_SLOT;
180 }
ager@chromium.org236ad962008-09-25 09:45:57 +0000181 static inline int ModeMask(Mode mode) { return 1 << mode; }
182
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000183 // Accessors
184 byte* pc() const { return pc_; }
185 void set_pc(byte* pc) { pc_ = pc; }
ager@chromium.org236ad962008-09-25 09:45:57 +0000186 Mode rmode() const { return rmode_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000187 intptr_t data() const { return data_; }
188
189 // Apply a relocation by delta bytes
ager@chromium.org3e875802009-06-29 08:26:34 +0000190 INLINE(void apply(intptr_t delta));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000191
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000192 // Is the pointer this relocation info refers to coded like a plain pointer
193 // or is it strange in some way (eg relative or patched into a series of
194 // instructions).
195 bool IsCodedSpecially();
196
ager@chromium.org32912102009-01-16 10:38:43 +0000197 // Read/modify the code target in the branch/call instruction
198 // this relocation applies to;
199 // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000200 INLINE(Address target_address());
201 INLINE(void set_target_address(Address target));
202 INLINE(Object* target_object());
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000203 INLINE(Handle<Object> target_object_handle(Assembler* origin));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000204 INLINE(Object** target_object_address());
205 INLINE(void set_target_object(Object* target));
206
kmillikin@chromium.org9155e252010-05-26 13:27:57 +0000207 // Read the address of the word containing the target_address in an
208 // instruction stream. What this means exactly is architecture-independent.
209 // The only architecture-independent user of this function is the serializer.
210 // The serializer uses it to find out how many raw bytes of instruction to
211 // output before the next target. Architecture-independent code shouldn't
212 // dereference the pointer it gets back from this.
ager@chromium.org32912102009-01-16 10:38:43 +0000213 INLINE(Address target_address_address());
kmillikin@chromium.org9155e252010-05-26 13:27:57 +0000214 // This indicates how much space a target takes up when deserializing a code
215 // stream. For most architectures this is just the size of a pointer. For
216 // an instruction like movw/movt where the target bits are mixed into the
217 // instruction bits the size of the target will be zero, indicating that the
218 // serializer should not step forwards in memory after a target is resolved
219 // and written. In this case the target_address_address function above
220 // should return the end of the instructions to be patched, allowing the
221 // deserializer to deserialize the instructions as raw bytes and put them in
222 // place, ready to be patched with the target.
223 INLINE(int target_address_size());
ager@chromium.org32912102009-01-16 10:38:43 +0000224
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000225 // Read/modify the reference in the instruction this relocation
226 // applies to; can only be called if rmode_ is external_reference
227 INLINE(Address* target_reference_address());
228
229 // Read/modify the address of a call instruction. This is used to relocate
230 // the break points where straight-line code is patched with a call
231 // instruction.
232 INLINE(Address call_address());
233 INLINE(void set_call_address(Address target));
234 INLINE(Object* call_object());
235 INLINE(Object** call_object_address());
236 INLINE(void set_call_object(Object* target));
237
kmillikin@chromium.org9155e252010-05-26 13:27:57 +0000238 inline void Visit(ObjectVisitor* v);
239
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000240 // Patch the code with some other code.
iposva@chromium.org245aa852009-02-10 00:49:54 +0000241 void PatchCode(byte* instructions, int instruction_count);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000242
243 // Patch the code with a call.
iposva@chromium.org245aa852009-02-10 00:49:54 +0000244 void PatchCodeWithCall(Address target, int guard_bytes);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000245
246 // Check whether this return sequence has been patched
247 // with a call to the debugger.
248 INLINE(bool IsPatchedReturnSequence());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000249
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000250 // Check whether this debug break slot has been patched with a call to the
251 // debugger.
252 INLINE(bool IsPatchedDebugBreakSlotSequence());
253
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000254#ifdef ENABLE_DISASSEMBLER
255 // Printing
ager@chromium.org236ad962008-09-25 09:45:57 +0000256 static const char* RelocModeName(Mode rmode);
mads.s.ager31e71382008-08-13 09:32:07 +0000257 void Print();
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000258#endif // ENABLE_DISASSEMBLER
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000259#ifdef DEBUG
260 // Debugging
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000261 void Verify();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000262#endif
263
ager@chromium.org236ad962008-09-25 09:45:57 +0000264 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
265 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
266 static const int kDebugMask = kPositionMask | 1 << COMMENT;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000267 static const int kApplyMask; // Modes affected by apply. Depends on arch.
268
269 private:
270 // On ARM, note that pc_ is the address of the constant pool entry
271 // to be relocated and not the address of the instruction
272 // referencing the constant pool entry (except when rmode_ ==
273 // comment).
274 byte* pc_;
ager@chromium.org236ad962008-09-25 09:45:57 +0000275 Mode rmode_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000276 intptr_t data_;
277 friend class RelocIterator;
278};
279
280
281// RelocInfoWriter serializes a stream of relocation info. It writes towards
282// lower addresses.
283class RelocInfoWriter BASE_EMBEDDED {
284 public:
285 RelocInfoWriter() : pos_(NULL), last_pc_(NULL), last_data_(0) {}
286 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), last_pc_(pc),
287 last_data_(0) {}
288
289 byte* pos() const { return pos_; }
290 byte* last_pc() const { return last_pc_; }
291
292 void Write(const RelocInfo* rinfo);
293
294 // Update the state of the stream after reloc info buffer
295 // and/or code is moved while the stream is active.
296 void Reposition(byte* pos, byte* pc) {
297 pos_ = pos;
298 last_pc_ = pc;
299 }
300
ager@chromium.org3e875802009-06-29 08:26:34 +0000301 // Max size (bytes) of a written RelocInfo. Longest encoding is
302 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
303 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
304 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
305 // Here we use the maximum of the two.
306 static const int kMaxSize = 16;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000307
308 private:
309 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
310 inline void WriteTaggedPC(uint32_t pc_delta, int tag);
311 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
ager@chromium.orge2902be2009-06-08 12:21:35 +0000312 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
313 inline void WriteTaggedData(intptr_t data_delta, int tag);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000314 inline void WriteExtraTag(int extra_tag, int top_tag);
315
316 byte* pos_;
317 byte* last_pc_;
318 intptr_t last_data_;
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000319 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000320};
321
322
323// A RelocIterator iterates over relocation information.
324// Typical use:
325//
326// for (RelocIterator it(code); !it.done(); it.next()) {
327// // do something with it.rinfo() here
328// }
329//
330// A mask can be specified to skip unwanted modes.
331class RelocIterator: public Malloced {
332 public:
333 // Create a new iterator positioned at
334 // the beginning of the reloc info.
335 // Relocation information with mode k is included in the
336 // iteration iff bit k of mode_mask is set.
337 explicit RelocIterator(Code* code, int mode_mask = -1);
338 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
339
340 // Iteration
341 bool done() const { return done_; }
342 void next();
343
344 // Return pointer valid until next next().
345 RelocInfo* rinfo() {
346 ASSERT(!done());
347 return &rinfo_;
348 }
349
350 private:
351 // Advance* moves the position before/after reading.
352 // *Read* reads from current byte(s) into rinfo_.
353 // *Get* just reads and returns info on current byte.
354 void Advance(int bytes = 1) { pos_ -= bytes; }
355 int AdvanceGetTag();
356 int GetExtraTag();
357 int GetTopTag();
358 void ReadTaggedPC();
359 void AdvanceReadPC();
360 void AdvanceReadData();
361 void AdvanceReadVariableLengthPCJump();
362 int GetPositionTypeTag();
363 void ReadTaggedData();
364
ager@chromium.org236ad962008-09-25 09:45:57 +0000365 static RelocInfo::Mode DebugInfoModeFromTag(int tag);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000366
367 // If the given mode is wanted, set it in rinfo_ and return true.
368 // Else return false. Used for efficiently skipping unwanted modes.
ager@chromium.org236ad962008-09-25 09:45:57 +0000369 bool SetMode(RelocInfo::Mode mode) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000370 return (mode_mask_ & 1 << mode) ? (rinfo_.rmode_ = mode, true) : false;
371 }
372
373 byte* pos_;
374 byte* end_;
375 RelocInfo rinfo_;
376 bool done_;
377 int mode_mask_;
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000378 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000379};
380
381
382//------------------------------------------------------------------------------
383// External function
384
385//----------------------------------------------------------------------------
386class IC_Utility;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000387class SCTableReference;
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000388#ifdef ENABLE_DEBUGGER_SUPPORT
389class Debug_Address;
390#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000391
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000392
393typedef void* ExternalReferenceRedirector(void* original, bool fp_return);
394
395
396// An ExternalReference represents a C++ address used in the generated
397// code. All references to C++ functions and variables must be encapsulated in
398// an ExternalReference instance. This is done in order to track the origin of
399// all external references in the code so that they can be bound to the correct
400// addresses when deserializing a heap.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000401class ExternalReference BASE_EMBEDDED {
402 public:
403 explicit ExternalReference(Builtins::CFunctionId id);
404
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000405 explicit ExternalReference(ApiFunction* ptr);
406
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000407 explicit ExternalReference(Builtins::Name name);
408
409 explicit ExternalReference(Runtime::FunctionId id);
410
411 explicit ExternalReference(Runtime::Function* f);
412
413 explicit ExternalReference(const IC_Utility& ic_utility);
414
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000415#ifdef ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000416 explicit ExternalReference(const Debug_Address& debug_address);
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000417#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000418
419 explicit ExternalReference(StatsCounter* counter);
420
421 explicit ExternalReference(Top::AddressId id);
422
423 explicit ExternalReference(const SCTableReference& table_ref);
424
425 // One-of-a-kind references. These references are not part of a general
426 // pattern. This means that they have to be added to the
427 // ExternalReferenceTable in serialize.cc manually.
428
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000429 static ExternalReference perform_gc_function();
ager@chromium.org357bf652010-04-12 11:30:10 +0000430 static ExternalReference fill_heap_number_with_random_function();
431 static ExternalReference random_uint32_function();
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000432 static ExternalReference transcendental_cache_array_address();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000433
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000434 // Static data in the keyed lookup cache.
435 static ExternalReference keyed_lookup_cache_keys();
436 static ExternalReference keyed_lookup_cache_field_offsets();
437
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000438 // Static variable Factory::the_hole_value.location()
439 static ExternalReference the_hole_value_location();
440
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000441 // Static variable Heap::roots_address()
442 static ExternalReference roots_address();
443
ager@chromium.org6f10e412009-02-13 10:11:16 +0000444 // Static variable StackGuard::address_of_jslimit()
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000445 static ExternalReference address_of_stack_limit();
446
447 // Static variable StackGuard::address_of_real_jslimit()
448 static ExternalReference address_of_real_stack_limit();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000449
ager@chromium.org32912102009-01-16 10:38:43 +0000450 // Static variable RegExpStack::limit_address()
451 static ExternalReference address_of_regexp_stack_limit();
452
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000453 // Static variables for RegExp.
454 static ExternalReference address_of_static_offsets_vector();
455 static ExternalReference address_of_regexp_stack_memory_address();
456 static ExternalReference address_of_regexp_stack_memory_size();
457
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000458 // Static variable Heap::NewSpaceStart()
459 static ExternalReference new_space_start();
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000460 static ExternalReference new_space_mask();
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000461 static ExternalReference heap_always_allocate_scope_depth();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000462
463 // Used for fast allocation in generated code.
464 static ExternalReference new_space_allocation_top_address();
465 static ExternalReference new_space_allocation_limit_address();
466
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000467 static ExternalReference double_fp_operation(Token::Value operation);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000468 static ExternalReference compare_doubles();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000469
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000470 static ExternalReference handle_scope_extensions_address();
471 static ExternalReference handle_scope_next_address();
472 static ExternalReference handle_scope_limit_address();
473
474 static ExternalReference scheduled_exception_address();
475
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000476 Address address() const {return reinterpret_cast<Address>(address_);}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000477
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000478#ifdef ENABLE_DEBUGGER_SUPPORT
479 // Function Debug::Break()
480 static ExternalReference debug_break();
481
482 // Used to check if single stepping is enabled in generated code.
483 static ExternalReference debug_step_in_fp_address();
484#endif
485
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000486#ifndef V8_INTERPRETED_REGEXP
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000487 // C functions called from RegExp generated code.
488
489 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
490 static ExternalReference re_case_insensitive_compare_uc16();
491
492 // Function RegExpMacroAssembler*::CheckStackGuardState()
493 static ExternalReference re_check_stack_guard_state();
494
495 // Function NativeRegExpMacroAssembler::GrowStack()
496 static ExternalReference re_grow_stack();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000497
498 // byte NativeRegExpMacroAssembler::word_character_bitmap
499 static ExternalReference re_word_character_map();
500
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000501#endif
502
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000503 // This lets you register a function that rewrites all external references.
504 // Used by the ARM simulator to catch calls to external references.
505 static void set_redirector(ExternalReferenceRedirector* redirector) {
506 ASSERT(redirector_ == NULL); // We can't stack them.
507 redirector_ = redirector;
508 }
509
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000510 private:
511 explicit ExternalReference(void* address)
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000512 : address_(address) {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000513
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000514 static ExternalReferenceRedirector* redirector_;
515
516 static void* Redirect(void* address, bool fp_return = false) {
517 if (redirector_ == NULL) return address;
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000518 void* answer = (*redirector_)(address, fp_return);
519 return answer;
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000520 }
521
522 static void* Redirect(Address address_arg, bool fp_return = false) {
523 void* address = reinterpret_cast<void*>(address_arg);
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000524 void* answer = (redirector_ == NULL) ?
525 address :
526 (*redirector_)(address, fp_return);
527 return answer;
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000528 }
529
530 void* address_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000531};
532
533
534// -----------------------------------------------------------------------------
535// Utility functions
536
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000537static inline bool is_intn(int x, int n) {
538 return -(1 << (n-1)) <= x && x < (1 << (n-1));
539}
540
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000541static inline bool is_int8(int x) { return is_intn(x, 8); }
ager@chromium.org5c838252010-02-19 08:53:10 +0000542static inline bool is_int16(int x) { return is_intn(x, 16); }
543static inline bool is_int18(int x) { return is_intn(x, 18); }
544static inline bool is_int24(int x) { return is_intn(x, 24); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000545
546static inline bool is_uintn(int x, int n) {
547 return (x & -(1 << n)) == 0;
548}
549
ager@chromium.orge2902be2009-06-08 12:21:35 +0000550static inline bool is_uint2(int x) { return is_uintn(x, 2); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000551static inline bool is_uint3(int x) { return is_uintn(x, 3); }
552static inline bool is_uint4(int x) { return is_uintn(x, 4); }
553static inline bool is_uint5(int x) { return is_uintn(x, 5); }
ager@chromium.orge2902be2009-06-08 12:21:35 +0000554static inline bool is_uint6(int x) { return is_uintn(x, 6); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000555static inline bool is_uint8(int x) { return is_uintn(x, 8); }
ager@chromium.org5c838252010-02-19 08:53:10 +0000556static inline bool is_uint10(int x) { return is_uintn(x, 10); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000557static inline bool is_uint12(int x) { return is_uintn(x, 12); }
558static inline bool is_uint16(int x) { return is_uintn(x, 16); }
559static inline bool is_uint24(int x) { return is_uintn(x, 24); }
ager@chromium.org5c838252010-02-19 08:53:10 +0000560static inline bool is_uint26(int x) { return is_uintn(x, 26); }
561static inline bool is_uint28(int x) { return is_uintn(x, 28); }
562
563static inline int NumberOfBitsSet(uint32_t x) {
564 unsigned int num_bits_set;
565 for (num_bits_set = 0; x; x >>= 1) {
566 num_bits_set += x & 1;
567 }
568 return num_bits_set;
569}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000570
571} } // namespace v8::internal
572
573#endif // V8_ASSEMBLER_H_