Skip to contentSkip to conversation

hw/char/sifive_uart: Fix broken UART on big endian hosts

PATCH Applied Thomas Huth 4 participants 5 messages Nov 4, 2024 SiFive drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/char/sifive_uart: Fix broken UART on big endian hosts

Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit part of the value does not work on big endian hosts. We've got to take the proper detour through an 8-bit variable.

Fixes 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")
---
 hw/char/sifive_uart.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/char/sifive_uart.c +2 -1
index aeb45d3601..5ae2a29ed6 100644
@@ -174,10 +174,11 @@ sifive_uart_write(void *opaque, hwaddr addr,
 {
     SiFiveUARTState *s = opaque;
     uint32_t value = val64;
+    uint8_t ch = value;
 
     switch (addr) {
     case SIFIVE_UART_TXFIFO:
-        sifive_uart_write_tx_fifo(s, (uint8_t *) &value, 1);
+        sifive_uart_write_tx_fifo(s, &ch, 1);
         return;
     case SIFIVE_UART_IE:
         s->ie = val64;
Signature · 1 line
2.47.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Thomas Huth

Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit part of the value does not work on big endian hosts. We've got to take the proper detour through an 8-bit variable.

Fixes 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")
---
 hw/char/sifive_uart.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

thanks
-- PMM

Reviewed-by on v1 1/1
#2 lore raw
In reply to Thomas Huth
Quoted 9 lines · Thomas Huth

Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit part of the value does not work on big endian hosts. We've got to take the proper detour through an 8-bit variable.

Fixes 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")
---
  hw/char/sifive_uart.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by on v1 1/1
#3 lore raw
In reply to Thomas Huth
Quoted 7 lines · Thomas Huth

Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit part of the value does not work on big endian hosts. We've got to take the proper detour through an 8-bit variable.

Fixes 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")

Urgh!

Thanks for the fix

Alistair

Quoted 25 lines
---
 hw/char/sifive_uart.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/char/sifive_uart.c +2 -2
index aeb45d3601..5ae2a29ed6 100644
@@ -174,10 +174,11 @@ sifive_uart_write(void *opaque, hwaddr addr,
 {
     SiFiveUARTState *s = opaque;
     uint32_t value = val64;
+    uint8_t ch = value;
 
     switch (addr) {
     case SIFIVE_UART_TXFIFO:
-        sifive_uart_write_tx_fifo(s, (uint8_t *) &value, 1);
+        sifive_uart_write_tx_fifo(s, &ch, 1);
         return;
     case SIFIVE_UART_IE:
         s->ie = val64;
--

2.47.0

#4 lore raw
In reply to Thomas Huth
Quoted 7 lines · Thomas Huth

Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit part of the value does not work on big endian hosts. We've got to take the proper detour through an 8-bit variable.

Fixes 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 25 lines
---
 hw/char/sifive_uart.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/char/sifive_uart.c +2 -2
index aeb45d3601..5ae2a29ed6 100644
@@ -174,10 +174,11 @@ sifive_uart_write(void *opaque, hwaddr addr,
 {
     SiFiveUARTState *s = opaque;
     uint32_t value = val64;
+    uint8_t ch = value;
 
     switch (addr) {
     case SIFIVE_UART_TXFIFO:
-        sifive_uart_write_tx_fifo(s, (uint8_t *) &value, 1);
+        sifive_uart_write_tx_fifo(s, &ch, 1);
         return;
     case SIFIVE_UART_IE:
         s->ie = val64;
--

2.47.0