| 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 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X87 | 7 #if V8_TARGET_ARCH_X87 |
| 8 | 8 |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 4323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4334 Label fast_elements_case; | 4334 Label fast_elements_case; |
| 4335 __ cmp(ecx, Immediate(FAST_ELEMENTS)); | 4335 __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 4336 __ j(equal, &fast_elements_case); | 4336 __ j(equal, &fast_elements_case); |
| 4337 GenerateCase(masm, FAST_HOLEY_ELEMENTS); | 4337 GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 4338 | 4338 |
| 4339 __ bind(&fast_elements_case); | 4339 __ bind(&fast_elements_case); |
| 4340 GenerateCase(masm, FAST_ELEMENTS); | 4340 GenerateCase(masm, FAST_ELEMENTS); |
| 4341 } | 4341 } |
| 4342 | 4342 |
| 4343 | 4343 |
| 4344 void CallApiFunctionStub::Generate(MacroAssembler* masm) { | 4344 static void CallApiFunctionStubHelper(MacroAssembler* masm, |
| 4345 const ParameterCount& argc, |
| 4346 bool return_first_arg, |
| 4347 bool call_data_undefined) { |
| 4345 // ----------- S t a t e ------------- | 4348 // ----------- S t a t e ------------- |
| 4346 // -- eax : callee | 4349 // -- eax : callee |
| 4347 // -- ebx : call_data | 4350 // -- ebx : call_data |
| 4348 // -- ecx : holder | 4351 // -- ecx : holder |
| 4349 // -- edx : api_function_address | 4352 // -- edx : api_function_address |
| 4350 // -- esi : context | 4353 // -- esi : context |
| 4354 // -- edi : number of arguments if argc is a register |
| 4351 // -- | 4355 // -- |
| 4352 // -- esp[0] : return address | 4356 // -- esp[0] : return address |
| 4353 // -- esp[4] : last argument | 4357 // -- esp[4] : last argument |
| 4354 // -- ... | 4358 // -- ... |
| 4355 // -- esp[argc * 4] : first argument | 4359 // -- esp[argc * 4] : first argument |
| 4356 // -- esp[(argc + 1) * 4] : receiver | 4360 // -- esp[(argc + 1) * 4] : receiver |
| 4357 // ----------------------------------- | 4361 // ----------------------------------- |
| 4358 | 4362 |
| 4359 Register callee = eax; | 4363 Register callee = eax; |
| 4360 Register call_data = ebx; | 4364 Register call_data = ebx; |
| 4361 Register holder = ecx; | 4365 Register holder = ecx; |
| 4362 Register api_function_address = edx; | 4366 Register api_function_address = edx; |
| 4363 Register return_address = edi; | |
| 4364 Register context = esi; | 4367 Register context = esi; |
| 4365 | 4368 |
| 4366 int argc = this->argc(); | |
| 4367 bool is_store = this->is_store(); | |
| 4368 bool call_data_undefined = this->call_data_undefined(); | |
| 4369 | |
| 4370 typedef FunctionCallbackArguments FCA; | 4369 typedef FunctionCallbackArguments FCA; |
| 4371 | 4370 |
| 4372 STATIC_ASSERT(FCA::kContextSaveIndex == 6); | 4371 STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 4373 STATIC_ASSERT(FCA::kCalleeIndex == 5); | 4372 STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 4374 STATIC_ASSERT(FCA::kDataIndex == 4); | 4373 STATIC_ASSERT(FCA::kDataIndex == 4); |
| 4375 STATIC_ASSERT(FCA::kReturnValueOffset == 3); | 4374 STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 4376 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); | 4375 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 4377 STATIC_ASSERT(FCA::kIsolateIndex == 1); | 4376 STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 4378 STATIC_ASSERT(FCA::kHolderIndex == 0); | 4377 STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 4379 STATIC_ASSERT(FCA::kArgsLength == 7); | 4378 STATIC_ASSERT(FCA::kArgsLength == 7); |
| 4380 | 4379 |
| 4381 __ pop(return_address); | 4380 DCHECK(argc.is_immediate() || edi.is(argc.reg())); |
| 4382 | 4381 |
| 4383 // context save | 4382 // pop return address and save context |
| 4384 __ push(context); | 4383 __ xchg(context, Operand(esp, 0)); |
| 4385 // load context from callee | |
| 4386 __ mov(context, FieldOperand(callee, JSFunction::kContextOffset)); | |
| 4387 | 4384 |
| 4388 // callee | 4385 // callee |
| 4389 __ push(callee); | 4386 __ push(callee); |
| 4390 | 4387 |
| 4391 // call data | 4388 // call data |
| 4392 __ push(call_data); | 4389 __ push(call_data); |
| 4393 | 4390 |
| 4394 Register scratch = call_data; | 4391 Register scratch = call_data; |
| 4395 if (!call_data_undefined) { | 4392 if (!call_data_undefined) { |
| 4396 // return value | 4393 // return value |
| 4397 __ push(Immediate(isolate()->factory()->undefined_value())); | 4394 __ push(Immediate(masm->isolate()->factory()->undefined_value())); |
| 4398 // return value default | 4395 // return value default |
| 4399 __ push(Immediate(isolate()->factory()->undefined_value())); | 4396 __ push(Immediate(masm->isolate()->factory()->undefined_value())); |
| 4400 } else { | 4397 } else { |
| 4401 // return value | 4398 // return value |
| 4402 __ push(scratch); | 4399 __ push(scratch); |
| 4403 // return value default | 4400 // return value default |
| 4404 __ push(scratch); | 4401 __ push(scratch); |
| 4405 } | 4402 } |
| 4406 // isolate | 4403 // isolate |
| 4407 __ push(Immediate(reinterpret_cast<int>(isolate()))); | 4404 __ push(Immediate(reinterpret_cast<int>(masm->isolate()))); |
| 4408 // holder | 4405 // holder |
| 4409 __ push(holder); | 4406 __ push(holder); |
| 4410 | 4407 |
| 4411 __ mov(scratch, esp); | 4408 __ mov(scratch, esp); |
| 4412 | 4409 |
| 4413 // return address | 4410 // push return address |
| 4414 __ push(return_address); | 4411 __ push(context); |
| 4412 |
| 4413 // load context from callee |
| 4414 __ mov(context, FieldOperand(callee, JSFunction::kContextOffset)); |
| 4415 | 4415 |
| 4416 // API function gets reference to the v8::Arguments. If CPU profiler | 4416 // API function gets reference to the v8::Arguments. If CPU profiler |
| 4417 // is enabled wrapper function will be called and we need to pass | 4417 // is enabled wrapper function will be called and we need to pass |
| 4418 // address of the callback as additional parameter, always allocate | 4418 // address of the callback as additional parameter, always allocate |
| 4419 // space for it. | 4419 // space for it. |
| 4420 const int kApiArgc = 1 + 1; | 4420 const int kApiArgc = 1 + 1; |
| 4421 | 4421 |
| 4422 // Allocate the v8::Arguments structure in the arguments' space since | 4422 // Allocate the v8::Arguments structure in the arguments' space since |
| 4423 // it's not controlled by GC. | 4423 // it's not controlled by GC. |
| 4424 const int kApiStackSpace = 4; | 4424 const int kApiStackSpace = 4; |
| 4425 | 4425 |
| 4426 __ PrepareCallApiFunction(kApiArgc + kApiStackSpace); | 4426 __ PrepareCallApiFunction(kApiArgc + kApiStackSpace); |
| 4427 | 4427 |
| 4428 // FunctionCallbackInfo::implicit_args_. | 4428 // FunctionCallbackInfo::implicit_args_. |
| 4429 __ mov(ApiParameterOperand(2), scratch); | 4429 __ mov(ApiParameterOperand(2), scratch); |
| 4430 __ add(scratch, Immediate((argc + FCA::kArgsLength - 1) * kPointerSize)); | 4430 if (argc.is_immediate()) { |
| 4431 // FunctionCallbackInfo::values_. | 4431 __ add(scratch, |
| 4432 __ mov(ApiParameterOperand(3), scratch); | 4432 Immediate((argc.immediate() + FCA::kArgsLength - 1) * kPointerSize)); |
| 4433 // FunctionCallbackInfo::length_. | 4433 // FunctionCallbackInfo::values_. |
| 4434 __ Move(ApiParameterOperand(4), Immediate(argc)); | 4434 __ mov(ApiParameterOperand(3), scratch); |
| 4435 // FunctionCallbackInfo::is_construct_call_. | 4435 // FunctionCallbackInfo::length_. |
| 4436 __ Move(ApiParameterOperand(5), Immediate(0)); | 4436 __ Move(ApiParameterOperand(4), Immediate(argc.immediate())); |
| 4437 // FunctionCallbackInfo::is_construct_call_. |
| 4438 __ Move(ApiParameterOperand(5), Immediate(0)); |
| 4439 } else { |
| 4440 __ lea(scratch, Operand(scratch, argc.reg(), times_pointer_size, |
| 4441 (FCA::kArgsLength - 1) * kPointerSize)); |
| 4442 // FunctionCallbackInfo::values_. |
| 4443 __ mov(ApiParameterOperand(3), scratch); |
| 4444 // FunctionCallbackInfo::length_. |
| 4445 __ mov(ApiParameterOperand(4), argc.reg()); |
| 4446 // FunctionCallbackInfo::is_construct_call_. |
| 4447 __ lea(argc.reg(), Operand(argc.reg(), times_pointer_size, |
| 4448 (FCA::kArgsLength + 1) * kPointerSize)); |
| 4449 __ mov(ApiParameterOperand(5), argc.reg()); |
| 4450 } |
| 4437 | 4451 |
| 4438 // v8::InvocationCallback's argument. | 4452 // v8::InvocationCallback's argument. |
| 4439 __ lea(scratch, ApiParameterOperand(2)); | 4453 __ lea(scratch, ApiParameterOperand(2)); |
| 4440 __ mov(ApiParameterOperand(0), scratch); | 4454 __ mov(ApiParameterOperand(0), scratch); |
| 4441 | 4455 |
| 4442 ExternalReference thunk_ref = | 4456 ExternalReference thunk_ref = |
| 4443 ExternalReference::invoke_function_callback(isolate()); | 4457 ExternalReference::invoke_function_callback(masm->isolate()); |
| 4444 | 4458 |
| 4445 Operand context_restore_operand(ebp, | 4459 Operand context_restore_operand(ebp, |
| 4446 (2 + FCA::kContextSaveIndex) * kPointerSize); | 4460 (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 4447 // Stores return the first js argument | 4461 // Stores return the first js argument |
| 4448 int return_value_offset = 0; | 4462 int return_value_offset = 0; |
| 4449 if (is_store) { | 4463 if (return_first_arg) { |
| 4450 return_value_offset = 2 + FCA::kArgsLength; | 4464 return_value_offset = 2 + FCA::kArgsLength; |
| 4451 } else { | 4465 } else { |
| 4452 return_value_offset = 2 + FCA::kReturnValueOffset; | 4466 return_value_offset = 2 + FCA::kReturnValueOffset; |
| 4453 } | 4467 } |
| 4454 Operand return_value_operand(ebp, return_value_offset * kPointerSize); | 4468 Operand return_value_operand(ebp, return_value_offset * kPointerSize); |
| 4455 __ CallApiFunctionAndReturn(api_function_address, | 4469 int stack_space = 0; |
| 4456 thunk_ref, | 4470 Operand is_construct_call_operand = ApiParameterOperand(5); |
| 4457 ApiParameterOperand(1), | 4471 Operand* stack_space_operand = &is_construct_call_operand; |
| 4458 argc + FCA::kArgsLength + 1, | 4472 if (argc.is_immediate()) { |
| 4459 return_value_operand, | 4473 stack_space = argc.immediate() + FCA::kArgsLength + 1; |
| 4460 &context_restore_operand); | 4474 stack_space_operand = nullptr; |
| 4475 } |
| 4476 __ CallApiFunctionAndReturn( |
| 4477 api_function_address, thunk_ref, ApiParameterOperand(1), stack_space, |
| 4478 stack_space_operand, return_value_operand, &context_restore_operand); |
| 4461 } | 4479 } |
| 4462 | 4480 |
| 4463 | 4481 |
| 4482 void CallApiFunctionStub::Generate(MacroAssembler* masm) { |
| 4483 // TODO(dcarney): make eax contain the function address. |
| 4484 bool call_data_undefined = this->call_data_undefined(); |
| 4485 CallApiFunctionStubHelper(masm, ParameterCount(edi), false, |
| 4486 call_data_undefined); |
| 4487 } |
| 4488 |
| 4489 |
| 4490 void CallApiAccessorStub::Generate(MacroAssembler* masm) { |
| 4491 bool is_store = this->is_store(); |
| 4492 int argc = is_store ? 1 : 0; |
| 4493 bool call_data_undefined = this->call_data_undefined(); |
| 4494 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, |
| 4495 call_data_undefined); |
| 4496 } |
| 4497 |
| 4498 |
| 4464 void CallApiGetterStub::Generate(MacroAssembler* masm) { | 4499 void CallApiGetterStub::Generate(MacroAssembler* masm) { |
| 4465 // ----------- S t a t e ------------- | 4500 // ----------- S t a t e ------------- |
| 4466 // -- esp[0] : return address | 4501 // -- esp[0] : return address |
| 4467 // -- esp[4] : name | 4502 // -- esp[4] : name |
| 4468 // -- esp[8 - kArgsLength*4] : PropertyCallbackArguments object | 4503 // -- esp[8 - kArgsLength*4] : PropertyCallbackArguments object |
| 4469 // -- ... | 4504 // -- ... |
| 4470 // -- edx : api_function_address | 4505 // -- edx : api_function_address |
| 4471 // ----------------------------------- | 4506 // ----------------------------------- |
| 4472 DCHECK(edx.is(ApiGetterDescriptor::function_address())); | 4507 DCHECK(edx.is(ApiGetterDescriptor::function_address())); |
| 4473 | 4508 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4485 __ lea(scratch, Operand(esp, 1 * kPointerSize)); | 4520 __ lea(scratch, Operand(esp, 1 * kPointerSize)); |
| 4486 | 4521 |
| 4487 __ PrepareCallApiFunction(kApiArgc); | 4522 __ PrepareCallApiFunction(kApiArgc); |
| 4488 __ mov(ApiParameterOperand(0), scratch); // name. | 4523 __ mov(ApiParameterOperand(0), scratch); // name. |
| 4489 __ add(scratch, Immediate(kPointerSize)); | 4524 __ add(scratch, Immediate(kPointerSize)); |
| 4490 __ mov(ApiParameterOperand(1), scratch); // arguments pointer. | 4525 __ mov(ApiParameterOperand(1), scratch); // arguments pointer. |
| 4491 | 4526 |
| 4492 ExternalReference thunk_ref = | 4527 ExternalReference thunk_ref = |
| 4493 ExternalReference::invoke_accessor_getter_callback(isolate()); | 4528 ExternalReference::invoke_accessor_getter_callback(isolate()); |
| 4494 | 4529 |
| 4495 __ CallApiFunctionAndReturn(api_function_address, | 4530 __ CallApiFunctionAndReturn(api_function_address, thunk_ref, |
| 4496 thunk_ref, | 4531 ApiParameterOperand(2), kStackSpace, nullptr, |
| 4497 ApiParameterOperand(2), | 4532 Operand(ebp, 7 * kPointerSize), NULL); |
| 4498 kStackSpace, | |
| 4499 Operand(ebp, 7 * kPointerSize), | |
| 4500 NULL); | |
| 4501 } | 4533 } |
| 4502 | 4534 |
| 4503 | 4535 |
| 4504 #undef __ | 4536 #undef __ |
| 4505 | 4537 |
| 4506 } } // namespace v8::internal | 4538 } } // namespace v8::internal |
| 4507 | 4539 |
| 4508 #endif // V8_TARGET_ARCH_X87 | 4540 #endif // V8_TARGET_ARCH_X87 |
| OLD | NEW |