From 706cc77c369fd3e4734b5a6aa813d421347f1814 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Wed, 15 Aug 2018 02:46:11 -0700 Subject: Fix printm on RV32 (#119) Use a proxy syscall instead of a blocking character write. Resolves #84 --- machine/htif.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'machine/htif.c') diff --git a/machine/htif.c b/machine/htif.c index d3921a4..aae8c56 100644 --- a/machine/htif.c +++ b/machine/htif.c @@ -4,6 +4,7 @@ #include "atomic.h" #include "mtrap.h" #include "fdt.h" +#include "syscall.h" #include extern uint64_t __htif_base; @@ -48,6 +49,11 @@ static void __set_tohost(uintptr_t dev, uintptr_t cmd, uintptr_t data) int htif_console_getchar() { +#if __riscv_xlen == 32 + // HTIF devices are not supported on RV32 + return -1; +#endif + spinlock_lock(&htif_lock); __check_fromhost(); int ch = htif_console_buf; @@ -85,9 +91,19 @@ void htif_syscall(uintptr_t arg) void htif_console_putchar(uint8_t ch) { +#if __riscv_xlen == 32 + // HTIF devices are not supported on RV32, so proxy a write system call + volatile uint64_t magic_mem[8]; + magic_mem[0] = SYS_write; + magic_mem[1] = 1; + magic_mem[2] = (uintptr_t)&ch; + magic_mem[3] = 1; + do_tohost_fromhost(0, 0, (uintptr_t)magic_mem); +#else spinlock_lock(&htif_lock); __set_tohost(1, 1, ch); spinlock_unlock(&htif_lock); +#endif } void htif_poweroff() -- cgit v1.1