xref: /qemu/include/exec/plugin-gen.h (revision b21af662c15522b83a973bc2ffd51d0117c0e039)
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 
1538b47b19SEmilio G. Cota #include "qemu/plugin.h"
1638b47b19SEmilio G. Cota #include "tcg/tcg.h"
1738b47b19SEmilio G. Cota 
1838b47b19SEmilio G. Cota struct DisasContextBase;
1938b47b19SEmilio G. Cota 
2038b47b19SEmilio G. Cota #ifdef CONFIG_PLUGIN
2138b47b19SEmilio G. Cota 
22*b21af662SRichard Henderson bool plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db,
23*b21af662SRichard Henderson                          bool supress);
2438b47b19SEmilio G. Cota void plugin_gen_tb_end(CPUState *cpu);
2538b47b19SEmilio G. Cota void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db);
2638b47b19SEmilio G. Cota void plugin_gen_insn_end(void);
2738b47b19SEmilio G. Cota 
2838b47b19SEmilio G. Cota void plugin_gen_disable_mem_helpers(void);
2938b47b19SEmilio G. Cota void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info);
3038b47b19SEmilio G. Cota 
31357af9beSAlex Bennée static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
32763f7e12SEmilio G. Cota {
33763f7e12SEmilio G. Cota     struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn;
34357af9beSAlex Bennée     abi_ptr off;
35763f7e12SEmilio G. Cota 
36763f7e12SEmilio G. Cota     if (insn == NULL) {
37763f7e12SEmilio G. Cota         return;
38763f7e12SEmilio G. Cota     }
39357af9beSAlex Bennée     off = pc - insn->vaddr;
40357af9beSAlex Bennée     if (off < insn->data->len) {
41357af9beSAlex Bennée         g_byte_array_set_size(insn->data, off);
42357af9beSAlex Bennée     } else if (off > insn->data->len) {
43357af9beSAlex Bennée         /* we have an unexpected gap */
44357af9beSAlex Bennée         g_assert_not_reached();
45357af9beSAlex Bennée     }
46763f7e12SEmilio G. Cota 
47763f7e12SEmilio G. Cota     insn->data = g_byte_array_append(insn->data, from, size);
48763f7e12SEmilio G. Cota }
49763f7e12SEmilio G. Cota 
5038b47b19SEmilio G. Cota #else /* !CONFIG_PLUGIN */
5138b47b19SEmilio G. Cota 
52*b21af662SRichard Henderson static inline bool
53*b21af662SRichard Henderson plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db, bool sup)
5438b47b19SEmilio G. Cota {
5538b47b19SEmilio G. Cota     return false;
5638b47b19SEmilio G. Cota }
5738b47b19SEmilio G. Cota 
5838b47b19SEmilio G. Cota static inline
5938b47b19SEmilio G. Cota void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db)
6038b47b19SEmilio G. Cota { }
6138b47b19SEmilio G. Cota 
6238b47b19SEmilio G. Cota static inline void plugin_gen_insn_end(void)
6338b47b19SEmilio G. Cota { }
6438b47b19SEmilio G. Cota 
6538b47b19SEmilio G. Cota static inline void plugin_gen_tb_end(CPUState *cpu)
6638b47b19SEmilio G. Cota { }
6738b47b19SEmilio G. Cota 
6838b47b19SEmilio G. Cota static inline void plugin_gen_disable_mem_helpers(void)
6938b47b19SEmilio G. Cota { }
7038b47b19SEmilio G. Cota 
7138b47b19SEmilio G. Cota static inline void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info)
7238b47b19SEmilio G. Cota { }
7338b47b19SEmilio G. Cota 
74357af9beSAlex Bennée static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
75763f7e12SEmilio G. Cota { }
76763f7e12SEmilio G. Cota 
7738b47b19SEmilio G. Cota #endif /* CONFIG_PLUGIN */
7838b47b19SEmilio G. Cota 
7938b47b19SEmilio G. Cota #endif /* QEMU_PLUGIN_GEN_H */
8038b47b19SEmilio G. Cota 
81