OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 static const bool kReturnHandlesDirectly = false; | 1405 static const bool kReturnHandlesDirectly = false; |
1406 #endif | 1406 #endif |
1407 | 1407 |
1408 | 1408 |
1409 Operand ApiParameterOperand(int index) { | 1409 Operand ApiParameterOperand(int index) { |
1410 return Operand( | 1410 return Operand( |
1411 esp, (index + (kReturnHandlesDirectly ? 0 : 1)) * kPointerSize); | 1411 esp, (index + (kReturnHandlesDirectly ? 0 : 1)) * kPointerSize); |
1412 } | 1412 } |
1413 | 1413 |
1414 | 1414 |
1415 void MacroAssembler::PrepareCallApiFunction(int argc, Register scratch) { | 1415 void MacroAssembler::PrepareCallApiFunction(int argc) { |
1416 if (kReturnHandlesDirectly) { | 1416 if (kReturnHandlesDirectly) { |
1417 EnterApiExitFrame(argc); | 1417 EnterApiExitFrame(argc); |
1418 // When handles are returned directly we don't have to allocate extra | 1418 // When handles are returned directly we don't have to allocate extra |
1419 // space for and pass an out parameter. | 1419 // space for and pass an out parameter. |
| 1420 if (emit_debug_code()) { |
| 1421 mov(esi, Immediate(BitCast<int32_t>(kZapValue))); |
| 1422 } |
1420 } else { | 1423 } else { |
1421 // We allocate two additional slots: return value and pointer to it. | 1424 // We allocate two additional slots: return value and pointer to it. |
1422 EnterApiExitFrame(argc + 2); | 1425 EnterApiExitFrame(argc + 2); |
1423 | 1426 |
1424 // The argument slots are filled as follows: | 1427 // The argument slots are filled as follows: |
1425 // | 1428 // |
1426 // n + 1: output cell | 1429 // n + 1: output slot |
1427 // n: arg n | 1430 // n: arg n |
1428 // ... | 1431 // ... |
1429 // 1: arg1 | 1432 // 1: arg1 |
1430 // 0: pointer to the output cell | 1433 // 0: pointer to the output slot |
1431 // | |
1432 // Note that this is one more "argument" than the function expects | |
1433 // so the out cell will have to be popped explicitly after returning | |
1434 // from the function. The out cell contains Handle. | |
1435 | 1434 |
1436 // pointer to out cell. | 1435 lea(esi, Operand(esp, (argc + 1) * kPointerSize)); |
1437 lea(scratch, Operand(esp, (argc + 1) * kPointerSize)); | 1436 mov(Operand(esp, 0 * kPointerSize), esi); |
1438 mov(Operand(esp, 0 * kPointerSize), scratch); // output. | |
1439 if (emit_debug_code()) { | 1437 if (emit_debug_code()) { |
1440 mov(Operand(esp, (argc + 1) * kPointerSize), Immediate(0)); // out cell. | 1438 mov(Operand(esi, 0), Immediate(0)); |
1441 } | 1439 } |
1442 } | 1440 } |
1443 } | 1441 } |
1444 | 1442 |
1445 | 1443 |
1446 MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn(ApiFunction* function, | 1444 MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn(ApiFunction* function, |
1447 int stack_space) { | 1445 int stack_space) { |
1448 ExternalReference next_address = | 1446 ExternalReference next_address = |
1449 ExternalReference::handle_scope_next_address(); | 1447 ExternalReference::handle_scope_next_address(); |
1450 ExternalReference limit_address = | 1448 ExternalReference limit_address = |
1451 ExternalReference::handle_scope_limit_address(); | 1449 ExternalReference::handle_scope_limit_address(); |
1452 ExternalReference level_address = | 1450 ExternalReference level_address = |
1453 ExternalReference::handle_scope_level_address(); | 1451 ExternalReference::handle_scope_level_address(); |
1454 | 1452 |
1455 // Allocate HandleScope in callee-save registers. | 1453 // Allocate HandleScope in callee-save registers. |
1456 mov(ebx, Operand::StaticVariable(next_address)); | 1454 mov(ebx, Operand::StaticVariable(next_address)); |
1457 mov(edi, Operand::StaticVariable(limit_address)); | 1455 mov(edi, Operand::StaticVariable(limit_address)); |
1458 add(Operand::StaticVariable(level_address), Immediate(1)); | 1456 add(Operand::StaticVariable(level_address), Immediate(1)); |
1459 | 1457 |
1460 // Call the api function! | 1458 // Call the api function! |
1461 call(function->address(), RelocInfo::RUNTIME_ENTRY); | 1459 call(function->address(), RelocInfo::RUNTIME_ENTRY); |
1462 | 1460 |
1463 if (!kReturnHandlesDirectly) { | 1461 if (!kReturnHandlesDirectly) { |
1464 // The returned value is a pointer to the handle holding the result. | 1462 // PrepareCallApiFunction saved pointer to the output slot into |
1465 // Dereference this to get to the location. | 1463 // callee-save register esi. |
1466 mov(eax, Operand(eax, 0)); | 1464 mov(eax, Operand(esi, 0)); |
1467 } | 1465 } |
1468 | 1466 |
1469 Label empty_handle; | 1467 Label empty_handle; |
1470 Label prologue; | 1468 Label prologue; |
1471 Label promote_scheduled_exception; | 1469 Label promote_scheduled_exception; |
1472 Label delete_allocated_handles; | 1470 Label delete_allocated_handles; |
1473 Label leave_exit_frame; | 1471 Label leave_exit_frame; |
1474 | 1472 |
1475 // Check if the result handle holds 0. | 1473 // Check if the result handle holds 0. |
1476 test(eax, Operand(eax)); | 1474 test(eax, Operand(eax)); |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2131 | 2129 |
2132 // Check that the code was patched as expected. | 2130 // Check that the code was patched as expected. |
2133 ASSERT(masm_.pc_ == address_ + size_); | 2131 ASSERT(masm_.pc_ == address_ + size_); |
2134 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2132 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
2135 } | 2133 } |
2136 | 2134 |
2137 | 2135 |
2138 } } // namespace v8::internal | 2136 } } // namespace v8::internal |
2139 | 2137 |
2140 #endif // V8_TARGET_ARCH_IA32 | 2138 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |