| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
| 7 | 7 |
| 8 #include "vm/runtime_entry.h" | 8 #include "vm/runtime_entry.h" |
| 9 | 9 |
| 10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
| 11 #include "vm/simulator.h" | 11 #include "vm/simulator.h" |
| 12 #include "vm/stub_code.h" | 12 #include "vm/stub_code.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 #define __ assembler-> | 16 #define __ assembler-> |
| 17 | 17 |
| 18 |
| 19 uword RuntimeEntry::GetEntryPoint() const { |
| 20 // Compute the effective address. When running under the simulator, |
| 21 // this is a redirection address that forces the simulator to call |
| 22 // into the runtime system. |
| 23 uword entry = reinterpret_cast<uword>(function()); |
| 24 #if defined(USING_SIMULATOR) |
| 25 // Redirection to leaf runtime calls supports a maximum of 4 arguments passed |
| 26 // in registers (maximum 2 double arguments for leaf float runtime calls). |
| 27 ASSERT(argument_count() >= 0); |
| 28 ASSERT(!is_leaf() || |
| 29 (!is_float() && (argument_count() <= 4)) || |
| 30 (argument_count() <= 2)); |
| 31 Simulator::CallKind call_kind = |
| 32 is_leaf() ? (is_float() ? Simulator::kLeafFloatRuntimeCall |
| 33 : Simulator::kLeafRuntimeCall) |
| 34 : Simulator::kRuntimeCall; |
| 35 entry = |
| 36 Simulator::RedirectExternalReference(entry, call_kind, argument_count()); |
| 37 #endif |
| 38 return entry; |
| 39 } |
| 40 |
| 41 |
| 18 // Generate code to call into the stub which will call the runtime | 42 // Generate code to call into the stub which will call the runtime |
| 19 // function. Input for the stub is as follows: | 43 // function. Input for the stub is as follows: |
| 20 // SP : points to the arguments and return value array. | 44 // SP : points to the arguments and return value array. |
| 21 // R5 : address of the runtime function to call. | 45 // R5 : address of the runtime function to call. |
| 22 // R4 : number of arguments to the call. | 46 // R4 : number of arguments to the call. |
| 23 void RuntimeEntry::Call(Assembler* assembler, intptr_t argument_count) const { | 47 void RuntimeEntry::Call(Assembler* assembler, intptr_t argument_count) const { |
| 24 // Compute the effective address. When running under the simulator, | |
| 25 // this is a redirection address that forces the simulator to call | |
| 26 // into the runtime system. | |
| 27 uword entry = GetEntryPoint(); | |
| 28 #if defined(USING_SIMULATOR) | |
| 29 // Redirection to leaf runtime calls supports a maximum of 8 arguments passed | |
| 30 // in registers. | |
| 31 ASSERT(argument_count >= 0); | |
| 32 ASSERT(!is_leaf() || (argument_count <= 8)); | |
| 33 Simulator::CallKind call_kind = | |
| 34 is_leaf() ? (is_float() ? Simulator::kLeafFloatRuntimeCall | |
| 35 : Simulator::kLeafRuntimeCall) | |
| 36 : Simulator::kRuntimeCall; | |
| 37 entry = | |
| 38 Simulator::RedirectExternalReference(entry, call_kind, argument_count); | |
| 39 #endif | |
| 40 ExternalLabel label(entry); | |
| 41 if (is_leaf()) { | 48 if (is_leaf()) { |
| 42 ASSERT(argument_count == this->argument_count()); | 49 ASSERT(argument_count == this->argument_count()); |
| 43 // Since we are entering C++ code, we must restore the C stack pointer from | 50 // Since we are entering C++ code, we must restore the C stack pointer from |
| 44 // the stack limit to an aligned value nearer to the top of the stack. | 51 // the stack limit to an aligned value nearer to the top of the stack. |
| 45 // We cache the Dart stack pointer and the stack limit in callee-saved | 52 // We cache the Dart stack pointer and the stack limit in callee-saved |
| 46 // registers, then align and call, restoring CSP and SP on return from the | 53 // registers, then align and call, restoring CSP and SP on return from the |
| 47 // call. | 54 // call. |
| 48 __ mov(R25, CSP); | 55 __ mov(R25, CSP); |
| 49 __ mov(R26, SP); | 56 __ mov(R26, SP); |
| 50 __ ReserveAlignedFrameSpace(0); | 57 __ ReserveAlignedFrameSpace(0); |
| 51 __ mov(CSP, SP); | 58 __ mov(CSP, SP); |
| 52 __ BranchLink(&label); | 59 __ ldr(TMP, Address(THR, Thread::OffsetFromThread(this))); |
| 60 __ blr(TMP); |
| 53 __ mov(SP, R26); | 61 __ mov(SP, R26); |
| 54 __ mov(CSP, R25); | 62 __ mov(CSP, R25); |
| 55 } else { | 63 } else { |
| 56 // Argument count is not checked here, but in the runtime entry for a more | 64 // Argument count is not checked here, but in the runtime entry for a more |
| 57 // informative error message. | 65 // informative error message. |
| 58 __ LoadExternalLabel(R5, &label); | 66 __ ldr(R5, Address(THR, Thread::OffsetFromThread(this))); |
| 59 __ LoadImmediate(R4, argument_count); | 67 __ LoadImmediate(R4, argument_count); |
| 60 __ BranchLink(*StubCode::CallToRuntime_entry()); | 68 __ BranchLink(*StubCode::CallToRuntime_entry()); |
| 61 } | 69 } |
| 62 } | 70 } |
| 63 | 71 |
| 64 } // namespace dart | 72 } // namespace dart |
| 65 | 73 |
| 66 #endif // defined TARGET_ARCH_ARM64 | 74 #endif // defined TARGET_ARCH_ARM64 |
| OLD | NEW |