qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Filippov <jcmvbkbc@gmail.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH 2/2] target/xtensa: Remove tswap() calls in semihosting simcall() helper
Date: Fri, 6 Dec 2024 04:41:36 -0800	[thread overview]
Message-ID: <CAMo8BfKMhNd0C2HwL2aGAjPUZS8B7u8ncyW5PicswPns28SAmA@mail.gmail.com> (raw)
In-Reply-To: <20241205232437.85235-3-philmd@linaro.org>

On Thu, Dec 5, 2024 at 3:24 PM Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> In preparation of heterogeneous emulation where cores with
> different endianness can run concurrently, we need to remove
> the tswap() calls -- which use a fixed per-binary endianness.
>
> Get the endianness of the CPU accessed using the libisa
> xtensa_isa_is_big_endian() call and replace the tswap() calls
> by bswap() ones when necessary.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/xtensa/xtensa-semi.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
> index fa21b7e11fc..21d23e39de5 100644
> --- a/target/xtensa/xtensa-semi.c
> +++ b/target/xtensa/xtensa-semi.c
> @@ -328,10 +328,17 @@ void HELPER(simcall)(CPUXtensaState *env)
>              struct timeval tv = {0};
>
>              if (target_tv) {
> +                bool cpu_big_endian = xtensa_isa_is_big_endian(env->config->isa);
> +                bool swap_needed = HOST_BIG_ENDIAN != cpu_big_endian;
> +
>                  cpu_memory_rw_debug(cs, target_tv,
>                          (uint8_t *)target_tvv, sizeof(target_tvv), 0);
> -                tv.tv_sec = (int32_t)tswap32(target_tvv[0]);
> -                tv.tv_usec = (int32_t)tswap32(target_tvv[1]);
> +                if (swap_needed) {
> +                    bswap32s(&target_tvv[0]);
> +                    bswap32s(&target_tvv[1]);
> +                }
> +                tv.tv_sec = (int32_t)target_tvv[0];
> +                tv.tv_usec = (int32_t)target_tvv[1];

This conversion looks a bit heavy. Maybe it would be better to
give tswap*() an additional env argument and give the target
a way to deal with it?

>              }
>              if (fd < 3 && sim_console) {
>                  if ((fd == 1 || fd == 2) && rq == SELECT_ONE_WRITE) {
> @@ -381,6 +388,8 @@ void HELPER(simcall)(CPUXtensaState *env)
>              int argc = semihosting_get_argc();
>              int str_offset = (argc + 1) * sizeof(uint32_t);
>              int i;
> +            bool cpu_big_endian = xtensa_isa_is_big_endian(env->config->isa);
> +            bool swap_needed = HOST_BIG_ENDIAN != cpu_big_endian;
>              uint32_t argptr;
>
>              for (i = 0; i < argc; ++i) {
> @@ -388,6 +397,9 @@ void HELPER(simcall)(CPUXtensaState *env)
>                  int str_size = strlen(str) + 1;
>
>                  argptr = tswap32(regs[3] + str_offset);

The tswap() is still here.

> +                if (swap_needed) {
> +                    bswap32s(&argptr);
> +                }
>
>                  cpu_memory_rw_debug(cs,
>                                      regs[3] + i * sizeof(uint32_t),

-- 
Thanks.
-- Max


  reply	other threads:[~2024-12-06 12:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-05 23:24 [PATCH 0/2] target/xtensa: Remove tswap() calls in semihosting Philippe Mathieu-Daudé
2024-12-05 23:24 ` [PATCH 1/2] target/xtensa: Implement xtensa_isa_is_big_endian() Philippe Mathieu-Daudé
2024-12-06 12:35   ` Max Filippov
2025-11-27  9:37     ` Philippe Mathieu-Daudé
2024-12-05 23:24 ` [PATCH 2/2] target/xtensa: Remove tswap() calls in semihosting simcall() helper Philippe Mathieu-Daudé
2024-12-06 12:41   ` Max Filippov [this message]
2024-12-06 14:34     ` Philippe Mathieu-Daudé
2024-12-06 14:54       ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMo8BfKMhNd0C2HwL2aGAjPUZS8B7u8ncyW5PicswPns28SAmA@mail.gmail.com \
    --to=jcmvbkbc@gmail.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).