Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame^] | 1 | // 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 | |
| 7 | namespace art { |
| 8 | |
| 9 | ManagedRegister CallingConvention::MethodRegister() { |
| 10 | return ManagedRegister::FromCoreRegister(R0); |
| 11 | } |
| 12 | |
| 13 | ManagedRegister CallingConvention::InterproceduralScratchRegister() { |
| 14 | return ManagedRegister::FromCoreRegister(R12); |
| 15 | } |
| 16 | |
| 17 | ManagedRegister CallingConvention::ReturnRegister() { |
| 18 | if (GetMethod()->IsReturnAFloat()) { |
| 19 | return ManagedRegister::FromSRegister(S0); |
| 20 | } else if (GetMethod()->IsReturnAFloat()) { |
| 21 | return ManagedRegister::FromDRegister(D0); |
| 22 | } else if (GetMethod()->IsReturnALong()) { |
| 23 | return ManagedRegister::FromRegisterPair(R0_R1); |
| 24 | } else { |
| 25 | return ManagedRegister::FromCoreRegister(R0); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // Managed runtime calling convention |
| 30 | |
| 31 | bool ManagedRuntimeCallingConvention::IsCurrentParamInRegister() { |
| 32 | return itr_position_ < 3; |
| 33 | } |
| 34 | |
| 35 | bool ManagedRuntimeCallingConvention::IsCurrentParamOnStack() { |
| 36 | return itr_position_ >= 3; |
| 37 | } |
| 38 | |
| 39 | static const Register kManagedArgumentRegisters[] = { |
| 40 | R1, R2, R3 |
| 41 | }; |
| 42 | ManagedRegister ManagedRuntimeCallingConvention::CurrentParamRegister() { |
| 43 | CHECK_LT(itr_position_, 3u); |
| 44 | return |
| 45 | ManagedRegister::FromCoreRegister(kManagedArgumentRegisters[itr_position_]); |
| 46 | } |
| 47 | |
| 48 | FrameOffset ManagedRuntimeCallingConvention::CurrentParamStackOffset() { |
| 49 | CHECK_GE(itr_position_, 3u); |
| 50 | return FrameOffset(displacement_.Int32Value() + |
| 51 | ((itr_position_ + itr_longs_and_doubles_ - 3) * kPointerSize)); |
| 52 | } |
| 53 | |
| 54 | // JNI calling convention |
| 55 | |
| 56 | bool JniCallingConvention::IsCurrentParamInRegister() { |
| 57 | return itr_position_ < 4; |
| 58 | } |
| 59 | |
| 60 | bool JniCallingConvention::IsCurrentParamOnStack() { |
| 61 | return itr_position_ >= 4; |
| 62 | } |
| 63 | |
| 64 | static const Register kJniArgumentRegisters[] = { |
| 65 | R0, R1, R2, R3 |
| 66 | }; |
| 67 | ManagedRegister JniCallingConvention::CurrentParamRegister() { |
| 68 | CHECK_LT(itr_position_, 4u); |
| 69 | return |
| 70 | ManagedRegister::FromCoreRegister(kJniArgumentRegisters[itr_position_]); |
| 71 | } |
| 72 | |
| 73 | FrameOffset JniCallingConvention::CurrentParamStackOffset() { |
| 74 | CHECK_GE(itr_position_, 4u); |
| 75 | return FrameOffset(displacement_.Int32Value() - OutArgSize() |
| 76 | + ((itr_position_ + itr_longs_and_doubles_ - 4) * kPointerSize)); |
| 77 | } |
| 78 | |
| 79 | size_t JniCallingConvention::NumberOfOutgoingStackArgs() { |
| 80 | return GetMethod()->NumArgs() + GetMethod()->NumLongOrDoubleArgs() - 2; |
| 81 | } |
| 82 | |
| 83 | } // namespace art |