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 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 4 | #include "calling_convention.h" |
| 5 | #include "logging.h" |
| 6 | #include "utils.h" |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 7 | |
| 8 | namespace art { |
| 9 | |
| 10 | ManagedRegister CallingConvention::MethodRegister() { |
| 11 | return ManagedRegister::FromCpuRegister(EDI); |
| 12 | } |
| 13 | |
| 14 | ManagedRegister CallingConvention::InterproceduralScratchRegister() { |
| 15 | return ManagedRegister::FromCpuRegister(ECX); |
| 16 | } |
| 17 | |
| 18 | ManagedRegister CallingConvention::ReturnRegister() { |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 19 | const Method *method = GetMethod(); |
| 20 | if (method->IsReturnAFloatOrDouble()) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 21 | return ManagedRegister::FromX87Register(ST0); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 22 | } else if (method->IsReturnALong()) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 23 | return ManagedRegister::FromRegisterPair(EAX_EDX); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 24 | } else if (method->IsReturnVoid()) { |
| 25 | return ManagedRegister::NoRegister(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 26 | } else { |
| 27 | return ManagedRegister::FromCpuRegister(EAX); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // Managed runtime calling convention |
| 32 | |
| 33 | bool ManagedRuntimeCallingConvention::IsCurrentParamInRegister() { |
| 34 | return false; // Everything is passed by stack |
| 35 | } |
| 36 | |
| 37 | bool ManagedRuntimeCallingConvention::IsCurrentParamOnStack() { |
| 38 | return true; // Everything is passed by stack |
| 39 | } |
| 40 | |
| 41 | ManagedRegister ManagedRuntimeCallingConvention::CurrentParamRegister() { |
| 42 | LOG(FATAL) << "Should not reach here"; |
| 43 | return ManagedRegister::NoRegister(); |
| 44 | } |
| 45 | |
| 46 | FrameOffset ManagedRuntimeCallingConvention::CurrentParamStackOffset() { |
Shih-wei Liao | 5381cf9 | 2011-07-27 00:28:04 -0700 | [diff] [blame] | 47 | return FrameOffset(displacement_.Int32Value() + (itr_slots_ * kPointerSize)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | // JNI calling convention |
| 51 | |
Carl Shapiro | e2d373e | 2011-07-25 15:20:06 -0700 | [diff] [blame] | 52 | bool JniCallingConvention::IsOutArgRegister(ManagedRegister) { |
| 53 | return false; // Everything is passed by stack |
| 54 | } |
| 55 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 56 | bool JniCallingConvention::IsCurrentParamInRegister() { |
| 57 | return false; // Everything is passed by stack |
| 58 | } |
| 59 | |
| 60 | bool JniCallingConvention::IsCurrentParamOnStack() { |
| 61 | return true; // Everything is passed by stack |
| 62 | } |
| 63 | |
| 64 | ManagedRegister JniCallingConvention::CurrentParamRegister() { |
| 65 | LOG(FATAL) << "Should not reach here"; |
| 66 | return ManagedRegister::NoRegister(); |
| 67 | } |
| 68 | |
| 69 | FrameOffset JniCallingConvention::CurrentParamStackOffset() { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 70 | return FrameOffset(displacement_.Int32Value() - OutArgSize() + |
Shih-wei Liao | 5381cf9 | 2011-07-27 00:28:04 -0700 | [diff] [blame] | 71 | (itr_slots_ * kPointerSize)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | size_t JniCallingConvention::NumberOfOutgoingStackArgs() { |
| 75 | return GetMethod()->NumArgs() + GetMethod()->NumLongOrDoubleArgs(); |
| 76 | } |
| 77 | |
| 78 | } // namespace art |