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 //go:build goexperiment.runtimesecret
6
7 // Note: this assembly file is used for testing only.
8 // We need to access registers directly to properly test
9 // that secrets are erased and go test doesn't like to conditionally
10 // include assembly files.
11 // These functions defined in the package proper and we
12 // rely on the linker to prune these away in regular builds
13
14 #include "go_asm.h"
15 #include "funcdata.h"
16
17 TEXT ·loadRegisters(SB),0,$0-8
18 MOVD p+0(FP), R0
19
20 MOVD (R0), R10
21 MOVD (R0), R11
22 MOVD (R0), R12
23 MOVD (R0), R13
24
25 FMOVD (R0), F15
26 FMOVD (R0), F16
27 FMOVD (R0), F17
28 FMOVD (R0), F18
29
30 VLD1 (R0), [V20.B16]
31 VLD1 (R0), [V21.H8]
32 VLD1 (R0), [V22.S4]
33 VLD1 (R0), [V23.D2]
34
35 RET
36
37 TEXT ·spillRegisters(SB),0,$0-16
38 MOVD p+0(FP), R0
39 MOVD R0, R1
40
41 MOVD R10, (R0)
42 MOVD R11, 8(R0)
43 MOVD R12, 16(R0)
44 MOVD R13, 24(R0)
45 ADD $32, R0
46
47 FMOVD F15, (R0)
48 FMOVD F16, 16(R0)
49 FMOVD F17, 32(R0)
50 FMOVD F18, 64(R0)
51 ADD $64, R0
52
53 VST1.P [V20.B16], (R0)
54 VST1.P [V21.H8], (R0)
55 VST1.P [V22.S4], (R0)
56 VST1.P [V23.D2], (R0)
57
58 SUB R1, R0, R0
59 MOVD R0, ret+8(FP)
60 RET
61
62 TEXT ·useSecret(SB),0,$0-24
63 NO_LOCAL_POINTERS
64
65 // Load secret into R0
66 MOVD secret_base+0(FP), R0
67 MOVD (R0), R0
68 // Scatter secret across registers.
69 // Increment low byte so we can tell which register
70 // a leaking secret came from.
71
72 // TODO(dmo): more substantial dirtying here
73 ADD $1, R0
74 MOVD R0, R1
75 ADD $1, R0
76 MOVD R0, R2
77 ADD $1, R0
78 MOVD R0, R3
79 ADD $1, R0
80 MOVD R0, R4
81 ADD $1, R0
82 MOVD R0, R5
83 ADD $1, R0
84 MOVD R0, R6
85 ADD $1, R0
86 MOVD R0, R7
87 ADD $1, R0
88 MOVD R0, R8
89 ADD $1, R0
90 MOVD R0, R9
91 ADD $1, R0
92 MOVD R0, R10
93 ADD $1, R0
94 MOVD R0, R11
95 ADD $1, R0
96 MOVD R0, R12
97 ADD $1, R0
98 MOVD R0, R13
99 ADD $1, R0
100 MOVD R0, R14
101 ADD $1, R0
102 MOVD R0, R15
103
104 // Dirty the floating point registers
105 ADD $1, R0
106 FMOVD R0, F0
107 ADD $1, R0
108 FMOVD R0, F1
109 ADD $1, R0
110 FMOVD R0, F2
111 ADD $1, R0
112 FMOVD R0, F3
113 ADD $1, R0
114 FMOVD R0, F4
115 ADD $1, R0
116 FMOVD R0, F5
117 ADD $1, R0
118 FMOVD R0, F6
119 ADD $1, R0
120 FMOVD R0, F7
121 ADD $1, R0
122 FMOVD R0, F8
123 ADD $1, R0
124 FMOVD R0, F9
125 ADD $1, R0
126 FMOVD R0, F10
127 ADD $1, R0
128 FMOVD R0, F11
129 ADD $1, R0
130 FMOVD R0, F12
131 ADD $1, R0
132 FMOVD R0, F13
133 ADD $1, R0
134 FMOVD R0, F14
135 ADD $1, R0
136 FMOVD R0, F15
137 ADD $1, R0
138 FMOVD R0, F16
139 ADD $1, R0
140 FMOVD R0, F17
141 ADD $1, R0
142 FMOVD R0, F18
143 ADD $1, R0
144 FMOVD R0, F19
145 ADD $1, R0
146 FMOVD R0, F20
147 ADD $1, R0
148 FMOVD R0, F21
149 ADD $1, R0
150 FMOVD R0, F22
151 ADD $1, R0
152 FMOVD R0, F23
153 ADD $1, R0
154 FMOVD R0, F24
155 ADD $1, R0
156 FMOVD R0, F25
157 ADD $1, R0
158 FMOVD R0, F26
159 ADD $1, R0
160 FMOVD R0, F27
161 ADD $1, R0
162 FMOVD R0, F28
163 ADD $1, R0
164 FMOVD R0, F29
165 ADD $1, R0
166 FMOVD R0, F30
167 ADD $1, R0
168 FMOVD R0, F31
169 RET
170
View as plain text