[PATCH v4 7/9] monitor: Truncate target register using ldn_he_p() API

Philippe Mathieu-Daudé posted 9 patches 1 week, 4 days ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, "Dr. David Alan Gilbert" <dave@treblig.org>, Markus Armbruster <armbru@redhat.com>, Zhao Liu <zhao1.liu@intel.com>, Marcelo Tosatti <mtosatti@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Max Filippov <jcmvbkbc@gmail.com>
There is a newer version of this series
[PATCH v4 7/9] monitor: Truncate target register using ldn_he_p() API
Posted by Philippe Mathieu-Daudé 1 week, 4 days ago
Rather than truncating with a target_long cast, use the
unaligned load/store API.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/monitor/hmp-target.h | 3 ---
 monitor/hmp-target.c         | 8 +++++---
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h
index 6d6653aee6e..788bc9e330a 100644
--- a/include/monitor/hmp-target.h
+++ b/include/monitor/hmp-target.h
@@ -27,15 +27,12 @@
 
 typedef struct MonitorDef MonitorDef;
 
-#ifdef COMPILING_PER_TARGET
-#include "cpu.h"
 struct MonitorDef {
     const char *name;
     int offset;
     uint64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int val);
     int type;
 };
-#endif
 
 #define MD_TULONG 0
 #define MD_U32    1
diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c
index 5738b47bb03..257605a1c96 100644
--- a/monitor/hmp-target.c
+++ b/monitor/hmp-target.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/bswap.h"
 #include "monitor-internal.h"
 #include "monitor/qdev.h"
 #include "net/slirp.h"
@@ -65,6 +66,7 @@ HMPCommand *hmp_cmds_for_target(bool info_command)
  */
 int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)
 {
+    const unsigned length = target_long_bits() / 8;
     const MonitorDef *md = target_monitor_defs();
     CPUState *cs = mon_get_cpu(mon);
     uint64_t tmp = 0;
@@ -83,11 +85,11 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)
                 void *ptr = (uint8_t *)env + md->offset;
 
                 switch(md->type) {
-                case MD_U32:
+                case MD_I32:
                     *pval = *(uint32_t *)ptr;
                     break;
                 case MD_TULONG:
-                    *pval = *(target_ulong *)ptr;
+                    *pval = ldn_he_p(ptr, length);
                     break;
                 default:
                     *pval = 0;
@@ -100,7 +102,7 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)
 
     ret = target_get_monitor_def(cs, name, &tmp);
     if (!ret) {
-        *pval = (target_ulong)tmp;
+        *pval = ldn_he_p(&tmp, length);
     }
 
     return ret;
-- 
2.52.0


Re: [PATCH v4 7/9] monitor: Truncate target register using ldn_he_p() API
Posted by BALATON Zoltan 1 week, 4 days ago
On Thu, 29 Jan 2026, Philippe Mathieu-Daudé wrote:
> Rather than truncating with a target_long cast, use the
> unaligned load/store API.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/monitor/hmp-target.h | 3 ---
> monitor/hmp-target.c         | 8 +++++---
> 2 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h
> index 6d6653aee6e..788bc9e330a 100644
> --- a/include/monitor/hmp-target.h
> +++ b/include/monitor/hmp-target.h
> @@ -27,15 +27,12 @@
>
> typedef struct MonitorDef MonitorDef;
>
> -#ifdef COMPILING_PER_TARGET
> -#include "cpu.h"
> struct MonitorDef {
>     const char *name;
>     int offset;
>     uint64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int val);
>     int type;
> };
> -#endif
>
> #define MD_TULONG 0
> #define MD_U32    1
> diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c
> index 5738b47bb03..257605a1c96 100644
> --- a/monitor/hmp-target.c
> +++ b/monitor/hmp-target.c
> @@ -23,6 +23,7 @@
>  */
>
> #include "qemu/osdep.h"
> +#include "qemu/bswap.h"
> #include "monitor-internal.h"
> #include "monitor/qdev.h"
> #include "net/slirp.h"
> @@ -65,6 +66,7 @@ HMPCommand *hmp_cmds_for_target(bool info_command)
>  */
> int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)
> {
> +    const unsigned length = target_long_bits() / 8;
>     const MonitorDef *md = target_monitor_defs();
>     CPUState *cs = mon_get_cpu(mon);
>     uint64_t tmp = 0;
> @@ -83,11 +85,11 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)
>                 void *ptr = (uint8_t *)env + md->offset;
>
>                 switch(md->type) {
> -                case MD_U32:
> +                case MD_I32:

Why is this changed? Doesn't seem to be realted to what the commit message 
says.

Regards,
BALATON Zoltan

>                     *pval = *(uint32_t *)ptr;
>                     break;
>                 case MD_TULONG:
> -                    *pval = *(target_ulong *)ptr;
> +                    *pval = ldn_he_p(ptr, length);
>                     break;
>                 default:
>                     *pval = 0;
> @@ -100,7 +102,7 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)
>
>     ret = target_get_monitor_def(cs, name, &tmp);
>     if (!ret) {
> -        *pval = (target_ulong)tmp;
> +        *pval = ldn_he_p(&tmp, length);
>     }
>
>     return ret;
>
Re: [PATCH v4 7/9] monitor: Truncate target register using ldn_he_p() API
Posted by Philippe Mathieu-Daudé 1 week, 4 days ago
On 29/1/26 16:06, BALATON Zoltan wrote:
> On Thu, 29 Jan 2026, Philippe Mathieu-Daudé wrote:
>> Rather than truncating with a target_long cast, use the
>> unaligned load/store API.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> include/monitor/hmp-target.h | 3 ---
>> monitor/hmp-target.c         | 8 +++++---
>> 2 files changed, 5 insertions(+), 6 deletions(-)


>> diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c
>> index 5738b47bb03..257605a1c96 100644
>> --- a/monitor/hmp-target.c
>> +++ b/monitor/hmp-target.c
>> @@ -23,6 +23,7 @@
>>  */
>>
>> #include "qemu/osdep.h"
>> +#include "qemu/bswap.h"
>> #include "monitor-internal.h"
>> #include "monitor/qdev.h"
>> #include "net/slirp.h"
>> @@ -65,6 +66,7 @@ HMPCommand *hmp_cmds_for_target(bool info_command)
>>  */
>> int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)
>> {
>> +    const unsigned length = target_long_bits() / 8;
>>     const MonitorDef *md = target_monitor_defs();
>>     CPUState *cs = mon_get_cpu(mon);
>>     uint64_t tmp = 0;
>> @@ -83,11 +85,11 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, 
>> const char *name)
>>                 void *ptr = (uint8_t *)env + md->offset;
>>
>>                 switch(md->type) {
>> -                case MD_U32:
>> +                case MD_I32:
> 
> Why is this changed? Doesn't seem to be realted to what the commit 
> message says.

Good catch! This is due to a broken rebase I suppose. The change is
explained in patch #5 "monitor: Have MonitorDef::get_value() return
an unsigned type".

I'll clean that up and respin.