Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 29 | #define V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 30 | |
| 31 | #include "assembler.h" |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 32 | #include "type-info.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 37 | // Flags used for the AllocateInNewSpace functions. |
| 38 | enum AllocationFlags { |
| 39 | // No special flags. |
| 40 | NO_ALLOCATION_FLAGS = 0, |
| 41 | // Return the pointer to the allocated already tagged as a heap object. |
| 42 | TAG_OBJECT = 1 << 0, |
| 43 | // The content of the result register already contains the allocation top in |
| 44 | // new space. |
| 45 | RESULT_CONTAINS_TOP = 1 << 1 |
| 46 | }; |
| 47 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 48 | // Convenience for platform-independent signatures. We do not normally |
| 49 | // distinguish memory operands from other operands on ia32. |
| 50 | typedef Operand MemOperand; |
| 51 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 52 | // Forward declaration. |
| 53 | class JumpTarget; |
| 54 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 55 | // MacroAssembler implements a collection of frequently used macros. |
| 56 | class MacroAssembler: public Assembler { |
| 57 | public: |
| 58 | MacroAssembler(void* buffer, int size); |
| 59 | |
| 60 | // --------------------------------------------------------------------------- |
| 61 | // GC Support |
| 62 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 63 | // For page containing |object| mark region covering |addr| dirty. |
| 64 | // RecordWriteHelper only works if the object is not in new |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 65 | // space. |
| 66 | void RecordWriteHelper(Register object, |
| 67 | Register addr, |
| 68 | Register scratch); |
| 69 | |
| 70 | // Check if object is in new space. |
| 71 | // scratch can be object itself, but it will be clobbered. |
| 72 | void InNewSpace(Register object, |
| 73 | Register scratch, |
| 74 | Condition cc, // equal for new space, not_equal otherwise. |
| 75 | Label* branch); |
| 76 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 77 | // For page containing |object| mark region covering [object+offset] |
| 78 | // dirty. |object| is the object being stored into, |value| is the |
| 79 | // object being stored. If offset is zero, then the scratch register |
| 80 | // contains the array index into the elements array represented as a |
| 81 | // Smi. All registers are clobbered by the operation. RecordWrite |
| 82 | // filters out smis so it does not update the write barrier if the |
| 83 | // value is a smi. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 84 | void RecordWrite(Register object, |
| 85 | int offset, |
| 86 | Register value, |
| 87 | Register scratch); |
| 88 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 89 | // For page containing |object| mark region covering |address| |
| 90 | // dirty. |object| is the object being stored into, |value| is the |
| 91 | // object being stored. All registers are clobbered by the |
| 92 | // operation. RecordWrite filters out smis so it does not update the |
| 93 | // write barrier if the value is a smi. |
| 94 | void RecordWrite(Register object, |
| 95 | Register address, |
| 96 | Register value); |
| 97 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 98 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 99 | // --------------------------------------------------------------------------- |
| 100 | // Debugger Support |
| 101 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 102 | void DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 103 | #endif |
| 104 | |
| 105 | // --------------------------------------------------------------------------- |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 106 | // Stack limit support |
| 107 | |
| 108 | // Do simple test for stack overflow. This doesn't handle an overflow. |
| 109 | void StackLimitCheck(Label* on_stack_limit_hit); |
| 110 | |
| 111 | // --------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 112 | // Activation frames |
| 113 | |
| 114 | void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } |
| 115 | void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } |
| 116 | |
| 117 | void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } |
| 118 | void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } |
| 119 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 120 | // Enter specific kind of exit frame; either in normal or debug mode. |
| 121 | // Expects the number of arguments in register eax and |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 122 | // sets up the number of arguments in register edi and the pointer |
| 123 | // to the first argument in register esi. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 124 | void EnterExitFrame(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 125 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 126 | void EnterApiExitFrame(int stack_space, int argc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 127 | |
| 128 | // Leave the current exit frame. Expects the return value in |
| 129 | // register eax:edx (untouched) and the pointer to the first |
| 130 | // argument in register esi. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 131 | void LeaveExitFrame(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 132 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 133 | // Find the function context up the context chain. |
| 134 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 135 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 136 | // Load the global function with the given index. |
| 137 | void LoadGlobalFunction(int index, Register function); |
| 138 | |
| 139 | // Load the initial map from the global function. The registers |
| 140 | // function and map can be the same. |
| 141 | void LoadGlobalFunctionInitialMap(Register function, Register map); |
| 142 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 143 | // --------------------------------------------------------------------------- |
| 144 | // JavaScript invokes |
| 145 | |
| 146 | // Invoke the JavaScript function code by either calling or jumping. |
| 147 | void InvokeCode(const Operand& code, |
| 148 | const ParameterCount& expected, |
| 149 | const ParameterCount& actual, |
| 150 | InvokeFlag flag); |
| 151 | |
| 152 | void InvokeCode(Handle<Code> code, |
| 153 | const ParameterCount& expected, |
| 154 | const ParameterCount& actual, |
| 155 | RelocInfo::Mode rmode, |
| 156 | InvokeFlag flag); |
| 157 | |
| 158 | // Invoke the JavaScript function in the given register. Changes the |
| 159 | // current context to the context in the function before invoking. |
| 160 | void InvokeFunction(Register function, |
| 161 | const ParameterCount& actual, |
| 162 | InvokeFlag flag); |
| 163 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 164 | void InvokeFunction(JSFunction* function, |
| 165 | const ParameterCount& actual, |
| 166 | InvokeFlag flag); |
| 167 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 168 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 169 | // the unresolved list if the name does not resolve. |
| 170 | void InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag); |
| 171 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 172 | // Store the function for the given builtin in the target register. |
| 173 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 174 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 175 | // Store the code object for the given builtin in the target register. |
| 176 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 177 | |
| 178 | // Expression support |
| 179 | void Set(Register dst, const Immediate& x); |
| 180 | void Set(const Operand& dst, const Immediate& x); |
| 181 | |
| 182 | // Compare object type for heap object. |
| 183 | // Incoming register is heap_object and outgoing register is map. |
| 184 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 185 | |
| 186 | // Compare instance type for map. |
| 187 | void CmpInstanceType(Register map, InstanceType type); |
| 188 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 189 | // Check if the map of an object is equal to a specified map and |
| 190 | // branch to label if not. Skip the smi check if not required |
| 191 | // (object is known to be a heap object) |
| 192 | void CheckMap(Register obj, |
| 193 | Handle<Map> map, |
| 194 | Label* fail, |
| 195 | bool is_heap_object); |
| 196 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 197 | // Check if the object in register heap_object is a string. Afterwards the |
| 198 | // register map contains the object map and the register instance_type |
| 199 | // contains the instance_type. The registers map and instance_type can be the |
| 200 | // same in which case it contains the instance type afterwards. Either of the |
| 201 | // registers map and instance_type can be the same as heap_object. |
| 202 | Condition IsObjectStringType(Register heap_object, |
| 203 | Register map, |
| 204 | Register instance_type); |
| 205 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 206 | // Check if a heap object's type is in the JSObject range, not including |
| 207 | // JSFunction. The object's map will be loaded in the map register. |
| 208 | // Any or all of the three registers may be the same. |
| 209 | // The contents of the scratch register will always be overwritten. |
| 210 | void IsObjectJSObjectType(Register heap_object, |
| 211 | Register map, |
| 212 | Register scratch, |
| 213 | Label* fail); |
| 214 | |
| 215 | // The contents of the scratch register will be overwritten. |
| 216 | void IsInstanceJSObjectType(Register map, Register scratch, Label* fail); |
| 217 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 218 | // FCmp is similar to integer cmp, but requires unsigned |
| 219 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 220 | void FCmp(); |
| 221 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 222 | // Smi tagging support. |
| 223 | void SmiTag(Register reg) { |
| 224 | ASSERT(kSmiTag == 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 225 | ASSERT(kSmiTagSize == 1); |
| 226 | add(reg, Operand(reg)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 227 | } |
| 228 | void SmiUntag(Register reg) { |
| 229 | sar(reg, kSmiTagSize); |
| 230 | } |
| 231 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 232 | // Modifies the register even if it does not contain a Smi! |
| 233 | void SmiUntag(Register reg, TypeInfo info, Label* non_smi) { |
| 234 | ASSERT(kSmiTagSize == 1); |
| 235 | sar(reg, kSmiTagSize); |
| 236 | if (info.IsSmi()) { |
| 237 | ASSERT(kSmiTag == 0); |
| 238 | j(carry, non_smi); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // Modifies the register even if it does not contain a Smi! |
| 243 | void SmiUntag(Register reg, Label* is_smi) { |
| 244 | ASSERT(kSmiTagSize == 1); |
| 245 | sar(reg, kSmiTagSize); |
| 246 | ASSERT(kSmiTag == 0); |
| 247 | j(not_carry, is_smi); |
| 248 | } |
| 249 | |
| 250 | // Assumes input is a heap object. |
| 251 | void JumpIfNotNumber(Register reg, TypeInfo info, Label* on_not_number); |
| 252 | |
| 253 | // Assumes input is a heap number. Jumps on things out of range. Also jumps |
| 254 | // on the min negative int32. Ignores frational parts. |
| 255 | void ConvertToInt32(Register dst, |
| 256 | Register src, // Can be the same as dst. |
| 257 | Register scratch, // Can be no_reg or dst, but not src. |
| 258 | TypeInfo info, |
| 259 | Label* on_not_int32); |
| 260 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 261 | void LoadPowerOf2(XMMRegister dst, Register scratch, int power); |
| 262 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 263 | // Abort execution if argument is not a number. Used in debug code. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 264 | void AbortIfNotNumber(Register object); |
| 265 | |
| 266 | // Abort execution if argument is not a smi. Used in debug code. |
| 267 | void AbortIfNotSmi(Register object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 268 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 269 | // Abort execution if argument is a smi. Used in debug code. |
| 270 | void AbortIfSmi(Register object); |
| 271 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 272 | // Abort execution if argument is a string. Used in debug code. |
| 273 | void AbortIfNotString(Register object); |
| 274 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 275 | // --------------------------------------------------------------------------- |
| 276 | // Exception handling |
| 277 | |
| 278 | // Push a new try handler and link into try handler chain. The return |
| 279 | // address must be pushed before calling this helper. |
| 280 | void PushTryHandler(CodeLocation try_location, HandlerType type); |
| 281 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 282 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 283 | void PopTryHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 284 | |
| 285 | // --------------------------------------------------------------------------- |
| 286 | // Inline caching support |
| 287 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 288 | // Generate code for checking access rights - used for security checks |
| 289 | // on access to global objects across environments. The holder register |
| 290 | // is left untouched, but the scratch register is clobbered. |
| 291 | void CheckAccessGlobalProxy(Register holder_reg, |
| 292 | Register scratch, |
| 293 | Label* miss); |
| 294 | |
| 295 | |
| 296 | // --------------------------------------------------------------------------- |
| 297 | // Allocation support |
| 298 | |
| 299 | // Allocate an object in new space. If the new space is exhausted control |
| 300 | // continues at the gc_required label. The allocated object is returned in |
| 301 | // result and end of the new object is returned in result_end. The register |
| 302 | // scratch can be passed as no_reg in which case an additional object |
| 303 | // reference will be added to the reloc info. The returned pointers in result |
| 304 | // and result_end have not yet been tagged as heap objects. If |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 305 | // result_contains_top_on_entry is true the content of result is known to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 306 | // the allocation top on entry (could be result_end from a previous call to |
| 307 | // AllocateInNewSpace). If result_contains_top_on_entry is true scratch |
| 308 | // should be no_reg as it is never used. |
| 309 | void AllocateInNewSpace(int object_size, |
| 310 | Register result, |
| 311 | Register result_end, |
| 312 | Register scratch, |
| 313 | Label* gc_required, |
| 314 | AllocationFlags flags); |
| 315 | |
| 316 | void AllocateInNewSpace(int header_size, |
| 317 | ScaleFactor element_size, |
| 318 | Register element_count, |
| 319 | Register result, |
| 320 | Register result_end, |
| 321 | Register scratch, |
| 322 | Label* gc_required, |
| 323 | AllocationFlags flags); |
| 324 | |
| 325 | void AllocateInNewSpace(Register object_size, |
| 326 | Register result, |
| 327 | Register result_end, |
| 328 | Register scratch, |
| 329 | Label* gc_required, |
| 330 | AllocationFlags flags); |
| 331 | |
| 332 | // Undo allocation in new space. The object passed and objects allocated after |
| 333 | // it will no longer be allocated. Make sure that no pointers are left to the |
| 334 | // object(s) no longer allocated as they would be invalid when allocation is |
| 335 | // un-done. |
| 336 | void UndoAllocationInNewSpace(Register object); |
| 337 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 338 | // Allocate a heap number in new space with undefined value. The |
| 339 | // register scratch2 can be passed as no_reg; the others must be |
| 340 | // valid registers. Returns tagged pointer in result register, or |
| 341 | // jumps to gc_required if new space is full. |
| 342 | void AllocateHeapNumber(Register result, |
| 343 | Register scratch1, |
| 344 | Register scratch2, |
| 345 | Label* gc_required); |
| 346 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 347 | // Allocate a sequential string. All the header fields of the string object |
| 348 | // are initialized. |
| 349 | void AllocateTwoByteString(Register result, |
| 350 | Register length, |
| 351 | Register scratch1, |
| 352 | Register scratch2, |
| 353 | Register scratch3, |
| 354 | Label* gc_required); |
| 355 | void AllocateAsciiString(Register result, |
| 356 | Register length, |
| 357 | Register scratch1, |
| 358 | Register scratch2, |
| 359 | Register scratch3, |
| 360 | Label* gc_required); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 361 | void AllocateAsciiString(Register result, |
| 362 | int length, |
| 363 | Register scratch1, |
| 364 | Register scratch2, |
| 365 | Label* gc_required); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 366 | |
| 367 | // Allocate a raw cons string object. Only the map field of the result is |
| 368 | // initialized. |
| 369 | void AllocateConsString(Register result, |
| 370 | Register scratch1, |
| 371 | Register scratch2, |
| 372 | Label* gc_required); |
| 373 | void AllocateAsciiConsString(Register result, |
| 374 | Register scratch1, |
| 375 | Register scratch2, |
| 376 | Label* gc_required); |
| 377 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 378 | // --------------------------------------------------------------------------- |
| 379 | // Support functions. |
| 380 | |
| 381 | // Check if result is zero and op is negative. |
| 382 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 383 | |
| 384 | // Check if result is zero and op is negative in code using jump targets. |
| 385 | void NegativeZeroTest(CodeGenerator* cgen, |
| 386 | Register result, |
| 387 | Register op, |
| 388 | JumpTarget* then_target); |
| 389 | |
| 390 | // Check if result is zero and any of op1 and op2 are negative. |
| 391 | // Register scratch is destroyed, and it must be different from op2. |
| 392 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 393 | Register scratch, Label* then_label); |
| 394 | |
| 395 | // Try to get function prototype of a function and puts the value in |
| 396 | // the result register. Checks that the function really is a |
| 397 | // function and jumps to the miss label if the fast checks fail. The |
| 398 | // function register will be untouched; the other registers may be |
| 399 | // clobbered. |
| 400 | void TryGetFunctionPrototype(Register function, |
| 401 | Register result, |
| 402 | Register scratch, |
| 403 | Label* miss); |
| 404 | |
| 405 | // Generates code for reporting that an illegal operation has |
| 406 | // occurred. |
| 407 | void IllegalOperation(int num_arguments); |
| 408 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 409 | // Picks out an array index from the hash field. |
| 410 | // Register use: |
| 411 | // hash - holds the index's hash. Clobbered. |
| 412 | // index - holds the overwritten index on exit. |
| 413 | void IndexFromHash(Register hash, Register index); |
| 414 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 415 | // --------------------------------------------------------------------------- |
| 416 | // Runtime calls |
| 417 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 418 | // Call a code stub. Generate the code if necessary. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 419 | void CallStub(CodeStub* stub); |
| 420 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 421 | // Call a code stub and return the code object called. Try to generate |
| 422 | // the code if necessary. Do not perform a GC but instead return a retry |
| 423 | // after GC failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 424 | MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 425 | |
| 426 | // Tail call a code stub (jump). Generate the code if necessary. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 427 | void TailCallStub(CodeStub* stub); |
| 428 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 429 | // Tail call a code stub (jump) and return the code object called. Try to |
| 430 | // generate the code if necessary. Do not perform a GC but instead return |
| 431 | // a retry after GC failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 432 | MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 433 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 434 | // Return from a code stub after popping its arguments. |
| 435 | void StubReturn(int argc); |
| 436 | |
| 437 | // Call a runtime routine. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 438 | void CallRuntime(Runtime::Function* f, int num_arguments); |
| 439 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 440 | // Call a runtime function, returning the CodeStub object called. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 441 | // Try to generate the stub code if necessary. Do not perform a GC |
| 442 | // but instead return a retry after GC failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 443 | MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::Function* f, |
| 444 | int num_arguments); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 445 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 446 | // Convenience function: Same as above, but takes the fid instead. |
| 447 | void CallRuntime(Runtime::FunctionId id, int num_arguments); |
| 448 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 449 | // Convenience function: Same as above, but takes the fid instead. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 450 | MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id, |
| 451 | int num_arguments); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 452 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 453 | // Convenience function: call an external reference. |
| 454 | void CallExternalReference(ExternalReference ref, int num_arguments); |
| 455 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 456 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 457 | // Like JumpToExternalReference, but also takes care of passing the number |
| 458 | // of parameters. |
| 459 | void TailCallExternalReference(const ExternalReference& ext, |
| 460 | int num_arguments, |
| 461 | int result_size); |
| 462 | |
| 463 | // Convenience function: tail call a runtime routine (jump). |
| 464 | void TailCallRuntime(Runtime::FunctionId fid, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 465 | int num_arguments, |
| 466 | int result_size); |
| 467 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 468 | // Before calling a C-function from generated code, align arguments on stack. |
| 469 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 470 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 471 | // Some compilers/platforms require the stack to be aligned when calling |
| 472 | // C++ code. |
| 473 | // Needs a scratch register to do some arithmetic. This register will be |
| 474 | // trashed. |
| 475 | void PrepareCallCFunction(int num_arguments, Register scratch); |
| 476 | |
| 477 | // Calls a C function and cleans up the space for arguments allocated |
| 478 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 479 | // garbage collection, since that might move the code and invalidate the |
| 480 | // return address (unless this is somehow accounted for by the called |
| 481 | // function). |
| 482 | void CallCFunction(ExternalReference function, int num_arguments); |
| 483 | void CallCFunction(Register function, int num_arguments); |
| 484 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 485 | // Prepares stack to put arguments (aligns and so on). Reserves |
| 486 | // space for return value if needed (assumes the return value is a handle). |
| 487 | // Uses callee-saved esi to restore stack state after call. Arguments must be |
| 488 | // stored in ApiParameterOperand(0), ApiParameterOperand(1) etc. |
| 489 | void PrepareCallApiFunction(int stack_space, int argc); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 490 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 491 | // Tail call an API function (jump). Allocates HandleScope, extracts |
| 492 | // returned value from handle and propagates exceptions. |
| 493 | // Clobbers ebx, esi, edi and caller-save registers. |
| 494 | void CallApiFunctionAndReturn(ApiFunction* function, int argc); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 495 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 496 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 497 | void JumpToExternalReference(const ExternalReference& ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 498 | |
| 499 | |
| 500 | // --------------------------------------------------------------------------- |
| 501 | // Utilities |
| 502 | |
| 503 | void Ret(); |
| 504 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 505 | // Emit code to discard a non-negative number of pointer-sized elements |
| 506 | // from the stack, clobbering only the esp register. |
| 507 | void Drop(int element_count); |
| 508 | |
| 509 | void Call(Label* target) { call(target); } |
| 510 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 511 | // Move if the registers are not identical. |
| 512 | void Move(Register target, Register source); |
| 513 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 514 | void Move(Register target, Handle<Object> value); |
| 515 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 516 | Handle<Object> CodeObject() { return code_object_; } |
| 517 | |
| 518 | |
| 519 | // --------------------------------------------------------------------------- |
| 520 | // StatsCounter support |
| 521 | |
| 522 | void SetCounter(StatsCounter* counter, int value); |
| 523 | void IncrementCounter(StatsCounter* counter, int value); |
| 524 | void DecrementCounter(StatsCounter* counter, int value); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 525 | void IncrementCounter(Condition cc, StatsCounter* counter, int value); |
| 526 | void DecrementCounter(Condition cc, StatsCounter* counter, int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 527 | |
| 528 | |
| 529 | // --------------------------------------------------------------------------- |
| 530 | // Debugging |
| 531 | |
| 532 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 533 | // Use --debug_code to enable. |
| 534 | void Assert(Condition cc, const char* msg); |
| 535 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 536 | void AssertFastElements(Register elements); |
| 537 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 538 | // Like Assert(), but always enabled. |
| 539 | void Check(Condition cc, const char* msg); |
| 540 | |
| 541 | // Print a message to stdout and abort execution. |
| 542 | void Abort(const char* msg); |
| 543 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 544 | // Check that the stack is aligned. |
| 545 | void CheckStackAlignment(); |
| 546 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 547 | // Verify restrictions about code generated in stubs. |
| 548 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 549 | bool generating_stub() { return generating_stub_; } |
| 550 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 551 | bool allow_stub_calls() { return allow_stub_calls_; } |
| 552 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 553 | // --------------------------------------------------------------------------- |
| 554 | // String utilities. |
| 555 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 556 | // Check whether the instance type represents a flat ascii string. Jump to the |
| 557 | // label if not. If the instance type can be scratched specify same register |
| 558 | // for both instance type and scratch. |
| 559 | void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type, |
| 560 | Register scratch, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 561 | Label* on_not_flat_ascii_string); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 562 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 563 | // Checks if both objects are sequential ASCII strings, and jumps to label |
| 564 | // if either is not. |
| 565 | void JumpIfNotBothSequentialAsciiStrings(Register object1, |
| 566 | Register object2, |
| 567 | Register scratch1, |
| 568 | Register scratch2, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 569 | Label* on_not_flat_ascii_strings); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 570 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 571 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 572 | bool generating_stub_; |
| 573 | bool allow_stub_calls_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 574 | // This handle will be patched with the code object on installation. |
| 575 | Handle<Object> code_object_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 576 | |
| 577 | // Helper functions for generating invokes. |
| 578 | void InvokePrologue(const ParameterCount& expected, |
| 579 | const ParameterCount& actual, |
| 580 | Handle<Code> code_constant, |
| 581 | const Operand& code_operand, |
| 582 | Label* done, |
| 583 | InvokeFlag flag); |
| 584 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 585 | // Activation support. |
| 586 | void EnterFrame(StackFrame::Type type); |
| 587 | void LeaveFrame(StackFrame::Type type); |
| 588 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 589 | void EnterExitFramePrologue(); |
| 590 | void EnterExitFrameEpilogue(int argc); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 591 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 592 | // Allocation support helpers. |
| 593 | void LoadAllocationTopHelper(Register result, |
| 594 | Register result_end, |
| 595 | Register scratch, |
| 596 | AllocationFlags flags); |
| 597 | void UpdateAllocationTopHelper(Register result_end, Register scratch); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 598 | |
| 599 | // Helper for PopHandleScope. Allowed to perform a GC and returns |
| 600 | // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and |
| 601 | // possibly returns a failure object indicating an allocation failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 602 | MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved, |
| 603 | Register scratch, |
| 604 | bool gc_allowed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 605 | }; |
| 606 | |
| 607 | |
| 608 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 609 | // debugging and other types of instrumentation. When using the code patcher |
| 610 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 611 | // relocation information. If any of these constraints are violated it causes |
| 612 | // an assertion. |
| 613 | class CodePatcher { |
| 614 | public: |
| 615 | CodePatcher(byte* address, int size); |
| 616 | virtual ~CodePatcher(); |
| 617 | |
| 618 | // Macro assembler to emit code. |
| 619 | MacroAssembler* masm() { return &masm_; } |
| 620 | |
| 621 | private: |
| 622 | byte* address_; // The address of the code being patched. |
| 623 | int size_; // Number of bytes of the expected patch size. |
| 624 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 625 | }; |
| 626 | |
| 627 | |
| 628 | // ----------------------------------------------------------------------------- |
| 629 | // Static helper functions. |
| 630 | |
| 631 | // Generate an Operand for loading a field from an object. |
| 632 | static inline Operand FieldOperand(Register object, int offset) { |
| 633 | return Operand(object, offset - kHeapObjectTag); |
| 634 | } |
| 635 | |
| 636 | |
| 637 | // Generate an Operand for loading an indexed field from an object. |
| 638 | static inline Operand FieldOperand(Register object, |
| 639 | Register index, |
| 640 | ScaleFactor scale, |
| 641 | int offset) { |
| 642 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 643 | } |
| 644 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 645 | // Generates an Operand for saving parameters after PrepareCallApiFunction. |
| 646 | Operand ApiParameterOperand(int index); |
| 647 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 648 | |
| 649 | #ifdef GENERATED_CODE_COVERAGE |
| 650 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 651 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 652 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 653 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 654 | #define ACCESS_MASM(masm) { \ |
| 655 | byte* ia32_coverage_function = \ |
| 656 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 657 | masm->pushfd(); \ |
| 658 | masm->pushad(); \ |
| 659 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 660 | masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 661 | masm->pop(eax); \ |
| 662 | masm->popad(); \ |
| 663 | masm->popfd(); \ |
| 664 | } \ |
| 665 | masm-> |
| 666 | #else |
| 667 | #define ACCESS_MASM(masm) masm-> |
| 668 | #endif |
| 669 | |
| 670 | |
| 671 | } } // namespace v8::internal |
| 672 | |
| 673 | #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ |