Message ID | 20230908060431.1903919-4-alistair.francis@wdc.com |
---|---|
State | New |
Headers | show |
Series | [PULL,01/65] target/riscv/cpu.c: do not run 'host' CPU with TCG | expand |
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
diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index f96df40124..40de6b8b77 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -30,6 +30,7 @@ #include "qemu/timer.h" #include "qemu/error-report.h" #include "exec/address-spaces.h" +#include "exec/tswap.h" #include "sysemu/dma.h" #define RISCV_DEBUG_HTIF 0 @@ -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) { uint8_t ch; - cpu_physical_memory_read(syscall[2], &ch, 1); + cpu_physical_memory_read(tswap64(syscall[2]), &ch, 1); qemu_chr_fe_write(&s->chr, &ch, 1); resp = 0x100 | (uint8_t)payload; } else {