[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC PATCH 5/6] xen/riscv: Add early_printk
Signed-off-by: Xie Xun <xiexun162534@xxxxxxxxx> --- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/early_printk.c | 48 +++++++++++++++++++++++ xen/arch/riscv/include/asm/early_printk.h | 10 +++++ 3 files changed, 59 insertions(+) create mode 100644 xen/arch/riscv/early_printk.c create mode 100644 xen/arch/riscv/include/asm/early_printk.h diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile index c61349818f..f9abc8401b 100644 --- a/xen/arch/riscv/Makefile +++ b/xen/arch/riscv/Makefile @@ -3,6 +3,7 @@ obj-y += lib/ obj-y += domctl.o obj-y += domain.o obj-y += delay.o +obj-y += early_printk.o obj-y += guestcopy.o obj-y += irq.o obj-y += p2m.o diff --git a/xen/arch/riscv/early_printk.c b/xen/arch/riscv/early_printk.c new file mode 100644 index 0000000000..81d69add01 --- /dev/null +++ b/xen/arch/riscv/early_printk.c @@ -0,0 +1,48 @@ +/* + * RISC-V early printk using SBI + * + * Copyright (C) 2021 Bobby Eshleman <bobbyeshleman@xxxxxxxxx> + */ +#include <asm/sbi.h> +#include <asm/early_printk.h> +#include <xen/stdarg.h> +#include <xen/lib.h> + +void _early_puts(const char *s, size_t nr) +{ + while ( nr-- > 0 ) + { + if (*s == '\n') + sbi_console_putchar('\r'); + sbi_console_putchar(*s); + s++; + } +} + +static void vprintk_early(const char *prefix, const char *fmt, va_list args) +{ + char buf[128]; + int sz; + + early_puts(prefix); + + sz = vscnprintf(buf, sizeof(buf), fmt, args); + + if ( sz < 0 ) { + early_puts("(XEN) vprintk_early error\n"); + return; + } + + if ( sz == 0 ) + return; + + _early_puts(buf, sz); +} + +void early_printk(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintk_early("(XEN) ", fmt, args); + va_end(args); +} diff --git a/xen/arch/riscv/include/asm/early_printk.h b/xen/arch/riscv/include/asm/early_printk.h new file mode 100644 index 0000000000..0d9928b333 --- /dev/null +++ b/xen/arch/riscv/include/asm/early_printk.h @@ -0,0 +1,10 @@ +#ifndef __EARLY_PRINTK_H__ +#define __EARLY_PRINTK_H__ + +#include <xen/string.h> + +#define early_puts(s) _early_puts((s), strlen((s))) +void _early_puts(const char *s, size_t nr); +void early_printk(const char *fmt, ...); + +#endif /* __EARLY_PRINTK_H__ */ -- 2.30.2
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |