OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_X87 | 5 #if V8_TARGET_ARCH_X87 |
6 | 6 |
7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 5328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5339 __ mov(Operand::StaticVariable(limit_address), edi); | 5339 __ mov(Operand::StaticVariable(limit_address), edi); |
5340 __ mov(edi, eax); | 5340 __ mov(edi, eax); |
5341 __ mov(Operand(esp, 0), | 5341 __ mov(Operand(esp, 0), |
5342 Immediate(ExternalReference::isolate_address(isolate))); | 5342 Immediate(ExternalReference::isolate_address(isolate))); |
5343 __ mov(eax, Immediate(delete_extensions)); | 5343 __ mov(eax, Immediate(delete_extensions)); |
5344 __ call(eax); | 5344 __ call(eax); |
5345 __ mov(eax, edi); | 5345 __ mov(eax, edi); |
5346 __ jmp(&leave_exit_frame); | 5346 __ jmp(&leave_exit_frame); |
5347 } | 5347 } |
5348 | 5348 |
5349 void CallApiCallbackStub::Generate(MacroAssembler* masm) { | 5349 static void CallApiFunctionStubHelper(MacroAssembler* masm, |
| 5350 const ParameterCount& argc, |
| 5351 bool return_first_arg, |
| 5352 bool call_data_undefined, bool is_lazy) { |
5350 // ----------- S t a t e ------------- | 5353 // ----------- S t a t e ------------- |
5351 // -- edi : callee | 5354 // -- edi : callee |
5352 // -- ebx : call_data | 5355 // -- ebx : call_data |
5353 // -- ecx : holder | 5356 // -- ecx : holder |
5354 // -- edx : api_function_address | 5357 // -- edx : api_function_address |
5355 // -- esi : context | 5358 // -- esi : context |
| 5359 // -- eax : number of arguments if argc is a register |
5356 // -- | 5360 // -- |
5357 // -- esp[0] : return address | 5361 // -- esp[0] : return address |
5358 // -- esp[4] : last argument | 5362 // -- esp[4] : last argument |
5359 // -- ... | 5363 // -- ... |
5360 // -- esp[argc * 4] : first argument | 5364 // -- esp[argc * 4] : first argument |
5361 // -- esp[(argc + 1) * 4] : receiver | 5365 // -- esp[(argc + 1) * 4] : receiver |
5362 // ----------------------------------- | 5366 // ----------------------------------- |
5363 | 5367 |
5364 Register callee = edi; | 5368 Register callee = edi; |
5365 Register call_data = ebx; | 5369 Register call_data = ebx; |
5366 Register holder = ecx; | 5370 Register holder = ecx; |
5367 Register api_function_address = edx; | 5371 Register api_function_address = edx; |
5368 Register context = esi; | 5372 Register context = esi; |
5369 Register return_address = eax; | 5373 Register return_address = eax; |
5370 | 5374 |
5371 typedef FunctionCallbackArguments FCA; | 5375 typedef FunctionCallbackArguments FCA; |
5372 | 5376 |
5373 STATIC_ASSERT(FCA::kContextSaveIndex == 6); | 5377 STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
5374 STATIC_ASSERT(FCA::kCalleeIndex == 5); | 5378 STATIC_ASSERT(FCA::kCalleeIndex == 5); |
5375 STATIC_ASSERT(FCA::kDataIndex == 4); | 5379 STATIC_ASSERT(FCA::kDataIndex == 4); |
5376 STATIC_ASSERT(FCA::kReturnValueOffset == 3); | 5380 STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
5377 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); | 5381 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
5378 STATIC_ASSERT(FCA::kIsolateIndex == 1); | 5382 STATIC_ASSERT(FCA::kIsolateIndex == 1); |
5379 STATIC_ASSERT(FCA::kHolderIndex == 0); | 5383 STATIC_ASSERT(FCA::kHolderIndex == 0); |
5380 STATIC_ASSERT(FCA::kArgsLength == 7); | 5384 STATIC_ASSERT(FCA::kArgsLength == 7); |
5381 | 5385 |
5382 DCHECK(argc.is_immediate() || eax.is(argc.reg())); | 5386 DCHECK(argc.is_immediate() || eax.is(argc.reg())); |
5383 | 5387 |
5384 __ pop(return_address); | 5388 if (argc.is_immediate()) { |
5385 // context save. | 5389 __ pop(return_address); |
5386 __ push(context); | 5390 // context save. |
| 5391 __ push(context); |
| 5392 } else { |
| 5393 // pop return address and save context |
| 5394 __ xchg(context, Operand(esp, 0)); |
| 5395 return_address = context; |
| 5396 } |
5387 | 5397 |
5388 // callee | 5398 // callee |
5389 __ push(callee); | 5399 __ push(callee); |
5390 | 5400 |
5391 // call data | 5401 // call data |
5392 __ push(call_data); | 5402 __ push(call_data); |
5393 | 5403 |
5394 Register scratch = call_data; | 5404 Register scratch = call_data; |
5395 if (!call_data_undefined()) { | 5405 if (!call_data_undefined) { |
5396 // return value | 5406 // return value |
5397 __ push(Immediate(masm->isolate()->factory()->undefined_value())); | 5407 __ push(Immediate(masm->isolate()->factory()->undefined_value())); |
5398 // return value default | 5408 // return value default |
5399 __ push(Immediate(masm->isolate()->factory()->undefined_value())); | 5409 __ push(Immediate(masm->isolate()->factory()->undefined_value())); |
5400 } else { | 5410 } else { |
5401 // return value | 5411 // return value |
5402 __ push(scratch); | 5412 __ push(scratch); |
5403 // return value default | 5413 // return value default |
5404 __ push(scratch); | 5414 __ push(scratch); |
5405 } | 5415 } |
5406 // isolate | 5416 // isolate |
5407 __ push(Immediate(reinterpret_cast<int>(masm->isolate()))); | 5417 __ push(Immediate(reinterpret_cast<int>(masm->isolate()))); |
5408 // holder | 5418 // holder |
5409 __ push(holder); | 5419 __ push(holder); |
5410 | 5420 |
5411 __ mov(scratch, esp); | 5421 __ mov(scratch, esp); |
5412 | 5422 |
5413 // push return address | 5423 // push return address |
5414 __ push(return_address); | 5424 __ push(return_address); |
5415 | 5425 |
5416 if (!is_lazy()) { | 5426 if (!is_lazy) { |
5417 // load context from callee | 5427 // load context from callee |
5418 __ mov(context, FieldOperand(callee, JSFunction::kContextOffset)); | 5428 __ mov(context, FieldOperand(callee, JSFunction::kContextOffset)); |
5419 } | 5429 } |
5420 | 5430 |
5421 // API function gets reference to the v8::Arguments. If CPU profiler | 5431 // API function gets reference to the v8::Arguments. If CPU profiler |
5422 // is enabled wrapper function will be called and we need to pass | 5432 // is enabled wrapper function will be called and we need to pass |
5423 // address of the callback as additional parameter, always allocate | 5433 // address of the callback as additional parameter, always allocate |
5424 // space for it. | 5434 // space for it. |
5425 const int kApiArgc = 1 + 1; | 5435 const int kApiArgc = 1 + 1; |
5426 | 5436 |
5427 // Allocate the v8::Arguments structure in the arguments' space since | 5437 // Allocate the v8::Arguments structure in the arguments' space since |
5428 // it's not controlled by GC. | 5438 // it's not controlled by GC. |
5429 const int kApiStackSpace = 4; | 5439 const int kApiStackSpace = 4; |
5430 | 5440 |
5431 PrepareCallApiFunction(masm, kApiArgc + kApiStackSpace); | 5441 PrepareCallApiFunction(masm, kApiArgc + kApiStackSpace); |
5432 | 5442 |
5433 // FunctionCallbackInfo::implicit_args_. | 5443 // FunctionCallbackInfo::implicit_args_. |
5434 __ mov(ApiParameterOperand(2), scratch); | 5444 __ mov(ApiParameterOperand(2), scratch); |
5435 __ add(scratch, Immediate((argc() + FCA::kArgsLength - 1) * kPointerSize)); | 5445 if (argc.is_immediate()) { |
5436 // FunctionCallbackInfo::values_. | 5446 __ add(scratch, |
5437 __ mov(ApiParameterOperand(3), scratch); | 5447 Immediate((argc.immediate() + FCA::kArgsLength - 1) * kPointerSize)); |
5438 // FunctionCallbackInfo::length_. | 5448 // FunctionCallbackInfo::values_. |
5439 __ Move(ApiParameterOperand(4), Immediate(argc)); | 5449 __ mov(ApiParameterOperand(3), scratch); |
5440 // FunctionCallbackInfo::is_construct_call_. | 5450 // FunctionCallbackInfo::length_. |
5441 __ Move(ApiParameterOperand(5), Immediate(0)); | 5451 __ Move(ApiParameterOperand(4), Immediate(argc.immediate())); |
| 5452 // FunctionCallbackInfo::is_construct_call_. |
| 5453 __ Move(ApiParameterOperand(5), Immediate(0)); |
| 5454 } else { |
| 5455 __ lea(scratch, Operand(scratch, argc.reg(), times_pointer_size, |
| 5456 (FCA::kArgsLength - 1) * kPointerSize)); |
| 5457 // FunctionCallbackInfo::values_. |
| 5458 __ mov(ApiParameterOperand(3), scratch); |
| 5459 // FunctionCallbackInfo::length_. |
| 5460 __ mov(ApiParameterOperand(4), argc.reg()); |
| 5461 // FunctionCallbackInfo::is_construct_call_. |
| 5462 __ lea(argc.reg(), Operand(argc.reg(), times_pointer_size, |
| 5463 (FCA::kArgsLength + 1) * kPointerSize)); |
| 5464 __ mov(ApiParameterOperand(5), argc.reg()); |
| 5465 } |
5442 | 5466 |
5443 // v8::InvocationCallback's argument. | 5467 // v8::InvocationCallback's argument. |
5444 __ lea(scratch, ApiParameterOperand(2)); | 5468 __ lea(scratch, ApiParameterOperand(2)); |
5445 __ mov(ApiParameterOperand(0), scratch); | 5469 __ mov(ApiParameterOperand(0), scratch); |
5446 | 5470 |
5447 ExternalReference thunk_ref = | 5471 ExternalReference thunk_ref = |
5448 ExternalReference::invoke_function_callback(masm->isolate()); | 5472 ExternalReference::invoke_function_callback(masm->isolate()); |
5449 | 5473 |
5450 Operand context_restore_operand(ebp, | 5474 Operand context_restore_operand(ebp, |
5451 (2 + FCA::kContextSaveIndex) * kPointerSize); | 5475 (2 + FCA::kContextSaveIndex) * kPointerSize); |
5452 // Stores return the first js argument | 5476 // Stores return the first js argument |
5453 int return_value_offset = 0; | 5477 int return_value_offset = 0; |
5454 if (is_store()) { | 5478 if (return_first_arg) { |
5455 return_value_offset = 2 + FCA::kArgsLength; | 5479 return_value_offset = 2 + FCA::kArgsLength; |
5456 } else { | 5480 } else { |
5457 return_value_offset = 2 + FCA::kReturnValueOffset; | 5481 return_value_offset = 2 + FCA::kReturnValueOffset; |
5458 } | 5482 } |
5459 Operand return_value_operand(ebp, return_value_offset * kPointerSize); | 5483 Operand return_value_operand(ebp, return_value_offset * kPointerSize); |
5460 int stack_space = 0; | 5484 int stack_space = 0; |
5461 Operand is_construct_call_operand = ApiParameterOperand(5); | 5485 Operand is_construct_call_operand = ApiParameterOperand(5); |
5462 Operand* stack_space_operand = &is_construct_call_operand; | 5486 Operand* stack_space_operand = &is_construct_call_operand; |
5463 stack_space = argc() + FCA::kArgsLength + 1; | 5487 if (argc.is_immediate()) { |
5464 stack_space_operand = nullptr; | 5488 stack_space = argc.immediate() + FCA::kArgsLength + 1; |
| 5489 stack_space_operand = nullptr; |
| 5490 } |
5465 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, | 5491 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
5466 ApiParameterOperand(1), stack_space, | 5492 ApiParameterOperand(1), stack_space, |
5467 stack_space_operand, return_value_operand, | 5493 stack_space_operand, return_value_operand, |
5468 &context_restore_operand); | 5494 &context_restore_operand); |
5469 } | 5495 } |
5470 | 5496 |
5471 | 5497 |
| 5498 void CallApiFunctionStub::Generate(MacroAssembler* masm) { |
| 5499 bool call_data_undefined = this->call_data_undefined(); |
| 5500 CallApiFunctionStubHelper(masm, ParameterCount(eax), false, |
| 5501 call_data_undefined, false); |
| 5502 } |
| 5503 |
| 5504 |
| 5505 void CallApiAccessorStub::Generate(MacroAssembler* masm) { |
| 5506 bool is_store = this->is_store(); |
| 5507 int argc = this->argc(); |
| 5508 bool call_data_undefined = this->call_data_undefined(); |
| 5509 bool is_lazy = this->is_lazy(); |
| 5510 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, |
| 5511 call_data_undefined, is_lazy); |
| 5512 } |
| 5513 |
| 5514 |
5472 void CallApiGetterStub::Generate(MacroAssembler* masm) { | 5515 void CallApiGetterStub::Generate(MacroAssembler* masm) { |
5473 // ----------- S t a t e ------------- | 5516 // ----------- S t a t e ------------- |
5474 // -- esp[0] : return address | 5517 // -- esp[0] : return address |
5475 // -- esp[4] : name | 5518 // -- esp[4] : name |
5476 // -- esp[8 .. (8 + kArgsLength*4)] : v8::PropertyCallbackInfo::args_ | 5519 // -- esp[8 .. (8 + kArgsLength*4)] : v8::PropertyCallbackInfo::args_ |
5477 // -- ... | 5520 // -- ... |
5478 // -- edx : api_function_address | 5521 // -- edx : api_function_address |
5479 // ----------------------------------- | 5522 // ----------------------------------- |
5480 DCHECK(edx.is(ApiGetterDescriptor::function_address())); | 5523 DCHECK(edx.is(ApiGetterDescriptor::function_address())); |
5481 | 5524 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5517 return_value_operand, NULL); | 5560 return_value_operand, NULL); |
5518 } | 5561 } |
5519 | 5562 |
5520 | 5563 |
5521 #undef __ | 5564 #undef __ |
5522 | 5565 |
5523 } // namespace internal | 5566 } // namespace internal |
5524 } // namespace v8 | 5567 } // namespace v8 |
5525 | 5568 |
5526 #endif // V8_TARGET_ARCH_X87 | 5569 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |