blob: 5f5506f1cc2c4766e0c999f6e047a691fee469d8 [file] [log] [blame]
Emilio G. Cota38b47b12018-12-07 15:33:56 -05001/*
2 * Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
3 *
4 * License: GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
6 *
7 * plugin-gen.h - TCG-dependent definitions for generating plugin code
8 *
9 * This header should be included only from plugin.c and C files that emit
10 * TCG code.
11 */
12#ifndef QEMU_PLUGIN_GEN_H
13#define QEMU_PLUGIN_GEN_H
14
Markus Armbruster7a5951f2022-12-22 13:08:11 +010015#include "exec/cpu_ldst.h"
Emilio G. Cota38b47b12018-12-07 15:33:56 -050016#include "qemu/plugin.h"
17#include "tcg/tcg.h"
18
19struct DisasContextBase;
20
21#ifdef CONFIG_PLUGIN
22
Richard Hendersonb21af662022-08-12 09:15:15 -070023bool plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db,
24 bool supress);
Emilio G. Cota38b47b12018-12-07 15:33:56 -050025void plugin_gen_tb_end(CPUState *cpu);
26void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db);
27void plugin_gen_insn_end(void);
28
29void plugin_gen_disable_mem_helpers(void);
30void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info);
31
Alex Bennée357af9b2021-10-26 11:22:26 +010032static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
Emilio G. Cota763f7e12018-12-07 20:53:09 -050033{
34 struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn;
Alex Bennée357af9b2021-10-26 11:22:26 +010035 abi_ptr off;
Emilio G. Cota763f7e12018-12-07 20:53:09 -050036
37 if (insn == NULL) {
38 return;
39 }
Alex Bennée357af9b2021-10-26 11:22:26 +010040 off = pc - insn->vaddr;
41 if (off < insn->data->len) {
42 g_byte_array_set_size(insn->data, off);
43 } else if (off > insn->data->len) {
44 /* we have an unexpected gap */
45 g_assert_not_reached();
46 }
Emilio G. Cota763f7e12018-12-07 20:53:09 -050047
48 insn->data = g_byte_array_append(insn->data, from, size);
49}
50
Emilio G. Cota38b47b12018-12-07 15:33:56 -050051#else /* !CONFIG_PLUGIN */
52
Richard Hendersonb21af662022-08-12 09:15:15 -070053static inline bool
54plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db, bool sup)
Emilio G. Cota38b47b12018-12-07 15:33:56 -050055{
56 return false;
57}
58
59static inline
60void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db)
61{ }
62
63static inline void plugin_gen_insn_end(void)
64{ }
65
66static inline void plugin_gen_tb_end(CPUState *cpu)
67{ }
68
69static inline void plugin_gen_disable_mem_helpers(void)
70{ }
71
72static inline void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info)
73{ }
74
Alex Bennée357af9b2021-10-26 11:22:26 +010075static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
Emilio G. Cota763f7e12018-12-07 20:53:09 -050076{ }
77
Emilio G. Cota38b47b12018-12-07 15:33:56 -050078#endif /* CONFIG_PLUGIN */
79
80#endif /* QEMU_PLUGIN_GEN_H */
81