ppc: remove incomplete undef list
[librseq.git] / include / rseq / rseq-ppc.h
CommitLineData
744d0b8b 1/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
784b0012
MD
2/*
3 * rseq-ppc.h
4 *
5 * (C) Copyright 2016-2018 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * (C) Copyright 2016-2018 - Boqun Feng <boqun.feng@gmail.com>
7 */
8
0158e666
MD
9/*
10 * RSEQ_SIG is used with the following trap instruction:
11 *
12 * powerpc-be: 0f e5 00 0b twui r5,11
13 * powerpc64-le: 0b 00 e5 0f twui r5,11
14 * powerpc64-be: 0f e5 00 0b twui r5,11
15 */
16
17#define RSEQ_SIG 0x0fe5000b
784b0012
MD
18
19#define rseq_smp_mb() __asm__ __volatile__ ("sync" ::: "memory", "cc")
20#define rseq_smp_lwsync() __asm__ __volatile__ ("lwsync" ::: "memory", "cc")
21#define rseq_smp_rmb() rseq_smp_lwsync()
22#define rseq_smp_wmb() rseq_smp_lwsync()
23
24#define rseq_smp_load_acquire(p) \
25__extension__ ({ \
26 __typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \
27 rseq_smp_lwsync(); \
28 ____p1; \
29})
30
31#define rseq_smp_acquire__after_ctrl_dep() rseq_smp_lwsync()
32
33#define rseq_smp_store_release(p, v) \
34do { \
35 rseq_smp_lwsync(); \
36 RSEQ_WRITE_ONCE(*p, v); \
37} while (0)
38
39#ifdef RSEQ_SKIP_FASTPATH
40#include "rseq-skip.h"
41#else /* !RSEQ_SKIP_FASTPATH */
42
43/*
dd01d0fb
MD
44 * The __rseq_cs_ptr_array and __rseq_cs sections can be used by debuggers to
45 * better handle single-stepping through the restartable critical sections.
784b0012
MD
46 */
47
48#ifdef __PPC64__
49
a799a7ba
MD
50#define RSEQ_STORE_LONG(arg) "std%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */
51#define RSEQ_STORE_INT(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */
52#define RSEQ_LOAD_LONG(arg) "ld%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */
53#define RSEQ_LOAD_INT(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */
54#define RSEQ_LOADX_LONG "ldx " /* From base register ("b" constraint) */
55#define RSEQ_CMP_LONG "cmpd "
d0c21ef2 56#define RSEQ_CMP_LONG_INT "cmpdi "
784b0012 57
9b1975bf
MD
58#define RSEQ_CS_PTR rseq_cs.ptr
59
784b0012
MD
60#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
61 start_ip, post_commit_offset, abort_ip) \
dd01d0fb 62 ".pushsection __rseq_cs, \"aw\"\n\t" \
784b0012
MD
63 ".balign 32\n\t" \
64 __rseq_str(label) ":\n\t" \
65 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
66 ".quad " __rseq_str(start_ip) ", " __rseq_str(post_commit_offset) ", " __rseq_str(abort_ip) "\n\t" \
dd01d0fb
MD
67 ".popsection\n\t" \
68 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
69 ".quad " __rseq_str(label) "b\n\t" \
784b0012
MD
70 ".popsection\n\t"
71
72#define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
73 RSEQ_INJECT_ASM(1) \
74 "lis %%r17, (" __rseq_str(cs_label) ")@highest\n\t" \
75 "ori %%r17, %%r17, (" __rseq_str(cs_label) ")@higher\n\t" \
76 "rldicr %%r17, %%r17, 32, 31\n\t" \
77 "oris %%r17, %%r17, (" __rseq_str(cs_label) ")@high\n\t" \
78 "ori %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \
79 "std %%r17, %[" __rseq_str(rseq_cs) "]\n\t" \
80 __rseq_str(label) ":\n\t"
81
90d9876e
MD
82/*
83 * Exit points of a rseq critical section consist of all instructions outside
fd622cad
MD
84 * of the critical section where a critical section can either branch to or
85 * reach through the normal course of its execution. The abort IP and the
86 * post-commit IP are already part of the __rseq_cs section and should not be
87 * explicitly defined as additional exit points. Knowing all exit points is
88 * useful to assist debuggers stepping over the critical section.
90d9876e
MD
89 */
90#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
91 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
92 ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n\t" \
93 ".popsection\n\t"
94
784b0012
MD
95#else /* #ifdef __PPC64__ */
96
a799a7ba
MD
97#define RSEQ_STORE_LONG(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */
98#define RSEQ_STORE_INT(arg) RSEQ_STORE_LONG(arg) /* To memory ("m" constraint) */
99#define RSEQ_LOAD_LONG(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */
100#define RSEQ_LOAD_INT(arg) RSEQ_LOAD_LONG(arg) /* From memory ("m" constraint) */
101#define RSEQ_LOADX_LONG "lwzx " /* From base register ("b" constraint) */
102#define RSEQ_CMP_LONG "cmpw "
d0c21ef2 103#define RSEQ_CMP_LONG_INT "cmpwi "
784b0012 104
9b1975bf
MD
105#define RSEQ_CS_PTR rseq_cs.ptr.ptr32
106
784b0012
MD
107#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
108 start_ip, post_commit_offset, abort_ip) \
dd01d0fb 109 ".pushsection __rseq_cs, \"aw\"\n\t" \
784b0012
MD
110 ".balign 32\n\t" \
111 __rseq_str(label) ":\n\t" \
112 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
113 /* 32-bit only supported on BE */ \
114 ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) "\n\t" \
dd01d0fb
MD
115 ".popsection\n\t" \
116 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
117 ".long 0x0, " __rseq_str(label) "b\n\t" \
784b0012
MD
118 ".popsection\n\t"
119
90d9876e
MD
120/*
121 * Exit points of a rseq critical section consist of all instructions outside
fd622cad
MD
122 * of the critical section where a critical section can either branch to or
123 * reach through the normal course of its execution. The abort IP and the
124 * post-commit IP are already part of the __rseq_cs section and should not be
125 * explicitly defined as additional exit points. Knowing all exit points is
126 * useful to assist debuggers stepping over the critical section.
90d9876e
MD
127 */
128#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
129 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
130 /* 32-bit only supported on BE */ \
131 ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(exit_ip) "\n\t" \
132 ".popsection\n\t"
133
784b0012
MD
134#define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
135 RSEQ_INJECT_ASM(1) \
136 "lis %%r17, (" __rseq_str(cs_label) ")@ha\n\t" \
137 "addi %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \
a799a7ba 138 RSEQ_STORE_INT(rseq_cs) "%%r17, %[" __rseq_str(rseq_cs) "]\n\t" \
784b0012
MD
139 __rseq_str(label) ":\n\t"
140
141#endif /* #ifdef __PPC64__ */
142
143#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
144 __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
145 (post_commit_ip - start_ip), abort_ip)
146
147#define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \
148 RSEQ_INJECT_ASM(2) \
a799a7ba 149 RSEQ_LOAD_INT(current_cpu_id) "%%r17, %[" __rseq_str(current_cpu_id) "]\n\t" \
784b0012
MD
150 "cmpw cr7, %[" __rseq_str(cpu_id) "], %%r17\n\t" \
151 "bne- cr7, " __rseq_str(label) "\n\t"
152
153#define RSEQ_ASM_DEFINE_ABORT(label, abort_label) \
154 ".pushsection __rseq_failure, \"ax\"\n\t" \
155 ".long " __rseq_str(RSEQ_SIG) "\n\t" \
156 __rseq_str(label) ":\n\t" \
157 "b %l[" __rseq_str(abort_label) "]\n\t" \
158 ".popsection\n\t"
159
160/*
161 * RSEQ_ASM_OPs: asm operations for rseq
162 * RSEQ_ASM_OP_R_*: has hard-code registers in it
163 * RSEQ_ASM_OP_* (else): doesn't have hard-code registers(unless cr7)
164 */
165#define RSEQ_ASM_OP_CMPEQ(var, expect, label) \
a799a7ba
MD
166 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
167 RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expect) "]\n\t" \
784b0012
MD
168 "bne- cr7, " __rseq_str(label) "\n\t"
169
170#define RSEQ_ASM_OP_CMPNE(var, expectnot, label) \
a799a7ba
MD
171 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
172 RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expectnot) "]\n\t" \
784b0012
MD
173 "beq- cr7, " __rseq_str(label) "\n\t"
174
175#define RSEQ_ASM_OP_STORE(value, var) \
a799a7ba 176 RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t"
784b0012
MD
177
178/* Load @var to r17 */
179#define RSEQ_ASM_OP_R_LOAD(var) \
a799a7ba 180 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t"
784b0012
MD
181
182/* Store r17 to @var */
183#define RSEQ_ASM_OP_R_STORE(var) \
a799a7ba 184 RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t"
784b0012
MD
185
186/* Add @count to r17 */
187#define RSEQ_ASM_OP_R_ADD(count) \
188 "add %%r17, %[" __rseq_str(count) "], %%r17\n\t"
189
190/* Load (r17 + voffp) to r17 */
191#define RSEQ_ASM_OP_R_LOADX(voffp) \
a799a7ba 192 RSEQ_LOADX_LONG "%%r17, %[" __rseq_str(voffp) "], %%r17\n\t"
784b0012
MD
193
194/* TODO: implement a faster memcpy. */
195#define RSEQ_ASM_OP_R_MEMCPY() \
d0c21ef2 196 RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \
784b0012
MD
197 "beq 333f\n\t" \
198 "addi %%r20, %%r20, -1\n\t" \
199 "addi %%r21, %%r21, -1\n\t" \
200 "222:\n\t" \
201 "lbzu %%r18, 1(%%r20)\n\t" \
202 "stbu %%r18, 1(%%r21)\n\t" \
203 "addi %%r19, %%r19, -1\n\t" \
d0c21ef2 204 RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \
784b0012
MD
205 "bne 222b\n\t" \
206 "333:\n\t" \
207
208#define RSEQ_ASM_OP_R_FINAL_STORE(var, post_commit_label) \
a799a7ba 209 RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
784b0012
MD
210 __rseq_str(post_commit_label) ":\n\t"
211
212#define RSEQ_ASM_OP_FINAL_STORE(value, var, post_commit_label) \
a799a7ba 213 RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" \
784b0012
MD
214 __rseq_str(post_commit_label) ":\n\t"
215
216static inline __attribute__((always_inline))
217int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
218{
219 RSEQ_INJECT_C(9)
220
221 __asm__ __volatile__ goto (
222 RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */
90d9876e
MD
223 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail])
224#ifdef RSEQ_COMPARE_TWICE
225 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1])
226 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2])
227#endif
784b0012
MD
228 /* Start rseq by storing table entry pointer into rseq_cs. */
229 RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs)
230 /* cmp cpuid */
231 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
232 RSEQ_INJECT_ASM(3)
233 /* cmp @v equal to @expect */
234 RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail])
235 RSEQ_INJECT_ASM(4)
236#ifdef RSEQ_COMPARE_TWICE
237 /* cmp cpuid */
238 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1])
239 /* cmp @v equal to @expect */
240 RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2])
241#endif
242 /* final store */
243 RSEQ_ASM_OP_FINAL_STORE(newv, v, 2)
244 RSEQ_INJECT_ASM(5)
245 RSEQ_ASM_DEFINE_ABORT(4, abort)
246 : /* gcc asm goto does not allow outputs */
247 : [cpu_id] "r" (cpu),
9698c399 248 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
9b1975bf 249 [rseq_cs] "m" (rseq_get_abi()->RSEQ_CS_PTR),
784b0012
MD
250 [v] "m" (*v),
251 [expect] "r" (expect),
252 [newv] "r" (newv)
253 RSEQ_INJECT_INPUT
254 : "memory", "cc", "r17"
255 RSEQ_INJECT_CLOBBER
256 : abort, cmpfail
257#ifdef RSEQ_COMPARE_TWICE
258 , error1, error2
259#endif
260 );
dd76f2d6 261 rseq_after_asm_goto();
784b0012
MD
262 return 0;
263abort:
dd76f2d6 264 rseq_after_asm_goto();
784b0012
MD
265 RSEQ_INJECT_FAILED
266 return -1;
267cmpfail:
dd76f2d6 268 rseq_after_asm_goto();
784b0012
MD
269 return 1;
270#ifdef RSEQ_COMPARE_TWICE
271error1:
dd76f2d6 272 rseq_after_asm_goto();
784b0012
MD
273 rseq_bug("cpu_id comparison failed");
274error2:
dd76f2d6 275 rseq_after_asm_goto();
784b0012
MD
276 rseq_bug("expected value comparison failed");
277#endif
278}
279
280static inline __attribute__((always_inline))
281int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
07fac865 282 int voffp, intptr_t *load, int cpu)
784b0012
MD
283{
284 RSEQ_INJECT_C(9)
285
286 __asm__ __volatile__ goto (
287 RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */
90d9876e
MD
288 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail])
289#ifdef RSEQ_COMPARE_TWICE
290 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1])
291 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2])
292#endif
784b0012
MD
293 /* Start rseq by storing table entry pointer into rseq_cs. */
294 RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs)
295 /* cmp cpuid */
296 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
297 RSEQ_INJECT_ASM(3)
298 /* cmp @v not equal to @expectnot */
299 RSEQ_ASM_OP_CMPNE(v, expectnot, %l[cmpfail])
300 RSEQ_INJECT_ASM(4)
301#ifdef RSEQ_COMPARE_TWICE
302 /* cmp cpuid */
303 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1])
304 /* cmp @v not equal to @expectnot */
305 RSEQ_ASM_OP_CMPNE(v, expectnot, %l[error2])
306#endif
307 /* load the value of @v */
308 RSEQ_ASM_OP_R_LOAD(v)
309 /* store it in @load */
310 RSEQ_ASM_OP_R_STORE(load)
311 /* dereference voffp(v) */
312 RSEQ_ASM_OP_R_LOADX(voffp)
313 /* final store the value at voffp(v) */
314 RSEQ_ASM_OP_R_FINAL_STORE(v, 2)
315 RSEQ_INJECT_ASM(5)
316 RSEQ_ASM_DEFINE_ABORT(4, abort)
317 : /* gcc asm goto does not allow outputs */
318 : [cpu_id] "r" (cpu),
9698c399 319 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
9b1975bf 320 [rseq_cs] "m" (rseq_get_abi()->RSEQ_CS_PTR),
784b0012
MD
321 /* final store input */
322 [v] "m" (*v),
323 [expectnot] "r" (expectnot),
324 [voffp] "b" (voffp),
325 [load] "m" (*load)
326 RSEQ_INJECT_INPUT
327 : "memory", "cc", "r17"
328 RSEQ_INJECT_CLOBBER
329 : abort, cmpfail
330#ifdef RSEQ_COMPARE_TWICE
331 , error1, error2
332#endif
333 );
dd76f2d6 334 rseq_after_asm_goto();
784b0012
MD
335 return 0;
336abort:
dd76f2d6 337 rseq_after_asm_goto();
784b0012
MD
338 RSEQ_INJECT_FAILED
339 return -1;
340cmpfail:
dd76f2d6 341 rseq_after_asm_goto();
784b0012
MD
342 return 1;
343#ifdef RSEQ_COMPARE_TWICE
344error1:
dd76f2d6 345 rseq_after_asm_goto();
784b0012
MD
346 rseq_bug("cpu_id comparison failed");
347error2:
dd76f2d6 348 rseq_after_asm_goto();
784b0012
MD
349 rseq_bug("expected value comparison failed");
350#endif
351}
352
353static inline __attribute__((always_inline))
354int rseq_addv(intptr_t *v, intptr_t count, int cpu)
355{
356 RSEQ_INJECT_C(9)
357
358 __asm__ __volatile__ goto (
359 RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */
90d9876e
MD
360#ifdef RSEQ_COMPARE_TWICE
361 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1])
362#endif
784b0012
MD
363 /* Start rseq by storing table entry pointer into rseq_cs. */
364 RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs)
365 /* cmp cpuid */
366 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
367 RSEQ_INJECT_ASM(3)
368#ifdef RSEQ_COMPARE_TWICE
369 /* cmp cpuid */
370 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1])
371#endif
372 /* load the value of @v */
373 RSEQ_ASM_OP_R_LOAD(v)
374 /* add @count to it */
375 RSEQ_ASM_OP_R_ADD(count)
376 /* final store */
377 RSEQ_ASM_OP_R_FINAL_STORE(v, 2)
378 RSEQ_INJECT_ASM(4)
379 RSEQ_ASM_DEFINE_ABORT(4, abort)
380 : /* gcc asm goto does not allow outputs */
381 : [cpu_id] "r" (cpu),
9698c399 382 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
9b1975bf 383 [rseq_cs] "m" (rseq_get_abi()->RSEQ_CS_PTR),
784b0012
MD
384 /* final store input */
385 [v] "m" (*v),
386 [count] "r" (count)
387 RSEQ_INJECT_INPUT
388 : "memory", "cc", "r17"
389 RSEQ_INJECT_CLOBBER
390 : abort
391#ifdef RSEQ_COMPARE_TWICE
392 , error1
393#endif
394 );
dd76f2d6 395 rseq_after_asm_goto();
784b0012
MD
396 return 0;
397abort:
dd76f2d6 398 rseq_after_asm_goto();
784b0012
MD
399 RSEQ_INJECT_FAILED
400 return -1;
401#ifdef RSEQ_COMPARE_TWICE
402error1:
dd76f2d6 403 rseq_after_asm_goto();
784b0012
MD
404 rseq_bug("cpu_id comparison failed");
405#endif
406}
407
408static inline __attribute__((always_inline))
409int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
410 intptr_t *v2, intptr_t newv2,
411 intptr_t newv, int cpu)
412{
413 RSEQ_INJECT_C(9)
414
415 __asm__ __volatile__ goto (
416 RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */
90d9876e
MD
417 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail])
418#ifdef RSEQ_COMPARE_TWICE
419 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1])
420 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2])
421#endif
784b0012
MD
422 /* Start rseq by storing table entry pointer into rseq_cs. */
423 RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs)
424 /* cmp cpuid */
425 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
426 RSEQ_INJECT_ASM(3)
427 /* cmp @v equal to @expect */
428 RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail])
429 RSEQ_INJECT_ASM(4)
430#ifdef RSEQ_COMPARE_TWICE
431 /* cmp cpuid */
432 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1])
433 /* cmp @v equal to @expect */
434 RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2])
435#endif
436 /* try store */
437 RSEQ_ASM_OP_STORE(newv2, v2)
438 RSEQ_INJECT_ASM(5)
439 /* final store */
440 RSEQ_ASM_OP_FINAL_STORE(newv, v, 2)
441 RSEQ_INJECT_ASM(6)
442 RSEQ_ASM_DEFINE_ABORT(4, abort)
443 : /* gcc asm goto does not allow outputs */
444 : [cpu_id] "r" (cpu),
9698c399 445 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
9b1975bf 446 [rseq_cs] "m" (rseq_get_abi()->RSEQ_CS_PTR),
784b0012
MD
447 /* try store input */
448 [v2] "m" (*v2),
449 [newv2] "r" (newv2),
450 /* final store input */
451 [v] "m" (*v),
452 [expect] "r" (expect),
453 [newv] "r" (newv)
454 RSEQ_INJECT_INPUT
455 : "memory", "cc", "r17"
456 RSEQ_INJECT_CLOBBER
457 : abort, cmpfail
458#ifdef RSEQ_COMPARE_TWICE
459 , error1, error2
460#endif
461 );
dd76f2d6 462 rseq_after_asm_goto();
784b0012
MD
463 return 0;
464abort:
dd76f2d6 465 rseq_after_asm_goto();
784b0012
MD
466 RSEQ_INJECT_FAILED
467 return -1;
468cmpfail:
dd76f2d6 469 rseq_after_asm_goto();
784b0012
MD
470 return 1;
471#ifdef RSEQ_COMPARE_TWICE
472error1:
dd76f2d6 473 rseq_after_asm_goto();
784b0012
MD
474 rseq_bug("cpu_id comparison failed");
475error2:
dd76f2d6 476 rseq_after_asm_goto();
784b0012
MD
477 rseq_bug("expected value comparison failed");
478#endif
479}
480
481static inline __attribute__((always_inline))
482int rseq_cmpeqv_trystorev_storev_release(intptr_t *v, intptr_t expect,
483 intptr_t *v2, intptr_t newv2,
484 intptr_t newv, int cpu)
485{
486 RSEQ_INJECT_C(9)
487
488 __asm__ __volatile__ goto (
489 RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */
90d9876e
MD
490 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail])
491#ifdef RSEQ_COMPARE_TWICE
492 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1])
493 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2])
494#endif
784b0012
MD
495 /* Start rseq by storing table entry pointer into rseq_cs. */
496 RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs)
497 /* cmp cpuid */
498 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
499 RSEQ_INJECT_ASM(3)
500 /* cmp @v equal to @expect */
501 RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail])
502 RSEQ_INJECT_ASM(4)
503#ifdef RSEQ_COMPARE_TWICE
504 /* cmp cpuid */
505 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1])
506 /* cmp @v equal to @expect */
507 RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2])
508#endif
509 /* try store */
510 RSEQ_ASM_OP_STORE(newv2, v2)
511 RSEQ_INJECT_ASM(5)
512 /* for 'release' */
513 "lwsync\n\t"
514 /* final store */
515 RSEQ_ASM_OP_FINAL_STORE(newv, v, 2)
516 RSEQ_INJECT_ASM(6)
517 RSEQ_ASM_DEFINE_ABORT(4, abort)
518 : /* gcc asm goto does not allow outputs */
519 : [cpu_id] "r" (cpu),
9698c399 520 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
9b1975bf 521 [rseq_cs] "m" (rseq_get_abi()->RSEQ_CS_PTR),
784b0012
MD
522 /* try store input */
523 [v2] "m" (*v2),
524 [newv2] "r" (newv2),
525 /* final store input */
526 [v] "m" (*v),
527 [expect] "r" (expect),
528 [newv] "r" (newv)
529 RSEQ_INJECT_INPUT
530 : "memory", "cc", "r17"
531 RSEQ_INJECT_CLOBBER
532 : abort, cmpfail
533#ifdef RSEQ_COMPARE_TWICE
534 , error1, error2
535#endif
536 );
dd76f2d6 537 rseq_after_asm_goto();
784b0012
MD
538 return 0;
539abort:
dd76f2d6 540 rseq_after_asm_goto();
784b0012
MD
541 RSEQ_INJECT_FAILED
542 return -1;
543cmpfail:
dd76f2d6 544 rseq_after_asm_goto();
784b0012
MD
545 return 1;
546#ifdef RSEQ_COMPARE_TWICE
547error1:
dd76f2d6 548 rseq_after_asm_goto();
784b0012
MD
549 rseq_bug("cpu_id comparison failed");
550error2:
dd76f2d6 551 rseq_after_asm_goto();
784b0012
MD
552 rseq_bug("expected value comparison failed");
553#endif
554}
555
556static inline __attribute__((always_inline))
557int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
558 intptr_t *v2, intptr_t expect2,
559 intptr_t newv, int cpu)
560{
561 RSEQ_INJECT_C(9)
562
563 __asm__ __volatile__ goto (
564 RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */
90d9876e
MD
565 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail])
566#ifdef RSEQ_COMPARE_TWICE
567 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1])
568 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2])
569 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3])
570#endif
784b0012
MD
571 /* Start rseq by storing table entry pointer into rseq_cs. */
572 RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs)
573 /* cmp cpuid */
574 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
575 RSEQ_INJECT_ASM(3)
576 /* cmp @v equal to @expect */
577 RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail])
578 RSEQ_INJECT_ASM(4)
579 /* cmp @v2 equal to @expct2 */
580 RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[cmpfail])
581 RSEQ_INJECT_ASM(5)
582#ifdef RSEQ_COMPARE_TWICE
583 /* cmp cpuid */
584 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1])
585 /* cmp @v equal to @expect */
586 RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2])
587 /* cmp @v2 equal to @expct2 */
588 RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[error3])
589#endif
590 /* final store */
591 RSEQ_ASM_OP_FINAL_STORE(newv, v, 2)
592 RSEQ_INJECT_ASM(6)
593 RSEQ_ASM_DEFINE_ABORT(4, abort)
594 : /* gcc asm goto does not allow outputs */
595 : [cpu_id] "r" (cpu),
9698c399 596 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
9b1975bf 597 [rseq_cs] "m" (rseq_get_abi()->RSEQ_CS_PTR),
784b0012
MD
598 /* cmp2 input */
599 [v2] "m" (*v2),
600 [expect2] "r" (expect2),
601 /* final store input */
602 [v] "m" (*v),
603 [expect] "r" (expect),
604 [newv] "r" (newv)
605 RSEQ_INJECT_INPUT
606 : "memory", "cc", "r17"
607 RSEQ_INJECT_CLOBBER
608 : abort, cmpfail
609#ifdef RSEQ_COMPARE_TWICE
610 , error1, error2, error3
611#endif
612 );
dd76f2d6 613 rseq_after_asm_goto();
784b0012
MD
614 return 0;
615abort:
dd76f2d6 616 rseq_after_asm_goto();
784b0012
MD
617 RSEQ_INJECT_FAILED
618 return -1;
619cmpfail:
dd76f2d6 620 rseq_after_asm_goto();
784b0012
MD
621 return 1;
622#ifdef RSEQ_COMPARE_TWICE
623error1:
dd76f2d6 624 rseq_after_asm_goto();
784b0012
MD
625 rseq_bug("cpu_id comparison failed");
626error2:
dd76f2d6 627 rseq_after_asm_goto();
784b0012
MD
628 rseq_bug("1st expected value comparison failed");
629error3:
dd76f2d6 630 rseq_after_asm_goto();
784b0012
MD
631 rseq_bug("2nd expected value comparison failed");
632#endif
633}
634
635static inline __attribute__((always_inline))
636int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
637 void *dst, void *src, size_t len,
638 intptr_t newv, int cpu)
639{
640 RSEQ_INJECT_C(9)
641
642 __asm__ __volatile__ goto (
643 RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */
90d9876e
MD
644 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail])
645#ifdef RSEQ_COMPARE_TWICE
646 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1])
647 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2])
648#endif
784b0012
MD
649 /* setup for mempcy */
650 "mr %%r19, %[len]\n\t"
651 "mr %%r20, %[src]\n\t"
652 "mr %%r21, %[dst]\n\t"
653 /* Start rseq by storing table entry pointer into rseq_cs. */
654 RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs)
655 /* cmp cpuid */
656 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
657 RSEQ_INJECT_ASM(3)
658 /* cmp @v equal to @expect */
659 RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail])
660 RSEQ_INJECT_ASM(4)
661#ifdef RSEQ_COMPARE_TWICE
662 /* cmp cpuid */
663 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1])
664 /* cmp @v equal to @expect */
665 RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2])
666#endif
667 /* try memcpy */
668 RSEQ_ASM_OP_R_MEMCPY()
669 RSEQ_INJECT_ASM(5)
670 /* final store */
671 RSEQ_ASM_OP_FINAL_STORE(newv, v, 2)
672 RSEQ_INJECT_ASM(6)
673 /* teardown */
674 RSEQ_ASM_DEFINE_ABORT(4, abort)
675 : /* gcc asm goto does not allow outputs */
676 : [cpu_id] "r" (cpu),
9698c399 677 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
9b1975bf 678 [rseq_cs] "m" (rseq_get_abi()->RSEQ_CS_PTR),
784b0012
MD
679 /* final store input */
680 [v] "m" (*v),
681 [expect] "r" (expect),
682 [newv] "r" (newv),
683 /* try memcpy input */
684 [dst] "r" (dst),
685 [src] "r" (src),
686 [len] "r" (len)
687 RSEQ_INJECT_INPUT
688 : "memory", "cc", "r17", "r18", "r19", "r20", "r21"
689 RSEQ_INJECT_CLOBBER
690 : abort, cmpfail
691#ifdef RSEQ_COMPARE_TWICE
692 , error1, error2
693#endif
694 );
dd76f2d6 695 rseq_after_asm_goto();
784b0012
MD
696 return 0;
697abort:
dd76f2d6 698 rseq_after_asm_goto();
784b0012
MD
699 RSEQ_INJECT_FAILED
700 return -1;
701cmpfail:
dd76f2d6 702 rseq_after_asm_goto();
784b0012
MD
703 return 1;
704#ifdef RSEQ_COMPARE_TWICE
705error1:
dd76f2d6 706 rseq_after_asm_goto();
784b0012
MD
707 rseq_bug("cpu_id comparison failed");
708error2:
dd76f2d6 709 rseq_after_asm_goto();
784b0012
MD
710 rseq_bug("expected value comparison failed");
711#endif
712}
713
714static inline __attribute__((always_inline))
715int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,
716 void *dst, void *src, size_t len,
717 intptr_t newv, int cpu)
718{
719 RSEQ_INJECT_C(9)
720
721 __asm__ __volatile__ goto (
722 RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */
90d9876e
MD
723 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail])
724#ifdef RSEQ_COMPARE_TWICE
725 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1])
726 RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2])
727#endif
784b0012
MD
728 /* setup for mempcy */
729 "mr %%r19, %[len]\n\t"
730 "mr %%r20, %[src]\n\t"
731 "mr %%r21, %[dst]\n\t"
732 /* Start rseq by storing table entry pointer into rseq_cs. */
733 RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs)
734 /* cmp cpuid */
735 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
736 RSEQ_INJECT_ASM(3)
737 /* cmp @v equal to @expect */
738 RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail])
739 RSEQ_INJECT_ASM(4)
740#ifdef RSEQ_COMPARE_TWICE
741 /* cmp cpuid */
742 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1])
743 /* cmp @v equal to @expect */
744 RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2])
745#endif
746 /* try memcpy */
747 RSEQ_ASM_OP_R_MEMCPY()
748 RSEQ_INJECT_ASM(5)
749 /* for 'release' */
750 "lwsync\n\t"
751 /* final store */
752 RSEQ_ASM_OP_FINAL_STORE(newv, v, 2)
753 RSEQ_INJECT_ASM(6)
754 /* teardown */
755 RSEQ_ASM_DEFINE_ABORT(4, abort)
756 : /* gcc asm goto does not allow outputs */
757 : [cpu_id] "r" (cpu),
9698c399 758 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
9b1975bf 759 [rseq_cs] "m" (rseq_get_abi()->RSEQ_CS_PTR),
784b0012
MD
760 /* final store input */
761 [v] "m" (*v),
762 [expect] "r" (expect),
763 [newv] "r" (newv),
764 /* try memcpy input */
765 [dst] "r" (dst),
766 [src] "r" (src),
767 [len] "r" (len)
768 RSEQ_INJECT_INPUT
769 : "memory", "cc", "r17", "r18", "r19", "r20", "r21"
770 RSEQ_INJECT_CLOBBER
771 : abort, cmpfail
772#ifdef RSEQ_COMPARE_TWICE
773 , error1, error2
774#endif
775 );
dd76f2d6 776 rseq_after_asm_goto();
784b0012
MD
777 return 0;
778abort:
dd76f2d6 779 rseq_after_asm_goto();
784b0012
MD
780 RSEQ_INJECT_FAILED
781 return -1;
782cmpfail:
dd76f2d6 783 rseq_after_asm_goto();
784b0012
MD
784 return 1;
785#ifdef RSEQ_COMPARE_TWICE
786error1:
dd76f2d6 787 rseq_after_asm_goto();
784b0012
MD
788 rseq_bug("cpu_id comparison failed");
789error2:
dd76f2d6 790 rseq_after_asm_goto();
784b0012
MD
791 rseq_bug("expected value comparison failed");
792#endif
793}
794
784b0012 795#endif /* !RSEQ_SKIP_FASTPATH */
This page took 0.095932 seconds and 4 git commands to generate.