atomic_common.c.inc (3244B)
1 /* 2 * Common Atomic Helper Functions 3 * 4 * This file should be included before the various instantiations of 5 * the atomic_template.h helpers. 6 * 7 * Copyright (c) 2019 Linaro 8 * Written by Alex Bennée <alex.bennee@linaro.org> 9 * 10 * SPDX-License-Identifier: GPL-2.0-or-later 11 * 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. 14 */ 15 16 static void atomic_trace_rmw_post(CPUArchState *env, target_ulong addr, 17 MemOpIdx oi) 18 { 19 qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_RW); 20 } 21 22 #if HAVE_ATOMIC128 23 static void atomic_trace_ld_post(CPUArchState *env, target_ulong addr, 24 MemOpIdx oi) 25 { 26 qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); 27 } 28 29 static void atomic_trace_st_post(CPUArchState *env, target_ulong addr, 30 MemOpIdx oi) 31 { 32 qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); 33 } 34 #endif 35 36 /* 37 * Atomic helpers callable from TCG. 38 * These have a common interface and all defer to cpu_atomic_* 39 * using the host return address from GETPC(). 40 */ 41 42 #define CMPXCHG_HELPER(OP, TYPE) \ 43 TYPE HELPER(atomic_##OP)(CPUArchState *env, target_ulong addr, \ 44 TYPE oldv, TYPE newv, uint32_t oi) \ 45 { return cpu_atomic_##OP##_mmu(env, addr, oldv, newv, oi, GETPC()); } 46 47 CMPXCHG_HELPER(cmpxchgb, uint32_t) 48 CMPXCHG_HELPER(cmpxchgw_be, uint32_t) 49 CMPXCHG_HELPER(cmpxchgw_le, uint32_t) 50 CMPXCHG_HELPER(cmpxchgl_be, uint32_t) 51 CMPXCHG_HELPER(cmpxchgl_le, uint32_t) 52 53 #ifdef CONFIG_ATOMIC64 54 CMPXCHG_HELPER(cmpxchgq_be, uint64_t) 55 CMPXCHG_HELPER(cmpxchgq_le, uint64_t) 56 #endif 57 58 #undef CMPXCHG_HELPER 59 60 #define ATOMIC_HELPER(OP, TYPE) \ 61 TYPE HELPER(glue(atomic_,OP))(CPUArchState *env, target_ulong addr, \ 62 TYPE val, uint32_t oi) \ 63 { return glue(glue(cpu_atomic_,OP),_mmu)(env, addr, val, oi, GETPC()); } 64 65 #ifdef CONFIG_ATOMIC64 66 #define GEN_ATOMIC_HELPERS(OP) \ 67 ATOMIC_HELPER(glue(OP,b), uint32_t) \ 68 ATOMIC_HELPER(glue(OP,w_be), uint32_t) \ 69 ATOMIC_HELPER(glue(OP,w_le), uint32_t) \ 70 ATOMIC_HELPER(glue(OP,l_be), uint32_t) \ 71 ATOMIC_HELPER(glue(OP,l_le), uint32_t) \ 72 ATOMIC_HELPER(glue(OP,q_be), uint64_t) \ 73 ATOMIC_HELPER(glue(OP,q_le), uint64_t) 74 #else 75 #define GEN_ATOMIC_HELPERS(OP) \ 76 ATOMIC_HELPER(glue(OP,b), uint32_t) \ 77 ATOMIC_HELPER(glue(OP,w_be), uint32_t) \ 78 ATOMIC_HELPER(glue(OP,w_le), uint32_t) \ 79 ATOMIC_HELPER(glue(OP,l_be), uint32_t) \ 80 ATOMIC_HELPER(glue(OP,l_le), uint32_t) 81 #endif 82 83 GEN_ATOMIC_HELPERS(fetch_add) 84 GEN_ATOMIC_HELPERS(fetch_and) 85 GEN_ATOMIC_HELPERS(fetch_or) 86 GEN_ATOMIC_HELPERS(fetch_xor) 87 GEN_ATOMIC_HELPERS(fetch_smin) 88 GEN_ATOMIC_HELPERS(fetch_umin) 89 GEN_ATOMIC_HELPERS(fetch_smax) 90 GEN_ATOMIC_HELPERS(fetch_umax) 91 92 GEN_ATOMIC_HELPERS(add_fetch) 93 GEN_ATOMIC_HELPERS(and_fetch) 94 GEN_ATOMIC_HELPERS(or_fetch) 95 GEN_ATOMIC_HELPERS(xor_fetch) 96 GEN_ATOMIC_HELPERS(smin_fetch) 97 GEN_ATOMIC_HELPERS(umin_fetch) 98 GEN_ATOMIC_HELPERS(smax_fetch) 99 GEN_ATOMIC_HELPERS(umax_fetch) 100 101 GEN_ATOMIC_HELPERS(xchg) 102 103 #undef ATOMIC_HELPER 104 #undef GEN_ATOMIC_HELPERS