138b47b19SEmilio G. Cota /* 238b47b19SEmilio G. Cota * Copyright (C) 2017, Emilio G. Cota <cota@braap.org> 338b47b19SEmilio G. Cota * 438b47b19SEmilio G. Cota * License: GNU GPL, version 2 or later. 538b47b19SEmilio G. Cota * See the COPYING file in the top-level directory. 638b47b19SEmilio G. Cota * 738b47b19SEmilio G. Cota * plugin-gen.h - TCG-dependent definitions for generating plugin code 838b47b19SEmilio G. Cota * 938b47b19SEmilio G. Cota * This header should be included only from plugin.c and C files that emit 1038b47b19SEmilio G. Cota * TCG code. 1138b47b19SEmilio G. Cota */ 1238b47b19SEmilio G. Cota #ifndef QEMU_PLUGIN_GEN_H 1338b47b19SEmilio G. Cota #define QEMU_PLUGIN_GEN_H 1438b47b19SEmilio G. Cota 157a5951f6SMarkus Armbruster #include "exec/cpu_ldst.h" 1638b47b19SEmilio G. Cota #include "qemu/plugin.h" 1738b47b19SEmilio G. Cota #include "tcg/tcg.h" 1838b47b19SEmilio G. Cota 1938b47b19SEmilio G. Cota struct DisasContextBase; 2038b47b19SEmilio G. Cota 2138b47b19SEmilio G. Cota #ifdef CONFIG_PLUGIN 2238b47b19SEmilio G. Cota 23b21af662SRichard Henderson bool plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db, 24b21af662SRichard Henderson bool supress); 2538b47b19SEmilio G. Cota void plugin_gen_tb_end(CPUState *cpu); 2638b47b19SEmilio G. Cota void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db); 2738b47b19SEmilio G. Cota void plugin_gen_insn_end(void); 2838b47b19SEmilio G. Cota 2938b47b19SEmilio G. Cota void plugin_gen_disable_mem_helpers(void); 30*fcdab382SRichard Henderson void plugin_gen_empty_mem_callback(TCGv_i64 addr, uint32_t info); 3138b47b19SEmilio G. Cota 32357af9beSAlex Bennée static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size) 33763f7e12SEmilio G. Cota { 34763f7e12SEmilio G. Cota struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn; 35357af9beSAlex Bennée abi_ptr off; 36763f7e12SEmilio G. Cota 37763f7e12SEmilio G. Cota if (insn == NULL) { 38763f7e12SEmilio G. Cota return; 39763f7e12SEmilio G. Cota } 40357af9beSAlex Bennée off = pc - insn->vaddr; 41357af9beSAlex Bennée if (off < insn->data->len) { 42357af9beSAlex Bennée g_byte_array_set_size(insn->data, off); 43357af9beSAlex Bennée } else if (off > insn->data->len) { 44357af9beSAlex Bennée /* we have an unexpected gap */ 45357af9beSAlex Bennée g_assert_not_reached(); 46357af9beSAlex Bennée } 47763f7e12SEmilio G. Cota 48763f7e12SEmilio G. Cota insn->data = g_byte_array_append(insn->data, from, size); 49763f7e12SEmilio G. Cota } 50763f7e12SEmilio G. Cota 5138b47b19SEmilio G. Cota #else /* !CONFIG_PLUGIN */ 5238b47b19SEmilio G. Cota 53b21af662SRichard Henderson static inline bool 54b21af662SRichard Henderson plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db, bool sup) 5538b47b19SEmilio G. Cota { 5638b47b19SEmilio G. Cota return false; 5738b47b19SEmilio G. Cota } 5838b47b19SEmilio G. Cota 5938b47b19SEmilio G. Cota static inline 6038b47b19SEmilio G. Cota void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db) 6138b47b19SEmilio G. Cota { } 6238b47b19SEmilio G. Cota 6338b47b19SEmilio G. Cota static inline void plugin_gen_insn_end(void) 6438b47b19SEmilio G. Cota { } 6538b47b19SEmilio G. Cota 6638b47b19SEmilio G. Cota static inline void plugin_gen_tb_end(CPUState *cpu) 6738b47b19SEmilio G. Cota { } 6838b47b19SEmilio G. Cota 6938b47b19SEmilio G. Cota static inline void plugin_gen_disable_mem_helpers(void) 7038b47b19SEmilio G. Cota { } 7138b47b19SEmilio G. Cota 72*fcdab382SRichard Henderson static inline void plugin_gen_empty_mem_callback(TCGv_i64 addr, uint32_t info) 7338b47b19SEmilio G. Cota { } 7438b47b19SEmilio G. Cota 75357af9beSAlex Bennée static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size) 76763f7e12SEmilio G. Cota { } 77763f7e12SEmilio G. Cota 7838b47b19SEmilio G. Cota #endif /* CONFIG_PLUGIN */ 7938b47b19SEmilio G. Cota 8038b47b19SEmilio G. Cota #endif /* QEMU_PLUGIN_GEN_H */ 8138b47b19SEmilio G. Cota 82