1// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5#include "vm/globals.h"
6#if defined(TARGET_ARCH_IA32)
7
8#include "vm/runtime_entry.h"
9
10#include "vm/compiler/assembler/assembler.h"
11#include "vm/stub_code.h"
12
13namespace dart {
14
15#define __ assembler->
16
17uword RuntimeEntry::GetEntryPoint() const {
18 return reinterpret_cast<uword>(function());
19}
20
21#if !defined(DART_PRECOMPILED_RUNTIME)
22// Generate code to call into the stub which will call the runtime
23// function. Input for the stub is as follows:
24// For regular runtime calls -
25// ESP : points to the arguments and return value array.
26// ECX : address of the runtime function to call.
27// EDX : number of arguments to the call as Smi.
28// For leaf calls the caller is responsible to setup the arguments
29// and look for return values based on the C calling convention.
30void RuntimeEntry::CallInternal(const RuntimeEntry* runtime_entry,
31 compiler::Assembler* assembler,
32 intptr_t argument_count) {
33 if (runtime_entry->is_leaf()) {
34 ASSERT(argument_count == runtime_entry->argument_count());
35 __ movl(EAX, compiler::Immediate(runtime_entry->GetEntryPoint()));
36 __ movl(compiler::Assembler::VMTagAddress(), EAX);
37 __ call(EAX);
38 __ movl(compiler::Assembler::VMTagAddress(),
39 compiler::Immediate(VMTag::kDartCompiledTagId));
40 } else {
41 // Argument count is not checked here, but in the runtime entry for a more
42 // informative error message.
43 __ movl(ECX, compiler::Immediate(runtime_entry->GetEntryPoint()));
44 __ movl(EDX, compiler::Immediate(argument_count));
45 __ CallToRuntime();
46 }
47}
48#endif // !defined(DART_PRECOMPILED_RUNTIME)
49
50} // namespace dart
51
52#endif // defined TARGET_ARCH_IA32
53