[PATCH v3 17/49] semihosting: Use struct gdb_stat in common_semi_flen_cb

Richard Henderson posted 49 patches 3 years, 1 month ago
There is a newer version of this series
[PATCH v3 17/49] semihosting: Use struct gdb_stat in common_semi_flen_cb
Posted by Richard Henderson 3 years, 1 month ago
Use offsetof instead of an integer constant.
Load the entire 64-bit size while we're at it.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 semihosting/arm-compat-semi.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index 2e0e7febb1..7becc14a81 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -325,14 +325,12 @@ static void
 common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err)
 {
     if (!err) {
-        /*
-         * The size is always stored in big-endian order, extract
-         * the value. We assume the size always fit in 32 bits.
-         */
-        uint32_t size;
-        cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32,
-                            (uint8_t *)&size, 4, 0);
-        ret = be32_to_cpu(size);
+        /* The size is always stored in big-endian order, extract the value. */
+        uint64_t size;
+        cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) +
+                            offsetof(struct gdb_stat, gdb_st_size),
+                            &size, 8, 0);
+        ret = be64_to_cpu(size);
     }
     common_semi_cb(cs, ret, err);
 }
-- 
2.34.1
Re: [PATCH v3 17/49] semihosting: Use struct gdb_stat in common_semi_flen_cb
Posted by Peter Maydell 3 years, 1 month ago
On Sat, 21 May 2022 at 01:04, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Use offsetof instead of an integer constant.
> Load the entire 64-bit size while we're at it.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  semihosting/arm-compat-semi.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)

Commit message seems to put the cart before the horse, in that
the important thing is the bugfix to read 64 bits and that
we choose to do that by using the struct offset is a detail :-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM