| 1 |
/* Support routine for SME. |
| 2 |
Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify it |
| 7 |
under the terms of the GNU General Public License as published |
| 8 |
by the Free Software Foundation; either version 3, or (at your |
| 9 |
option) any later version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, but WITHOUT |
| 12 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 14 |
License for more details. |
| 15 |
|
| 16 |
Under Section 7 of GPL version 3, you are granted additional |
| 17 |
permissions described in the GCC Runtime Library Exception, version |
| 18 |
3.1, as published by the Free Software Foundation. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License and |
| 21 |
a copy of the GCC Runtime Library Exception along with this program; |
| 22 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 23 |
<http://www.gnu.org/licenses/>. */ |
| 24 |
|
| 25 |
#include "aarch64-asm.h" |
| 26 |
|
| 27 |
/* Used for lazy ZA save. Call ABI: |
| 28 |
- Private ZA, streaming-compatible. |
| 29 |
- x0-x13, x19-x29, sp and fp regs are call preserved. |
| 30 |
- Takes no argument. |
| 31 |
- Does not return a value. |
| 32 |
- Can abort on failure (then registers are not preserved). */ |
| 33 |
|
| 34 |
HIDDEN (__aarch64_have_sme) |
| 35 |
|
| 36 |
variant_pcs (__arm_tpidr2_save) |
| 37 |
|
| 38 |
ENTRY (__arm_tpidr2_save) |
| 39 |
/* Check if SME is available. */ |
| 40 |
adrp x14, __aarch64_have_sme |
| 41 |
ldrb w14, [x14, :lo12:__aarch64_have_sme] |
| 42 |
cbz w14, L(end) |
| 43 |
|
| 44 |
.inst 0xd53bd0ae /* mrs x14, tpidr2_el0 */ |
| 45 |
cbz x14, L(end) |
| 46 |
|
| 47 |
/* check reserved bytes. */ |
| 48 |
ldrh w15, [x14, 10] |
| 49 |
ldr w16, [x14, 12] |
| 50 |
orr w15, w15, w16 |
| 51 |
cbnz w15, L(fail) |
| 52 |
|
| 53 |
ldr x16, [x14] |
| 54 |
cbz x16, L(end) |
| 55 |
ldrh w17, [x14, 8] |
| 56 |
cbz w17, L(end) |
| 57 |
|
| 58 |
/* x14: tpidr2, x15: 0, |
| 59 |
x16: za_save_buffer, x17: num_za_save_slices. */ |
| 60 |
|
| 61 |
L(save_loop): |
| 62 |
.inst 0xe1206200 /* str za[w15, 0], [x16] */ |
| 63 |
.inst 0xe1206201 /* str za[w15, 1], [x16, 1, mul vl] */ |
| 64 |
.inst 0xe1206202 /* str za[w15, 2], [x16, 2, mul vl] */ |
| 65 |
.inst 0xe1206203 /* str za[w15, 3], [x16, 3, mul vl] */ |
| 66 |
.inst 0xe1206204 /* str za[w15, 4], [x16, 4, mul vl] */ |
| 67 |
.inst 0xe1206205 /* str za[w15, 5], [x16, 5, mul vl] */ |
| 68 |
.inst 0xe1206206 /* str za[w15, 6], [x16, 6, mul vl] */ |
| 69 |
.inst 0xe1206207 /* str za[w15, 7], [x16, 7, mul vl] */ |
| 70 |
.inst 0xe1206208 /* str za[w15, 8], [x16, 8, mul vl] */ |
| 71 |
.inst 0xe1206209 /* str za[w15, 9], [x16, 9, mul vl] */ |
| 72 |
.inst 0xe120620a /* str za[w15, 10], [x16, 10, mul vl] */ |
| 73 |
.inst 0xe120620b /* str za[w15, 11], [x16, 11, mul vl] */ |
| 74 |
.inst 0xe120620c /* str za[w15, 12], [x16, 12, mul vl] */ |
| 75 |
.inst 0xe120620d /* str za[w15, 13], [x16, 13, mul vl] */ |
| 76 |
.inst 0xe120620e /* str za[w15, 14], [x16, 14, mul vl] */ |
| 77 |
.inst 0xe120620f /* str za[w15, 15], [x16, 15, mul vl] */ |
| 78 |
add w15, w15, 16 |
| 79 |
.inst 0x04305a10 /* addsvl x16, x16, 16 */ |
| 80 |
cmp w17, w15 |
| 81 |
bhi L(save_loop) |
| 82 |
L(end): |
| 83 |
ret |
| 84 |
L(fail): |
| 85 |
PACIASP |
| 86 |
stp x29, x30, [sp, -32]! |
| 87 |
.cfi_adjust_cfa_offset 32 |
| 88 |
.cfi_rel_offset x29, 0 |
| 89 |
.cfi_rel_offset x30, 8 |
| 90 |
mov x29, sp |
| 91 |
.inst 0x04e0e3f0 /* cntd x16 */ |
| 92 |
str x16, [sp, 16] |
| 93 |
.cfi_rel_offset 46, 16 |
| 94 |
.inst 0xd503467f /* smstop */ |
| 95 |
bl abort |
| 96 |
END (__arm_tpidr2_save) |
| 97 |
|
| 98 |
/* Hidden alias used by __arm_za_disable. */ |
| 99 |
.global __libgcc_arm_tpidr2_save |
| 100 |
HIDDEN (__libgcc_arm_tpidr2_save) |
| 101 |
.set __libgcc_arm_tpidr2_save, __arm_tpidr2_save |