| 1 |
/* Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 2 |
Contributed by Richard Henderson <[email protected]>. |
| 3 |
|
| 4 |
This file is part of the GNU Transactional Memory Library (libitm). |
| 5 |
|
| 6 |
Libitm is free software; you can redistribute it and/or modify it |
| 7 |
under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
Libitm is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 |
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 "asmcfi.h" |
| 26 |
|
| 27 |
#define BTI_C hint 34 |
| 28 |
#define PACIASP hint 25 |
| 29 |
#define AUTIASP hint 29 |
| 30 |
#define PACIBSP hint 27 |
| 31 |
#define AUTIBSP hint 31 |
| 32 |
|
| 33 |
#if defined(HAVE_AS_CFI_PSEUDO_OP) && defined(__GCC_HAVE_DWARF2_CFI_ASM) |
| 34 |
# define cfi_negate_ra_state .cfi_negate_ra_state |
| 35 |
# define cfi_b_key_frame .cfi_b_key_frame |
| 36 |
#else |
| 37 |
# define cfi_negate_ra_state |
| 38 |
# define cfi_b_key_frame |
| 39 |
#endif |
| 40 |
|
| 41 |
#if __ARM_FEATURE_PAC_DEFAULT & 1 |
| 42 |
# define CFI_PAC_TOGGLE cfi_negate_ra_state |
| 43 |
# define CFI_PAC_KEY |
| 44 |
# define PAC_AND_BTI PACIASP |
| 45 |
# define AUT AUTIASP |
| 46 |
#elif __ARM_FEATURE_PAC_DEFAULT & 2 |
| 47 |
# define CFI_PAC_TOGGLE cfi_negate_ra_state |
| 48 |
# define CFI_PAC_KEY cfi_b_key_frame |
| 49 |
# define PAC_AND_BTI PACIBSP |
| 50 |
# define AUT AUTIBSP |
| 51 |
#else |
| 52 |
# define CFI_PAC_TOGGLE |
| 53 |
# define CFI_PAC_KEY |
| 54 |
# define PAC_AND_BTI BTI_C |
| 55 |
# define AUT |
| 56 |
#endif |
| 57 |
|
| 58 |
.text |
| 59 |
.align 2 |
| 60 |
.global _ITM_beginTransaction |
| 61 |
.type _ITM_beginTransaction, %function |
| 62 |
|
| 63 |
_ITM_beginTransaction: |
| 64 |
cfi_startproc |
| 65 |
CFI_PAC_KEY |
| 66 |
PAC_AND_BTI |
| 67 |
CFI_PAC_TOGGLE |
| 68 |
mov x1, sp |
| 69 |
stp x29, x30, [sp, -11*16]! |
| 70 |
cfi_adjust_cfa_offset(11*16) |
| 71 |
cfi_rel_offset(x29, 0) |
| 72 |
cfi_rel_offset(x30, 8) |
| 73 |
mov x29, sp |
| 74 |
stp x19, x20, [sp, 1*16] |
| 75 |
stp x21, x22, [sp, 2*16] |
| 76 |
stp x23, x24, [sp, 3*16] |
| 77 |
stp x25, x26, [sp, 4*16] |
| 78 |
stp x27, x28, [sp, 5*16] |
| 79 |
stp d8, d9, [sp, 6*16] |
| 80 |
stp d10, d11, [sp, 7*16] |
| 81 |
stp d12, d13, [sp, 8*16] |
| 82 |
stp d14, d15, [sp, 9*16] |
| 83 |
str x1, [sp, 10*16] |
| 84 |
|
| 85 |
/* Invoke GTM_begin_transaction with the struct we just built. */ |
| 86 |
mov x1, sp |
| 87 |
bl GTM_begin_transaction |
| 88 |
|
| 89 |
/* Return; we don't need to restore any of the call-saved regs. */ |
| 90 |
ldp x29, x30, [sp], 11*16 |
| 91 |
cfi_adjust_cfa_offset(-11*16) |
| 92 |
cfi_restore(x29) |
| 93 |
cfi_restore(x30) |
| 94 |
AUT |
| 95 |
CFI_PAC_TOGGLE |
| 96 |
ret |
| 97 |
cfi_endproc |
| 98 |
.size _ITM_beginTransaction, . - _ITM_beginTransaction |
| 99 |
|
| 100 |
.align 2 |
| 101 |
.global GTM_longjmp |
| 102 |
.hidden GTM_longjmp |
| 103 |
.type GTM_longjmp, %function |
| 104 |
|
| 105 |
GTM_longjmp: |
| 106 |
/* The first parameter becomes the return value (x0). |
| 107 |
The third parameter is ignored for now. */ |
| 108 |
cfi_startproc |
| 109 |
CFI_PAC_KEY |
| 110 |
BTI_C |
| 111 |
ldp x19, x20, [x1, 1*16] |
| 112 |
ldp x21, x22, [x1, 2*16] |
| 113 |
ldp x23, x24, [x1, 3*16] |
| 114 |
ldp x25, x26, [x1, 4*16] |
| 115 |
ldp x27, x28, [x1, 5*16] |
| 116 |
ldp d8, d9, [x1, 6*16] |
| 117 |
ldp d10, d11, [x1, 7*16] |
| 118 |
ldp d12, d13, [x1, 8*16] |
| 119 |
ldp d14, d15, [x1, 9*16] |
| 120 |
ldr x3, [x1, 10*16] |
| 121 |
ldp x29, x30, [x1] |
| 122 |
cfi_def_cfa(x1, 0) |
| 123 |
CFI_PAC_TOGGLE |
| 124 |
mov sp, x3 |
| 125 |
AUT |
| 126 |
CFI_PAC_TOGGLE |
| 127 |
br x30 |
| 128 |
cfi_endproc |
| 129 |
.size GTM_longjmp, . - GTM_longjmp |
| 130 |
|
| 131 |
/* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ |
| 132 |
#define FEATURE_1_AND 0xc0000000 |
| 133 |
#define FEATURE_1_BTI 1 |
| 134 |
#define FEATURE_1_PAC 2 |
| 135 |
|
| 136 |
/* Supported features based on the code generation options. */ |
| 137 |
#if defined(__ARM_FEATURE_BTI_DEFAULT) |
| 138 |
# define BTI_FLAG FEATURE_1_BTI |
| 139 |
#else |
| 140 |
# define BTI_FLAG 0 |
| 141 |
#endif |
| 142 |
|
| 143 |
#if __ARM_FEATURE_PAC_DEFAULT & 3 |
| 144 |
# define PAC_FLAG FEATURE_1_PAC |
| 145 |
#else |
| 146 |
# define PAC_FLAG 0 |
| 147 |
#endif |
| 148 |
|
| 149 |
/* Add a NT_GNU_PROPERTY_TYPE_0 note. */ |
| 150 |
#define GNU_PROPERTY(type, value) \ |
| 151 |
.section .note.gnu.property, "a"; \ |
| 152 |
.p2align 3; \ |
| 153 |
.word 4; \ |
| 154 |
.word 16; \ |
| 155 |
.word 5; \ |
| 156 |
.asciz "GNU"; \ |
| 157 |
.word type; \ |
| 158 |
.word 4; \ |
| 159 |
.word value; \ |
| 160 |
.word 0; |
| 161 |
|
| 162 |
#if defined(__linux__) || defined(__FreeBSD__) |
| 163 |
.section .note.GNU-stack, "", %progbits |
| 164 |
|
| 165 |
/* Add GNU property note if built with branch protection. */ |
| 166 |
# if (BTI_FLAG|PAC_FLAG) != 0 |
| 167 |
GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG) |
| 168 |
# endif |
| 169 |
#endif |