|
| 1 | +#include "../assembly.h" |
| 2 | + |
| 3 | +.arch armv8-a+sme2 |
| 4 | + |
| 5 | +// For Apple platforms at the moment, we just call abort() directly |
| 6 | +// after stopping SM mode unconditionally. |
| 7 | +.p2align 2 |
| 8 | +DEFINE_COMPILERRT_PRIVATE_FUNCTION(do_abort) |
| 9 | +.cfi_startproc |
| 10 | + .variant_pcs SYMBOL_NAME(do_abort) |
| 11 | + stp x29, x30, [sp, #-32]! |
| 12 | + .cfi_def_cfa_offset 32 |
| 13 | + .cfi_offset w30, -24 |
| 14 | + .cfi_offset w29, -32 |
| 15 | + smstop sm |
| 16 | + bl SYMBOL_NAME(abort) |
| 17 | +.cfi_endproc |
| 18 | +END_COMPILERRT_FUNCTION(do_abort) |
| 19 | + |
| 20 | +DEFINE_COMPILERRT_FUNCTION(__arm_tpidr2_save) |
| 21 | + // If TPIDR2_EL0 is null, the subroutine does nothing. |
| 22 | + mrs x16, TPIDR2_EL0 |
| 23 | + cbz x16, 1f |
| 24 | + |
| 25 | + // If any of the reserved bytes in the first 16 bytes of the TPIDR2 block are |
| 26 | + // nonzero, the subroutine [..] aborts in some platform-defined manner. |
| 27 | + ldrh w14, [x16, #10] |
| 28 | + cbnz w14, 2f |
| 29 | + ldr w14, [x16, #12] |
| 30 | + cbnz w14, 2f |
| 31 | + |
| 32 | + // If za_save_buffer is NULL, the subroutine does nothing. |
| 33 | + ldr x14, [x16] |
| 34 | + cbz x14, 1f |
| 35 | + |
| 36 | + // If num_za_save_slices is zero, the subroutine does nothing. |
| 37 | + ldrh w14, [x16, #8] |
| 38 | + cbz x14, 1f |
| 39 | + |
| 40 | + mov x15, xzr |
| 41 | + ldr x16, [x16] |
| 42 | +0: |
| 43 | + str za[w15,0], [x16] |
| 44 | + addsvl x16, x16, #1 |
| 45 | + add x15, x15, #1 |
| 46 | + cmp x14, x15 |
| 47 | + b.ne 0b |
| 48 | +1: |
| 49 | + ret |
| 50 | +2: |
| 51 | + b SYMBOL_NAME(do_abort) |
| 52 | +END_COMPILERRT_FUNCTION(__arm_tpidr2_save) |
| 53 | + |
| 54 | +.p2align 2 |
| 55 | +DEFINE_COMPILERRT_FUNCTION(__arm_za_disable) |
| 56 | +.cfi_startproc |
| 57 | + // Otherwise, the subroutine behaves as if it did the following: |
| 58 | + // * Call __arm_tpidr2_save. |
| 59 | + stp x29, x30, [sp, #-16]! |
| 60 | + .cfi_def_cfa_offset 16 |
| 61 | + mov x29, sp |
| 62 | + .cfi_def_cfa w29, 16 |
| 63 | + .cfi_offset w30, -8 |
| 64 | + .cfi_offset w29, -16 |
| 65 | + bl SYMBOL_NAME(__arm_tpidr2_save) |
| 66 | + |
| 67 | + // * Set TPIDR2_EL0 to null. |
| 68 | + msr TPIDR2_EL0, xzr |
| 69 | + |
| 70 | + // * Set PSTATE.ZA to 0. |
| 71 | + smstop za |
| 72 | + |
| 73 | + .cfi_def_cfa wsp, 16 |
| 74 | + ldp x29, x30, [sp], #16 |
| 75 | + .cfi_def_cfa_offset 0 |
| 76 | + .cfi_restore w30 |
| 77 | + .cfi_restore w29 |
| 78 | +0: |
| 79 | + ret |
| 80 | +.cfi_endproc |
| 81 | +END_COMPILERRT_FUNCTION(__arm_za_disable) |
| 82 | + |
| 83 | +.p2align 2 |
| 84 | +DEFINE_COMPILERRT_FUNCTION(__arm_tpidr2_restore) |
| 85 | +.cfi_startproc |
| 86 | + .variant_pcs SYMBOL_NAME(__arm_tpidr2_restore) |
| 87 | + // If TPIDR2_EL0 is nonnull, the subroutine aborts in some platform-specific |
| 88 | + // manner. |
| 89 | + mrs x14, TPIDR2_EL0 |
| 90 | + cbnz x14, 2f |
| 91 | + |
| 92 | + // If any of the reserved bytes in the first 16 bytes of BLK are nonzero, |
| 93 | + // the subroutine [..] aborts in some platform-defined manner. |
| 94 | + ldrh w14, [x0, #10] |
| 95 | + cbnz w14, 2f |
| 96 | + ldr w14, [x0, #12] |
| 97 | + cbnz w14, 2f |
| 98 | + |
| 99 | + // If BLK.za_save_buffer is NULL, the subroutine does nothing. |
| 100 | + ldr x16, [x0] |
| 101 | + cbz x16, 1f |
| 102 | + |
| 103 | + // If BLK.num_za_save_slices is zero, the subroutine does nothing. |
| 104 | + ldrh w14, [x0, #8] |
| 105 | + cbz x14, 1f |
| 106 | + |
| 107 | + mov x15, xzr |
| 108 | +0: |
| 109 | + ldr za[w15,0], [x16] |
| 110 | + addsvl x16, x16, #1 |
| 111 | + add x15, x15, #1 |
| 112 | + cmp x14, x15 |
| 113 | + b.ne 0b |
| 114 | +1: |
| 115 | + ret |
| 116 | +2: |
| 117 | + b SYMBOL_NAME(do_abort) |
| 118 | +.cfi_endproc |
| 119 | +END_COMPILERRT_FUNCTION(__arm_tpidr2_restore) |
| 120 | + |
| 121 | +.p2align 2 |
| 122 | +DEFINE_COMPILERRT_FUNCTION(__arm_sme_state) |
| 123 | + .variant_pcs SYMBOL_NAME(__arm_sme_state) |
| 124 | + orr x0, x0, #0xC000000000000000 |
| 125 | + mrs x16, SVCR |
| 126 | + bfxil x0, x16, #0, #2 |
| 127 | + mrs x1, TPIDR2_EL0 |
| 128 | + ret |
| 129 | +END_COMPILERRT_FUNCTION(__arm_sme_state) |
0 commit comments