plugin-gen: add module for TCG-related code
We first inject empty instrumentation from translator_loop.
After translation, we go through the plugins to see what
they want to register for, filling in the empty instrumentation.
If if turns out that some instrumentation remains unused, we
remove it.
This approach supports the following features:
- Inlining TCG code for simple operations. Note that we do not
export TCG ops to plugins. Instead, we give them a C API to
insert inlined ops. So far we only support adding an immediate
to a u64, e.g. to count events.
- "Direct" callbacks. These are callbacks that do not go via
a helper. Instead, the helper is defined at run-time, so that
the plugin code is directly called from TCG. This makes direct
callbacks as efficient as possible; they are therefore used
for very frequent events, e.g. memory callbacks.
- Passing the host address to memory callbacks. Most of this
is implemented in a later patch though.
- Instrumentation of memory accesses performed from helpers.
See the corresponding comment, as well as a later patch.
Signed-off-by: Emilio G. Cota <cota@braap.org>
[AJB: add alloc_tcg_plugin_context, use glib, rm hwaddr]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
2018-12-07 23:33:56 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
|
|
|
|
*
|
|
|
|
* License: GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
* plugin-gen.h - TCG-dependent definitions for generating plugin code
|
|
|
|
*
|
|
|
|
* This header should be included only from plugin.c and C files that emit
|
|
|
|
* TCG code.
|
|
|
|
*/
|
|
|
|
#ifndef QEMU_PLUGIN_GEN_H
|
|
|
|
#define QEMU_PLUGIN_GEN_H
|
|
|
|
|
|
|
|
#include "qemu/plugin.h"
|
|
|
|
#include "tcg/tcg.h"
|
|
|
|
|
|
|
|
struct DisasContextBase;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PLUGIN
|
|
|
|
|
2022-08-12 19:15:15 +03:00
|
|
|
bool plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db,
|
|
|
|
bool supress);
|
plugin-gen: add module for TCG-related code
We first inject empty instrumentation from translator_loop.
After translation, we go through the plugins to see what
they want to register for, filling in the empty instrumentation.
If if turns out that some instrumentation remains unused, we
remove it.
This approach supports the following features:
- Inlining TCG code for simple operations. Note that we do not
export TCG ops to plugins. Instead, we give them a C API to
insert inlined ops. So far we only support adding an immediate
to a u64, e.g. to count events.
- "Direct" callbacks. These are callbacks that do not go via
a helper. Instead, the helper is defined at run-time, so that
the plugin code is directly called from TCG. This makes direct
callbacks as efficient as possible; they are therefore used
for very frequent events, e.g. memory callbacks.
- Passing the host address to memory callbacks. Most of this
is implemented in a later patch though.
- Instrumentation of memory accesses performed from helpers.
See the corresponding comment, as well as a later patch.
Signed-off-by: Emilio G. Cota <cota@braap.org>
[AJB: add alloc_tcg_plugin_context, use glib, rm hwaddr]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
2018-12-07 23:33:56 +03:00
|
|
|
void plugin_gen_tb_end(CPUState *cpu);
|
|
|
|
void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db);
|
|
|
|
void plugin_gen_insn_end(void);
|
|
|
|
|
|
|
|
void plugin_gen_disable_mem_helpers(void);
|
|
|
|
void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info);
|
|
|
|
|
2021-10-26 13:22:26 +03:00
|
|
|
static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
|
2018-12-08 04:53:09 +03:00
|
|
|
{
|
|
|
|
struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn;
|
2021-10-26 13:22:26 +03:00
|
|
|
abi_ptr off;
|
2018-12-08 04:53:09 +03:00
|
|
|
|
|
|
|
if (insn == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-26 13:22:26 +03:00
|
|
|
off = pc - insn->vaddr;
|
|
|
|
if (off < insn->data->len) {
|
|
|
|
g_byte_array_set_size(insn->data, off);
|
|
|
|
} else if (off > insn->data->len) {
|
|
|
|
/* we have an unexpected gap */
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
2018-12-08 04:53:09 +03:00
|
|
|
|
|
|
|
insn->data = g_byte_array_append(insn->data, from, size);
|
|
|
|
}
|
|
|
|
|
plugin-gen: add module for TCG-related code
We first inject empty instrumentation from translator_loop.
After translation, we go through the plugins to see what
they want to register for, filling in the empty instrumentation.
If if turns out that some instrumentation remains unused, we
remove it.
This approach supports the following features:
- Inlining TCG code for simple operations. Note that we do not
export TCG ops to plugins. Instead, we give them a C API to
insert inlined ops. So far we only support adding an immediate
to a u64, e.g. to count events.
- "Direct" callbacks. These are callbacks that do not go via
a helper. Instead, the helper is defined at run-time, so that
the plugin code is directly called from TCG. This makes direct
callbacks as efficient as possible; they are therefore used
for very frequent events, e.g. memory callbacks.
- Passing the host address to memory callbacks. Most of this
is implemented in a later patch though.
- Instrumentation of memory accesses performed from helpers.
See the corresponding comment, as well as a later patch.
Signed-off-by: Emilio G. Cota <cota@braap.org>
[AJB: add alloc_tcg_plugin_context, use glib, rm hwaddr]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
2018-12-07 23:33:56 +03:00
|
|
|
#else /* !CONFIG_PLUGIN */
|
|
|
|
|
2022-08-12 19:15:15 +03:00
|
|
|
static inline bool
|
|
|
|
plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db, bool sup)
|
plugin-gen: add module for TCG-related code
We first inject empty instrumentation from translator_loop.
After translation, we go through the plugins to see what
they want to register for, filling in the empty instrumentation.
If if turns out that some instrumentation remains unused, we
remove it.
This approach supports the following features:
- Inlining TCG code for simple operations. Note that we do not
export TCG ops to plugins. Instead, we give them a C API to
insert inlined ops. So far we only support adding an immediate
to a u64, e.g. to count events.
- "Direct" callbacks. These are callbacks that do not go via
a helper. Instead, the helper is defined at run-time, so that
the plugin code is directly called from TCG. This makes direct
callbacks as efficient as possible; they are therefore used
for very frequent events, e.g. memory callbacks.
- Passing the host address to memory callbacks. Most of this
is implemented in a later patch though.
- Instrumentation of memory accesses performed from helpers.
See the corresponding comment, as well as a later patch.
Signed-off-by: Emilio G. Cota <cota@braap.org>
[AJB: add alloc_tcg_plugin_context, use glib, rm hwaddr]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
2018-12-07 23:33:56 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
static inline void plugin_gen_insn_end(void)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
static inline void plugin_gen_tb_end(CPUState *cpu)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
static inline void plugin_gen_disable_mem_helpers(void)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
static inline void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info)
|
|
|
|
{ }
|
|
|
|
|
2021-10-26 13:22:26 +03:00
|
|
|
static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
|
2018-12-08 04:53:09 +03:00
|
|
|
{ }
|
|
|
|
|
plugin-gen: add module for TCG-related code
We first inject empty instrumentation from translator_loop.
After translation, we go through the plugins to see what
they want to register for, filling in the empty instrumentation.
If if turns out that some instrumentation remains unused, we
remove it.
This approach supports the following features:
- Inlining TCG code for simple operations. Note that we do not
export TCG ops to plugins. Instead, we give them a C API to
insert inlined ops. So far we only support adding an immediate
to a u64, e.g. to count events.
- "Direct" callbacks. These are callbacks that do not go via
a helper. Instead, the helper is defined at run-time, so that
the plugin code is directly called from TCG. This makes direct
callbacks as efficient as possible; they are therefore used
for very frequent events, e.g. memory callbacks.
- Passing the host address to memory callbacks. Most of this
is implemented in a later patch though.
- Instrumentation of memory accesses performed from helpers.
See the corresponding comment, as well as a later patch.
Signed-off-by: Emilio G. Cota <cota@braap.org>
[AJB: add alloc_tcg_plugin_context, use glib, rm hwaddr]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
2018-12-07 23:33:56 +03:00
|
|
|
#endif /* CONFIG_PLUGIN */
|
|
|
|
|
|
|
|
#endif /* QEMU_PLUGIN_GEN_H */
|
|
|
|
|