88
99#include "../assembly.h"
1010
11- #ifdef HAS_ASM_SME
12- #define ARCH armv9 - a + sme
13- #define SMSTOP_SM smstop sm
14- #define SMSTOP_ZA smstop za
15- #define REG_TPIDR2_EL0 TPIDR2_EL0
16- #define REG_SVCR SVCR
17- #define ADDSVL_X16_X16_1 addsvl x16 , x16 , # 1
18- #define LDR_ZA_W15_0_X16 ldr za [ w15 , 0 ], [ x16 ]
19- #define STR_ZA_W15_0_X16 str za [ w15 , 0 ], [ x16 ]
20- #define CNTD_X0 cntd x0
21- #define CFI_OFFSET_VG_MINUS_16 .cfi_offset vg , - 16
22- #else
23- #define ARCH armv8 - a
24- #define SMSTOP_SM .inst 0xd503427f
25- #define SMSTOP_ZA .inst 0xd503447f
26- #define REG_TPIDR2_EL0 S3_3_C13_C0_5
27- #define REG_SVCR S3_3_C4_C2_2
28- #define ADDSVL_X16_X16_1 .inst 0x04305830
29- #define LDR_ZA_W15_0_X16 .inst 0xe1006200
30- #define STR_ZA_W15_0_X16 .inst 0xe1206200
31- #define CNTD_X0 .inst 0x04e0e3e0
32- #define CFI_OFFSET_VG_MINUS_16 .cfi_escape 0x10 , 0x2e , 0x03 , 0x11 , 0x70 , 0x22 // $ vg @ cfa - 16
33- #endif
3411
3512#if !defined(__APPLE__)
3613#define TPIDR2_SYMBOL SYMBOL_NAME(__aarch64_has_sme_and_tpidr2_el0)
4219#define TPIDR2_SYMBOL_OFFSET SYMBOL_NAME(__aarch64_has_sme_and_tpidr2_el0)@pageoff
4320#endif
4421
45- .arch ARCH
22+ .arch armv9 - a + sme
4623
4724// Utility function which calls a system's abort() routine. Because the function
4825// is streaming - compatible it should disable streaming - SVE mode before calling
4926// abort(). Note th at there is no need to preserve any state before the call ,
5027// because the function does not return.
5128DEFINE_COMPILERRT_PRIVATE_FUNCTION(do_abort)
5229.cfi_startproc
53- .variant_pcs SYMBOL_NAME(do_abort)
30+ .variant_pcs SYMBOL_NAME(do_abort)
5431 stp x29 , x30 , [ sp , # - 32 ] !
55- CNTD_X0
32+ cntd x0
5633 // Store VG to a stack location th at we describe with .cfi_offset
5734 str x0 , [ sp , # 16 ]
5835 .cfi_def_cfa_offset 32
5936 .cfi_offset w30 , - 24
6037 .cfi_offset w29 , - 32
61- CFI_OFFSET_VG_MINUS_16
38+ .cfi_offset vg , - 16
6239 bl __arm_sme_state
6340 tbz x0 , # 0 , 2f
64411 :
65- SMSTOP_SM
42+ smstop sm
66432 :
6744 // We can't make this into a tail - call because the unwinder would
6845 // need to restore the value of VG.
@@ -74,7 +51,7 @@ END_COMPILERRT_FUNCTION(do_abort)
7451// th at is set as part of the compiler - rt startup code.
7552// __aarch64_has_sme_and_tpidr2_el0
7653DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_sme_state)
77- .variant_pcs __arm_sme_state
54+ .variant_pcs __arm_sme_state
7855 mov x0 , xzr
7956 mov x1 , xzr
8057
@@ -83,18 +60,18 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_sme_state)
8360 cbz w16 , 1f
84610 :
8562 orr x0 , x0 , # 0xC000000000000000
86- mrs x16 , REG_SVCR
63+ mrs x16 , SVCR
8764 bfxil x0 , x16 , # 0 , # 2
88- mrs x1 , REG_TPIDR2_EL0
65+ mrs x1 , TPIDR2_EL0
89661 :
9067 ret
9168END_COMPILERRT_OUTLINE_FUNCTION(__arm_sme_state)
9269
9370DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_restore)
94- .variant_pcs __arm_tpidr2_restore
71+ .variant_pcs __arm_tpidr2_restore
9572 // If TPIDR2_EL0 is nonnull , the subroutine aborts in some platform - specific
9673 // manner.
97- mrs x14 , REG_TPIDR2_EL0
74+ mrs x14 , TPIDR2_EL0
9875 cbnz x14 , 2f
9976
10077 // If any of the reserved bytes in the first 16 bytes of BLK are nonzero ,
@@ -114,8 +91,8 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_restore)
11491
11592 mov x15 , xzr
116930 :
117- LDR_ZA_W15_0_X16
118- ADDSVL_X16_X16_1
94+ ldr za [ w15 , 0 ], [ x16 ]
95+ addsvl x16 , x16 , # 1
11996 add x15 , x15 , # 1
12097 cmp x14 , x15
12198 b.ne 0b
@@ -126,14 +103,15 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_restore)
126103END_COMPILERRT_OUTLINE_FUNCTION(__arm_tpidr2_restore)
127104
128105DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_save)
106+ .variant_pcs __arm_tpidr2_restore
129107 // If the current thread does not have access to TPIDR2_EL0 , the subroutine
130108 // does nothing.
131109 adrp x14 , TPIDR2_SYMBOL
132110 ldrb w14 , [ x14 , TPIDR2_SYMBOL_OFFSET ]
133111 cbz w14 , 1f
134112
135113 // If TPIDR2_EL0 is null , the subroutine does nothing.
136- mrs x16 , REG_TPIDR2_EL0
114+ mrs x16 , TPIDR2_EL0
137115 cbz x16 , 1f
138116
139117 // If any of the reserved bytes in the first 16 bytes of the TPIDR2 block are
@@ -153,8 +131,8 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_save)
153131
154132 mov x15 , xzr
1551330 :
156- STR_ZA_W15_0_X16
157- ADDSVL_X16_X16_1
134+ str za [ w15 , 0 ], [ x16 ]
135+ addsvl x16 , x16 , # 1
158136 add x15 , x15 , # 1
159137 cmp x14 , x15
160138 b.ne 0b
@@ -165,6 +143,7 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_save)
165143END_COMPILERRT_OUTLINE_FUNCTION(__arm_tpidr2_save)
166144
167145DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_za_disable)
146+ .variant_pcs __arm_tpidr2_restore
168147 // If the current thread does not have access to SME , the subroutine does
169148 // nothing.
170149 adrp x14 , TPIDR2_SYMBOL
@@ -182,10 +161,10 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_za_disable)
182161 bl __arm_tpidr2_save
183162
184163 // * Set TPIDR2_EL0 to null.
185- msr REG_TPIDR2_EL0 , xzr
164+ msr TPIDR2_EL0 , xzr
186165
187166 // * Set PSTATE.ZA to 0 .
188- SMSTOP_ZA
167+ smstop za
189168
190169 .cfi_def_cfa wsp , 16
191170 ldp x29 , x30 , [ sp ], # 16
0 commit comments