diff options
Diffstat (limited to 'machine/htif.c')
-rw-r--r-- | machine/htif.c | 16 |
1 files changed, 16 insertions, 0 deletions
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 <string.h> 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() |