From 39dfe5408328043b5434c9295ac6cbdd07562957 Mon Sep 17 00:00:00 2001 From: Zakk Chen Date: Tue, 10 Aug 2021 21:27:51 -0700 Subject: [PATCH] Improve nop_putc and fix bug. in clang, the result is c.mv a1, a0 c.li a0, -1 c.mv a0, a1 slli zero, a0, 0x11 c.jr ra result is incorrect, we need to add a0 into clobber list. --- src/tty.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tty.c b/src/tty.c index e5ffdb26..fff06556 100644 --- a/src/tty.c +++ b/src/tty.c @@ -43,7 +43,8 @@ int nop_putc(int c) { // truly in a0, for easier post-processing, and so there is a single // 32-bit opcode to match against. // So explicitly ensure that the argument is placed into a0 first. - __asm__ volatile("mv a0, %0; slli x0,a0,0x11" ::"r"(c)); + register long xc asm("a0") = c; + __asm__ volatile("slli x0,a0,0x11" ::"r"(xc)); return -1; } int metal_tty_putc(int c) __attribute__((weak, alias("nop_putc")));