From 72ca3f49e3eef9b18946b8d4e77019c1441e1a97 Mon Sep 17 00:00:00 2001 From: Zac Walker Date: Tue, 20 Feb 2024 15:30:33 +0100 Subject: [PATCH v1 03/13] aarch64: Mark x18 register as a fixed register for MS ABI Define the MS ABI for aarch64-w64-mingw32. Adjust FIXED_REGISTERS and STATIC_CHAIN_REGNUM for different ABIs. The X18 register is reserved on Windows for the TEB. gcc/ChangeLog: * config.gcc: Define TARGET_ARM64_MS_ABI when Arm64 MS ABI is used. * config/aarch64/aarch64.h (FIXED_X18): Define if X18 regsiter is fixed. (CALL_USED_X18): Define if X18 register is call used. (FIXED_REGISTERS): Adjust FIXED_REGISTERS for different ABIs. (STATIC_CHAIN_REGNUM): Define STATIC_CHAIN_REGNUM acording to ABI. --- gcc/config.gcc | 1 + gcc/config/aarch64/aarch64.h | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gcc/config.gcc b/gcc/config.gcc index 092a091595d..2a9e4c44f50 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -1276,6 +1276,7 @@ aarch64*-*-mingw*) default_use_cxa_atexit=yes need_64bit_isa=yes user_headers_inc_next_post="${user_headers_inc_next_post} float.h" + tm_defines="${tm_defines} TARGET_ARM64_MS_ABI=1" ;; aarch64*-wrs-vxworks*) tm_file="${tm_file} elfos.h aarch64/aarch64-elf.h" diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h index 45e901cda64..36916e7a97d 100644 --- a/gcc/config/aarch64/aarch64.h +++ b/gcc/config/aarch64/aarch64.h @@ -536,11 +536,20 @@ constexpr auto AARCH64_FL_DEFAULT_ISA_MODE = AARCH64_FL_SM_OFF; register. GCC internally uses the poly_int variable aarch64_sve_vg instead. */ +/* 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 + #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, 0, 0, 0, 0, 0, 0, /* R16 - R23 */ \ + 0, 0, FIXED_X18, 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 */ \ @@ -564,7 +573,7 @@ constexpr auto AARCH64_FL_DEFAULT_ISA_MODE = AARCH64_FL_SM_OFF; { \ 1, 1, 1, 1, 1, 1, 1, 1, /* R0 - R7 */ \ 1, 1, 1, 1, 1, 1, 1, 1, /* R8 - R15 */ \ - 1, 1, 1, 0, 0, 0, 0, 0, /* R16 - R23 */ \ + 1, 1, CALL_USED_X18, 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 */ \ @@ -642,7 +651,11 @@ constexpr auto AARCH64_FL_DEFAULT_ISA_MODE = AARCH64_FL_SM_OFF; uses alloca. */ #define EXIT_IGNORE_STACK (cfun->calls_alloca) -#define STATIC_CHAIN_REGNUM R18_REGNUM +#ifdef TARGET_ARM64_MS_ABI +# define STATIC_CHAIN_REGNUM R17_REGNUM +#else +# define STATIC_CHAIN_REGNUM R18_REGNUM +#endif #define HARD_FRAME_POINTER_REGNUM R29_REGNUM #define FRAME_POINTER_REGNUM SFP_REGNUM #define STACK_POINTER_REGNUM SP_REGNUM -- 2.25.1