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" |
| 32 | |
| 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 36 | // Convenience for platform-independent signatures. We do not normally |
| 37 | // distinguish memory operands from other operands on ia32. |
| 38 | typedef Operand MemOperand; |
| 39 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 40 | // Forward declaration. |
| 41 | class JumpTarget; |
| 42 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 43 | // MacroAssembler implements a collection of frequently used macros. |
| 44 | class MacroAssembler: public Assembler { |
| 45 | public: |
| 46 | MacroAssembler(void* buffer, int size); |
| 47 | |
| 48 | // --------------------------------------------------------------------------- |
| 49 | // GC Support |
| 50 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 51 | // Set the remebered set bit for an address which points into an |
| 52 | // object. RecordWriteHelper only works if the object is not in new |
| 53 | // space. |
| 54 | void RecordWriteHelper(Register object, |
| 55 | Register addr, |
| 56 | Register scratch); |
| 57 | |
| 58 | // Check if object is in new space. |
| 59 | // scratch can be object itself, but it will be clobbered. |
| 60 | void InNewSpace(Register object, |
| 61 | Register scratch, |
| 62 | Condition cc, // equal for new space, not_equal otherwise. |
| 63 | Label* branch); |
| 64 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 65 | // Set the remembered set bit for [object+offset]. |
| 66 | // object is the object being stored into, value is the object being stored. |
| 67 | // If offset is zero, then the scratch register contains the array index into |
| 68 | // the elements array represented as a Smi. |
| 69 | // All registers are clobbered by the operation. |
| 70 | void RecordWrite(Register object, |
| 71 | int offset, |
| 72 | Register value, |
| 73 | Register scratch); |
| 74 | |
| 75 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 76 | // --------------------------------------------------------------------------- |
| 77 | // Debugger Support |
| 78 | |
| 79 | void SaveRegistersToMemory(RegList regs); |
| 80 | void RestoreRegistersFromMemory(RegList regs); |
| 81 | void PushRegistersFromMemory(RegList regs); |
| 82 | void PopRegistersToMemory(RegList regs); |
| 83 | void CopyRegistersFromStackToMemory(Register base, |
| 84 | Register scratch, |
| 85 | RegList regs); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 86 | void DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 87 | #endif |
| 88 | |
| 89 | // --------------------------------------------------------------------------- |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 90 | // Stack limit support |
| 91 | |
| 92 | // Do simple test for stack overflow. This doesn't handle an overflow. |
| 93 | void StackLimitCheck(Label* on_stack_limit_hit); |
| 94 | |
| 95 | // --------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 96 | // Activation frames |
| 97 | |
| 98 | void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } |
| 99 | void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } |
| 100 | |
| 101 | void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } |
| 102 | void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } |
| 103 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 104 | // Enter specific kind of exit frame; either in normal or debug mode. |
| 105 | // Expects the number of arguments in register eax and |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 106 | // sets up the number of arguments in register edi and the pointer |
| 107 | // to the first argument in register esi. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 108 | void EnterExitFrame(ExitFrame::Mode mode); |
| 109 | |
| 110 | void EnterApiExitFrame(ExitFrame::Mode mode, int stack_space, int argc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 111 | |
| 112 | // Leave the current exit frame. Expects the return value in |
| 113 | // register eax:edx (untouched) and the pointer to the first |
| 114 | // argument in register esi. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 115 | void LeaveExitFrame(ExitFrame::Mode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 116 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 117 | // Find the function context up the context chain. |
| 118 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 119 | |
| 120 | // --------------------------------------------------------------------------- |
| 121 | // JavaScript invokes |
| 122 | |
| 123 | // Invoke the JavaScript function code by either calling or jumping. |
| 124 | void InvokeCode(const Operand& code, |
| 125 | const ParameterCount& expected, |
| 126 | const ParameterCount& actual, |
| 127 | InvokeFlag flag); |
| 128 | |
| 129 | void InvokeCode(Handle<Code> code, |
| 130 | const ParameterCount& expected, |
| 131 | const ParameterCount& actual, |
| 132 | RelocInfo::Mode rmode, |
| 133 | InvokeFlag flag); |
| 134 | |
| 135 | // Invoke the JavaScript function in the given register. Changes the |
| 136 | // current context to the context in the function before invoking. |
| 137 | void InvokeFunction(Register function, |
| 138 | const ParameterCount& actual, |
| 139 | InvokeFlag flag); |
| 140 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 141 | void InvokeFunction(JSFunction* function, |
| 142 | const ParameterCount& actual, |
| 143 | InvokeFlag flag); |
| 144 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 145 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 146 | // the unresolved list if the name does not resolve. |
| 147 | void InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag); |
| 148 | |
| 149 | // Store the code object for the given builtin in the target register. |
| 150 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 151 | |
| 152 | // Expression support |
| 153 | void Set(Register dst, const Immediate& x); |
| 154 | void Set(const Operand& dst, const Immediate& x); |
| 155 | |
| 156 | // Compare object type for heap object. |
| 157 | // Incoming register is heap_object and outgoing register is map. |
| 158 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 159 | |
| 160 | // Compare instance type for map. |
| 161 | void CmpInstanceType(Register map, InstanceType type); |
| 162 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 163 | // Check if the map of an object is equal to a specified map and |
| 164 | // branch to label if not. Skip the smi check if not required |
| 165 | // (object is known to be a heap object) |
| 166 | void CheckMap(Register obj, |
| 167 | Handle<Map> map, |
| 168 | Label* fail, |
| 169 | bool is_heap_object); |
| 170 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 171 | // Check if the object in register heap_object is a string. Afterwards the |
| 172 | // register map contains the object map and the register instance_type |
| 173 | // contains the instance_type. The registers map and instance_type can be the |
| 174 | // same in which case it contains the instance type afterwards. Either of the |
| 175 | // registers map and instance_type can be the same as heap_object. |
| 176 | Condition IsObjectStringType(Register heap_object, |
| 177 | Register map, |
| 178 | Register instance_type); |
| 179 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 180 | // FCmp is similar to integer cmp, but requires unsigned |
| 181 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 182 | void FCmp(); |
| 183 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 184 | // Smi tagging support. |
| 185 | void SmiTag(Register reg) { |
| 186 | ASSERT(kSmiTag == 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 187 | ASSERT(kSmiTagSize == 1); |
| 188 | add(reg, Operand(reg)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 189 | } |
| 190 | void SmiUntag(Register reg) { |
| 191 | sar(reg, kSmiTagSize); |
| 192 | } |
| 193 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 194 | // Abort execution if argument is not a number. Used in debug code. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 195 | void AbortIfNotNumber(Register object); |
| 196 | |
| 197 | // Abort execution if argument is not a smi. Used in debug code. |
| 198 | void AbortIfNotSmi(Register object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 199 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 200 | // --------------------------------------------------------------------------- |
| 201 | // Exception handling |
| 202 | |
| 203 | // Push a new try handler and link into try handler chain. The return |
| 204 | // address must be pushed before calling this helper. |
| 205 | void PushTryHandler(CodeLocation try_location, HandlerType type); |
| 206 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 207 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 208 | void PopTryHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 209 | |
| 210 | // --------------------------------------------------------------------------- |
| 211 | // Inline caching support |
| 212 | |
| 213 | // Generates code that verifies that the maps of objects in the |
| 214 | // prototype chain of object hasn't changed since the code was |
| 215 | // generated and branches to the miss label if any map has. If |
| 216 | // necessary the function also generates code for security check |
| 217 | // in case of global object holders. The scratch and holder |
| 218 | // registers are always clobbered, but the object register is only |
| 219 | // clobbered if it the same as the holder register. The function |
| 220 | // returns a register containing the holder - either object_reg or |
| 221 | // holder_reg. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 222 | // The function can optionally (when save_at_depth != |
| 223 | // kInvalidProtoDepth) save the object at the given depth by moving |
| 224 | // it to [esp + kPointerSize]. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 225 | Register CheckMaps(JSObject* object, Register object_reg, |
| 226 | JSObject* holder, Register holder_reg, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 227 | Register scratch, |
| 228 | int save_at_depth, |
| 229 | Label* miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 230 | |
| 231 | // Generate code for checking access rights - used for security checks |
| 232 | // on access to global objects across environments. The holder register |
| 233 | // is left untouched, but the scratch register is clobbered. |
| 234 | void CheckAccessGlobalProxy(Register holder_reg, |
| 235 | Register scratch, |
| 236 | Label* miss); |
| 237 | |
| 238 | |
| 239 | // --------------------------------------------------------------------------- |
| 240 | // Allocation support |
| 241 | |
| 242 | // Allocate an object in new space. If the new space is exhausted control |
| 243 | // continues at the gc_required label. The allocated object is returned in |
| 244 | // result and end of the new object is returned in result_end. The register |
| 245 | // scratch can be passed as no_reg in which case an additional object |
| 246 | // reference will be added to the reloc info. The returned pointers in result |
| 247 | // and result_end have not yet been tagged as heap objects. If |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 248 | // 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] | 249 | // the allocation top on entry (could be result_end from a previous call to |
| 250 | // AllocateInNewSpace). If result_contains_top_on_entry is true scratch |
| 251 | // should be no_reg as it is never used. |
| 252 | void AllocateInNewSpace(int object_size, |
| 253 | Register result, |
| 254 | Register result_end, |
| 255 | Register scratch, |
| 256 | Label* gc_required, |
| 257 | AllocationFlags flags); |
| 258 | |
| 259 | void AllocateInNewSpace(int header_size, |
| 260 | ScaleFactor element_size, |
| 261 | Register element_count, |
| 262 | Register result, |
| 263 | Register result_end, |
| 264 | Register scratch, |
| 265 | Label* gc_required, |
| 266 | AllocationFlags flags); |
| 267 | |
| 268 | void AllocateInNewSpace(Register object_size, |
| 269 | Register result, |
| 270 | Register result_end, |
| 271 | Register scratch, |
| 272 | Label* gc_required, |
| 273 | AllocationFlags flags); |
| 274 | |
| 275 | // Undo allocation in new space. The object passed and objects allocated after |
| 276 | // it will no longer be allocated. Make sure that no pointers are left to the |
| 277 | // object(s) no longer allocated as they would be invalid when allocation is |
| 278 | // un-done. |
| 279 | void UndoAllocationInNewSpace(Register object); |
| 280 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 281 | // Allocate a heap number in new space with undefined value. The |
| 282 | // register scratch2 can be passed as no_reg; the others must be |
| 283 | // valid registers. Returns tagged pointer in result register, or |
| 284 | // jumps to gc_required if new space is full. |
| 285 | void AllocateHeapNumber(Register result, |
| 286 | Register scratch1, |
| 287 | Register scratch2, |
| 288 | Label* gc_required); |
| 289 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 290 | // Allocate a sequential string. All the header fields of the string object |
| 291 | // are initialized. |
| 292 | void AllocateTwoByteString(Register result, |
| 293 | Register length, |
| 294 | Register scratch1, |
| 295 | Register scratch2, |
| 296 | Register scratch3, |
| 297 | Label* gc_required); |
| 298 | void AllocateAsciiString(Register result, |
| 299 | Register length, |
| 300 | Register scratch1, |
| 301 | Register scratch2, |
| 302 | Register scratch3, |
| 303 | Label* gc_required); |
| 304 | |
| 305 | // Allocate a raw cons string object. Only the map field of the result is |
| 306 | // initialized. |
| 307 | void AllocateConsString(Register result, |
| 308 | Register scratch1, |
| 309 | Register scratch2, |
| 310 | Label* gc_required); |
| 311 | void AllocateAsciiConsString(Register result, |
| 312 | Register scratch1, |
| 313 | Register scratch2, |
| 314 | Label* gc_required); |
| 315 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 316 | // --------------------------------------------------------------------------- |
| 317 | // Support functions. |
| 318 | |
| 319 | // Check if result is zero and op is negative. |
| 320 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 321 | |
| 322 | // Check if result is zero and op is negative in code using jump targets. |
| 323 | void NegativeZeroTest(CodeGenerator* cgen, |
| 324 | Register result, |
| 325 | Register op, |
| 326 | JumpTarget* then_target); |
| 327 | |
| 328 | // Check if result is zero and any of op1 and op2 are negative. |
| 329 | // Register scratch is destroyed, and it must be different from op2. |
| 330 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 331 | Register scratch, Label* then_label); |
| 332 | |
| 333 | // Try to get function prototype of a function and puts the value in |
| 334 | // the result register. Checks that the function really is a |
| 335 | // function and jumps to the miss label if the fast checks fail. The |
| 336 | // function register will be untouched; the other registers may be |
| 337 | // clobbered. |
| 338 | void TryGetFunctionPrototype(Register function, |
| 339 | Register result, |
| 340 | Register scratch, |
| 341 | Label* miss); |
| 342 | |
| 343 | // Generates code for reporting that an illegal operation has |
| 344 | // occurred. |
| 345 | void IllegalOperation(int num_arguments); |
| 346 | |
| 347 | // --------------------------------------------------------------------------- |
| 348 | // Runtime calls |
| 349 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 350 | // Call a code stub. Generate the code if necessary. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 351 | void CallStub(CodeStub* stub); |
| 352 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 353 | // Call a code stub and return the code object called. Try to generate |
| 354 | // the code if necessary. Do not perform a GC but instead return a retry |
| 355 | // after GC failure. |
| 356 | Object* TryCallStub(CodeStub* stub); |
| 357 | |
| 358 | // Tail call a code stub (jump). Generate the code if necessary. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 359 | void TailCallStub(CodeStub* stub); |
| 360 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 361 | // Tail call a code stub (jump) and return the code object called. Try to |
| 362 | // generate the code if necessary. Do not perform a GC but instead return |
| 363 | // a retry after GC failure. |
| 364 | Object* TryTailCallStub(CodeStub* stub); |
| 365 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 366 | // Return from a code stub after popping its arguments. |
| 367 | void StubReturn(int argc); |
| 368 | |
| 369 | // Call a runtime routine. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 370 | void CallRuntime(Runtime::Function* f, int num_arguments); |
| 371 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 372 | // Call a runtime function, returning the CodeStub object called. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 373 | // Try to generate the stub code if necessary. Do not perform a GC |
| 374 | // but instead return a retry after GC failure. |
| 375 | Object* TryCallRuntime(Runtime::Function* f, int num_arguments); |
| 376 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 377 | // Convenience function: Same as above, but takes the fid instead. |
| 378 | void CallRuntime(Runtime::FunctionId id, int num_arguments); |
| 379 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 380 | // Convenience function: call an external reference. |
| 381 | void CallExternalReference(ExternalReference ref, int num_arguments); |
| 382 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 383 | // Convenience function: Same as above, but takes the fid instead. |
| 384 | Object* TryCallRuntime(Runtime::FunctionId id, int num_arguments); |
| 385 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 386 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 387 | // Like JumpToExternalReference, but also takes care of passing the number |
| 388 | // of parameters. |
| 389 | void TailCallExternalReference(const ExternalReference& ext, |
| 390 | int num_arguments, |
| 391 | int result_size); |
| 392 | |
| 393 | // Convenience function: tail call a runtime routine (jump). |
| 394 | void TailCallRuntime(Runtime::FunctionId fid, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | int num_arguments, |
| 396 | int result_size); |
| 397 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 398 | // Before calling a C-function from generated code, align arguments on stack. |
| 399 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 400 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 401 | // Some compilers/platforms require the stack to be aligned when calling |
| 402 | // C++ code. |
| 403 | // Needs a scratch register to do some arithmetic. This register will be |
| 404 | // trashed. |
| 405 | void PrepareCallCFunction(int num_arguments, Register scratch); |
| 406 | |
| 407 | // Calls a C function and cleans up the space for arguments allocated |
| 408 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 409 | // garbage collection, since that might move the code and invalidate the |
| 410 | // return address (unless this is somehow accounted for by the called |
| 411 | // function). |
| 412 | void CallCFunction(ExternalReference function, int num_arguments); |
| 413 | void CallCFunction(Register function, int num_arguments); |
| 414 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 415 | void PushHandleScope(Register scratch); |
| 416 | |
| 417 | // Pops a handle scope using the specified scratch register and |
| 418 | // ensuring that saved register, it is not no_reg, is left unchanged. |
| 419 | void PopHandleScope(Register saved, Register scratch); |
| 420 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 421 | // As PopHandleScope, but does not perform a GC. Instead, returns a |
| 422 | // retry after GC failure object if GC is necessary. |
| 423 | Object* TryPopHandleScope(Register saved, Register scratch); |
| 424 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 425 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 426 | void JumpToExternalReference(const ExternalReference& ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 427 | |
| 428 | |
| 429 | // --------------------------------------------------------------------------- |
| 430 | // Utilities |
| 431 | |
| 432 | void Ret(); |
| 433 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 434 | // Emit code to discard a non-negative number of pointer-sized elements |
| 435 | // from the stack, clobbering only the esp register. |
| 436 | void Drop(int element_count); |
| 437 | |
| 438 | void Call(Label* target) { call(target); } |
| 439 | |
| 440 | void Move(Register target, Handle<Object> value); |
| 441 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 442 | Handle<Object> CodeObject() { return code_object_; } |
| 443 | |
| 444 | |
| 445 | // --------------------------------------------------------------------------- |
| 446 | // StatsCounter support |
| 447 | |
| 448 | void SetCounter(StatsCounter* counter, int value); |
| 449 | void IncrementCounter(StatsCounter* counter, int value); |
| 450 | void DecrementCounter(StatsCounter* counter, int value); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 451 | void IncrementCounter(Condition cc, StatsCounter* counter, int value); |
| 452 | void DecrementCounter(Condition cc, StatsCounter* counter, int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | |
| 454 | |
| 455 | // --------------------------------------------------------------------------- |
| 456 | // Debugging |
| 457 | |
| 458 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 459 | // Use --debug_code to enable. |
| 460 | void Assert(Condition cc, const char* msg); |
| 461 | |
| 462 | // Like Assert(), but always enabled. |
| 463 | void Check(Condition cc, const char* msg); |
| 464 | |
| 465 | // Print a message to stdout and abort execution. |
| 466 | void Abort(const char* msg); |
| 467 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 468 | // Check that the stack is aligned. |
| 469 | void CheckStackAlignment(); |
| 470 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 471 | // Verify restrictions about code generated in stubs. |
| 472 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 473 | bool generating_stub() { return generating_stub_; } |
| 474 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 475 | bool allow_stub_calls() { return allow_stub_calls_; } |
| 476 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 477 | // --------------------------------------------------------------------------- |
| 478 | // String utilities. |
| 479 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 480 | // Check whether the instance type represents a flat ascii string. Jump to the |
| 481 | // label if not. If the instance type can be scratched specify same register |
| 482 | // for both instance type and scratch. |
| 483 | void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type, |
| 484 | Register scratch, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 485 | Label* on_not_flat_ascii_string); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 486 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 487 | // Checks if both objects are sequential ASCII strings, and jumps to label |
| 488 | // if either is not. |
| 489 | void JumpIfNotBothSequentialAsciiStrings(Register object1, |
| 490 | Register object2, |
| 491 | Register scratch1, |
| 492 | Register scratch2, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 493 | Label* on_not_flat_ascii_strings); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 494 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 495 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 496 | bool generating_stub_; |
| 497 | bool allow_stub_calls_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 498 | // This handle will be patched with the code object on installation. |
| 499 | Handle<Object> code_object_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 500 | |
| 501 | // Helper functions for generating invokes. |
| 502 | void InvokePrologue(const ParameterCount& expected, |
| 503 | const ParameterCount& actual, |
| 504 | Handle<Code> code_constant, |
| 505 | const Operand& code_operand, |
| 506 | Label* done, |
| 507 | InvokeFlag flag); |
| 508 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 509 | // Activation support. |
| 510 | void EnterFrame(StackFrame::Type type); |
| 511 | void LeaveFrame(StackFrame::Type type); |
| 512 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 513 | void EnterExitFramePrologue(ExitFrame::Mode mode); |
| 514 | void EnterExitFrameEpilogue(ExitFrame::Mode mode, int argc); |
| 515 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 516 | // Allocation support helpers. |
| 517 | void LoadAllocationTopHelper(Register result, |
| 518 | Register result_end, |
| 519 | Register scratch, |
| 520 | AllocationFlags flags); |
| 521 | void UpdateAllocationTopHelper(Register result_end, Register scratch); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 522 | |
| 523 | // Helper for PopHandleScope. Allowed to perform a GC and returns |
| 524 | // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and |
| 525 | // possibly returns a failure object indicating an allocation failure. |
| 526 | Object* PopHandleScopeHelper(Register saved, |
| 527 | Register scratch, |
| 528 | bool gc_allowed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | |
| 532 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 533 | // debugging and other types of instrumentation. When using the code patcher |
| 534 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 535 | // relocation information. If any of these constraints are violated it causes |
| 536 | // an assertion. |
| 537 | class CodePatcher { |
| 538 | public: |
| 539 | CodePatcher(byte* address, int size); |
| 540 | virtual ~CodePatcher(); |
| 541 | |
| 542 | // Macro assembler to emit code. |
| 543 | MacroAssembler* masm() { return &masm_; } |
| 544 | |
| 545 | private: |
| 546 | byte* address_; // The address of the code being patched. |
| 547 | int size_; // Number of bytes of the expected patch size. |
| 548 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 549 | }; |
| 550 | |
| 551 | |
| 552 | // ----------------------------------------------------------------------------- |
| 553 | // Static helper functions. |
| 554 | |
| 555 | // Generate an Operand for loading a field from an object. |
| 556 | static inline Operand FieldOperand(Register object, int offset) { |
| 557 | return Operand(object, offset - kHeapObjectTag); |
| 558 | } |
| 559 | |
| 560 | |
| 561 | // Generate an Operand for loading an indexed field from an object. |
| 562 | static inline Operand FieldOperand(Register object, |
| 563 | Register index, |
| 564 | ScaleFactor scale, |
| 565 | int offset) { |
| 566 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 567 | } |
| 568 | |
| 569 | |
| 570 | #ifdef GENERATED_CODE_COVERAGE |
| 571 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 572 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 573 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 574 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 575 | #define ACCESS_MASM(masm) { \ |
| 576 | byte* ia32_coverage_function = \ |
| 577 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 578 | masm->pushfd(); \ |
| 579 | masm->pushad(); \ |
| 580 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 581 | masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 582 | masm->pop(eax); \ |
| 583 | masm->popad(); \ |
| 584 | masm->popfd(); \ |
| 585 | } \ |
| 586 | masm-> |
| 587 | #else |
| 588 | #define ACCESS_MASM(masm) masm-> |
| 589 | #endif |
| 590 | |
| 591 | |
| 592 | } } // namespace v8::internal |
| 593 | |
| 594 | #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ |