Browse Source
Fix printm on RV32 (#119)
Use a proxy syscall instead of a blocking character write.
Resolves #84
pull/121/head
Andrew Waterman
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
16 additions and
0 deletions
-
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() |
|
|
|
|