2 * Common Atomic Helper Functions
4 * This file should be included before the various instantiations of
5 * the atomic_template.h helpers.
7 * Copyright (c) 2019 Linaro
8 * Written by Alex Bennée <alex.bennee@linaro.org>
10 * SPDX-License-Identifier: GPL-2.0-or-later
12 * This work is licensed under the terms of the GNU GPL, version 2 or later.
13 * See the COPYING file in the top-level directory.
16 static void atomic_trace_rmw_post(CPUArchState *env, uint64_t addr,
19 qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_RW);
23 * Atomic helpers callable from TCG.
24 * These have a common interface and all defer to cpu_atomic_*
25 * using the host return address from GETPC().
28 #define CMPXCHG_HELPER(OP, TYPE) \
29 TYPE HELPER(atomic_##OP)(CPUArchState *env, uint64_t addr, \
30 TYPE oldv, TYPE newv, uint32_t oi) \
31 { return cpu_atomic_##OP##_mmu(env, addr, oldv, newv, oi, GETPC()); }
33 CMPXCHG_HELPER(cmpxchgb, uint32_t)
34 CMPXCHG_HELPER(cmpxchgw_be, uint32_t)
35 CMPXCHG_HELPER(cmpxchgw_le, uint32_t)
36 CMPXCHG_HELPER(cmpxchgl_be, uint32_t)
37 CMPXCHG_HELPER(cmpxchgl_le, uint32_t)
39 #ifdef CONFIG_ATOMIC64
40 CMPXCHG_HELPER(cmpxchgq_be, uint64_t)
41 CMPXCHG_HELPER(cmpxchgq_le, uint64_t)
45 CMPXCHG_HELPER(cmpxchgo_be, Int128)
46 CMPXCHG_HELPER(cmpxchgo_le, Int128)
51 Int128 HELPER(nonatomic_cmpxchgo)(CPUArchState *env, uint64_t addr,
52 Int128 cmpv, Int128 newv, uint32_t oi)
54 #if TCG_TARGET_REG_BITS == 32
55 uintptr_t ra = GETPC();
58 oldv = cpu_ld16_mmu(env, addr, oi, ra);
59 if (int128_eq(oldv, cmpv)) {
60 cpu_st16_mmu(env, addr, newv, oi, ra);
62 /* Even with comparison failure, still need a write cycle. */
63 probe_write(env, addr, 16, get_mmuidx(oi), ra);
67 g_assert_not_reached();
71 #define ATOMIC_HELPER(OP, TYPE) \
72 TYPE HELPER(glue(atomic_,OP))(CPUArchState *env, uint64_t addr, \
73 TYPE val, uint32_t oi) \
74 { return glue(glue(cpu_atomic_,OP),_mmu)(env, addr, val, oi, GETPC()); }
76 #ifdef CONFIG_ATOMIC64
77 #define GEN_ATOMIC_HELPERS(OP) \
78 ATOMIC_HELPER(glue(OP,b), uint32_t) \
79 ATOMIC_HELPER(glue(OP,w_be), uint32_t) \
80 ATOMIC_HELPER(glue(OP,w_le), uint32_t) \
81 ATOMIC_HELPER(glue(OP,l_be), uint32_t) \
82 ATOMIC_HELPER(glue(OP,l_le), uint32_t) \
83 ATOMIC_HELPER(glue(OP,q_be), uint64_t) \
84 ATOMIC_HELPER(glue(OP,q_le), uint64_t)
86 #define GEN_ATOMIC_HELPERS(OP) \
87 ATOMIC_HELPER(glue(OP,b), uint32_t) \
88 ATOMIC_HELPER(glue(OP,w_be), uint32_t) \
89 ATOMIC_HELPER(glue(OP,w_le), uint32_t) \
90 ATOMIC_HELPER(glue(OP,l_be), uint32_t) \
91 ATOMIC_HELPER(glue(OP,l_le), uint32_t)
94 GEN_ATOMIC_HELPERS(fetch_add)
95 GEN_ATOMIC_HELPERS(fetch_and)
96 GEN_ATOMIC_HELPERS(fetch_or)
97 GEN_ATOMIC_HELPERS(fetch_xor)
98 GEN_ATOMIC_HELPERS(fetch_smin)
99 GEN_ATOMIC_HELPERS(fetch_umin)
100 GEN_ATOMIC_HELPERS(fetch_smax)
101 GEN_ATOMIC_HELPERS(fetch_umax)
103 GEN_ATOMIC_HELPERS(add_fetch)
104 GEN_ATOMIC_HELPERS(and_fetch)
105 GEN_ATOMIC_HELPERS(or_fetch)
106 GEN_ATOMIC_HELPERS(xor_fetch)
107 GEN_ATOMIC_HELPERS(smin_fetch)
108 GEN_ATOMIC_HELPERS(umin_fetch)
109 GEN_ATOMIC_HELPERS(smax_fetch)
110 GEN_ATOMIC_HELPERS(umax_fetch)
112 GEN_ATOMIC_HELPERS(xchg)
115 #undef GEN_ATOMIC_HELPERS