OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 19 matching lines...) Expand all Loading... |
30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
31 #include "codegen-inl.h" | 31 #include "codegen-inl.h" |
32 #include "assembler-x64.h" | 32 #include "assembler-x64.h" |
33 #include "macro-assembler-x64.h" | 33 #include "macro-assembler-x64.h" |
34 #include "serialize.h" | 34 #include "serialize.h" |
35 #include "debug.h" | 35 #include "debug.h" |
36 | 36 |
37 namespace v8 { | 37 namespace v8 { |
38 namespace internal { | 38 namespace internal { |
39 | 39 |
| 40 const Register kCArgRegs[kCArgRegsCount] = { |
| 41 #ifdef _WIN64 |
| 42 rcx, rdx, r8, r9 |
| 43 #else |
| 44 rdi, rsi, rdx, rcx, r8, r9 |
| 45 #endif |
| 46 }; |
| 47 |
| 48 |
40 MacroAssembler::MacroAssembler(void* buffer, int size) | 49 MacroAssembler::MacroAssembler(void* buffer, int size) |
41 : Assembler(buffer, size), | 50 : Assembler(buffer, size), |
42 generating_stub_(false), | 51 generating_stub_(false), |
43 allow_stub_calls_(true), | 52 allow_stub_calls_(true), |
44 code_object_(Heap::undefined_value()) { | 53 code_object_(Heap::undefined_value()) { |
45 } | 54 } |
46 | 55 |
47 | 56 |
48 void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) { | 57 void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) { |
49 movq(destination, Operand(r13, index << kPointerSizeLog2)); | 58 movq(destination, Operand(r13, index << kPointerSizeLog2)); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) { | 373 void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) { |
365 CallRuntime(Runtime::FunctionForId(id), num_arguments); | 374 CallRuntime(Runtime::FunctionForId(id), num_arguments); |
366 } | 375 } |
367 | 376 |
368 | 377 |
369 void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { | 378 void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { |
370 // If the expected number of arguments of the runtime function is | 379 // If the expected number of arguments of the runtime function is |
371 // constant, we check that the actual number of arguments match the | 380 // constant, we check that the actual number of arguments match the |
372 // expectation. | 381 // expectation. |
373 if (f->nargs >= 0 && f->nargs != num_arguments) { | 382 if (f->nargs >= 0 && f->nargs != num_arguments) { |
374 IllegalOperation(num_arguments); | 383 int num_args_on_stack = |
| 384 (Runtime::EXIT_FRAME_CALL == f->calling_convention) ? 0 : num_arguments; |
| 385 IllegalOperation(num_args_on_stack); |
375 return; | 386 return; |
376 } | 387 } |
377 | 388 |
378 // TODO(1236192): Most runtime routines don't need the number of | 389 switch (f->calling_convention) { |
379 // arguments passed in because it is constant. At some point we | 390 case Runtime::EXIT_FRAME_CALL: { |
380 // should remove this need and make the runtime routine entry code | 391 // Arguments are expected to be pushed on stack in left-to-right order. |
381 // smarter. | 392 // The stub will pass reference to them as Arguments into the function. |
382 movq(rax, Immediate(num_arguments)); | 393 |
383 movq(rbx, ExternalReference(f)); | 394 // TODO(1236192): Most runtime routines don't need the number of |
384 CEntryStub ces(f->result_size); | 395 // arguments passed in because it is constant. At some point we |
385 CallStub(&ces); | 396 // should remove this need and make the runtime routine entry code |
| 397 // smarter. |
| 398 movq(rax, Immediate(num_arguments)); |
| 399 movq(rbx, ExternalReference(f)); |
| 400 CEntryStub ces(f->result_size); |
| 401 CallStub(&ces); |
| 402 break; |
| 403 } |
| 404 case Runtime::DIRECT_CALL_NOT_FAILS: |
| 405 // Arguments are expected to be put into the registers in order of |
| 406 // kCArgRegs. |
| 407 ASSERT(num_arguments <= kCArgRegsCount); |
| 408 PrepareCallCFunction(num_arguments); |
| 409 CallCFunction(ExternalReference(f), num_arguments); |
| 410 break; |
| 411 } |
386 } | 412 } |
387 | 413 |
388 | 414 |
389 void MacroAssembler::CallExternalReference(const ExternalReference& ext, | 415 void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
390 int num_arguments) { | 416 int num_arguments) { |
391 movq(rax, Immediate(num_arguments)); | 417 movq(rax, Immediate(num_arguments)); |
392 movq(rbx, ext); | 418 movq(rbx, ext); |
393 | 419 |
394 CEntryStub stub(1); | 420 CEntryStub stub(1); |
395 CallStub(&stub); | 421 CallStub(&stub); |
396 } | 422 } |
397 | 423 |
| 424 void MacroAssembler::TailCallRuntime(Runtime::FunctionId id, |
| 425 int num_arguments, |
| 426 int result_size) { |
| 427 Runtime::Function* f = Runtime::FunctionForId(id); |
398 | 428 |
399 void MacroAssembler::TailCallRuntime(ExternalReference const& ext, | 429 ASSERT(f->nargs == -1 || f->nargs == num_arguments); |
| 430 if (f->calling_convention == Runtime::EXIT_FRAME_CALL) { |
| 431 TailCallExternalReference(ExternalReference(f), num_arguments, result_size); |
| 432 } else if (f->calling_convention == Runtime::DIRECT_CALL_NOT_FAILS) { |
| 433 // Move arguments to registers |
| 434 ASSERT(kCArgRegsCount >= num_arguments); |
| 435 pop(rax); // get return address |
| 436 for (int i = 0; i < num_arguments; i++) { |
| 437 pop(kCArgRegs[num_arguments - 1 - i]); |
| 438 } |
| 439 PrepareCallCFunction(num_arguments); // align stack |
| 440 movq(kScratchRegister, ExternalReference(f)); |
| 441 push(rax); // return |
| 442 jmp(kScratchRegister); |
| 443 } |
| 444 } |
| 445 |
| 446 |
| 447 void MacroAssembler::TailCallExternalReference(ExternalReference const& ext, |
400 int num_arguments, | 448 int num_arguments, |
401 int result_size) { | 449 int result_size) { |
402 // ----------- S t a t e ------------- | 450 // ----------- S t a t e ------------- |
403 // -- rsp[0] : return address | 451 // -- rsp[0] : return address |
404 // -- rsp[8] : argument num_arguments - 1 | 452 // -- rsp[8] : argument num_arguments - 1 |
405 // ... | 453 // ... |
406 // -- rsp[8 * num_arguments] : argument 0 (receiver) | 454 // -- rsp[8 * num_arguments] : argument 0 (receiver) |
407 // ----------------------------------- | 455 // ----------------------------------- |
408 | 456 |
409 // TODO(1236192): Most runtime routines don't need the number of | 457 // TODO(1236192): Most runtime routines don't need the number of |
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2577 CodePatcher::~CodePatcher() { | 2625 CodePatcher::~CodePatcher() { |
2578 // Indicate that code has changed. | 2626 // Indicate that code has changed. |
2579 CPU::FlushICache(address_, size_); | 2627 CPU::FlushICache(address_, size_); |
2580 | 2628 |
2581 // Check that the code was patched as expected. | 2629 // Check that the code was patched as expected. |
2582 ASSERT(masm_.pc_ == address_ + size_); | 2630 ASSERT(masm_.pc_ == address_ + size_); |
2583 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2631 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
2584 } | 2632 } |
2585 | 2633 |
2586 } } // namespace v8::internal | 2634 } } // namespace v8::internal |
OLD | NEW |