plugins: add an API to read registers

We can only request a list of registers once the vCPU has been
initialised so the user needs to use either call the get function on
vCPU initialisation or during the translation phase.

We don't expose the reg number to the plugin instead hiding it behind
an opaque handle. For now this is just the gdb_regnum encapsulated in
an anonymous GPOINTER but in future as we add more state for plugins
to track we can expand it.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706
Based-on:  <20231025093128.33116-18-akihiko.odaki@daynix.com>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20240227144335.1196131-24-alex.bennee@linaro.org>
This commit is contained in:
Alex Bennée
2024-02-27 14:43:29 +00:00
parent c006147122
commit 8df5e27cf7
3 changed files with 105 additions and 2 deletions

View File

@ -11,6 +11,7 @@
#ifndef QEMU_QEMU_PLUGIN_H
#define QEMU_QEMU_PLUGIN_H
#include <glib.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
@ -229,8 +230,8 @@ struct qemu_plugin_insn;
* @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs
* @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs
*
* Note: currently unused, plugins cannot read or change system
* register state.
* Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change
* system register state.
*/
enum qemu_plugin_cb_flags {
QEMU_PLUGIN_CB_NO_REGS,
@ -707,4 +708,49 @@ uint64_t qemu_plugin_end_code(void);
QEMU_PLUGIN_API
uint64_t qemu_plugin_entry_code(void);
/** struct qemu_plugin_register - Opaque handle for register access */
struct qemu_plugin_register;
/**
* typedef qemu_plugin_reg_descriptor - register descriptions
*
* @handle: opaque handle for retrieving value with qemu_plugin_read_register
* @name: register name
* @feature: optional feature descriptor, can be NULL
*/
typedef struct {
struct qemu_plugin_register *handle;
const char *name;
const char *feature;
} qemu_plugin_reg_descriptor;
/**
* qemu_plugin_get_registers() - return register list for current vCPU
*
* Returns a potentially empty GArray of qemu_plugin_reg_descriptor.
* Caller frees the array (but not the const strings).
*
* Should be used from a qemu_plugin_register_vcpu_init_cb() callback
* after the vCPU is initialised, i.e. in the vCPU context.
*/
QEMU_PLUGIN_API
GArray *qemu_plugin_get_registers(void);
/**
* qemu_plugin_read_register() - read register for current vCPU
*
* @handle: a @qemu_plugin_reg_handle handle
* @buf: A GByteArray for the data owned by the plugin
*
* This function is only available in a context that register read access is
* explicitly requested via the QEMU_PLUGIN_CB_R_REGS flag.
*
* Returns the size of the read register. The content of @buf is in target byte
* order. On failure returns -1.
*/
QEMU_PLUGIN_API
int qemu_plugin_read_register(struct qemu_plugin_register *handle,
GByteArray *buf);
#endif /* QEMU_QEMU_PLUGIN_H */