aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2023-07-21 11:47:20 +0200
committerMichael Tokarev <mjt@tls.msk.ru>2023-09-20 10:18:14 +0300
commita57e4cc6fe81a0b2ca8a32db91ca45df205c4a8f (patch)
tree3695ba996f41f22f1f751c0cce12729d735deab4
parentaeb931d82b13c50587268f462dcd46b23d2086ff (diff)
downloadqemu-a57e4cc6fe81a0b2ca8a32db91ca45df205c4a8f.zip
qemu-a57e4cc6fe81a0b2ca8a32db91ca45df205c4a8f.tar.gz
qemu-a57e4cc6fe81a0b2ca8a32db91ca45df205c4a8f.tar.bz2
hw/char/riscv_htif: Fix the console syscall on big endian hosts
Values that have been read via cpu_physical_memory_read() from the guest's memory have to be swapped in case the host endianess differs from the guest. Fixes: a6e13e31d5 ("riscv_htif: Support console output via proxy syscall") Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Message-Id: <20230721094720.902454-3-thuth@redhat.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com> (cherry picked from commit 058096f1c55ab688db7e1d6814aaefc1bcd87f7a) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> (Mjt: context fix in hw/char/riscv_htif.c for #include)
-rw-r--r--hw/char/riscv_htif.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c
index e6e0fa3..198175e 100644
--- a/hw/char/riscv_htif.c
+++ b/hw/char/riscv_htif.c
@@ -29,6 +29,7 @@
#include "chardev/char-fe.h"
#include "qemu/timer.h"
#include "qemu/error-report.h"
+#include "exec/tswap.h"
#define RISCV_DEBUG_HTIF 0
#define HTIF_DEBUG(fmt, ...) \
@@ -167,11 +168,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 {