12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/*
22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project
32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License.
62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at
72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software
112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and
142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License.
152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */
162c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_COMPILER_JNI_QUICK_ARM_CALLING_CONVENTION_ARM_H_
18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_COMPILER_JNI_QUICK_ARM_CALLING_CONVENTION_ARM_H_
192c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
207940e44f4517de5e2634a7e07d58d0fb26160513Brian Carlstrom#include "jni/quick/calling_convention.h"
212c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
222c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersnamespace art {
232c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersnamespace arm {
242c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
25790a6b7312979513710c366b411ba6791ddf78c2Ian Rogersconstexpr size_t kFramePointerSize = 4;
26790a6b7312979513710c366b411ba6791ddf78c2Ian Rogers
2725ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampeclass ArmManagedRuntimeCallingConvention FINAL : public ManagedRuntimeCallingConvention {
282c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers public:
29ca190666fb11820153f74274c495ba1f913d8a69Ian Rogers  ArmManagedRuntimeCallingConvention(bool is_static, bool is_synchronized, const char* shorty)
30790a6b7312979513710c366b411ba6791ddf78c2Ian Rogers      : ManagedRuntimeCallingConvention(is_static, is_synchronized, shorty, kFramePointerSize) {}
3125ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ~ArmManagedRuntimeCallingConvention() OVERRIDE {}
322c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  // Calling convention
3325ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister ReturnRegister() OVERRIDE;
3425ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister InterproceduralScratchRegister() OVERRIDE;
352c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  // Managed runtime calling convention
3625ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister MethodRegister() OVERRIDE;
3725ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  bool IsCurrentParamInRegister() OVERRIDE;
3825ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  bool IsCurrentParamOnStack() OVERRIDE;
3925ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister CurrentParamRegister() OVERRIDE;
4025ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  FrameOffset CurrentParamStackOffset() OVERRIDE;
41fca82208f7128fcda09b6a4743199308332558a2Dmitry Petrochenko  const ManagedRegisterEntrySpills& EntrySpills() OVERRIDE;
4200f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers
432c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers private:
44fca82208f7128fcda09b6a4743199308332558a2Dmitry Petrochenko  ManagedRegisterEntrySpills entry_spills_;
45b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers
462c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  DISALLOW_COPY_AND_ASSIGN(ArmManagedRuntimeCallingConvention);
472c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers};
482c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
4925ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampeclass ArmJniCallingConvention FINAL : public JniCallingConvention {
502c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers public:
513887c468d731420e929e6ad3acf190d5431e94fcRoland Levillain  ArmJniCallingConvention(bool is_static, bool is_synchronized, const char* shorty);
5225ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ~ArmJniCallingConvention() OVERRIDE {}
532c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  // Calling convention
5425ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister ReturnRegister() OVERRIDE;
5525ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister IntReturnRegister() OVERRIDE;
5625ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister InterproceduralScratchRegister() OVERRIDE;
572c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  // JNI calling convention
5825ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  void Next() OVERRIDE;  // Override default behavior for AAPCS
5925ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  size_t FrameSize() OVERRIDE;
6025ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  size_t OutArgSize() OVERRIDE;
6125ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  const std::vector<ManagedRegister>& CalleeSaveRegisters() const OVERRIDE {
62bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers    return callee_save_regs_;
63bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers  }
6425ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister ReturnScratchRegister() const OVERRIDE;
6525ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  uint32_t CoreSpillMask() const OVERRIDE;
667cde48c56df5b57aed524cce44c902bc720f2d6cSebastien Hertz  uint32_t FpSpillMask() const OVERRIDE;
6725ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  bool IsCurrentParamInRegister() OVERRIDE;
6825ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  bool IsCurrentParamOnStack() OVERRIDE;
6925ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister CurrentParamRegister() OVERRIDE;
7025ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  FrameOffset CurrentParamStackOffset() OVERRIDE;
712c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
72d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe  // AAPCS mandates return values are extended.
73d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe  bool RequiresSmallResultTypeExtension() const OVERRIDE {
74d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe    return false;
75d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe  }
76d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe
772c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers protected:
7825ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  size_t NumberOfOutgoingStackArgs() OVERRIDE;
792c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
802c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers private:
81bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers  // TODO: these values aren't unique and can be shared amongst instances
82bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers  std::vector<ManagedRegister> callee_save_regs_;
83bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers
8467375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers  // Padding to ensure longs and doubles are not split in AAPCS
8567375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers  size_t padding_;
8667375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers
872c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  DISALLOW_COPY_AND_ASSIGN(ArmJniCallingConvention);
882c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers};
892c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
902c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers}  // namespace arm
912c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers}  // namespace art
922c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
93fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif  // ART_COMPILER_JNI_QUICK_ARM_CALLING_CONVENTION_ARM_H_
94