Skip to content

Commit f99c303

Browse files
committed
[patches][picolibc][aarch64] Initialize SME
These two patches add the following needed for SME support in picolibc 1. If SME or SME2 is enabled at EL3, 1.1 Clear TPIDR2_EL0 [1] The value of TPIDR2_EL0 resets to an architecturally UNKNOWN value at warm reset. This means we need to clear it manually at startup. 1.2 Initialise SME Streaming SVE Vector length to 2048 bits Initialize the SME control register SMCR_EL3 [2] to set the effective streaming SVE vector length to the maximum supported value of 2048 bits. 2. Add implementation of the __aarch64_sme_accessible compiler-rt relies on the the __aarch64_sme_accessible support function to emit SME ABI support routines calls [3]. __aarch64_sme_accessible returns non-zero when SME support is enabled in the underlying hardware. [1] https://developer.arm.com/documentation/ddi0601/2025-09/AArch64-Registers/TPIDR2-EL0--EL0-Read-Write-Software-Thread-ID-Register-2?lang=en [2] https://developer.arm.com/documentation/ddi0601/2025-09/AArch64-Registers/SMCR-EL3--SME-Control-Register--EL3-?lang=en [3] llvm/llvm-project@2b05fa8
1 parent 2f3ed7f commit f99c303

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
From 4bbe72b4dc2215e1799f3cff9054e3c8bfff253e Mon Sep 17 00:00:00 2001
2+
From: Amilendra Kodithuwakku <[email protected]>
3+
Date: Thu, 29 Jan 2026 16:45:01 +0000
4+
Subject: [PATCH] [picolibc][SME] Initialize SME during C-runtime
5+
initialization (crt0)
6+
7+
Check if SME or SME2 is enabled and do the following
8+
9+
1. Clear TPIDR2_EL0 [1]
10+
The value of TPIDR2_EL0 resets to an architecturally UNKNOWN value
11+
at warm reset.
12+
This means we need to clear it manually at startup.
13+
14+
2. Initialise SME Streaming SVE Vector length to 2048 bits
15+
Initialize the SME control register SMCR_EL3 [2] to set the
16+
effective streaming SVE vector length to the maximum supported
17+
value of 2048 bits.
18+
19+
[1] https://developer.arm.com/documentation/ddi0601/2025-09/AArch64-Registers/TPIDR2-EL0--EL0-Read-Write-Software-Thread-ID-Register-2?lang=en
20+
[2] https://developer.arm.com/documentation/ddi0601/2025-09/AArch64-Registers/SMCR-EL3--SME-Control-Register--EL3-?lang=en
21+
---
22+
picocrt/machine/aarch64/crt0.S | 23 +++++++++++++++++++++++
23+
1 file changed, 23 insertions(+)
24+
25+
diff --git a/picocrt/machine/aarch64/crt0.S b/picocrt/machine/aarch64/crt0.S
26+
index 831a57677..4e4dc5942 100644
27+
--- a/picocrt/machine/aarch64/crt0.S
28+
+++ b/picocrt/machine/aarch64/crt0.S
29+
@@ -40,6 +40,9 @@
30+
31+
#define MMU_INVALID_FLAGS 0
32+
33+
+#define FEAT_SME_1 (1LL << 24)
34+
+#define FEAT_SME_2 (1LL << 25)
35+
+
36+
.macro start_page_table
37+
.section .rodata
38+
.global __identity_page_table
39+
@@ -136,6 +139,26 @@ _start:
40+
#endif
41+
#endif // __ARM_FP
42+
43+
+ /* Determine if SME or SME2 is available */
44+
+ mrs x0, id_aa64pfr1_el1
45+
+ tst x0, (FEAT_SME_1|FEAT_SME_2)
46+
+ b.eq .Lnosme
47+
+
48+
+ /* Clear TPIDR2_EL0 */
49+
+ msr S3_3_C13_C0_5, xzr
50+
+ isb
51+
+
52+
+ /* set up Streaming SVE Vector Length (SVL) in SMCR_EL3 (4 LSB). */
53+
+ mov x2, #0xF
54+
+
55+
+ /* Try to set the maximum value supported by the architecture (2048). */
56+
+ mrs x1, s3_6_c1_c2_6 /* mrs x1, smcr_el3 */
57+
+ bfi x1, x2, 0, 4
58+
+ msr s3_6_c1_c2_6, x1 /* msr smcr_el3, x1 */
59+
+ isb
60+
+
61+
+.Lnosme:
62+
+
63+
/* Jump into C code */
64+
bl _cstart
65+
.size _start, .-_start
66+
--
67+
2.34.1
68+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From 328e99571dc59093dd0dfd7a73707abd651f69ad Mon Sep 17 00:00:00 2001
2+
From: Amilendra Kodithuwakku <[email protected]>
3+
Date: Thu, 29 Jan 2026 09:19:13 +0000
4+
Subject: [PATCH] [picolibc][SME] Add implementation of the
5+
__aarch64_sme_accessible
6+
7+
compiler-rt relies on the the __aarch64_sme_accessible support
8+
function to emit SME ABI support routines calls [1].
9+
__aarch64_sme_accessible returns non-zero when SME support is
10+
enabled in the underlying hardware.
11+
12+
[1] https://github.com/llvm/llvm-project/commit/2b05fa8f0be7e38f4b4364ea855a3d200ded7480
13+
---
14+
picocrt/machine/aarch64/crt0.c | 8 ++++++++
15+
1 file changed, 8 insertions(+)
16+
17+
diff --git a/picocrt/machine/aarch64/crt0.c b/picocrt/machine/aarch64/crt0.c
18+
index 41b90545f..95d37a323 100644
19+
--- a/picocrt/machine/aarch64/crt0.c
20+
+++ b/picocrt/machine/aarch64/crt0.c
21+
@@ -60,6 +60,14 @@ _set_tls(void *tls)
22+
__asm__ volatile("msr tpidr_el0, %x0" : : "r"(tls - TP_OFFSET));
23+
}
24+
25+
+int __aarch64_sme_accessible() {
26+
+ int result = 0;
27+
+ __asm__ volatile ("mrs %x[result], id_aa64pfr1_el1" : [result]"=r"(result) : : );
28+
+ /* Although the ISA reserves BITS 24~27 for SME, at this point of time,
29+
+ only BITS 24 (SME) and 25 (SME + SME2 ZT0 register) have meaning.*/
30+
+ return (result & 0x3000000) != 0;
31+
+}
32+
+
33+
#include "../../crt0.h"
34+
35+
/* Defined in crt0.S */
36+
--
37+
2.34.1
38+

0 commit comments

Comments
 (0)