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

[qemu-xen stable-4.18] hw/char/riscv_htif: Fix printing of console characters on big endian hosts



commit 3af03de983108bc8c60a1a274b3e81a9553d4ce1
Author:     Thomas Huth <thuth@xxxxxxxxxx>
AuthorDate: Fri Jul 21 11:47:19 2023 +0200
Commit:     Michael Tokarev <mjt@xxxxxxxxxx>
CommitDate: Tue Sep 12 13:37:02 2023 +0300

    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.
    
    Fixes: 5033606780 ("RISC-V HTIF Console")
    Signed-off-by: Thomas Huth <thuth@xxxxxxxxxx>
    Reviewed-by: Alistair Francis <alistair.francis@xxxxxxx>
    Reviewed-by: Bin Meng <bmeng@xxxxxxxxxxx>
    Reviewed-by: Daniel Henrique Barboza <dbarboza@xxxxxxxxxxxxxxxx>
    Reviewed-by: Philippe Mathieu-Daudé <philmd@xxxxxxxxxx>
    Message-Id: <20230721094720.902454-2-thuth@xxxxxxxxxx>
    Signed-off-by: Alistair Francis <alistair.francis@xxxxxxx>
    (cherry picked from commit c255946e3df4d9660e4f468a456633c24393d468)
    Signed-off-by: Michael Tokarev <mjt@xxxxxxxxxx>
---
 hw/char/riscv_htif.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c
index 098de50e35..e6e0fa3015 100644
--- a/hw/char/riscv_htif.c
+++ b/hw/char/riscv_htif.c
@@ -190,7 +190,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);
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#stable-4.18



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.