1 // Copyright 2024 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 #include "go_asm.h"
6 #include "textflag.h"
7
8 TEXT ·EnableDIT(SB),$0-1
9 MRS DIT, R0
10 UBFX $24, R0, $1, R1
11 MOVB R1, ret+0(FP)
12 TBNZ $0, R1, ret
13 MSR $1, DIT
14 #ifdef GOOS_darwin
15 // Arm documents that barriers are not necessary when writing to, or reading
16 // from, PSTATE fields. However, Apple documentation indicates that barriers
17 // should be used, in particular when setting the PSTATE.DIT field. Barriers
18 // aren't cheap, so only use them on Apple silicon for now.
19 //
20 // See go.dev/issue/77776.
21 MOVBU internal∕cpu·ARM64+const_offsetARM64HasSB(SB), R2
22 TBZ $0, R2, sbFallback
23 SB
24 #endif
25 ret:
26 RET
27 sbFallback:
28 DSB $7 // nsh
29 ISB $15 // sy
30 RET
31
32 TEXT ·DITEnabled(SB),$0-1
33 MRS DIT, R0
34 UBFX $24, R0, $1, R1
35 MOVB R1, ret+0(FP)
36 RET
37
38 TEXT ·DisableDIT(SB),$0
39 MSR $0, DIT
40 RET
41
View as plain text