blob: 7b9b843939e992bfc0a69163344a4e28dee60ea3 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// 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 Merrick75681382010-08-19 15:07:18 +010032#include "type-info.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000033
34namespace v8 {
35namespace internal {
36
Kristian Monsen25f61362010-05-21 11:50:48 +010037// Flags used for the AllocateInNewSpace functions.
38enum 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 Clarkee46be812010-01-19 14:06:41 +000048// Convenience for platform-independent signatures. We do not normally
49// distinguish memory operands from other operands on ia32.
50typedef Operand MemOperand;
51
Steve Blocka7e24c12009-10-30 11:49:00 +000052// Forward declaration.
53class JumpTarget;
54
Steve Blocka7e24c12009-10-30 11:49:00 +000055// MacroAssembler implements a collection of frequently used macros.
56class MacroAssembler: public Assembler {
57 public:
58 MacroAssembler(void* buffer, int size);
59
60 // ---------------------------------------------------------------------------
61 // GC Support
62
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010063 // For page containing |object| mark region covering |addr| dirty.
64 // RecordWriteHelper only works if the object is not in new
Steve Block6ded16b2010-05-10 14:33:55 +010065 // 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 Block8defd9f2010-07-08 12:39:36 +010077 // 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 Blocka7e24c12009-10-30 11:49:00 +000084 void RecordWrite(Register object,
85 int offset,
86 Register value,
87 Register scratch);
88
Steve Block8defd9f2010-07-08 12:39:36 +010089 // 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 Blocka7e24c12009-10-30 11:49:00 +000098#ifdef ENABLE_DEBUGGER_SUPPORT
99 // ---------------------------------------------------------------------------
100 // Debugger Support
101
Andrei Popescu402d9372010-02-26 13:31:12 +0000102 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000103#endif
104
105 // ---------------------------------------------------------------------------
Steve Blockd0582a62009-12-15 09:54:21 +0000106 // 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 Blocka7e24c12009-10-30 11:49:00 +0000112 // 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 Blockd0582a62009-12-15 09:54:21 +0000120 // Enter specific kind of exit frame; either in normal or debug mode.
121 // Expects the number of arguments in register eax and
Steve Blocka7e24c12009-10-30 11:49:00 +0000122 // sets up the number of arguments in register edi and the pointer
123 // to the first argument in register esi.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100124 void EnterExitFrame();
Steve Blockd0582a62009-12-15 09:54:21 +0000125
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100126 void EnterApiExitFrame(int stack_space, int argc);
Steve Blocka7e24c12009-10-30 11:49:00 +0000127
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 Monsen80d68ea2010-09-08 11:05:35 +0100131 void LeaveExitFrame();
Steve Blocka7e24c12009-10-30 11:49:00 +0000132
Steve Blockd0582a62009-12-15 09:54:21 +0000133 // Find the function context up the context chain.
134 void LoadContext(Register dst, int context_chain_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000135
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100136 // 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 Blocka7e24c12009-10-30 11:49:00 +0000143 // ---------------------------------------------------------------------------
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 Popescu402d9372010-02-26 13:31:12 +0000164 void InvokeFunction(JSFunction* function,
165 const ParameterCount& actual,
166 InvokeFlag flag);
167
Steve Blocka7e24c12009-10-30 11:49:00 +0000168 // 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 Block791712a2010-08-27 10:21:07 +0100172 // Store the function for the given builtin in the target register.
173 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
174
Steve Blocka7e24c12009-10-30 11:49:00 +0000175 // 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 Popescu31002712010-02-23 13:46:05 +0000189 // 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 Clarkee46be812010-01-19 14:06:41 +0000197 // 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 Murdoch7f4d5bd2010-06-15 11:15:29 +0100206 // 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 Blocka7e24c12009-10-30 11:49:00 +0000218 // 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 Clarkee46be812010-01-19 14:06:41 +0000222 // Smi tagging support.
223 void SmiTag(Register reg) {
224 ASSERT(kSmiTag == 0);
Steve Block6ded16b2010-05-10 14:33:55 +0100225 ASSERT(kSmiTagSize == 1);
226 add(reg, Operand(reg));
Leon Clarkee46be812010-01-19 14:06:41 +0000227 }
228 void SmiUntag(Register reg) {
229 sar(reg, kSmiTagSize);
230 }
231
Iain Merrick75681382010-08-19 15:07:18 +0100232 // 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 Monsen0d5e1162010-09-30 15:31:59 +0100261 void LoadPowerOf2(XMMRegister dst, Register scratch, int power);
262
Andrei Popescu402d9372010-02-26 13:31:12 +0000263 // Abort execution if argument is not a number. Used in debug code.
Steve Block6ded16b2010-05-10 14:33:55 +0100264 void AbortIfNotNumber(Register object);
265
266 // Abort execution if argument is not a smi. Used in debug code.
267 void AbortIfNotSmi(Register object);
Andrei Popescu402d9372010-02-26 13:31:12 +0000268
Iain Merrick75681382010-08-19 15:07:18 +0100269 // Abort execution if argument is a smi. Used in debug code.
270 void AbortIfSmi(Register object);
271
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100272 // Abort execution if argument is a string. Used in debug code.
273 void AbortIfNotString(Register object);
274
Steve Blocka7e24c12009-10-30 11:49:00 +0000275 // ---------------------------------------------------------------------------
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 Clarkee46be812010-01-19 14:06:41 +0000282 // Unlink the stack handler on top of the stack from the try handler chain.
283 void PopTryHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000284
285 // ---------------------------------------------------------------------------
286 // Inline caching support
287
Steve Blocka7e24c12009-10-30 11:49:00 +0000288 // 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 Blockd0582a62009-12-15 09:54:21 +0000305 // result_contains_top_on_entry is true the content of result is known to be
Steve Blocka7e24c12009-10-30 11:49:00 +0000306 // 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 Block3ce2e202009-11-05 08:53:23 +0000338 // 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 Blockd0582a62009-12-15 09:54:21 +0000347 // 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 Merrick9ac36c92010-09-13 15:29:50 +0100361 void AllocateAsciiString(Register result,
362 int length,
363 Register scratch1,
364 Register scratch2,
365 Label* gc_required);
Steve Blockd0582a62009-12-15 09:54:21 +0000366
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 Blocka7e24c12009-10-30 11:49:00 +0000378 // ---------------------------------------------------------------------------
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 Monsen80d68ea2010-09-08 11:05:35 +0100409 // 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 Blocka7e24c12009-10-30 11:49:00 +0000415 // ---------------------------------------------------------------------------
416 // Runtime calls
417
Leon Clarkee46be812010-01-19 14:06:41 +0000418 // Call a code stub. Generate the code if necessary.
Steve Blocka7e24c12009-10-30 11:49:00 +0000419 void CallStub(CodeStub* stub);
420
Leon Clarkee46be812010-01-19 14:06:41 +0000421 // 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 Reck59135872010-11-02 12:39:01 -0700424 MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub);
Leon Clarkee46be812010-01-19 14:06:41 +0000425
426 // Tail call a code stub (jump). Generate the code if necessary.
Steve Blockd0582a62009-12-15 09:54:21 +0000427 void TailCallStub(CodeStub* stub);
428
Leon Clarkee46be812010-01-19 14:06:41 +0000429 // 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 Reck59135872010-11-02 12:39:01 -0700432 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub);
Leon Clarkee46be812010-01-19 14:06:41 +0000433
Steve Blocka7e24c12009-10-30 11:49:00 +0000434 // Return from a code stub after popping its arguments.
435 void StubReturn(int argc);
436
437 // Call a runtime routine.
Steve Blocka7e24c12009-10-30 11:49:00 +0000438 void CallRuntime(Runtime::Function* f, int num_arguments);
439
Leon Clarke4515c472010-02-03 11:58:03 +0000440 // Call a runtime function, returning the CodeStub object called.
Leon Clarkee46be812010-01-19 14:06:41 +0000441 // Try to generate the stub code if necessary. Do not perform a GC
442 // but instead return a retry after GC failure.
John Reck59135872010-11-02 12:39:01 -0700443 MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::Function* f,
444 int num_arguments);
Leon Clarkee46be812010-01-19 14:06:41 +0000445
Steve Blocka7e24c12009-10-30 11:49:00 +0000446 // Convenience function: Same as above, but takes the fid instead.
447 void CallRuntime(Runtime::FunctionId id, int num_arguments);
448
Leon Clarkee46be812010-01-19 14:06:41 +0000449 // Convenience function: Same as above, but takes the fid instead.
John Reck59135872010-11-02 12:39:01 -0700450 MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id,
451 int num_arguments);
Leon Clarkee46be812010-01-19 14:06:41 +0000452
Ben Murdochbb769b22010-08-11 14:56:33 +0100453 // Convenience function: call an external reference.
454 void CallExternalReference(ExternalReference ref, int num_arguments);
455
Steve Blocka7e24c12009-10-30 11:49:00 +0000456 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +0100457 // 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 Blocka7e24c12009-10-30 11:49:00 +0000465 int num_arguments,
466 int result_size);
467
Steve Block6ded16b2010-05-10 14:33:55 +0100468 // 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 Reck59135872010-11-02 12:39:01 -0700485 // 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 Blockd0582a62009-12-15 09:54:21 +0000490
John Reck59135872010-11-02 12:39:01 -0700491 // 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 Clarkee46be812010-01-19 14:06:41 +0000495
Steve Blocka7e24c12009-10-30 11:49:00 +0000496 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +0100497 void JumpToExternalReference(const ExternalReference& ext);
Steve Blocka7e24c12009-10-30 11:49:00 +0000498
499
500 // ---------------------------------------------------------------------------
501 // Utilities
502
503 void Ret();
504
Leon Clarkee46be812010-01-19 14:06:41 +0000505 // 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 Monsen0d5e1162010-09-30 15:31:59 +0100511 // Move if the registers are not identical.
512 void Move(Register target, Register source);
513
Leon Clarkee46be812010-01-19 14:06:41 +0000514 void Move(Register target, Handle<Object> value);
515
Steve Blocka7e24c12009-10-30 11:49:00 +0000516 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 Clarked91b9f72010-01-27 17:25:45 +0000525 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
526 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000527
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 Merrick75681382010-08-19 15:07:18 +0100536 void AssertFastElements(Register elements);
537
Steve Blocka7e24c12009-10-30 11:49:00 +0000538 // 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 Block6ded16b2010-05-10 14:33:55 +0100544 // Check that the stack is aligned.
545 void CheckStackAlignment();
546
Steve Blocka7e24c12009-10-30 11:49:00 +0000547 // 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 Clarked91b9f72010-01-27 17:25:45 +0000553 // ---------------------------------------------------------------------------
554 // String utilities.
555
Andrei Popescu402d9372010-02-26 13:31:12 +0000556 // 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 Block6ded16b2010-05-10 14:33:55 +0100561 Label* on_not_flat_ascii_string);
Andrei Popescu402d9372010-02-26 13:31:12 +0000562
Leon Clarked91b9f72010-01-27 17:25:45 +0000563 // 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 Block6ded16b2010-05-10 14:33:55 +0100569 Label* on_not_flat_ascii_strings);
Leon Clarked91b9f72010-01-27 17:25:45 +0000570
Steve Blocka7e24c12009-10-30 11:49:00 +0000571 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000572 bool generating_stub_;
573 bool allow_stub_calls_;
Andrei Popescu31002712010-02-23 13:46:05 +0000574 // This handle will be patched with the code object on installation.
575 Handle<Object> code_object_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000576
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 Blocka7e24c12009-10-30 11:49:00 +0000585 // Activation support.
586 void EnterFrame(StackFrame::Type type);
587 void LeaveFrame(StackFrame::Type type);
588
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100589 void EnterExitFramePrologue();
590 void EnterExitFrameEpilogue(int argc);
Steve Blockd0582a62009-12-15 09:54:21 +0000591
Steve Blocka7e24c12009-10-30 11:49:00 +0000592 // 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 Clarkee46be812010-01-19 14:06:41 +0000598
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 Reck59135872010-11-02 12:39:01 -0700602 MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved,
603 Register scratch,
604 bool gc_allowed);
Steve Blocka7e24c12009-10-30 11:49:00 +0000605};
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.
613class 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.
632static 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.
638static 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 Reck59135872010-11-02 12:39:01 -0700645// Generates an Operand for saving parameters after PrepareCallApiFunction.
646Operand ApiParameterOperand(int index);
647
Steve Blocka7e24c12009-10-30 11:49:00 +0000648
649#ifdef GENERATED_CODE_COVERAGE
650extern 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_