qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PULL 03/65] hw/char/riscv_htif: Fix the console syscall on big endi


From: Michael Tokarev
Subject: Re: [PULL 03/65] hw/char/riscv_htif: Fix the console syscall on big endian hosts
Date: Fri, 8 Sep 2023 09:15:22 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0

08.09.2023 09:03, Alistair Francis wrote:
From: Thomas Huth <thuth@redhat.com>

@@ -209,11 +210,11 @@ static void htif_handle_tohost_write(HTIFState *s, 
uint64_t val_written)
              } else {
                  uint64_t syscall[8];
                  cpu_physical_memory_read(payload, syscall, sizeof(syscall));
-                if (syscall[0] == PK_SYS_WRITE &&
-                    syscall[1] == HTIF_DEV_CONSOLE &&
-                    syscall[3] == HTIF_CONSOLE_CMD_PUTC) {
+                if (tswap64(syscall[0]) == PK_SYS_WRITE &&
+                    tswap64(syscall[1]) == HTIF_DEV_CONSOLE &&
+                    tswap64(syscall[3]) == HTIF_CONSOLE_CMD_PUTC) {

Maybe not in this very case as it does not seem to be speed-critical,
but I'd say we can change that to read backwards, like:

 +                if (syscall[0] == tswap64(PK_SYS_WRITE) ...

This way it's easier for the compiler to omit call to tswap64 entirely
and calculate the static value at compile time, so only comparison is
left for the runtime.

But this way it's less readable as well.

Just a side note.

/mjt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]