christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1 | // 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.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 33 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | |
| 35 | #ifndef V8_ASSEMBLER_H_ |
| 36 | #define V8_ASSEMBLER_H_ |
| 37 | |
| 38 | #include "runtime.h" |
| 39 | #include "top.h" |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 40 | #include "token.h" |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 41 | #include "objects.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 43 | namespace v8 { |
| 44 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
| 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.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 53 | class Label BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 54 | 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.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 87 | friend class RegexpAssembler; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | friend class Displacement; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 89 | friend class ShadowTarget; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 90 | friend class RegExpMacroAssemblerIrregexp; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | // ----------------------------------------------------------------------------- |
| 95 | // Relocation information |
| 96 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 97 | |
| 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 | |
| 105 | class RelocInfo BASE_EMBEDDED { |
| 106 | public: |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 107 | // 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.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 121 | 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.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 124 | EMBEDDED_OBJECT, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 125 | |
| 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.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 132 | DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 133 | 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.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 141 | LAST_GCED_ENUM = EMBEDDED_OBJECT |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | RelocInfo() {} |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 146 | RelocInfo(byte* pc, Mode rmode, intptr_t data) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 147 | : pc_(pc), rmode_(rmode), data_(data) { |
| 148 | } |
| 149 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 150 | 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.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 178 | static inline bool IsDebugBreakSlot(Mode mode) { |
| 179 | return mode == DEBUG_BREAK_SLOT; |
| 180 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 181 | static inline int ModeMask(Mode mode) { return 1 << mode; } |
| 182 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | // Accessors |
| 184 | byte* pc() const { return pc_; } |
| 185 | void set_pc(byte* pc) { pc_ = pc; } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 186 | Mode rmode() const { return rmode_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | intptr_t data() const { return data_; } |
| 188 | |
| 189 | // Apply a relocation by delta bytes |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 190 | INLINE(void apply(intptr_t delta)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 192 | // 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.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 197 | // 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 200 | INLINE(Address target_address()); |
| 201 | INLINE(void set_target_address(Address target)); |
| 202 | INLINE(Object* target_object()); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 203 | INLINE(Handle<Object> target_object_handle(Assembler* origin)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | INLINE(Object** target_object_address()); |
| 205 | INLINE(void set_target_object(Object* target)); |
| 206 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 207 | // 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.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 213 | INLINE(Address target_address_address()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 214 | // 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.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 224 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | // 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.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 238 | inline void Visit(ObjectVisitor* v); |
| 239 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | // Patch the code with some other code. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 241 | void PatchCode(byte* instructions, int instruction_count); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 242 | |
| 243 | // Patch the code with a call. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 244 | void PatchCodeWithCall(Address target, int guard_bytes); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 245 | |
| 246 | // Check whether this return sequence has been patched |
| 247 | // with a call to the debugger. |
| 248 | INLINE(bool IsPatchedReturnSequence()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 250 | // 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.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 254 | #ifdef ENABLE_DISASSEMBLER |
| 255 | // Printing |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 256 | static const char* RelocModeName(Mode rmode); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 257 | void Print(); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 258 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 259 | #ifdef DEBUG |
| 260 | // Debugging |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 261 | void Verify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 262 | #endif |
| 263 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 264 | 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | 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.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 275 | Mode rmode_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | intptr_t data_; |
| 277 | friend class RelocIterator; |
| 278 | }; |
| 279 | |
| 280 | |
| 281 | // RelocInfoWriter serializes a stream of relocation info. It writes towards |
| 282 | // lower addresses. |
| 283 | class 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.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 301 | // 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 307 | |
| 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.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 312 | inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag); |
| 313 | inline void WriteTaggedData(intptr_t data_delta, int tag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | 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.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 319 | DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 320 | }; |
| 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. |
| 331 | class 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.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 365 | static RelocInfo::Mode DebugInfoModeFromTag(int tag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 366 | |
| 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.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 369 | bool SetMode(RelocInfo::Mode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 370 | 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.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 378 | DISALLOW_COPY_AND_ASSIGN(RelocIterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 379 | }; |
| 380 | |
| 381 | |
| 382 | //------------------------------------------------------------------------------ |
| 383 | // External function |
| 384 | |
| 385 | //---------------------------------------------------------------------------- |
| 386 | class IC_Utility; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 387 | class SCTableReference; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 388 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 389 | class Debug_Address; |
| 390 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 392 | |
| 393 | typedef 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 401 | class ExternalReference BASE_EMBEDDED { |
| 402 | public: |
| 403 | explicit ExternalReference(Builtins::CFunctionId id); |
| 404 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 405 | explicit ExternalReference(ApiFunction* ptr); |
| 406 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | 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.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 415 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 416 | explicit ExternalReference(const Debug_Address& debug_address); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 417 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 418 | |
| 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.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 429 | static ExternalReference perform_gc_function(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 430 | static ExternalReference fill_heap_number_with_random_function(); |
| 431 | static ExternalReference random_uint32_function(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 432 | static ExternalReference transcendental_cache_array_address(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 434 | // 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 438 | // Static variable Factory::the_hole_value.location() |
| 439 | static ExternalReference the_hole_value_location(); |
| 440 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 441 | // Static variable Heap::roots_address() |
| 442 | static ExternalReference roots_address(); |
| 443 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 444 | // Static variable StackGuard::address_of_jslimit() |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 445 | 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 449 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 450 | // Static variable RegExpStack::limit_address() |
| 451 | static ExternalReference address_of_regexp_stack_limit(); |
| 452 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 453 | // 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 458 | // Static variable Heap::NewSpaceStart() |
| 459 | static ExternalReference new_space_start(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 460 | static ExternalReference new_space_mask(); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 461 | static ExternalReference heap_always_allocate_scope_depth(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 462 | |
| 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.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 467 | static ExternalReference double_fp_operation(Token::Value operation); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 468 | static ExternalReference compare_doubles(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 470 | 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.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 476 | Address address() const {return reinterpret_cast<Address>(address_);} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 478 | #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.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 486 | #ifndef V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 487 | // 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.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 497 | |
| 498 | // byte NativeRegExpMacroAssembler::word_character_bitmap |
| 499 | static ExternalReference re_word_character_map(); |
| 500 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 501 | #endif |
| 502 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 503 | // 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | private: |
| 511 | explicit ExternalReference(void* address) |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 512 | : address_(address) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 513 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 514 | static ExternalReferenceRedirector* redirector_; |
| 515 | |
| 516 | static void* Redirect(void* address, bool fp_return = false) { |
| 517 | if (redirector_ == NULL) return address; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 518 | void* answer = (*redirector_)(address, fp_return); |
| 519 | return answer; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static void* Redirect(Address address_arg, bool fp_return = false) { |
| 523 | void* address = reinterpret_cast<void*>(address_arg); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 524 | void* answer = (redirector_ == NULL) ? |
| 525 | address : |
| 526 | (*redirector_)(address, fp_return); |
| 527 | return answer; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | void* address_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | }; |
| 532 | |
| 533 | |
| 534 | // ----------------------------------------------------------------------------- |
| 535 | // Utility functions |
| 536 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 537 | static inline bool is_intn(int x, int n) { |
| 538 | return -(1 << (n-1)) <= x && x < (1 << (n-1)); |
| 539 | } |
| 540 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 541 | static inline bool is_int8(int x) { return is_intn(x, 8); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 542 | static inline bool is_int16(int x) { return is_intn(x, 16); } |
| 543 | static inline bool is_int18(int x) { return is_intn(x, 18); } |
| 544 | static inline bool is_int24(int x) { return is_intn(x, 24); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | |
| 546 | static inline bool is_uintn(int x, int n) { |
| 547 | return (x & -(1 << n)) == 0; |
| 548 | } |
| 549 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 550 | static inline bool is_uint2(int x) { return is_uintn(x, 2); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 551 | static inline bool is_uint3(int x) { return is_uintn(x, 3); } |
| 552 | static inline bool is_uint4(int x) { return is_uintn(x, 4); } |
| 553 | static inline bool is_uint5(int x) { return is_uintn(x, 5); } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 554 | static inline bool is_uint6(int x) { return is_uintn(x, 6); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | static inline bool is_uint8(int x) { return is_uintn(x, 8); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 556 | static inline bool is_uint10(int x) { return is_uintn(x, 10); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | static inline bool is_uint12(int x) { return is_uintn(x, 12); } |
| 558 | static inline bool is_uint16(int x) { return is_uintn(x, 16); } |
| 559 | static inline bool is_uint24(int x) { return is_uintn(x, 24); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 560 | static inline bool is_uint26(int x) { return is_uintn(x, 26); } |
| 561 | static inline bool is_uint28(int x) { return is_uintn(x, 28); } |
| 562 | |
| 563 | static 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 570 | |
| 571 | } } // namespace v8::internal |
| 572 | |
| 573 | #endif // V8_ASSEMBLER_H_ |