This change has been refactored based on the review and will be included in v2.

Original aarch64.h will remain unchanged, and the required definition for MS 
ABI will be implemented in aarch64-abi-ms.h. The reference to this file will be 
added to config.gcc.
This change has been verified, and it appears to work correctly.

The X18 register should not be used in any case.
The call used flag should be set to 0 for the X18 register to prevent its use 
in function calls.
The same applies to the static chain. The X17 register will be used instead of 
X18.

Regards,
Evgeny


gcc/config.gcc
@@ -1263,7 +1263,8 @@

aarch64-*-mingw*)
+       tm_file="${tm_file} aarch64/aarch64-abi-ms.h"



gcc/config/aarch64/aarch64-abi-ms.h
/* Copyright */

/* X18 reserved for the TEB on Windows.  */

#undef FIXED_REGISTERS
#define FIXED_REGISTERS                             \
  {                                                                     \
    0, 0, 0, 0,   0, 0, 0, 0,   /* R0 - R7 */           \
    0, 0, 0, 0,   0, 0, 0, 0,   /* R8 - R15 */          \
    0, 0, 1, 0,   0, 0, 0, 0,   /* R16 - R23.  */       \
    0, 0, 0, 0,   0, 1, 0, 1,   /* R24 - R30, SP */     \
    0, 0, 0, 0,   0, 0, 0, 0,   /* V0 - V7 */       \
    0, 0, 0, 0,   0, 0, 0, 0,   /* V8 - V15 */          \
    0, 0, 0, 0,   0, 0, 0, 0,   /* V16 - V23 */     \
    0, 0, 0, 0,   0, 0, 0, 0,   /* V24 - V31 */     \
    1, 1, 1, 1,                 /* SFP, AP, CC, VG */       \
    0, 0, 0, 0,   0, 0, 0, 0,   /* P0 - P7 */       \
    0, 0, 0, 0,   0, 0, 0, 0,   /* P8 - P15 */      \
    1, 1,                       /* FFR and FFRT */                  \
    1, 1, 1, 1, 1, 1, 1, 1      /* Fake registers */    \
  }

#undef CALL_REALLY_USED_REGISTERS
#define CALL_REALLY_USED_REGISTERS                  \
  {                                                                         \
    1, 1, 1, 1,   1, 1, 1, 1,   /* R0 - R7 */           \
    1, 1, 1, 1,   1, 1, 1, 1,   /* R8 - R15 */          \
    1, 1, 0, 0,   0, 0, 0, 0,   /* R16 - R23.  */   \
    0, 0, 0, 0,   0, 1, 1, 1,   /* R24 - R30, SP */     \
    1, 1, 1, 1,   1, 1, 1, 1,   /* V0 - V7 */           \
    0, 0, 0, 0,   0, 0, 0, 0,   /* V8 - V15 */          \
    1, 1, 1, 1,   1, 1, 1, 1,   /* V16 - V23 */     \
    1, 1, 1, 1,   1, 1, 1, 1,   /* V24 - V31 */     \
    1, 1, 1, 0,                 /* SFP, AP, CC, VG */       \
    1, 1, 1, 1,   1, 1, 1, 1,   /* P0 - P7 */       \
    1, 1, 1, 1,   1, 1, 1, 1,   /* P8 - P15 */      \
    1, 1,                       /* FFR and FFRT */              \
    0, 0, 0, 0, 0, 0, 0, 0      /* Fake registers */    \
  }

#undef  STATIC_CHAIN_REGNUM
#define STATIC_CHAIN_REGNUM             R17_REGNUM

 

-----Original Message-----
Thursday, February 22, 2024 12:55 PM 
Richard Earnshaw (lists) wrote:

+/* X18 reserved for the TEB on Windows.  */ #ifdef TARGET_ARM64_MS_ABI 
+# define FIXED_X18 1 # define CALL_USED_X18 0 #else # define FIXED_X18 
+0 # define CALL_USED_X18 1 #endif

I'm not overly keen on ifdefs like this (and the one below), it can get quite 
confusing if we have to support more than a couple of ABIs.  Perhaps we could 
create a couple of new headers, one for the EABI (which all existing targets 
would then need to include) and one for the MS ABI.  Then the mingw port would 
use that instead of the EABI header.

An alternative is to make all this dynamic, based on the setting of the 
aarch64_calling_abi enum and to make the adjustments in 
aarch64_conditional_register_usage.

+# define CALL_USED_X18 0

Is that really correct?  If the register is really reserved, but some code 
modifies it anyway, this will cause the compiler to restore the old value at 
the end of a function; generally, for a reserved register, code that knows what 
it's doing would want to make permanent changes to this value.

+#ifdef TARGET_ARM64_MS_ABI
+# define STATIC_CHAIN_REGNUM           R17_REGNUM
+#else
+# define STATIC_CHAIN_REGNUM           R18_REGNUM
+#endif

If we went the enum way, we'd want something like

#define STATIC_CHAIN_REGNUM (calling_abi == AARCH64_CALLING_ABI_MS ? R17_REGNUM 
: R18_REGNUM)

R.

Reply via email to