[RFC PATCH 28/34] accel/tcg: Make plugin-gen.c target independent

Anton Johansson via posted 34 patches 10 months, 1 week ago
[RFC PATCH 28/34] accel/tcg: Make plugin-gen.c target independent
Posted by Anton Johansson via 10 months, 1 week ago
Switches computation of offsets into CPUState to use that the offset
between CPUState and CPUArchState is guaranteed to be sizeof(CPUState).

Signed-off-by: Anton Johansson <anjo@rev.ng>
---
 accel/tcg/plugin-gen.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
index d31c9993ea..ce7635958f 100644
--- a/accel/tcg/plugin-gen.c
+++ b/accel/tcg/plugin-gen.c
@@ -43,10 +43,9 @@
  * CPU's index into a TCG temp, since the first callback did it already.
  */
 #include "qemu/osdep.h"
-#include "cpu.h"
 #include "tcg/tcg.h"
 #include "tcg/tcg-temp-internal.h"
-#include "tcg/tcg-op.h"
+#include "tcg/tcg-op-common.h"
 #include "exec/exec-all.h"
 #include "exec/plugin-gen.h"
 #include "exec/translator.h"
@@ -104,8 +103,8 @@ static void gen_empty_udata_cb(void)
     TCGv_ptr udata = tcg_temp_ebb_new_ptr();
 
     tcg_gen_movi_ptr(udata, 0);
-    tcg_gen_ld_i32(cpu_index, tcg_env,
-                   -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));
+    tcg_gen_ld_i32(cpu_index, tcg_env, offsetof(CPUState, cpu_index) -
+                                       sizeof(CPUState));
     gen_helper_plugin_vcpu_udata_cb(cpu_index, udata);
 
     tcg_temp_free_ptr(udata);
@@ -138,8 +137,8 @@ static void gen_empty_mem_cb(TCGv_i64 addr, uint32_t info)
 
     tcg_gen_movi_i32(meminfo, info);
     tcg_gen_movi_ptr(udata, 0);
-    tcg_gen_ld_i32(cpu_index, tcg_env,
-                   -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));
+    tcg_gen_ld_i32(cpu_index, tcg_env, offsetof(CPUState, cpu_index) -
+                                       sizeof(CPUState));
 
     gen_helper_plugin_vcpu_mem_cb(cpu_index, meminfo, addr, udata);
 
@@ -158,7 +157,7 @@ static void gen_empty_mem_helper(void)
 
     tcg_gen_movi_ptr(ptr, 0);
     tcg_gen_st_ptr(ptr, tcg_env, offsetof(CPUState, plugin_mem_cbs) -
-                                 offsetof(ArchCPU, env));
+                                 sizeof(CPUState));
     tcg_temp_free_ptr(ptr);
 }
 
@@ -582,7 +581,7 @@ void plugin_gen_disable_mem_helpers(void)
         return;
     }
     tcg_gen_st_ptr(tcg_constant_ptr(NULL), tcg_env,
-                   offsetof(CPUState, plugin_mem_cbs) - offsetof(ArchCPU, env));
+                   offsetof(CPUState, plugin_mem_cbs) - sizeof(CPUState));
 }
 
 static void plugin_gen_tb_udata(const struct qemu_plugin_tb *ptb,
-- 
2.43.0
Re: [RFC PATCH 28/34] accel/tcg: Make plugin-gen.c target independent
Posted by Richard Henderson 10 months, 1 week ago
On 1/20/24 00:40, Anton Johansson wrote:
> Switches computation of offsets into CPUState to use that the offset
> between CPUState and CPUArchState is guaranteed to be sizeof(CPUState).
> 
> Signed-off-by: Anton Johansson<anjo@rev.ng>
> ---
>   accel/tcg/plugin-gen.c | 15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~