CallingConvention.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. namespace ARMeilleure.CodeGen.Arm64
  3. {
  4. static class CallingConvention
  5. {
  6. private const int RegistersMask = unchecked((int)0xffffffff);
  7. // Some of those register have specific roles and can't be used as general purpose registers.
  8. // X18 - Reserved for platform specific usage.
  9. // X29 - Frame pointer.
  10. // X30 - Return address.
  11. // X31 - Not an actual register, in some cases maps to SP, and in others to ZR.
  12. private const int ReservedRegsMask = (1 << CodeGenCommon.ReservedRegister) | (1 << 18) | (1 << 29) | (1 << 30) | (1 << 31);
  13. public static int GetIntAvailableRegisters()
  14. {
  15. return RegistersMask & ~ReservedRegsMask;
  16. }
  17. public static int GetVecAvailableRegisters()
  18. {
  19. return RegistersMask;
  20. }
  21. public static int GetIntCallerSavedRegisters()
  22. {
  23. return (GetIntCalleeSavedRegisters() ^ RegistersMask) & ~ReservedRegsMask;
  24. }
  25. public static int GetFpCallerSavedRegisters()
  26. {
  27. return GetFpCalleeSavedRegisters() ^ RegistersMask;
  28. }
  29. public static int GetVecCallerSavedRegisters()
  30. {
  31. return GetVecCalleeSavedRegisters() ^ RegistersMask;
  32. }
  33. public static int GetIntCalleeSavedRegisters()
  34. {
  35. return 0x1ff80000; // X19 to X28
  36. }
  37. public static int GetFpCalleeSavedRegisters()
  38. {
  39. return 0xff00; // D8 to D15
  40. }
  41. public static int GetVecCalleeSavedRegisters()
  42. {
  43. return 0;
  44. }
  45. public static int GetArgumentsOnRegsCount()
  46. {
  47. return 8;
  48. }
  49. public static int GetIntArgumentRegister(int index)
  50. {
  51. if ((uint)index < (uint)GetArgumentsOnRegsCount())
  52. {
  53. return index;
  54. }
  55. throw new ArgumentOutOfRangeException(nameof(index));
  56. }
  57. public static int GetVecArgumentRegister(int index)
  58. {
  59. if ((uint)index < (uint)GetArgumentsOnRegsCount())
  60. {
  61. return index;
  62. }
  63. throw new ArgumentOutOfRangeException(nameof(index));
  64. }
  65. public static int GetIntReturnRegister()
  66. {
  67. return 0;
  68. }
  69. public static int GetIntReturnRegisterHigh()
  70. {
  71. return 1;
  72. }
  73. public static int GetVecReturnRegister()
  74. {
  75. return 0;
  76. }
  77. }
  78. }