riscv: Fix the console of the Spike machine on big endian hosts
cover riscv: Fix the console of the Spike machine on big endian hosts
The tests/avocado/riscv_opensbi.py avocado test is currently failing on big endian hosts since the console of the Spike machine is not working there. With two small patches, this can be fixed: First patch fixes riscv64, and the second one fixes riscv32.
Thomas Huth (2):
hw/char/riscv_htif: Fix printing of console characters on big endian
hosts
hw/char/riscv_htif: Fix the console syscall on big endian hosts
hw/char/riscv_htif.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.39.3
PATCH 1/2 hw/char/riscv_htif: Fix printing of console characters on big endian hosts
The character that should be printed is stored in the 64 bit "payload" variable. The code currently tries to print it by taking the address of the variable and passing this pointer to qemu_chr_fe_write(). However, this only works on little endian hosts where the least significant bits are stored on the lowest address. To do this in a portable way, we have to store the value in an uint8_t variable instead.
--- hw/char/riscv_htif.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/char/riscv_htif.c +2 -1
@@ -232,7 +232,8 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) s->tohost =0 ;/* clear to indicate we read */ return ; }else if (cmd ==HTIF_CONSOLE_CMD_PUTC ) { -qemu_chr_fe_write (&s->chr, (uint8_t *)&payload,1 ); +uint8_t ch = (uint8_t )payload; +qemu_chr_fe_write (&s->chr, &ch,1 ); resp =0x100 | (uint8_t )payload; }else {qemu_log ("HTIF device %d: unknown command\n" , device);
Signature · 1 line
2.39.3
Re: [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts
Quoted 8 lines · Thomas Huth
The character that should be printed is stored in the 64 bit "payload" variable. The code currently tries to print it by taking the address of the variable and passing this pointer to
qemu_chr_fe_write(). However, this only works on little endian hosts where the least significant bits are stored on the lowest address. To do this in a portable way, we have to store the value in anuint8_tvariable instead.
Quoted 6 lines
Fixes 5033606780 ("RISC-V HTIF Console")Signed-off-by Thomas Huth <[email protected]>--- hw/char/riscv_htif.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Re: [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts
In reply to Thomas HuthQuoted 10 lines · Thomas Huth
The character that should be printed is stored in the 64 bit "payload" variable. The code currently tries to print it by taking the address of the variable and passing this pointer to
qemu_chr_fe_write(). However, this only works on little endian hosts where the least significant bits are stored on the lowest address. To do this in a portable way, we have to store the value in anuint8_tvariable instead.Fixes 5033606780 ("RISC-V HTIF Console")Signed-off-by Thomas Huth <[email protected]>---
Quoted 17 lines
hw/char/riscv_htif.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/char/riscv_htif.c +2
-1@@ -232,7 +232,8 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) s->tohost =0 ;/* clear to indicate we read */ return ; }else if (cmd ==HTIF_CONSOLE_CMD_PUTC ) { -qemu_chr_fe_write (&s->chr, (uint8_t *)&payload,1 ); +uint8_t ch = (uint8_t )payload; +qemu_chr_fe_write (&s->chr, &ch,1 ); resp =0x100 | (uint8_t )payload; }else {qemu_log ("HTIF device %d: unknown command\n" , device);
Re: [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts
In reply to Thomas HuthQuoted 7 lines · Thomas Huth
The character that should be printed is stored in the 64 bit "payload" variable. The code currently tries to print it by taking the address of the variable and passing this pointer to
qemu_chr_fe_write(). However, this only works on little endian hosts where the least significant bits are stored on the lowest address. To do this in a portable way, we have to store the value in anuint8_tvariable instead.
Quoted 5 lines
Fixes 5033606780 ("RISC-V HTIF Console")Signed-off-by Thomas Huth <[email protected]>--- hw/char/riscv_htif.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Re: [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts
In reply to Thomas HuthQuoted 10 lines · Thomas Huth
The character that should be printed is stored in the 64 bit "payload" variable. The code currently tries to print it by taking the address of the variable and passing this pointer to
qemu_chr_fe_write(). However, this only works on little endian hosts where the least significant bits are stored on the lowest address. To do this in a portable way, we have to store the value in anuint8_tvariable instead.Fixes 5033606780 ("RISC-V HTIF Console")Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 22 lines
--- hw/char/riscv_htif.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/char/riscv_htif.c +2
-2@@ -232,7 +232,8 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) s->tohost =0 ;/* clear to indicate we read */ return ; }else if (cmd ==HTIF_CONSOLE_CMD_PUTC ) { -qemu_chr_fe_write (&s->chr, (uint8_t *)&payload,1 ); +uint8_t ch = (uint8_t )payload; +qemu_chr_fe_write (&s->chr, &ch,1 ); resp =0x100 | (uint8_t )payload; }else {qemu_log ("HTIF device %d: unknown command\n" , device); --2.39.3
PATCH 2/2 hw/char/riscv_htif: Fix the console syscall on big endian hosts
In reply to Thomas HuthValues 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.
--- hw/char/riscv_htif.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/char/riscv_htif.c +5 -4
@@ -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 {
Signature · 1 line
2.39.3
Re: [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall on big endian hosts
Quoted 3 lines · Thomas Huth
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
typo: endianness
Quoted 8 lines
from the guest.
Fixes a6e13e31d5 ("riscv_htif: Support console output via proxy syscall")Signed-off-by Thomas Huth <[email protected]>--- hw/char/riscv_htif.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Re: [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall on big endian hosts
In reply to Thomas HuthQuoted 7 lines · Thomas Huth
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 <[email protected]>---
Quoted 31 lines
hw/char/riscv_htif.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/char/riscv_htif.c +5
-4@@ -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 {
Re: [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall on big endian hosts
In reply to Thomas HuthQuoted 7 lines · Thomas Huth
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 <[email protected]>
Alistair
Quoted 36 lines
--- hw/char/riscv_htif.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/char/riscv_htif.c +5
-5@@ -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 { --2.39.3
Alistair Francis
AppliedQuoted 10 lines · Thomas Huth
The
tests/avocado/riscv_opensbi.pyavocado test is currently failing on big endian hosts since the console of the Spike machine is not working there. With two small patches, this can be fixed: First patch fixes riscv64, and the second one fixes riscv32.Thomas Huth (2):
hw/char/riscv_htif: Fix printing of console characters on big endian
hosts
hw/char/riscv_htif: Fix the console syscall on big endian hosts
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 8 lines
hw/char/riscv_htif.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)--
2.39.3