blob: bac943b3123e3ade3ed166ddaa8a48b8cb1bf4f6 [file] [log] [blame]
Ian Rogersb033c752011-07-20 12:22:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2// Author: irogers@google.com (Ian Rogers)
3
4#include "src/calling_convention.h"
5#include "src/logging.h"
6
7namespace art {
8
9ManagedRegister CallingConvention::MethodRegister() {
10 return ManagedRegister::FromCoreRegister(R0);
11}
12
13ManagedRegister CallingConvention::InterproceduralScratchRegister() {
14 return ManagedRegister::FromCoreRegister(R12);
15}
16
17ManagedRegister CallingConvention::ReturnRegister() {
Ian Rogers45a76cb2011-07-21 22:00:15 -070018 const Method *method = GetMethod();
Ian Rogersb033c752011-07-20 12:22:35 -070019 if (GetMethod()->IsReturnAFloat()) {
20 return ManagedRegister::FromSRegister(S0);
Ian Rogers45a76cb2011-07-21 22:00:15 -070021 } else if (GetMethod()->IsReturnADouble()) {
Ian Rogersb033c752011-07-20 12:22:35 -070022 return ManagedRegister::FromDRegister(D0);
Ian Rogers45a76cb2011-07-21 22:00:15 -070023 } else if (method->IsReturnALong()) {
Ian Rogersb033c752011-07-20 12:22:35 -070024 return ManagedRegister::FromRegisterPair(R0_R1);
Ian Rogers45a76cb2011-07-21 22:00:15 -070025 } else if (method->IsReturnVoid()) {
26 return ManagedRegister::NoRegister();
Ian Rogersb033c752011-07-20 12:22:35 -070027 } else {
28 return ManagedRegister::FromCoreRegister(R0);
29 }
30}
31
32// Managed runtime calling convention
33
34bool ManagedRuntimeCallingConvention::IsCurrentParamInRegister() {
35 return itr_position_ < 3;
36}
37
38bool ManagedRuntimeCallingConvention::IsCurrentParamOnStack() {
39 return itr_position_ >= 3;
40}
41
42static const Register kManagedArgumentRegisters[] = {
43 R1, R2, R3
44};
45ManagedRegister ManagedRuntimeCallingConvention::CurrentParamRegister() {
46 CHECK_LT(itr_position_, 3u);
47 return
48 ManagedRegister::FromCoreRegister(kManagedArgumentRegisters[itr_position_]);
49}
50
51FrameOffset ManagedRuntimeCallingConvention::CurrentParamStackOffset() {
52 CHECK_GE(itr_position_, 3u);
53 return FrameOffset(displacement_.Int32Value() +
54 ((itr_position_ + itr_longs_and_doubles_ - 3) * kPointerSize));
55}
56
57// JNI calling convention
58
59bool JniCallingConvention::IsCurrentParamInRegister() {
60 return itr_position_ < 4;
61}
62
63bool JniCallingConvention::IsCurrentParamOnStack() {
64 return itr_position_ >= 4;
65}
66
67static const Register kJniArgumentRegisters[] = {
68 R0, R1, R2, R3
69};
70ManagedRegister JniCallingConvention::CurrentParamRegister() {
71 CHECK_LT(itr_position_, 4u);
72 return
73 ManagedRegister::FromCoreRegister(kJniArgumentRegisters[itr_position_]);
74}
75
76FrameOffset JniCallingConvention::CurrentParamStackOffset() {
77 CHECK_GE(itr_position_, 4u);
78 return FrameOffset(displacement_.Int32Value() - OutArgSize()
79 + ((itr_position_ + itr_longs_and_doubles_ - 4) * kPointerSize));
80}
81
82size_t JniCallingConvention::NumberOfOutgoingStackArgs() {
83 return GetMethod()->NumArgs() + GetMethod()->NumLongOrDoubleArgs() - 2;
84}
85
86} // namespace art